Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6375241yba; Thu, 11 Apr 2019 18:54:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyENKoONsn8B8M5kf5/TgUA3v3Yes77c7bZ2xHWfwMmXeG3SifM2w0ph+6Na/LyFlzJxFAj X-Received: by 2002:aa7:83d1:: with SMTP id j17mr54362348pfn.78.1555034040905; Thu, 11 Apr 2019 18:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555034040; cv=none; d=google.com; s=arc-20160816; b=X34X0rOAdbAOzJSIeAoF7W/qcl37Ovtw58KpwOGJwuMEsBTYAuQPIDM8LN0/ed+Fmw kLiAhYPgLYRM9y4jP1IYZT/CfTw/4Acr6QB2VGH2F3hnKjbnPdBp4Ci30QYCyOCLwu4p Acafi+0oof3V+QGUMGV1OMxlXqhUIh2uPYGNGy27cXoYTIZs3nr6DEpWqvkVsvQ/lahd RkFOGnibfugoa/6ghJE76v5HRPL9WE2aCxdGyshrxp8R8tR532IrQU1vNSMt3hYcERRs 94PT1wjo0G/fLwtobW2B8HpJ5hHEgvQkeHyasfpisdBpR0q1N6PkPzNG8QotEm2G9NkN TzzQ== 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; bh=h/K5yPEAdDZEW+7frjB82jwZaxD8x+fA0eh60i8OD3g=; b=AgRRtyE4vR8wwN+OTW4H8S6DVkIS4xaYELsQsTvZMA+INhWyHtO3LX/erRRaRJw0DS 3z8oW2GbQIkHtQscGZjlgpGWyiKEajYfTOAz1jFXZtYPufTIy/O1ey+bI+bm1NuIG+sb /O/9MdkrzLmtrb1bZWHHp2PTlIdBPeyA1xuVE/7S7Svf2QN44m4T/2yiXPzZMaJIKTyI sAeHeOl3o90y2Ok6r+yWFAsP2nydGoahjJ2X25R1AkDBRTFZ1yD/5f9J+wNprmDHfqTV uRX5jxvIbb7avRy1ovoHPuuFAhvDD2da9OlAWA/AaN5SGyG7HgrYZlDxEYi/JZaR0alZ Ygiw== 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 t9si24495112pgp.273.2019.04.11.18.53.44; Thu, 11 Apr 2019 18:54:00 -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 S1726936AbfDLBwy (ORCPT + 99 others); Thu, 11 Apr 2019 21:52:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:48956 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726905AbfDLBwx (ORCPT ); Thu, 11 Apr 2019 21:52:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4022BACF8; Fri, 12 Apr 2019 01:52:52 +0000 (UTC) From: NeilBrown To: Thomas Graf , Herbert Xu , David Miller Date: Fri, 12 Apr 2019 11:52:08 +1000 Subject: [PATCH 4/5] rhashtable: replace rht_ptr_locked() with rht_assign_locked() Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Message-ID: <155503392804.17793.16261235110097755380.stgit@noble.brown> In-Reply-To: <155503371949.17793.8266195008003399968.stgit@noble.brown> References: <155503371949.17793.8266195008003399968.stgit@noble.brown> 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 The only times rht_ptr_locked() is used, it is to store a new value in a bucket-head. This is the only time it makes sense to use it too. So replace it by a function which does the whole task: Sets the lock bit and assigns to a bucket head. Signed-off-by: NeilBrown --- include/linux/rhashtable.h | 9 ++++++--- lib/rhashtable.c | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h index b54e6436547e..882bc0fcea4b 100644 --- a/include/linux/rhashtable.h +++ b/include/linux/rhashtable.h @@ -316,6 +316,7 @@ static inline struct rhash_lock_head __rcu **rht_bucket_insert( * local_bh. For that we have rht_assign_unlock(). As rcu_assign_pointer() * provides the same release semantics that bit_spin_unlock() provides, * this is safe. + * When we write to a bucket without unlocking, we use rht_assign_locked(). */ static inline void rht_lock(struct bucket_table *tbl, @@ -369,10 +370,12 @@ static inline struct rhash_head *rht_ptr_exclusive( return (void *)(((unsigned long)p) & ~BIT(1)); } -static inline struct rhash_lock_head __rcu *rht_ptr_locked(const - struct rhash_head *p) +static inline void rht_assign_locked(struct rhash_lock_head __rcu **bkt, + struct rhash_head *obj) { - return (void *)(((unsigned long)p) | BIT(1)); + struct rhash_head __rcu **p = (struct rhash_head __rcu **)bkt; + + rcu_assign_pointer(*p, (void *)((unsigned long)obj | BIT(1))); } static inline void rht_assign_unlock(struct bucket_table *tbl, diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 1f38f550ba76..3bae6b05b4ba 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -260,7 +260,7 @@ static int rhashtable_rehash_one(struct rhashtable *ht, rcu_assign_pointer(*pprev, next); else /* Need to preserved the bit lock. */ - rcu_assign_pointer(*bkt, rht_ptr_locked(next)); + rht_assign_locked(bkt, next); out: return err; @@ -518,7 +518,7 @@ static void *rhashtable_lookup_one(struct rhashtable *ht, rcu_assign_pointer(*pprev, obj); else /* Need to preserve the bit lock */ - rcu_assign_pointer(*bkt, rht_ptr_locked(obj)); + rht_assign_locked(bkt, obj); return NULL; } @@ -571,7 +571,7 @@ static struct bucket_table *rhashtable_insert_one(struct rhashtable *ht, /* bkt is always the head of the list, so it holds * the lock, which we need to preserve */ - rcu_assign_pointer(*bkt, rht_ptr_locked(obj)); + rht_assign_locked(bkt, obj); atomic_inc(&ht->nelems); if (rht_grow_above_75(ht, tbl))