Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1060516lqo; Fri, 17 May 2024 09:27:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBnAJzqt6Fy5HgI4jcZi5wf+oSL4rPKz5oE49uYECZp1cmdjKYiTY1gTSec5+2YpwtqWswkx4Ngb0p4o1BkuuT3PbhvCvLSekTm3Gq+w== X-Google-Smtp-Source: AGHT+IFXnF/WWAkWwZYPuQiINN1/Coio6G0+PvgeiQiT4jnOPRhUChYlHbeyD4CaOBCDXaQYtCUT X-Received: by 2002:ac8:5e50:0:b0:43e:3878:6658 with SMTP id d75a77b69052e-43e3878691cmr79073061cf.31.1715963248372; Fri, 17 May 2024 09:27:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715963248; cv=pass; d=google.com; s=arc-20160816; b=ntyUNUFij+iOG4GlyHFe1fvbpa/4MjCB4exh1WvdSWgThZAy3MiePJARYuUyUt2iN3 Gukn6VOEmSxpHJnkP+1YJXfhncXb6ghU+qooNwHwwT/Q7pYiE6NgaB8CwD6LIGN5UBPP WsGfZ4h8dsnFI8vX3I0kLHHfLwmTkNz5vXqJsgpZ2mdMl8rLTXCFhtGxtpA9+7ba9KDD VJWT1xA6UP1U9pEkasJxPBjiQ+pAdFkSkj/GrRrJ2jn5ksHY+1efpNlDs5PptGvZzsxF 0AtiKQ9oyyJPxo1EcltIZlpoBbyxD1QmPWVxMV5cugk8wSmTByLPvyMj2finwsbs5mdf SSjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zHHFYGGHR8IWFe03susFUhICZjFQcAnsx/YAE07Ghdw=; fh=p9BUNDkK0oAqYatKxUgoch9OVeZP3o+/zIiVtRn83kI=; b=DEeh6va1Cya3dFlVOMVfCnKdTGdqQrtKTLzKARpeDv4w73QJ2HCY83WMY/OlDuE/H6 RFVfwn/tMDyvHjsIy1grH8N3ewmjjElNC4Q9Ja/U+EcQVh/Gh6/k7Qk9JFwwRxxDcYDt 59Tt716XVWl9tAovWzXmwmktZALIEcJcCuCdFN3yklJA+XjBmbfcwaVpQghRjzdTI1v5 EQR+PDJ4VNZmze8MYZicsQH0v54sj6flxdiA9pT7srBY5fm9WffHDizj94avHnhD3+BU ezJV2bMFFJfi74U4FxYQk9827g3cM1aWcGTxfB1mycjThPMDNjBageJbATCNr8gNn1uT ptzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Em4r12zY; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182347-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182347-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43e2867848esi28874651cf.504.2024.05.17.09.27.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 09:27:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182347-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Em4r12zY; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-182347-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182347-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 10BFC1C21BCE for ; Fri, 17 May 2024 16:27:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83D1012FB36; Fri, 17 May 2024 16:27:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Em4r12zY" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 0CAC141C68; Fri, 17 May 2024 16:27:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715963240; cv=none; b=nom5SQvz5Zurvo9W5ZbBmCIjy3597fjoiaZOJ2pBn72wfbCcZSN64QOL1va5uGqvZxvTJZccQB4hKJandsYwbREIY9B4Q+tXiLex8eXEx0jW2YXAWtmI6/ptQgijkbg1jw369yPpBZhU+NpW3AxoEIMgieaU55ULMk1Yj9CLNgs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715963240; c=relaxed/simple; bh=dOWyivRVjUsmi9qycvWUG6w2Rgzchn0zj4IqRET+Xtk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hRmpdWWW+nEm1TdaJrHp1wbg0RjxsyRfQJjfBATbl8hYTYbx9/Fl9932BBWwC5axHJwB0I7Rls3oiKgeabk/MdsOlPi9rpRPSmIrXuSuUTM1X4Oy3r1Er/e8gr9HJiLBV02ToUpSg/ic6vAwGFemwifmmlsYiu8i2CqHr7qqA2c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Em4r12zY; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a59a934ad50so470393066b.1; Fri, 17 May 2024 09:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715963237; x=1716568037; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zHHFYGGHR8IWFe03susFUhICZjFQcAnsx/YAE07Ghdw=; b=Em4r12zY+ON4jf6azOpDvZ+uRkGcSow6FypnUhl4ESWUfVU+A+5qxUp7p0/UMJi2gE tRNgUI2Qirblhj8hWPq0zC/u2H/X99XBUUlZKmYcJrnIoUAGeNtDMbcAMhYb6DUvZXel KOm1fMx5eU09mmFBBbQfDuXvOLL0wrvxJMdklevaaJl3KibmdgcyL/2seQ0jAtsfzBsZ O437aE4f1irMx3ahtbrCT+Wb4Av3LAmQiV2afKNJvH6ISUNARG8hTILWlpLKnGyKRF0e cCufX2MyZA6OapRxT1vWjoSCHataWghufZivVFkEjJRBcfb5D3sBhjhtZvSX5tV28+xp CYHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715963237; x=1716568037; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zHHFYGGHR8IWFe03susFUhICZjFQcAnsx/YAE07Ghdw=; b=aa/3PYszHwgDSoHc+bZXjewnWROVWMww6qyAH+e5Jjd2LVVIm1icgk3IR9gjnSqS/q IzyImV7TDdDjARdD9OOhckX8/TJuxlD7oWu78e+K0Vb0mNM7J5gUxBScavrLnjYxaOzN Rv5ASCnIE2ehlIVKugT1sK9LDa7kv5SFTizdaG6qYFMgC7/OGSxM0PV8mPGFlR+z2gyq 9B1PipA8ZM0LU5EQ6Ze+Xn946CJf1XLNwWKRBbWUafMRQuEvQ1kHKxbl3GXHtMVTAB1U 6DMzxaPp55e3oVAGsf/kULNra2i3F2U6PCQLZTrxxKXqwe5+FQwpQIs3q7D4A63UlMGZ Plbw== X-Forwarded-Encrypted: i=1; AJvYcCVH6WlqZOHFjhWWtaCVPn5aMNEMeNuGKMz3g1y5KcpOkvUbQ8HIXAZbE3ELcBDpCd1vpIZTmolVDBVx5c/SH/xODWoudSDIj6ECaXuFwSOzjwieD99Xbx8hOwaUlM9DVQMV X-Gm-Message-State: AOJu0Yy4VebRx2OvAexSxjNkeLhHhS0Uy9eZ03PVBId2ZKGf3ty4XAMJ 1lB1WqKEY3/kN/wy7RDN5vGo6sp+3MvXcGGesAU/FI1gC1HbMtHS X-Received: by 2002:a17:906:7248:b0:a59:a431:f955 with SMTP id a640c23a62f3a-a5a2d6786e5mr1465349566b.73.1715963237063; Fri, 17 May 2024 09:27:17 -0700 (PDT) Received: from andrea ([151.76.51.227]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b01d3dsm1125803166b.186.2024.05.17.09.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 09:27:16 -0700 (PDT) Date: Fri, 17 May 2024 18:27:12 +0200 From: Andrea Parri To: Frederic Weisbecker Cc: Valentin Schneider , LKML , "Paul E . McKenney" , Boqun Feng , Joel Fernandes , Neeraj Upadhyay , Uladzislau Rezki , Zqiang , rcu Subject: Re: [PATCH 2/6] rcu: Remove superfluous full memory barrier upon first EQS snapshot Message-ID: References: <20240515125332.9306-1-frederic@kernel.org> <20240515125332.9306-3-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: > Z6.0+pooncelock+poonceLock+pombonce.litmus shows an example of > how full ordering is subtely incomplete without smp_mb__after_spinlock(). > > But still, smp_mb__after_unlock_lock() is supposed to be weaker than > smp_mb__after_spinlock() and yet I'm failing to produce a litmus test > that is successfull with the latter and fails with the former. smp_mb__after_unlock_lock() is a nop without a matching unlock-lock; smp_mb__after_spinlock() not quite... C after_spinlock__vs__after_unlock_lock { } P0(int *x, int *y, spinlock_t *s) { int r0; WRITE_ONCE(*x, 1); spin_lock(s); smp_mb__after_spinlock(); r0 = READ_ONCE(*y); spin_unlock(s); } P1(int *x, int *y) { int r1; WRITE_ONCE(*y, 1); smp_mb(); r1 = READ_ONCE(*x); } exists (0:r0=0 /\ 1:r1=0) > For example, and assuming smp_mb__after_unlock_lock() is expected to be > chained across locking, here is a litmus test inspired by > Z6.0+pooncelock+poonceLock+pombonce.litmus that never observes the condition > even though I would expect it should, as opposed to using > smp_mb__after_spinlock(): > > C smp_mb__after_unlock_lock > > {} > > P0(int *w, int *x, spinlock_t *mylock) > { > spin_lock(mylock); > WRITE_ONCE(*w, 1); > WRITE_ONCE(*x, 1); > spin_unlock(mylock); > } > > P1(int *x, int *y, spinlock_t *mylock) > { > int r0; > > spin_lock(mylock); > smp_mb__after_unlock_lock(); > r0 = READ_ONCE(*x); > WRITE_ONCE(*y, 1); > spin_unlock(mylock); > } > > P2(int *y, int *z, spinlock_t *mylock) > { > int r0; > > spin_lock(mylock); > r0 = READ_ONCE(*y); > WRITE_ONCE(*z, 1); > spin_unlock(mylock); > } > > P3(int *w, int *z) > { > int r1; > > WRITE_ONCE(*z, 2); > smp_mb(); > r1 = READ_ONCE(*w); > } > > exists (1:r0=1 /\ 2:r0=1 /\ z=2 /\ 3:r1=0) Here's an informal argument to explain this outcome. It is not the only according to the LKMM, but the first that came to my mind. And this is longer than I wished. TL; DR: Full barriers are strong, really strong. Remark full memory barriers share the following "strong-fence property": A ->full-barrier B implies (SFP) A propagates (aka, is visible) to _every CPU before B executes (cf. tools/memory-model/Documentation/explanation.txt for details about the concepts of "propagation" and "execution"). For example, in the snippet above, P0:WRITE_ONCE(*w, 1) ->full-barrier P1:spin_unlock(mylock) since P0:spin_unlock(mylock) ->reads-from P1:spin_lock(mylock) ->program-order P1:smp_mb__after_unlock_lock() acts as a full memory barrier. (1:r0=1 and 2:r0=1 together determine the so called critical-sections' order (CSO).) By contradiction, 1) P0:WRITE_ONCE(*w, 1) propagates to P3 before P1:spin_unlock(mylock) executes (SFP) 2) P1:spin_unlock(mylock) executes before P2:spin_lock(mylock) executes (CSO) 3) P2:spin_lock(mylock) executes before P2:WRITE_ONCE(*z, 1) executes (P2:spin_lock() is an ACQUIRE op) 4) P2:WRITE_ONCE(*z, 1) executes before P2:WRITE_ONCE(*z, 1) propagates P3 (intuitively, a store is visible to the local CPU before being visible to a remote CPU) 5) P2:WRITE_ONCE(*z, 1) propagates to P3 before P3:WRITE_ONCE(*z, 2) executes (z=2) 6) P3:WRITE_ONCE(*z, 2) executes before P3:WRITE_ONCE(*z, 2) propagates to P0 (a store is visible to the local CPU before being visible to a remote CPU) 7) P3:WRITE_ONCE(*z, 2) propagates to P0 before P3:READ_ONCE(*w) executes (SFP) 8) P3:READ_ONCE(*w) executes before P0:WRITE_ONCE(*w, 1) propagates to P3 (3:r1=0) Put together, (1-8) gives: P0:WRITE_ONCE(*w, 1) propagates to P3 before P0:WRITE_ONCE(*w, 1) propagates to P3 an absurd. Andrea