Re: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline memcmp
Borislav Petkov <[email protected]> Tue, 28 Jul 2026 16:33:32 -0700
| Newsgroups | gmane.linux.kernel,gmane.comp.emulators.xen.devel |
|---|---|
| Message-ID | <20260728233332.GCamk8TN3cyN-Ohr31@fat_crate.local> |
On Thu, Jul 23, 2026 at 08:49:13PM -0400, Brian Gerst wrote:
> Your suggestion is good, but should have a comment explaining why it's there
> to someone reading the code in the future.
I have this there now:
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 6827551720dd..7bc34f9272fb 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -32,6 +32,11 @@
int memcmp(const void *s1, const void *s2, size_t len)
{
bool diff;
+
+ /*
+ * Make sure ZF is properly set in the len==0 case because in it,
+ * RCX==0 and the REPE; CMPSB won't get executed.
+ */
asm volatile("test %3, %3\n\t"
"repe cmpsb"
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette