Received: by 10.192.165.148 with SMTP id m20csp305637imm; Thu, 3 May 2018 20:56:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoBfSLJA/qpgc9wUjKg55PaTeDaNt/46hSR8ALv1B6VXXQRnPuBcuW+ZgaKEwi5LrayRV79 X-Received: by 2002:a17:902:14d:: with SMTP id 71-v6mr1503251plb.275.1525406193489; Thu, 03 May 2018 20:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525406193; cv=none; d=google.com; s=arc-20160816; b=YUQ8p3mCcJ6bSBw7bUwm7GvauQZVQORhTJWWG81Ll9OwxocmalrGqcEMUA3Txt3+0/ JVHkOoy5uLW1PtO+gK3doN9huMFm3KMNHJt+UGIefbqe0vgoV7T9Tdn/xdnZpmOUlikY fUck5LJBiGjN0rvjinLiGDrksMGBZRYOiEi73ixpyDQBdXk8+UdUQQNb29xCkXEmqD6Z z5xJHA9IckEOw5TfkKAus4h+QN3LcxqydihEflVHcD1MgdN247sBYk1grSqIIjS3IRCr HOGo+RhyfP9NfStvgJI2LsHdDkVa22lAq/+XYdzshc935529frIaXKvSztvHVkkOLuPa kjXQ== 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=vBz9G8aQF1SQg20Boe9CfOkjgWmvV6fc1H5rsmyXHNY=; b=XS2PpRRqSSDneo+/aGiXuPWPLrfmgf31gbEtSomxsz+r6/x0IJGGrz7uvs153Xseix u7m3Cj77F6MvU7clqNr5SFCK5rZbLTnQNyP6QQBPw74rqKYKLsf3LhcVkljEA9INjk1u fob+fle0uIJTLoSFVFxUwpeu4BeVv9yeAYMFU9yW3U7/gSEjambhUD6l4M/7tA8ZWdM0 lLS71C6gUvyjsU+vReGPxKd4mpLxJtyI6JGhFhT8cwsZVda5Cpu0nCR03E8kn+5eY+U/ hoquDt+VILUK+WjvR+wPPGSjSNEsCQIe2afwffYiH3sFdUgp7BmXsg88sHdIdo04WZap wbDg== 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 n128-v6si12299234pgn.15.2018.05.03.20.56.19; Thu, 03 May 2018 20:56:33 -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 S1751461AbeEDDzC (ORCPT + 99 others); Thu, 3 May 2018 23:55:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:44974 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbeEDDy7 (ORCPT ); Thu, 3 May 2018 23:54:59 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2618BABB2; Fri, 4 May 2018 03:54:58 +0000 (UTC) From: NeilBrown To: Thomas Graf , Herbert Xu Date: Fri, 04 May 2018 13:54:14 +1000 Subject: [PATCH 3/8] rhashtable: use cmpxchg() to protect ->future_tbl. Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <152540605430.18473.11758878046224478232.stgit@noble> In-Reply-To: <152540595840.18473.11298241115621799037.stgit@noble> References: <152540595840.18473.11298241115621799037.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 | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 4a3f94e8e8a6..b73afe1dec7e 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -298,21 +298,16 @@ 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. + * The use of 'tmp' is simply to ensure we get the required memory + * barriers before the cmpxchg(). */ - rcu_assign_pointer(old_tbl->future_tbl, new_tbl); + struct bucket_table *tmp; - spin_unlock_bh(old_tbl->locks); + rcu_assign_pointer(tmp, new_tbl); + if (cmpxchg(&old_tbl->future_tbl, NULL, tmp) != NULL) + return -EEXIST; return 0; }