mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hernan Ponce de Leon <hernan.poncedeleon@huaweicloud.com>
To: Alan Stern <stern@rowland.harvard.edu>,
	Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
Cc: paulmck@kernel.org, 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, dlustig@nvidia.com, joel@joelfernandes.org,
	urezki@gmail.com, quic_neeraju@quicinc.com, frederic@kernel.org,
	linux-kernel@vger.kernel.org, lkmm@lists.linux.dev
Subject: Re: [PATCHv2 0/4] tools/memory-model: Define more of LKMM in tools/memory-model
Date: Mon, 29 Jul 2024 15:30:37 +0200	[thread overview]
Message-ID: <eb9548de-e66e-3dcd-9136-8702a5bc2934@huaweicloud.com> (raw)
In-Reply-To: <d6a76968-d10b-c60b-245a-f58116eca6af@huaweicloud.com>

On 7/12/2024 10:06 AM, Hernan Ponce de Leon wrote:
> On 6/10/2024 10:38 AM, Hernan Ponce de Leon wrote:
>> On 6/8/2024 3:00 AM, Alan Stern wrote:
>>> On Wed, Jun 05, 2024 at 09:58:42PM +0200, Jonas Oberhauser wrote:
>>>>
>>>>
>>>> Am 6/4/2024 um 7:56 PM schrieb Alan Stern:
>>>>> Just to clarify: Your first step encompasses patches 1 - 3, and the
>>>>> second step is patch 4.  The first three patches can be applied 
>>>>> now, but
>>>>> the last one needs to wait until herd7 has been updated.  Is this all
>>>>> correct?
>>>>
>>>> Exactly.
>>>
>>> With regard to patch 4, how much thought have you and Hernan given to
>>> backward compatibility?  Once herd7 is changed, old memory model files
>>> will no longer work correctly.
>>>
>>
>> Honestly, I did not think much about this (at least until Akira 
>> mentioned in my PR). My hope was that changes to the model could be 
>> back-ported to previous kernel versions. However that would not work 
>> for existing out-of-tree files.
>>
>> My question is: is compatibility with out-of-tree files really a 
>> requirement? I would argue that if people are using outdated models, 
>> they may get wrong results anyway. This is because some of the changes 
>> done to lkmm during the last few years change the expected result for 
>> some litmus tests.
>>
>> Hernan
> 
> I pushed some new changes to the code for backward compatibility [1]. 
> The series also needs the patch at the bottom to properly deal with the 
> ordering of failing CAses and non-returning operations. With it, all 
> litmus tests return the correct result (the script needs to pass option 
> -lkmm-legacy false to herd).

I have been playing around with an alternative to this.

Rather than implementing this as an "option", I can implemented it as a 
"model variant (*)" and add this to the model

flag ~empty (if "lkmmlatest" then 0 else _)
   as new-lkmm-models-require-variant-lkmmlatest

If the user forgets to set the variant for the new model, herd7 will 
flag the executions showing that something is off.

To be fully backward compatible, we would need to backport this to old 
models

flag ~empty (if "lkmmlatest" then 1 else _)
   as new-lkmm-models-require-variant-lkmmlatest

If the user (wrongly) sets the variant for an old model, the the 
executions will be flagged.

Any thoughts?

Hernan

(*) This trick seems to be used for some arm models

https://github.com/herd/herdtools7/blob/master/herd/libdir/arm-models/mixed/ec.cat#L66C1-L67C67

> 
> Implementation-wise, there are two things that I would like to have:
> 
> - atomic_add_unless implementation is treated different than the rest 
> and it is one of the few remaining cases where memory orderings are 
> hardcoded [2]. I would like to define it in the .def file as
> 
>      atomic_add_unless(X,V,U) __atomic_add_unless{ONCE}(X,V,U)
> 
> - "deref" and "lderef" instructions seems to add a "rb_dep" fence. None 
> of the model files (.cat, .def, .bell) refers to "rb_dep" so this looks 
> useless to me. However, I never checked the details of these 
> dereferencing instruction so I might be missing something. Maybe Paul 
> can clarify.
> 
> Hernan
> 
> [1] https://github.com/herd/herdtools7/pull/865
> [2] https://github.com/herd/herdtools7/issues/868
> 
> 
> diff --git a/tools/memory-model/linux-kernel.def 
> b/tools/memory-model/linux-kernel.def
> index 001366ff3fb4..5a40c2cad39b 100644
> --- a/tools/memory-model/linux-kernel.def
> +++ b/tools/memory-model/linux-kernel.def
> @@ -32,10 +32,10 @@ xchg(X,V)  __xchg{MB}(X,V)
>   xchg_relaxed(X,V) __xchg{ONCE}(X,V)
>   xchg_release(X,V) __xchg{RELEASE}(X,V)
>   xchg_acquire(X,V) __xchg{ACQUIRE}(X,V)
> -cmpxchg(X,V,W) __cmpxchg{MB}(X,V,W)
> -cmpxchg_relaxed(X,V,W) __cmpxchg{ONCE}(X,V,W)
> -cmpxchg_acquire(X,V,W) __cmpxchg{ACQUIRE}(X,V,W)
> -cmpxchg_release(X,V,W) __cmpxchg{RELEASE}(X,V,W)
> +cmpxchg(X,V,W) __cmpxchg{MB,ONCE}(X,V,W)
> +cmpxchg_relaxed(X,V,W) __cmpxchg{ONCE,ONCE}(X,V,W)
> +cmpxchg_acquire(X,V,W) __cmpxchg{ACQUIRE,ONCE}(X,V,W)
> +cmpxchg_release(X,V,W) __cmpxchg{RELEASE,ONCE}(X,V,W)
> 
>   // Spinlocks
>   spin_lock(X) { __lock(X); }
> @@ -63,14 +63,14 @@ atomic_set(X,V) { WRITE_ONCE(*X,V); }
>   atomic_read_acquire(X) smp_load_acquire(X)
>   atomic_set_release(X,V) { smp_store_release(X,V); }
> 
> -atomic_add(V,X) { __atomic_op(X,+,V); }
> -atomic_sub(V,X) { __atomic_op(X,-,V); }
> -atomic_and(V,X) { __atomic_op(X,&,V); }
> -atomic_or(V,X)  { __atomic_op(X,|,V); }
> -atomic_xor(V,X) { __atomic_op(X,^,V); }
> -atomic_inc(X)   { __atomic_op(X,+,1); }
> -atomic_dec(X)   { __atomic_op(X,-,1); }
> -atomic_andnot(V,X) { __atomic_op(X,&~,V); }
> +atomic_add(V,X) { __atomic_op{NORETURN}(X,+,V); }
> +atomic_sub(V,X) { __atomic_op{NORETURN}(X,-,V); }
> +atomic_and(V,X) { __atomic_op{NORETURN}(X,&,V); }
> +atomic_or(V,X)  { __atomic_op{NORETURN}(X,|,V); }
> +atomic_xor(V,X) { __atomic_op{NORETURN}(X,^,V); }
> +atomic_inc(X)   { __atomic_op{NORETURN}(X,+,1); }
> +atomic_dec(X)   { __atomic_op{NORETURN}(X,-,1); }
> +atomic_andnot(V,X) { __atomic_op{NORETURN}(X,&~,V); }
> 
>   atomic_add_return(V,X) __atomic_op_return{MB}(X,+,V)
>   atomic_add_return_relaxed(V,X) __atomic_op_return{ONCE}(X,+,V)
> @@ -127,10 +127,10 @@ atomic_xchg(X,V) __xchg{MB}(X,V)
>   atomic_xchg_relaxed(X,V) __xchg{ONCE}(X,V)
>   atomic_xchg_release(X,V) __xchg{RELEASE}(X,V)
>   atomic_xchg_acquire(X,V) __xchg{ACQUIRE}(X,V)
> -atomic_cmpxchg(X,V,W) __cmpxchg{MB}(X,V,W)
> -atomic_cmpxchg_relaxed(X,V,W) __cmpxchg{ONCE}(X,V,W)
> -atomic_cmpxchg_acquire(X,V,W) __cmpxchg{ACQUIRE}(X,V,W)
> -atomic_cmpxchg_release(X,V,W) __cmpxchg{RELEASE}(X,V,W)
> +atomic_cmpxchg(X,V,W) __cmpxchg{MB,ONCE}(X,V,W)
> +atomic_cmpxchg_relaxed(X,V,W) __cmpxchg{ONCE,ONCE}(X,V,W)
> +atomic_cmpxchg_acquire(X,V,W) __cmpxchg{ACQUIRE,ONCE}(X,V,W)
> +atomic_cmpxchg_release(X,V,W) __cmpxchg{RELEASE,ONCE}(X,V,W)
> 
>   atomic_sub_and_test(V,X) __atomic_op_return{MB}(X,-,V) == 0
>   atomic_dec_and_test(X)  __atomic_op_return{MB}(X,-,1) == 0


  reply	other threads:[~2024-07-29 13:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 15:29 Jonas Oberhauser
2024-06-04 16:00 ` [PATCHv2 1/4] tools/memory-model: Legitimize current use of tags in LKMM macros Jonas Oberhauser
2024-06-04 16:04 ` [PATCHv2 2/4] tools/memory-model: Define applicable tags on operation in tools/ Jonas Oberhauser
2024-06-05  4:25   ` Boqun Feng
2024-06-05  9:54     ` Jonas Oberhauser
2024-06-04 16:04 ` [PATCHv2 3/4] tools/memory-model: Define effect of Mb tags on RMWs " Jonas Oberhauser
2024-06-05  4:28   ` Boqun Feng
2024-06-05 13:40     ` Alan Stern
2024-06-05 19:56     ` Jonas Oberhauser
2024-06-17 22:43       ` Boqun Feng
2024-06-04 16:05 ` [PATCHv2 4/4] tools/memory-model: Distinguish between syntactic and semantic tags Jonas Oberhauser
2024-06-04 17:56 ` [PATCHv2 0/4] tools/memory-model: Define more of LKMM in tools/memory-model Alan Stern
2024-06-05 19:58   ` Jonas Oberhauser
2024-06-06 16:37     ` Paul E. McKenney
2024-06-10  8:04       ` Jonas Oberhauser
2024-06-10 15:21         ` Paul E. McKenney
2024-06-08  1:00     ` Alan Stern
2024-06-10  8:38       ` Hernan Ponce de Leon
2024-07-12  8:06         ` Hernan Ponce de Leon
2024-07-29 13:30           ` Hernan Ponce de Leon [this message]
2024-07-29 14:45             ` Jonas Oberhauser
2024-07-29 15:19               ` Hernan Ponce de Leon
2024-07-29 15:44                 ` Jonas Oberhauser
2024-07-29 15:53                   ` Hernan Ponce de Leon
2024-07-29 16:05                     ` Jonas Oberhauser
2024-06-10  9:08       ` Jonas Oberhauser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb9548de-e66e-3dcd-9136-8702a5bc2934@huaweicloud.com \
    --to=hernan.poncedeleon@huaweicloud.com \
    --cc=akiyks@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=frederic@kernel.org \
    --cc=j.alglave@ucl.ac.uk \
    --cc=joel@joelfernandes.org \
    --cc=jonas.oberhauser@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkmm@lists.linux.dev \
    --cc=luc.maranget@inria.fr \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=quic_neeraju@quicinc.com \
    --cc=stern@rowland.harvard.edu \
    --cc=urezki@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®