From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 68556360EC3 for ; Wed, 1 Jul 2026 14:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782917939; cv=none; b=L2yIsOguAmCH8SSsj4fc+DMsL9FlIEf4S+SvULz/il0ozsWQhfW0VhSArJ9XlCR26M/Tfk6FzfFBMZdl8M8PSB7/4lKaQPaVkw9/OKTnsasCOrdr2pmZIj/fRiKO76tGqiqb6Bxbr61vX/7ZlMuEgA7Bm3u7wl1ydOrCG9fVAf0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782917939; c=relaxed/simple; bh=1uOM5lsFMLLw4ODf/wPfN/Ti3F6O0goLAyeXULhGhPQ=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=qYlcMtKPBcLKQ4AsZrotwOpP9gtWdWDEkzWEkcGmX3j8Nd+qdbQ6Xzx5pBe4FEy/h3B4rHS3bFFg4LFdoQsGuF1gCRIuPyUHpDt4QsfB5XLZzTS5thQVfF6POMUxbQOOoX5lcf/ObTnpnNvdi4faV8Y18ESyj+lOASxZHHjz9XA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=PVy1HSQL; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="PVy1HSQL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:Message-ID:References: In-Reply-To:Subject:Cc:To:From:Date:MIME-Version:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BZbTYczaqR+mc0JSoafl6QcdAzR5SvJPdrKk020zPEg=; b=PVy1HSQLMkQpFi7ZTp853RG96b F2mF12VBmD1hT/zcrqto++UkCFfRWhhxRJ8mlk5lnCU1HMZ9w9MSTXUCDJJxTL464QIi5fLKqe53P hQWAUxmAxLJKfvrZoGTRDyyvP0Rz5BFSu1uRa4rGqFFLGyMdIYEk7QE359FXCSzpWrixldz1LYPsG Y6ug4IkBhv1nKfxHNt62cYIL3DC+ySS+M8Sq49/nhmGYCeVMGwLqvXJO9VzNJxjdKVEV9fSEu+CMe VFT9FcR4vkE9tQI3/rsi9C/rCdhcT6wDhaKgo+P6UC5pznSJ6pe1cata4EyIIgqE+hM58kzVi9uOw PC7GOjjQ==; Received: from maestria.local.igalia.com ([192.168.10.14] helo=mail.igalia.com) by fanzine2.igalia.com with esmtps (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wewOT-007byj-B1; Wed, 01 Jul 2026 16:58:29 +0200 Received: from webmail.service.igalia.com ([192.168.21.45]) by mail.igalia.com with esmtp (Exim) id 1wewOQ-00841m-SR; Wed, 01 Jul 2026 16:58:29 +0200 Received: from localhost ([127.0.0.1] helo=webmail.igalia.com) by webmail.service.igalia.com with esmtp (Exim 4.98.2) (envelope-from ) id 1wewOQ-0000000DnWw-2mEJ; Wed, 01 Jul 2026 16:58:26 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 01 Jul 2026 11:58:26 -0300 From: Mauricio Faria de Oliveira To: Peter Zijlstra , Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , 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 In-Reply-To: <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> <20260701070531.GK48970@noisy.programming.kicks-ass.net> Message-ID: X-Sender: mfo@igalia.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Report: NO, Score=-2.2, Tests=ALL_TRUSTED=-3,BAYES_50=0.8,URIBL_BLOCKED=0.001 X-Spam-Score: -21 X-Spam-Bar: -- On 2026-07-01 04:05, Peter Zijlstra wrote: > 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? Thanks for looking into this. Yes, your question and suggestion above are essentially patch 1 in v4 [1]. Borislav Petkov requested a clean header in arch/x86/include/asm/shared/ for this (without other code), which is patch 1 in v5. cheers, [1] https://lore.kernel.org/all/20260526-pvh-kasan-inline-v4-1-a310e6a25ecd@igalia.com/ -- Mauricio