Skip to content

Commit c74a1a6

Browse files
ubizjakjgross1
authored andcommitted
xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()
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> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Reviewed-by: Jan Beulich <jbeulich@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20260122141754.116129-1-ubizjak@gmail.com>
1 parent b13cd24 commit c74a1a6

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

drivers/xen/mcelog.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd,
165165
case MCE_GETCLEAR_FLAGS: {
166166
unsigned flags;
167167

168-
do {
169-
flags = xen_mcelog.flags;
170-
} while (cmpxchg(&xen_mcelog.flags, flags, 0) != flags);
168+
flags = xchg(&xen_mcelog.flags, 0);
171169

172170
return put_user(flags, p);
173171
}

0 commit comments

Comments
 (0)