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 9EF52401490 for ; Tue, 26 May 2026 14:53:10 +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=1779807192; cv=none; b=dUXlmUunspaROfZpoW/VbglLaobu0lxw8f6h3daigzMtJpE/CIQVvC7Xtu/23Vfu5IsRToC8AdFjTZ7GOsYofycHbeLQA/94NtYJH4ui8Y6yqYNHpeSB0yDBcFVGY3/XL3KmlU158G80k9u2z3tJNIcsxVYW8M+KjKKmD8yCDlQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779807192; c=relaxed/simple; bh=6gPEFS5PB1ZY8aGvkIwnsSd14VrBYDyN6jvykgK+Egs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nKKBILTtl+3EMyM6unUYt+hpLcPXv4ppjsfoWWRHyx6LUARqYXSSYB+w9P5bozTFbm2Oeosr20pfrP3H6JjCbd3Rw1BejoNfpWw8TEbX9XAmCRM+yN2V2KVZeOKQ4GwHWuqntzB6qE4XuWjKvrxI2kHKfHHDsJUZt80gN4UcWJg= 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=RJTHWlKG; 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="RJTHWlKG" 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=UTOmAuiPQ1w9q3gPb2qsdx9jiBuxtzvoq44hIQ1/dkQ=; b=RJTHWlKG1FeZ9gjM4LsjQuc4z9 +EQtwpdyMJpAtgaD4rOIVqx8Z99YlVI9XB6jBHb6uJYJoPyHJixkVQMqzdi7qdxja69KdeeFeGMhz 3yxL2rVgY6JiUVCUZyeK+kgW5Df5TQ1MvN8IcIOJJ4RLddvuoncNls7UDgyWAfAyBSJ9riQS3MjgK y4/bYCWT6uTLVwUq+vX0ms9ijYzHwBU6gudxf6Zwt4E0sGM/pwigpWIuDzfkvy6TpvLfQD6O+eGsE C7csYOpMgdpyVA2bjrhy1dclhRahumZC3ivC8LdLf9uYdd8dnf2DGxYTnK1Sc5gn/crvTQStqiMu/ 7qXv9MQw==; Received: from 186-249-145-161.shared.desktop.com.br ([186.249.145.161] helo=[192.168.1.68]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wRt9K-008TwX-OV; Tue, 26 May 2026 16:52:55 +0200 From: Mauricio Faria de Oliveira Date: Tue, 26 May 2026 11:52:34 -0300 Subject: [PATCH v4 2/4] 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: <20260526-pvh-kasan-inline-v4-2-a310e6a25ecd@igalia.com> References: <20260526-pvh-kasan-inline-v4-0-a310e6a25ecd@igalia.com> In-Reply-To: <20260526-pvh-kasan-inline-v4-0-a310e6a25ecd@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 in 'boot/string.c' and its users (eg, 'boot/compressed/string.c' and 'purgatory/purgatory.ro') into the inline string functions header to be reused. Note that the inline memcmp() returns 0/1, not -1/0/1 as regular memcmp() (reported by David Laight ), which is not caused or changed by this commit; this will be addressed separately. Signed-off-by: Mauricio Faria de Oliveira Reviewed-by: Juergen Gross --- arch/x86/boot/string.c | 6 ++---- arch/x86/include/asm/string_inline.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index ac0f900ebc47efa81c92e1bb2010ea41677899c4..544681d046c3f87101309ffaca0c90512a244856 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_inline.h b/arch/x86/include/asm/string_inline.h index ffcfa6583d2bc7b91d078888518d0e80248af940..91ed89bfdfa9b148002441e94f48039b17f70391 100644 --- a/arch/x86/include/asm/string_inline.h +++ b/arch/x86/include/asm/string_inline.h @@ -23,4 +23,15 @@ static __always_inline void *__inline_memset(void *s, int v, size_t n) return ret; } +/* 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_STRING_INLINE_H */ -- 2.51.0