mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mauricio Faria de Oliveira <mfo@igalia.com>
To: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, Juergen Gross <jgross@suse.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	kernel-dev@igalia.com, linux-kernel@vger.kernel.org,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline memcmp
Date: Thu, 23 Jul 2026 20:17:02 -0300	[thread overview]
Message-ID: <1e451a9179c1faa8e7805d17c6e1ee10@igalia.com> (raw)
In-Reply-To: <20260722170334.GCamD35gwrCng30WH1@fat_crate.local>

On 2026-07-22 14:03, Borislav Petkov wrote:
> hpa in To:.
> 
> On Tue, Jul 21, 2026 at 12:56:43PM -0300, Mauricio Faria de Oliveira wrote:
>> Add the volatile qualifier and clobbers parameter to prevent bugs with
>> instruction reordering and optimization.
>> 
>> Also check the zero-length case, as the 'repe' prefix does not run the
>> 'cmpsb' instruction if the 'count' register is zero, which doesn't set
> 
> Please use capital letters for insns: REPE, CMPSB and you don't need to put
> words in '' - it reads fine without them.

Ok.

> 
>> the condition-code/zero flag, so the result is based on a stale flag.
>> 
>> Those are pre-existing issues found by Sashiko.
>> 
>> Link: https://sashiko.dev/#/patchset/20260701-pvh-kasan-inline-v6-0-ba99045dfa9f%40igalia.com
>> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
>> ---
>>  arch/x86/include/asm/shared/string.h | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
>> index 02b92927553f7b8e1c87e6122bbaa70439e57ea7..166274e44f3cb49e3dccab3cdac281d67aef5d44 100644
>> --- a/arch/x86/include/asm/shared/string.h
>> +++ b/arch/x86/include/asm/shared/string.h
>> @@ -11,8 +11,12 @@ static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_
>>  {
>>  	bool diff;
>>  
>> -	asm("repe cmpsb"
>> -	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
>> +	if (len == 0)
>> +		return 0;
>> +
>> +	asm volatile("repe cmpsb"
>> +		     : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
>> +		     : : "cc", "memory");
>>  
>>  	return diff;
>>  }
> 
> So this is a fix which should probably go to stable, I think. Going back into
> git history, it points to
> 
>   62bd0337d0c4 ("Top header file for new x86 setup code")
> 
> from 2007. And we have carried it this way through the years and who knows
> what hit this or not. So please make this the first patch in your set - you
> can even send it separately so that I can get route it through stable.

Sure:
https://lore.kernel.org/all/20260723-x86-memcmp-asm-v2-1-d93ecb43797f@igalia.com/

> Then you can base the rest ontop.

Done:
https://lore.kernel.org/all/20260723-pvh-kasan-inline-v8-0-c1f62c156f52@igalia.com/

Thanks,

> 
> Thx.

-- 
Mauricio

  parent reply	other threads:[~2026-07-23 23:17 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 15:56 [PATCH v7 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-07-21 15:56 ` [PATCH v7 1/5] x86/asm, x86/boot: expose inline memcmp Mauricio Faria de Oliveira
2026-07-21 15:56 ` [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in " Mauricio Faria de Oliveira
2026-07-22 17:03   ` Borislav Petkov
2026-07-22 18:45     ` H. Peter Anvin
2026-07-23  6:59       ` Jan Beulich
2026-07-23 23:12         ` H. Peter Anvin
2026-07-24  0:35           ` Mauricio Faria de Oliveira
2026-07-24 21:53             ` H. Peter Anvin
2026-07-24 23:35               ` H. Peter Anvin
2026-07-24 23:57                 ` H. Peter Anvin
2026-07-25  0:25                   ` H. Peter Anvin
2026-07-25 10:27                     ` David Laight
2026-07-23 19:37       ` Brian Gerst
2026-07-23 23:13         ` H. Peter Anvin
2026-07-24  0:49           ` Brian Gerst
2026-07-24 21:40             ` H. Peter Anvin
2026-07-25 10:34             ` David Laight
2026-07-26  2:57               ` H. Peter Anvin
2026-07-28 23:33             ` Borislav Petkov
2026-07-23 23:20       ` Mauricio Faria de Oliveira
2026-07-22 18:48     ` H. Peter Anvin
2026-07-23 23:26       ` Mauricio Faria de Oliveira
2026-07-23 23:17     ` Mauricio Faria de Oliveira [this message]
2026-07-21 15:56 ` [PATCH v7 3/5] x86/asm: group inline string functions Mauricio Faria de Oliveira
2026-07-23 21:59   ` Borislav Petkov
2026-07-24  0:51     ` Mauricio Faria de Oliveira
2026-07-21 15:56 ` [PATCH v7 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
2026-07-21 15:56 ` [PATCH v7 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=1e451a9179c1faa8e7805d17c6e1ee10@igalia.com \
    --to=mfo@igalia.com \
    --cc=adobriyan@gmail.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --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®