Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16091055rwd; Mon, 26 Jun 2023 05:46:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4biRkBUxJiKcNJXCWHnCFU87Vtn013tuVbUbD4o5Ugsz6ep9rzEzIe322UKmjiqKl58wKV X-Received: by 2002:a2e:9c07:0:b0:2b4:6ca3:7747 with SMTP id s7-20020a2e9c07000000b002b46ca37747mr15302220lji.28.1687783580771; Mon, 26 Jun 2023 05:46:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687783580; cv=none; d=google.com; s=arc-20160816; b=YOW+rq/+/JdYx1w5tT2+Q6LjI/HvvVkgOh2VTqx2+0rVCwkLKkpCFLdtF6con6IQCm dWf/SaQKaEf5ws98Qbj4B2MhyP1RHUk/Em8yddLKrHE+3NQb5rDYJU78zspbFLgw6RdB /XQqrnZQ+/vieclb6UvktkE3u5JIqd8NHQGoVABDuigwuzMBbHHNV/EozarEtHvp17gO GStYCXzrNiJhQnIr3N92htYNd0eQ8D8AIc2AImoU15KlJY7dKE3HwA3qr3XBK2VRrilE iMA7Q1DLiXXEF1xxXswYRynL9OG46MBmfCOPZ/TVodnQDzJYwW52MpiHe/GSHbdKoded bHEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8YSyaOyMZUwWdPCBFPBOGGL6eMvWvn9+nsXpTtRO8nI=; fh=IfziUg6h224tUhqGUYXJrVUlOErIf6a7lSEmbvW1zEo=; b=L7Ay4RuT/IkF7E0ABCdmLc60zOIEKwoCU0uqwLZW6ktK43mbawOpnlTGyhSCJDK6yC SqFPWn/HADJJBZrto2wdYfsHI+ycIfNvLMI69VGjVDji0en5htEu16tF+iehRF2QyqOb TVIrv2rm/CW2t7Hiz5dx9SzEfd7Aql4t6j/h+YTOzG4YialV3WPWr8eex17Nv8ld8Df8 ttxuInX9LcR6wiKUwO5ga3xiDSIQSfwL8DmpRa5SSf/Ul59IFh+GsdQDTKFYpXA34ry1 K2SNjn7w7+EOCqgqSXUXfp48zkUVjBdnYVFaLVxJ3KWAwj6iLLzZSd4+cMw1zHxL8UD1 BC5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i3jnKCEl; 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 d15-20020a056402078f00b0051bea2cd018si2524352edy.567.2023.06.26.05.45.55; Mon, 26 Jun 2023 05:46:20 -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=i3jnKCEl; 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 S229712AbjFZMZE (ORCPT + 99 others); Mon, 26 Jun 2023 08:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231264AbjFZMYX (ORCPT ); Mon, 26 Jun 2023 08:24:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61F592970; Mon, 26 Jun 2023 05:22:52 -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 80C7E60E26; Mon, 26 Jun 2023 12:22:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6806C433C0; Mon, 26 Jun 2023 12:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687782168; bh=QFJoYAoa2djqSERhowqC20itD6kv95F3np82eWmAz+Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i3jnKCElPEbglru8D6DfI9k7iJ3oTU2OgLAtuSR1cTHVDbx5ifZGflwTYAg4yhF1O dQDDRBx/KXYZILa3/e164u2C7PBxgNDRXZIkWQ11X8yKy3Gvv44hS4ZuU1cI4lkfaV fwPPAEXiXjwAcyYLpvEjI7tX3ZAYfFe0XL5api/mri1HFt2lfrlcNXPGG0Z2RGhUOm YCaUbL88VvEEHyNrROXamBXPm9qNEMmoHALDylSN5P4GYYFfbzEippl1y9RHeCZt5j hGN+389eLoFso3N7Pv+WdeH79D4Sh3EVz2d3wX/didUC8GBoVLQUrvh685YFUBQXFM q1WSJ4f2++6TA== Date: Mon, 26 Jun 2023 13:22:44 +0100 From: Will Deacon To: Alan Huang Cc: paulmck@kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] rcu: Add necessary WRITE_ONCE() Message-ID: <20230626122243.GB19941@willie-the-truck> References: <20230620171346.207076-1-mmpgouride@gmail.com> <50c4aa37-388b-449c-8184-00a9d69471fc@paulmck-laptop> <2fd1169a-a695-4bff-9611-a84dd02025b2@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Sat, Jun 24, 2023 at 02:31:12AM +0800, Alan Huang wrote: > > > 2023年6月23日 下午1:17,Paul E. McKenney 写道: > > > > On Wed, Jun 21, 2023 at 10:08:28AM +0800, Alan Huang wrote: > >> > >>> 2023年6月21日 06:26,Paul E. McKenney 写道: > >>> > >>> On Tue, Jun 20, 2023 at 05:13:46PM +0000, Alan Huang wrote: > >>>> Commit c54a2744497d("list: Add hlist_unhashed_lockless()") and > >>>> commit 860c8802ace1("rcu: Use WRITE_ONCE() for assignments to > >>>> ->pprev for hlist_nulls") added various WRITE_ONCE() to pair with > >>>> the READ_ONCE() in hlist_unhashed_lockless(), but there are still > >>>> some places where WRITE_ONCE() was not added, this commit adds that. > >>>> > >>>> Also add WRITE_ONCE() to pair with the READ_ONCE() in hlist_empty(). > >>>> > >>>> Signed-off-by: Alan Huang > >>> > >>> On hlist_nulls_add_tail_rcu(), good catch, thank you! > >>> > >>> On the others, are there really cases where a lockless read races with > >>> the update? At first glance, that sounds like a usage bug. For example, > >>> as I understand it, when you use something like hlist_del(), you are > >>> supposed to ensure that there are no concurrent readers. Which is the > >>> point of the assignment of the special value LIST_POISON2, right? > >> > >> Do you mean there are cases where a lockless read races with hlist_add_head/hlist_add_before > >> hlist_add_behind/__hlist_del, but there is no real case where a lockless read races with the hlist_del_init/hlist_del > >> hlist_move_list? > >> > >> There may be no real case where a lockless read races with the hlist_del_init/hlist_del > >> hlist_move_list. But for the sake of completeness, I added those WRITE_ONCE, after all, if there is WRITE_ONCE > >> in __hlist_del, why not add WRITE_ONCE in its caller, like hlist_del()? > > > > You might well have located a larger issue. We want to be able to use > > KCSAN to find unintended data races, but as you noted, there might > > be different requirements for RCU-protected linked lists and for > > lock-protected linked lists. If there are, then there is probably > > existing linked-list code that is using the wrong primitive, for > > example, using (or failing to use) the one that Eric Dumazet provided. > > For example, mismatched API usage might be causing the differences in > > uses of _ONCE() primitives that you are calling out. > > I noticed a thread: > > https://lore.kernel.org/lkml/20200324153643.15527-2-will@kernel.org/ > > It seems like Will wanted to remove that hlist_unhashed_lockless()? > But I can’t find any further updates. > > Will: Can you tell me what happened later? IIRC, there were potential correctness issues with accesses being torn (possibly by the compiler) which meant that some additional surgery was needed to make some of the list accesses safe without locks. I then ran into problems understanding how list_empty_careful() is supposed to work which weren't resolved. I think the best summary of where I got stuck (and moved onto more pressing things) is: https://lore.kernel.org/lkml/20200424173932.GK21141@willie-the-truck/ Will