Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp248490imj; Thu, 7 Feb 2019 03:47:32 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib3XJtSTh6MYc+ABJmSjFzgFgpjhxTS8kxATeSBGzKmC5mfYcvKHHz7VGLruPu1m7M7ktk/ X-Received: by 2002:a17:902:28aa:: with SMTP id f39mr16087475plb.297.1549540052658; Thu, 07 Feb 2019 03:47:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549540052; cv=none; d=google.com; s=arc-20160816; b=KiISNH4Ve7Hmv5DZ8CzIo+bB+qdKxiEvyM9irDw8gbwt1Kt0cSzs9+qNGESUaaQQNG Zu9f9YMi49rio/lIhpjYXkpTto4bXZYENl/TBv5lXMi10Zz30nfioVFLLgd42qv6I6KU 5IpipzQwiR0c0ryLrfNhD8V4ZbJInlwhU79FnF/LSU1m1OVWIKSupgzs5TqTOor4OjVN zeE2Lfe74N3eKR5cgSVWrdAjpu2BM01pYj4jm19QzBLGItQCHtdbipflQFq3O7igT3A4 bcbcGb5JULaliVZMXug8SFYP9ODKbjlf/qDUNDLKzeQaeHbgeKH3rfX7dU7hE7g8l5uw qLtg== 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:date:subject:cc:to :from:dkim-signature; bh=NsGkVfdq0O/3/WcYYGm3GrpbWTNulnGoHgAx9VkNKiM=; b=Jsrm6X/pS4CXI7TmPn8TyJx9hsZAXvoWVqhNFa19+pTj3ugS2kx9intLcgblfl3kaR 2C40Rk/L9QDx1IVUrIlOjEnkeuE09FQaTtifhjuRiLnxyMkx/0Vnpdk5GGAGkdy5IHug wctOuMVMiZWG8aErt849PR1WAvEYcgFJtjSeeXeTRn1Af2rfU0mAMuhRzZl7MXa9LEzg VwmEGIy17++rjrLJvMv5uawzMmHdMWvT/KrU0Y7pstN+17SN1fCv4M8Z2rarlHrSi7jn LEB47LDHtZTLs0OJWXePNesNFmFqOZ4Z6aRRCndRzlINxFJK++DhZTYA1GsREqhuHx6P Cbzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WcCl4Uup; 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 m86si1609001pfi.160.2019.02.07.03.47.16; Thu, 07 Feb 2019 03:47:32 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=WcCl4Uup; 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 S1726769AbfBGLmu (ORCPT + 99 others); Thu, 7 Feb 2019 06:42:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:32842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727169AbfBGLmr (ORCPT ); Thu, 7 Feb 2019 06:42:47 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D3E1521904; Thu, 7 Feb 2019 11:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549539766; bh=y3xO+55gmNe1NrAVJwR1K04JdKUiOqRM7gd7WXTxsao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WcCl4UupAceCIhxRW4w73T5kGFwPup+84KFU04VbdFZisuv7lwWCBkdKaRH5vIOW4 qdT3m/uQtWtkcBQiFwxRPQc25H8JRUj46HhvJwOK5+0/TKdVIuVpAS+Jitnisobpv8 7x+q3VZT2BhyAVhKQH+EhLM5FRSwqqnr68U8deyk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Herbert Xu , Ben Hutchings Subject: [PATCH 4.4 07/34] rhashtable: Add rhashtable_lookup() Date: Thu, 7 Feb 2019 12:41:49 +0100 Message-Id: <20190207113025.851245215@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207113025.552605181@linuxfoundation.org> References: <20190207113025.552605181@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ben Hutchings Extracted from commit ca26893f05e8 "rhashtable: Add rhlist interface". Cc: Herbert Xu Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/rhashtable.h | 69 +++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 17 deletions(-) --- a/include/linux/rhashtable.h +++ b/include/linux/rhashtable.h @@ -515,18 +515,8 @@ static inline int rhashtable_compare(str return memcmp(ptr + ht->p.key_offset, arg->key, ht->p.key_len); } -/** - * rhashtable_lookup_fast - search hash table, inlined version - * @ht: hash table - * @key: the pointer to the key - * @params: hash table parameters - * - * Computes the hash value for the key and traverses the bucket chain looking - * for a entry with an identical key. The first matching entry is returned. - * - * Returns the first entry on which the compare function returned true. - */ -static inline void *rhashtable_lookup_fast( +/* Internal function, do not use. */ +static inline struct rhash_head *__rhashtable_lookup( struct rhashtable *ht, const void *key, const struct rhashtable_params params) { @@ -538,8 +528,6 @@ static inline void *rhashtable_lookup_fa struct rhash_head *he; unsigned int hash; - rcu_read_lock(); - tbl = rht_dereference_rcu(ht->tbl, ht); restart: hash = rht_key_hashfn(ht, tbl, key, params); @@ -548,8 +536,7 @@ restart: params.obj_cmpfn(&arg, rht_obj(ht, he)) : rhashtable_compare(&arg, rht_obj(ht, he))) continue; - rcu_read_unlock(); - return rht_obj(ht, he); + return he; } /* Ensure we see any new tables. */ @@ -558,11 +545,59 @@ restart: tbl = rht_dereference_rcu(tbl->future_tbl, ht); if (unlikely(tbl)) goto restart; - rcu_read_unlock(); return NULL; } +/** + * rhashtable_lookup - search hash table + * @ht: hash table + * @key: the pointer to the key + * @params: hash table parameters + * + * Computes the hash value for the key and traverses the bucket chain looking + * for a entry with an identical key. The first matching entry is returned. + * + * This must only be called under the RCU read lock. + * + * Returns the first entry on which the compare function returned true. + */ +static inline void *rhashtable_lookup( + struct rhashtable *ht, const void *key, + const struct rhashtable_params params) +{ + struct rhash_head *he = __rhashtable_lookup(ht, key, params); + + return he ? rht_obj(ht, he) : NULL; +} + +/** + * rhashtable_lookup_fast - search hash table, without RCU read lock + * @ht: hash table + * @key: the pointer to the key + * @params: hash table parameters + * + * Computes the hash value for the key and traverses the bucket chain looking + * for a entry with an identical key. The first matching entry is returned. + * + * Only use this function when you have other mechanisms guaranteeing + * that the object won't go away after the RCU read lock is released. + * + * Returns the first entry on which the compare function returned true. + */ +static inline void *rhashtable_lookup_fast( + struct rhashtable *ht, const void *key, + const struct rhashtable_params params) +{ + void *obj; + + rcu_read_lock(); + obj = rhashtable_lookup(ht, key, params); + rcu_read_unlock(); + + return obj; +} + /* Internal function, please use rhashtable_insert_fast() instead. This * function returns the existing element already in hashes in there is a clash, * otherwise it returns an error via ERR_PTR().