mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Mauricio Faria de Oliveira <mfo@igalia.com>,
	kernel-dev@igalia.com, linux-kernel@vger.kernel.org,
	xen-devel@lists.xenproject.org, Thomas Gleixner <tglx@kernel.org>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Juergen Gross <jgross@suse.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Brian Gerst <brgerst@gmail.com>
Subject: Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
Date: Wed, 2 Sep 2026 09:33:54 +0100	[thread overview]
Message-ID: <20260902093354.582c2f07@pumpkin> (raw)
In-Reply-To: <16110ecc-fc0d-4b9d-a958-2a75ca60b69f@suse.com>

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
> 


  reply	other threads:[~2026-09-02  8:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-09-01 13:16   ` Jan Beulich
2026-09-02  8:33     ` David Laight [this message]
2026-09-02 14:18       ` H. Peter Anvin
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-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
2026-09-02 23:58       ` Borislav Petkov
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 ` [PATCH v9 3/5] x86/asm: group inline string functions 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

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=20260902093354.582c2f07@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfo@igalia.com \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --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®