* [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-08-22 18:33 [PATCH v9 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
@ 2026-08-22 18:33 ` Mauricio Faria de Oliveira
2026-09-01 13:16 ` Jan Beulich
2026-09-02 2:31 ` Borislav Petkov
2026-08-22 18:33 ` [PATCH v9 2/5] x86/asm, x86/boot: expose inline memcmp() Mauricio Faria de Oliveira
` (3 subsequent siblings)
4 siblings, 2 replies; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-08-22 18:33 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
According to the GCC documentation, conditions in the flags register
(e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
"=@ccnz" output operand.
"""
6.11.2.4 Flag Output Operands
On some targets, a special form of output operand exists by which
conditions in the flags register may be outputs of the asm. [...]
6.11.2.6 Clobbers and Scratch Registers
While the compiler is aware of changes to entries listed in the
output operands, [...]
Clobber descriptions may not in any way overlap with an input or
output operand. [...]
"""
Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@zytor.com/
Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Flag-Output-Operands [1]
Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1 [2]
---
arch/x86/boot/string.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 1632d40e1f545ae0665597069b568ea6b6c263e5..03278b4393887cb71cb063818d3378c4f52b06f8 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t len)
asm volatile("test %3, %3\n\t"
"repe cmpsb"
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
- : : "cc", "memory");
+ : : "memory");
return diff;
}
--
2.47.3
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-08-22 18:33 ` [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp() Mauricio Faria de Oliveira
@ 2026-09-01 13:16 ` Jan Beulich
2026-09-02 8:33 ` David Laight
2026-09-02 2:31 ` Borislav Petkov
1 sibling, 1 reply; 17+ messages in thread
From: Jan Beulich @ 2026-09-01 13:16 UTC (permalink / raw)
To: Mauricio Faria de Oliveira
Cc: kernel-dev, linux-kernel, xen-devel, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Brian Gerst
On 22.08.2026 20:33, Mauricio Faria de Oliveira wrote:
> According to the GCC documentation, conditions in the flags register
> (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
>
> Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
>
> Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
> "=@ccnz" output operand.
>
> """
> 6.11.2.4 Flag Output Operands
>
> On some targets, a special form of output operand exists by which
> conditions in the flags register may be outputs of the asm. [...]
>
> 6.11.2.6 Clobbers and Scratch Registers
>
> While the compiler is aware of changes to entries listed in the
> output operands, [...]
>
> Clobber descriptions may not in any way overlap with an input or
> output operand. [...]
> """
>
> Reported-by: "H. Peter Anvin" <hpa@zytor.com>
> Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@zytor.com/
> Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
> Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Flag-Output-Operands [1]
> Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1 [2]
Reviewed-by: Jan Beulich <jbeulich@suse.com>
> --- a/arch/x86/boot/string.c
> +++ b/arch/x86/boot/string.c
> @@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t len)
> asm volatile("test %3, %3\n\t"
> "repe cmpsb"
> : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
> - : : "cc", "memory");
> + : : "memory");
In fact I'm using a modified gcc which properly rejects such conflicting
uses of output and clobber. ("cc" clobbers are redundant on x86 anyway.)
Jan
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-01 13:16 ` Jan Beulich
@ 2026-09-02 8:33 ` David Laight
2026-09-02 14:18 ` H. Peter Anvin
0 siblings, 1 reply; 17+ messages in thread
From: David Laight @ 2026-09-02 8:33 UTC (permalink / raw)
To: Jan Beulich
Cc: Mauricio Faria de Oliveira, kernel-dev, linux-kernel, xen-devel,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Brian Gerst
On Tue, 1 Sep 2026 15:16:58 +0200
Jan Beulich <jbeulich@suse.com> wrote:
> On 22.08.2026 20:33, Mauricio Faria de Oliveira wrote:
> > According to the GCC documentation, conditions in the flags register
> > (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
> >
> > Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
> >
> > Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
> > "=@ccnz" output operand.
> >
> > """
> > 6.11.2.4 Flag Output Operands
> >
> > On some targets, a special form of output operand exists by which
> > conditions in the flags register may be outputs of the asm. [...]
> >
> > 6.11.2.6 Clobbers and Scratch Registers
> >
> > While the compiler is aware of changes to entries listed in the
> > output operands, [...]
> >
> > Clobber descriptions may not in any way overlap with an input or
> > output operand. [...]
> > """
> >
> > Reported-by: "H. Peter Anvin" <hpa@zytor.com>
> > Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@zytor.com/
> > Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
> > Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
> > Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Flag-Output-Operands [1]
> > Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1 [2]
>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>
> > --- a/arch/x86/boot/string.c
> > +++ b/arch/x86/boot/string.c
> > @@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t len)
> > asm volatile("test %3, %3\n\t"
> > "repe cmpsb"
> > : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
> > - : : "cc", "memory");
> > + : : "memory");
>
> In fact I'm using a modified gcc which properly rejects such conflicting
> uses of output and clobber. ("cc" clobbers are redundant on x86 anyway.)
And, if "cc" clobber wasn't redundant, you'd need clobbers for the cc flags
that weren't being used as output values.
David
>
> Jan
>
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-02 8:33 ` David Laight
@ 2026-09-02 14:18 ` H. Peter Anvin
0 siblings, 0 replies; 17+ messages in thread
From: H. Peter Anvin @ 2026-09-02 14:18 UTC (permalink / raw)
To: David Laight, Jan Beulich
Cc: Mauricio Faria de Oliveira, kernel-dev, linux-kernel, xen-devel,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Brian Gerst
On September 2, 2026 1:33:54 AM PDT, David Laight <david.laight.linux@gmail.com> wrote:
>On Tue, 1 Sep 2026 15:16:58 +0200
>Jan Beulich <jbeulich@suse.com> wrote:
>
>> On 22.08.2026 20:33, Mauricio Faria de Oliveira wrote:
>> > According to the GCC documentation, conditions in the flags register
>> > (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
>> >
>> > Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
>> >
>> > Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
>> > "=@ccnz" output operand.
>> >
>> > """
>> > 6.11.2.4 Flag Output Operands
>> >
>> > On some targets, a special form of output operand exists by which
>> > conditions in the flags register may be outputs of the asm. [...]
>> >
>> > 6.11.2.6 Clobbers and Scratch Registers
>> >
>> > While the compiler is aware of changes to entries listed in the
>> > output operands, [...]
>> >
>> > Clobber descriptions may not in any way overlap with an input or
>> > output operand. [...]
>> > """
>> >
>> > Reported-by: "H. Peter Anvin" <hpa@zytor.com>
>> > Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@zytor.com/
>> > Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
>> > Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
>> > Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Flag-Output-Operands [1]
>> > Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1 [2]
>>
>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>>
>> > --- a/arch/x86/boot/string.c
>> > +++ b/arch/x86/boot/string.c
>> > @@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t len)
>> > asm volatile("test %3, %3\n\t"
>> > "repe cmpsb"
>> > : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
>> > - : : "cc", "memory");
>> > + : : "memory");
>>
>> In fact I'm using a modified gcc which properly rejects such conflicting
>> uses of output and clobber. ("cc" clobbers are redundant on x86 anyway.)
>
>And, if "cc" clobber wasn't redundant, you'd need clobbers for the cc flags
>that weren't being used as output values.
>
>David
>
>>
>> Jan
>>
>
No. The condition codes aren't orthogonal like that. There is only one flags register.
(On x86 I believe asm statements are assumed to clobber the flags unconditionally, because it is so common.)
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-08-22 18:33 ` [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp() Mauricio Faria de Oliveira
2026-09-01 13:16 ` Jan Beulich
@ 2026-09-02 2:31 ` Borislav Petkov
2026-09-02 13:29 ` Michael Matz
1 sibling, 1 reply; 17+ messages in thread
From: Borislav Petkov @ 2026-09-02 2:31 UTC (permalink / raw)
To: Mauricio Faria de Oliveira, Michael Matz, Richard Biener
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Jan Beulich,
Brian Gerst, kernel-dev, linux-kernel, xen-devel
On Sat, Aug 22, 2026 at 03:33:17PM -0300, Mauricio Faria de Oliveira wrote:
> According to the GCC documentation, conditions in the flags register
> (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
>
> Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
>
> Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
> "=@ccnz" output operand.
>
> """
> 6.11.2.4 Flag Output Operands
>
> On some targets, a special form of output operand exists by which
> conditions in the flags register may be outputs of the asm. [...]
>
> 6.11.2.6 Clobbers and Scratch Registers
>
> While the compiler is aware of changes to entries listed in the
> output operands, [...]
>
> Clobber descriptions may not in any way overlap with an input or
> output operand. [...]
> """
>
> Reported-by: "H. Peter Anvin" <hpa@zytor.com>
> Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@zytor.com/
> Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
> Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Flag-Output-Operands [1]
> Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1 [2]
> ---
> arch/x86/boot/string.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
> index 1632d40e1f545ae0665597069b568ea6b6c263e5..03278b4393887cb71cb063818d3378c4f52b06f8 100644
> --- a/arch/x86/boot/string.c
> +++ b/arch/x86/boot/string.c
> @@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t len)
> asm volatile("test %3, %3\n\t"
> "repe cmpsb"
> : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
> - : : "cc", "memory");
> + : : "memory");
> return diff;
> }
So far, so good.
But then I'd expect that gcc would enforce that. I know it can't have it when
the clobbers contain input or output regs:
In function ‘__memcmp’,
inlined from ‘main’ at memcmp.c:25:6:
memcmp.c:11:9: error: ‘asm’ operand has impossible constraints or there are not enough registers
11 | asm volatile("test %3, %3\n\t"
| ^~~
but with "cc" clobbers it works.
That's gcc-16 btw.
Micha, Richi?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-02 2:31 ` Borislav Petkov
@ 2026-09-02 13:29 ` Michael Matz
2026-09-02 13:48 ` Mauricio Faria de Oliveira
2026-09-02 23:58 ` Borislav Petkov
0 siblings, 2 replies; 17+ messages in thread
From: Michael Matz @ 2026-09-02 13:29 UTC (permalink / raw)
To: Borislav Petkov
Cc: Mauricio Faria de Oliveira, Richard Biener, Thomas Gleixner,
Ingo Molnar, Dave Hansen, x86, H. Peter Anvin, Juergen Gross,
Alexey Dobriyan, Boris Ostrovsky, Jan Beulich, Brian Gerst,
kernel-dev, linux-kernel, xen-devel
[-- Attachment #1: Type: text/plain, Size: 1938 bytes --]
Hello,
On Tue, 1 Sep 2026, Borislav Petkov wrote:
> On Sat, Aug 22, 2026 at 03:33:17PM -0300, Mauricio Faria de Oliveira wrote:
> > According to the GCC documentation, conditions in the flags register
> > (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
> >
> > Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
> >
> > Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
> > "=@ccnz" output operand.
Strictly speaking, on x86, the '=@ccXY' constraints are register outputs
into normal random integer registers (though they are of course
initialized in a funny way), while the 'cc' clobber is not a register at
all, but rather a fuzzy idea of "state" in old cc0-based compilers (which
the x86 backend isn't anymore since, ... well, about forever, 1999). As
such they both really don't conflict and ...
> But then I'd expect that gcc would enforce that. I know it can't have it
> when the clobbers contain input or output regs:
>
> In function ‘__memcmp’,
> inlined from ‘main’ at memcmp.c:25:6:
> memcmp.c:11:9: error: ‘asm’ operand has impossible constraints or there are not enough registers
> 11 | asm volatile("test %3, %3\n\t"
> | ^~~
>
> but with "cc" clobbers it works.
... hence there's nothing to report. In fact what an explicit 'cc'
clobber once meant in cc0 backends (that indiscriminated flag "state") is
manufactured by the non-cc0 backends (all of them now) automatically
whenever an asm has no flag output constraints at all. (On x86 that means
it adds the "flags" register (internal name for the collection of flag
status bits) to the clobber set automatically when there are no =@ccXY
constraints).
You can regard all 'cc' clobbers as pure source compatibility, they have
no meaning anymore. But as they are so ubiquitous (even in our own docu),
they remain recognized.
Ciao,
Michael.
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-02 13:29 ` Michael Matz
@ 2026-09-02 13:48 ` Mauricio Faria de Oliveira
2026-09-03 0:01 ` Borislav Petkov
2026-09-02 23:58 ` Borislav Petkov
1 sibling, 1 reply; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-02 13:48 UTC (permalink / raw)
To: Michael Matz, Borislav Petkov
Cc: Richard Biener, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst, kernel-dev, linux-kernel, xen-devel
On 2026-09-02 10:29, Michael Matz wrote:
> Hello,
>
> On Tue, 1 Sep 2026, Borislav Petkov wrote:
>
>> On Sat, Aug 22, 2026 at 03:33:17PM -0300, Mauricio Faria de Oliveira wrote:
>> > According to the GCC documentation, conditions in the flags register
>> > (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
>> >
>> > Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
>> >
>> > Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
>> > "=@ccnz" output operand.
>
> Strictly speaking, on x86, the '=@ccXY' constraints are register outputs
> into normal random integer registers (though they are of course
> initialized in a funny way), while the 'cc' clobber is not a register at
> all, but rather a fuzzy idea of "state" in old cc0-based compilers (which
> the x86 backend isn't anymore since, ... well, about forever, 1999). As
> such they both really don't conflict and ...
>
>> But then I'd expect that gcc would enforce that. I know it can't have it
>> when the clobbers contain input or output regs:
>>
>> In function ‘__memcmp’,
>> inlined from ‘main’ at memcmp.c:25:6:
>> memcmp.c:11:9: error: ‘asm’ operand has impossible constraints or there are not enough registers
>> 11 | asm volatile("test %3, %3\n\t"
>> | ^~~
>>
>> but with "cc" clobbers it works.
>
> ... hence there's nothing to report. In fact what an explicit 'cc'
> clobber once meant in cc0 backends (that indiscriminated flag "state") is
> manufactured by the non-cc0 backends (all of them now) automatically
> whenever an asm has no flag output constraints at all. (On x86 that means
> it adds the "flags" register (internal name for the collection of flag
> status bits) to the clobber set automatically when there are no =@ccXY
> constraints).
>
> You can regard all 'cc' clobbers as pure source compatibility, they have
> no meaning anymore. But as they are so ubiquitous (even in our own docu),
> they remain recognized.
Michael, thanks for the detailed explanation; that's very nice to know.
Boris, I guess this may be added as clarification in the commit message.
Would you prefer another version with it?
Thanks,
>
>
> Ciao,
> Michael.
--
Mauricio
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-02 13:48 ` Mauricio Faria de Oliveira
@ 2026-09-03 0:01 ` Borislav Petkov
2026-09-03 0:07 ` Mauricio Faria de Oliveira
2026-09-03 8:40 ` David Laight
0 siblings, 2 replies; 17+ messages in thread
From: Borislav Petkov @ 2026-09-03 0:01 UTC (permalink / raw)
To: Mauricio Faria de Oliveira
Cc: Michael Matz, Richard Biener, Thomas Gleixner, Ingo Molnar,
Dave Hansen, x86, H. Peter Anvin, Juergen Gross, Alexey Dobriyan,
Boris Ostrovsky, Jan Beulich, Brian Gerst, kernel-dev,
linux-kernel, xen-devel
On Wed, Sep 02, 2026 at 10:48:14AM -0300, Mauricio Faria de Oliveira wrote:
> Boris, I guess this may be added as clarification in the commit message.
> Would you prefer another version with it?
Yeah, I'd actually prefer it in the code itself so that we can find it easier.
This file is as good as any.
Something like this:
/*
* Summarized explanation that "cc" clobbers don't have a meaning
*
*/
and leave the "cc" clobber there but commented out:
/* "cc" ... */
so that we can grep for it easier later.
Thanks!
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-03 0:01 ` Borislav Petkov
@ 2026-09-03 0:07 ` Mauricio Faria de Oliveira
2026-09-03 0:39 ` Borislav Petkov
2026-09-03 8:40 ` David Laight
1 sibling, 1 reply; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-03 0:07 UTC (permalink / raw)
To: Borislav Petkov
Cc: Michael Matz, Richard Biener, Thomas Gleixner, Ingo Molnar,
Dave Hansen, x86, H. Peter Anvin, Juergen Gross, Alexey Dobriyan,
Boris Ostrovsky, Jan Beulich, Brian Gerst, kernel-dev,
linux-kernel, xen-devel
On 2026-09-02 21:01, Borislav Petkov wrote:
> On Wed, Sep 02, 2026 at 10:48:14AM -0300, Mauricio Faria de Oliveira wrote:
>> Boris, I guess this may be added as clarification in the commit message.
>> Would you prefer another version with it?
>
> Yeah, I'd actually prefer it in the code itself so that we can find it easier.
> This file is as good as any.
>
> Something like this:
>
> /*
> * Summarized explanation that "cc" clobbers don't have a meaning
> *
> */
>
> and leave the "cc" clobber there but commented out:
>
> /* "cc" ... */
>
> so that we can grep for it easier later.
>
> Thanks!
Sure, will do in the next version.
The rest of this series is OK to you?
I can wait for further feedback and combine it with this change.
Thanks!
--
Mauricio
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-03 0:07 ` Mauricio Faria de Oliveira
@ 2026-09-03 0:39 ` Borislav Petkov
0 siblings, 0 replies; 17+ messages in thread
From: Borislav Petkov @ 2026-09-03 0:39 UTC (permalink / raw)
To: Mauricio Faria de Oliveira
Cc: Michael Matz, Richard Biener, Thomas Gleixner, Ingo Molnar,
Dave Hansen, x86, H. Peter Anvin, Juergen Gross, Alexey Dobriyan,
Boris Ostrovsky, Jan Beulich, Brian Gerst, kernel-dev,
linux-kernel, xen-devel
On Wed, Sep 02, 2026 at 09:07:07PM -0300, Mauricio Faria de Oliveira wrote:
> The rest of this series is OK to you?
> I can wait for further feedback and combine it with this change.
Please wait - I haven't gone through the rest.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-03 0:01 ` Borislav Petkov
2026-09-03 0:07 ` Mauricio Faria de Oliveira
@ 2026-09-03 8:40 ` David Laight
1 sibling, 0 replies; 17+ messages in thread
From: David Laight @ 2026-09-03 8:40 UTC (permalink / raw)
To: Borislav Petkov
Cc: Mauricio Faria de Oliveira, Michael Matz, Richard Biener,
Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Jan Beulich,
Brian Gerst, kernel-dev, linux-kernel, xen-devel
On Wed, 2 Sep 2026 17:01:32 -0700
Borislav Petkov <bp@alien8.de> wrote:
> On Wed, Sep 02, 2026 at 10:48:14AM -0300, Mauricio Faria de Oliveira wrote:
> > Boris, I guess this may be added as clarification in the commit message.
> > Would you prefer another version with it?
>
> Yeah, I'd actually prefer it in the code itself so that we can find it easier.
> This file is as good as any.
>
> Something like this:
>
> /*
> * Summarized explanation that "cc" clobbers don't have a meaning
> *
> */
>
> and leave the "cc" clobber there but commented out:
>
> /* "cc" ... */
>
> so that we can grep for it easier later.
Why would you need to?
Apart from a scan to just remove them all...
David
>
> Thanks!
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
2026-09-02 13:29 ` Michael Matz
2026-09-02 13:48 ` Mauricio Faria de Oliveira
@ 2026-09-02 23:58 ` Borislav Petkov
1 sibling, 0 replies; 17+ messages in thread
From: Borislav Petkov @ 2026-09-02 23:58 UTC (permalink / raw)
To: Michael Matz
Cc: Mauricio Faria de Oliveira, Richard Biener, Thomas Gleixner,
Ingo Molnar, Dave Hansen, x86, H. Peter Anvin, Juergen Gross,
Alexey Dobriyan, Boris Ostrovsky, Jan Beulich, Brian Gerst,
kernel-dev, linux-kernel, xen-devel
On Wed, Sep 02, 2026 at 03:29:44PM +0200, Michael Matz wrote:
> Strictly speaking, on x86, the '=@ccXY' constraints are register outputs
> into normal random integer registers (though they are of course
> initialized in a funny way), while the 'cc' clobber is not a register at
> all, but rather a fuzzy idea of "state" in old cc0-based compilers (which
> the x86 backend isn't anymore since, ... well, about forever, 1999). As
> such they both really don't conflict and ...
>
> > But then I'd expect that gcc would enforce that. I know it can't have it
> > when the clobbers contain input or output regs:
> >
> > In function ‘__memcmp’,
> > inlined from ‘main’ at memcmp.c:25:6:
> > memcmp.c:11:9: error: ‘asm’ operand has impossible constraints or there are not enough registers
> > 11 | asm volatile("test %3, %3\n\t"
> > | ^~~
> >
> > but with "cc" clobbers it works.
>
> ... hence there's nothing to report.
Aaaha, so the enforcement is solely documentation-based. :-)
> In fact what an explicit 'cc' clobber once meant in cc0 backends (that
> indiscriminated flag "state") is manufactured by the non-cc0 backends (all
> of them now) automatically whenever an asm has no flag output constraints at
> all. (On x86 that means it adds the "flags" register (internal name for the
> collection of flag status bits) to the clobber set automatically when there
> are no =@ccXY constraints).
>
> You can regard all 'cc' clobbers as pure source compatibility, they have
> no meaning anymore. But as they are so ubiquitous (even in our own docu),
> they remain recognized.
Ah ok, I see. so we'll simply forget them.
Thanks Micha!
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v9 2/5] x86/asm, x86/boot: expose inline memcmp()
2026-08-22 18:33 [PATCH v9 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp() Mauricio Faria de Oliveira
@ 2026-08-22 18:33 ` Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 3/5] x86/asm: group inline string functions Mauricio Faria de Oliveira
` (2 subsequent siblings)
4 siblings, 0 replies; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-08-22 18:33 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
Move the inline memcmp function currently only available in 'boot/string.c'
into the shared string function header <asm/shared/string.h> to be reused.
This is not done through <asm/string.h> to avoid pulling unnecessary code
in 'boot/string.c' that causes build errors in 'boot/compressed/string.c'
and 'purgatory/purgatory.ro'.
No functional changes.
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
Thanks to David Laight for noticing the return value difference between
inline and regular memcmp().
---
arch/x86/boot/string.c | 13 ++-----------
arch/x86/include/asm/shared/string.h | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 03278b4393887cb71cb063818d3378c4f52b06f8..be454a6864225f3a972c3e81826b77ed4e8a57fe 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -15,6 +15,7 @@
#include <linux/errno.h>
#include <linux/limits.h>
#include <asm/asm.h>
+#include <asm/shared/string.h>
#include "ctype.h"
#include "string.h"
@@ -31,17 +32,7 @@
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)
- : : "memory");
- return diff;
+ return __inline_memcmp(s1, s2, len);
}
/*
diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
new file mode 100644
index 0000000000000000000000000000000000000000..06c1d5e5013e4d59cfb49866d10e164362d2c4cc
--- /dev/null
+++ b/arch/x86/include/asm/shared/string.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_SHARED_STRING_H
+#define _ASM_X86_SHARED_STRING_H
+
+/*
+ * This inline memcmp() returns 0 (equal) or 1 (not equal).
+ * The regular memcmp() returns <0 (less than), 0 (equal), or >0 (greater than)
+ * to indicate ordering as well.
+ */
+static __always_inline int __inline_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)
+ : : "memory");
+
+ return diff;
+}
+
+#endif /* _ASM_X86_SHARED_STRING_H */
--
2.47.3
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH v9 3/5] x86/asm: group inline string functions
2026-08-22 18:33 [PATCH v9 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp() Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 2/5] x86/asm, x86/boot: expose inline memcmp() Mauricio Faria de Oliveira
@ 2026-08-22 18:33 ` Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 5/5] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
4 siblings, 0 replies; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-08-22 18:33 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
Group the __inline string functions in the same header.
Use <asm/shared/string.h> since __inline_memcmp() must remain there for use
by arch/x86/boot/string.c.
No functional changes.
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
arch/x86/include/asm/shared/string.h | 21 +++++++++++++++++++++
arch/x86/include/asm/string.h | 21 +--------------------
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
index 06c1d5e5013e4d59cfb49866d10e164362d2c4cc..ab033d27c581e44ba3f5a494ca29e31776be51f2 100644
--- a/arch/x86/include/asm/shared/string.h
+++ b/arch/x86/include/asm/shared/string.h
@@ -2,6 +2,27 @@
#ifndef _ASM_X86_SHARED_STRING_H
#define _ASM_X86_SHARED_STRING_H
+static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
+{
+ void *ret = to;
+
+ asm volatile("rep movsb"
+ : "+D" (to), "+S" (from), "+c" (len)
+ : : "memory");
+ return ret;
+}
+
+static __always_inline void *__inline_memset(void *s, int v, size_t n)
+{
+ void *ret = s;
+
+ asm volatile("rep stosb"
+ : "+D" (s), "+c" (n)
+ : "a" ((uint8_t)v)
+ : "memory");
+ return ret;
+}
+
/*
* This inline memcmp() returns 0 (equal) or 1 (not equal).
* The regular memcmp() returns <0 (less than), 0 (equal), or >0 (greater than)
diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..dbf59f0d4cca71e2ddce0d8764aeec8782236669 100644
--- a/arch/x86/include/asm/string.h
+++ b/arch/x86/include/asm/string.h
@@ -8,25 +8,6 @@
# include <asm/string_64.h>
#endif
-static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
-{
- void *ret = to;
-
- asm volatile("rep movsb"
- : "+D" (to), "+S" (from), "+c" (len)
- : : "memory");
- return ret;
-}
-
-static __always_inline void *__inline_memset(void *s, int v, size_t n)
-{
- void *ret = s;
-
- asm volatile("rep stosb"
- : "+D" (s), "+c" (n)
- : "a" ((uint8_t)v)
- : "memory");
- return ret;
-}
+#include <asm/shared/string.h>
#endif /* _ASM_X86_STRING_H */
--
2.47.3
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH v9 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base()
2026-08-22 18:33 [PATCH v9 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
` (2 preceding siblings ...)
2026-08-22 18:33 ` [PATCH v9 3/5] x86/asm: group inline string functions Mauricio Faria de Oliveira
@ 2026-08-22 18:33 ` Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 5/5] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
4 siblings, 0 replies; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-08-22 18:33 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
Even with __builtin the compiler may decide to use the out of line function
instead of the inline implementation.
The existing code is broken with gcc-14/15 but not gcc-12/13 (Ubuntu 25.10)
and vmlinux no longer boots with CONFIG_PVH if CONFIG_KASAN_GENERIC is set.
For testing purposes, if the size argument is reduced from 12 to 8 then the
compiler decides to use the inline implementation; that shows results vary.
Switch the builtin to the inline implementation to address it.
Fixes: 416a33c9afce ("x86/cpu: fix unbootable VMs by inlining memcmp() in hypervisor_cpuid_base()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
---
arch/x86/include/asm/cpuid/api.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/api.h
index 82eddfa2347b32b76c2ea9b85f005ca5416ac71f..2d9f3d4d63de6e721f275d9e80d372edbdfedf30 100644
--- a/arch/x86/include/asm/cpuid/api.h
+++ b/arch/x86/include/asm/cpuid/api.h
@@ -204,7 +204,7 @@ static inline u32 cpuid_base_hypervisor(const char *sig, u32 leaves)
* from PVH early boot code before instrumentation is set up
* and memcmp() itself may be instrumented.
*/
- if (!__builtin_memcmp(sig, signature, 12) &&
+ if (!__inline_memcmp(sig, signature, 12) &&
(leaves == 0 || ((eax - base) >= leaves)))
return base;
}
--
2.47.3
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH v9 5/5] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh()
2026-08-22 18:33 [PATCH v9 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
` (3 preceding siblings ...)
2026-08-22 18:33 ` [PATCH v9 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
@ 2026-08-22 18:33 ` Mauricio Faria de Oliveira
4 siblings, 0 replies; 17+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-08-22 18:33 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
Even with __builtin the compiler may decide to use the out of line function
instead of the inline implementation.
This particular one (still) generated the inline implementation as expected
(at least in these compiler versions) but this is not guaranteed to remain.
Switch the builtin to the inline implementation to address it.
Fixes: fbe5a6dfe492 ("xen, pvh: fix unbootable VMs by inlining memset() in xen_prepare_pvh()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
---
arch/x86/platform/pvh/enlighten.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enlighten.c
index f2053cbe9b0ce3d2178938269607c652ae8f528e..cb442cbd9d828619421babb281bfe9759edbca8a 100644
--- a/arch/x86/platform/pvh/enlighten.c
+++ b/arch/x86/platform/pvh/enlighten.c
@@ -8,6 +8,7 @@
#include <asm/hypervisor.h>
#include <asm/e820/api.h>
#include <asm/x86_init.h>
+#include <asm/string.h>
#include <asm/xen/interface.h>
@@ -129,7 +130,7 @@ void __init xen_prepare_pvh(void)
* This must not compile to "call memset" because memset() may be
* instrumented.
*/
- __builtin_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
+ __inline_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
hypervisor_specific_init(xen_guest);
--
2.47.3
^ permalink raw reply [flat|nested] 17+ messages in thread