Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2417140rwo; Thu, 3 Aug 2023 09:04:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+VQG7SjUCkLJHrZP8johURRCPmV6DHWy2tV4Q7/T5SnpNk/67gblJM04l+IZCT97jXFdx X-Received: by 2002:a17:903:2301:b0:1bb:9f07:5e0 with SMTP id d1-20020a170903230100b001bb9f0705e0mr21721133plh.60.1691078677825; Thu, 03 Aug 2023 09:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691078677; cv=none; d=google.com; s=arc-20160816; b=rWYXIdLxwXF3IMbu7MskkOd6KRTkuc334IA58aPTJ9R4DTWit5z41EnR+aTlTtSvKH 4lb8IcvARvEDiYpRAGu5LYJrMt3G7PAIbtbIHIRLA+0ZPHIb7vGGiCU17qufBEa6SOHV iUKrLS74kB2G5MSwWofQqIJxEvPOI+7jczC64DHotO/RC1s1vUKleZlscZcJElorzYYr ldqYfW+gjq/KvefBLdWHpyf+HzOxRvv7w+VsCUAMt1FAeOiT03MhmGdyQPrF+BrbXD29 jemFgkvbL09rUMzP7Uhzf0IhQpIYQUI24a+74orvWoxE8GUOZ9Rh2jMzdjPPOA5Tj9iX Xz8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=19BZNGqKOrPHBBOl2OIBFvG7nlcaxoTrDeHm2ZDX1TA=; fh=bjAKNIax2rH2//zNrGOQcaXrKV9TGUuAJc3FJ25Ien8=; b=wDEfWNYfn4PyW/OqobeqmkyxfAb3N3Zbbmyab2KFPsXszENt/ZizMFLvM8gReiPLqV o0K/O/q7h5DZu+HRZ91gtVbLPLMqYJ7tLgDPX9Y0zlQ1fmAwAW9paHcfsGnvNqnfUJRa Mfufu/WgC8mJsgDD9uruldWEVVgUtZMyMB0rOhwMy5KURCywVmC8L7cshP/iR/t0Ol8A BHRUK+8Jb5PqyER2VJj7xzW+qqSmzr3o0wDjqF/SXt9h9/eiW1yY77tIJqZnkg6O4RCz AZFwIQLIvRI0zemEDP4K/1fbaNgTBhkvUK8uVquaoIkjMF3ZAAIGK7yX4zZY4lS10A51 TUsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=W8tofW1S; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a170903024800b001b041591a5fsi70998plh.459.2023.08.03.09.04.17; Thu, 03 Aug 2023 09:04:37 -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=@gmail.com header.s=20221208 header.b=W8tofW1S; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235963AbjHCNoK (ORCPT + 99 others); Thu, 3 Aug 2023 09:44:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236748AbjHCNnZ (ORCPT ); Thu, 3 Aug 2023 09:43:25 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CCE55254; Thu, 3 Aug 2023 06:40:21 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686ed1d2594so827508b3a.2; Thu, 03 Aug 2023 06:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691070020; x=1691674820; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=19BZNGqKOrPHBBOl2OIBFvG7nlcaxoTrDeHm2ZDX1TA=; b=W8tofW1SuF9HGXbhGt1RS/OKnyCIc2o+7Q4E9Mvb83NSzkw0Hb4y2WpDlL7esofUW3 7mH1po3DNTYdhcCGWsprQxa2uJUUAnjP5wDkcGZ2K3EP9v9gj9O+UNFPS/A8mMEd9toh f0HlDQrKVRnEb2tnRNGvcQIElWx5TAsmw3agJmEjK4BBPRXVRDKR3SDJ6M69cVKVjAkW Mqhjoo9XseJODyFp3nHgOOLMahILyVBza2cZZS8zlhAXTtn/jVYbz6lRqAU2VSR2qHz6 9vLBEaxd1hL/VZV5lBW08+dFZTaqgdkQssZeBS3/tsJksBGZVva9PW1RXRaL1P6FQmvM fQPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691070020; x=1691674820; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=19BZNGqKOrPHBBOl2OIBFvG7nlcaxoTrDeHm2ZDX1TA=; b=Ol/sKTMWInE/fxfpdwV0CIAClJmqnJeGHS5IkvPJrPRO7gUzoiOmYKeNIQOuT5hC1k Z1XdHUjBktY3ghc/AtFa2T75ggOs468OPFk+OqI90CN43Jcn7SBpouOw4YSBnxF0aDdZ fownoocPlu0ozCJN89VR0D7VSgZH08Q+KxlORED394l1QeBuRs4+poUF+LEegCrr4W55 IpnVX+H6QV+yQ0oFGdQJ47XMmYvroQxIwWq4AhJD96DQTDs1CWOiVC9uxQqEA5NPGafu vtvJOxAwNycYlBtXlK6gWJ83UnEck7ce9Xudd3eWKFADGjAxZLDvmAlKioeSnRNNELEp 14mQ== X-Gm-Message-State: ABy/qLaUBAQvw34T8Yzc+zy523AL/Q5H0xGLwybNGyUFtQ8rFOqgUsi5 nbGoCNLotmKaOhQyJCZUsqs= X-Received: by 2002:a05:6a00:148b:b0:67b:2eba:bed4 with SMTP id v11-20020a056a00148b00b0067b2ebabed4mr25209241pfu.14.1691070020449; Thu, 03 Aug 2023 06:40:20 -0700 (PDT) Received: from [127.0.0.1] ([2402:d0c0:2:a2a::1]) by smtp.gmail.com with ESMTPSA id d25-20020aa78e59000000b0062cf75a9e6bsm12841091pfr.131.2023.08.03.06.40.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2023 06:40:20 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: Question about the barrier() in hlist_nulls_for_each_entry_rcu() From: Alan Huang In-Reply-To: <43d29007-3c59-4497-a1e5-26f182a7f4c5@paulmck-laptop> Date: Thu, 3 Aug 2023 21:40:11 +0800 Cc: Joel Fernandes , Eric Dumazet , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, rcu@vger.kernel.org, roman.gushchin@linux.dev Content-Transfer-Encoding: quoted-printable Message-Id: <784ABF9D-303F-4FC8-8AFF-A3FF319B4E7A@gmail.com> References: <1E0741E0-2BD9-4FA3-BA41-4E83315A10A8@joelfernandes.org> <1AF98387-B78C-4556-BE2E-E8F88ADACF8A@gmail.com> <43d29007-3c59-4497-a1e5-26f182a7f4c5@paulmck-laptop> To: "Paul E. McKenney" X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 > 2023=E5=B9=B48=E6=9C=881=E6=97=A5 =E4=B8=8A=E5=8D=884:09=EF=BC=8CPaul = E. McKenney =E5=86=99=E9=81=93=EF=BC=9A >=20 > On Fri, Jul 21, 2023 at 10:27:04PM +0800, Alan Huang wrote: >>=20 >>> 2023=E5=B9=B47=E6=9C=8821=E6=97=A5 20:54=EF=BC=8CJoel Fernandes = =E5=86=99=E9=81=93=EF=BC=9A >>>=20 >>>=20 >>>=20 >>>> On Jul 20, 2023, at 4:00 PM, Alan Huang = wrote: >>>>=20 >>>> =EF=BB=BF >>>>> 2023=E5=B9=B47=E6=9C=8821=E6=97=A5 03:22=EF=BC=8CEric Dumazet = =E5=86=99=E9=81=93=EF=BC=9A >>>>>=20 >>>>>> On Thu, Jul 20, 2023 at 8:54=E2=80=AFPM Alan Huang = wrote: >>>>>>=20 >>>>>> Hi, >>>>>>=20 >>>>>> I noticed a commit c87a124a5d5e(=E2=80=9Cnet: force a reload of = first item in hlist_nulls_for_each_entry_rcu=E2=80=9D) >>>>>> and a related discussion [1]. >>>>>>=20 >>>>>> After reading the whole discussion, it seems like that ptr->field = was cached by gcc even with the deprecated >>>>>> ACCESS_ONCE(), so my question is: >>>>>>=20 >>>>>> Is that a compiler bug? If so, has this bug been fixed today, = ten years later? >>>>>>=20 >>>>>> What about READ_ONCE(ptr->field)? >>>>>=20 >>>>> Make sure sparse is happy. >>>>=20 >>>> It caused a problem without barrier(), and the deprecated = ACCESS_ONCE() didn=E2=80=99t help: >>>>=20 >>>> https://lore.kernel.org/all/519D19DA.50400@yandex-team.ru/ >>>>=20 >>>> So, my real question is: With READ_ONCE(ptr->field), are there = still some unusual cases where gcc=20 >>>> decides not to reload ptr->field? >>>=20 >>> I am a bit doubtful there will be strong (any?) interest in = replacing the barrier() with READ_ONCE() without any tangible reason, = regardless of whether a gcc issue was fixed. >>>=20 >>> But hey, if you want to float the idea=E2=80=A6 >>=20 >> We already had the READ_ONCE() in rcu_deference_raw(). >>=20 >> The barrier() here makes me think we need write code like below: >> =09 >> READ_ONCE(head->first); >> barrier(); >> READ_ONCE(head->first); >>=20 >> With READ_ONCE (or the deprecated ACCESS_ONCE), >> I don=E2=80=99t think a compiler should cache the value of = head->first. >=20 > Apologies for the late reply! >=20 > If both are READ_ONCE(), you should not need the barrier(). Unless = there > is some other code not shown in your example that requires it, that = is. And unless the compiler has a bug. :)=20 So, the barrier() in hlist_nulls_for_each_entry_rcu() is a workaround = for a compiler bug. >=20 > Thanx, Paul >=20 >>> Thanks, >>>=20 >>> - Joel >>>=20 >>>>=20 >>>>>=20 >>>>> Do you have a patch for review ? >>>>=20 >>>> Possibly next month. :) >>>>=20 >>>>>=20 >>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>> [1] = https://lore.kernel.org/all/1369699930.3301.494.camel@edumazet-glaptop/ >>>>>>=20 >>>>>> Thanks, >>>>>> Alan