Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp5782lqh; Mon, 6 May 2024 09:31:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQwN3DZ38Im/GhGPc8cwSQngLPvzTKvIXofrF0FBA9RFsUsKK28QLilOM8D1WWlkPAuaAiGh08iuw4+J1I1gaPUC0vV0ejNnHzAbQcsQ== X-Google-Smtp-Source: AGHT+IExioFsQZAU9u3/vXd6Z4MoA1JyQDgc7QimqvHSWKxilVgOmdIj+PyA3fgWRCWfEhUxTwzH X-Received: by 2002:a17:906:2ec4:b0:a59:a639:55c4 with SMTP id s4-20020a1709062ec400b00a59a63955c4mr3821695eji.1.1715013096042; Mon, 06 May 2024 09:31:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715013096; cv=pass; d=google.com; s=arc-20160816; b=nt1VBAJxRL+f/Bc+WfMPRRzZWI2s0fe/UUYsxiyekDQPOckZfOMijZLwJg0jj2rdkW l2NzwktyJaRhAF7AZgB5EpU9Er08jihXFNPbV5BcjWRxu7mhHVv9sTv4IXNTCWeu/W1r ZhstI4LnaD29bXcYi1tRdELNnKRFKCzHAiOd9uOvXx6muepS4Z/zMBtdO0suxuyADb1A qgYs4sYsEdKHIW2ubAp4ftbHAgjqzV3hC62FbIQWuvZ3YZN6QHv5JCVbIY4DZke81nK2 zpYOzSRCPQx4j9Zr6ERKPQdyJvqJl0cYqsnuC7vrLZ+dcfwHplZUkbbLPX3NYrjep0G3 0tJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=/YVwBX2FSYtg5gJtv8TjeipEVeae+iMDOt6ZaRezUGk=; fh=KssM8PRYlzWzbtpYA/+OeQ/pgblRcls1YT7HESXh64I=; b=NoTL+L8B9P5CFOhc1ryrXh4oqKY6QFjr/r34FQGZPJO8TaP0k6SCg0EE8XSqxhJDEn JmHlXloWbctDVJ3icyNSfENi01XFYPnFAVxZHdMD6YXiMnRPP9+U6y9j+eZbNfac2pEn 68pXr2umDRyfZ6tjg8ndIjjhwKfIxkBli4M6xvIIxC+ucZ8XoJxgolFBhwRk5KGTEoNw MFA/6pJei6kIQph3Jgxt9Ns/cHeo+rK1h07bYhhhVC4Sh7MflfxmrzU0KyWD2VjCny+P 3e99vi88k4bdSei1OGzLEd4LaYD2yyeAFisGMNN/fV5FKIT9OPrmEkzeL1V7PQkegHJG tD9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-170178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170178-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l22-20020a170906795600b00a59beb28948si2339222ejo.218.2024.05.06.09.31.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 09:31:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-170178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170178-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B8E821F24BF2 for ; Mon, 6 May 2024 16:31:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A65D156F4B; Mon, 6 May 2024 16:31:22 +0000 (UTC) Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) (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 E95E2156F34; Mon, 6 May 2024 16:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715013081; cv=none; b=BISXfW7sg5B2S6V9jTIxHbzgiGviq2ISst+Rq3HEmNDY9ZM7wd8gvzSBvHPr2x3NhN3TFTNIYnxmV7SXw0CjnqHkRX8ELiI2PkGpJwWPPeNc4s3Ctff3NW6WkTDSCwOKA7eyfkZKPxcUx45aLm5H9Xz0rO9tRcDIaDe2fOrdsQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715013081; c=relaxed/simple; bh=Er0V6WEj6xcmIloHj8PhBrFsH5cQFszCcAIUgKVv2lg=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=j534JZnNFdYMpB+o1jNt9vJiI7A3frUYg3KO2eT5zBtOENvg6P5mfnEZicrfaQ04tjvZdsNCnBdu99hvT3ftIcbiljQ2l8sDFp2zlakLhTOHjsxKV/1vvwt3uNli+LuBQIh3t3aixPD546MeyiL/zsXuBhBXjDI74ZiJ2ECF2fY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4VY6166k6Xz9xHvY; Tue, 7 May 2024 00:14:18 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id 31CD5140444; Tue, 7 May 2024 00:31:04 +0800 (CST) Received: from [10.48.135.242] (unknown [10.48.135.242]) by APP2 (Coremail) with SMTP id GxC2BwDHASa4BTlmcv6hBw--.23635S2; Mon, 06 May 2024 17:31:03 +0100 (CET) Message-ID: <16381d02-cb70-4ae5-b24e-aa73afad9aed@huaweicloud.com> Date: Mon, 6 May 2024 18:30:45 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH memory-model 2/4] Documentation/litmus-tests: Demonstrate unordered failing cmpxchg From: Jonas Oberhauser To: "Paul E. McKenney" , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, Frederic Weisbecker , Daniel Lustig , Joel Fernandes , Mark Rutland , Jonathan Corbet , linux-doc@vger.kernel.org References: <42a43181-a431-44bd-8aff-6b305f8111ba@paulmck-laptop> <20240501232132.1785861-2-paulmck@kernel.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:GxC2BwDHASa4BTlmcv6hBw--.23635S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr13Cw4kXw4UKr47Cr1Dtrb_yoW8Kryx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/2024 um 1:21 AM schrieb Paul E. McKenney: >> This commit adds four litmus tests showing that a failing cmpxchg() >> operation is unordered unless followed by an smp_mb__after_atomic() >> operation. > > So far, my understanding was that all RMW operations without suffix > (xchg(), cmpxchg(), ...) will be interpreted as F[Mb];...;F[Mb]. > > I guess this shows again how important it is to model these full > barriers explicitly inside the cat model, instead of relying on implicit > conversions internal to herd. > > I'd like to propose a patch to this effect. > > What is the intended behavior of a failed cmpxchg()? Is it the same as a > relaxed one? > > My suggestion would be in the direction of marking read and write events > of these operations as Mb, and then defining > > (* full barrier events that appear in non-failing RMW *) > let RMW_MB = Mb & (dom(rmw) | range(rmw)) > > > let mb = >     [M] ; fencerel(Mb) ; [M] >   | [M] ; (po \ rmw) ; [RMW_MB] ; po^? ; [M] >   | [M] ; po^? ; [RMW_MB] ; (po \ rmw) ; [M] >   | ... > > The po \ rmw is because ordering is not provided internally of the > rmw (removed the unnecessary si since LKMM is still non-mixed-accesses) This could also be written with a single rule: | [M] ; (po \ rmw) & (po^?; [RMW_MB] ; po^?) ; [M] > I suspect that after we added [rmw] sequences it could > perhaps be simplified [...] > No, my suspicion is wrong - this would incorrectly let full-barrier RMWs act like strong fences when they appear in an rmw sequence. if (z==1) || x = 2; || xchg(&y,2) || if (y==2) x = 1; || y =_rel 1; || || z=1; right now, we allow x=2 overwriting x=1 (in case the last thread does not propagate x=2 along with z=1) because on power, the xchg might be implemented with a sync that doesn't get executed until the very end of the program run. Instead of its negative form (everything other than inside the rmw), it could also be rewritten positively. Here's a somewhat short form: let mb = [M] ; fencerel(Mb) ; [M] (* everything across a full barrier RMW is ordered. This includes up to one event inside the RMW. *) | [M] ; po ; [RMW_MB] ; po ; [M] (* full barrier RMW writes are ordered with everything behind the RMW *) | [W & RMW_MB] ; po ; [M] (* full barrier RMW reads are ordered with everything before the RMW *) | [M] ; po ; [R & RMW_MB] | ... Good luck, jonas