Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7223415rwp; Tue, 18 Jul 2023 11:55:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlF0IaOfVqK3PTs0vha+ykPzwWmRrNWgihSEoKrsTWEG3HELoS74UNp6IYFjxsxQzkvbQCM9 X-Received: by 2002:a05:6a00:2d1b:b0:66f:3fc5:6167 with SMTP id fa27-20020a056a002d1b00b0066f3fc56167mr532983pfb.1.1689706501533; Tue, 18 Jul 2023 11:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689706501; cv=none; d=google.com; s=arc-20160816; b=xYv4JpgCVElTS05aT8VQXFvLapkbB3cSxp0tZDmWSAm1wqmc/+H7v3FlFQuzZXs+1I /luud3JGmI/uKX1R3o1Pau9d/DqTavio9MKKBp9XfH99D7HPgz/MpWuZqIE3PYYyoRgL qXQK62+4t+306aW5xR0NyyTxLM1oZJPk53RBemAJDTg5do/50ZkkCxque/wVqQ8YDmAZ 8vdqepxB14cM7FOykrr3WG8oHjQrG2WH3ZrhZcgEUW/okhs1IJNVrfThLvQXtbrYDrEF hSDSj2HZcziOSA9viN7d2LAdl9VRjVbOWhD6bz+W4Ryu8Irm8gvjPHwKdGSCeYmrocrz LrZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=LT9AeJxUUBvJiaM3WRsYjSBS+zpYI3zyNJR9Khz1/B8=; fh=PmzLqzgvjbzuhhohJoUNTSiO8CfYzOFvcfaP19itSYc=; b=pO91s1cHdIKLfOpmPHd9H8Ucxy+2aFN98qarb0gQgjgOU/IgpK09EReUql/ne3I5so mrYaILnMUwwfUpMKUGAGTx4PAI31zs3UraE5fLkEjQz1rkGunKg6XoxwdKfhU6lqCG3T oioEia6i7bofBJqWFZMnfLQxq9Q5BhI/2tc3P8+LSnQFFCNya1lLNC0REgRJL4RJtffm PYtBSTqNn6/d2GMeFKw2AY1axxGiDe4qb44bduTgJp/G1b9xYUXOZNf6GwRTpg0WQJP7 XTqa2Mna1hUrW8Rna+wDewllWqjPvJIUM4XQxNU/8PCEK5N/fZQCbxunWU9ORj32snKe WThQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J83MPQUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a056a0023c400b0065addb172d1si1966063pfc.380.2023.07.18.11.54.48; Tue, 18 Jul 2023 11:55:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J83MPQUN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbjGRScF (ORCPT + 99 others); Tue, 18 Jul 2023 14:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbjGRScD (ORCPT ); Tue, 18 Jul 2023 14:32:03 -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 C1473F0; Tue, 18 Jul 2023 11:32:02 -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 33A0D61653; Tue, 18 Jul 2023 18:32:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DE9BC433C7; Tue, 18 Jul 2023 18:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689705121; bh=l8baMBxLHo8xo/gePwxWBpJyf65ETLy32ieqmnFWIWA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=J83MPQUNKBD+OnvqW/hkocKgtvizr6JsNsiLnkizdxB0+jwAXkqM3ERcS7JlE3em+ I2+f+hjqkN0ANtwk1e4MNsAV7vLEqMqKQ6hvZvs5A9fEETMoHisu4/yYAb18wBM3rD KKvl8SPSI6T0QKbXuq2cRC+cOQOVYQeGOcY8Q4bJ8x5s5MUFMmEaeheBKBxyPFZ+dc InUwbFSzOgrB2xy+RFMBRAbpOe3XwxvJFCNfOWT7UmFF0iy0sXsUKUGSogFLexTARW 9UaaTlk7heJBf3Wbzkai3VNHJ9VlpF3u08YwiG4yng/PSSlqrBAdVdchadjLsQiGva 7+1ckpQY9VMNA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2D0BCCE04CD; Tue, 18 Jul 2023 11:32:01 -0700 (PDT) Date: Tue, 18 Jul 2023 11:32:01 -0700 From: "Paul E. McKenney" To: Alan Huang Cc: Joel Fernandes , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org Subject: Re: [PATCH rcu 6/6] rcu: Use WRITE_ONCE() for assignments to ->next for rculist_nulls Message-ID: <3f6b04b3-af22-49f0-8d3c-269640f9f762@paulmck-laptop> Reply-To: paulmck@kernel.org References: <6127192c-da9b-4599-9738-6e8f92e6c75c@paulmck-laptop> <20230717180317.1097590-6-paulmck@kernel.org> <9651c3b4-0791-5cd7-567f-f65d28bc8fae@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 18, 2023 at 10:48:07PM +0800, Alan Huang wrote: > > > 2023年7月18日 21:49,Joel Fernandes 写道: > > > > On 7/17/23 14:03, Paul E. McKenney wrote: > >> From: Alan Huang > >> When the objects managed by rculist_nulls are allocated with > >> SLAB_TYPESAFE_BY_RCU, old readers may still hold references to an object > >> even though it is just now being added, which means the modification of > >> ->next is visible to readers. This patch therefore uses WRITE_ONCE() > >> for assignments to ->next. > >> Signed-off-by: Alan Huang > >> Signed-off-by: Paul E. McKenney > > > > Did we ever conclude that the READ_ONCE() counterparts were not needed? ;-) > > Read-side is already protected by rcu_dereference_raw() in hlist_nulls_for_each_entry_{rcu, safe}. It turns out that different traversal synchronization designs want different pointers using WRITE_ONCE(). > > But incremental progress and all, so this LGTM: > > Reviewed-by: Joel Fernandes (Google) I will apply all four on my next rebase, thank you! Thanx, Paul > > thanks, > > > > - Joel > > > > > >> --- > >> include/linux/rculist_nulls.h | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> diff --git a/include/linux/rculist_nulls.h b/include/linux/rculist_nulls.h > >> index ba4c00dd8005..89186c499dd4 100644 > >> --- a/include/linux/rculist_nulls.h > >> +++ b/include/linux/rculist_nulls.h > >> @@ -101,7 +101,7 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n, > >> { > >> struct hlist_nulls_node *first = h->first; > >> - n->next = first; > >> + WRITE_ONCE(n->next, first); > >> WRITE_ONCE(n->pprev, &h->first); > >> rcu_assign_pointer(hlist_nulls_first_rcu(h), n); > >> if (!is_a_nulls(first)) > >> @@ -137,7 +137,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n, > >> last = i; > >> if (last) { > >> - n->next = last->next; > >> + WRITE_ONCE(n->next, last->next); > >> n->pprev = &last->next; > >> rcu_assign_pointer(hlist_nulls_next_rcu(last), n); > >> } else { > > >