From nobody Sun May 3 14:26:26 2026 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: quoted-printable 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..bbee78637b349e42e9281d8df50= d89d48f4490b9 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/string.h b/arch/x86/include/asm/string.h index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..ae6c1f4fda858bd837064755752= 9d98c23305a53 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 =20 +#ifndef _SETUP #ifdef CONFIG_X86_32 # include #else # include #endif +#endif =20 static __always_inline void *__inline_memcpy(void *to, const void *from, s= ize_t len) { @@ -29,4 +31,14 @@ static __always_inline void *__inline_memset(void *s, in= t v, size_t n) return ret; } =20 +/* 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" + : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); + return diff; +} + #endif /* _ASM_X86_STRING_H */ --=20 2.51.0 From nobody Sun May 3 14:26:26 2026 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 8225734CFAB 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=h+yP2h/xqABQrU1nZwkAZoC/Y6aAZwN4TL12iGqHsknjhMGc41/OlwP3eXaerN2RaJrcXh5zZoW8+8XYSDiBSgoOTxCUZ5PRZ3rIvGxW4Iay1XBquBeowo2+gkmMqsAga1ANfhEwJDT+NuodJ8D7vcp5r6gp3F0voapxjuH8GkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306287; c=relaxed/simple; bh=8gVzdoicfvdCkC7sgsGM/tA8kC0LNOWWaGgnOhovi/Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cQXdmpZ86j9sastLEBdwlOONasKJ/hIrmZMSAGxGrcna5wk6CLJspI6ne7cBrjsYoSSCFEEsWmKUmNEqij9ctA7+GChiMlHX5mLeRAoi2D5yEUdfb69RHt4d7eUTLEPxWWAjLQa0GeXMwy+jOoWLJq2w3VVxTOFBc+0zrMOet8k= 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=bT9QWa2/; 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="bT9QWa2/" 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=Zz/49n6HLOp2S/OeD7sPTmJzkRUr+J7y2sWYsLTQJ/E=; b=bT9QWa2/6EnHf8FMEWzVyJYWdg TndVTUiVOSQd5LUgUvgdaW55vIe5zI5VuKSjfjlU55pSWRKbw3ls2QbctcOEoaEeLcvZbMRGinUcA k4wQSxM7YiAH7YxhMKVKA0YDO/pdXtCgBcL38Lv97jzH2HVlkrEl3BPMyaDLgrmRHr5gGz+8Uobb/ PD05O8QljGHOdLYiy5UsNnHfqUkObU0gNRMhZ9g3KIZIn3UFGbhmn9TAmcFQNrwD3O5sbkWHLVwAS EFgTSTfHa+ccp8g4ZIULndckD596O2T7kXh95DWTSDlAvOGi9rNce49LR1RJY/ipOm8hV8zDDsq0u DE1U06mA==; 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 1wHOYF-00305I-4T; Mon, 27 Apr 2026 18:11:14 +0200 From: Mauricio Faria de Oliveira Date: Mon, 27 Apr 2026 13:10:58 -0300 Subject: [PATCH v2 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() 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: quoted-printable Message-Id: <20260427-pvh-kasan-inline-v2-2-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 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 44fa82e1267ce98c7f5f92f69b58f79e235f7261..c3bd1e51067346e817240b484dc= 0d0e5f02dcc4f 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -203,7 +203,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.51.0 From nobody Sun May 3 14:26:26 2026 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 1329A350D7D for ; Mon, 27 Apr 2026 16:11:28 +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=1777306290; cv=none; b=YRa5NYWSFC27FSYhttWI3abfBhiOJu73CAnzmqU/G9NiE1YTu29dbPE+7IYtPvcFzdr8lfGotk/YJHeJ3HMdVm+elElUBQZzYZwEoEjxWLA88h0nmQlYz5VqQD4pEMj1fXNeySbC8W/vVCaPD2xWMQr0qD2jSQyk2bancS4al5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777306290; c=relaxed/simple; bh=Rpd2bDENozYBUXz5eQwv3LiQKsh6q8YFJplqg+d4FyA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GV1H36YOCDqCCRlnWuVx3BzV5kJi9E9zwUC90h0PtRh5eKzRX2RAZgYYcGKt1gxxMCN+G37G1LmwUdhsFYqoc+L/RimRo3gsjasdJPCq6/IoEqSbmUbSimYmMp/v0AXnMxXNTkSU6WRZLt38CRvQGYxSHtytvkKwRGQm5tQBJks= 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=fgk9vBXi; 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="fgk9vBXi" 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=L3Sr9rY5U1mD/3546TE+xOT1mBFRY3YzwAzYlEgEGo8=; b=fgk9vBXil4XOQk4uEvi1ffSPD/ Ddejad/dkDzfLbOfDpVRwlSEL8l+83x9REQxqLJE5P0P7Zcnblttj3wKgaJIAgeJCuLMvDs93QHmB yQ+8cMrD8LBhVzy/NBcad2ZndJY56E3kRvhPzpN7oMsiaqahalL2FvucTDUE+/VAJG7Nok8J+9uK5 gMyGYvmDSEuR69SyjaV4wxkHe+wyJio9QLxsqdNfI3WH6dtxol/474EbFFs+fVkEMzTnbI0Gx7IAh I93hGl9HcJZRK/+jDv8TvrqkYWVAG/lKWWRB0AHOwLqdPC5dlQ6PqZhywGCh4b3rXOuhjgZT6H5b6 Ql97rhvQ==; 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 1wHOYJ-00305I-Ut; Mon, 27 Apr 2026 18:11:19 +0200 From: Mauricio Faria de Oliveira Date: Mon, 27 Apr 2026 13:10:59 -0300 Subject: [PATCH v2 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() 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: quoted-printable Message-Id: <20260427-pvh-kasan-inline-v2-3-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 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 the case, as seen with the previous commit. Switch the builtin to the inline implementation to prevent a similar issue. 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.51.0