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 821CA34A3DB for ; Mon, 27 Apr 2026 16:11:24 +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=1777306287; cv=none; b=cutQaHFgMEYdnrpbLYxo/lccxdX5FNniJoVPcBiDKxRx9XFETRU0VPvZ8krheJuRf/Dl78V4I3xfzi65z8ZK/2M56YOahw88wbAmRZdzla93HRw2BFjWrnt9y7/YGW829ZEWHBrS9n9D+0uJhKRGBztF/c8C7ae/qg3IVfuNERs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306287; c=relaxed/simple; bh=2NzYCXUW0l/PmHNG0o7AKzQ0U67HXPZFcy3oxZxQPjs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RElPpcMpqcwIn6yT00cBnIBrmw96yEl+qAvAHG9GR/xzmSNxWplEbGpnCS9RKorbl+Tnw3NTlkc/p/RbtY8UpzDPtvKjAhpdKEub9fOdERpOM/13DK1mbSucS8U8NCRHMdv7ogqIgy+zaZ9fR+4Q7QIyMMlXSVUsyQijE2NqaAA= 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=QxsK4/f7; 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="QxsK4/f7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: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=n3ajKxuTrRUfsiVj5FBK8xcgDaSM+ZE9NLMVQk1nTrI=; b=QxsK4/f792XfNJZnw4R/py56Gm O+k4W/mihmFFVTUUZMfQ0nUdEg1WrfuqVZJxD3rPNqi2E+ytoTDyLexvIR3OCaQ/+pmWsRuUxFr4T aNisP+xzF1BD6JdDL1oaYcc+61KIfukuaFd0wFL+ZQnbvU0l5ugtrNZa/vAiOm1d6mVfMzqpTW9t0 dbS1QpK4yuAJPUmhTrvHjpw4cV+9EBagVyLamVRWDWm4F/CzeGTpRN+hRtmtP3P9HtOvJuDOJSzwy XhFHlnU3CLZ91x/hLBoIYlN5b9n1z1U5lML0P7HUP4GuJZCIhoyhSma7jlgvvI9FjN0pCsM8yA3rF Lk1TaFVw==; Received: from 186-249-145-131.shared.desktop.com.br ([186.249.145.131] helo=[192.168.1.66]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wHOYA-00305I-Nh; Mon, 27 Apr 2026 18:11:10 +0200 From: Mauricio Faria de Oliveira Date: Mon, 27 Apr 2026 13:10:57 -0300 Subject: [PATCH v2 1/3] x86/asm, x86/boot: Expose inline memcmp 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260427-pvh-kasan-inline-v2-1-2c57b8dcff6a@igalia.com> References: <20260427-pvh-kasan-inline-v2-0-2c57b8dcff6a@igalia.com> In-Reply-To: <20260427-pvh-kasan-inline-v2-0-2c57b8dcff6a@igalia.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Alexey Dobriyan , Boris Ostrovsky Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Move the inline memcmp function, currently only available to boot code (boot/string.c), into the header with similar inline string functions (include/asm/string.h) so it may be reused. Add a _SETUP guard in string.h so not to include the 32/64-bit specific string headers in boot/ code (16-bit, real mode) and avoid build errors. Note: this memcmp() only returns 0/1, not -1/0/1 as regular memcmp(), as reported by David Laight. This should be addressed separately. Signed-off-by: Mauricio Faria de Oliveira --- arch/x86/boot/string.c | 6 ++---- arch/x86/include/asm/string.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index b25c6a9303b7314d5caf5c9306239811705294fe..bbee78637b349e42e9281d8df50d89d48f4490b9 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/string.h b/arch/x86/include/asm/string.h index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..ae6c1f4fda858bd8370647557529d98c23305a53 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -2,11 +2,13 @@ #ifndef _ASM_X86_STRING_H #define _ASM_X86_STRING_H +#ifndef _SETUP #ifdef CONFIG_X86_32 # include #else # include #endif +#endif static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len) { @@ -29,4 +31,14 @@ static __always_inline void *__inline_memset(void *s, int v, size_t n) return ret; } +/* Note: this memcmp() only 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_STRING_H */ -- 2.51.0