From patchwork Mon Jul 17 18:01:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316145 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 7D3BEC0015E for ; Mon, 17 Jul 2023 18:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbjGQSBP (ORCPT ); Mon, 17 Jul 2023 14:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbjGQSBO (ORCPT ); Mon, 17 Jul 2023 14:01:14 -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 41FB999; Mon, 17 Jul 2023 11:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BAF7E611C3; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2568FC433C8; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=xVhWqN5eTUt3G/KbriOgUta82k5eGkWbLsO5XCSoMTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tM0uuN6VgnjizZ71vBqyLoTzTm8+0MnUxrBU309KsSO1E/YC9yI+2XWOfLkgkoJ8Q HGTEGBgjXuFw5SwUMnEyqajvfyTXVq4hoRiF2TzzMX6ZL/XpLmhvyMN1f28PqqCjoq EqgwgS32IGiLbQrHAbwFrxloDLifJegD1ZfKqq4PRKB7hRQ3ak5JZxh+yvpl40WUCW D5qCwV2p6nB5NW7lwaert+k7Rd8K7PCY6VzJBh5ZSR0r0Cry1U491BLV9B6rIozO+a kx7iGN+9DFtyyv1cpSnlgXbtjdlzNQQvcLIkuZQ6ld4UnVozqebFezZ4FV3tSFTyHY HSKADhFu8ya6Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D11B4CE03F1; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Tycho Andersen , "Paul E . McKenney" Subject: [PATCH rcu 1/7] documentation/rcu: Fix typo Date: Mon, 17 Jul 2023 11:01:04 -0700 Message-Id: <20230717180110.1097362-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: Tycho Andersen s/slat/splat/ Signed-off-by: Tycho Andersen Signed-off-by: Paul E. McKenney --- Documentation/RCU/lockdep-splat.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/RCU/lockdep-splat.rst b/Documentation/RCU/lockdep-splat.rst index 2a5c79db57dc..bcbc4b3c88d7 100644 --- a/Documentation/RCU/lockdep-splat.rst +++ b/Documentation/RCU/lockdep-splat.rst @@ -10,7 +10,7 @@ misuses of the RCU API, most notably using one of the rcu_dereference() family to access an RCU-protected pointer without the proper protection. When such misuse is detected, an lockdep-RCU splat is emitted. -The usual cause of a lockdep-RCU slat is someone accessing an +The usual cause of a lockdep-RCU splat is someone accessing an RCU-protected data structure without either (1) being in the right kind of RCU read-side critical section or (2) holding the right update-side lock. This problem can therefore be serious: it might result in random memory From patchwork Mon Jul 17 18:01:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316146 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 F1F90C001DC for ; Mon, 17 Jul 2023 18:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231163AbjGQSBQ (ORCPT ); Mon, 17 Jul 2023 14:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbjGQSBO (ORCPT ); Mon, 17 Jul 2023 14:01:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3A7E6F; Mon, 17 Jul 2023 11:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D4C50611CA; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36057C433C9; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=DbRDqkDR7+Vdxt3VeUxm8chleSMkPylSYd1qg6TB8zI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QLwBXp7Crfow6M3KYd6+plxls68Ur0fT2Nkdatp/DZbVsRouOnFr70xUb3c/klwIu iTQeflgIKapQD0pB+6zg1GG3TLRV8h5ia2A1KLxkgz9z7fUVVWIzqMo8FnUM798Nvs ZbuxcS0w1aWy1kdI3aIswrMKMvVF1iulD9IhgKVm1p4roahptjOYrgcr/hNxlkmQxW Iftf0F3rrGtRO4y93Si7fcv3oxQV+sVNOBAJa3D3ZGc44/d+Ur0e7ii53kST26ZVwH QVaG9t9pLV+fO40Mykmp40T1/IqNDJNghiVkhh2aQYCtO81VFz8hRlPgYE30GdASqa n51GMMaiPGQ1A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D3F33CE04CD; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Alan Huang , "Paul E . McKenney" Subject: [PATCH rcu 2/7] docs/RCU: Add the missing rcu_read_unlock() Date: Mon, 17 Jul 2023 11:01:05 -0700 Message-Id: <20230717180110.1097362-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: Alan Huang We should exit the RCU read-side critical section before re-entering. Signed-off-by: Alan Huang Signed-off-by: Paul E. McKenney --- Documentation/RCU/rculist_nulls.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 9a734bf54b76..0612a6387d8e 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -29,8 +29,10 @@ algorithms: rcu_read_lock() obj = lockless_lookup(key); if (obj) { - if (!try_get_ref(obj)) // might fail for free objects + if (!try_get_ref(obj)) { // might fail for free objects + rcu_read_unlock(); goto begin; + } /* * Because a writer could delete object, and a writer could * reuse these object before the RCU grace period, we From patchwork Mon Jul 17 18:01:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316147 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 649D5EB64DC for ; Mon, 17 Jul 2023 18:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230364AbjGQSBQ (ORCPT ); Mon, 17 Jul 2023 14:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbjGQSBO (ORCPT ); Mon, 17 Jul 2023 14:01:14 -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 5FBC9E76; Mon, 17 Jul 2023 11:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D961B611CD; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44FACC433C7; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=3M0SpVkyWqfYcXcGZBOE8myfp0f75lb5pDV5D9CsGeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=afXPWLmb4HPEM6fiia71/JKSX40Lvp7TBlcEji2LtAn9S9oRB+ZMODyrPR5gjN7B6 wzJsYdjGlJX9aQsI9GuuEulcxHqfek81LzayTYxTqOfTxlrXmhrDXcstXa07HeDxim SezmFQVm65dlBNQST2StigcXNJiGCMCJXqKiZAaegLT/8uXmHwGT0JbARInUsIk083 ZvSASeRPAjV+HraDMQm7aI37pjiL8tHN6OvlU1RKKgW6I0rnNKfSshRgAOMil5d7a+ BeMlWLDhvc0krR7ouaabAIr3vSoLQFm8ZP4Sgmw44uNa4AVfEY1NCAOqlbarkDOqGG l+AY2Cg4whPWQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D65F4CE0806; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, SeongJae Park , Joel Fernandes , "Paul E . McKenney" Subject: [PATCH rcu 3/7] Docs/RCU/rculist_nulls: Fix trivial coding style Date: Mon, 17 Jul 2023 11:01:06 -0700 Message-Id: <20230717180110.1097362-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: SeongJae Park 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 Reviewed-by: Joel Fernandes (Google) Signed-off-by: Paul E. McKenney --- 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 0612a6387d8e..25b739885cfa 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 @@ -70,8 +70,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 Mon Jul 17 18:01:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316149 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 6FC37C001DF for ; Mon, 17 Jul 2023 18:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbjGQSBR (ORCPT ); Mon, 17 Jul 2023 14:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbjGQSBO (ORCPT ); Mon, 17 Jul 2023 14:01:14 -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 8EBA1115; Mon, 17 Jul 2023 11:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E74FF611CE; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5101BC433CB; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=Y/tGOWx5q4ZXPiE4it7zg9nYO16lZ6O1v/m4xTWMYUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZzwrAmSWJKoFU94kWriauk8IWoBE5TS+HnmT9tykbdY2EHGd4AYQEqu00ysi5aHFl ilwh6BJ0kVhp/tgiuy2qklG84FTHT42EG8indXY6dc4SKsjBRPffbKs+e18ia5PrIc bePSuyefnHyvvqMSMBgyI+vtAnTf4Hfak9p9q+lZYRdv1Dqbaks4EYmmS9t6BHrgvV qfTTWgxs72OwqK6jS+0JYUGn07iRbzAB5m7jaYI+kuQ2rlCASpLmpoDIqfxv0Yq3VD 7UJ+V8ClN6aEQNK70VOvWXDg3rG6EiAAJs70Sczxu4PECyeX7lnsMpUDhnCPWKOmxr B7aU9iDg+nIRQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D8FA2CE0836; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, SeongJae Park , Joel Fernandes , "Paul E . McKenney" Subject: [PATCH rcu 4/7] Docs/RCU/rculist_nulls: Assign 'obj' before use from the examples Date: Mon, 17 Jul 2023 11:01:07 -0700 Message-Id: <20230717180110.1097362-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: SeongJae Park 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 Reviewed-by: Joel Fernandes (Google) Signed-off-by: Paul E. McKenney --- 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 25b739885cfa..4d6f077552ed 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -56,7 +56,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; @@ -68,7 +68,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 Mon Jul 17 18:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316150 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 72505C0015E for ; Mon, 17 Jul 2023 18:01:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231251AbjGQSBS (ORCPT ); Mon, 17 Jul 2023 14:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbjGQSBO (ORCPT ); Mon, 17 Jul 2023 14:01:14 -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 905DB1BE; Mon, 17 Jul 2023 11:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 01F90611D0; Mon, 17 Jul 2023 18:01:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F51CC43395; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=4H5bZcoG+0w9ieEzeSthnT4nJRX8tO6DLkfwj3Il66k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rtpKCZlN+OtkLZWQbdGg9iStTUBMHDho2PwBrOUbZSOew1cdg8FOlMwI0GwnMv+tS nnUt0ZsWRL5IT44W+fBP/BZ/ADUc357QMvZSIaidaBQTrSJjdvMz9sAODwhcQYIOHv D7e5e/tiNMmgsa6re/QAfAaxbR8HHYneBYbCjsI6Br4AKPCXEHg+3cWAplYD9rJ39M 8eXnV4hN5LBFzDTdmIV5EBUnN8CA+nodzVQJCs7spfpz/+z6gyPnxDz72Nic5SOutF U6x/zFnIBBk/aaKhZn4uO9SUHAy/c9J39JJv40P0p78cGAygMUV/Gl8PSL6tTiB8rs Ha4qMnoHLjPZQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DB19BCE0902; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, SeongJae Park , "Paul E . McKenney" Subject: [PATCH rcu 5/7] Docs/RCU/rculist_nulls: Specify type of the object in examples Date: Mon, 17 Jul 2023 11:01:08 -0700 Message-Id: <20230717180110.1097362-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: SeongJae Park The type of 'obj' in example code of rculist_nulls.rst is implicit. Provide the specific type of it before the example code. Suggested-by: Paul E. McKenney Link: https://lore.kernel.org/rcu/43943609-f80c-4b6a-9844-994eef800757@paulmck-laptop/ Signed-off-by: SeongJae Park Signed-off-by: Paul E. McKenney --- Documentation/RCU/rculist_nulls.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 4d6f077552ed..479cedfec446 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -18,7 +18,16 @@ to solve following problem. Without 'nulls', a typical RCU linked list managing objects which are allocated with SLAB_TYPESAFE_BY_RCU kmem_cache can use the following -algorithms: +algorithms. Following examples assume 'obj' is a pointer to such +objects, which is having below type. + +:: + + struct object { + struct hlist_node obj_node; + atomic_t refcnt; + unsigned int key; + }; 1) Lookup algorithm ------------------- @@ -144,6 +153,9 @@ the beginning. If the object was moved to the same chain, then the reader doesn't care: It might occasionally scan the list again without harm. +Note that using hlist_nulls means the type of 'obj_node' field of +'struct object' becomes 'struct hlist_nulls_node'. + 1) lookup algorithm ------------------- From patchwork Mon Jul 17 18:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316151 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 DF3C7C001DE for ; Mon, 17 Jul 2023 18:01:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231250AbjGQSBT (ORCPT ); Mon, 17 Jul 2023 14:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbjGQSBP (ORCPT ); Mon, 17 Jul 2023 14:01:15 -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 B38EB10C7; Mon, 17 Jul 2023 11:01:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 56611611D4; Mon, 17 Jul 2023 18:01:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81611C433A9; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=vMU/XgK+8/tyV/dKBByzpBIuwOGp8w97JCzbfLX+ZeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9PPHQZiElIu01MSdWkSAMWPCHtk3+ULIDkRUtTy+2KSA4s50662trJuB+lhQlESi 6yImgsJSej19sc8OrrtpAlUsnkBaPz1Lu4p33NvTC3l5VhC3z0Ki2wN0lVlEueJ8BT y1HHhmXwV2PEB65Xzt/2EcMVOJKgD3DPo2PVMp8FBTt9IC0lVpubSaZoFJFkd0w1Td EEnAfNjZhqYu/iR1d/b/1+L4yXRRjULLr7IApvLNZzGwG8Hlo9iARtupoykSmcOSEM 5rhY5kUujZybVuRJa3BAr3coH8hkC0f25wkqyjJ2J21Z5oUK5y5erARLAtsm3XiimC 3duUJiqkDYsZw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DD2EECE092F; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, SeongJae Park , "Paul E . McKenney" Subject: [PATCH rcu 6/7] Docs/RCU/rculist_nulls: Fix hlist_[nulls]_head field names of 'obj' Date: Mon, 17 Jul 2023 11:01:09 -0700 Message-Id: <20230717180110.1097362-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: SeongJae Park The example code snippets on rculist_nulls.rst are assuming 'obj' to have the 'hlist_head' or 'hlist_nulls_head' field named 'obj_node', but a sentence and some code snippets are wrongly calling 'obj->obj_node.next' as 'obj->obj_next', or 'obj->obj_node' as 'member'. Fix it. Signed-off-by: SeongJae Park Signed-off-by: Paul E. McKenney --- Documentation/RCU/rculist_nulls.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 479cedfec446..1fb086066377 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -65,7 +65,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; }) && - ({ obj = hlist_entry(pos, typeof(*obj), member); 1; }); + ({ obj = hlist_entry(pos, typeof(*obj), obj_node); 1; }); pos = rcu_dereference(next)) if (obj->key == key) return obj; @@ -77,7 +77,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; }) && - ({ obj = hlist_entry(pos, typeof(*obj), member); 1; }); + ({ obj = hlist_entry(pos, typeof(*obj), obj_node); 1; }); pos = rcu_dereference(pos->next)) if (obj->key == key) return obj; @@ -97,7 +97,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 @@ -165,7 +165,7 @@ Note that using hlist_nulls means the type of 'obj_node' field of head = &table[slot]; begin: rcu_read_lock(); - hlist_nulls_for_each_entry_rcu(obj, node, head, member) { + hlist_nulls_for_each_entry_rcu(obj, node, head, obj_node) { if (obj->key == key) { if (!try_get_ref(obj)) { // might fail for free objects rcu_read_unlock(); From patchwork Mon Jul 17 18:01:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13316148 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 CED66C001E0 for ; Mon, 17 Jul 2023 18:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231224AbjGQSBR (ORCPT ); Mon, 17 Jul 2023 14:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbjGQSBP (ORCPT ); Mon, 17 Jul 2023 14:01:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B37FEE6C; Mon, 17 Jul 2023 11:01:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5737F611D5; Mon, 17 Jul 2023 18:01:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F604C433AD; Mon, 17 Jul 2023 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689616872; bh=xfeG1xbltoTNTdzL3NqsELbTv/pa9FZB5bRq1zF+OuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rYV63FMskzWxOynzItXA45uVGlpO3lupAQaIN8axaEuksbv960TRV2h2o3luJZuLB ylpn6KwLy/bs8SfIVknVOgKv8FSWLf6x2t3tGV90Et5z3obUQEhd0PB+5r8q8Q20gT 1U0pEZlKNIDmCcFQLNI1rc9YmIJxMlQlkau6jGm4gpBmx7EA9jmXCgspiaiH6ADrL/ jFtZTpIFTVLrjZMIEkbzCf4+E3Dwzr8yrCe2E2B2XMwJmf3H6bobh2FTgoEvXFpQBh U8F2eFEoBpz52Vc2H1mZahNNCwyysN3SBwdKXiXbv1PKzPNT2lusiHhW8zsUDj8+HT Txi7v1wuTyKrg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DF4D9CE0930; Mon, 17 Jul 2023 11:01:11 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, SeongJae Park , "Paul E . McKenney" Subject: [PATCH rcu 7/7] Docs/RCU/rculist_nulls: Fix text about atomic_set_release() Date: Mon, 17 Jul 2023 11:01:10 -0700 Message-Id: <20230717180110.1097362-7-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: SeongJae Park The document says we can avoid extra _release() in insert function when hlist_nulls is used, but that's not true[1]. Drop it. [1] https://lore.kernel.org/rcu/46440869-644a-4982-b790-b71b43976c66@paulmck-laptop/ Signed-off-by: SeongJae Park Signed-off-by: Paul E. McKenney --- Documentation/RCU/rculist_nulls.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/RCU/rculist_nulls.rst b/Documentation/RCU/rculist_nulls.rst index 1fb086066377..21e40fcc08de 100644 --- a/Documentation/RCU/rculist_nulls.rst +++ b/Documentation/RCU/rculist_nulls.rst @@ -140,8 +140,7 @@ very very fast (before the end of RCU grace period) Avoiding extra smp_rmb() ======================== -With hlist_nulls we can avoid extra smp_rmb() in lockless_lookup() -and extra _release() in insert function. +With hlist_nulls we can avoid extra smp_rmb() in lockless_lookup(). For example, if we choose to store the slot number as the 'nulls' end-of-list marker for each slot of the hash table, we can detect @@ -196,6 +195,9 @@ Note that using hlist_nulls means the type of 'obj_node' field of 2) Insert algorithm ------------------- +Same to the above one, but uses hlist_nulls_add_head_rcu() instead of +hlist_add_head_rcu(). + :: /*