Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp125757lqc; Thu, 7 Mar 2024 12:14:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVIzOw4OnuZT9RlYfk5uy3rg1C2827k4xckBJ5WKeJspMgDfFS/OHH+1McMoJc4B9GPWfCNg69/JkPysZPzXZdGNeL4OZLHPX32ZDqLKQ== X-Google-Smtp-Source: AGHT+IEngOG9z6voyuwF/6u8hS5xyWQXH6yOEqwHSJ1s6eiYBwwKeQPsDXgRpqlIjL2d36b6F54O X-Received: by 2002:a17:902:e5cd:b0:1dc:c8b3:9376 with SMTP id u13-20020a170902e5cd00b001dcc8b39376mr3950943plf.7.1709842494720; Thu, 07 Mar 2024 12:14:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709842494; cv=pass; d=google.com; s=arc-20160816; b=gWgoj3UGDg0bTg+u+BBGFLhfFoV6POFE6bNT6T4VAxA4HhMr2ph6lIg+uZkUvAlmtZ pjiE8FU+bb6zDNbRPe8dqnCavyW1tEQIQZgXpUUw2MTAobU0MO3dY5WQK1+qujOdeGu/ hjJs0NJsED2NgU55VH4HwPq0iSIR6d814u/+90w89Bs+yxZSNjJoB3fYBJK9mjmzSblx ONlIwGMILKmEXnccNA+N0JQ/xNVK7bLfudjj81+Ulk/5CtWM0aCjOCa3doGbOrvqE6iR TEaeNeOTDoqSdgOAamAIfcW0fRBbh1I5IQQtMCVrOS0PAEVxDGyVhJGbGvP6IEtt9Oxx J48g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=b6kBgbL9HAhEpnz7T+Yyi2IbRse7Tjb+btEkUQHTFGM=; fh=Agfbo4IcyOXUaGaS4PiDFIDdCPzjgvPjjMZ3sI+eG4g=; b=q9CA68c4uTzq68duXnN+LhF/O48r5BUO8yU++FxPYqR/1U9sOKZLsgpLWuk7DIcZtd G0bUShCm83MDRsnp2AOxmqMZ2bMIyRu/BiX14E5KTLDhSv/gdHHgNyAi30gADUNWLXRx f8m00tqeAPWunhC1nEnL1xcTjNnrDexUU5ztioHVJ4CHCeFeQ69hJISqVNIEZ4ylEv+T TMa60LoUjOSwedFNsjEdQfcys6e024aWjXrTlCCAwtnbX56bF29neimOcwCWUmIJzS3t Ew4v8CNjvebOQxNTbqfx4uFKaSA9xgigrBNbor78aIASl7Nuu78t5a34Oy3E9OfxnCY7 pcaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=MdfrHBLx; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-96154-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96154-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 145-20020a630297000000b005e4c83e4f41si6656529pgc.183.2024.03.07.12.14.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:14:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96154-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=MdfrHBLx; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-96154-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96154-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B381EB25C90 for ; Thu, 7 Mar 2024 20:01:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88B19137C36; Thu, 7 Mar 2024 20:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="MdfrHBLx" Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 661FD1350D6 for ; Thu, 7 Mar 2024 20:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709841667; cv=none; b=qAKW553Fd6GSucygyBcR2+aHE3wT/DPTwxqGiePfGbJ+tydJLosyzbJSKL7Rt1yASOqApbz5l7OXDfERcEB80b5jsOy8SqyxSoOEnudrZgx1I8tPBIIul/mj7pCBbo6G0JW2uThnRXualu1FT0ipC7qL34PThGHtwuqt7DgrR/s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709841667; c=relaxed/simple; bh=20dZ8K6KYsjFLDRa9KVUU+GTtq9ea4tPvWyMafwWw8k=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=tb+68qPE5xUPMUvpF9TYIMk9MRd+FngpdkAOJ4xpbTWHOf4cS6wc94em9QqMj6WEGptOBabDNjwaQmLEC+t10etM74cf+t06WmuW5Lk8IVui19j4ib1Os+Kh+I23/EseHmzVHwK83+tfXePa1Dok6EdnaQE68VASQzPvV5slRyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=MdfrHBLx; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-565d1656c12so2435767a12.1 for ; Thu, 07 Mar 2024 12:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1709841663; x=1710446463; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=b6kBgbL9HAhEpnz7T+Yyi2IbRse7Tjb+btEkUQHTFGM=; b=MdfrHBLxH/RIH6gZIR42cr6QJSYvLHAGU6G4aJVYagTvGdSoH/pSP2qTk+N5mJ0DJS awNXTOxWNkGO5NF3IFe5651lbkVrIlr4JE0Fdgd6pc0Nc+LRuDUuvwe0G+Caxvxqi4hg 680DwLN+jicX8rnjex442RRtmdy2znzRZuVzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709841663; x=1710446463; h=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=b6kBgbL9HAhEpnz7T+Yyi2IbRse7Tjb+btEkUQHTFGM=; b=VevhhFDrquCxBIc5BPS08oUx7wjLA3Iyhx85YoOrpydoA7BBWxZAOuFUpHiC9jbyaS vIpxhTN3HY5pzrUnJVn3ztlHtYL1NKFf1rfIzXHgW5LqfAqfPD20wnbXQkQPgItcUPSS AiDFgLbOmR8k+4EbD++vmDgDY06R6juXXpZRHLIxSgXs0hqIwbLQ2gLP0HnOFdRTpIbS 0aOA158qen9Um/kHV7ZYXFq5kjb+FFtnSj9hkhRfh/m408hHa2mUvUwVaGErqy3rIJYt cBzjqnSPtFCNP4uUA4bt2vzeGCwIYxRBMgbQKX7SNHQI4fs+bM+P038fhVwNHb8HeYHv RJIQ== X-Forwarded-Encrypted: i=1; AJvYcCUGB4vG0SpLFbt9Q9x6gj3IiUMr99l2WHRPtQ7aJrGTsAzlQk8qbIpymhR2m94X09X1uO75owBqgGNfaytTE0JCva4AyRqQxTbvDhC4 X-Gm-Message-State: AOJu0Yz9+NH4aXx+Bi6EMfGY/U9DwELpTMojI0XGjT0lnlfntMmOiXhv mv5Uc1H9XpQVtXBIsvIQfxNfdQXSIjoOKYauny6yZu/IU7ycXmGarwZalPsDhRReCxqlQKd5LY/ XFce/YQ== X-Received: by 2002:a50:bb44:0:b0:566:13f8:bcc with SMTP id y62-20020a50bb44000000b0056613f80bccmr736407ede.0.1709841663549; Thu, 07 Mar 2024 12:01:03 -0800 (PST) Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com. [209.85.218.54]) by smtp.gmail.com with ESMTPSA id k22-20020aa7c056000000b0056706105abesm6420407edo.33.2024.03.07.12.01.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 12:01:02 -0800 (PST) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a3ddc13bbb3so443962966b.0 for ; Thu, 07 Mar 2024 12:01:02 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVPjHBcKF8XLAYD31IuRuiaFVJZKFJZQSXJu0JV6uyHMQ92xzYJ/bswR4s3YNiwf8/HAdoN2dG22BL+c5kO1rbD4od+trVlC0+8XmjR X-Received: by 2002:a17:906:a18a:b0:a3e:4d7c:9ce1 with SMTP id s10-20020a170906a18a00b00a3e4d7c9ce1mr1133545ejy.21.1709841661652; Thu, 07 Mar 2024 12:01:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240306135504.2b3872ef@gandalf.local.home> <20240306142738.7b66a716@rorschach.local.home> <83b47424-e5e0-46de-aa63-d413a5aa6cec@paulmck-laptop> <851dc594-d2ea-4050-b7c6-e33a1cddf3a1@efficios.com> <72b14322-78c1-4479-9c4e-b0e11c1f0d53@paulmck-laptop> In-Reply-To: From: Linus Torvalds Date: Thu, 7 Mar 2024 12:00:44 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] rcutorture: Fix rcu_torture_pipe_update_one()/rcu_torture_writer() data race and concurrency bug To: paulmck@kernel.org Cc: Mathieu Desnoyers , Steven Rostedt , linke li , joel@joelfernandes.org, boqun.feng@gmail.com, dave@stgolabs.net, frederic@kernel.org, jiangshanlai@gmail.com, josh@joshtriplett.org, linux-kernel@vger.kernel.org, qiang.zhang1211@gmail.com, quic_neeraju@quicinc.com, rcu@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Thu, 7 Mar 2024 at 11:47, Paul E. McKenney wrote: > > > - The per-thread counter (Thread-Local Storage) incremented by a single > > thread, read by various threads concurrently, is a good target > > for WRITE_ONCE()/READ_ONCE() pairing. This is actually what we do in > > various liburcu implementations which track read-side critical sections > > per-thread. > > Agreed, but do any of these use WRITE_ONCE(x, READ_ONCE(x) + 1) or > similar? Absolutely not. The READ_ONCE->WRITE_ONCE pattern is almost certainly a bug. The valid reason to have a WRITE_ONCE() is that there's a _later_ READ_ONCE() on another CPU. So WRITE_ONCE->READ_ONCE (across threads) is very valid. But READ_ONCE->WRITE_ONCE (inside a thread) simply is not a valid operation. We do have things like "local_t", which allows for non-smp-safe local thread atomic accesses, but they explicitly are *NOT* about some kind of READ_ONCE -> WRITE_ONCE sequence that by definition cannot be atomic unless you disable interrupts and disable preemption (at which point they become pointless and only generate worse code). But the point of "local_t" is that you can do things that aresafe if there is no SMP issues. They are kind of an extension of the percpu_add() kind of operations. In fact, I think it might be interesting to catch those READ_ONCE->WRITE_ONCE chains (perhaps with coccinelle?) because they are a sign of bugs. Now, there's certainly some possibility of "I really don't care about some stats, I'm willing to do non-smp-safe and non-thread safe operations if they are faster". So I'm not saying a READ_ONCE->WRITE_ONCE data dependency is _always_ a bug, but I do think it's a pattern that is very very close to being one. Linus