From: Alexey Makhalov <amakhalov@vmware.com> To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: Alexey Makhalov <amakhalov@vmware.com>, pv-drivers@vmware.com, netdev@vger.kernel.org, richardcochran@gmail.com, dmitry.torokhov@gmail.com, akaher@vmware.com, linux-graphics-maintainer@vmware.com, jsipek@vmware.com, linux-input@vger.kernel.org, namit@vmware.com Subject: [PATCH 6/6] x86/vmware: Add TDX hypercall support Date: Wed, 22 Nov 2023 15:30:58 -0800 [thread overview] Message-ID: <20231122233058.185601-14-amakhalov@vmware.com> (raw) In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> VMware hypercalls use I/O port, VMCALL or VMMCALL instructions. Add __tdx_hypercall path to support TDX guests. No change in high bandwidth hypercalls, as only low bandwidth ones are supported for TDX guests. Co-developed-by: Tim Merrifield <timothym@vmware.com> Signed-off-by: Tim Merrifield <timothym@vmware.com> Signed-off-by: Alexey Makhalov <amakhalov@vmware.com> --- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 9 +++++ 2 files changed, 81 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 17091eba68cb..cd58ff8ef1af 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -40,6 +40,54 @@ extern u8 vmware_hypercall_mode; +#define VMWARE_TDX_VENDOR_LEAF 0x1AF7E4909ULL +#define VMWARE_TDX_HCALL_FUNC 1 + +extern void vmware_tdx_hypercall_args(struct tdx_module_args *args); + +/* + * TDCALL[TDG.VP.VMCALL] uses rax (arg0) and rcx (arg2), while the use of + * rbp (arg6) is discouraged by the TDX specification. Therefore, we + * remap those registers to r12, r13 and r14, respectively. + */ +static inline +unsigned long vmware_tdx_hypercall(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5, uint32_t *out6) +{ + struct tdx_module_args args = { + .r10 = VMWARE_TDX_VENDOR_LEAF, + .r11 = VMWARE_TDX_HCALL_FUNC, + .r12 = VMWARE_HYPERVISOR_MAGIC, + .r13 = cmd, + .rbx = in1, + .rdx = in3, + .rsi = in4, + .rdi = in5, + .r14 = in6, + }; + + vmware_tdx_hypercall_args(&args); + + if (out1) + *out1 = args.rbx; + if (out2) + *out2 = args.r13; + if (out3) + *out3 = args.rdx; + if (out4) + *out4 = args.rsi; + if (out5) + *out5 = args.rdi; + if (out6) + *out6 = args.r14; + + return args.r12; +} + /* * 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. @@ -67,6 +115,10 @@ 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, 0, NULL, NULL, + NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -85,6 +137,10 @@ unsigned long vmware_hypercall3(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, 0, out1, out2, + NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -104,6 +160,10 @@ unsigned long vmware_hypercall4(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, 0, out1, out2, + out3, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -123,6 +183,10 @@ unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, 0, NULL, + out2, NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -145,6 +209,10 @@ unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, 0, 0, 0, NULL, out2, + out3, out4, out5, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), "=D" (*out5) @@ -166,6 +234,10 @@ unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, 0, out1, + out2, out3, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 3aa1adaed18f..0207e8ced92c 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -428,6 +428,15 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & BIT(VCPU_LEGACY_X2APIC)); } +#ifdef CONFIG_INTEL_TDX_GUEST +/* __tdx_hypercall() is not exported. So, export the wrapper */ +void vmware_tdx_hypercall_args(struct tdx_module_args *args) +{ + __tdx_hypercall(args); +} +EXPORT_SYMBOL_GPL(vmware_tdx_hypercall_args); +#endif + #ifdef CONFIG_AMD_MEM_ENCRYPT static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) -- 2.39.0
WARNING: multiple messages have this Message-ID (diff)
From: Alexey Makhalov <amakhalov@vmware.com> To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov <amakhalov@vmware.com> Subject: [PATCH 6/6] x86/vmware: Add TDX hypercall support Date: Wed, 22 Nov 2023 15:30:58 -0800 [thread overview] Message-ID: <20231122233058.185601-14-amakhalov@vmware.com> (raw) In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> VMware hypercalls use I/O port, VMCALL or VMMCALL instructions. Add __tdx_hypercall path to support TDX guests. No change in high bandwidth hypercalls, as only low bandwidth ones are supported for TDX guests. Co-developed-by: Tim Merrifield <timothym@vmware.com> Signed-off-by: Tim Merrifield <timothym@vmware.com> Signed-off-by: Alexey Makhalov <amakhalov@vmware.com> --- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 9 +++++ 2 files changed, 81 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 17091eba68cb..cd58ff8ef1af 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -40,6 +40,54 @@ extern u8 vmware_hypercall_mode; +#define VMWARE_TDX_VENDOR_LEAF 0x1AF7E4909ULL +#define VMWARE_TDX_HCALL_FUNC 1 + +extern void vmware_tdx_hypercall_args(struct tdx_module_args *args); + +/* + * TDCALL[TDG.VP.VMCALL] uses rax (arg0) and rcx (arg2), while the use of + * rbp (arg6) is discouraged by the TDX specification. Therefore, we + * remap those registers to r12, r13 and r14, respectively. + */ +static inline +unsigned long vmware_tdx_hypercall(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5, uint32_t *out6) +{ + struct tdx_module_args args = { + .r10 = VMWARE_TDX_VENDOR_LEAF, + .r11 = VMWARE_TDX_HCALL_FUNC, + .r12 = VMWARE_HYPERVISOR_MAGIC, + .r13 = cmd, + .rbx = in1, + .rdx = in3, + .rsi = in4, + .rdi = in5, + .r14 = in6, + }; + + vmware_tdx_hypercall_args(&args); + + if (out1) + *out1 = args.rbx; + if (out2) + *out2 = args.r13; + if (out3) + *out3 = args.rdx; + if (out4) + *out4 = args.rsi; + if (out5) + *out5 = args.rdi; + if (out6) + *out6 = args.r14; + + return args.r12; +} + /* * 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. @@ -67,6 +115,10 @@ 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, 0, NULL, NULL, + NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -85,6 +137,10 @@ unsigned long vmware_hypercall3(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, 0, out1, out2, + NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -104,6 +160,10 @@ unsigned long vmware_hypercall4(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, 0, out1, out2, + out3, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -123,6 +183,10 @@ unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, 0, NULL, + out2, NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -145,6 +209,10 @@ unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, 0, 0, 0, NULL, out2, + out3, out4, out5, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), "=D" (*out5) @@ -166,6 +234,10 @@ unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, 0, out1, + out2, out3, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 3aa1adaed18f..0207e8ced92c 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -428,6 +428,15 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & BIT(VCPU_LEGACY_X2APIC)); } +#ifdef CONFIG_INTEL_TDX_GUEST +/* __tdx_hypercall() is not exported. So, export the wrapper */ +void vmware_tdx_hypercall_args(struct tdx_module_args *args) +{ + __tdx_hypercall(args); +} +EXPORT_SYMBOL_GPL(vmware_tdx_hypercall_args); +#endif + #ifdef CONFIG_AMD_MEM_ENCRYPT static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) -- 2.39.0
next prev parent reply other threads:[~2023-11-22 23:31 UTC|newest] Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-22 23:30 [PATCH 0/6] VMware hypercalls enhancements Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 1/6] x86/vmware: Move common macros to vmware.h Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 2/6] x86/vmware: Introduce vmware_hypercall API Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 3/6] ptp/vmware: Use " Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 4/6] input/vmmouse: " Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-24 19:46 ` Simon Horman 2023-11-24 19:46 ` Simon Horman 2023-11-25 1:22 ` Alexey Makhalov 2023-11-25 1:22 ` Alexey Makhalov 2023-11-25 4:58 ` dmitry.torokhov 2023-11-25 4:58 ` dmitry.torokhov 2023-11-25 5:01 ` Dmitry Torokhov 2023-11-25 5:01 ` Dmitry Torokhov 2023-11-22 23:30 ` [PATCH 5/6] drm/vmwgfx: " Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 6/6] x86/vmware: Add TDX hypercall support Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 0/6] VMware hypercalls enhancements Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-12-01 23:24 ` [PATCH v2 " Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-01 23:24 ` [PATCH v2 1/6] x86/vmware: Move common macros to vmware.h Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-04 10:32 ` Borislav Petkov 2023-12-04 10:32 ` Borislav Petkov 2023-12-01 23:24 ` [PATCH v2 2/6] x86/vmware: Introduce vmware_hypercall API Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-04 10:35 ` Borislav Petkov 2023-12-04 10:35 ` Borislav Petkov 2023-12-01 23:24 ` [PATCH v2 3/6] ptp/vmware: Use " Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-01 23:24 ` [PATCH v2 4/6] input/vmmouse: " Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-01 23:24 ` [PATCH v2 5/6] drm/vmwgfx: " Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-05 20:27 ` Borislav Petkov 2023-12-05 20:27 ` Borislav Petkov 2023-12-05 21:18 ` Alexey Makhalov 2023-12-05 21:18 ` Alexey Makhalov 2023-12-01 23:24 ` [PATCH v2 6/6] x86/vmware: Add TDX hypercall support Alexey Makhalov 2023-12-01 23:24 ` Alexey Makhalov 2023-12-04 10:31 ` Borislav Petkov 2023-12-04 10:31 ` Borislav Petkov 2023-12-05 21:24 ` Dave Hansen 2023-12-05 21:24 ` Dave Hansen 2023-12-05 21:41 ` Alexey Makhalov 2023-12-05 21:41 ` Alexey Makhalov 2023-12-05 22:43 ` Tim Merrifield 2023-12-05 22:43 ` Tim Merrifield 2023-12-05 23:03 ` Dave Hansen 2023-12-05 23:03 ` Dave Hansen 2023-12-06 0:11 ` Alexey Makhalov 2023-12-06 0:11 ` Alexey Makhalov 2023-12-06 7:15 ` [PATCH] " Alexey Makhalov 2023-12-06 7:15 ` Alexey Makhalov 2023-12-07 17:12 ` Dave Hansen 2023-12-07 17:12 ` Dave Hansen 2023-12-08 2:27 ` Alexey Makhalov 2023-12-08 2:27 ` Alexey Makhalov 2023-12-08 2:32 ` Alexey Makhalov 2023-12-08 2:32 ` Alexey Makhalov 2023-12-05 19:57 ` [PATCH v2 6/6] " kernel test robot 2023-12-05 19:57 ` kernel test robot 2023-12-05 21:04 ` kernel test robot 2023-12-05 21:04 ` kernel test robot 2023-11-22 23:30 ` [PATCH 1/6] x86/vmware: Move common macros to vmware.h Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 2/6] x86/vmware: Introduce vmware_hypercall API Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 3/6] ptp/vmware: Use " Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 4/6] input/vmmouse: " Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` [PATCH 5/6] drm/vmwgfx: " Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov 2023-11-22 23:30 ` Alexey Makhalov [this message] 2023-11-22 23:30 ` [PATCH 6/6] x86/vmware: Add TDX hypercall support Alexey Makhalov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231122233058.185601-14-amakhalov@vmware.com \ --to=amakhalov@vmware.com \ --cc=airlied@gmail.com \ --cc=akaher@vmware.com \ --cc=bp@alien8.d \ --cc=daniel@ffwll.ch \ --cc=dave.hansen@linux.intel.co \ --cc=dmitry.torokhov@gmail.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=hpa@zytor.com \ --cc=jsipek@vmware.com \ --cc=linux-graphics-maintainer@vmware.com \ --cc=linux-input@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=maarten.lankhorst@linux.intel.com \ --cc=mingo@redhat.com \ --cc=mripard@kernel.org \ --cc=namit@vmware.com \ --cc=netdev@vger.kernel.org \ --cc=pv-drivers@vmware.com \ --cc=richardcochran@gmail.com \ --cc=tglx@linutronix.de \ --cc=timothym@vmware.com \ --cc=tzimmermann@suse.de \ --cc=virtualization@lists.linux.dev \ --cc=x86@kernel.org \ --cc=zackr@vmware.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.