Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp388838lqh; Tue, 7 May 2024 02:12:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2EZYqunY6VeNvZfuEZwZXbrbz3+rkxix/4lFV7AwFnXA7sZYcGTiv6BDgODTaVki2xCcrjAqJxyOe+EuxIJGOuw+vt2DFiro2FLQnzw== X-Google-Smtp-Source: AGHT+IEMThREIJcQG2XLMz2fm6ePtoFoeDZWqI5fXDqLP3U0ZcPSxo/L/0G7Jonlz57NDq9szEe5 X-Received: by 2002:a05:620a:2a0c:b0:790:76ae:ab0f with SMTP id o12-20020a05620a2a0c00b0079076aeab0fmr15518550qkp.64.1715073125322; Tue, 07 May 2024 02:12:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715073125; cv=pass; d=google.com; s=arc-20160816; b=h7l+7INzJQ8zlQH8hXo/BOREuMKo5uDukDgNyK/0w44hgnjZgnJSdZjDqEMyV/miif nIOZLjvxyXmN9VzB518wfOwNEd0zHfm0cJnPmqQAvA8E0OTR4PkE9fbQRJQpid4t4Bsg WUBLdEji7yZ/+BEhKPWA0LzBsEFgtPzuuYhxbHZi9NfGlgHvy1E+l4QC6zYNPbsMn0+p 6U3cYFMZoaklPzP3GER47BHm2yzO+uywzpD2+MOrrH2sZ/uvPPP8e3fOhk0ivXJFtYez Mh6iC4o8O9CP4UAJ1KSj/MznHbYeVOkU/ZWur9C7D20bauNDsq9tPvfb92dBc9iLas1r R2BA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=lkxGWFtglR1FbdlOglWg1kpNqpTvTn2VEWO+q4aoFHw=; fh=GKNlTCmcMHi4VHR/wtXsPuflURa+Czols/7Ku/bAurE=; b=iWPnY8Y1hsvsPJUzevHJVM5tDYkriteYWjcdAjwxHUhKta5/UGLJyZtY8F6EHuBaVy Sv7jTEavwRo/vm43GEI0loDCwoaMLw3C27Ygv2x9Zvx9WJ4hHzRYlCOG+Fr5iH533hvk GmdDfLzTTL3bx3L0OMEFH773ov7i6F7hFCLPO4JnXTBwanGjidCR+U2QsTXEMsgj/69C aYLqP0muQFqMlq/d/osqeQcH4HDiOHI6eK+gxXnAz7senaZdCRiYbTSJPAMnjO+l5PeF tY9Q5f/p+uRYno1E2heLAlZNRLT+leSVUSeuPtH16umGTSEUoKYStQRJkKROW9MSTsjS apNQ==; 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-170915-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170915-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l6-20020a05620a28c600b0079065cff3aesi11601892qkp.754.2024.05.07.02.12.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 02:12:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170915-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; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-170915-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170915-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D8F371C21319 for ; Tue, 7 May 2024 09:12:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46B2114D6F8; Tue, 7 May 2024 09:11:58 +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 3D6BF6BFC0; Tue, 7 May 2024 09:11:54 +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=1715073117; cv=none; b=oqzXnMjjHJXUi43kpNBrdfh1Z5aaolu2w08440qnU5h/KiYWNRMS1884RCL+Ll11vWmi4QxmXuB8ALdk/7XiR52UTy8jbRzNWOs/mm2STu0p1R5fMhePQ69wyVvM1FtCoNLpTM3SMQXi0+F4GDK5uwJqH2YVvT41XC2psShkeLQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715073117; c=relaxed/simple; bh=YHXlC7kJ8K1unV8F/MZ9J57OGBK3Citlye2x7wU1iwo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ibGOO5FFEL1zWsv57/rwCUAAN5XE/A5qnX5TMry9KHnMOV4xRVAlxBfAntKdvwoWgJZtEAiG2uYQbmEWQI46YS3tz0bojT+GLmPaQ/opmUfI25qx79Q2ByweEUcksSPGZKSuEdlTFbeQWNcK/ufw58U3QGNGWutbhrZZH/GNb4A= 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.29]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4VYXCb0gGNz9v7fr; Tue, 7 May 2024 16:54:51 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id A26CE14074A; Tue, 7 May 2024 17:11:40 +0800 (CST) Received: from [10.45.158.162] (unknown [10.45.158.162]) by APP2 (Coremail) with SMTP id GxC2BwB3Yyc+8DlmamutBw--.32210S2; Tue, 07 May 2024 10:11:40 +0100 (CET) Message-ID: Date: Tue, 7 May 2024 11:11:19 +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 To: paulmck@kernel.org, luc.maranget@inria.fr 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, 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> From: Jonas Oberhauser 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:GxC2BwB3Yyc+8DlmamutBw--.32210S2 X-Coremail-Antispam: 1UD129K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p/ Am 5/6/2024 um 8:00 PM schrieb Paul E. McKenney: > 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. At least the herd and Dat3M implementations seem to be doing that, at least according to this thread sent to me by Hernan. https://github.com/herd/herdtools7/issues/384#issue-1243049709 > >>> 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! :P >> 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? I suspect that it doesn't work out of the box because of some of the implicit magic herd is doing that could get in the way, so I'd need some help from Luc to actually turn this into a patch that can be tested. (or at least confirmation that just by changing a few things in the .def & .bell files we can sidestep the implicit behaviors). But at least in my proofs it seems to be equivalent. (there may still be differences in opinion on what some herd things mean, so what I/Viktor have formalized as the semantics of the herd model may not be exactly the behavior of LKMM in herd. hence testing is necessary too as a sanity check) best wishes, jonas