From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Uros Bizjak <ubizjak@gmail.com>,
xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Subject: Re: [PATCH] xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()
Date: Thu, 22 Jan 2026 14:22:01 +0000 [thread overview]
Message-ID: <b8262c0d-5602-436f-9137-46621e39fd03@citrix.com> (raw)
In-Reply-To: <20260122141754.116129-1-ubizjak@gmail.com>
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>
prev parent reply other threads:[~2026-01-22 14:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 14:17 Uros Bizjak
2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:21 ` Jan Beulich
2026-01-22 14:22 ` Andrew Cooper [this message]
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=b8262c0d-5602-436f-9137-46621e39fd03@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=sstabellini@kernel.org \
--cc=ubizjak@gmail.com \
--cc=xen-devel@lists.xenproject.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®