* [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()
@ 2026-01-22 14:17 Uros Bizjak
2026-01-22 14:21 ` Jan Beulich
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Uros Bizjak @ 2026-01-22 14:17 UTC (permalink / raw)
To: xen-devel, linux-kernel
Cc: Uros Bizjak, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while
atomically clearing it. This was previously implemented using a
cmpxchg() loop.
Replace the cmpxchg() loop with a single xchg(), which provides the
same atomic get-and-clear semantics, avoids retry spinning under
contention, and simplifies the code.
The code on x86_64 improves from:
186: 8b 15 00 00 00 00 mov 0x0(%rip),%edx
18c: 89 d0 mov %edx,%eax
18e: f0 0f b1 0d 00 00 00 lock cmpxchg %ecx,0x0(%rip)
195: 00
196: 39 c2 cmp %eax,%edx
198: 75 ec jne 186 <...>
to just:
186: 87 05 00 00 00 00 xchg %eax,0x0(%rip)
No functional change intended.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
---
drivers/xen/mcelog.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/xen/mcelog.c b/drivers/xen/mcelog.c
index 4f65b641c054..abe658c73b7b 100644
--- a/drivers/xen/mcelog.c
+++ b/drivers/xen/mcelog.c
@@ -165,9 +165,7 @@ static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd,
case MCE_GETCLEAR_FLAGS: {
unsigned flags;
- do {
- flags = xen_mcelog.flags;
- } while (cmpxchg(&xen_mcelog.flags, flags, 0) != flags);
+ flags = xchg(&xen_mcelog.flags, 0);
return put_user(flags, p);
}
--
2.52.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()
2026-01-22 14:17 [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg() Uros Bizjak
2026-01-22 14:21 ` Jan Beulich
@ 2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:22 ` Andrew Cooper
2 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2026-01-22 14:21 UTC (permalink / raw)
To: Uros Bizjak
Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
xen-devel, linux-kernel
On 22.01.2026 15:17, Uros Bizjak wrote:
> The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while
> atomically clearing it. This was previously implemented using a
> cmpxchg() loop.
>
> Replace the cmpxchg() loop with a single xchg(), which provides the
> same atomic get-and-clear semantics, avoids retry spinning under
> contention, and simplifies the code.
>
> The code on x86_64 improves from:
>
> 186: 8b 15 00 00 00 00 mov 0x0(%rip),%edx
> 18c: 89 d0 mov %edx,%eax
> 18e: f0 0f b1 0d 00 00 00 lock cmpxchg %ecx,0x0(%rip)
> 195: 00
> 196: 39 c2 cmp %eax,%edx
> 198: 75 ec jne 186 <...>
>
> to just:
>
> 186: 87 05 00 00 00 00 xchg %eax,0x0(%rip)
>
> No functional change intended.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()
2026-01-22 14:17 [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg() Uros Bizjak
@ 2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:22 ` Andrew Cooper
2 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2026-01-22 14:21 UTC (permalink / raw)
To: Uros Bizjak
Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
xen-devel, linux-kernel
On 22.01.2026 15:17, Uros Bizjak wrote:
> The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while
> atomically clearing it. This was previously implemented using a
> cmpxchg() loop.
>
> Replace the cmpxchg() loop with a single xchg(), which provides the
> same atomic get-and-clear semantics, avoids retry spinning under
> contention, and simplifies the code.
>
> The code on x86_64 improves from:
>
> 186: 8b 15 00 00 00 00 mov 0x0(%rip),%edx
> 18c: 89 d0 mov %edx,%eax
> 18e: f0 0f b1 0d 00 00 00 lock cmpxchg %ecx,0x0(%rip)
> 195: 00
> 196: 39 c2 cmp %eax,%edx
> 198: 75 ec jne 186 <...>
>
> to just:
>
> 186: 87 05 00 00 00 00 xchg %eax,0x0(%rip)
>
> No functional change intended.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()
2026-01-22 14:17 [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg() Uros Bizjak
2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:21 ` Jan Beulich
@ 2026-01-22 14:22 ` Andrew Cooper
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Cooper @ 2026-01-22 14:22 UTC (permalink / raw)
To: Uros Bizjak, xen-devel, linux-kernel
Cc: Andrew Cooper, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
On 22/01/2026 2:17 pm, Uros Bizjak wrote:
> The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while
> atomically clearing it. This was previously implemented using a
> cmpxchg() loop.
>
> Replace the cmpxchg() loop with a single xchg(), which provides the
> same atomic get-and-clear semantics, avoids retry spinning under
> contention, and simplifies the code.
>
> The code on x86_64 improves from:
>
> 186: 8b 15 00 00 00 00 mov 0x0(%rip),%edx
> 18c: 89 d0 mov %edx,%eax
> 18e: f0 0f b1 0d 00 00 00 lock cmpxchg %ecx,0x0(%rip)
> 195: 00
> 196: 39 c2 cmp %eax,%edx
> 198: 75 ec jne 186 <...>
>
> to just:
>
> 186: 87 05 00 00 00 00 xchg %eax,0x0(%rip)
>
> No functional change intended.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> ---
> drivers/xen/mcelog.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/xen/mcelog.c b/drivers/xen/mcelog.c
> index 4f65b641c054..abe658c73b7b 100644
> --- a/drivers/xen/mcelog.c
> +++ b/drivers/xen/mcelog.c
> @@ -165,9 +165,7 @@ static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd,
> case MCE_GETCLEAR_FLAGS: {
> unsigned flags;
>
> - do {
> - flags = xen_mcelog.flags;
> - } while (cmpxchg(&xen_mcelog.flags, flags, 0) != flags);
> + flags = xchg(&xen_mcelog.flags, 0);
>
> return put_user(flags, p);
> }
Oh yeah, that was very daft beforehand.
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-22 14:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-22 14:17 [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg() Uros Bizjak
2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:22 ` Andrew Cooper
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®