Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp726319lqb; Fri, 24 May 2024 11:10:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5svRdKni3uGJu31j/zEa6h7U8vPeW0+LRk9lM6HrOpWlN9Ff55QEGeekXqk8WNFbhwydsx9KAqyu3PiWRq2SOVUfEGSMfXcdL+F6eOg== X-Google-Smtp-Source: AGHT+IHNr5S3lr+CgzHrbxUS58We9ugIIDlvTl/sha4YbRm/jaxC2u6GLdbcQ3E8xo7mLD3mh5ob X-Received: by 2002:a17:906:c9c6:b0:a54:c130:21fd with SMTP id a640c23a62f3a-a62642d9ca3mr208152266b.13.1716574207895; Fri, 24 May 2024 11:10:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716574207; cv=pass; d=google.com; s=arc-20160816; b=hcXl+YxGd8F2TfCpw4RHoRr5Qfq9XL5pzN22u+lWvhMpLd5OOaRVpi3LZVbfc/4xmC d6ek1WIqyWiQ1nJqxuSBksPbM9Cj1zLgCshvt+jsWbIKFvkqEn96S/lFaCm0pApaeHkq AXwfNC3Bwn36kFZPqL8z4bapl/Uh3inYJ/76S7+1MQqzShqK3+IGdusK3T2D3zuz+HHq vh5thNW0ZdxPS3/pDdTP+UEKwsYbtHQNnloV2tuPyetsRIkfmkyUBx9izKZXr0ZwFNCO 8ekiSsZGyVOCczEj4wKBjvNONbe+wphptFwRngKHE9jpimXOcw4tYUkB5wz+4wQmiA8q Tx7g== 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=ZjhZ0Me0nPj+NzUCnoQUdFDdkh8iOQTKt0GaqXEd/DM=; fh=pWO0V5jmq4KMxeBe1q2zhvlHXkDuIitXQhSC4mwFpck=; b=UrVLwlpKrO5dw9lhAvQfgGkefRJzUNe+SP+s5biAMa9PEYwS9gh/doIypwtY4yqEUX ZXIA5IHaqglrppFD2p++G/nnEddheG5QEIumnlL0tyGVOeBP3nlt4RPhCqzLa6Q9tm7k 4eWI5Zf9JTeXc09CD+XcUkOJsJbhgE6h685immOnS2/IcKW0TeTHtHfiIWjUa3MRptgS RZlFsMQjzjLu3J5YoCS15cYC7Iw+YLG8/ueVMEVqwGZ+HcnNCTOElMp+hJFyEh+qPuQL 3Uee9/QL5Xec2nMSiRa9j0DCzh/NLdqeEWNZRjcB3AZIETUx0+yVETB3f0/0jJd6LNNc pBPg==; 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-188988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188988-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 a640c23a62f3a-a626cc64295si103425066b.523.2024.05.24.11.10.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 11:10:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188988-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-188988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188988-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 6F6621F21B6F for ; Fri, 24 May 2024 18:10:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA90A3BBCB; Fri, 24 May 2024 18:10:00 +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 D43223B1A3; Fri, 24 May 2024 18:09:57 +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=1716574200; cv=none; b=h7JVcpu1e3hj/oxaPzf4WC3TGfa8U2+FfeFh9PspF7Y2Ee71ch1ZMoV+WSvoc0Pk+w5CaMMtfhpoG72WixHVmg1iNz8yq3+tVsxLtrNljPZ+lK7LXQRzW/d15XdAYA3t3NUsRQbhYZ8NMfJJZFdGVZyP0ueLII92NVvdyaqQdNw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716574200; c=relaxed/simple; bh=OpEg4tnxAfumgql19ci41Ux2BVE1kkAJMz9U8MpGbOc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VfO07I6ZinYUD6UjwkT8gyP9ovPGCgCsrYAsxybhBp64Fh3DyyvkKN3C61XAwULohCdx5f0EjSIIRe1Joj7smZFwjM3p4ulkXEHRZsxl1t1RHHTg7o/NK/VGCYrQBI5/s0pWiz9uwuJKSs9+51s5dT/fg2bb0oE0jO+Cij8Bqnw= 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 4VmCL815Fvz9v7Hm; Sat, 25 May 2024 01:52:32 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id C0124140794; Sat, 25 May 2024 02:09:41 +0800 (CST) Received: from [10.45.153.18] (unknown [10.45.153.18]) by APP2 (Coremail) with SMTP id GxC2BwBXkSXb11BmqTLTCA--.35053S2; Fri, 24 May 2024 19:09:41 +0100 (CET) Message-ID: <99cc68a9-477a-4ebe-b769-465a4016bdf6@huaweicloud.com> Date: Fri, 24 May 2024 20:09:28 +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: LKMM: Making RMW barriers explicit To: Alan Stern , Boqun Feng Cc: Hernan Ponce de Leon , "Paul E. McKenney" , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@meta.com, parri.andrea@gmail.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, Joel Fernandes References: <58042cf3-e515-4e5f-ab48-1d0d6123c9e9@huaweicloud.com> <6174fd09-b287-49ae-b117-c3a36ef3800a@rowland.harvard.edu> <7bd31eca-3cf3-4377-a747-ec224262bd2e@huaweicloud.com> <35b3fd07-fa85-4244-b9cb-50ea54d9de6a@rowland.harvard.edu> <9256f95a-858b-435f-b40a-a4508a1096c9@rowland.harvard.edu> From: Jonas Oberhauser In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:GxC2BwBXkSXb11BmqTLTCA--.35053S2 X-Coremail-Antispam: 1UD129KBjvJXoW3GryxGry3Kw4rAF18CrWDCFg_yoWxJw17pF W3Ga4DKw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024 um 4:53 PM schrieb Alan Stern: > On Fri, May 24, 2024 at 07:34:06AM -0700, Boqun Feng wrote: >> On Fri, May 24, 2024 at 10:14:25AM -0400, Alan Stern wrote: >> [...] >>>> Not really, RMW events contains all events generated from >>>> read-modify-write primitives, if there is an R event without a rmw >>>> relation (i.e there is no corresponding write event), it's a failed RWM >>>> by definition: it cannot be anything else. >>> >>> Not true. An R event without an rmw relation could be a READ_ONCE(). >> >> No, the R event is already in the RWM events, it has come from a rwm >> atomic. > > Oh, right. For some reason I was thinking that an instruction could > belong to only one set, R or RMW. But that doesn't make sense. I thought the same, so I perhaps contributed to that confusion. > >>> Or a plain read. The memory model uses the tag to distinguish these >>> cases. >>> >>>>> that it would work is merely an artifact of herd7's internal actions. I >>>>> think it would be much cleaner if herd7 represented these events in some >>>>> other way, particularly if we can tell it how. >>>>> >>>>> After all, herd7 already does generate different sets of events for >>>>> successful (both R and W) and failed (only R) RMWs. It's not such a big >>>>> stretch to make the R events it generates different in the two cases. >>>>> >>>> >>>> I thought we want to simplify the herd internal processing by avoid >>>> adding mb events in cmpxchg() cases, in the same spirit, if syntactic >>>> tagging is already good enough, why do we want to make herd complicate? >>> >>> Herd7 already is complicated by the fact that it needs to handle >>> cmpxchg() instructions in two ways: success and failure. This >>> complication is unavoidable. Adding one extra layer (different tags for >>> the different ways) is an insignificant increase in the complication, >>> IMO. And it's a net reduction when you compare it to the amount of >>> complication currently in the herd7 code. >>> >>> Also what about cmpxchg_acquire()? If it fails, it will generate an R >>> event with an acquire tag not in the rmw relation. I would like that, but that is not the current implementation, a failed atomic_compare_exchange always produces a R*[once]; this behavior is currently hardcoded in herd7. >>> There is no way to >>> tell such events apart from a normal smp_load_acquire(), and so the .cat >>> file would have no way to know that the event should not have acquire >>> semantics. I guess we would have to rename this tag, as well. >> >> No, >> >> let read_of_rmw = (RMW & R) >> let fail_read_of_rmw = read_of_rmw / dom(rmw) >> let fail_cmpxchg_acquire = fail_read_of_rmw & [Acquire] >> >> gives you all the failed cmpxchg_acquire() apart from a normal >> smp_load_acquire(). > > Yes, I see. Using this approach, no further changes to herd7 or the > def file would be needed. We would just have to add 'mb to the > Accesses enumeration and to the list of tags allowed for an RMW > instruction. > > Question: Since R and RMW have different lists of allowable tags, how > does herd7 decide which tags are allowed for an event that is in both > the R and RMW sets? After looking over the patch draft for herd7 written by Hernan [1], my best guess is: it doen't. It seems that after herd7 detects you are using LKMM it simply drops all tags except 'acquire on read and 'release on store. Everything else becomes 'once (and 'mb adds some F[mb] sometimes). That means that if one were to go through with the earlier suggestion to distinguish between the smp_mb() Mb and the cmpxchg() Mb, e.g. by calling the latter RmwMb, current herd7 would always erase the RmwMb tag because it is not called "acquire" or "release". The same would happen of course if you introduced an RmwAcquire tag. So there are several options: - treat the tags as a syntactic thing which is always present, and specify their meaning purely in the cat file, analogous to what you have defined above. This is personally my favorite solution. To implement this in herd7 we would simply remove all the current special cases for the LKMM barriers, which I like. However then we need to actually define the behavior of herd if an inappropriate tag (like release on a load) is provided. Since the restriction is actually mostly enforced by the .def file - by simply not providing a smp_store_acquire() etc. -, that only concerns RMWs, where xchg_acquire() would apply the Acquire tag to the write also. The easiest solution is to simply remove the syntax for specifying restrictions - it seems it is not doing much right now anyways - and do the filtering inside .bell, with things like (* only writes can have Release tags *) let Release = Release & W \ (RMW \ rng(rmw)) One good thing about this way is that it would work even without modifying herd, since it is in a sense idempotent with the transformations done by herd. FWIW, in our internal weak memory model in Dresden we did exactly this, and use REL for the syntax and Rel for the semantic release ordering to make the distinction more clear, with things like: let Acq = (ACQ | SC) & (R | F) let Rel = (REL | SC) & (W | F) (SC is our equivalent to LKMM's Mb) - treat the tags as semantic markers that are only present or not under some circumstances, and define the semantics fully based on the present tags. The circumstances are currently hardcoded in herd7, but we should move them out with some syntax like __cmpxchg{acquire}{once}. This requires touching the parser and of course still has the issue with the acquire tag appearing on the store as well. - provide a full syntax for defining the event sequence that is expected. For example, for a cmpxchg we could do cmpxchg = { F[success-cmpxchg]; c = R&RMW[once]; if (c==v) { W&RMW[once]; } F[success-cmpxchg] } and then define in .bell that a success-cmpxchg is an mb if it is directly next to a cmpxchg that succeeds. The advantage is that you can customize the representation to whatever kernel devs thing is the most intuitive. The downside is that it requires major rewrites to herd7, someone to think about a reasonable language for specifying this etc. Best wishes, jonas [1] https://github.com/herd/herdtools7/pull/865