Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp879786lqo; Fri, 17 May 2024 04:40:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXsPFijhRiwlgT3aPxfqLSb875QyiSJ74xQa/xZTHHLye/812TA+1u77OY7WMiJc/Th1Z+meZHmJ/2l9fGdZnb8c5wOVDgsQPXhDfy/+Q== X-Google-Smtp-Source: AGHT+IEqMzN6qYUH9aILOyQrdxC/hLH1N+0vVAzkSQFeUzG7no3J8Y40zdzb1KYadmCCJfmVTNjJ X-Received: by 2002:a17:906:b0c:b0:a59:b342:3ed5 with SMTP id a640c23a62f3a-a5a2d54d194mr1484256366b.15.1715946021878; Fri, 17 May 2024 04:40:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715946021; cv=pass; d=google.com; s=arc-20160816; b=OiaTE0ORhcV6r6YDaS21lNQB916RstLkqtlw7jKPTUfKwKgD2ApcUFlDS9EBBiXQ35 pVY9Tva3XjyPIciqg8teJJSH0h1BG3fZdj+c0RRtuEAr/Pb5+hrZWPtZXk06ofl5dLUB eVNCw6gRUss9G6EI8vL9dcO3IPhtOz0aUCf5PI2mRMSqu3AOJfds0DOCD/AIVMEjNzKt TtaQlzDOSGlDGadB9gIoNVHq1ayKF0fKEPyXMmGZ+LQtfI2M5OzYe4M3vFcEPWczHtuJ 5l9Re1fctQkAFf7Kl5SmEvg2yIdDYxdT2AXgfQWmOmxUoD5HjgORn3AkH+2iGEMBrLBn Mpjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UpgsiwiOiL73UbQRD0FLoRo/KIAcd8E/KmCJgZLx9pk=; fh=NLjnBGxnrPYd2POIS2L17wt89lg/avewdrjn4uiCsNA=; b=l5bDILjHLySQEm9sZUxTjAJyi4uZcSrmz2YKiDUC967TBUXjgcozP4MjCKT3ACyKpn JH0Qo3ujpMcPUW2+FLKLbWDxlIO1oDnUj+zCLA/5HFymwsjyGhhNlh8r+dtpC20KTb1O g+NeOJL0ynk5tn7q8k+CrIVcM0p4swrLwgYs9NN3SWvGGnrJrWT9oMHImREWa2CUEnjA tLTTy8aMPldqH1cXErB9GhWuOuHCSq3KBSPZM0fzsnnUX9gwHQ/wWlRQG5dhdmY7ZyDR h0r5ClX7BuBhZ93Ih2OHg/KW1BLwXaUAJmbFVseBOD2dx5iRKr3Hk+c2R9pJvxk+vxKm o2iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W7CpS19M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-182062-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182062-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2c83bsi954977966b.1032.2024.05.17.04.40.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 04:40:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182062-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W7CpS19M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-182062-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182062-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9A1731F244B5 for ; Fri, 17 May 2024 11:40:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92E1B3E48F; Fri, 17 May 2024 11:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W7CpS19M" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B15893D541; Fri, 17 May 2024 11:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715946014; cv=none; b=H8dMEFz7wHQZO5ImWBdI1+Wb9SWxHsSJjS95mmdO4i6d0uciPKTqne1kcZswNhMs7L9vWGdqSHjbn4iZtl5oiE9sgtw24LtesFtflDCKT5Dct82OeMknuBSWY8MBcNa8aVBB4qA1JzDNl2qnTqtYH2xzpgxMOFaMvQDT82QQfBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715946014; c=relaxed/simple; bh=D256TFI+0c0WlOF4Wi9/+Mvuafjti0O9GN9MOXChFTA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pIIETmOCOhHKy6d0r/DFdUSuGPMH7DfeSzH8DLHknlaXOtSsqqhZ801puFybejS8TE69gxPeOJoh95tROcEZxomZrS1xcqtmmdzfFOUwGa4zoWHR/5LMMDkSSbINwYIOnp3swrn3OaMwmEgz+4rgcxiNM2WoBViwNpKmP9gaXAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W7CpS19M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF65CC2BD10; Fri, 17 May 2024 11:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715946014; bh=D256TFI+0c0WlOF4Wi9/+Mvuafjti0O9GN9MOXChFTA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W7CpS19MtjTMMeLh1uaMPRX3B8kkUBgRRIoCCPR/du5PzbO0OQaCLgG04bB0lPNSw AWkfT4fXaxe4pPObdcjSZjYrghF90t8xpWkzJ47kHUXGh16nOromse0dMLich+hUt8 AaT4ycaZgOgvBzVvqKXf68jf57vxXcbifAc2H84sD5csirZ8yqcY+hv/CfFUcUf+R8 tSQby/+AzdECBBuDSAC3BtMUiJzTxf4yAioyQxTwRPuI9fWgv8vBpUPefwvyJ/i0wG MJDcP9WHOG4GMgulHGMdLuAQs2wNOHN4vyYD2DzMdLmmCYAWaplHMTFrbyApaetdB5 lGWfXGXRoWs/Q== Date: Fri, 17 May 2024 13:40:11 +0200 From: Frederic Weisbecker To: Andrea Parri 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Le Fri, May 17, 2024 at 09:29:14AM +0200, Andrea Parri a ?crit : > I know my remark may seem a little biased, ;-) but the semantics of > smp_mb__after_unlock_lock() and smp_mb__after_spinlock() have been > somehowr/formally documented in the LKMM. This means, in particular, > that one can write "litmus tests" with the barriers at stake and then > "run"/check such tests against the _current model. > > For example, (based on inline comments in include/linux/spinlock.h) > > $ cat after_spinlock.litmus > C after_spinlock > > { } > > P0(int *x, spinlock_t *s) > { > spin_lock(s); > WRITE_ONCE(*x, 1); > spin_unlock(s); > } > > P1(int *x, int *y, spinlock_t *s) > { > int r0; > > spin_lock(s); > smp_mb__after_spinlock(); > r0 = READ_ONCE(*x); > WRITE_ONCE(*y, 1); > spin_unlock(s); > } > > P2(int *x, int *y) > { > int r1; > int r2; > > r1 = READ_ONCE(*y); > smp_rmb(); > r2 = READ_ONCE(*x); > } > > exists (1:r0=1 /\ 2:r1=1 /\ 2:r2=0) > > $ herd7 -conf linux-kernel.cfg after_spinlock.litmus > Test after_spinlock Allowed > States 7 > 1:r0=0; 2:r1=0; 2:r2=0; > 1:r0=0; 2:r1=0; 2:r2=1; > 1:r0=0; 2:r1=1; 2:r2=0; > 1:r0=0; 2:r1=1; 2:r2=1; > 1:r0=1; 2:r1=0; 2:r2=0; > 1:r0=1; 2:r1=0; 2:r2=1; > 1:r0=1; 2:r1=1; 2:r2=1; > No > Witnesses > Positive: 0 Negative: 7 > Condition exists (1:r0=1 /\ 2:r1=1 /\ 2:r2=0) > Observation after_spinlock Never 0 7 > Time after_spinlock 0.01 > Hash=b377bde8fe3565fcdd0eb2bdfaf3351e > > Notice that, according to the current model at least, the state in > the above "exists" clause remains forbidden _after removal of the > smp_mb__after_spinlock() barrier. In this sense, if you want, the > inline comment (I contributed to) is misleading/incomplete. :-/ 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. 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)