Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3126454lqo; Tue, 14 May 2024 23:45:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUS4gqJK3N2/9nDX7+ven8LNzd7z1H3GL+pbPuJHiEN7r82bcE0VP7RW8poWlIZUhawp9F63uoVL8GuglVnEAs1HJzpnJX+GtQ+08809g== X-Google-Smtp-Source: AGHT+IFVx5o4JL1GSj9D0CTy8mfQh9IaoNUj+9RIReB+OR5i9XcXhN2Ei/zCHRmSfNZrgyOCXsNf X-Received: by 2002:a05:6402:14d5:b0:574:ed8b:eb1e with SMTP id 4fb4d7f45d1cf-574ed8bec46mr1627569a12.10.1715755539401; Tue, 14 May 2024 23:45:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715755539; cv=pass; d=google.com; s=arc-20160816; b=FXRkk9Zf7/e9DKsVtq0JNxkbyCX+tU0PAF+6NkBW0DDV0hEuq/Gham6YNikSeTY1vA THqzU2fq94GOyruosrjMpU7F4HLSrAXj5VDD9BDF/GcHA0C1NBMDpO+HG/KOeiI6eOJu SEBdJ4aAibMF39vXoLNMJyFUKv0SiaWc1Bqzar3MJorx14X0bGtYCWqYTLLpaMege/GO Nv4aCtm5YaWusp9gzvPTTfTVxG5EXVRW/gwEYEs6Gq+Ct7HGuqvHvv34PI5nwWisjTv8 kwBNrENEv2IXzyOW8mKkIadSONEV4ZsryHxcJJieDjczyDWY/CbcEg2cy0nCv8si8MX1 zi3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=pyRBzkeiWX7MKJ5qax+CPuCjSArB+LXsRtEoCAPzkgk=; fh=99b7zMddJtFd4cQhmPd1aP1+S+uS+74yYD/dBMIYUhw=; b=dizPFl8SmaPpra6h+3OHCmpsuUteW0SWQVY4c5megjnlwK1ZQKjGmssZKkBpht1D48 OSX6kTqnacLc2l/q3bkrXqpRrEa0DGg7D4dm0Hs7iaLepWxz4KsoIb4fWgJyLaNvjDG4 5gbRQKz/PwGHWLX6snHadn0FVpPjGDmQnU3ktPwZii+d9VeCEGGlBBSJ+WVkm6oWwWI6 tUQWFmPSE2lB9SO3y1n50OHIvy2f7mj0gf5/T6gwQOebRhurDjHkapjscDabloJmnKSz eRYazPYweNK8LW9GwSEh9kVSR1lre4X6dzNRCfpm8jxWIvMyvIm1wW4FcC1ZIsHePMlr MLSA==; 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-179531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179531-linux.lists.archive=gmail.com@vger.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 4fb4d7f45d1cf-574306695f4si5384586a12.114.2024.05.14.23.45.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 23:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179531-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; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-179531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179531-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 024D71F20F69 for ; Wed, 15 May 2024 06:45:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 432C33FBA7; Wed, 15 May 2024 06:45:10 +0000 (UTC) Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) (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 243ACEA4; Wed, 15 May 2024 06:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755509; cv=none; b=jPlJMzVVseD3xH5KvpVHIvQWxVM7y/0rq9YvtgdM/vFDLCfjx3RG+Vc6e8MnvDz02s2NYZZxVcRuRwWDtBnm4ehnPD0PjkWBS7nkVFwxiLQorP6zd2Y/CkHpR17grwMoEofI5l6RjOVexqBMkk6nYpEZGjVhrss3mHQKI0g6P/E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755509; c=relaxed/simple; bh=rr/1kVdootVVGU7hj5fWVS2fCteWe7tsqWLCJvLLKkU=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=U0fARLmRDdCvyf3/a3yc8ZKP1U1orMmpCZXFrvi08wnGlD88Vu0f24ee2o9f7KuJvaSd3PiHcfYa0C/q63yd8udhvi6lmjVU+oEmHRcmxR/0Qy/eD69Be8b+kw8TSh354KmhShExDXlN9SR1iQdJHgGJnz7Lg1AyzZTLuV3Jwuw= 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.46 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 frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4VfNZN0Twxz9v7Hl; Wed, 15 May 2024 14:27:56 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id F0B4A1404D9; Wed, 15 May 2024 14:44:48 +0800 (CST) Received: from [10.221.98.131] (unknown [10.221.98.131]) by APP2 (Coremail) with SMTP id GxC2BwBnoCTQWURm3bwvCA--.4342S2; Wed, 15 May 2024 07:44:48 +0100 (CET) Message-ID: <143273e9-1243-60bc-4fb0-eea6fb3de355@huaweicloud.com> Date: Wed, 15 May 2024 08:44:30 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Hernan Ponce de Leon Subject: Re: [PATCH memory-model 2/4] Documentation/litmus-tests: Demonstrate unordered failing cmpxchg To: paulmck@kernel.org, Jonas Oberhauser Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, mingo@kernel.org, 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> <16381d02-cb70-4ae5-b24e-aa73afad9aed@huaweicloud.com> <2a695f63-6c9a-4837-ac03-f0a5c63daaaf@paulmck-laptop> Content-Language: en-US In-Reply-To: <2a695f63-6c9a-4837-ac03-f0a5c63daaaf@paulmck-laptop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:GxC2BwBnoCTQWURm3bwvCA--.4342S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAryDXF4kKFy3Wr1fAFW3Awb_yoW5uw4kpF yrKayUKrs7JrWUAw4Iva1jqF10vrZ3JFW5Xw15tryUAan8GF1FvFyYqrW5ury2yrsaka1j vr1Y9347Zry5AaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvKb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWUJVW8JwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7I2V7IY0VAS 07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_ WrylIxkvb40E47kJMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF 0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x07boZ2-UUUUU= X-CM-SenderInfo: xkhu0tnqos00pfhgvzhhrqqx5xdzvxpfor3voofrz/ On 5/6/2024 8:00 PM, Paul E. McKenney wrote: > On Mon, May 06, 2024 at 06:30:45PM +0200, Jonas Oberhauser wrote: >> Am 5/6/2024 um 12:05 PM schrieb Jonas Oberhauser: >>> Am 5/2/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? > > Yes, and unless I am too confused, LKMM currently does implement this. > Please let me know if I am missing something. > >>> 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) > > Addition of mixed-access support would be quite welcome! > >> 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] >> | ... > > Does this produce the results expected by the litmus tests in the Linux > kernel source tree and also those at https://github.com/paulmckrcu/litmus? > > Thanx, Paul I implemented in the dartagnan tool the changes proposed by Jonas (i.e. changing the mb definition in the cat model and removing the fences that were added programmatically). I run this using the ~5K litmus test I have (it should include everything from the source tree + the non-LISA ones from your repo). I also checked with the version of qspinlock discussed in [1]. I do get the expected results. Hernan [1] https://lkml.org/lkml/2022/8/26/597