From nobody Thu Apr 9 09:03:33 2026 Received: from mail-qt1-f226.google.com (mail-qt1-f226.google.com [209.85.160.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7529E1F09A8 for ; Tue, 10 Mar 2026 00:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101835; cv=none; b=dDPSuUY8rVyBBvmLoKkr+Rkn2xE9KLpkXThVkanNWVOTLt0jzQMt1UuWsPVvGAI93r8ZbvOA7dHWSUyfP8JjGtCkTE6MNjP3h+9yfEzcplmdQUECFS7IPWZUvgWtdB6FvltsRkVKOFhj41J0eP/EH6IB/iws4TUK4qEOEB9WnCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101835; c=relaxed/simple; bh=sYGIrnAJyjCt8iIoF30ta2b9Ec4Gre5mQsKFa6a6+tY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SzVMqHO8kSzxEM0OOksAHdnafNmN3s18BTnVu5eI/lMd1hp87YOZf2M6M4MgFuZJlsR02D/7LTbYk4QwOOkTnvWttFZSoVwJ0nrgqbd5SCIbXra4pcQCjGbcBjK6L3tzuoIs/FS+TaA124ja7XSDun5iZTJK9PY4eTQ6nhnPRrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=f4X3Syj7; arc=none smtp.client-ip=209.85.160.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="f4X3Syj7" Received: by mail-qt1-f226.google.com with SMTP id d75a77b69052e-506a747448dso108567211cf.0 for ; Mon, 09 Mar 2026 17:17:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773101832; x=1773706632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sDBpeRPGQkSyveVh0r0L9u3UrQSmg15QNxwWzbeb67Y=; b=NaamJrl6kuaRnOSPpf558SqJEfTvEUlQkHFo8LVOR3g2htRpseASYAaPeJYY3g3QHA QYpQGwad5oHX9vHlQ+Medxz+DqnedTQRCqSpfy0uF72zbkD13Dp7XRVODhfvK4BNcKMK lgWZbO6NIYjH1pf6FwTPpXcqAZdjrUiwGbyzfr2XGFlQ3iVkvjwMr4yKxoSl7IkxMxCv AKzsB8EAxyyFJ1A40gKH6tRtp4K3mrdoUtE/eqC90XHPkxcKii257uYWm3lt7TdP4mB3 2Jo/Da2XKH23SBpl8vX4OHaUDgNqc/sc/IarJq60z2NmW+I9qmqyc0+IIzJSYWFxaZjk O1EQ== X-Forwarded-Encrypted: i=1; AJvYcCUVICi35x3X9hbwxR/SP9fyPXKa5yQMGxnZVhTMgmZRBQueRNkHVKkknjIMJzQ9znLq0bHfHoAEXNtsX4I=@vger.kernel.org X-Gm-Message-State: AOJu0YwzJ5F6ItIS5vQlL7V92Ln9+OPtVgRwnfg3TaOe1Qk855kltgB5 eBVQh9XyD7SM6YZWE8qb91rv/bGXGsf3WgCxYFMThza55GKgmttzf/6SuAZX3IeKstCxs9IkHVM /u0XtMatjeo/mgUMwSvmjqZpY+8ZKm41PpclWusoz0YlInvZKX/Hl/nNKCEEuJeddriJg92HPtd NVqnQYRscHFJcDPZOzzF8xecW94fM1oFibkxHv7kx93rxYVN4HYjN/Qo/npdCLCwFNstH80lTXC B++fcZbiXhI0IFJVxfcaHU= X-Gm-Gg: ATEYQzxV3L0qdrkxseXnfajBKx+XqWdkl4l5bbsKlPlytc51i51RS8G9EZ33nS6fgAq NZYQwVV6KlUdlrsjRIyaj2hUoacS4JgDW/YVU7hFj1KEixT2lCtCEkkRLUkjfi5yhsU1AyVT47A SJsRuD7FITGAXN9rbI3XuwMcOlpigDgLuiSAsV62MwC1BBzSoh13XxXiMw6OiZW1KNeSTUsDS0v 36cPxVrqx+gouZYckNQiiJKx+uD/SEsZxROhUJ9oapbvlO4AcTvsKpWYJrTcu+fRZqVnuIyVGl9 jYKj0Ak6hpXrXFyTUqlB7gTqoLh7WsciryS58clgHuq/EXnVhfUNTyHD5okshQpi6rXWojN0uNj 7n40m2/1K+gF5txnpcb9g7S3ddd14JNokJpvSIGWYqlw3GGxYyXhsnZeAnOJRk65gOgsVCb2T0i NxV2hDrWqXn+nDPowspcHnTbTT1OFxqap6bfLfA100A11FgGeuwo7xJ+aGIA3J X-Received: by 2002:a05:622a:1814:b0:509:f18:84eb with SMTP id d75a77b69052e-5090f1896b0mr102868301cf.43.1773101832110; Mon, 09 Mar 2026 17:17:12 -0700 (PDT) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-29.dlp.protect.broadcom.com. [144.49.247.29]) by smtp-relay.gmail.com with ESMTPS id d75a77b69052e-5091702ef5dsm5200041cf.4.2026.03.09.17.17.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2026 17:17:12 -0700 (PDT) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-2be2f742c46so61826205eec.0 for ; Mon, 09 Mar 2026 17:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1773101831; x=1773706631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sDBpeRPGQkSyveVh0r0L9u3UrQSmg15QNxwWzbeb67Y=; b=f4X3Syj70+mcQhcPejd5U3SiSEt8rAUQHH17KUHO3peKSg/p37rlk0UTndji55vc4X QQf7GVwJDfinGEkZGd3lfEl68ZqrqPq9zFPahWgjB6jGW227Qyg7PxtEKmCTM9SSDj9t zW2okiap1kKYZt0J6OXAUFxes45BzYStpCYrc= X-Forwarded-Encrypted: i=1; AJvYcCXu6ds5ajTgrZ3ErwipeCOgi2yaGAzTZXL+E4AxN+G6FE8WyqTt7h8YY9dXpX866/J4t+CWGd2Jbk0BLh4=@vger.kernel.org X-Received: by 2002:a05:7300:8623:b0:2be:2409:6c6e with SMTP id 5a478bee46e88-2be4de767damr6029552eec.5.1773101830116; Mon, 09 Mar 2026 17:17:10 -0700 (PDT) X-Received: by 2002:a05:7300:8623:b0:2be:2409:6c6e with SMTP id 5a478bee46e88-2be4de767damr6029533eec.5.1773101829206; Mon, 09 Mar 2026 17:17:09 -0700 (PDT) Received: from amakhalov-build-vm.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2be4f948324sm12678991eec.17.2026.03.09.17.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 17:17:08 -0700 (PDT) From: Alexey Makhalov To: x86@kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: ajay.kaher@broadcom.com, brennan.lamoreaux@broadcom.com, bo.gan@broadcom.com, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, kas@kernel.org, rick.p.edgecombe@intel.com, linux-coco@lists.linux.dev, Alexey Makhalov , Linus Torvalds Subject: [PATCH v2 1/4] x86/vmware: Introduce common vmware_hypercall() Date: Mon, 9 Mar 2026 23:52:47 +0000 Message-ID: <20260309235250.2611115-2-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260309235250.2611115-1-alexey.makhalov@broadcom.com> References: <20260307004238.1181299-1-alexey.makhalov@broadcom.com> <20260309235250.2611115-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e Content-Type: text/plain; charset="utf-8" Introduce vmware_hypercall(), a unified low-bandwidth VMware hypercall API, and convert the static inlines vmware_hypercallX() family into thin wrappers on top of it. vmware_hypercall() is implemented as a static call with four backend implementations: backdoor, vmcall, vmmcall, and tdxcall. All share the same logical API but differ in their underlying register mappings. By updating the static call target early during boot, before the first hypercall is issued, the !alternatives_patched case no longer needs to be handled. This allows removal of vmware_hypercall_slow(). The new API implements the widest practical hypercall use case: up to six input and six output arguments. While this may be slightly less efficient due to clobbering all six registers and moving unused arguments - it avoids subtle ABI issues, including cases where other hypervisors implementing VMware hypercalls corrupt registers. See QEMU issue #3293 ("vmmouse driver corrupts upper 32 bits of registers on x86-64") for an example of such behavior. Additionally, enhance the VMware hypercall ABI documentation in . Link: https://gitlab.com/qemu-project/qemu/-/issues/3293 Suggested-by: Linus Torvalds Signed-off-by: Alexey Makhalov --- arch/x86/include/asm/vmware.h | 274 ++++++++++++++------------------- arch/x86/kernel/cpu/vmware.c | 276 +++++++++++++++++++--------------- 2 files changed, 267 insertions(+), 283 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 4220dae14a2d..6a084e088b30 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -3,48 +3,84 @@ #define _ASM_X86_VMWARE_H =20 #include -#include #include +#include =20 /* * VMware hypercall ABI. * - * - Low bandwidth (LB) hypercalls (I/O port based, vmcall and vmmcall) - * have up to 6 input and 6 output arguments passed and returned using - * registers: %eax (arg0), %ebx (arg1), %ecx (arg2), %edx (arg3), - * %esi (arg4), %edi (arg5). - * The following input arguments must be initialized by the caller: - * arg0 - VMWARE_HYPERVISOR_MAGIC - * arg2 - Hypercall command - * arg3 bits [15:0] - Port number, LB and direction flags + * - Low bandwidth (LB) hypercalls: I/O port based (aka backdoor), vmcall = and + * vmmcall have up to 6 input and 6 output on registers arguments, with the + * register mapping: + * +------+----------------------------------------+-----------------+ + * | Reg | Input argument | Output argument | + * +=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ + * | %eax | VMWARE_HYPERVISOR_MAGIC | out0 | + * +------+----------------------------------------+-----------------+ + * | %ebx | (in1) | out1 | + * +------+----------------------------------------+-----------------+ + * | %ecx | (cmd) - Hypercall command | out2 | + * +------+----------------------------------------+-----------------+ + * | %edx | Bits [15:0] - Port number for backdoor | out3 | + * | | Zero for vmcall/vmmcall | | + * | | Bits [31:16] - (in3) | | + * +------+----------------------------------------+-----------------+ + * | %esi | (in4) | out4 | + * +------+----------------------------------------+-----------------+ + * | %edi | (in5) | out5 | + * +------+----------------------------------------+-----------------+ * - * - Low bandwidth TDX hypercalls (x86_64 only) are similar to LB - * hypercalls. They also have up to 6 input and 6 output on registers - * arguments, with different argument to register mapping: - * %r12 (arg0), %rbx (arg1), %r13 (arg2), %rdx (arg3), - * %rsi (arg4), %rdi (arg5). + * - Low bandwidth TDX hypercalls (x86_64 only) are similar to LB hypercal= ls. + * They also have up to 6 input and 6 output on registers arguments, with + * different argument to register mapping: + * +------+----------------------------------------+-----------------+ + * | Reg | Input argument | Output argument | + * +=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ + * | %r12 | VMWARE_HYPERVISOR_MAGIC | out0 | + * +------+----------------------------------------+-----------------+ + * | %ebx | (in1) | out1 | + * +------+----------------------------------------+-----------------+ + * | %r13 | (cmd) - Hypercall command | out2 | + * +------+----------------------------------------+-----------------+ + * | %edx | Bits [15:0] - Must be zero | out3 | + * | | Bits [31:16] - (in3) | | + * +------+----------------------------------------+-----------------+ + * | %esi | (in4) | out4 | + * +------+----------------------------------------+-----------------+ + * | %edi | (in5) | out5 | + * +------+----------------------------------------+-----------------+ * - * - High bandwidth (HB) hypercalls are I/O port based only. They have - * up to 7 input and 7 output arguments passed and returned using - * registers: %eax (arg0), %ebx (arg1), %ecx (arg2), %edx (arg3), - * %esi (arg4), %edi (arg5), %ebp (arg6). - * The following input arguments must be initialized by the caller: - * arg0 - VMWARE_HYPERVISOR_MAGIC - * arg1 - Hypercall command - * arg3 bits [15:0] - Port number, HB and direction flags + * - High bandwidth (HB) hypercalls are I/O port based only. They have up = to 7 + * input and 7 output on reegister arguments with the following mapping: + * +------+----------------------------------------+-----------------+ + * | Reg | Input argument | Output argument | + * +=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ + * | %eax | VMWARE_HYPERVISOR_MAGIC | out0 | + * +------+----------------------------------------+-----------------+ + * | %ebx | (cmd) - Hypercall command | out1 | + * +------+----------------------------------------+-----------------+ + * | %ebx | (in2) | out2 | + * +------+----------------------------------------+-----------------+ + * | %edx | Bits [15:0] - Port number and HB flag | out3 | + * | | Bits [31:16] - (in3) | | + * +------+----------------------------------------+-----------------+ + * | %esi | (in4) | out4 | + * +------+----------------------------------------+-----------------+ + * | %edi | (in5) | out5 | + * +------+----------------------------------------+-----------------+ + * | %ebp | (in6) | out6 | + * +------+----------------------------------------+-----------------+ * - * For compatibility purposes, x86_64 systems use only lower 32 bits - * for input and output arguments. + * For compatibility purposes, x86_64 systems use only lower 32 bits for i= nput + * and output arguments. * - * The hypercall definitions differ in the low word of the %edx (arg3) - * in the following way: the old I/O port based interface uses the port - * number to distinguish between high- and low bandwidth versions, and - * uses IN/OUT instructions to define transfer direction. + * The hypercall definitions differ in the low word of the %edx (arg3) in = the + * following way: the old I/O port based interface uses the port number, t= he + * bandwidth mode flag, and uses IN/OUT instructions to define transfer + * direction. * - * The new vmcall interface instead uses a set of flags to select - * bandwidth mode and transfer direction. The flags should be loaded - * into arg3 by any user and are automatically replaced by the port - * number if the I/O port method is used. + * The new vmcall interface instead uses a set of flags to select bandwidth + * mode and transfer direction. */ =20 #define VMWARE_HYPERVISOR_HB BIT(0) @@ -70,103 +106,64 @@ #define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) #define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) =20 -extern unsigned long vmware_hypercall_slow(unsigned long cmd, - unsigned long in1, unsigned long in3, - unsigned long in4, unsigned long in5, - u32 *out1, u32 *out2, u32 *out3, - u32 *out4, u32 *out5); - #define VMWARE_TDX_VENDOR_LEAF 0x1af7e4909ULL #define VMWARE_TDX_HCALL_FUNC 1 =20 -extern unsigned long vmware_tdx_hypercall(unsigned long cmd, - unsigned long in1, unsigned long in3, - unsigned long in4, unsigned long in5, - u32 *out1, u32 *out2, u32 *out3, - u32 *out4, u32 *out5); +unsigned long dummy_vmware_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5); =20 /* - * The low bandwidth call. The low word of %edx is presumed to have OUT bit - * set. The high word of %edx may contain input data from the caller. + * Low bandwidth (LB) VMware hypercall. + * + * It is backed by the backdoor, vmcall, vmmcall or tdx call implementatio= n. + * + * Use inX/outX arguments naming as the register mappings vary between + * different implementations. See VMware hypercall ABI above. + * These 10 arguments could be nicely wrapped in in/out structures, but it + * will introduce unnecessary structs copy in vmware_tdx_hypercall(). + * + * NOTE: + * Do not merge vmware_{backdoor,vmcall,vmmcall}_hypercall implementations + * using alternative instructions. Such patching mechanism can not be used + * in vmware_hypercall path, as the first hypercall will be called much + * before the apply_alternatives(). See vmware_platform_setup(). */ -#define VMWARE_HYPERCALL \ - ALTERNATIVE_2("movw %[port], %%dx\n\t" \ - "inl (%%dx), %%eax", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) +DECLARE_STATIC_CALL(vmware_hypercall, dummy_vmware_hypercall); =20 +/* + * Set of commonly used vmware_hypercallX functions - wrappers on top of t= he + * vmware_hypercall. + */ static inline unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) { - unsigned long out0; - - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, - NULL, NULL, NULL, NULL, NULL); - - if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) - return vmware_hypercall_slow(cmd, in1, 0, 0, 0, - NULL, NULL, NULL, NULL, NULL); + u32 out1, out2, out3, out4, out5; =20 - asm_inline volatile (VMWARE_HYPERCALL - : "=3Da" (out0) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (0) - : "cc", "memory"); - return out0; + return static_call_mod(vmware_hypercall)(cmd, in1, 0, 0, 0, + &out1, &out2, &out3, &out4, &out5); } =20 static inline unsigned long vmware_hypercall3(unsigned long cmd, unsigned long in1, u32 *out1, u32 *out2) { - unsigned long out0; - - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, - out1, out2, NULL, NULL, NULL); - - if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) - return vmware_hypercall_slow(cmd, in1, 0, 0, 0, - out1, out2, NULL, NULL, NULL); + u32 out3, out4, out5; =20 - asm_inline volatile (VMWARE_HYPERCALL - : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (0) - : "di", "si", "cc", "memory"); - return out0; + return static_call_mod(vmware_hypercall)(cmd, in1, 0, 0, 0, + out1, out2, &out3, &out4, &out5); } =20 static inline unsigned long vmware_hypercall4(unsigned long cmd, unsigned long in1, u32 *out1, u32 *out2, u32 *out3) { - unsigned long out0; - - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, - out1, out2, out3, NULL, NULL); - - if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) - return vmware_hypercall_slow(cmd, in1, 0, 0, 0, - out1, out2, out3, NULL, NULL); + u32 out4, out5; =20 - asm_inline volatile (VMWARE_HYPERCALL - : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), "=3Dd" (*out3) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (0) - : "di", "si", "cc", "memory"); - return out0; + return static_call_mod(vmware_hypercall)(cmd, in1, 0, 0, 0, + out1, out2, out3, &out4, &out5); } =20 static inline @@ -174,27 +171,10 @@ unsigned long vmware_hypercall5(unsigned long cmd, un= signed long in1, unsigned long in3, unsigned long in4, unsigned long in5, u32 *out2) { - unsigned long out0; - - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, - NULL, out2, NULL, NULL, NULL); + u32 out1, out3, out4, out5; =20 - if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) - return vmware_hypercall_slow(cmd, in1, in3, in4, in5, - NULL, out2, NULL, NULL, NULL); - - asm_inline volatile (VMWARE_HYPERCALL - : "=3Da" (out0), "=3Dc" (*out2) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (in3), - "S" (in4), - "D" (in5) - : "cc", "memory"); - return out0; + return static_call_mod(vmware_hypercall)(cmd, in1, in3, in4, in5, + &out1, out2, &out3, &out4, &out5); } =20 static inline @@ -202,26 +182,10 @@ unsigned long vmware_hypercall6(unsigned long cmd, un= signed long in1, unsigned long in3, u32 *out2, u32 *out3, u32 *out4, u32 *out5) { - unsigned long out0; - - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return vmware_tdx_hypercall(cmd, in1, in3, 0, 0, - NULL, out2, out3, out4, out5); + u32 out1; =20 - if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) - return vmware_hypercall_slow(cmd, in1, in3, 0, 0, - NULL, out2, out3, out4, out5); - - asm_inline volatile (VMWARE_HYPERCALL - : "=3Da" (out0), "=3Dc" (*out2), "=3Dd" (*out3), "=3DS" (*out4), - "=3DD" (*out5) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (in3) - : "cc", "memory"); - return out0; + return static_call_mod(vmware_hypercall)(cmd, in1, in3, 0, 0, + &out1, out2, out3, out4, out5); } =20 static inline @@ -230,27 +194,10 @@ unsigned long vmware_hypercall7(unsigned long cmd, un= signed long in1, unsigned long in5, u32 *out1, u32 *out2, u32 *out3) { - unsigned long out0; - - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) - return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, - out1, out2, out3, NULL, NULL); + u32 out4, out5; =20 - if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) - return vmware_hypercall_slow(cmd, in1, in3, in4, in5, - out1, out2, out3, NULL, NULL); - - asm_inline volatile (VMWARE_HYPERCALL - : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), "=3Dd" (*out3) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (in3), - "S" (in4), - "D" (in5) - : "cc", "memory"); - return out0; + return static_call_mod(vmware_hypercall)(cmd, in1, in3, in4, in5, + out1, out2, out3, &out4, &out5); } =20 #ifdef CONFIG_X86_64 @@ -322,6 +269,5 @@ unsigned long vmware_hypercall_hb_in(unsigned long cmd,= unsigned long in2, return out0; } #undef VMW_BP_CONSTRAINT -#undef VMWARE_HYPERCALL =20 #endif diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index a3e6936839b1..93acd3414e37 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -64,70 +64,140 @@ struct vmware_steal_time { }; =20 static unsigned long vmware_tsc_khz __ro_after_init; -static u8 vmware_hypercall_mode __ro_after_init; - -unsigned long vmware_hypercall_slow(unsigned long cmd, - unsigned long in1, unsigned long in3, - unsigned long in4, unsigned long in5, - u32 *out1, u32 *out2, u32 *out3, - u32 *out4, u32 *out5) -{ - unsigned long out0, rbx, rcx, rdx, rsi, rdi; - - switch (vmware_hypercall_mode) { - case CPUID_VMWARE_FEATURES_ECX_VMCALL: - asm_inline volatile ("vmcall" - : "=3Da" (out0), "=3Db" (rbx), "=3Dc" (rcx), - "=3Dd" (rdx), "=3DS" (rsi), "=3DD" (rdi) - : "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (in3), - "S" (in4), - "D" (in5) - : "cc", "memory"); - break; - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: - asm_inline volatile ("vmmcall" - : "=3Da" (out0), "=3Db" (rbx), "=3Dc" (rcx), - "=3Dd" (rdx), "=3DS" (rsi), "=3DD" (rdi) - : "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (in3), - "S" (in4), - "D" (in5) - : "cc", "memory"); - break; - default: - asm_inline volatile ("movw %[port], %%dx; inl (%%dx), %%eax" - : "=3Da" (out0), "=3Db" (rbx), "=3Dc" (rcx), - "=3Dd" (rdx), "=3DS" (rsi), "=3DD" (rdi) - : [port] "i" (VMWARE_HYPERVISOR_PORT), - "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (in1), - "c" (cmd), - "d" (in3), - "S" (in4), - "D" (in5) - : "cc", "memory"); - break; - } +static u8 vmware_hypercall_mode __initdata; + +static unsigned long vmware_backdoor_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5) +{ + unsigned long out0; + + /* The low word of in3(%edx) must have the backdoor port number */ + in3 =3D (in3 & ~0xffff) | VMWARE_HYPERVISOR_PORT; + + asm_inline volatile ("inl (%%dx), %%eax" + : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), + "=3Dd" (*out3), "=3DS" (*out4), "=3DD" (*out5) + : "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (in3), + "S" (in4), + "D" (in5) + : "cc", "memory"); =20 - if (out1) - *out1 =3D rbx; - if (out2) - *out2 =3D rcx; - if (out3) - *out3 =3D rdx; - if (out4) - *out4 =3D rsi; - if (out5) - *out5 =3D rdi; + return out0; +} + +static unsigned long vmware_vmcall_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5) +{ + unsigned long out0; + + /* The low word of in3(%edx) must be zero: LB, IN */ + in3 &=3D ~0xffff; + + asm_inline volatile ("vmcall" + : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), + "=3Dd" (*out3), "=3DS" (*out4), "=3DD" (*out5) + : "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (in3), + "S" (in4), + "D" (in5) + : "cc", "memory"); =20 return out0; } =20 +static unsigned long vmware_vmmcall_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5) +{ + unsigned long out0; + + /* The low word of in3(%edx) must be zero: LB, IN */ + in3 &=3D ~0xffff; + + asm_inline volatile ("vmmcall" + : "=3Da" (out0), "=3Db" (*out1), "=3Dc" (*out2), + "=3Dd" (*out3), "=3DS" (*out4), "=3DD" (*out5) + : "a" (VMWARE_HYPERVISOR_MAGIC), + "b" (in1), + "c" (cmd), + "d" (in3), + "S" (in4), + "D" (in5) + : "cc", "memory"); + + return out0; +} + +/* + * TDCALL[TDG.VP.VMCALL] uses %rax (arg0) and %rcx (arg2). Therefore, + * we remap those registers to %r12 and %r13, respectively. + */ +static unsigned long vmware_tdx_hypercall(unsigned long cmd, + unsigned long in1, unsigned long in3, + unsigned long in4, unsigned long in5, + u32 *out1, u32 *out2, u32 *out3, + u32 *out4, u32 *out5) +{ +#ifdef CONFIG_INTEL_TDX_GUEST + struct tdx_module_args args =3D {}; + + if (!hypervisor_is_type(X86_HYPER_VMWARE)) { + pr_warn_once("Incorrect usage\n"); + return ULONG_MAX; + } + + if (cmd & ~VMWARE_CMD_MASK) { + pr_warn_once("Out of range command %lx\n", cmd); + return ULONG_MAX; + } + + args.rbx =3D in1; + /* The low word of in3(%rdx) must be zero: LB, IN */ + args.rdx =3D in3 & ~0xffff; + args.rsi =3D in4; + args.rdi =3D in5; + args.r10 =3D VMWARE_TDX_VENDOR_LEAF; + args.r11 =3D VMWARE_TDX_HCALL_FUNC; + args.r12 =3D VMWARE_HYPERVISOR_MAGIC; + args.r13 =3D cmd; + /* CPL */ + args.r15 =3D 0; + + __tdx_hypercall(&args); + + *out1 =3D args.rbx; + *out2 =3D args.r13; + *out3 =3D args.rdx; + *out4 =3D args.rsi; + *out5 =3D args.rdi; + + return args.r12; +#else + return ULONG_MAX; +#endif +} + + +DEFINE_STATIC_CALL(vmware_hypercall, vmware_backdoor_hypercall); +EXPORT_STATIC_CALL_GPL(vmware_hypercall); + +/* + * Perform backdoor probbing of the hypervisor when + * X86_FEATURE_HYPERVISOR bit is not set. + */ static inline int __vmware_platform(void) { u32 eax, ebx, ecx; @@ -397,11 +467,35 @@ static void __init vmware_set_capabilities(void) setup_force_cpu_cap(X86_FEATURE_VMW_VMMCALL); } =20 +static void __init vmware_select_hypercall(void) +{ + char *mode; + + if (IS_ENABLED(CONFIG_INTEL_TDX_GUEST) && + cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { + static_call_update(vmware_hypercall, vmware_tdx_hypercall); + mode =3D "tdcall"; + } else if (vmware_hypercall_mode =3D=3D CPUID_VMWARE_FEATURES_ECX_VMCALL)= { + static_call_update(vmware_hypercall, vmware_vmcall_hypercall); + mode =3D "vmcall"; + } else if (vmware_hypercall_mode =3D=3D CPUID_VMWARE_FEATURES_ECX_VMMCALL= ) { + static_call_update(vmware_hypercall, vmware_vmmcall_hypercall); + mode =3D "vmmcall"; + } else { + mode =3D "backdoor"; + } + + pr_info("hypercall mode: %s\n", mode); +} + static void __init vmware_platform_setup(void) { u32 eax, ebx, ecx; u64 lpj, tsc_khz; =20 + /* Update vmware_hypercall() before the first use. */ + vmware_select_hypercall(); + eax =3D vmware_hypercall3(VMWARE_CMD_GETHZ, UINT_MAX, &ebx, &ecx); =20 if (ebx !=3D UINT_MAX) { @@ -443,7 +537,7 @@ static void __init vmware_platform_setup(void) vmware_set_capabilities(); } =20 -static u8 __init vmware_select_hypercall(void) +static u8 __init get_hypercall_mode(void) { int eax, ebx, ecx, edx; =20 @@ -456,8 +550,8 @@ static u8 __init vmware_select_hypercall(void) * While checking the dmi string information, just checking the product * serial key should be enough, as this will always have a VMware * specific string when running under VMware hypervisor. - * If !boot_cpu_has(X86_FEATURE_HYPERVISOR), vmware_hypercall_mode - * intentionally defaults to 0. + * If !boot_cpu_has(X86_FEATURE_HYPERVISOR), __vmware_platform() + * intentionally defaults to backdoor hypercall. */ static u32 __init vmware_platform(void) { @@ -470,11 +564,7 @@ static u32 __init vmware_platform(void) if (!memcmp(hyper_vendor_id, "VMwareVMware", 12)) { if (eax >=3D CPUID_VMWARE_FEATURES_LEAF) vmware_hypercall_mode =3D - vmware_select_hypercall(); - - pr_info("hypercall mode: 0x%02x\n", - (unsigned int) vmware_hypercall_mode); - + get_hypercall_mode(); return CPUID_VMWARE_INFO_LEAF; } } else if (dmi_available && dmi_name_in_serial("VMware") && @@ -494,58 +584,6 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & GETVCPU_INFO_LEGACY_X2APIC); } =20 -#ifdef CONFIG_INTEL_TDX_GUEST -/* - * TDCALL[TDG.VP.VMCALL] uses %rax (arg0) and %rcx (arg2). Therefore, - * we remap those registers to %r12 and %r13, respectively. - */ -unsigned long vmware_tdx_hypercall(unsigned long cmd, - unsigned long in1, unsigned long in3, - unsigned long in4, unsigned long in5, - u32 *out1, u32 *out2, u32 *out3, - u32 *out4, u32 *out5) -{ - struct tdx_module_args args =3D {}; - - if (!hypervisor_is_type(X86_HYPER_VMWARE)) { - pr_warn_once("Incorrect usage\n"); - return ULONG_MAX; - } - - if (cmd & ~VMWARE_CMD_MASK) { - pr_warn_once("Out of range command %lx\n", cmd); - return ULONG_MAX; - } - - args.rbx =3D in1; - args.rdx =3D in3; - args.rsi =3D in4; - args.rdi =3D in5; - args.r10 =3D VMWARE_TDX_VENDOR_LEAF; - args.r11 =3D VMWARE_TDX_HCALL_FUNC; - args.r12 =3D VMWARE_HYPERVISOR_MAGIC; - args.r13 =3D cmd; - /* CPL */ - args.r15 =3D 0; - - __tdx_hypercall(&args); - - if (out1) - *out1 =3D args.rbx; - if (out2) - *out2 =3D args.r13; - if (out3) - *out3 =3D args.rdx; - if (out4) - *out4 =3D args.rsi; - if (out5) - *out5 =3D args.rdi; - - return args.r12; -} -EXPORT_SYMBOL_GPL(vmware_tdx_hypercall); -#endif - #ifdef CONFIG_AMD_MEM_ENCRYPT static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) --=20 2.43.7 From nobody Thu Apr 9 09:03:33 2026 Received: from mail-qv1-f100.google.com (mail-qv1-f100.google.com [209.85.219.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 553851F03D9 for ; Tue, 10 Mar 2026 00:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101834; cv=none; b=Dm1kYb4zIzSshcvlwLrUnFQfoEKNtooJjZvl6VIbNGJDVgi7p+vbfvDPxFTI/irov0dd6KJW77ySftatvBtO24urVxX7dI/opcPMmgfNH1UOZf9lIzhfsfTd6Zh8GwQadBKnJ+EiVoaI+nAYdvaR7fkOP7v5xt+Gwsn0IHGEPd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101834; c=relaxed/simple; bh=IuU7841Kb58NNELaJ1BogWUtCo2ilSrj/nV0cjFquRE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JyXakAI971h0Gd/Hf2FxsxabDZyIZDh4xd4K4JlsqhYf2aDXRUEM2klCF6vGhT/2gPlY/UpjwM4Io2tRc2nssy7cTii2Xtekag01PpDlAb4XiZmRDRs0qRz/5j8VZnJtzSVlTQIx7kgj45Kfx030RyA2bH3W9BaRwvUxiiadZFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=IHUMB7il; arc=none smtp.client-ip=209.85.219.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="IHUMB7il" Received: by mail-qv1-f100.google.com with SMTP id 6a1803df08f44-89a0ece9f14so102084376d6.3 for ; Mon, 09 Mar 2026 17:17:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773101832; x=1773706632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XXx6sN1Xw89vovWYZx/fM1gj3YL15VXYd9/H4L59JUg=; b=VRuV3x0pRhdLx9Rikh+d1xMoRNMd5pOUOCGec/21Gl8XfLcjeUQiKgwdgi53wzZVFl X9NHjD3ycKj5p28q+Ajnet5T4R7nqsdax/mFY0vupdNUuUSjbNM/Z68pZHShIsBiKGl0 CAm9q8WE2FjEKMVuszUu+OxQxt5NDXJc1X/NGljBbx1GtwXYEpmD9rlOj1DTBTCKu5U2 X+vFa0hjRHyRNpDv+Zy0uxdHzrWFjOWfd9HHYyvILMVa0w/71Ie79xIlGFHlssxcKetI lNwnPNfC8uEO29iStPO1uP5+EAaPieds2fimmkWSkUH5e/jxqpGN6oEYDDQAGaaRPo0Z XY3w== X-Forwarded-Encrypted: i=1; AJvYcCV54nFr4WhcdxYRBnwcWhOdPL9+5mALEH3bsVwNpA8JwOHvQ1m6RS6Y4JqUN05uCSAy2i9yrnfyT+CmKgY=@vger.kernel.org X-Gm-Message-State: AOJu0YwI9+GXQOh9bFC6Y/U6reHlbDfAddakX9pYg1CFuqo7ucd0ozME 8z60xUjslQKqWMLZNzJ+BfA/5mjhpYpzmwhgVMqF29LPyc9Zm3FpzgP1bQSIRIwaoAl5hlQ03O+ 4xPU/K5X33IuHuvLzJv8H/tMu6sAu1ak/rfJjojAfAMGrVSXqgp29nyFXO6FsYZZR+A6epIKNMc Eg7jszvmNUgRwlRUCshLjsj4PdUCcqM1E0bc2tEP+JXHfezRSHvs4kCy+t3N7K51jUO9TBpy7fK oqOkITRX0jNTLyNShjRJ00= X-Gm-Gg: ATEYQzwExcJmWVlPsU3mC3p0uFryg7p3ArWON7BOGxDzN80RIVGZ9zBFGxfTKK8xO6h wH3SD+fd2UQPHXPCb9wQlTIfptkMWCACtIcW8y+KzXgKEjx+Ov6NZBqlqpaLkRtiCPtcgqTVO16 vU10P9PjQFrXadk4VxeD5bNG5twC8uTsgTpfAz4Aw4qFZKJY+QK+32wEnpNmRwHfSobA8pbDiWT zAmr4a1oAh77j0LyTWAX321XwbclQzUkI6Y/8rPfrT0V6OpxXNE2EqeAGoUyQko8mQ4cL2acWPp 5mUczjXfAtsZjtfCJwI0n9oe/t3BBqCpQ1MT6V4Q1mQ6uHNzDRGLTVG2O4accTNZiSHfJOPoJK+ +MMAU0WYhHEpvo3OeUa6RGZubUEDhjq4ws8iwHJ+xWO121nj4P0bq22riKLlRhialnOt7lfH95C Ssrk5YU8+AxX8oxxkMRtuDHF7CLtEMfpDnF2XSMi89dLogFxrTufRvv4OcojV3g6c= X-Received: by 2002:a05:6214:234f:b0:89a:126a:5b7d with SMTP id 6a1803df08f44-89a30a1e79fmr208644176d6.2.1773101832286; Mon, 09 Mar 2026 17:17:12 -0700 (PDT) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-102.dlp.protect.broadcom.com. [144.49.247.102]) by smtp-relay.gmail.com with ESMTPS id 6a1803df08f44-89a57b9b3casm1367986d6.15.2026.03.09.17.17.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2026 17:17:12 -0700 (PDT) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso9901131eec.0 for ; Mon, 09 Mar 2026 17:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1773101831; x=1773706631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XXx6sN1Xw89vovWYZx/fM1gj3YL15VXYd9/H4L59JUg=; b=IHUMB7ilbXKCW645rvxyVIpHXalETpdDKFstRy7X0fgLXZQideg5A/kZQkkEIjPaLL vwgHG8l1MYDzrn5+q1nva+ThwL3OLkc4JScRAEvDFH5ZjxNZYsdJhVlqaGlFWMi9fPwi MhX3Aa8yylhEWkvAEgh0+a7rjA8/Z3yLCbWQE= X-Forwarded-Encrypted: i=1; AJvYcCU/DG5JQWHJaj6yjLrGRroe5JRewEjwlCVT/ObfuDzMRqlJcJnhwYbewCEomdSAan7qjDkXrhw3mvY5xRU=@vger.kernel.org X-Received: by 2002:a05:7300:a887:b0:2a4:3593:466c with SMTP id 5a478bee46e88-2be4de8e1cdmr5614032eec.8.1773101831044; Mon, 09 Mar 2026 17:17:11 -0700 (PDT) X-Received: by 2002:a05:7300:a887:b0:2a4:3593:466c with SMTP id 5a478bee46e88-2be4de8e1cdmr5614014eec.8.1773101830462; Mon, 09 Mar 2026 17:17:10 -0700 (PDT) Received: from amakhalov-build-vm.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2be4f948324sm12678991eec.17.2026.03.09.17.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 17:17:10 -0700 (PDT) From: Alexey Makhalov To: x86@kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: ajay.kaher@broadcom.com, brennan.lamoreaux@broadcom.com, bo.gan@broadcom.com, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, kas@kernel.org, rick.p.edgecombe@intel.com, linux-coco@lists.linux.dev, Alexey Makhalov Subject: [PATCH v2 2/4] x86/vmware: Log kmsg dump on panic Date: Mon, 9 Mar 2026 23:52:48 +0000 Message-ID: <20260309235250.2611115-3-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260309235250.2611115-1-alexey.makhalov@broadcom.com> References: <20260307004238.1181299-1-alexey.makhalov@broadcom.com> <20260309235250.2611115-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e Content-Type: text/plain; charset="utf-8" Improve debugability of VMware Linux guests by dumping kernel messages during a panic to VM log file (vmware.log). Co-developed-by: Bo Gan Signed-off-by: Bo Gan Signed-off-by: Alexey Makhalov --- arch/x86/include/asm/vmware.h | 1 + arch/x86/kernel/cpu/vmware.c | 132 ++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 6a084e088b30..c23164503e54 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -93,6 +93,7 @@ #define VMWARE_HYPERVISOR_MAGIC 0x564d5868U =20 #define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_MESSAGE 30 #define VMWARE_CMD_GETHZ 45 #define VMWARE_CMD_GETVCPU_INFO 68 #define VMWARE_CMD_STEALCLOCK 91 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 93acd3414e37..9955f2ea0c84 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -211,6 +212,13 @@ static unsigned long vmware_get_tsc_khz(void) return vmware_tsc_khz; } =20 +static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper, + struct kmsg_dump_detail *detail); + +static struct kmsg_dumper kmsg_dumper =3D { + .dump =3D kmsg_dumper_vmware_log +}; + #ifdef CONFIG_PARAVIRT static struct cyc2ns_data vmware_cyc2ns __ro_after_init; static bool vmw_sched_clock __initdata =3D true; @@ -535,6 +543,8 @@ static void __init vmware_platform_setup(void) #endif =20 vmware_set_capabilities(); + + kmsg_dump_register(&kmsg_dumper); } =20 static u8 __init get_hypercall_mode(void) @@ -630,3 +640,125 @@ const __initconst struct hypervisor_x86 x86_hyper_vmw= are =3D { .runtime.sev_es_hcall_finish =3D vmware_sev_es_hcall_finish, #endif }; + +#define VMWARE_HB_CMD_MESSAGE 0 +#define MESSAGE_STATUS_SUCCESS (0x01 << 16) +#define MESSAGE_STATUS_CPT (0x10 << 16) +#define MESSAGE_STATUS_HB (0x80 << 16) + +#define RPCI_PROTOCOL_NUM 0x49435052 /* 'RPCI' */ +#define GUESTMSG_FLAG_COOKIE 0x80000000 + +#define MESSAGE_TYPE_OPEN (0 << 16) +#define MESSAGE_TYPE_SENDSIZE (1 << 16) +#define MESSAGE_TYPE_SEND (2 << 16) +#define MESSAGE_TYPE_CLOSE (6 << 16) + +struct vmw_msg { + u32 id; + u32 cookie_high; + u32 cookie_low; +}; + +static int +vmware_log_open(struct vmw_msg *msg) +{ + u32 info; + + vmware_hypercall6(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_OPEN, + RPCI_PROTOCOL_NUM | GUESTMSG_FLAG_COOKIE, + 0, &info, &msg->id, &msg->cookie_high, + &msg->cookie_low); + + if ((info & MESSAGE_STATUS_SUCCESS) =3D=3D 0) + return 1; + + msg->id &=3D 0xffff0000UL; + return 0; +} + +static int +vmware_log_close(struct vmw_msg *msg) +{ + u32 info; + + vmware_hypercall5(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_CLOSE, 0, msg->id, + msg->cookie_high, msg->cookie_low, &info); + + if ((info & MESSAGE_STATUS_SUCCESS) =3D=3D 0) + return 1; + return 0; +} + +static int +vmware_log_send(struct vmw_msg *msg, const char *string) +{ + u32 info; + u32 len =3D strlen(string); + +retry: + vmware_hypercall5(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_SENDSIZE, len, + msg->id, msg->cookie_high, msg->cookie_low, &info); + + if (!(info & MESSAGE_STATUS_SUCCESS)) + return 1; + + /* HB port can't access encrypted memory. */ + if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT) && (info & MESSAGE_STATUS_HB)) { + vmware_hypercall_hb_out( + VMWARE_HB_CMD_MESSAGE | MESSAGE_STATUS_SUCCESS, + len, msg->id, (uintptr_t) string, msg->cookie_low, + msg->cookie_high, &info); + } else { + do { + u32 word; + size_t s =3D min_t(u32, len, sizeof(word)); + + memcpy(&word, string, s); + len -=3D s; + string +=3D s; + + vmware_hypercall5(VMWARE_CMD_MESSAGE | MESSAGE_TYPE_SEND, + word, msg->id, msg->cookie_high, + msg->cookie_low, &info); + } while (len && (info & MESSAGE_STATUS_SUCCESS)); + } + + if ((info & MESSAGE_STATUS_SUCCESS) =3D=3D 0) { + if (info & MESSAGE_STATUS_CPT) + /* A checkpoint occurred. Retry. */ + goto retry; + return 1; + } + return 0; +} +STACK_FRAME_NON_STANDARD(vmware_log_send); + +/* + * kmsg_dumper_vmware_log - dumps kmsg to vmware.log file on the host + */ +static void kmsg_dumper_vmware_log(struct kmsg_dumper *dumper, + struct kmsg_dump_detail *detail) +{ + struct vmw_msg msg; + struct kmsg_dump_iter iter; + static char line[1024]; + size_t len =3D 0; + + /* Line prefix to send to VM log file. */ + line[0] =3D 'l'; + line[1] =3D 'o'; + line[2] =3D 'g'; + line[3] =3D ' '; + + kmsg_dump_rewind(&iter); + while (kmsg_dump_get_line(&iter, true, line + 4, sizeof(line) - 4, + &len)) { + line[len + 4] =3D '\0'; + if (vmware_log_open(&msg)) + return; + if (vmware_log_send(&msg, line)) + return; + vmware_log_close(&msg); + } +} --=20 2.43.7 From nobody Thu Apr 9 09:03:33 2026 Received: from mail-qt1-f226.google.com (mail-qt1-f226.google.com [209.85.160.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 784151DE2D8 for ; Tue, 10 Mar 2026 00:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101835; cv=none; b=M1D31KH+TiaHi8RiSdywaki/pAo+nG4B0qkc18qA730OQ1JiYR0pmXBpdesS3783qWdzlC8TwkM9F63pHsjcZR1D70a0f2ZlRdKc/mtXU7daxhs43TKwcUBQI7ywmzvwOt3D4YaoVuKHwerjM8+5DEBeozRVkF+QKisKg26nVCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101835; c=relaxed/simple; bh=Zj2gWskcTdeCbRgEtbKYU2726zg6QEH0voYcKcQfhMQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yr0ZTzwf6uVZg0g0MYkPaANJt3pmTBpw+G490bMPmkf+LG0JeOZXSla2sAXjTV47hbwcPFvPjOXUtPtu5KbURd7S8cPigX1KXepjcyUtYUKhPgkgWG6ewF9r0QVIpSFgzF54WzT5Jk0QIOdvanG9VeLhcRjii1MbNThbKZ2rvY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=JwWlAIuV; arc=none smtp.client-ip=209.85.160.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="JwWlAIuV" Received: by mail-qt1-f226.google.com with SMTP id d75a77b69052e-509046c5c7fso29587671cf.1 for ; Mon, 09 Mar 2026 17:17:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773101833; x=1773706633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OiGZAwROU5TJxpiCLUT0uYKKo5HkD6AnGMRObmR/GVo=; b=UR/MlKzSYSibikehEn8+P8JgJOVjhMMU5nkCZkOtH0xiyPYLoQYfqVVm9B/TrQ0rz5 mkA5+g5lNwlqZv3IdVak+N3H5emnbnUaQ3y0EohXsjZ3uyI6+Yh0cMozbaIGLJsvOLOW OCBOvbgkGyHIeteXUPIgk9zmKy43jduH/uABAf1CpYDhKoXjcm8i07xh1ikdsMYoLABE uupHQlggJfdJ3uhu9p6WaovG4PclsUGaDrlfr5VRp4I0W4lU78Dnxp8Up/SgoZPxczXx oZ0dg53q5BqKbFIbgPVmHieQwGG3fvjZ/wB8DXK91Vl8BLqLxNnRXW8+Z93emzSfENmf LOhg== X-Forwarded-Encrypted: i=1; AJvYcCVeQOtbALEpQ/7a0iietXHJbbGUC6QZqL2682vOOvNKnsPOsy4aAbTjnmBQrcJRBFID+i6BcVUrOv+j11k=@vger.kernel.org X-Gm-Message-State: AOJu0YwDKK8O3fdCeJ7hp03nAJv//H6jLT0zHd+z2pzouzh+Y7FRYf6v YFloxhbYwnhipC6ZalgHWgdKrdqW+1pOFKHX4H/rE/Z0rpSXptAgznoOQHo2ziXytNZfEQIW6vo c7jhS+v8dN5SnE/sSYmqNml1g6niVRyjKkvEl57wbLiDuFB3DvztZH5wNElpGna/QjHoT/o3KWQ VYU5/EvpWuXChrKHWL+L4dY8C98opEMTlcgtMd5N0zw0gbbOSy+4MN0OR2krakBZBW9DZiL8I86 n0nGB1+Psqh44KP6VF59FY= X-Gm-Gg: ATEYQzznt024IKcbqsU2No9kU497UsYMG6dk3KmtqZOR+52Ud+k776X+psWQzx9nGur FvgsPRJ0HL+qUoduel5tVE3inUb76HhBw8AfvGDOJMPaPfkahhOwzlgZQjr1FQoS/A/Tim573VG mR7vxjUIHhMnT6XkW2OuQFEtk9iYlY0kW2H0S1BW1mlAFU8Hzo3AWr9Ug/7kGrE0QzfjbBW1mDP 3JTyJyUihxZuJyg0x/jpNSxs3sLLkeXgi6uYaPv/j/uLoxVcy7OBdDcoi3gGC+FWtNsrxWGCdRX 7HuLbk5rA/2lRXhK/QUOvUZITggfWtPtJmrLsHQCTpfljVarler0p+PRn1/wOeNVg/aeYuQmcxz IJzwjj/YavtT48NaADmzk6n3/uPjdvdSkQxPC9nrMT4MUIT7OAZvAT7MiP+UKTAkRJ9hLIRpBGu pBPjBHe7DRqbwuFcclc381lBTvaUmJB9WGdwFLCVoEnCUiHSD5RE2bs7lybKRZRb0= X-Received: by 2002:a05:622a:1482:b0:509:1887:23d with SMTP id d75a77b69052e-50918870e9dmr76682971cf.67.1773101833459; Mon, 09 Mar 2026 17:17:13 -0700 (PDT) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-102.dlp.protect.broadcom.com. [144.49.247.102]) by smtp-relay.gmail.com with ESMTPS id d75a77b69052e-508f63b43basm10908481cf.0.2026.03.09.17.17.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2026 17:17:13 -0700 (PDT) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-2be21f89332so7716906eec.0 for ; Mon, 09 Mar 2026 17:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1773101832; x=1773706632; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OiGZAwROU5TJxpiCLUT0uYKKo5HkD6AnGMRObmR/GVo=; b=JwWlAIuVVHA4+vZsKm58nkX+ZQNixP+lcQKJIdRP3XVt1s/62RznIpqDJ/o9rcrzPX Vic/tq0A5SENWnmDb9PMIUae5GBid2h0g3dsBxlV2a4iS1e5UQSXRiZEXzQkBP9wOOiQ 4nnjYFSv+zxwQVoxojFPmiqs8sLegl5BQ4HeE= X-Forwarded-Encrypted: i=1; AJvYcCVveFhCj2MvqpdyAHy2eYC47xDzoQL5FXatNVTIVHPYbBtmkl18QYwbueLsgciqTduLNF6HUuM8/dw8yPw=@vger.kernel.org X-Received: by 2002:a05:7300:b90b:b0:2ba:9115:2fab with SMTP id 5a478bee46e88-2be4dfef8fdmr4822976eec.12.1773101832197; Mon, 09 Mar 2026 17:17:12 -0700 (PDT) X-Received: by 2002:a05:7300:b90b:b0:2ba:9115:2fab with SMTP id 5a478bee46e88-2be4dfef8fdmr4822962eec.12.1773101831621; Mon, 09 Mar 2026 17:17:11 -0700 (PDT) Received: from amakhalov-build-vm.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2be4f948324sm12678991eec.17.2026.03.09.17.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 17:17:11 -0700 (PDT) From: Alexey Makhalov To: x86@kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: ajay.kaher@broadcom.com, brennan.lamoreaux@broadcom.com, bo.gan@broadcom.com, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, kas@kernel.org, rick.p.edgecombe@intel.com, linux-coco@lists.linux.dev, Alexey Makhalov Subject: [PATCH v2 3/4] x86/vmware: Report guest crash to the hypervisor Date: Mon, 9 Mar 2026 23:52:49 +0000 Message-ID: <20260309235250.2611115-4-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260309235250.2611115-1-alexey.makhalov@broadcom.com> References: <20260307004238.1181299-1-alexey.makhalov@broadcom.com> <20260309235250.2611115-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e Content-Type: text/plain; charset="utf-8" Register the guest crash reporter to panic_notifier_list, which will be called at panic time. Guest crash reporter will report the crash to the hypervisor through a hypercall. Co-developed-by: Brennan Lamoreaux Signed-off-by: Brennan Lamoreaux Signed-off-by: Alexey Makhalov --- arch/x86/include/asm/vmware.h | 1 + arch/x86/kernel/cpu/vmware.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index c23164503e54..bf6141353774 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -97,6 +97,7 @@ #define VMWARE_CMD_GETHZ 45 #define VMWARE_CMD_GETVCPU_INFO 68 #define VMWARE_CMD_STEALCLOCK 91 +#define VMWARE_CMD_REPORTGUESTCRASH 102 /* * Hypercall command mask: * bits [6:0] command, range [0, 127] diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 9955f2ea0c84..c631e577348a 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -451,6 +452,24 @@ static void __init vmware_paravirt_ops_setup(void) #define vmware_paravirt_ops_setup() do {} while (0) #endif =20 +static int vmware_report_guest_crash(struct notifier_block *self, + unsigned long action, void *data) +{ + vmware_hypercall1(VMWARE_CMD_REPORTGUESTCRASH, 0); + return 0; +} + +static struct notifier_block guest_crash_reporter =3D { + .notifier_call =3D vmware_report_guest_crash +}; + +static int __init register_guest_crash_reporter(void) +{ + atomic_notifier_chain_register(&panic_notifier_list, + &guest_crash_reporter); + + return 0; +} /* * VMware hypervisor takes care of exporting a reliable TSC to the guest. * Still, due to timing difference when running on virtual cpus, the TSC c= an @@ -545,6 +564,8 @@ static void __init vmware_platform_setup(void) vmware_set_capabilities(); =20 kmsg_dump_register(&kmsg_dumper); + + register_guest_crash_reporter(); } =20 static u8 __init get_hypercall_mode(void) --=20 2.43.7 From nobody Thu Apr 9 09:03:33 2026 Received: from mail-pl1-f226.google.com (mail-pl1-f226.google.com [209.85.214.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F4EF1F0991 for ; Tue, 10 Mar 2026 00:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101837; cv=none; b=mWluvUznTpFTlOa+lCIUfYu4duHQmD1U3dMaS/WxlvPd+vl8KfIyQnXqye5aJtDCXhp+0T3egZiuiEecPYlS6opIh+gIj/5Me8508MaY4BYnllBRFAWuJu+faUKSa/BH6HnJqd+nGCgtxOpyN7woEE2LX1T6JolyN1jRhyv0Hr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773101837; c=relaxed/simple; bh=rKD0SlqWqw8PldbinZpjfbtws753oTvboPLwBks61Bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=POpJCtAzeL1IWDQ1+q7BoPJDxePuRZaWt7xT94WN/wUA57sP4u9NH/PWU00HwTYRgP16mUXYIWe2cozoUxdYUFHHgFDphyCth7Jc58lbjxqTKATdodoF4QN1O/50LNysPypvUW78CC4hE+W98aa/6xxKutZDFBRqAHlktSnVUqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=HrVhzXJY; arc=none smtp.client-ip=209.85.214.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="HrVhzXJY" Received: by mail-pl1-f226.google.com with SMTP id d9443c01a7336-2aae146b604so88376745ad.3 for ; Mon, 09 Mar 2026 17:17:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773101835; x=1773706635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3zolKHaPCOFbG+Mda3dOxeNhtXRim55Oc2EZIL0u4Uc=; b=lHiQZzRRm0MGlno48PCVAOTfprJGt9yMTghf53ElwP+hqh7cb+C8ZPKscfQqn8hek6 UkeWXbXXcYKJCvJ4gUxgjiQXeB83x5Xdop0824TSM+GyQife+2tpbk+T8XiP9pp8MO2Y gjKjmB/enUiuaFBGm7YDyjhscMMQ/95L5sh1Fm9UX8LFArGBWHEnnTNWQmVqiYM0xCI1 p9viYb6wCikOXljc1IFn/6zqGEvmiitNHfuSJlZNDBYC7qkCD67IdoKcxGU3JB4R68jJ 3OWh0Cx8CNatRHYo1e/ojvatwTmoppA8y69p7aGAzhg1wH8ZCjFlAekyayzzk/lTFNvY vwkA== X-Forwarded-Encrypted: i=1; AJvYcCXPYsFWiiY+6xz9Gt6KP9CzbY+doxSi/prZBoVZ8xwZe4NlTceNuVZLTrmHghotXL/yfdHJ7l8a5CAk/L4=@vger.kernel.org X-Gm-Message-State: AOJu0Yys1u/1tQPfeVHetwOiGfZBy0h7kP0w/vN0Qhj+NEgNw7dPukXf H7009whSll7roQjItZ9HM7+Gzy5l4JUsopkXtghy3pAoojiYo1Ca/LW4SyoBPgE94QdKvwyZYYf xdrOlYG6Gfrytk5dt+2H8tkJbAe1NZLz7uWTaBW557sXpZxXy5Ytwj6lhsziIg7oeFvoIPkiZkr YPDG0PfMnK4YhlOBpyDIURbQRxMylKVvFgHplMKOvVKkIqy+eGcUm59EPd4b/QLhrKplWJqrAvq 5JDAuIj6V1uhpSGJwzDwAs= X-Gm-Gg: ATEYQzxH6Roz/NbLk0IzJviGAmI5DixY7lRoqwYripKzbyPccc+wFU30JZprN269sci hM51lULQdCxfLsEYUTUNentTeRpq80yf7Sh7mj0tfIjDnDqM0YwHObJiwwjPPbrGXBCovXld6Zs 2mWP23JGlV142pyvFRi7Et8La2RPOAik3sqiqrXIfjgfWKG2K68K3q3MKli09Z7d/FWkJInlLSH CYWcX/nqc+1G/ufDVC4gzMXlv49ujmzzrZ4GD49l5L3GovmKxdz2EnMqFX9lE1DOKN90AsrDDO+ Se7mYZ8sRzyuklxCp3m7cx2kUM5w5JItEDPdss74eEjTgr9juugpt2jnmdhF5YO0HFo2zAGG9Bo hGHaKcMatfOpa0spLMGU42MhUmtdNjwBFU/6E8qFoSH7jGJ3gfbOpOEQNe1wnqHvevOwNLTAaOF ned+5JPVulJytrBuRn/47UdLrTWHeYZBSkPc7CAQKXUsELktDuNtslfwq3p0QC X-Received: by 2002:a17:902:e786:b0:2ae:588a:f3e5 with SMTP id d9443c01a7336-2ae8243b580mr117508195ad.30.1773101835525; Mon, 09 Mar 2026 17:17:15 -0700 (PDT) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-29.dlp.protect.broadcom.com. [144.49.247.29]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2ae83f59cccsm16745775ad.53.2026.03.09.17.17.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2026 17:17:15 -0700 (PDT) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-2ba9a744f7dso13608816eec.0 for ; Mon, 09 Mar 2026 17:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1773101834; x=1773706634; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3zolKHaPCOFbG+Mda3dOxeNhtXRim55Oc2EZIL0u4Uc=; b=HrVhzXJY2M4purZithaWwKSdPMev4oyiXdaUfjPNUbEVBayw1vVI/xnhDuxn5jNCT9 83RXDrW/5UUxbA4Sq6YGSrNVT3TdTzG0GfqRc9gAwDxNYUbYN0fPeB+M98rGE7/JiizV /mNuQAUC/MWABOWKdkLVMISQuj1EeC9TT4eTA= X-Forwarded-Encrypted: i=1; AJvYcCUBkuFMSBLA+FGcK9rJ7r1B4+r1+j16PSWY9NwXgAW3gqeFP9uTXp2pV0Ey57wYRdhnE3ccUh/N/MxCbnw=@vger.kernel.org X-Received: by 2002:a05:7300:80cb:b0:2bd:cbc7:16e2 with SMTP id 5a478bee46e88-2be4deaee17mr5421673eec.13.1773101833689; Mon, 09 Mar 2026 17:17:13 -0700 (PDT) X-Received: by 2002:a05:7300:80cb:b0:2bd:cbc7:16e2 with SMTP id 5a478bee46e88-2be4deaee17mr5421644eec.13.1773101832785; Mon, 09 Mar 2026 17:17:12 -0700 (PDT) Received: from amakhalov-build-vm.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2be4f948324sm12678991eec.17.2026.03.09.17.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 17:17:12 -0700 (PDT) From: Alexey Makhalov To: x86@kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: ajay.kaher@broadcom.com, brennan.lamoreaux@broadcom.com, bo.gan@broadcom.com, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, kas@kernel.org, rick.p.edgecombe@intel.com, linux-coco@lists.linux.dev, Alexey Makhalov Subject: [PATCH v2 4/4] x86/vmware: Support steal time clock for encrypted guests Date: Mon, 9 Mar 2026 23:52:50 +0000 Message-ID: <20260309235250.2611115-5-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260309235250.2611115-1-alexey.makhalov@broadcom.com> References: <20260307004238.1181299-1-alexey.makhalov@broadcom.com> <20260309235250.2611115-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e Content-Type: text/plain; charset="utf-8" Shared memory containing steal time counter should be set to decrypted when guest memory is encrypted. Co-developed-by: Bo Gan Signed-off-by: Bo Gan Signed-off-by: Alexey Makhalov --- arch/x86/kernel/cpu/vmware.c | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index c631e577348a..523a9b99847d 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include =20 #undef pr_fmt #define pr_fmt(fmt) "vmware: " fmt @@ -379,9 +381,47 @@ static struct notifier_block vmware_pv_reboot_nb =3D { .notifier_call =3D vmware_pv_reboot_notify, }; =20 +/* + * Map per-CPU variables for all possible CPUs as decrypted. + * Do this early in boot, before sharing the corresponding + * guest physical addresses with the hypervisor. + */ +static void __init set_shared_memory_decrypted(void) +{ + int cpu; + + if (!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + return; + + for_each_possible_cpu(cpu) { + unsigned long size =3D sizeof(vmw_steal_time); + unsigned long addr =3D (unsigned long)&per_cpu(vmw_steal_time, + cpu); + + /* + * There is no generic high-level API to mark memory as + * decrypted. Intel's set_memory_decrypted() depends on the + * buddy allocator and can fail early in boot if a page split + * is required and allocation is not possible. Use AMD's + * early_set_memory_decrypted() instead, which can perform + * the split during early boot. + */ + early_set_memory_decrypted(addr, size); + + /* That's it for AMD */ + if (cc_vendor =3D=3D CC_VENDOR_AMD) + continue; + + set_memory_decrypted(addr & PAGE_MASK, 1UL << + get_order((addr & ~PAGE_MASK) + size)); + + } +} + #ifdef CONFIG_SMP static void __init vmware_smp_prepare_boot_cpu(void) { + set_shared_memory_decrypted(); vmware_guest_cpu_init(); native_smp_prepare_boot_cpu(); } @@ -444,6 +484,7 @@ static void __init vmware_paravirt_ops_setup(void) vmware_cpu_down_prepare) < 0) pr_err("vmware_guest: Failed to install cpu hotplug callbacks\n"); #else + set_shared_memory_decrypted(); vmware_guest_cpu_init(); #endif } --=20 2.43.7