From patchwork Thu May 18 22:40:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13247482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E31CC7EE30 for ; Thu, 18 May 2023 22:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbjERWkV (ORCPT ); Thu, 18 May 2023 18:40:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbjERWkU (ORCPT ); Thu, 18 May 2023 18:40:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51E6E6E; Thu, 18 May 2023 15:40:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 82A1E65290; Thu, 18 May 2023 22:40:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A613C433A8; Thu, 18 May 2023 22:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684449619; bh=SJxI8K9C2w5GlQmZqTJRQSZCMc1JRXWEVEA8cvqdWaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AhW0Cn0f1RevzDaWU0j6r2dq/quj3SUeeEW9Q9uD+27BTcyCxAb8DWP1oDoUuMmXw 7ggKr9g+nTi86Tpgg7dH1+pt+DGTN11r3tG+SXLNV6vQrRBNH7WNq/SrCE1TKXwsMU Adz0O/wz/WwiebYlIBVbmv7NPVkv5x9/gLFBHYBgdcAfW7ZThG9JqZFxL6ucL4u9nI K4Saj11CePhstbNsuvKC6qqEhRwOvzhxXj2bfPFN0cfN5mcXh6f1dnHDuT0lKoZ1Uw 468aEX5WhFycuC7x24O6V3IQgfcdhGg4/u4Bk85AWG9IdvvvL0ihojMMoW2FSxfvET xxvGip7ZvV0PA== From: SeongJae Park To: paulmck@kernel.org Cc: SeongJae Park , joel@joelfernandes.org, corbet@lwn.net, rcu@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] Docs/RCU/rculist_nulls: Fix trivial coding style Date: Thu, 18 May 2023 22:40:05 +0000 Message-Id: <20230518224008.2468-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518224008.2468-1-sj@kernel.org> References: <20230518224008.2468-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org Lookup example of non-hlist_nulls management is missing a semicolon, and having inconsistent indentation (one line is using single space indentation while others are using two spaces indentation). Fix the trivial issues. Signed-off-by: SeongJae Park --- Documentation/RCU/rculist_nulls.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 9a734bf54b76..253ecd869fc2 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -26,7 +26,7 @@ algorithms: :: begin: - rcu_read_lock() + rcu_read_lock(); obj = lockless_lookup(key); if (obj) { if (!try_get_ref(obj)) // might fail for free objects @@ -68,8 +68,8 @@ And note the traditional hlist_for_each_entry_rcu() misses this smp_rmb():: pos && ({ prefetch(pos->next); 1; }) && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); pos = rcu_dereference(pos->next)) - if (obj->key == key) - return obj; + if (obj->key == key) + return obj; return NULL; Quoting Corey Minyard:: From patchwork Thu May 18 22:40:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13247483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55F14C7EE37 for ; Thu, 18 May 2023 22:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbjERWkW (ORCPT ); Thu, 18 May 2023 18:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbjERWkV (ORCPT ); Thu, 18 May 2023 18:40:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80D1E61; Thu, 18 May 2023 15:40:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3D876652B3; Thu, 18 May 2023 22:40:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E33EC433A0; Thu, 18 May 2023 22:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684449619; bh=pru6AOR5Vm1jRjLusfcHlb0JB0ZcJOquRSj2dOKmD7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gvGqlzOd1Ed6Aksnz0b7RZ42saJtCqIni0wD7N022+7SqFUL2WJ5+nCSFqE19Fe8M JxhPHeidqqtUOLRzsy15e84LHkHlVga9S3F4s9x0tgA3HI5bOSN4ZawZ8PPnuuaU0C Z8Vo3d3bD7zYiMLX36XnTbTKr0a/q+GLJD2HxAECbKKV3of+nqHTsxgecCJ7vf9UYY 7AiImHhPV1Mf6JrxN16OrL4VFTd7d95wc1cjkChLXcd79xN9T9F5FSJZvQ34WEupKQ NJTbA69wTNwn7qsNNfVR1Tm3drppRIJVwOnibRgou/d5KLAeBwVXeCBIYfH+wcV2Pq KTVEsWfPPaUbA== From: SeongJae Park To: paulmck@kernel.org Cc: SeongJae Park , joel@joelfernandes.org, corbet@lwn.net, rcu@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] Docs/RCU/rculist_nulls: Assign 'obj' before use from the examples Date: Thu, 18 May 2023 22:40:06 +0000 Message-Id: <20230518224008.2468-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518224008.2468-1-sj@kernel.org> References: <20230518224008.2468-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org Lookup example code snippets in rculist_nulls.rst are using 'obj' without assignment. Fix the code to assign it properly. Signed-off-by: SeongJae Park --- Documentation/RCU/rculist_nulls.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 253ecd869fc2..94a8bfe9f560 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -54,7 +54,7 @@ but a version with an additional memory barrier (smp_rmb()) struct hlist_node *node, *next; for (pos = rcu_dereference((head)->first); pos && ({ next = pos->next; smp_rmb(); prefetch(next); 1; }) && - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); + ({ obj = hlist_entry(pos, typeof(*obj), member); 1; }); pos = rcu_dereference(next)) if (obj->key == key) return obj; @@ -66,7 +66,7 @@ And note the traditional hlist_for_each_entry_rcu() misses this smp_rmb():: struct hlist_node *node; for (pos = rcu_dereference((head)->first); pos && ({ prefetch(pos->next); 1; }) && - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); + ({ obj = hlist_entry(pos, typeof(*obj), member); 1; }); pos = rcu_dereference(pos->next)) if (obj->key == key) return obj; From patchwork Thu May 18 22:40:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13247485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 966CBC7EE43 for ; Thu, 18 May 2023 22:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230519AbjERWkY (ORCPT ); Thu, 18 May 2023 18:40:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjERWkW (ORCPT ); Thu, 18 May 2023 18:40:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6249AE64; Thu, 18 May 2023 15:40:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E48BB638BE; Thu, 18 May 2023 22:40:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8F0CC4339B; Thu, 18 May 2023 22:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684449620; bh=fecc2OUGYvaY7HhyWoq5AoCd5a8aYFQhBEm7VND8WRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P18tjltVWhrWdAx/t73MdYzudw5rAwtcgHmB/MnIe2y6gVDckQF6FTRGLFg5731sU JE8gbMwtGGjpyk1PixlH1id+rzzkUnMY7HfZjyVRsUV1HP8FnjtWswBasnQXpAHtsp 6ir0BbvnOUsku7PcQI00Gs+RbQmLmmpQ14v5cqILduXW0oWTIcegiWs1T0oDdXfgZi R27bwO9Bwj80Phs8CAWxV7dquax9Pk2BNtHDLSFke/1Fc6SO/V6pXockfnzEc//t3D Kew9iJOBJow0x/qHQ/A+sccnynoNIEtq3gnQjfqjzmQxlnKsu4mtFw4A96Ynsalyfq U++W4rKV2PkHQ== From: SeongJae Park To: paulmck@kernel.org Cc: SeongJae Park , joel@joelfernandes.org, corbet@lwn.net, rcu@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] Docs/RCU/rculist_nulls: Fix hlist_head field name of 'obj' Date: Thu, 18 May 2023 22:40:07 +0000 Message-Id: <20230518224008.2468-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518224008.2468-1-sj@kernel.org> References: <20230518224008.2468-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org The example code snippets on rculist_nulls.rst are assuming 'obj' to have the 'hlist_head' field named 'obj_node', but a sentence is wrongly mentioning 'obj->obj_node.next' as 'obj->obj_next'. Fix it. Signed-off-by: SeongJae Park --- Documentation/RCU/rculist_nulls.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 94a8bfe9f560..5cd6f3f8810f 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -86,7 +86,7 @@ Quoting Corey Minyard:: 2) Insertion algorithm ---------------------- -We need to make sure a reader cannot read the new 'obj->obj_next' value +We need to make sure a reader cannot read the new 'obj->obj_node.next' value and previous value of 'obj->key'. Otherwise, an item could be deleted from a chain, and inserted into another chain. If new chain was empty before the move, 'next' pointer is NULL, and lockless reader can not From patchwork Thu May 18 22:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13247484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB1B1C7EE2E for ; Thu, 18 May 2023 22:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbjERWkX (ORCPT ); Thu, 18 May 2023 18:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbjERWkW (ORCPT ); Thu, 18 May 2023 18:40:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5D08E6E; Thu, 18 May 2023 15:40:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 96DFB65290; Thu, 18 May 2023 22:40:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D96CC4339C; Thu, 18 May 2023 22:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684449621; bh=mYcPMMrN9V5gypfz26UfLD+vMchASHDokjM0vkhV+Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ucL2a7MgZPPqtpXsUTgCswQPPRnexmjCSgdKfPjcP9HjKQ6yaF9WpZbAaPDPjRry9 3uskc28qepqVcPcSg1/M6GwpDedvHESb98wt74Sc+YnspeuSz6Yrmxws30HPnO5JjU XeOTyqZqf7wyLLYouBMz2jaJogzjHzMsmpq86e1WDoOii2tmUpLux40hFMBQaZKbYI Yw+ze0IEjJfdpQYuqXX4HaY/DxINFLsl2Xn7PC18tHnClFpWIvbj2voBBQKBpDOMiA iV6xC4AZkXsJmSzoczNly6SzZXlp7oWaiDzHmxbOY1+I5BkiuyXXxDMTKHuRuWD8/l 0T3wu7dtCsPOQ== From: SeongJae Park To: paulmck@kernel.org Cc: SeongJae Park , joel@joelfernandes.org, corbet@lwn.net, rcu@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] Docs/RCU/rculist_nulls: Drop unnecessary '_release' in insert function Date: Thu, 18 May 2023 22:40:08 +0000 Message-Id: <20230518224008.2468-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518224008.2468-1-sj@kernel.org> References: <20230518224008.2468-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org The document says we can avoid extra smp_rmb() in lockless_lookup() and extra _release() in insert function when hlist_nulls is used. However, the example code snippet for the insert function is still using the extra _release(). Drop it. Signed-off-by: SeongJae Park Reviewed-by: Joel Fernandes (Google) --- Documentation/RCU/rculist_nulls.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 5cd6f3f8810f..463270273d89 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -191,7 +191,7 @@ scan the list again without harm. obj = kmem_cache_alloc(cachep); lock_chain(); // typically a spin_lock() obj->key = key; - atomic_set_release(&obj->refcnt, 1); // key before refcnt + atomic_set(&obj->refcnt, 1); /* * insert obj in RCU way (readers might be traversing chain) */