Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp200700rwo; Fri, 21 Jul 2023 10:27:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlGasedm0kuCRnsPH3t2kgtpoJnWPhd4BbTtTKmD31Gx8BHeuRGsFoCU9j7L32eDdcn+q/w2 X-Received: by 2002:a17:90a:984:b0:263:f68d:adca with SMTP id 4-20020a17090a098400b00263f68dadcamr1804210pjo.20.1689960463668; Fri, 21 Jul 2023 10:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689960463; cv=none; d=google.com; s=arc-20160816; b=xC74b4FX7WphOFIjSjrgcdVobXpTraKxzIc3UBkXATSqDc+tcGf6O0jI1zS3AJJIjU iFsJuli3vPAPQr8NETktHRn7ZM+EmY2u2YcUYemEwLkTCsl3BgNRIAwdWc8a/mzLIIWA 8M3e5rvKhNfLe7/d2kAm3WaSkJd52w+kabWP11l6snHeWxyp5WTFkmGm/QOFuLuDsgbz OyH1GuvENGFPNMxfCNMai5l5fdoGeL3VfTiobC8JHFA/FCbsezPW2npO7hUUAZSNO4Jp CeZV9QESiZP0tdwIaKRz4vQIAY8sEYC/UGzI9heutWgKiPFGfiwusRRu9TMWx4TyB1lw 1fZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9K5VHhZFEzQffhn522CBvGHgBcaIDvu9FEQtTEAlvh8=; fh=RogAIoVPbJlI58vPNsu27fu46lRh9Y+Yu3xP3U6+jSA=; b=bOx9IyJjWs+lt/s8jFn/2OvZvvsOuFf8ZcsEgQMurxawNcGGE1RJHzvErI8Wi+8+bJ yYOxIaWRpxDibDpzksQ+b5HPmUg95c44vdH6jdBX6+fMg5cov5c1/FaznLWB62gWPsas 5xaPpep0JFBJ4OMiIqMECCeaFpT5A/lvMVqoKW8nju7ka88AjTcWXzuVlNVN87cBx+EE ZqWm9sVQT9jLfQYDQTqN5AiN86XXRXU27W4YrNlLKVGQQDA5H7YEPQlKYeBzuQ207LeM 7lvIECCOlnFIYEGbsRxjQEzLcZeCDZ2eqqhXAfNIx7GQNXPF5C7TL6NtIwpN+1WNhQBG ZXuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=v9suOoHB; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a17090aa88600b0026360db339fsi3597332pjq.12.2023.07.21.10.27.31; Fri, 21 Jul 2023 10:27:43 -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=@joelfernandes.org header.s=google header.b=v9suOoHB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbjGURO6 (ORCPT + 99 others); Fri, 21 Jul 2023 13:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjGUROz (ORCPT ); Fri, 21 Jul 2023 13:14:55 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C62F52D4E for ; Fri, 21 Jul 2023 10:14:53 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b961822512so32793591fa.2 for ; Fri, 21 Jul 2023 10:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1689959692; x=1690564492; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9K5VHhZFEzQffhn522CBvGHgBcaIDvu9FEQtTEAlvh8=; b=v9suOoHBlIk67EKDKPqWLhrvssc3VmdYen5EzwX5m/TcUyTOkr+Ok1N1Qaa2m2hhVU dqHw3CQNBMJ741j1Q41aKPaQP8tzE+Ad/rNDqGHrMjkShpnw72khf+y+t5siZc4LowW8 oTLzbsiQo87tyS4+gTUmElWm6wi61LFe0O8IY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689959692; x=1690564492; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9K5VHhZFEzQffhn522CBvGHgBcaIDvu9FEQtTEAlvh8=; b=Jm1Mt9NLAq7aVMVzNMrfpouHCU8NfC3mwQssUd/veHt/AP5sbGGOyv4KpqGd+WddfH R9LMCYdrcar8pZZylVJCrzBGGojkSzo7LkGoThcl7o23JwkJ4PIdSESoUbUdvCoFBViw 3hrvrrIg1snHlw4nL9BcNRaVFw0onbgASTKIryqQNTmxxI6sTAsaPwbmO1I/UwZE5qdW JDuxNRnRKuY0keZb1WbXrW0inNYd7dUJPCev1z4CpnPzDFZfr+I1nT5cdEvrWty5bqw/ xg22MoQ7XubbdJJcctK4O5MLzGig697/h29JXCO7C81Fsar1azjtmsuZI6IhRliIfl7o 0jgg== X-Gm-Message-State: ABy/qLbBNf6HWawmuUtn8ZHliwklShufgIJilhNI4OfLrByqC44rGpWd YENXdZBGaUp2uZFKQrygSDxrEW4vndv3n1aSadTNnQ== X-Received: by 2002:a05:651c:205:b0:2b5:9f54:e290 with SMTP id y5-20020a05651c020500b002b59f54e290mr1980021ljn.0.1689959691909; Fri, 21 Jul 2023 10:14:51 -0700 (PDT) MIME-Version: 1.0 References: <1E0741E0-2BD9-4FA3-BA41-4E83315A10A8@joelfernandes.org> <1AF98387-B78C-4556-BE2E-E8F88ADACF8A@gmail.com> <962bb2b940e64e7da7b71d11b307defc@AcuMS.aculab.com> In-Reply-To: <962bb2b940e64e7da7b71d11b307defc@AcuMS.aculab.com> From: Joel Fernandes Date: Fri, 21 Jul 2023 13:14:40 -0400 Message-ID: Subject: Re: Question about the barrier() in hlist_nulls_for_each_entry_rcu() To: David Laight Cc: Alan Huang , Eric Dumazet , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "rcu@vger.kernel.org" , "Paul E. McKenney" , "roman.gushchin@linux.dev" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 Fri, Jul 21, 2023 at 11:59=E2=80=AFAM David Laight wrote: > > .... > > Right, it shouldn't need to cache. To Eric's point it might be risky to= remove > > the barrier() and someone needs to explain that issue first (or IMO the= re needs > > to be another tangible reason like performance etc). Anyway, FWIW I wro= te a > > simple program and I am not seeing the head->first cached with the patt= ern you > > shared above: > > > > #include > > > > #define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) > > #define barrier() __asm__ __volatile__("": : :"memory") > > > > typedef struct list_head { > > int first; > > struct list_head *next; > > } list_head; > > > > int main() { > > list_head *head =3D (list_head *)malloc(sizeof(list_head)); > > head->first =3D 1; > > head->next =3D 0; > > > > READ_ONCE(head->first); > > barrier(); > > READ_ONCE(head->first); > > > > free(head); > > return 0; > > } > > You probably need to try harder to generate the error. > It probably has something to do code surrounding the > sk_nulls_for_each_rcu() in the ca065d0c^ version of udp.c. > > That patch removes the retry loop - and probably breaks udp receive. > The issue is that sockets can be moved between the 'hash2' chains > (eg by connect()) without being freed. I was just replying to Alan's question on the behavior of READ_ONCE() since I myself recently got surprised by compiler optimizations related to it. I haven't looked into the actual UDP code. - Joel