From nobody Thu Jul 23 21:13:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=igalia.com ARC-Seal: i=1; a=rsa-sha256; t=1784649445; cv=none; d=zohomail.com; s=zohoarc; b=ghmdLtlgT/n00Q+tczMkx7Qf/ffBaQrelqZTFVpbe8KHqW3j1oYeVu4H1TyHD5kM7Xz8SiKs14J13czSIr2cxmFKW/h3qaExRGU4f42jg+rv3vq0n5R7EVpThBCB1oN7oCzUBdjeYEMSUZWYW4a7fZ7b4MM3TN5YDMvCXNOU3Ug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784649445; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Uipb51QFeEvi5TG6B4ZY+2g5b0lo7cvCdn79s0YKKcE=; b=Cc6ZAn6sGHQBkbUzbBIPPa5u7WtAadjiRaPZHuj1H8KMdpE5FZs3xJ7bYwIf2qFX3CfMTPr3VDUqrhqKMprHEvaqVsogNXnmmVP1cnI5OkHaM++q7JTvuSw5hWMkLkNngcEPDPt3DTRx8LoSGFjt8fnWVuYLij7fz1mBpUrQ5vA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 178464944517790.6659891261678; Tue, 21 Jul 2026 08:57:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1367905.1617558 (Exim 4.92) (envelope-from ) id 1wmCq8-0003YO-0t; Tue, 21 Jul 2026 15:57:04 +0000 Received: by outflank-mailman (output) from mailman id 1367905.1617558; Tue, 21 Jul 2026 15:57:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCq7-0003YH-U0; Tue, 21 Jul 2026 15:57:03 +0000 Received: by outflank-mailman (input) for mailman id 1367905; Tue, 21 Jul 2026 15:57:02 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCq6-0003Y4-7h for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 15:57:02 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wmCq5-00542f-9u for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 17:57:01 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a5f96c5-e002-0a2a0a5209dd-0a2a4503c112-6 for ; Tue, 21 Jul 2026 17:57:00 +0200 Received: from [213.97.179.56] (helo=fanzine2.igalia.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a5f96cb-fae8-0a2a45030019-d561b338a856-3 for ; Tue, 21 Jul 2026 17:57:00 +0200 Received: from 186-249-149-197.shared.desktop.com.br ([186.249.149.197] 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 1wmCpt-001fqi-Eb; Tue, 21 Jul 2026 17:56:49 +0200 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20170329 header.d=igalia.com header.i="@igalia.com" header.h="Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" 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=Uipb51QFeEvi5TG6B4ZY+2g5b0lo7cvCdn79s0YKKcE=; b=hGk+yJ88jGjqL7iOLL1yEV/47c HP8E2r3TKSIVWPEtx/UpbVazkMudv3S1AqfGBfQ5FpwKcX7TdtVodfJV8fESYAsG3S6qGTfP5arV8 hhbfhE4Jgab6WOru3Q2bd0RKHFvYf7DoWPJZXVHDbeTEoSpBY/nZy3XHYtdPGuif0SetsmW8XdnCM PXA8IkSEtKcouxoOjI5Ba7iALVBJuDRPIf1wDSF8gyNSkGx5RUkywpY7p1uB22OCq+LTPe252oniN olsqR2fqsgPtmekvmu3dOW57RqCs1s421QtgCdRETkkYIxzg8b3Z3LazmDyn53TK5S/oY+btreQgK poR6RwOA==; From: Mauricio Faria de Oliveira Date: Tue, 21 Jul 2026 12:56:42 -0300 Subject: [PATCH v7 1/5] x86/asm, x86/boot: expose inline memcmp MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260721-pvh-kasan-inline-v7-1-38979a50cef0@igalia.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> In-Reply-To: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@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 X-purgate-ID: tlsNG-33051d/1784649420-756834E9-562BC017/0/0 X-purgate-type: clean X-purgate-size: 2184 X-ZohoMail-DKIM: pass (identity @igalia.com) X-ZM-MESSAGEID: 1784649446959158500 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'. 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 | 6 ++---- arch/x86/include/asm/shared/string.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index ac0f900ebc47efa81c92e1bb2010ea41677899c4..be454a6864225f3a972c3e81826= b77ed4e8a57fe 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" =20 @@ -31,10 +32,7 @@ =20 int memcmp(const void *s1, const void *s2, size_t len) { - bool diff; - asm("repe cmpsb" - : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); - return diff; + return __inline_memcmp(s1, s2, len); } =20 /* diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/sh= ared/string.h new file mode 100644 index 0000000000000000000000000000000000000000..02b92927553f7b8e1c87e6122bb= aa70439e57ea7 --- /dev/null +++ b/arch/x86/include/asm/shared/string.h @@ -0,0 +1,20 @@ +/* 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; + + asm("repe cmpsb" + : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); + + return diff; +} + +#endif /* _ASM_X86_SHARED_STRING_H */ --=20 2.47.3 From nobody Thu Jul 23 21:13:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=igalia.com ARC-Seal: i=1; a=rsa-sha256; t=1784649453; cv=none; d=zohomail.com; s=zohoarc; b=fg01gvjOdhU5WAklKzyiHOO+eDA/Sl1Ux7R7OFm/6UFTYgwoZGN2jxTZ5yodkXJsMoBEI2ogbd0/jWCWxYxIOEseMnWUe4AbGvXc68hABCx87wNH05XU00/b0Z+o7aTegb07hI5RkAyTKd32izfz9TNsvTc8nAj2qzpXTqHAXSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784649453; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=De2dzZj2ttdukFtf63NNllXcxOhpCCmsArNb8hGxCvQ=; b=I0zwa0Z+UXu3BrPGsT53tF9Vx2l2vtaeXxgUb+narwEmd305Cv4xMTmerdKmacJYJSPDbT5A0m2T9hmyUNI6S5EgcAUdVN0ekH2p6Dq0oEBHQfS3Tw/xPejajkdpIz5oyCVw2Z/W6LO5zItn3NQ38zx5QcWrffSwtLW6T/A4qkI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1784649453354812.2615999650415; Tue, 21 Jul 2026 08:57:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1367907.1617577 (Exim 4.92) (envelope-from ) id 1wmCq9-0003xl-J9; Tue, 21 Jul 2026 15:57:05 +0000 Received: by outflank-mailman (output) from mailman id 1367907.1617577; Tue, 21 Jul 2026 15:57:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCq9-0003xe-FF; Tue, 21 Jul 2026 15:57:05 +0000 Received: by outflank-mailman (input) for mailman id 1367907; Tue, 21 Jul 2026 15:57:04 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCq7-0003YG-Ue for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 15:57:03 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wmCq7-0030N8-4j for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 17:57:03 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a5f96a5-2eae-0a2a0a5409dd-0a2a450bdfd2-46 for ; Tue, 21 Jul 2026 17:57:02 +0200 Received: from [213.97.179.56] (helo=fanzine2.igalia.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a5f96ce-b7e8-0a2a450b0019-d561b338c9a4-3 for ; Tue, 21 Jul 2026 17:57:02 +0200 Received: from 186-249-149-197.shared.desktop.com.br ([186.249.149.197] 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 1wmCpx-001fqi-Oj; Tue, 21 Jul 2026 17:56:53 +0200 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20170329 header.d=igalia.com header.i="@igalia.com" header.h="Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" 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=De2dzZj2ttdukFtf63NNllXcxOhpCCmsArNb8hGxCvQ=; b=narRMe9qdgSyv2htjupS5xLCA/ UpBYEUhR2i7F/ieE7TontYsiFUncVK+69v4Zh6RreeDii9nB5w0mQ/aC83KKCzLthuHglKUcYDjko u0Cs3LJCpghLi0lNGq+IcEyNpfEL2wVLDToXk09DFSc5KghK7ihXvzoVNm4zZ4CcP2+MKIgelye0E tPvA1WtxAd94eKFrS9Fot9kNePPEkXciEOfL5JniFP9DWPzl18KD8YGFqCyohIyZ8wM38mRYXw7RO L9jxpje39WQcyovalSh1T/nkn+h4gQawnjhvCxX5ydVUVcI4rE4mY7RvOoKNKr2w4EZ7sDPHeyiGL i7oZ772w==; From: Mauricio Faria de Oliveira Date: Tue, 21 Jul 2026 12:56:43 -0300 Subject: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline memcmp MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260721-pvh-kasan-inline-v7-2-38979a50cef0@igalia.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> In-Reply-To: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@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 X-purgate-ID: tlsNG-42698a/1784649422-AB2DC9EA-B8750806/0/0 X-purgate-type: clean X-purgate-size: 1320 X-ZohoMail-DKIM: pass (identity @igalia.com) X-ZM-MESSAGEID: 1784649454364158500 Add the volatile qualifier and clobbers parameter to prevent bugs with instruction reordering and optimization. Also check the zero-length case, as the 'repe' prefix does not run the 'cmpsb' instruction if the 'count' register is zero, which doesn't set the condition-code/zero flag, so the result is based on a stale flag. Those are pre-existing issues found by Sashiko. Link: https://sashiko.dev/#/patchset/20260701-pvh-kasan-inline-v6-0-ba99045= dfa9f%40igalia.com Signed-off-by: Mauricio Faria de Oliveira --- arch/x86/include/asm/shared/string.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/sh= ared/string.h index 02b92927553f7b8e1c87e6122bbaa70439e57ea7..166274e44f3cb49e3dccab3cdac= 281d67aef5d44 100644 --- a/arch/x86/include/asm/shared/string.h +++ b/arch/x86/include/asm/shared/string.h @@ -11,8 +11,12 @@ static __always_inline int __inline_memcmp(const void *s= 1, const void *s2, size_ { bool diff; =20 - asm("repe cmpsb" - : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); + if (len =3D=3D 0) + return 0; + + asm volatile("repe cmpsb" + : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) + : : "cc", "memory"); =20 return diff; } --=20 2.47.3 From nobody Thu Jul 23 21:13:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=igalia.com ARC-Seal: i=1; a=rsa-sha256; t=1784649450; cv=none; d=zohomail.com; s=zohoarc; b=RRilZ/xGsemiJb9ghV3xX0BW98SLDIWelOwB1d4dlyZDrCX1+iL7gEM182b8xNICuLvuossvsGRzGmXBKcHQ7UJAtDX9FQCois/0iF3umVExOaWqszvXjGNa9ZD5ZZ37AEd91lmFl6Cmgj7Zo0SdUC4Hdxdez7+7oT7hh13TvUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784649450; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6ydr4gjm8knb3/GExgHyDpALgw8COsdA2yPnrgwuQDA=; b=Jw2MS98X7cyLsijjRALmodUjtGZTYW/QmTHi+M5cg08A+mNi3XmKTh6vBFnZXmEp07JyAXaVQuYT7DCvSCEPoLstQa+PBl9r+18KRRPnwcHzPtAvvt8wdsTlYo6PBKYSQm03p4jufSlheJes3SM5CboMgMbPS1sbZqH9qceofKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1784649450183429.5226539836525; Tue, 21 Jul 2026 08:57:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1367908.1617586 (Exim 4.92) (envelope-from ) id 1wmCqA-0004BA-PE; Tue, 21 Jul 2026 15:57:06 +0000 Received: by outflank-mailman (output) from mailman id 1367908.1617586; Tue, 21 Jul 2026 15:57:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCqA-0004B2-MF; Tue, 21 Jul 2026 15:57:06 +0000 Received: by outflank-mailman (input) for mailman id 1367908; Tue, 21 Jul 2026 15:57:06 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCqA-00047F-BQ for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 15:57:06 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wmCq9-00A8Sg-NB for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 17:57:05 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a5f96ce-5cb7-0a2a0a5109dd-0a2a4508a69c-6 for ; Tue, 21 Jul 2026 17:57:05 +0200 Received: from [213.97.179.56] (helo=fanzine2.igalia.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a5f96d0-f659-0a2a45080019-d561b338cf6a-3 for ; Tue, 21 Jul 2026 17:57:05 +0200 Received: from 186-249-149-197.shared.desktop.com.br ([186.249.149.197] 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 1wmCq1-001fqi-Km; Tue, 21 Jul 2026 17:56:57 +0200 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20170329 header.d=igalia.com header.i="@igalia.com" header.h="Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" 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=6ydr4gjm8knb3/GExgHyDpALgw8COsdA2yPnrgwuQDA=; b=SsVENWohVjwIJtHkP79GoUi3hF +s/IaQPs1ixDPA84dNDdk3hqoealnVkF9L+JuQ3VilOhMV9uL1FD2XCjblhCOpxtBYbPTl/0NiBm7 jQgAE8MHz5Il/Z5zV01CgHGkdMnzWZZo9dFbUoWfHOaSDsfr1dVfSSx/qU0GJp+vl+UGICUYcwonC w8ae0iNXNB3xiCvHssfIoZARP98r8fRiz/61TJqoJRnG1KnLUQQB87yhDUoyDJW9EbKbQUbOhE55v w5YUN/lFGE7ay7QUoOWiZvrrmFPXvKYADlNjZ75dnFKwyA7u0HXxYi4XifbOyE/BS4JUIuOY/4ABf 3Zzayl8A==; From: Mauricio Faria de Oliveira Date: Tue, 21 Jul 2026 12:56:44 -0300 Subject: [PATCH v7 3/5] x86/asm: group inline string functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260721-pvh-kasan-inline-v7-3-38979a50cef0@igalia.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> In-Reply-To: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@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 X-purgate-ID: tlsNG-c1860d/1784649425-D6B4187B-CF0F6831/0/0 X-purgate-type: clean X-purgate-size: 2425 X-ZohoMail-DKIM: pass (identity @igalia.com) X-ZM-MESSAGEID: 1784649452520158500 Group the __inline string functions in the same header. Use since __inline_memcmp() must remain there for use by arch/x86/boot/string.c. Signed-off-by: Mauricio Faria de Oliveira --- arch/x86/include/asm/shared/string.h | 26 ++++++++++++++++++++++++++ arch/x86/include/asm/string.h | 21 +-------------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/sh= ared/string.h index 166274e44f3cb49e3dccab3cdac281d67aef5d44..9714fbda8b734e20686bfb88a6c= a857bfee59e1a 100644 --- a/arch/x86/include/asm/shared/string.h +++ b/arch/x86/include/asm/shared/string.h @@ -2,6 +2,32 @@ #ifndef _ASM_X86_SHARED_STRING_H #define _ASM_X86_SHARED_STRING_H =20 +/* + * The __inline string functions are grouped in this file for consistency = and + * for use by arch/x86/boot code due to limitations on including asm/strin= g.h. + */ + +static __always_inline void *__inline_memcpy(void *to, const void *from, s= ize_t len) +{ + void *ret =3D to; + + asm volatile("rep movsb" + : "+D" (to), "+S" (from), "+c" (len) + : : "memory"); + return ret; +} + +static __always_inline void *__inline_memset(void *s, int v, size_t n) +{ + void *ret =3D s; + + asm volatile("rep stosb" + : "+D" (s), "+c" (n) + : "a" ((uint8_t)v) + : "memory"); + return ret; +} + /* * This inline memcmp() returns 0 (equal) or 1 (not equal). * The regular memcmp() returns <0 (less than), 0 (equal), or >0 (greater = than) diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..dbf59f0d4cca71e2ddce0d8764a= eec8782236669 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -8,25 +8,6 @@ # include #endif =20 -static __always_inline void *__inline_memcpy(void *to, const void *from, s= ize_t len) -{ - void *ret =3D to; - - asm volatile("rep movsb" - : "+D" (to), "+S" (from), "+c" (len) - : : "memory"); - return ret; -} - -static __always_inline void *__inline_memset(void *s, int v, size_t n) -{ - void *ret =3D s; - - asm volatile("rep stosb" - : "+D" (s), "+c" (n) - : "a" ((uint8_t)v) - : "memory"); - return ret; -} +#include =20 #endif /* _ASM_X86_STRING_H */ --=20 2.47.3 From nobody Thu Jul 23 21:13:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=igalia.com ARC-Seal: i=1; a=rsa-sha256; t=1784649459; cv=none; d=zohomail.com; s=zohoarc; b=GyJnr7oGvhd84VwJJAqPjG0b0/yl5tEuD3qmmAkklTflTMZD0HOuQ9ZijTp0+ujwdKXIEPuVzK6eoCkT5lo2Y0+SH6v3wESuZ2LPKlvW4QJtUU4/WpUf0lR9Ti1IoxzLchFZNeLbr9JTLDC/piWBcEKfKR4fXsVMPODWrYUrrv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784649459; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H2GAc7mtrFpKl87p+adcJZhrkVbc1evwDywNzt1ulrU=; b=QwZyLH5wpWExtd46wHmbaG/ZvkYmokfyejo1QxqFI4CODme9qkbTnj3DuM5vg6eG71mOid4mYQh0WM2T+1IRXGzKotDVE94n7fCsMdAqcQxPw8IlxapxqjVD/9qawi0J5WNsYoq9G+LN4XeGJpl57YFm4ljQV4jemG+ZdKzwskQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1784649459153405.70796763133774; Tue, 21 Jul 2026 08:57:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1367909.1617595 (Exim 4.92) (envelope-from ) id 1wmCqG-0004Tk-0n; Tue, 21 Jul 2026 15:57:12 +0000 Received: by outflank-mailman (output) from mailman id 1367909.1617595; Tue, 21 Jul 2026 15:57:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCqF-0004Tb-TG; Tue, 21 Jul 2026 15:57:11 +0000 Received: by outflank-mailman (input) for mailman id 1367909; Tue, 21 Jul 2026 15:57:11 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCqF-0004SE-47 for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 15:57:11 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wmCqE-00FUhY-HK for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 17:57:10 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a5f96d3-5cb7-0a2a0a5109dd-0a2a45028c22-8 for ; Tue, 21 Jul 2026 17:57:10 +0200 Received: from [213.97.179.56] (helo=fanzine2.igalia.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a5f96d5-6ca4-0a2a45020019-d561b338c1ba-3 for ; Tue, 21 Jul 2026 17:57:10 +0200 Received: from 186-249-149-197.shared.desktop.com.br ([186.249.149.197] 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 1wmCq5-001fqi-KV; Tue, 21 Jul 2026 17:57:01 +0200 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20170329 header.d=igalia.com header.i="@igalia.com" header.h="Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" 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=H2GAc7mtrFpKl87p+adcJZhrkVbc1evwDywNzt1ulrU=; b=jkKx9H55MATnseHJXY81Cspvjl 99yL1XY80tw3CjNdRhms7d2OgdbbPrMwjer7mpauJndcaay8k1gKRvA6DRea0FRzmmy7Z83AOFCo6 2Do13QujniJVM+JrS0AyG87eUPc5rB4EzSE8Mj062ssbo2Pwmr2WhEVZh5vEFZ5neyOZss4rYM7aO nnA55l0uLXkxNJyDs0lm7ZJ7THEVb099ufQ2eQ2hYrBdIqw+8AVIqDC9gS/Qvl6mYEPV9E/NfodXs aEtW05edbcx6O0H8EWeIxodq5SF69Wp3FXOCUgxpj7fJhtLoI0uSHaZeytExSJQT2z/CvOMr9FVaC I/xKiP8g==; From: Mauricio Faria de Oliveira Date: Tue, 21 Jul 2026 12:56:45 -0300 Subject: [PATCH v7 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260721-pvh-kasan-inline-v7-4-38979a50cef0@igalia.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> In-Reply-To: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@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 X-purgate-ID: tlsNG-720697/1784649430-F3CBA2AC-9A7A3234/0/0 X-purgate-type: clean X-purgate-size: 1458 X-ZohoMail-DKIM: pass (identity @igalia.com) X-ZM-MESSAGEID: 1784649460427158500 Even with __builtin the compiler may decide to use the out of line function instead of the inline implementation. The existing code is broken with gcc-14/15 but not gcc-12/13 (Ubuntu 25.10) and vmlinux no longer boots with CONFIG_PVH if CONFIG_KASAN_GENERIC is set. For testing purposes, if the size argument is reduced from 12 to 8 then the compiler decides to use the inline implementation; that shows results vary. Switch the builtin to the inline implementation to address it. Fixes: 416a33c9afce ("x86/cpu: fix unbootable VMs by inlining memcmp() in h= ypervisor_cpuid_base()") Signed-off-by: Mauricio Faria de Oliveira Reviewed-by: Juergen Gross --- arch/x86/include/asm/cpuid/api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 82eddfa2347b32b76c2ea9b85f005ca5416ac71f..2d9f3d4d63de6e721f275d9e80d= 372edbdfedf30 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -204,7 +204,7 @@ static inline u32 cpuid_base_hypervisor(const char *sig= , u32 leaves) * from PVH early boot code before instrumentation is set up * and memcmp() itself may be instrumented. */ - if (!__builtin_memcmp(sig, signature, 12) && + if (!__inline_memcmp(sig, signature, 12) && (leaves =3D=3D 0 || ((eax - base) >=3D leaves))) return base; } --=20 2.47.3 From nobody Thu Jul 23 21:13:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=igalia.com ARC-Seal: i=1; a=rsa-sha256; t=1784649454; cv=none; d=zohomail.com; s=zohoarc; b=NfwWG54Eor/7x2Y+IEX0bIlnsHciHZwOWIK9vIpf2JoMHyWj72XtslGbya+GmbKYq7bNjmw//42SbYNpy42CmMkXlcIRobHPSreVa4HKJHuv18oY+p7izNUHdDlbtJWYzhoFFJ1a6ZlOmk5f+0/9UQmIw9L14SL7dLzGrE5F75c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784649454; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zBAAE6UPiVcuOT4Hdx5zYoG+Uei+rPkEJSxQ4+nbtAc=; b=kvnG2A/9FIpnamePkaqX2B/hYByxwlPvI/jL9DcErU3VtPSRqMrU+GzLmQUeRDbxPJEmCJENt6qJUl7RRMGRRQ7ey/BMpU8CTzfqVuQD2N4WRH1pvXokEQnnYi31/dHPi0Cb6p3ktiwCetVPlz6X5JhPjmFzEZzCt4xAWNOourI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1784649454398950.8547310104766; Tue, 21 Jul 2026 08:57:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1367911.1617603 (Exim 4.92) (envelope-from ) id 1wmCqL-0004pt-8S; Tue, 21 Jul 2026 15:57:17 +0000 Received: by outflank-mailman (output) from mailman id 1367911.1617603; Tue, 21 Jul 2026 15:57:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCqL-0004pf-4k; Tue, 21 Jul 2026 15:57:17 +0000 Received: by outflank-mailman (input) for mailman id 1367911; Tue, 21 Jul 2026 15:57:16 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wmCqK-0004nH-8Q for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 15:57:16 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wmCqJ-00546t-Jw for xen-devel@lists.xenproject.org; Tue, 21 Jul 2026 17:57:15 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a5f96b4-e002-0a2a0a5209dd-0a2a4506d0f4-44 for ; Tue, 21 Jul 2026 17:57:15 +0200 Received: from [213.97.179.56] (helo=fanzine2.igalia.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a5f96db-195a-0a2a45060019-d561b3389efc-3 for ; Tue, 21 Jul 2026 17:57:15 +0200 Received: from 186-249-149-197.shared.desktop.com.br ([186.249.149.197] 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 1wmCqA-001fqi-7r; Tue, 21 Jul 2026 17:57:06 +0200 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20170329 header.d=igalia.com header.i="@igalia.com" header.h="Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From" 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=zBAAE6UPiVcuOT4Hdx5zYoG+Uei+rPkEJSxQ4+nbtAc=; b=JrbOnFQR6dfy/X/BZvtx9of337 mDDlmRD41imICMI1FGTnn5J0zzoMzEReUP8KM9dS2pdkZBuiviwA2X/GCTxk+wTWd1vVJ7u1OQ7m7 vPPBQyHafQmncEvQDOu71j0nTsBoZQE3V5WRB32p+GoJBUdx5RJ3EIv9DMB8jQPrwTGoHPK1LT0Zn HphIxyb63klsPuH5iBsJ8uH3IZJdL8ucIkrGoRchp3N3iEjU03C6Ge0XYdTqBad1fzb3LC4mUgdmd kUrs5K2OYc6HOCWl6JxrLBy6U3bIWkD8EHlcoK//Dwoq6Z/1gr/iqPJcUHYUhVyG9w5Bj4jJTdOF3 x/4vn0Wg==; From: Mauricio Faria de Oliveira Date: Tue, 21 Jul 2026 12:56:46 -0300 Subject: [PATCH v7 5/5] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260721-pvh-kasan-inline-v7-5-38979a50cef0@igalia.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> In-Reply-To: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@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 X-purgate-ID: tlsNG-16d1c6/1784649435-FD20877B-90D1485B/0/0 X-purgate-type: clean X-purgate-size: 1416 X-ZohoMail-DKIM: pass (identity @igalia.com) X-ZM-MESSAGEID: 1784649456367158500 Even with __builtin the compiler may decide to use the out of line function instead of the inline implementation. This particular one (still) generated the inline implementation as expected (at least in these compiler versions) but this is not guaranteed to remain. Switch the builtin to the inline implementation to address it. Fixes: fbe5a6dfe492 ("xen, pvh: fix unbootable VMs by inlining memset() in = xen_prepare_pvh()") Signed-off-by: Mauricio Faria de Oliveira Reviewed-by: Juergen Gross --- arch/x86/platform/pvh/enlighten.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enli= ghten.c index f2053cbe9b0ce3d2178938269607c652ae8f528e..cb442cbd9d828619421babb281b= fe9759edbca8a 100644 --- a/arch/x86/platform/pvh/enlighten.c +++ b/arch/x86/platform/pvh/enlighten.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 #include =20 @@ -129,7 +130,7 @@ void __init xen_prepare_pvh(void) * This must not compile to "call memset" because memset() may be * instrumented. */ - __builtin_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams)); + __inline_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams)); =20 hypervisor_specific_init(xen_guest); =20 --=20 2.47.3