From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 195CA368263 for ; Wed, 1 Jul 2026 07:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782889547; cv=none; b=Pg2fHdpaIy9z9C1cZSm9R2OFIn9RlOVBhkpkU9YI5Kdt0I5tYY+oiVuElRBS7FRHemnSDcfbw8tR6iAzksB42zUh54oeHim2ef/QK+EGqrzpqqnO4AAj4iQT9hEwiaungZbfYMst9GkZaloyvZdqVXXRs9RMK2DgH6Tn2Ej4axI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782889547; c=relaxed/simple; bh=KmgsPOqxsopxzfbILnAMl8E9IGrO4gzlzZbYvvVMXBE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fyVqQX5dFmyCjnaNAtZFw3t4O9/ju8XFnKzIiQi3RLx6Heo+uW9iRcPWuZoOHwdbwCfo1kbpg02gRrULgsZKw6RBfPRay6JMXW2n2kLkKSFL65vjmdRt1Zp/aAPKCOKmCJPE6jajjjEgX17C5TYTt/PMt0zPw/c1uGcYJ4zOFyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=obljbhui; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="obljbhui" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+AaYpDAuxo7H4NIsCnNAZDJ/up1aHckwKckTsZUvyYo=; b=obljbhuiEFfUuQG2puQ/PkbnJB ObvbkN3jtXxrgtWidSkKLpIFrJAhoSkE0ln3nU9mr8U/s6eVLGJ3wgVZE8OqsfGTjooaeg/G1q0Bx 4ykvNq3SVgHh1vZGY7LQyVu+cJwysZH/AAayjUiEuDzqqlHKusFT0kOfmcjqEYfAVSrhjYoo/ALlN eDOtGEALQpKWr8R+L6fOm2nhZ/X04WVjwDX15RQsFxk+5sT62z2LjJ/ohPAf6WnBh3i2BJ4e5YSFk ZvmTMJW/gH/cz4XaFf28ftNCy6xI6xFAw48J2trogdaLMXogw0JaXN+VhndNhW4UY1f5oe60hJl86 9HZxYVNg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wep0n-00000006Avt-1h6e; Wed, 01 Jul 2026 07:05:33 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id ECCFA30035C; Wed, 01 Jul 2026 09:05:31 +0200 (CEST) Date: Wed, 1 Jul 2026 09:05:31 +0200 From: Peter Zijlstra To: Mauricio Faria de Oliveira Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Alexey Dobriyan , Boris Ostrovsky , kernel-dev@igalia.com, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH RESEND v5 1/3] x86/asm, x86/boot: expose inline memcmp Message-ID: <20260701070531.GK48970@noisy.programming.kicks-ass.net> References: <20260630-pvh-kasan-inline-v5-0-52afc979be81@igalia.com> <20260630-pvh-kasan-inline-v5-1-52afc979be81@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260630-pvh-kasan-inline-v5-1-52afc979be81@igalia.com> On Tue, Jun 30, 2026 at 02:21:46PM -0300, Mauricio Faria de Oliveira wrote: > Move the inline memcmp function currently only available in 'boot/string.c' > into the shared string function header to be reused. > > This is not done through to avoid pulling unnecessary code > in 'boot/string.c' that causes build errors in 'boot/compressed/string.c' > and 'purgatory/purgatory.ro'. > > Note that the inline memcmp() returns 0/1, not -1/0/1 as regular memcmp() > (reported by David Laight ). > > Signed-off-by: Mauricio Faria de Oliveira > --- > arch/x86/boot/string.c | 6 ++---- > arch/x86/include/asm/shared/string.h | 16 ++++++++++++++++ > arch/x86/include/asm/string.h | 1 + > 3 files changed, 19 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c > index ac0f900ebc47efa81c92e1bb2010ea41677899c4..be454a6864225f3a972c3e81826b77ed4e8a57fe 100644 > --- a/arch/x86/boot/string.c > +++ b/arch/x86/boot/string.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include "ctype.h" > #include "string.h" > > @@ -31,10 +32,7 @@ > > int memcmp(const void *s1, const void *s2, size_t len) > { > - bool diff; > - asm("repe cmpsb" > - : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); > - 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..422952152f533ad75b98f3873297b39c4f5e2477 > --- /dev/null > +++ b/arch/x86/include/asm/shared/string.h > @@ -0,0 +1,16 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_SHARED_STRING_H > +#define _ASM_X86_SHARED_STRING_H > + > +/* Note: this memcmp() returns 0/1, not -1/0/1 as regular memcmp(). */ > +static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len) > +{ > + bool diff; > + > + asm("repe cmpsb" > + : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); > + > + return diff; > +} > + > +#endif /* _ASM_X86_SHARED_STRING_H */ > diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h > index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..f0f4fd8227bf992e78c69209efb31f0a9a0cc3b1 100644 > --- a/arch/x86/include/asm/string.h > +++ b/arch/x86/include/asm/string.h > @@ -7,6 +7,7 @@ > #else > # include > #endif > +#include > > static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len) > { It seems weird to have __inline_mem{cpy,set}() in a different header than __inline_memcmp(). I'm assuming this is because boot cannot include the normal string thing? Perhaps make inline_string.h or somesuch to carry all three of them and include that from the relevant places?