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 357F935F8C9 for ; Sat, 22 Aug 2026 18:33:12 +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=1787423596; cv=none; b=iMBSCci4ko2Oko/NeZXVRg393Yf3Eb5qE839LmjbX8MUSDnIjDeJ3WbUfT8lcFKufwS1DN4mh8xlrrZzFn4QlakXn/CYOCJeX/jvWydf0intYPE3xNIzQoamxtxcdIbJglpha2LjiK2o6GbolnH51vNsG0F1mB7TDeCh1V1I7MM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787423596; c=relaxed/simple; bh=ttEOtfMUlQNZRhLXYSAIaxxQVNy8G6eDqI8W7SsNVoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lmgY4IjHxynVNwroV3sE5CnNr0qvK/R/DrOsypYVe/ckSCR7ts3m9IA2TcdD3dE90KlTqTRU0gjIHPFCLC1j2/dO3twGyi9nnY7l5ed9lIUr9dgQM6i2bTWzPsnY8yRshSXWJzkg1VwN1GPnZ2uDOS0YdYzoSWiY6PWo1jQqtKQ= 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=o1Z+vuNG; 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="o1Z+vuNG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=MfLC1dIVusQxZmyyohtK3IB4hBpAg/kOqSLp9mxwz1M=; b=o1Z+vuNGqvlMK/ozeR0ZPZbzr1 gAQJqvr5CTnKAOkG9FSljuSrO7FBTDKKyyxvLqRc0XQYtRff6BhHSr6b2JpR8m8aqc3MYeM8fhc7u C5rwoS4DgpDkFS2xMIqzIMu4VHDgWluOs6s236Wx+O6j7O0z0FoMWlIt5GbxY6MwBRs5xNFuKz7ut GOU0x8Sho2S8rnKR2SZzqU1YpjnhxkZSMunIiVO9M2TZzt25+FiG0ysrCy8nBQihnZLZD8RUWVwUu 0iig+O6Dt7z1KJcrkzHM27AKSg+JjS/hcQZek133GV2/n+ZY6sEroD+a4QyRaV8CJZa8AIfcZn9/A 7oo4Zviw==; Received: from 186-249-148-4.shared.desktop.com.br ([186.249.148.4] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wxqWc-007bWT-5S; Sat, 22 Aug 2026 20:33:02 +0200 From: Mauricio Faria de Oliveira Date: Sat, 22 Aug 2026 15:33:18 -0300 Subject: [PATCH v9 2/5] 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: <20260822-pvh-kasan-inline-v9-2-e70ef3b75b6a@igalia.com> References: <20260822-pvh-kasan-inline-v9-0-e70ef3b75b6a@igalia.com> In-Reply-To: <20260822-pvh-kasan-inline-v9-0-e70ef3b75b6a@igalia.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Alexey Dobriyan , Boris Ostrovsky , Jan Beulich , Brian Gerst 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 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'. No functional changes. Signed-off-by: Mauricio Faria de Oliveira --- Thanks to David Laight for noticing the return value difference between inline and regular memcmp(). --- arch/x86/boot/string.c | 13 ++----------- arch/x86/include/asm/shared/string.h | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index 03278b4393887cb71cb063818d3378c4f52b06f8..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,17 +32,7 @@ int memcmp(const void *s1, const void *s2, size_t len) { - bool diff; - - /* - * Make sure ZF is properly set in the len==0 case because in it, - * RCX==0 and the REPE; CMPSB won't get executed. - */ - asm volatile("test %3, %3\n\t" - "repe cmpsb" - : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) - : : "memory"); - 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..06c1d5e5013e4d59cfb49866d10e164362d2c4cc --- /dev/null +++ b/arch/x86/include/asm/shared/string.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_SHARED_STRING_H +#define _ASM_X86_SHARED_STRING_H + +/* + * This inline memcmp() returns 0 (equal) or 1 (not equal). + * The regular memcmp() returns <0 (less than), 0 (equal), or >0 (greater than) + * to indicate ordering as well. + */ +static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len) +{ + bool diff; + + /* + * Make sure ZF is properly set in the len==0 case because in it, + * RCX==0 and the REPE; CMPSB won't get executed. + */ + asm volatile("test %3, %3\n\t" + "repe cmpsb" + : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) + : : "memory"); + + return diff; +} + +#endif /* _ASM_X86_SHARED_STRING_H */ -- 2.47.3