Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp180386imm; Thu, 31 May 2018 21:48:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKzngpo8I47QrGGHYj0sZzRerCcXRsXyULzS7Sb+LsYfekLgP5HdFDquYpCJTDu1UrlpVWt X-Received: by 2002:a63:7847:: with SMTP id t68-v6mr206746pgc.329.1527828483741; Thu, 31 May 2018 21:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527828483; cv=none; d=google.com; s=arc-20160816; b=N3Yt5BTTBEByyigdD9JOcBq6MPlvl8Cqvw3VovvgY0w5AFM8D6UjaX/+d2pzzOq3A8 4pv8T+prFFAHve5VhBUPCosdCON3YX388G6P1BMUA/0AVP0F3tyKesCCbQPFmzNkFErJ 5GndXCKL1f7KPJNjOThdoFTU54cCzSyIpk21lnF6zqlKx1eq6d3VBRBBbKkFroXL1wlh jIEysOO3aKq8cmKhUCAbesDlPQ0d+ZJK8JcRrArzM5/qOqjCRxEjWqKeckJkUDM7cjRL zXjsqatwQ9AcGaOMhn700T5KeUfYecXXn52l7A6PQElLgJX/BgfWIwnDuP1ccIe78Fwi 9ZiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from:arc-authentication-results; bh=yo50xurrGia0L7oYFTwdEx4/QSXIFeS2bJ0Ie7b4VcA=; b=mco5H5SMVjQ89H/SwNUBNQVn0a17u1ZuKhUcYK9XU6kgZLWMqGSoJOPBH1OUja5xMg 5K2HIQyhkmHYZijmJg8JjdWheLGdimBm0VpNSjQuzCCwP/MYd0c2XeAOwyAb8pzMW4x3 kYIr1srq60S2ZSXz+Ke9Oi8cGjme2s2WwZdwy5alyOA59zJQ7E//1z+1Mmiv0sYKHPMY 22RuA7C1X1t6Wzs4viVVYxYZLzxt1lMjEbsGczSZ6j88639mqONqdNN/v6NA6xA25QpJ Z4H96wOunZiX5vWus89EO8Ou5z+KdZFdM7JUpRxziy8bEw4p6rbJCRyto2mpqT72QM9i KJUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18-v6si38465789pfd.357.2018.05.31.21.47.49; Thu, 31 May 2018 21:48:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751492AbeFAEpw (ORCPT + 99 others); Fri, 1 Jun 2018 00:45:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:34063 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441AbeFAEpt (ORCPT ); Fri, 1 Jun 2018 00:45:49 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A633AAD02; Fri, 1 Jun 2018 04:45:47 +0000 (UTC) From: NeilBrown To: Thomas Graf , Herbert Xu Date: Fri, 01 Jun 2018 14:44:09 +1000 Subject: [PATCH 07/18] rhashtable: use cmpxchg() to protect ->future_tbl. Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <152782824954.30340.10107132482367263068.stgit@noble> In-Reply-To: <152782754287.30340.4395718227884933670.stgit@noble> References: <152782754287.30340.4395718227884933670.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rather than borrowing one of the bucket locks to protect ->future_tbl updates, use cmpxchg(). This gives more freedom to change how bucket locking is implemented. Signed-off-by: NeilBrown --- lib/rhashtable.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index e209069f1d74..b5d17bce19ff 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -297,21 +297,14 @@ static int rhashtable_rehash_attach(struct rhashtable *ht, struct bucket_table *old_tbl, struct bucket_table *new_tbl) { - /* Protect future_tbl using the first bucket lock. */ - spin_lock_bh(old_tbl->locks); - - /* Did somebody beat us to it? */ - if (rcu_access_pointer(old_tbl->future_tbl)) { - spin_unlock_bh(old_tbl->locks); - return -EEXIST; - } - /* Make insertions go into the new, empty table right away. Deletions * and lookups will be attempted in both tables until we synchronize. + * As cmpxchg() provides strong barriers, we do not need + * rcu_assign_pointer(). */ - rcu_assign_pointer(old_tbl->future_tbl, new_tbl); - spin_unlock_bh(old_tbl->locks); + if (cmpxchg(&old_tbl->future_tbl, NULL, new_tbl) != NULL) + return -EEXIST; return 0; }