Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1476560imm; Fri, 6 Jul 2018 00:24:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfy75Ml+QNhdS14yriKR3P7mSENAsV65qDbsOOFfxVQFEOx9bApqEX5OB5JTgrNcJtZIC+A X-Received: by 2002:a63:686:: with SMTP id 128-v6mr2300789pgg.338.1530861887883; Fri, 06 Jul 2018 00:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530861887; cv=none; d=google.com; s=arc-20160816; b=fqIXB/VCwJVPUWbcX4QKFbhy8Cc5TPLPxM2gPWTdiq/NdMEDi78YmdBmlpNwE6zR63 kEdP6YriWQuwYKpNlHXrveugBxvvlWsxBD5SKEuIXvJJR8AequPJSjSVl19/ZR8ramO6 2r//7XkSjKXY8FSVuTieUbHqio736gmAdGXRb4+kjxxg2lNJ/D/byTnYgKwVdWNc47LZ O4yHUyQgCpyyU0lCePFOXhLkuqHlOejhpZl8Akk3pAxLUC+e71U6Ai7FIhXvqXMSs+5M 38Ob1VgOJzlfz4S2fd7FxdSFwmxJuq0iTKdNnMRWYmGPXPJOpaJhfXdVweuLhFCboBq3 5CBg== 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=3PePChDyjzp8CgSatIJEKzoBm0ym73GmFLOUAOfHESU=; b=W9B4+T/gNISysGqy3/gw31GvXkMALaqARnykzjd/sTFg3IBvHROLmNkFQYr6VReIIl sIlRD4UGjcSWKDusyaEiuEwAEs0ATPAOWhZzA4w+VcA2U/Ckr1uliyu4QEWxpQT/y5DZ aHBLT2yYYqkL2F8tV/j/+iBZbhMXzVNOmoh7D8KJZs8iR6W5B5MzVVr3FhYnA6tBpvAt ha7z9V+K5eIu6xkgWlVmA3L1Uzzd7An1+GvKZYGzaKKekDmJPCA4rfyW0EvfhnZiAjED sGicWujbFnle7ozViJH2RbeFZkvhIdeC9VGDiSabfVma2d3aXg+fSmZ1PhFGa0ncJ/Ll nxsQ== 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 w6-v6si7342248pgb.61.2018.07.06.00.24.33; Fri, 06 Jul 2018 00:24:47 -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 S1754269AbeGFHX0 (ORCPT + 99 others); Fri, 6 Jul 2018 03:23:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:48936 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753476AbeGFHXX (ORCPT ); Fri, 6 Jul 2018 03:23:23 -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 66588AFD0; Fri, 6 Jul 2018 07:23:22 +0000 (UTC) From: NeilBrown To: Thomas Graf , Herbert Xu Date: Fri, 06 Jul 2018 17:22:30 +1000 Subject: [PATCH 3/5] rhashtable: allow rht_bucket_var to return NULL. Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <153086175012.24852.12288342670006044159.stgit@noble> In-Reply-To: <153086169828.24852.10332573315056854948.stgit@noble> References: <153086169828.24852.10332573315056854948.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 returning a pointer a static nulls, rht_bucket_var() now returns NULL if the bucket doesn't exist. This will make the next patch, which stores a bitlock in the bucket pointer, somewhat cleaner. Signed-off-by: NeilBrown --- include/linux/rhashtable.h | 11 +++++++++-- lib/rhashtable.c | 29 ++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h index 26ed3b299028..a4ff6ae524a0 100644 --- a/include/linux/rhashtable.h +++ b/include/linux/rhashtable.h @@ -284,6 +284,8 @@ void rhashtable_destroy(struct rhashtable *ht); struct rhash_head __rcu **rht_bucket_nested(const struct bucket_table *tbl, unsigned int hash); +struct rhash_head __rcu **__rht_bucket_nested(const struct bucket_table *tbl, + unsigned int hash); struct rhash_head __rcu **rht_bucket_nested_insert(struct rhashtable *ht, struct bucket_table *tbl, unsigned int hash); @@ -313,7 +315,7 @@ static inline struct rhash_head __rcu *const *rht_bucket( static inline struct rhash_head __rcu **rht_bucket_var( struct bucket_table *tbl, unsigned int hash) { - return unlikely(tbl->nest) ? rht_bucket_nested(tbl, hash) : + return unlikely(tbl->nest) ? __rht_bucket_nested(tbl, hash) : &tbl->buckets[hash]; } @@ -916,6 +918,8 @@ static inline int __rhashtable_remove_fast_one( spin_lock_bh(lock); pprev = rht_bucket_var(tbl, hash); + if (!pprev) + goto out; rht_for_each_continue(he, *pprev, tbl, hash) { struct rhlist_head *list; @@ -960,6 +964,7 @@ static inline int __rhashtable_remove_fast_one( break; } +out: spin_unlock_bh(lock); if (err > 0) { @@ -1068,6 +1073,8 @@ static inline int __rhashtable_replace_fast( spin_lock_bh(lock); pprev = rht_bucket_var(tbl, hash); + if (!pprev) + goto out; rht_for_each_continue(he, *pprev, tbl, hash) { if (he != obj_old) { pprev = &he->next; @@ -1079,7 +1086,7 @@ static inline int __rhashtable_replace_fast( err = 0; break; } - +out: spin_unlock_bh(lock); return err; diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 27a5ffa993d4..7a68c1f0b6d0 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -240,8 +240,10 @@ static int rhashtable_rehash_one(struct rhashtable *ht, unsigned int old_hash) goto out; err = -ENOENT; + if (!pprev) + goto out; - rht_for_each(entry, old_tbl, old_hash) { + rht_for_each_continue(entry, *pprev, old_tbl, old_hash) { err = 0; next = rht_dereference_bucket(entry->next, old_tbl, old_hash); @@ -498,6 +500,8 @@ static void *rhashtable_lookup_one(struct rhashtable *ht, elasticity = RHT_ELASTICITY; pprev = rht_bucket_var(tbl, hash); + if (!pprev) + return ERR_PTR(-ENOENT); rht_for_each_continue(head, *pprev, tbl, hash) { struct rhlist_head *list; struct rhlist_head *plist; @@ -1160,11 +1164,10 @@ void rhashtable_destroy(struct rhashtable *ht) } EXPORT_SYMBOL_GPL(rhashtable_destroy); -struct rhash_head __rcu **rht_bucket_nested(const struct bucket_table *tbl, - unsigned int hash) +struct rhash_head __rcu **__rht_bucket_nested(const struct bucket_table *tbl, + unsigned int hash) { const unsigned int shift = PAGE_SHIFT - ilog2(sizeof(void *)); - static struct rhash_head __rcu *rhnull; unsigned int index = hash & ((1 << tbl->nest) - 1); unsigned int size = tbl->size >> tbl->nest; unsigned int subhash = hash; @@ -1182,15 +1185,23 @@ struct rhash_head __rcu **rht_bucket_nested(const struct bucket_table *tbl, subhash >>= shift; } - if (!ntbl) { - if (!rhnull) - INIT_RHT_NULLS_HEAD(rhnull, NULL, 0); - return &rhnull; - } + if (!ntbl) + return NULL; return &ntbl[subhash].bucket; } +EXPORT_SYMBOL_GPL(__rht_bucket_nested); + +struct rhash_head __rcu **rht_bucket_nested(const struct bucket_table *tbl, + unsigned int hash) +{ + static struct rhash_head __rcu *rhnull; + + if (!rhnull) + INIT_RHT_NULLS_HEAD(rhnull); + return __rht_bucket_nested(tbl, hash) ?: &rhnull; +} EXPORT_SYMBOL_GPL(rht_bucket_nested); struct rhash_head __rcu **rht_bucket_nested_insert(struct rhashtable *ht,