|
Hi Julien,
Thanks for pointing this out.
I revisited the rationale for adding CLREX here, and I don't think there is a sufficient reason for Xen to do so.
I found a rejected RFC^[1] in Linux in 2015 to add CLREX in atomic operations. In that RFC, Linux arm maintainers said there is no need to add CLREX.
I also found a patch^[2] that makes LLVM emit CLREX on this path, with the rationale that keeping the monitor set might have a negative performance impact on some microarchitectures. However, I have not been able to find concrete microarchitecture-specific
evidence or measurements demonstrating such an impact.
Please consider this patch withdrawn.
Thanks for the review.
Regards,
Ryoji
From: Julien Grall <julien@xxxxxxx>
Sent: Wednesday, September 9, 2026 16:10
To: 岡本 涼二 <okamoto@xxxxxxxxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx <xen-devel@xxxxxxxxxxxxxxxxxxxx>
Cc: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>; Stefano Stabellini <sstabellini@xxxxxxxxxx>; Bertrand Marquis <bertrand.marquis@xxxxxxx>; Michal Orzel <michal.orzel@xxxxxxx>; Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
Subject: Re: [PATCH v2] xen/arm64/atomic: Clear exclusive monitor on cmpxchg failure
Hi Ryoji,
On 09/09/2026 08:12, Ryoji Okamoto wrote:
> When the value comparison fails in atomic_cmpxchg, the code branches
> out without executing stxr, leaving the exclusive monitor in the
> exclusive state set by ldxr.
>
> Add `clrex` to the failure path to explicitly clear the exclusive
> monitor.
The Xen atomics operations were originally taken from Linux. Looking at
the implementation there, I don't see a clrex on the failure path. Do
you have more details why we would want it?
Also, if this is necessary on arm64, then we most likely we want the
same for the arm32 implementation (including __atomic_add_unless()).
Cheers,
--
Julien Grall
|