Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2878890img; Sun, 24 Mar 2019 22:07:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfEtVqBFwpZa2sQkbdD/NnGQF5WoUbv8v2iUP1jZOzWoxzvFddEYZAn9V24bnk5NMmUl7I X-Received: by 2002:a63:1060:: with SMTP id 32mr21607494pgq.126.1553490440113; Sun, 24 Mar 2019 22:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553490440; cv=none; d=google.com; s=arc-20160816; b=ZKSTk2l8SFW+f+i8JA2XvRl4bKn+tNTMfRnGeAQ4XctsM1deipaCLT8TzySPItuAuD 9belzHcZxgYBHb6xGpdefDcYcm8FOmLne4rLmdyuDjSS0EMLjGa6Wle2C/YRxY6/Y3Zv 5CHlrESQHXhuHDDd6tQLmADpmsWCo63xl5ouBMA4HN1CMkQJCeGMZwraqvEA6SAF8KxS Wn/uwpHLqhCSCOUCCkGV/hUQNQ8bH3XxD2JORPX7g/3/y4wRYvKLXDDapFIu+veZXfwi KZSe3OZ6dvCvM4LVXjSl2pNljROKAl+pynlA1k+aoQebQPeO8ztDTIFVbUQSGRhuv6Py oaHw== 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=SIIdWmVkSFDkTmlo0oijw7QfcSYjvMotNH3ZH8/Zs/c=; b=BBAeBrhKgzkXoWiOk0+BR11IBslBunoQ1IlZE/pMNEdtUTQvkKKItNlqEVnTv+oFOr kWa5y4Ibbwa1hW6FAEGYDJa8oe+infKmSabeQGrpnIEFAxLA+E1i8cHs0V9ydxy0BCL/ ZF00h6ZrNVVEgUYIxl2wYX8FguKEkSmiMJ1A0as3JQM35iQcpCSfR7+Nzcjnae3hHP64 9hCeGBZGrDM7V89SUaVC9EtBrvKyPXFvWVmD8yVh7ZLinNsNQMFr9ccoS40Xubb/F4aS HH3SMfBcG7YKUP7cW2yMG/HdXlUleWuyONBtLeDryZ1LtJjBDpNX7ng51bRg/fqtGnRc mLww== 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 x6si12425820pgr.372.2019.03.24.22.07.04; Sun, 24 Mar 2019 22:07:20 -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 S1729440AbfCYFGU (ORCPT + 99 others); Mon, 25 Mar 2019 01:06:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:42568 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726101AbfCYFGT (ORCPT ); Mon, 25 Mar 2019 01:06:19 -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 40454AC61; Mon, 25 Mar 2019 05:06:17 +0000 (UTC) From: NeilBrown To: Thomas Graf , Herbert Xu Date: Mon, 25 Mar 2019 16:05:39 +1100 Subject: [PATCH 2/4] rhashtable: allow rht_bucket_var to return NULL. Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <155349033957.1111.16505338697791203910.stgit@noble.brown> In-Reply-To: <155349021177.1111.15681654355431465791.stgit@noble.brown> References: <155349021177.1111.15681654355431465791.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 Rather than returning a pointer to 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. This change involves introducing __rht_bucket_nested() which is like rht_bucket_nested(), but doesn't provide the static nulls, and changing rht_bucket_nested() to call this and possible provide a static nulls - as is still needed for the non-var case. 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 86dfa417848d..0c9175aeab8a 100644 --- a/include/linux/rhashtable.h +++ b/include/linux/rhashtable.h @@ -265,6 +265,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); @@ -294,7 +296,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]; } @@ -890,6 +892,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_from(he, *pprev, tbl, hash) { struct rhlist_head *list; @@ -934,6 +938,7 @@ static inline int __rhashtable_remove_fast_one( break; } +out: spin_unlock_bh(lock); if (err > 0) { @@ -1042,6 +1047,8 @@ static inline int __rhashtable_replace_fast( spin_lock_bh(lock); pprev = rht_bucket_var(tbl, hash); + if (!pprev) + goto out; rht_for_each_from(he, *pprev, tbl, hash) { if (he != obj_old) { pprev = &he->next; @@ -1053,7 +1060,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 afe01a5048d7..e3b726bf2dd3 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -237,8 +237,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_from(entry, *pprev, old_tbl, old_hash) { err = 0; next = rht_dereference_bucket(entry->next, old_tbl, old_hash); @@ -492,6 +494,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_from(head, *pprev, tbl, hash) { struct rhlist_head *list; struct rhlist_head *plist; @@ -1157,11 +1161,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; @@ -1179,15 +1182,23 @@ struct rhash_head __rcu **rht_bucket_nested(const struct bucket_table *tbl, subhash >>= shift; } - if (!ntbl) { - if (!rhnull) - INIT_RHT_NULLS_HEAD(rhnull); - 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,