VMware hypercalls enhancements
Subsystems (13)
cover VMware hypercalls enhancements
VMware hypercalls invocations were all spread out across the kernel implementing same ABI as in-place asm-inline. With encrypted memory and confidential computing it became harder to maintain every changes in these hypercall implementations.
Intention of this patchset is to introduce arch independent VMware hypercall API layer other subsystems such as device drivers can call to, while hiding architecture specific implementation behind.
Second patch introduces the vmware_hypercall low and high bandwidth families of functions, with little enhancements there. Sixth patch adds tdx hypercall support
arm64 implementation of vmware_hypercalls is in drivers/gpu/drm/ vmwgfx/vmwgfx_msg_arm64.h and going to be moved to arch/arm64 with a separate patchset with the introduction of VMware Linux guest support for arm64.
No functional changes in drivers/input/mouse/vmmouse.c and drivers/ptp/ptp_vmw.c
Alexey Makhalov (6):
x86/vmware: Move common macros to vmware.h
x86/vmware: Introduce vmware_hypercall API
ptp/vmware: Use vmware_hypercall API
input/vmmouse: Use vmware_hypercall API
drm/vmwgfx: Use vmware_hypercall API
x86/vmware: Add TDX hypercall support
arch/x86/include/asm/vmware.h | 327 ++++++++++++++++++++-- arch/x86/kernel/cpu/vmware.c | 101 ++----- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 ++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++---- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 ------------ drivers/input/mouse/vmmouse.c | 76 ++--- drivers/ptp/ptp_vmw.c | 12 +- 7 files changed, 551 insertions(+), 520 deletions(-)
Signature · 1 line
2.39.0
PATCH 1/6 x86/vmware: Move common macros to vmware.h
Move VMware hypercall macros to vmware.h as a preparation step for the next commit. No functional changes besides exporting vmware_hypercall_mode symbol.
--- arch/x86/include/asm/vmware.h | 69 ++++++++++++++++++++++++++++++----- arch/x86/kernel/cpu/vmware.c | 57 +++-------------------------- 2 files changed, 66 insertions(+), 60 deletions(-)
arch/x86/include/asm/vmware.h +60 -9
@@ -8,25 +8,37 @@/* * The hypercall definitions differ in the low word of the %edx argument -* in the following way: the old port base interface uses the port -* number to distinguish between high- and low bandwidth versions. +* 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 new vmcall interface instead uses a set of flags to select * bandwidth mode and transfer direction. The flags should be loaded * into %dx by any user and are automatically replaced by the port -* number if the VMWARE_HYPERVISOR_PORT method is used. +* number if the I/O port method is used. * * In short, new driver code should strictly use the new definition of * %dx content. */ -/* Old port-based version */ -#define VMWARE_HYPERVISOR_PORT 0x5658 -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 +#define VMWARE_HYPERVISOR_HB BIT(0) +#define VMWARE_HYPERVISOR_OUT BIT(1) -/* Current vmcall / vmmcall version */ -#define VMWARE_HYPERVISOR_HB BIT(0) -#define VMWARE_HYPERVISOR_OUT BIT(1) +#define VMWARE_HYPERVISOR_PORT 0x5658 +#define VMWARE_HYPERVISOR_PORT_HB (VMWARE_HYPERVISOR_PORT | \ + VMWARE_HYPERVISOR_HB) + +#define VMWARE_HYPERVISOR_MAGIC 0x564D5868U + +#define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_GETHZ 45 +#define VMWARE_CMD_GETVCPU_INFO 68 +#define VMWARE_CMD_STEALCLOCK 91 + +#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) +#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) + +extern u8 vmware_hypercall_mode;/* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \
@@ -54,4 +66,43 @@ "rep insb", \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) + +#define VMWARE_PORT (cmd, eax, ebx, ecx, edx) \ + __asm__("inl (%%dx), %%eax" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMCALL (cmd, eax, ebx, ecx, edx) \ + __asm__("vmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMMCALL (cmd, eax, ebx, ecx, edx) \ + __asm__("vmmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_CMD (cmd, eax, ebx, ecx, edx) do { \ + switch (vmware_hypercall_mode) { \ + case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ + VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ + VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + default: \ + VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ + break; \ + } \ + } while (0) +#endif
arch/x86/kernel/cpu/vmware.c +6 -51
81 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH 1/6 x86/vmware: Move common macros to vmware.h
In reply to Alexey MakhalovMove VMware hypercall macros to vmware.h as a preparation step for the next commit. No functional changes besides exporting vmware_hypercall_mode symbol.
--- arch/x86/include/asm/vmware.h | 69 ++++++++++++++++++++++++++++++----- arch/x86/kernel/cpu/vmware.c | 57 +++-------------------------- 2 files changed, 66 insertions(+), 60 deletions(-)
arch/x86/include/asm/vmware.h +60 -9
@@ -8,25 +8,37 @@/* * The hypercall definitions differ in the low word of the %edx argument -* in the following way: the old port base interface uses the port -* number to distinguish between high- and low bandwidth versions. +* 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 new vmcall interface instead uses a set of flags to select * bandwidth mode and transfer direction. The flags should be loaded * into %dx by any user and are automatically replaced by the port -* number if the VMWARE_HYPERVISOR_PORT method is used. +* number if the I/O port method is used. * * In short, new driver code should strictly use the new definition of * %dx content. */ -/* Old port-based version */ -#define VMWARE_HYPERVISOR_PORT 0x5658 -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 +#define VMWARE_HYPERVISOR_HB BIT(0) +#define VMWARE_HYPERVISOR_OUT BIT(1) -/* Current vmcall / vmmcall version */ -#define VMWARE_HYPERVISOR_HB BIT(0) -#define VMWARE_HYPERVISOR_OUT BIT(1) +#define VMWARE_HYPERVISOR_PORT 0x5658 +#define VMWARE_HYPERVISOR_PORT_HB (VMWARE_HYPERVISOR_PORT | \ + VMWARE_HYPERVISOR_HB) + +#define VMWARE_HYPERVISOR_MAGIC 0x564D5868U + +#define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_GETHZ 45 +#define VMWARE_CMD_GETVCPU_INFO 68 +#define VMWARE_CMD_STEALCLOCK 91 + +#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) +#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) + +extern u8 vmware_hypercall_mode;/* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \
@@ -54,4 +66,43 @@ "rep insb", \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) + +#define VMWARE_PORT (cmd, eax, ebx, ecx, edx) \ + __asm__("inl (%%dx), %%eax" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMCALL (cmd, eax, ebx, ecx, edx) \ + __asm__("vmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMMCALL (cmd, eax, ebx, ecx, edx) \ + __asm__("vmmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_CMD (cmd, eax, ebx, ecx, edx) do { \ + switch (vmware_hypercall_mode) { \ + case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ + VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ + VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + default: \ + VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ + break; \ + } \ + } while (0) +#endif
arch/x86/kernel/cpu/vmware.c +6 -51
81 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH 2/6 x86/vmware: Introduce vmware_hypercall API
In reply to Alexey MakhalovIntroducing vmware_hypercall family of functions as a common implementation to be used by the VMware guest code and virtual device drivers in arhitecture independent manner.
By analogy with KVM hypercall API, vmware_hypercallX and vmware_hypercall_hb_{out,in} set of functions was added to achieve that. Architecture specific implementation should be hidden inside.
It will simplify future enhancements in VMware hypercalls such as SEV-ES and TDX related changes without needs to modify a caller in device drivers code.
Current implementation extends an idea from commit bac7b4e84323 ("x86/vmware: Update platform detection code for VMCALL/VMMCALL hypercalls") to have a slow, but safe path in VMWARE_HYPERCALL when alternatives are not yet applied. This logic was inherited from VMWARE_CMD from the commit mentioned above. Default alternative code was optimized by size to reduse excessive nop alignment once alternatives are applied. Total default code size is 26 bytes, in worse case (3 bytes alternative) remaining 23 bytes will be aligned by only 3 long NOP instructions.
--- arch/x86/include/asm/vmware.h | 262 ++++++++++++++++++++++++++-------- arch/x86/kernel/cpu/vmware.c | 35 ++--- 2 files changed, 220 insertions(+), 77 deletions(-)
arch/x86/include/asm/vmware.h +206 -56
@@ -40,69 +40,219 @@extern u8 vmware_hypercall_mode; -/* The low bandwidth call. The low word of edx is presumed clear. */ -#define VMWARE_HYPERCALL \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT) ", %%dx; " \ - "inl (%%dx), %%eax", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) -/* -* The high bandwidth out call. The low word of edx is presumed to have the -* HB and OUT bits set. +* 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. */ -#define VMWARE_HYPERCALL_HB_OUT \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep outsb", \ +#define VMWARE_HYPERCALL \ + ALTERNATIVE_3("cmpb $" \ + __stringify(CPUID_VMWARE_FEATURES_ECX_VMMCALL) \ + ", %[mode]\n\t" \ + "jg 2f\n\t" \ + "je 1f\n\t" \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax\n\t" \ + "jmp 3f\n\t" \ + "1: vmmcall\n\t" \ + "jmp 3f\n\t" \ + "2: vmcall\n\t" \ + "3:\n\t", \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax", X86_FEATURE_HYPERVISOR, \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall1 (unsigned long cmd,unsigned long in1) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall3 (unsigned long cmd,unsigned long in1, +uint32_t *out1,uint32_t *out2) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall4 (unsigned long cmd,unsigned long in1, +uint32_t *out1,uint32_t *out2, +uint32_t *out3) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall5 (unsigned long cmd,unsigned long in1, +unsigned long in3,unsigned long in4, +unsigned long in5,uint32_t *out2) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3), +" S " (in4), +" D " (in5) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall6 (unsigned long cmd,unsigned long in1, +unsigned long in3,uint32_t *out2, +uint32_t *out3,uint32_t *out4, +uint32_t *out5) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), + "=D" (*out5) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall7 (unsigned long cmd,unsigned long in1, +unsigned long in3,unsigned long in4, +unsigned long in5,uint32_t *out1, +uint32_t *out2,uint32_t *out3) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3), +" S " (in4), +" D " (in5) + : "cc", "memory"); + return out0; +} + + +#ifdef CONFIG_X86_64 +#define VMW_BP_REG "%%rbp" +#define VMW_BP_CONSTRAINT "r" +#else +#define VMW_BP_REG "%%ebp" +#define VMW_BP_CONSTRAINT "m" +#endif +/* -* The high bandwidth in call. The low word of edx is presumed to have the -* HB bit set. +* High bandwidth calls are not supported on encrypted memory guests. +* The caller should check cc_platform_has(CC_ATTR_MEM_ENCRYPT) and use +* low bandwidth hypercall it memory encryption is set. +* This assumption simplifies HB hypercall impementation to just I/O port +* based approach without alternative patching. */ -#define VMWARE_HYPERCALL_HB_IN \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep insb", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall_hb_out (unsigned long cmd,unsigned long in2, +unsigned long in3,unsigned long in4, +unsigned long in5,unsigned long in6, +uint32_t *out1) +{ +unsigned long out0; + + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep outsb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=a" (out0), "=b" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), +"b" (cmd), +"c" (in2), +"d" (in3 |VMWARE_HYPERVISOR_PORT_HB ), +"S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); +return out0; +} + +static inline +unsigned long vmware_hypercall_hb_in (unsigned long cmd,unsigned long in2, +unsigned long in3,unsigned long in4, +unsigned long in5,unsigned long in6, +uint32_t *out1) +{ +unsigned long out0; -#define VMWARE_PORT (cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL (cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL (cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD (cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep insb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=a" (out0), "=b" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), +"b" (cmd), +"c" (in2), +"d" (in3 |VMWARE_HYPERVISOR_PORT_HB ), +"S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); +return out0; +} +#undef VMW_BP_REG +#undef VMW_BP_CONSTRAINT +#undef VMWARE_HYPERCALL#endif
arch/x86/kernel/cpu/vmware.c +14 -21
@@ -67,9 +67,10 @@ EXPORT_SYMBOL_GPL(vmware_hypercall_mode);static inline int __vmware_platform (void ) { -uint32_t eax, ebx, ecx, edx; -VMWARE_CMD (GETVERSION , eax, ebx, ecx, edx); -return eax != (uint32_t )-1 && ebx ==VMWARE_HYPERVISOR_MAGIC ; +uint32_t eax, ebx, ecx; + + eax =vmware_hypercall3 (VMWARE_CMD_GETVERSION ,0 , &ebx, &ecx); +return eax !=UINT_MAX && ebx ==VMWARE_HYPERVISOR_MAGIC ; }static unsigned long vmware_get_tsc_khz (void )
@@ -121,21 +122,12 @@ static void __init vmware_cyc2ns_setup(void)pr_info ("using clock offset of %llu ns\n" , d->cyc2ns_offset); } -static int vmware_cmd_stealclock (uint32_t arg1,uint32_t arg2) +static int vmware_cmd_stealclock (uint32_t addr_hi,uint32_t addr_lo) { -uint32_t result, info; - - asm volatile (VMWARE_HYPERCALL : - "=a"(result), - "=c"(info) : - "a"(VMWARE_HYPERVISOR_MAGIC), - "b"(0), - "c"(VMWARE_CMD_STEALCLOCK), - "d"(0), - "S"(arg1), - "D"(arg2) : - "memory"); -return result; +uint32_t info; + +return vmware_hypercall5 (VMWARE_CMD_STEALCLOCK ,0 ,0 , addr_hi, addr_lo, + &info); }static bool stealclock_enable (phys_addr_t pa)
@@ -344,10 +336,10 @@ static void __init vmware_set_capabilities(void)static void __init vmware_platform_setup (void ) { -uint32_t eax, ebx, ecx, edx; +uint32_t eax, ebx, ecx;uint64_t lpj, tsc_khz; -VMWARE_CMD (GETHZ , eax, ebx, ecx, edx); + eax =vmware_hypercall3 (VMWARE_CMD_GETHZ ,UINT_MAX , &ebx, &ecx);if (ebx !=UINT_MAX ) { lpj = tsc_khz = eax | (((uint64_t )ebx) <<32 );
@@ -429,8 +421,9 @@ static uint32_t __init vmware_platform(void)/* Checks if hypervisor supports x2apic without VT-D interrupt remapping. */ static bool __init vmware_legacy_x2apic_available (void ) { -uint32_t eax, ebx, ecx, edx; -VMWARE_CMD (GETVCPU_INFO , eax, ebx, ecx, edx); +uint32_t eax; + + eax =vmware_hypercall1 (VMWARE_CMD_GETVCPU_INFO ,0 );return !(eax &BIT (VCPU_RESERVED )) && (eax &BIT (VCPU_LEGACY_X2APIC )); }
Signature · 1 line
2.39.0
PATCH 2/6 x86/vmware: Introduce vmware_hypercall API
In reply to Alexey MakhalovIntroducing vmware_hypercall family of functions as a common implementation to be used by the VMware guest code and virtual device drivers in arhitecture independent manner.
By analogy with KVM hypercall API, vmware_hypercallX and vmware_hypercall_hb_{out,in} set of functions was added to achieve that. Architecture specific implementation should be hidden inside.
It will simplify future enhancements in VMware hypercalls such as SEV-ES and TDX related changes without needs to modify a caller in device drivers code.
Current implementation extends an idea from commit bac7b4e84323 ("x86/vmware: Update platform detection code for VMCALL/VMMCALL hypercalls") to have a slow, but safe path in VMWARE_HYPERCALL when alternatives are not yet applied. This logic was inherited from VMWARE_CMD from the commit mentioned above. Default alternative code was optimized by size to reduse excessive nop alignment once alternatives are applied. Total default code size is 26 bytes, in worse case (3 bytes alternative) remaining 23 bytes will be aligned by only 3 long NOP instructions.
--- arch/x86/include/asm/vmware.h | 262 ++++++++++++++++++++++++++-------- arch/x86/kernel/cpu/vmware.c | 35 ++--- 2 files changed, 220 insertions(+), 77 deletions(-)
arch/x86/include/asm/vmware.h +206 -56
@@ -40,69 +40,219 @@extern u8 vmware_hypercall_mode; -/* The low bandwidth call. The low word of edx is presumed clear. */ -#define VMWARE_HYPERCALL \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT) ", %%dx; " \ - "inl (%%dx), %%eax", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) -/* -* The high bandwidth out call. The low word of edx is presumed to have the -* HB and OUT bits set. +* 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. */ -#define VMWARE_HYPERCALL_HB_OUT \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep outsb", \ +#define VMWARE_HYPERCALL \ + ALTERNATIVE_3("cmpb $" \ + __stringify(CPUID_VMWARE_FEATURES_ECX_VMMCALL) \ + ", %[mode]\n\t" \ + "jg 2f\n\t" \ + "je 1f\n\t" \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax\n\t" \ + "jmp 3f\n\t" \ + "1: vmmcall\n\t" \ + "jmp 3f\n\t" \ + "2: vmcall\n\t" \ + "3:\n\t", \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax", X86_FEATURE_HYPERVISOR, \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall1 (unsigned long cmd,unsigned long in1) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall3 (unsigned long cmd,unsigned long in1, +uint32_t *out1,uint32_t *out2) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall4 (unsigned long cmd,unsigned long in1, +uint32_t *out1,uint32_t *out2, +uint32_t *out3) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall5 (unsigned long cmd,unsigned long in1, +unsigned long in3,unsigned long in4, +unsigned long in5,uint32_t *out2) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3), +" S " (in4), +" D " (in5) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall6 (unsigned long cmd,unsigned long in1, +unsigned long in3,uint32_t *out2, +uint32_t *out3,uint32_t *out4, +uint32_t *out5) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), + "=D" (*out5) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall7 (unsigned long cmd,unsigned long in1, +unsigned long in3,unsigned long in4, +unsigned long in5,uint32_t *out1, +uint32_t *out2,uint32_t *out3) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3), +" S " (in4), +" D " (in5) + : "cc", "memory"); + return out0; +} + + +#ifdef CONFIG_X86_64 +#define VMW_BP_REG "%%rbp" +#define VMW_BP_CONSTRAINT "r" +#else +#define VMW_BP_REG "%%ebp" +#define VMW_BP_CONSTRAINT "m" +#endif +/* -* The high bandwidth in call. The low word of edx is presumed to have the -* HB bit set. +* High bandwidth calls are not supported on encrypted memory guests. +* The caller should check cc_platform_has(CC_ATTR_MEM_ENCRYPT) and use +* low bandwidth hypercall it memory encryption is set. +* This assumption simplifies HB hypercall impementation to just I/O port +* based approach without alternative patching. */ -#define VMWARE_HYPERCALL_HB_IN \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep insb", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall_hb_out (unsigned long cmd,unsigned long in2, +unsigned long in3,unsigned long in4, +unsigned long in5,unsigned long in6, +uint32_t *out1) +{ +unsigned long out0; + + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep outsb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=a" (out0), "=b" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), +"b" (cmd), +"c" (in2), +"d" (in3 |VMWARE_HYPERVISOR_PORT_HB ), +"S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); +return out0; +} + +static inline +unsigned long vmware_hypercall_hb_in (unsigned long cmd,unsigned long in2, +unsigned long in3,unsigned long in4, +unsigned long in5,unsigned long in6, +uint32_t *out1) +{ +unsigned long out0; -#define VMWARE_PORT (cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL (cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL (cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD (cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep insb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=a" (out0), "=b" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), +"b" (cmd), +"c" (in2), +"d" (in3 |VMWARE_HYPERVISOR_PORT_HB ), +"S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); +return out0; +} +#undef VMW_BP_REG +#undef VMW_BP_CONSTRAINT +#undef VMWARE_HYPERCALL#endif
arch/x86/kernel/cpu/vmware.c +14 -21
@@ -67,9 +67,10 @@ EXPORT_SYMBOL_GPL(vmware_hypercall_mode);static inline int __vmware_platform (void ) { -uint32_t eax, ebx, ecx, edx; -VMWARE_CMD (GETVERSION , eax, ebx, ecx, edx); -return eax != (uint32_t )-1 && ebx ==VMWARE_HYPERVISOR_MAGIC ; +uint32_t eax, ebx, ecx; + + eax =vmware_hypercall3 (VMWARE_CMD_GETVERSION ,0 , &ebx, &ecx); +return eax !=UINT_MAX && ebx ==VMWARE_HYPERVISOR_MAGIC ; }static unsigned long vmware_get_tsc_khz (void )
@@ -121,21 +122,12 @@ static void __init vmware_cyc2ns_setup(void)pr_info ("using clock offset of %llu ns\n" , d->cyc2ns_offset); } -static int vmware_cmd_stealclock (uint32_t arg1,uint32_t arg2) +static int vmware_cmd_stealclock (uint32_t addr_hi,uint32_t addr_lo) { -uint32_t result, info; - - asm volatile (VMWARE_HYPERCALL : - "=a"(result), - "=c"(info) : - "a"(VMWARE_HYPERVISOR_MAGIC), - "b"(0), - "c"(VMWARE_CMD_STEALCLOCK), - "d"(0), - "S"(arg1), - "D"(arg2) : - "memory"); -return result; +uint32_t info; + +return vmware_hypercall5 (VMWARE_CMD_STEALCLOCK ,0 ,0 , addr_hi, addr_lo, + &info); }static bool stealclock_enable (phys_addr_t pa)
@@ -344,10 +336,10 @@ static void __init vmware_set_capabilities(void)static void __init vmware_platform_setup (void ) { -uint32_t eax, ebx, ecx, edx; +uint32_t eax, ebx, ecx;uint64_t lpj, tsc_khz; -VMWARE_CMD (GETHZ , eax, ebx, ecx, edx); + eax =vmware_hypercall3 (VMWARE_CMD_GETHZ ,UINT_MAX , &ebx, &ecx);if (ebx !=UINT_MAX ) { lpj = tsc_khz = eax | (((uint64_t )ebx) <<32 );
@@ -429,8 +421,9 @@ static uint32_t __init vmware_platform(void)/* Checks if hypervisor supports x2apic without VT-D interrupt remapping. */ static bool __init vmware_legacy_x2apic_available (void ) { -uint32_t eax, ebx, ecx, edx; -VMWARE_CMD (GETVCPU_INFO , eax, ebx, ecx, edx); +uint32_t eax; + + eax =vmware_hypercall1 (VMWARE_CMD_GETVCPU_INFO ,0 );return !(eax &BIT (VCPU_RESERVED )) && (eax &BIT (VCPU_LEGACY_X2APIC )); }
Signature · 1 line
2.39.0
PATCH 3/6 ptp/vmware: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended.
--- drivers/ptp/ptp_vmw.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/ptp/ptp_vmw.c +3 -9
@@ -14,7 +14,6 @@#include <asm/hypervisor.h> #include <asm/vmware.h> -#define VMWARE_MAGIC 0x564D5868#define VMWARE_CMD_PCLK (nr) ((nr << 16) | 97)#define VMWARE_CMD_PCLK_GETTIME VMWARE_CMD_PCLK(0)
@@ -24,15 +23,10 @@ static struct ptp_clock *ptp_vmw_clock;static int ptp_vmw_pclk_read (u64 *ns) { -u32 ret, nsec_hi, nsec_lo, unused1, unused2, unused3; - - asm volatile (VMWARE_HYPERCALL : - "=a"(ret), "=b"(nsec_hi), "=c"(nsec_lo), "=d"(unused1), - "=S"(unused2), "=D"(unused3) : - "a"(VMWARE_MAGIC), "b"(0), - "c"(VMWARE_CMD_PCLK_GETTIME), "d"(0) : - "memory"); +u32 ret, nsec_hi, nsec_lo; + ret =vmware_hypercall3 (VMWARE_CMD_PCLK_GETTIME ,0 , + &nsec_hi, &nsec_lo);if (ret ==0 ) *ns = ((u64 )nsec_hi <<32 ) | nsec_lo;return ret;
Signature · 1 line
2.39.0
PATCH 3/6 ptp/vmware: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended.
--- drivers/ptp/ptp_vmw.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/ptp/ptp_vmw.c +3 -9
@@ -14,7 +14,6 @@#include <asm/hypervisor.h> #include <asm/vmware.h> -#define VMWARE_MAGIC 0x564D5868#define VMWARE_CMD_PCLK (nr) ((nr << 16) | 97)#define VMWARE_CMD_PCLK_GETTIME VMWARE_CMD_PCLK(0)
@@ -24,15 +23,10 @@ static struct ptp_clock *ptp_vmw_clock;static int ptp_vmw_pclk_read (u64 *ns) { -u32 ret, nsec_hi, nsec_lo, unused1, unused2, unused3; - - asm volatile (VMWARE_HYPERCALL : - "=a"(ret), "=b"(nsec_hi), "=c"(nsec_lo), "=d"(unused1), - "=S"(unused2), "=D"(unused3) : - "a"(VMWARE_MAGIC), "b"(0), - "c"(VMWARE_CMD_PCLK_GETTIME), "d"(0) : - "memory"); +u32 ret, nsec_hi, nsec_lo; + ret =vmware_hypercall3 (VMWARE_CMD_PCLK_GETTIME ,0 , + &nsec_hi, &nsec_lo);if (ret ==0 ) *ns = ((u64 )nsec_hi <<32 ) | nsec_lo;return ret;
Signature · 1 line
2.39.0
cover VMware hypercalls enhancements
In reply to Alexey MakhalovVMware hypercalls invocations were all spread out across the kernel implementing same ABI as in-place asm-inline. With encrypted memory and confidential computing it became harder to maintain every changes in these hypercall implementations.
Intention of this patchset is to introduce arch independent VMware hypercall API layer other subsystems such as device drivers can call to, while hiding architecture specific implementation behind.
Second patch introduces the vmware_hypercall low and high bandwidth families of functions, with little enhancements there. Sixth patch adds tdx hypercall support
arm64 implementation of vmware_hypercalls is in drivers/gpu/drm/ vmwgfx/vmwgfx_msg_arm64.h and going to be moved to arch/arm64 with a separate patchset with the introduction of VMware Linux guest support for arm64.
No functional changes in drivers/input/mouse/vmmouse.c and drivers/ptp/ptp_vmw.c
Alexey Makhalov (6):
x86/vmware: Move common macros to vmware.h
x86/vmware: Introduce vmware_hypercall API
ptp/vmware: Use vmware_hypercall API
input/vmmouse: Use vmware_hypercall API
drm/vmwgfx: Use vmware_hypercall API
x86/vmware: Add TDX hypercall support
arch/x86/include/asm/vmware.h | 327 ++++++++++++++++++++-- arch/x86/kernel/cpu/vmware.c | 101 ++----- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 ++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++---- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 ------------ drivers/input/mouse/vmmouse.c | 76 ++--- drivers/ptp/ptp_vmw.c | 12 +- 7 files changed, 551 insertions(+), 520 deletions(-)
Signature · 1 line
2.39.0
v2 cover VMware hypercalls enhancements
From: Alexey Makhalov <[email protected]>
VMware hypercalls invocations were all spread out across the kernel implementing same ABI as in-place asm-inline. With encrypted memory and confidential computing it became harder to maintain every changes in these hypercall implementations.
Intention of this patchset is to introduce arch independent VMware hypercall API layer other subsystems such as device drivers can call to, while hiding architecture specific implementation behind.
Second patch introduces the vmware_hypercall low and high bandwidth families of functions, with little enhancements there. Sixth patch adds tdx hypercall support
arm64 implementation of vmware_hypercalls is in drivers/gpu/drm/ vmwgfx/vmwgfx_msg_arm64.h and going to be moved to arch/arm64 with a separate patchset with the introduction of VMware Linux guest support for arm64.
No functional changes in drivers/input/mouse/vmmouse.c and drivers/ptp/ptp_vmw.c
v1->v2 changes (no functional changes):
- Improved commit message in patches 2 and 5.
- Added Reviewed-by for all patches.
- Added Ack from Dmitry Torokhov in patch 4. No fixes regarding reported by Simon Horman gcc error in this patch.
x86 maintainers, please consider merging this patch set in your branch.
Alexey Makhalov (6):
x86/vmware: Move common macros to vmware.h
x86/vmware: Introduce vmware_hypercall API
ptp/vmware: Use vmware_hypercall API
input/vmmouse: Use vmware_hypercall API
drm/vmwgfx: Use vmware_hypercall API
x86/vmware: Add TDX hypercall support
arch/x86/include/asm/vmware.h | 327 ++++++++++++++++++++-- arch/x86/kernel/cpu/vmware.c | 101 ++----- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 ++++-------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++---- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 ------------ drivers/input/mouse/vmmouse.c | 76 ++--- drivers/ptp/ptp_vmw.c | 12 +- 7 files changed, 551 insertions(+), 520 deletions(-)
Signature · 1 line
2.39.0
PATCH v2 1/6 x86/vmware: Move common macros to vmware.h
Move VMware hypercall macros to vmware.h as a preparation step for the next commit. No functional changes besides exporting vmware_hypercall_mode symbol.
--- arch/x86/include/asm/vmware.h | 69 ++++++++++++++++++++++++++++++----- arch/x86/kernel/cpu/vmware.c | 57 +++-------------------------- 2 files changed, 66 insertions(+), 60 deletions(-)
arch/x86/include/asm/vmware.h +60 -9
@@ -8,25 +8,37 @@/* * The hypercall definitions differ in the low word of the %edx argument -* in the following way: the old port base interface uses the port -* number to distinguish between high- and low bandwidth versions. +* 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 new vmcall interface instead uses a set of flags to select * bandwidth mode and transfer direction. The flags should be loaded * into %dx by any user and are automatically replaced by the port -* number if the VMWARE_HYPERVISOR_PORT method is used. +* number if the I/O port method is used. * * In short, new driver code should strictly use the new definition of * %dx content. */ -/* Old port-based version */ -#define VMWARE_HYPERVISOR_PORT 0x5658 -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 +#define VMWARE_HYPERVISOR_HB BIT(0) +#define VMWARE_HYPERVISOR_OUT BIT(1) -/* Current vmcall / vmmcall version */ -#define VMWARE_HYPERVISOR_HB BIT(0) -#define VMWARE_HYPERVISOR_OUT BIT(1) +#define VMWARE_HYPERVISOR_PORT 0x5658 +#define VMWARE_HYPERVISOR_PORT_HB (VMWARE_HYPERVISOR_PORT | \ + VMWARE_HYPERVISOR_HB) + +#define VMWARE_HYPERVISOR_MAGIC 0x564D5868U + +#define VMWARE_CMD_GETVERSION 10 +#define VMWARE_CMD_GETHZ 45 +#define VMWARE_CMD_GETVCPU_INFO 68 +#define VMWARE_CMD_STEALCLOCK 91 + +#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) +#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) + +extern u8 vmware_hypercall_mode;/* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \
@@ -54,4 +66,43 @@ "rep insb", \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) + +#define VMWARE_PORT (cmd, eax, ebx, ecx, edx) \ + __asm__("inl (%%dx), %%eax" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMCALL (cmd, eax, ebx, ecx, edx) \ + __asm__("vmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMMCALL (cmd, eax, ebx, ecx, edx) \ + __asm__("vmmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_CMD (cmd, eax, ebx, ecx, edx) do { \ + switch (vmware_hypercall_mode) { \ + case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ + VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ + VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + default: \ + VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ + break; \ + } \ + } while (0) +#endif
arch/x86/kernel/cpu/vmware.c +6 -51
81 lines not on this page · raw message
Signature · 1 line
2.39.0
Borislav Petkov
maintainerRe: [PATCH v2 1/6] x86/vmware: Move common macros to vmware.h
Quoted 2 lines · Alexey Makhalov
Move VMware hypercall macros to
vmware.has a preparation step for the next commit. No functional changes besides exporting
"next commit" in git is ambiguous. Get rid of such formulations.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v2 2/6 x86/vmware: Introduce vmware_hypercall API
In reply to Alexey MakhalovIntroducing vmware_hypercall family of functions as a common implementation to be used by the VMware guest code and virtual device drivers in architecture independent manner.
By analogy with KVM hypercall API, vmware_hypercallX and vmware_hypercall_hb_{out,in} set of functions was added to achieve that. Architecture specific implementation should be hidden inside.
It will simplify future enhancements in VMware hypercalls such as SEV-ES and TDX related changes without needs to modify a caller in device drivers code.
Current implementation extends an idea from commit bac7b4e84323 ("x86/vmware: Update platform detection code for VMCALL/VMMCALL hypercalls") to have a slow, but safe path in VMWARE_HYPERCALL earlier during the boot when alternatives are not yet applied. This logic was inherited from VMWARE_CMD from the commit mentioned above. Default alternative code was optimized by size to reduce excessive nop alignment once alternatives are applied. Total default code size is 26 bytes, in worse case (3 bytes alternative) remaining 23 bytes will be aligned by only 3 long NOP instructions.
--- arch/x86/include/asm/vmware.h | 262 ++++++++++++++++++++++++++-------- arch/x86/kernel/cpu/vmware.c | 35 ++--- 2 files changed, 220 insertions(+), 77 deletions(-)
arch/x86/include/asm/vmware.h +206 -56
@@ -40,69 +40,219 @@extern u8 vmware_hypercall_mode; -/* The low bandwidth call. The low word of edx is presumed clear. */ -#define VMWARE_HYPERCALL \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT) ", %%dx; " \ - "inl (%%dx), %%eax", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) -/* -* The high bandwidth out call. The low word of edx is presumed to have the -* HB and OUT bits set. +* 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. */ -#define VMWARE_HYPERCALL_HB_OUT \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep outsb", \ +#define VMWARE_HYPERCALL \ + ALTERNATIVE_3("cmpb $" \ + __stringify(CPUID_VMWARE_FEATURES_ECX_VMMCALL) \ + ", %[mode]\n\t" \ + "jg 2f\n\t" \ + "je 1f\n\t" \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax\n\t" \ + "jmp 3f\n\t" \ + "1: vmmcall\n\t" \ + "jmp 3f\n\t" \ + "2: vmcall\n\t" \ + "3:\n\t", \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax", X86_FEATURE_HYPERVISOR, \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall1 (unsigned long cmd,unsigned long in1) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall3 (unsigned long cmd,unsigned long in1, +uint32_t *out1,uint32_t *out2) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall4 (unsigned long cmd,unsigned long in1, +uint32_t *out1,uint32_t *out2, +uint32_t *out3) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (0) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall5 (unsigned long cmd,unsigned long in1, +unsigned long in3,unsigned long in4, +unsigned long in5,uint32_t *out2) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3), +" S " (in4), +" D " (in5) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall6 (unsigned long cmd,unsigned long in1, +unsigned long in3,uint32_t *out2, +uint32_t *out3,uint32_t *out4, +uint32_t *out5) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), + "=D" (*out5) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3) + : "cc", "memory"); + return out0; +} + +static inline +unsigned long vmware_hypercall7 (unsigned long cmd,unsigned long in1, +unsigned long in3,unsigned long in4, +unsigned long in5,uint32_t *out1, +uint32_t *out2,uint32_t *out3) +{ +unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), +" a" (VMWARE_HYPERVISOR_MAGIC), +" b" (in1), +" c" (cmd), +" d" (in3), +" S " (in4), +" D " (in5) + : "cc", "memory"); + return out0; +} + + +#ifdef CONFIG_X86_64 +#define VMW_BP_REG "%%rbp" +#define VMW_BP_CONSTRAINT "r" +#else +#define VMW_BP_REG "%%ebp" +#define VMW_BP_CONSTRAINT "m" +#endif +/* -* The high bandwidth in call. The low word of edx is presumed to have the -* HB bit set. +* High bandwidth calls are not supported on encrypted memory guests. +* The caller should check cc_platform_has(CC_ATTR_MEM_ENCRYPT) and use +* low bandwidth hypercall it memory encryption is set. +* This assumption simplifies HB hypercall impementation to just I/O port +* based approach without alternative patching. */ -#define VMWARE_HYPERCALL_HB_IN \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep insb", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall_hb_out (unsigned long cmd,unsigned long in2, +unsigned long in3,unsigned long in4, +unsigned long in5,unsigned long in6, +uint32_t *out1) +{ +unsigned long out0; + + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep outsb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=a" (out0), "=b" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), +"b" (cmd), +"c" (in2), +"d" (in3 |VMWARE_HYPERVISOR_PORT_HB ), +"S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); +return out0; +} + +static inline +unsigned long vmware_hypercall_hb_in (unsigned long cmd,unsigned long in2, +unsigned long in3,unsigned long in4, +unsigned long in5,unsigned long in6, +uint32_t *out1) +{ +unsigned long out0; -#define VMWARE_PORT (cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL (cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL (cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD (cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep insb\n\t" + "pop " VMW_BP_REG "\n\t" + UNWIND_HINT_RESTORE + : "=a" (out0), "=b" (*out1) + : "a" (VMWARE_HYPERVISOR_MAGIC), +"b" (cmd), +"c" (in2), +"d" (in3 |VMWARE_HYPERVISOR_PORT_HB ), +"S" (in4), + "D" (in5), + [in6] VMW_BP_CONSTRAINT (in6) + : "cc", "memory"); +return out0; +} +#undef VMW_BP_REG +#undef VMW_BP_CONSTRAINT +#undef VMWARE_HYPERCALL#endif
arch/x86/kernel/cpu/vmware.c +14 -21
@@ -67,9 +67,10 @@ EXPORT_SYMBOL_GPL(vmware_hypercall_mode);static inline int __vmware_platform (void ) { -uint32_t eax, ebx, ecx, edx; -VMWARE_CMD (GETVERSION , eax, ebx, ecx, edx); -return eax != (uint32_t )-1 && ebx ==VMWARE_HYPERVISOR_MAGIC ; +uint32_t eax, ebx, ecx; + + eax =vmware_hypercall3 (VMWARE_CMD_GETVERSION ,0 , &ebx, &ecx); +return eax !=UINT_MAX && ebx ==VMWARE_HYPERVISOR_MAGIC ; }static unsigned long vmware_get_tsc_khz (void )
@@ -121,21 +122,12 @@ static void __init vmware_cyc2ns_setup(void)pr_info ("using clock offset of %llu ns\n" , d->cyc2ns_offset); } -static int vmware_cmd_stealclock (uint32_t arg1,uint32_t arg2) +static int vmware_cmd_stealclock (uint32_t addr_hi,uint32_t addr_lo) { -uint32_t result, info; - - asm volatile (VMWARE_HYPERCALL : - "=a"(result), - "=c"(info) : - "a"(VMWARE_HYPERVISOR_MAGIC), - "b"(0), - "c"(VMWARE_CMD_STEALCLOCK), - "d"(0), - "S"(arg1), - "D"(arg2) : - "memory"); -return result; +uint32_t info; + +return vmware_hypercall5 (VMWARE_CMD_STEALCLOCK ,0 ,0 , addr_hi, addr_lo, + &info); }static bool stealclock_enable (phys_addr_t pa)
@@ -344,10 +336,10 @@ static void __init vmware_set_capabilities(void)static void __init vmware_platform_setup (void ) { -uint32_t eax, ebx, ecx, edx; +uint32_t eax, ebx, ecx;uint64_t lpj, tsc_khz; -VMWARE_CMD (GETHZ , eax, ebx, ecx, edx); + eax =vmware_hypercall3 (VMWARE_CMD_GETHZ ,UINT_MAX , &ebx, &ecx);if (ebx !=UINT_MAX ) { lpj = tsc_khz = eax | (((uint64_t )ebx) <<32 );
@@ -429,8 +421,9 @@ static uint32_t __init vmware_platform(void)/* Checks if hypervisor supports x2apic without VT-D interrupt remapping. */ static bool __init vmware_legacy_x2apic_available (void ) { -uint32_t eax, ebx, ecx, edx; -VMWARE_CMD (GETVCPU_INFO , eax, ebx, ecx, edx); +uint32_t eax; + + eax =vmware_hypercall1 (VMWARE_CMD_GETVCPU_INFO ,0 );return !(eax &BIT (VCPU_RESERVED )) && (eax &BIT (VCPU_LEGACY_X2APIC )); }
Signature · 1 line
2.39.0
Borislav Petkov
maintainerRe: [PATCH v2 2/6] x86/vmware: Introduce vmware_hypercall API
Quoted 8 lines · Alexey Makhalov
Introducing
vmware_hypercallfamily of functions as a common implementation to be used by the VMware guest code and virtual device drivers in architecture independent manner.By analogy with KVM hypercall API,
vmware_hypercallXand vmware_hypercall_hb_{out,in} set of functions was added to achieve that. Architecture specific implementation should be hidden inside.
Pls read section "2) Describe your changes" in Documentation/process/submitting-patches.rst for more details on how to formulate your commit messages.
Also, see section "Changelog" in Documentation/process/maintainer-tip.rst
More specifically:
"Describe your changes in imperative mood, e.g. "make xyzzy do frotz" instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy to do frotz", as if you are giving orders to the codebase to change its behaviour."
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v2 3/6 ptp/vmware: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended.
--- drivers/ptp/ptp_vmw.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/ptp/ptp_vmw.c +3 -9
@@ -14,7 +14,6 @@#include <asm/hypervisor.h> #include <asm/vmware.h> -#define VMWARE_MAGIC 0x564D5868#define VMWARE_CMD_PCLK (nr) ((nr << 16) | 97)#define VMWARE_CMD_PCLK_GETTIME VMWARE_CMD_PCLK(0)
@@ -24,15 +23,10 @@ static struct ptp_clock *ptp_vmw_clock;static int ptp_vmw_pclk_read (u64 *ns) { -u32 ret, nsec_hi, nsec_lo, unused1, unused2, unused3; - - asm volatile (VMWARE_HYPERCALL : - "=a"(ret), "=b"(nsec_hi), "=c"(nsec_lo), "=d"(unused1), - "=S"(unused2), "=D"(unused3) : - "a"(VMWARE_MAGIC), "b"(0), - "c"(VMWARE_CMD_PCLK_GETTIME), "d"(0) : - "memory"); +u32 ret, nsec_hi, nsec_lo; + ret =vmware_hypercall3 (VMWARE_CMD_PCLK_GETTIME ,0 , + &nsec_hi, &nsec_lo);if (ret ==0 ) *ns = ((u64 )nsec_hi <<32 ) | nsec_lo;return ret;
Signature · 1 line
2.39.0
PATCH v2 4/6 input/vmmouse: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended.
--- drivers/input/mouse/vmmouse.c | 76 ++++++++++------------------------- 1 file changed, 22 insertions(+), 54 deletions(-)
drivers/input/mouse/vmmouse.c +22 -54
@@ -21,19 +21,16 @@#include "psmouse.h" #include "vmmouse.h" -#define VMMOUSE_PROTO_MAGIC 0x564D5868U -/* * Main commands supported by the vmmouse hypervisor port. */ -#define VMMOUSE_PROTO_CMD_GETVERSION 10 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_DATA 39 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_STATUS 40 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND 41 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_RESTRICT 86 +#define VMWARE_CMD_ABSPOINTER_DATA 39 +#define VMWARE_CMD_ABSPOINTER_STATUS 40 +#define VMWARE_CMD_ABSPOINTER_COMMAND 41 +#define VMWARE_CMD_ABSPOINTER_RESTRICT 86/* -* Subcommands for VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND +* Subcommands for VMWARE_CMD_ABSPOINTER_COMMAND */ #define VMMOUSE_CMD_ENABLE 0x45414552U#define VMMOUSE_CMD_DISABLE 0x000000f5U
@@ -76,28 +73,6 @@ struct vmmouse_data {char dev_name[128 ]; }; -/* -* Hypervisor-specific bi-directional communication channel -* implementing the vmmouse protocol. Should never execute on -* bare metal hardware. -*/ -#define VMMOUSE_CMD (cmd, in1, out1, out2, out3, out4) \ -({ \ - unsigned long __dummy1, __dummy2; \ - __asm__ __volatile__ (VMWARE_HYPERCALL : \ - "=a"(out1), \ - "=b"(out2), \ - "=c"(out3), \ - "=d"(out4), \ - "=S"(__dummy1), \ - "=D"(__dummy2) : \ - "a"(VMMOUSE_PROTO_MAGIC), \ - "b"(in1), \ - "c"(VMMOUSE_PROTO_CMD_##cmd), \ - "d"(0) : \ - "memory"); \ -}) -/** * vmmouse_report_button - report button state on the correct input device *
@@ -145,14 +120,12 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse)struct input_dev *abs_dev = priv->abs_dev;struct input_dev *pref_dev;u32 status, x, y, z; -u32 dummy1, dummy2, dummy3;unsigned int queue_length;unsigned int count =255 ;while (count--) {/* See if we have motion data. */ -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , - status, dummy1, dummy2, dummy3); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &VMMOUSE_ERROR ) ==VMMOUSE_ERROR ) {psmouse_err (psmouse,"failed to fetch status data\n" );/*
@@ -172,7 +145,8 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse) }/* Now get it */ -VMMOUSE_CMD (ABSPOINTER_DATA ,4 , status, x, y, z); + status =vmware_hypercall4 (VMWARE_CMD_ABSPOINTER_DATA ,4 , + &x, &y, &z);/* * And report what we've got. Prefer to report button
@@ -247,14 +221,10 @@ static psmouse_ret_t vmmouse_process_byte(struct psmouse *psmouse)static void vmmouse_disable (struct psmouse *psmouse) {u32 status; -u32 dummy1, dummy2, dummy3, dummy4; - -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_DISABLE , - dummy1, dummy2, dummy3, dummy4); -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , - status, dummy1, dummy2, dummy3); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND ,VMMOUSE_CMD_DISABLE ); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &VMMOUSE_ERROR ) !=VMMOUSE_ERROR )psmouse_warn (psmouse,"failed to disable vmmouse device\n" ); }
@@ -271,26 +241,24 @@ static void vmmouse_disable(struct psmouse *psmouse)static int vmmouse_enable (struct psmouse *psmouse) {u32 status, version; -u32 dummy1, dummy2, dummy3, dummy4;/* * Try enabling the device. If successful, we should be able to * read valid version ID back from it. */ -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_ENABLE , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND ,VMMOUSE_CMD_ENABLE );/* * See if version ID can be retrieved. */ -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , status, dummy1, dummy2, dummy3); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &0x0000ffff ) ==0 ) {psmouse_dbg (psmouse,"empty flags - assuming no device\n" );return -ENXIO ; } -VMMOUSE_CMD (ABSPOINTER_DATA ,1 /* single item */ , - version, dummy1, dummy2, dummy3); + version =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_DATA , +1 /* single item */ );if (version !=VMMOUSE_VERSION_ID ) {psmouse_dbg (psmouse,"Unexpected version value: %u vs %u\n" , (unsigned ) version,VMMOUSE_VERSION_ID );
@@ -301,11 +269,11 @@ static int vmmouse_enable(struct psmouse *psmouse)/* * Restrict ioport access, if possible. */ -VMMOUSE_CMD (ABSPOINTER_RESTRICT ,VMMOUSE_RESTRICT_CPL0 , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_RESTRICT , +VMMOUSE_RESTRICT_CPL0 ); -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_REQUEST_ABSOLUTE , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND , +VMMOUSE_CMD_REQUEST_ABSOLUTE );return 0 ; }
@@ -342,7 +310,7 @@ static bool vmmouse_check_hypervisor(void)*/ int vmmouse_detect (struct psmouse *psmouse,bool set_properties) { -u32 response, version, dummy1, dummy2; +u32 response, version, type;if (!vmmouse_check_hypervisor ()) { psmouse_dbg(psmouse,
@@ -351,9 +319,9 @@ int vmmouse_detect(struct psmouse *psmouse, bool set_properties) }/* Check if the device is present */ - response = ~VMMOUSE_PROTO_MAGIC ; -VMMOUSE_CMD (GETVERSION ,0 , version, response, dummy1, dummy2); -if (response !=VMMOUSE_PROTO_MAGIC || version ==0xffffffffU ) + response = ~VMWARE_HYPERVISOR_MAGIC ; + version =vmware_hypercall3 (VMWARE_CMD_GETVERSION ,0 , &response, &type); +if (response !=VMWARE_HYPERVISOR_MAGIC || version ==0xffffffffU )return -ENXIO ;if (set_properties) {
Signature · 1 line
2.39.0
PATCH v2 5/6 drm/vmwgfx: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code.
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant of vmware_hypercall here for now. The move of these functions to arch/arm64/include/asm/vmware.h as well as removal of drivers/gpu/drm/vmwgfx/vmwgfx_msg_{x86,arm64}.h header files will be performed in the follow up patchset.
--- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 +++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++++++++------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 -------------------- 3 files changed, 197 insertions(+), 358 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +61 -112
@@ -48,8 +48,6 @@#define RETRIES 3 -#define VMW_HYPERVISOR_MAGIC 0x564D5868 -#define VMW_PORT_CMD_MSG 30#define VMW_PORT_CMD_HB_MSG 0#define VMW_PORT_CMD_OPEN_CHANNEL (MSG_TYPE_OPEN << 16 | VMW_PORT_CMD_MSG)
@@ -104,20 +102,18 @@ static const char* const mksstat_kern_name_desc[MKSSTAT_KERN_COUNT][2] =*/ static int vmw_open_channel (struct rpc_channel *channel,unsigned int protocol) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; +u32 ecx, edx, esi, edi; -VMW_PORT (VMW_PORT_CMD_OPEN_CHANNEL , - (protocol |GUESTMSG_FLAG_COOKIE ), si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall6 (VMW_PORT_CMD_OPEN_CHANNEL , + (protocol |GUESTMSG_FLAG_COOKIE ),0 , + &ecx, &edx, &esi, &edi);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )return -EINVAL ; channel->channel_id =HIGH_WORD (edx); - channel->cookie_high = si; - channel->cookie_low = di; + channel->cookie_high = esi; + channel->cookie_low = edi;return 0 ; }
@@ -133,17 +129,13 @@ static int vmw_open_channel(struct rpc_channel *channel, unsigned int protocol)*/ static int vmw_close_channel (struct rpc_channel *channel) { -unsigned long eax, ebx, ecx, edx, si, di; - -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; +u32 ecx; -VMW_PORT (VMW_PORT_CMD_CLOSE_CHANNEL , -0 , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_CLOSE_CHANNEL , +0 , channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )return -EINVAL ;
@@ -163,24 +155,18 @@ static int vmw_close_channel(struct rpc_channel *channel)static unsigned long vmw_port_hb_out (struct rpc_channel *channel,const char *msg,bool hb) { -unsigned long si, di, eax, ebx, ecx, edx; +u32 ebx, ecx;unsigned long msg_len =strlen (msg);/* HB port can't access encrypted memory. */ if (hb && !cc_platform_has (CC_ATTR_MEM_ENCRYPT )) { -unsigned long bp = channel->cookie_high; -u32 channel_id = (channel->channel_id <<16 ); - - si = (uintptr_t ) msg; - di = channel->cookie_low; - -VMW_PORT_HB_OUT ( +vmware_hypercall_hb_out ( (MESSAGE_STATUS_SUCCESS <<16 ) |VMW_PORT_CMD_HB_MSG , - msg_len, si, di, -VMWARE_HYPERVISOR_HB | channel_id | -VMWARE_HYPERVISOR_OUT , -VMW_HYPERVISOR_MAGIC , bp, - eax, ebx, ecx, edx, si, di); + msg_len, + channel->channel_id <<16 , + (uintptr_t ) msg, channel->cookie_low, + channel->cookie_high, + &ebx);return ebx; }
@@ -194,14 +180,13 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,memcpy (&word, msg, bytes); msg_len -= bytes; msg += bytes; - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_MSG | (MSG_TYPE_SENDPAYLOAD <<16 ), - word, si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); + +vmware_hypercall5 (VMW_PORT_CMD_MSG | + (MSG_TYPE_SENDPAYLOAD <<16 ), + word, channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx); }return ecx;
@@ -220,22 +205,17 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,static unsigned long vmw_port_hb_in (struct rpc_channel *channel,char *reply,unsigned long reply_len,bool hb) { -unsigned long si, di, eax, ebx, ecx, edx; +u32 ebx, ecx, edx;/* HB port can't access encrypted memory */ if (hb && !cc_platform_has (CC_ATTR_MEM_ENCRYPT )) { -unsigned long bp = channel->cookie_low; -u32 channel_id = (channel->channel_id <<16 ); - - si = channel->cookie_high; - di = (uintptr_t ) reply; - -VMW_PORT_HB_IN ( +vmware_hypercall_hb_in ( (MESSAGE_STATUS_SUCCESS <<16 ) |VMW_PORT_CMD_HB_MSG , - reply_len, si, di, -VMWARE_HYPERVISOR_HB | channel_id, -VMW_HYPERVISOR_MAGIC , bp, - eax, ebx, ecx, edx, si, di); + reply_len, + channel->channel_id <<16 , + channel->cookie_high, + (uintptr_t ) reply, channel->cookie_low, + &ebx);return ebx; }
@@ -245,14 +225,13 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,while (reply_len) { unsigned int bytes = min_t(unsigned long, reply_len, 4); - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_MSG | (MSG_TYPE_RECVPAYLOAD <<16 ), -MESSAGE_STATUS_SUCCESS , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall7 (VMW_PORT_CMD_MSG | + (MSG_TYPE_RECVPAYLOAD <<16 ), +MESSAGE_STATUS_SUCCESS , + channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )break ;
@@ -276,22 +255,18 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,*/ static int vmw_send_msg (struct rpc_channel *channel,const char *msg) { -unsigned long eax, ebx, ecx, edx, si, di; +u32 ebx, ecx;size_t msg_len =strlen (msg);int retries =0 ;while (retries <RETRIES ) { retries++; -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_SENDSIZE , - msg_len, si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_SENDSIZE , + msg_len, channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {/* Expected success. Give up. */
@@ -329,7 +304,7 @@ STACK_FRAME_NON_STANDARD(vmw_send_msg);static int vmw_recv_msg (struct rpc_channel *channel,void **msg,size_t *msg_len) { -unsigned long eax, ebx, ecx, edx, si, di; +u32 ebx, ecx, edx;char *reply;size_t reply_len;int retries =0 ;
@@ -341,15 +316,11 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,while (retries <RETRIES ) { retries++; -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_RECVSIZE , -0 , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall7 (VMW_PORT_CMD_RECVSIZE , +0 , channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {DRM_ERROR ("Failed to get reply size for host message.\n" );
@@ -384,16 +355,12 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg, reply[reply_len] ='\0' ; - -/* Ack buffer */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_RECVSTATUS , -MESSAGE_STATUS_SUCCESS , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_RECVSTATUS , +MESSAGE_STATUS_SUCCESS , + channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {kfree (reply);
@@ -652,13 +619,7 @@ static inline void reset_ppn_array(PPN64 *arr, size_t size)*/ static inline void hypervisor_ppn_reset_all (void ) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_RESET , -0 , si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_RESET ,0 ); }/**
@@ -669,13 +630,7 @@ static inline void hypervisor_ppn_reset_all(void)*/ static inline void hypervisor_ppn_add (PPN64 pfn) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_ADD_PPN , - (unsigned long )pfn, si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_ADD_PPN , (unsigned long )pfn); }/**
@@ -686,13 +641,7 @@ static inline void hypervisor_ppn_add(PPN64 pfn)*/ static inline void hypervisor_ppn_remove (PPN64 pfn) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_REMOVE_PPN , - (unsigned long )pfn, si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_REMOVE_PPN , (unsigned long )pfn); }#if IS_ENABLED (CONFIG_DRM_VMWGFX_MKSSTATS )
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h +136 -61
228 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +0 -185
191 lines not on this page · raw message
Signature · 1 line
2.39.0
Borislav Petkov
maintainerRe: [PATCH v2 5/6] drm/vmwgfx: Use vmware_hypercall API
Quoted 8 lines · Alexey Makhalov
Switch from
VMWARE_HYPERCALLmacro tovmware_hypercallAPI. Eliminate arch specific code.
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant ofvmware_hypercallhere for now. The move of these functions toarch/arm64/include/asm/vmware.has well as removal ofdrivers/gpu/drm/vmwgfx/vmwgfx_msg_{x86,arm64}.hheader files will be performed in the follow up patchset.
Same note as for patch 1 - no commit order in git.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteAlexey Makhalov
maintainerRe: [PATCH v2 5/6] drm/vmwgfx: Use vmware_hypercall API
Quoted 4 lines · Borislav Petkov
Quoted 3 lines · Alexey Makhalov
Switch from
VMWARE_HYPERCALLmacro tovmware_hypercallAPI. Eliminate arch specific code.
Quoted 8 lines
Quoted 5 lines
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant ofvmware_hypercallhere for now. The move of these functions toarch/arm64/include/asm/vmware.has well as removal ofdrivers/gpu/drm/vmwgfx/vmwgfx_msg_{x86,arm64}.hheader files will be performed in the follow up patchset.Same note as for patch 1 - no commit order in git.
Thanks for the review Borislav. I'll address your comments regarding description messages in v3. It is going to be sent from @broadcom.com and may take some time to align with corporate legal stuff.
--Alexey
Signature · 1 line
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
PATCH v2 6/6 x86/vmware: Add TDX hypercall support
In reply to Alexey MakhalovVMware 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.
--- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 9 +++++ 2 files changed, 81 insertions(+)
arch/x86/include/asm/vmware.h +72 -0
@@ -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),
arch/x86/kernel/cpu/vmware.c +9 -0
@@ -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)
Signature · 1 line
2.39.0
Borislav Petkov
maintainerRe: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
arch/x86/kernel/cpu/vmware.c static bool __init vmware_legacy_x2apic_available(void) · line 437
Quoted 7 lines · Alexey Makhalov
arch/x86/kernel/cpu/vmware.c +7
-0+#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);
Uuuh, lovely. I'd like to see what the TDX folks think about this export first.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
Quoted 10 lines · Borislav Petkov
arch/x86/kernel/cpu/vmware.c static bool __init vmware_legacy_x2apic_available(void) · line 437
Quoted 7 lines · Alexey Makhalov
arch/x86/kernel/cpu/vmware.c +7
-0+#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);Uuuh, lovely. I'd like to see what the TDX folks think about this export first.
I don't really like it much. This does a generic thing (make a TDX hypercall) with a specific name ("vmware_"). If you want to make an argument that a certain chunk of the __tdx_hypercall() space is just for VMWare and you also add a VMWare-specific check and then export *that*, it might be acceptable.
But I don't want random modules able to make random, unrestricted TDX hypercalls. That's asking for trouble.
Alexey Makhalov
maintainerRe: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
Quoted 12 lines · Dave Hansen
Quoted 10 lines · Borislav Petkov
arch/x86/kernel/cpu/vmware.c static bool __init vmware_legacy_x2apic_available(void) · line 437
Quoted 7 lines · Alexey Makhalov
arch/x86/kernel/cpu/vmware.c +7
-0+#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);Uuuh, lovely. I'd like to see what the TDX folks think about this export first.
Quoted 8 lines
I don't really like it much. This does a generic thing (make a TDX hypercall) with a specific name ("
vmware_"). If you want to make an argument that a certain chunk of the__tdx_hypercall()space is just for VMWare and you also add a VMWare-specific check and then export *that*, it might be acceptable.But I don't want random modules able to make random, unrestricted TDX hypercalls. That's asking for trouble.
Considering exporting of __tdx_hypercall for random modules is not an option, what VMware specific checks you are suggesting?
Signature · 1 line
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
Re: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
Hi Dave and Alexey,
Regarding VMware-specific checks, it may be beneficial to add some additional checks
such as ensuring that the hypervisor vendor is VMware, r12==VMWARE_HYPERVISOR_MAGIC,
r10==VMWARE_TDX_VENDOR_LEAF, r11==VMWARE_TDX_HCALL_FUNC and r13 (command) is restricted to those few commands we expect to be invoked from the kernel or drivers by VMware-specific
code.
If we add these checks, would folks be OK with exporting this function?
Quoted 40 lines · Alexey Makhalov
Quoted 12 lines · Dave Hansen
Quoted 10 lines · Borislav Petkov
arch/x86/kernel/cpu/vmware.c static bool __init vmware_legacy_x2apic_available(void) · line 437
Quoted 7 lines · Alexey Makhalov
arch/x86/kernel/cpu/vmware.c +7
-0+#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);Uuuh, lovely. I'd like to see what the TDX folks think about this export first.
Quoted 8 lines
I don't really like it much. This does a generic thing (make a TDX hypercall) with a specific name ("
vmware_"). If you want to make an argument that a certain chunk of the__tdx_hypercall()space is just for VMWare and you also add a VMWare-specific check and then export *that*, it might be acceptable.But I don't want random modules able to make random, unrestricted TDX hypercalls. That's asking for trouble.
Considering exporting of
__tdx_hypercallfor random modules is not an option, what VMware specific checks you are suggesting?--
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
Signature · 11 lines
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
Re: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
In reply to Alexey MakhalovQuoted 11 lines · Alexey Makhalov
Quoted 8 lines
I don't really like it much. This does a generic thing (make a TDX hypercall) with a specific name ("vmware_"). If you want to make an argument that a certain chunk of the
__tdx_hypercall()space is just for VMWare and you also add a VMWare-specific check and then export *that*, it might be acceptable.But I don't want random modules able to make random, unrestricted TDX hypercalls. That's asking for trouble.
Considering exporting of
__tdx_hypercallfor random modules is not an option, what VMware specific checks you are suggesting?
Make sure it can only be called running on VMWare guests. A check for X86_HYPER_VMWARE seems simple enough.
Second, unless the space is *HUGE*, you want to be exporting things like __vmware_platform() or vmware_legacy_x2apic_available(), *NOT* the underlying hypercall functions.
We want to make sure that the interfaces are well defined and bounded.
Alexey Makhalov
maintainerRe: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
Quoted 13 lines · Dave Hansen
Quoted 11 lines · Alexey Makhalov
Quoted 8 lines
I don't really like it much. This does a generic thing (make a TDX hypercall) with a specific name ("vmware_"). If you want to make an argument that a certain chunk of the
__tdx_hypercall()space is just for VMWare and you also add a VMWare-specific check and then export *that*, it might be acceptable.But I don't want random modules able to make random, unrestricted TDX hypercalls. That's asking for trouble.
Considering exporting of
__tdx_hypercallfor random modules is not an option, what VMware specific checks you are suggesting?
Quoted 8 lines
Make sure it can only be called running on VMWare guests. A check for
X86_HYPER_VMWAREseems simple enough.Second, unless the space is *HUGE*, you want to be exporting things like
__vmware_platform()orvmware_legacy_x2apic_available(), *NOT* the underlying hypercall functions.We want to make sure that the interfaces are well defined and bounded.
Thanks Dave and Tim for your suggestions. I followed Dave recommendation to have a simple check for X86_HYPER_VMWARE.
Please review patch 6, which I'll send shortly.
Thanks,
--Alexey
Signature · 1 line
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
Alexey Makhalov
maintainerPATCH 1/1 x86/vmware: Add TDX hypercall support
From: Alexey Makhalov <[email protected]>
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.
--- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 10 +++++ 2 files changed, 82 insertions(+)
arch/x86/include/asm/vmware.h +72 -0
@@ -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),
arch/x86/kernel/cpu/vmware.c +10 -0
@@ -428,6 +428,16 @@ static bool __init vmware_legacy_x2apic_available(void) (eax &BIT (VCPU_LEGACY_X2APIC )); } +#ifdef CONFIG_INTEL_TDX_GUEST +/* Export tdx hypercall and allow it only for VMware guests. */ +void vmware_tdx_hypercall_args (struct tdx_module_args *args) +{ +if (hypervisor_is_type (X86_HYPER_VMWARE )) +__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)
Signature · 1 line
2.39.0
Re: [PATCH] x86/vmware: Add TDX hypercall support
arch/x86/kernel/cpu/vmware.c static bool __init vmware_legacy_x2apic_available(void) · line 439
Quoted 9 lines · Alexey Makhalov
arch/x86/kernel/cpu/vmware.c +9
-0+#ifdef CONFIG_INTEL_TDX_GUEST +/* Export tdx hypercall and allow it only for VMware guests. */ +void vmware_tdx_hypercall_args (struct tdx_module_args *args) +{ +if (hypervisor_is_type (X86_HYPER_VMWARE )) +__tdx_hypercall (args); +} +EXPORT_SYMBOL_GPL (vmware_tdx_hypercall_args); +#endif
I think this is still too generic. This still allows anything setting X86_HYPER_VMWARE to make any TDX hypercall.
I'd *much* rather you export something like vmware_tdx_hypercall() or even the high-level calls like hypervisor_ppn_reset_all(). The higher level and more specialized the interface, the less likely it is to be abused.
Alexey Makhalov
maintainerRe: [PATCH] x86/vmware: Add TDX hypercall support
Quoted 14 lines · Dave Hansen
arch/x86/kernel/cpu/vmware.c static bool __init vmware_legacy_x2apic_available(void) · line 439
Quoted 9 lines · Alexey Makhalov
arch/x86/kernel/cpu/vmware.c +9
-0+#ifdef CONFIG_INTEL_TDX_GUEST +/* Export tdx hypercall and allow it only for VMware guests. */ +void vmware_tdx_hypercall_args (struct tdx_module_args *args) +{ +if (hypervisor_is_type (X86_HYPER_VMWARE )) +__tdx_hypercall (args); +} +EXPORT_SYMBOL_GPL (vmware_tdx_hypercall_args); +#endif I think this is still too generic. This still allows anything setting
X86_HYPER_VMWAREto make any TDX hypercall.
Quoted 4 lines
I'd *much* rather you export something like
vmware_tdx_hypercall()or even the high-level calls likehypervisor_ppn_reset_all(). The higher level and more specialized the interface, the less likely it is to be abused.
Dave, I understood your point. Please take a look on the next version of the patch.
I export vmware_tdx_hypercall(), while vmware_tdx_hypercall_args() is a
static inline wrapper on top.
Most of the vmware hypercall logic plus sanity checks are now in exported function. While only input and output argument handling remains in the wrapper to allow compiler optimization for hypercalls with few argument. Exporting vmware_tdx_hypercall1, vmware_tdx_hypercall3, and so on is not an option either.
Regards,
--Alexey
Alexey Makhalov
maintainerPATCH 1/1 x86/vmware: Add TDX hypercall support
From: Alexey Makhalov <[email protected]>
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.
--- arch/x86/include/asm/vmware.h | 83 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 22 ++++++++++ 2 files changed, 105 insertions(+)
arch/x86/include/asm/vmware.h +83 -0
@@ -34,12 +34,65 @@#define VMWARE_CMD_GETHZ 45#define VMWARE_CMD_GETVCPU_INFO 68#define VMWARE_CMD_STEALCLOCK 91 +/* +* Hypercall command mask: +* bits[6:0] command, range [0, 127] +* bits[19:16] sub-command, range [0, 15] +*/ +#define VMWARE_CMD_MASK 0xf007fULL#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0)#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1)extern u8 vmware_hypercall_mode; +#define VMWARE_TDX_VENDOR_LEAF 0x1af7e4909ULL +#define VMWARE_TDX_HCALL_FUNC 1 + +extern unsigned long vmware_tdx_hypercall (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_args (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) +{ +unsigned long ret; + +struct tdx_module_args args = { + .r13 = cmd, + .rbx = in1, + .rdx = in3, + .rsi = in4, + .rdi = in5, + .r14 = in6, + }; + + ret =vmware_tdx_hypercall (&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 ret; +} +/* * 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 +120,11 @@ 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_args (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 +143,11 @@ 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_args (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 +167,11 @@ 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_args (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 +191,11 @@ 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_args (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 +218,11 @@ 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_args (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 +244,11 @@ 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_args (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),
arch/x86/kernel/cpu/vmware.c +22 -0
@@ -428,6 +428,28 @@ static bool __init vmware_legacy_x2apic_available(void) (eax &BIT (VCPU_LEGACY_X2APIC )); } +#ifdef CONFIG_INTEL_TDX_GUEST +unsigned long vmware_tdx_hypercall (struct tdx_module_args *args) +{ +if (!hypervisor_is_type (X86_HYPER_VMWARE )) +return 0 ; + +if (args->r13 & ~VMWARE_CMD_MASK ) { +pr_warn ("Out of range command %llx\n" , args->r13); +return 0 ; + } + + args->r10 =VMWARE_TDX_VENDOR_LEAF ; + args->r11 =VMWARE_TDX_HCALL_FUNC ; + args->r12 =VMWARE_HYPERVISOR_MAGIC ; + +__tdx_hypercall (args); + +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)
Signature · 1 line
2.39.0
kernel test robot
build botRe: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
In reply to Alexey Makhalovkernel test robot noticed the following build errors:
Hi Alexey,
kernel test robot noticed the following build errors:
[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on dtor-input/next dtor-input/for-linus linus/master v6.7-rc4 next-20231205] [cannot apply to tip/x86/vmware]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexey-Makhalov/x86-vmware-Move-common-macros-to-vmware-h/20231202-072821 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20231201232452.220355-7-amakhalov%40vmware.com patch subject: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support config: x86_64-buildonly-randconfig-003-20231203 (https://download.01.org/0day-ci/archive/20231206/[email protected]/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
In file included from drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h:38,
from drivers/gpu/drm/vmwgfx/vmwgfx_msg.c:37:
>> arch/x86/include/asm/vmware.h:46:46: warning: 'struct tdx_module_args' declared inside parameter list will not be visible outside of this definition or declaration
46 | extern void vmware_tdx_hypercall_args(struct tdx_module_args *args);
| ^~~~~~~~~~~~~~~
arch/x86/include/asm/vmware.h: In function 'vmware_tdx_hypercall':
>> arch/x86/include/asm/vmware.h:61:9: error: variable 'args' has initializer but incomplete type
61 | struct tdx_module_args args = {
| ^~~~~~~~~~~~~~~
>> arch/x86/include/asm/vmware.h:62:4: error: 'struct tdx_module_args' has no member named 'r10'
62 | .r10 = VMWARE_TDX_VENDOR_LEAF,
| ^~~
>> arch/x86/include/asm/vmware.h:43:32: warning: excess elements in struct initializer
43 | #define VMWARE_TDX_VENDOR_LEAF 0x1AF7E4909ULL
| ^~~~~~~~~~~~~~
arch/x86/include/asm/vmware.h:62:10: note: in expansion of macro 'VMWARE_TDX_VENDOR_LEAF'
62 | .r10 = VMWARE_TDX_VENDOR_LEAF,
| ^~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/vmware.h:43:32: note: (near initialization for 'args')
43 | #define VMWARE_TDX_VENDOR_LEAF 0x1AF7E4909ULL
| ^~~~~~~~~~~~~~
arch/x86/include/asm/vmware.h:62:10: note: in expansion of macro 'VMWARE_TDX_VENDOR_LEAF'
62 | .r10 = VMWARE_TDX_VENDOR_LEAF,
| ^~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/vmware.h:63:4: error: 'struct tdx_module_args' has no member named 'r11'
63 | .r11 = VMWARE_TDX_HCALL_FUNC,
| ^~~
arch/x86/include/asm/vmware.h:44:32: warning: excess elements in struct initializer
44 | #define VMWARE_TDX_HCALL_FUNC 1
| ^
arch/x86/include/asm/vmware.h:63:10: note: in expansion of macro 'VMWARE_TDX_HCALL_FUNC'
63 | .r11 = VMWARE_TDX_HCALL_FUNC,
| ^~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/vmware.h:44:32: note: (near initialization for 'args')
44 | #define VMWARE_TDX_HCALL_FUNC 1
| ^
arch/x86/include/asm/vmware.h:63:10: note: in expansion of macro 'VMWARE_TDX_HCALL_FUNC'
63 | .r11 = VMWARE_TDX_HCALL_FUNC,
| ^~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/vmware.h:64:4: error: 'struct tdx_module_args' has no member named 'r12'
64 | .r12 = VMWARE_HYPERVISOR_MAGIC,
| ^~~
arch/x86/include/asm/vmware.h:31:34: warning: excess elements in struct initializer
31 | #define VMWARE_HYPERVISOR_MAGIC 0x564D5868U
| ^~~~~~~~~~~
arch/x86/include/asm/vmware.h:64:10: note: in expansion of macro 'VMWARE_HYPERVISOR_MAGIC'
64 | .r12 = VMWARE_HYPERVISOR_MAGIC,
| ^~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/vmware.h:31:34: note: (near initialization for 'args')
31 | #define VMWARE_HYPERVISOR_MAGIC 0x564D5868U
| ^~~~~~~~~~~
arch/x86/include/asm/vmware.h:64:10: note: in expansion of macro 'VMWARE_HYPERVISOR_MAGIC'
64 | .r12 = VMWARE_HYPERVISOR_MAGIC,
| ^~~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/vmware.h:65:4: error: 'struct tdx_module_args' has no member named 'r13'
65 | .r13 = cmd,
| ^~~
arch/x86/include/asm/vmware.h:65:10: warning: excess elements in struct initializer
65 | .r13 = cmd,
| ^~~
arch/x86/include/asm/vmware.h:65:10: note: (near initialization for 'args')
>> arch/x86/include/asm/vmware.h:66:4: error: 'struct tdx_module_args' has no member named 'rbx'
66 | .rbx = in1,
| ^~~
arch/x86/include/asm/vmware.h:66:10: warning: excess elements in struct initializer
66 | .rbx = in1,
| ^~~
arch/x86/include/asm/vmware.h:66:10: note: (near initialization for 'args')
>> arch/x86/include/asm/vmware.h:67:4: error: 'struct tdx_module_args' has no member named 'rdx'
67 | .rdx = in3,
| ^~~
arch/x86/include/asm/vmware.h:67:10: warning: excess elements in struct initializer
67 | .rdx = in3,
| ^~~
arch/x86/include/asm/vmware.h:67:10: note: (near initialization for 'args')
>> arch/x86/include/asm/vmware.h:68:4: error: 'struct tdx_module_args' has no member named 'rsi'
68 | .rsi = in4,
| ^~~
arch/x86/include/asm/vmware.h:68:10: warning: excess elements in struct initializer
68 | .rsi = in4,
| ^~~
arch/x86/include/asm/vmware.h:68:10: note: (near initialization for 'args')
>> arch/x86/include/asm/vmware.h:69:4: error: 'struct tdx_module_args' has no member named 'rdi'
69 | .rdi = in5,
| ^~~
arch/x86/include/asm/vmware.h:69:10: warning: excess elements in struct initializer
69 | .rdi = in5,
| ^~~
arch/x86/include/asm/vmware.h:69:10: note: (near initialization for 'args')
>> arch/x86/include/asm/vmware.h:70:4: error: 'struct tdx_module_args' has no member named 'r14'
70 | .r14 = in6,
| ^~~
arch/x86/include/asm/vmware.h:70:10: warning: excess elements in struct initializer
70 | .r14 = in6,
| ^~~
arch/x86/include/asm/vmware.h:70:10: note: (near initialization for 'args')
>> arch/x86/include/asm/vmware.h:61:25: error: storage size of 'args' isn't known
61 | struct tdx_module_args args = {
| ^~~~
>> arch/x86/include/asm/vmware.h:61:25: warning: unused variable 'args' [-Wunused-variable]vim +/args +61 arch/x86/include/asm/vmware.h
42
> 43 #define VMWARE_TDX_VENDOR_LEAF 0x1AF7E4909ULL
44 #define VMWARE_TDX_HCALL_FUNC 1
45
> 46 extern void vmware_tdx_hypercall_args(struct tdx_module_args *args);
47
48 /*
49 * TDCALL[TDG.VP.VMCALL] uses rax (arg0) and rcx (arg2), while the use of
50 * rbp (arg6) is discouraged by the TDX specification. Therefore, we
51 * remap those registers to r12, r13 and r14, respectively.
52 */
53 static inline
54 unsigned long vmware_tdx_hypercall(unsigned long cmd, unsigned long in1,
55 unsigned long in3, unsigned long in4,
56 unsigned long in5, unsigned long in6,
57 uint32_t *out1, uint32_t *out2,
58 uint32_t *out3, uint32_t *out4,
59 uint32_t *out5, uint32_t *out6)
60 {
> 61 struct tdx_module_args args = {
> 62 .r10 = VMWARE_TDX_VENDOR_LEAF,
> 63 .r11 = VMWARE_TDX_HCALL_FUNC,
> 64 .r12 = VMWARE_HYPERVISOR_MAGIC,
> 65 .r13 = cmd,
> 66 .rbx = in1,
> 67 .rdx = in3,
> 68 .rsi = in4,
> 69 .rdi = in5,
> 70 .r14 = in6,
71 };
72
73 vmware_tdx_hypercall_args(&args);
74
75 if (out1)
76 *out1 = args.rbx;
77 if (out2)
78 *out2 = args.r13;
79 if (out3)
80 *out3 = args.rdx;
81 if (out4)
82 *out4 = args.rsi;
83 if (out5)
84 *out5 = args.rdi;
85 if (out6)
86 *out6 = args.r14;
87
88 return args.r12;
89 }
90 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support
In reply to Alexey Makhalovkernel test robot noticed the following build errors:
Hi Alexey,
kernel test robot noticed the following build errors:
[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on dtor-input/next dtor-input/for-linus linus/master v6.7-rc4 next-20231205] [cannot apply to tip/x86/vmware]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexey-Makhalov/x86-vmware-Move-common-macros-to-vmware-h/20231202-072821 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20231201232452.220355-7-amakhalov%40vmware.com patch subject: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support config: i386-buildonly-randconfig-005-20231202 (https://download.01.org/0day-ci/archive/20231206/[email protected]/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
In file included from drivers/gpu/drm/vmwgfx/vmwgfx_msg.c:37:
In file included from drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h:38:
>> arch/x86/include/asm/vmware.h:46:46: warning: declaration of 'struct tdx_module_args' will not be visible outside of this function [-Wvisibility]
extern void vmware_tdx_hypercall_args(struct tdx_module_args *args);
^
>> arch/x86/include/asm/vmware.h:61:25: error: variable has incomplete type 'struct tdx_module_args'
struct tdx_module_args args = {
^
arch/x86/include/asm/vmware.h:61:9: note: forward declaration of 'struct tdx_module_args'
struct tdx_module_args args = {
^1 warning and 1 error generated.
vim +61 arch/x86/include/asm/vmware.h
45
> 46 extern void vmware_tdx_hypercall_args(struct tdx_module_args *args);
47
48 /*
49 * TDCALL[TDG.VP.VMCALL] uses rax (arg0) and rcx (arg2), while the use of
50 * rbp (arg6) is discouraged by the TDX specification. Therefore, we
51 * remap those registers to r12, r13 and r14, respectively.
52 */
53 static inline
54 unsigned long vmware_tdx_hypercall(unsigned long cmd, unsigned long in1,
55 unsigned long in3, unsigned long in4,
56 unsigned long in5, unsigned long in6,
57 uint32_t *out1, uint32_t *out2,
58 uint32_t *out3, uint32_t *out4,
59 uint32_t *out5, uint32_t *out6)
60 {
> 61 struct tdx_module_args args = {
62 .r10 = VMWARE_TDX_VENDOR_LEAF,
63 .r11 = VMWARE_TDX_HCALL_FUNC,
64 .r12 = VMWARE_HYPERVISOR_MAGIC,
65 .r13 = cmd,
66 .rbx = in1,
67 .rdx = in3,
68 .rsi = in4,
69 .rdi = in5,
70 .r14 = in6,
71 };
72
73 vmware_tdx_hypercall_args(&args);
74
75 if (out1)
76 *out1 = args.rbx;
77 if (out2)
78 *out2 = args.r13;
79 if (out3)
80 *out3 = args.rdx;
81 if (out4)
82 *out4 = args.rsi;
83 if (out5)
84 *out5 = args.rdi;
85 if (out6)
86 *out6 = args.r14;
87
88 return args.r12;
89 }
90 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 4/6 input/vmmouse: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended.
--- drivers/input/mouse/vmmouse.c | 76 ++++++++++------------------------- 1 file changed, 22 insertions(+), 54 deletions(-)
drivers/input/mouse/vmmouse.c +22 -54
@@ -21,19 +21,16 @@#include "psmouse.h" #include "vmmouse.h" -#define VMMOUSE_PROTO_MAGIC 0x564D5868U -/* * Main commands supported by the vmmouse hypervisor port. */ -#define VMMOUSE_PROTO_CMD_GETVERSION 10 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_DATA 39 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_STATUS 40 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND 41 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_RESTRICT 86 +#define VMWARE_CMD_ABSPOINTER_DATA 39 +#define VMWARE_CMD_ABSPOINTER_STATUS 40 +#define VMWARE_CMD_ABSPOINTER_COMMAND 41 +#define VMWARE_CMD_ABSPOINTER_RESTRICT 86/* -* Subcommands for VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND +* Subcommands for VMWARE_CMD_ABSPOINTER_COMMAND */ #define VMMOUSE_CMD_ENABLE 0x45414552U#define VMMOUSE_CMD_DISABLE 0x000000f5U
@@ -76,28 +73,6 @@ struct vmmouse_data {char dev_name[128 ]; }; -/* -* Hypervisor-specific bi-directional communication channel -* implementing the vmmouse protocol. Should never execute on -* bare metal hardware. -*/ -#define VMMOUSE_CMD (cmd, in1, out1, out2, out3, out4) \ -({ \ - unsigned long __dummy1, __dummy2; \ - __asm__ __volatile__ (VMWARE_HYPERCALL : \ - "=a"(out1), \ - "=b"(out2), \ - "=c"(out3), \ - "=d"(out4), \ - "=S"(__dummy1), \ - "=D"(__dummy2) : \ - "a"(VMMOUSE_PROTO_MAGIC), \ - "b"(in1), \ - "c"(VMMOUSE_PROTO_CMD_##cmd), \ - "d"(0) : \ - "memory"); \ -}) -/** * vmmouse_report_button - report button state on the correct input device *
@@ -145,14 +120,12 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse)struct input_dev *abs_dev = priv->abs_dev;struct input_dev *pref_dev;u32 status, x, y, z; -u32 dummy1, dummy2, dummy3;unsigned int queue_length;unsigned int count =255 ;while (count--) {/* See if we have motion data. */ -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , - status, dummy1, dummy2, dummy3); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &VMMOUSE_ERROR ) ==VMMOUSE_ERROR ) {psmouse_err (psmouse,"failed to fetch status data\n" );/*
@@ -172,7 +145,8 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse) }/* Now get it */ -VMMOUSE_CMD (ABSPOINTER_DATA ,4 , status, x, y, z); + status =vmware_hypercall4 (VMWARE_CMD_ABSPOINTER_DATA ,4 , + &x, &y, &z);/* * And report what we've got. Prefer to report button
@@ -247,14 +221,10 @@ static psmouse_ret_t vmmouse_process_byte(struct psmouse *psmouse)static void vmmouse_disable (struct psmouse *psmouse) {u32 status; -u32 dummy1, dummy2, dummy3, dummy4; - -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_DISABLE , - dummy1, dummy2, dummy3, dummy4); -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , - status, dummy1, dummy2, dummy3); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND ,VMMOUSE_CMD_DISABLE ); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &VMMOUSE_ERROR ) !=VMMOUSE_ERROR )psmouse_warn (psmouse,"failed to disable vmmouse device\n" ); }
@@ -271,26 +241,24 @@ static void vmmouse_disable(struct psmouse *psmouse)static int vmmouse_enable (struct psmouse *psmouse) {u32 status, version; -u32 dummy1, dummy2, dummy3, dummy4;/* * Try enabling the device. If successful, we should be able to * read valid version ID back from it. */ -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_ENABLE , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND ,VMMOUSE_CMD_ENABLE );/* * See if version ID can be retrieved. */ -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , status, dummy1, dummy2, dummy3); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &0x0000ffff ) ==0 ) {psmouse_dbg (psmouse,"empty flags - assuming no device\n" );return -ENXIO ; } -VMMOUSE_CMD (ABSPOINTER_DATA ,1 /* single item */ , - version, dummy1, dummy2, dummy3); + version =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_DATA , +1 /* single item */ );if (version !=VMMOUSE_VERSION_ID ) {psmouse_dbg (psmouse,"Unexpected version value: %u vs %u\n" , (unsigned ) version,VMMOUSE_VERSION_ID );
@@ -301,11 +269,11 @@ static int vmmouse_enable(struct psmouse *psmouse)/* * Restrict ioport access, if possible. */ -VMMOUSE_CMD (ABSPOINTER_RESTRICT ,VMMOUSE_RESTRICT_CPL0 , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_RESTRICT , +VMMOUSE_RESTRICT_CPL0 ); -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_REQUEST_ABSOLUTE , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND , +VMMOUSE_CMD_REQUEST_ABSOLUTE );return 0 ; }
@@ -342,7 +310,7 @@ static bool vmmouse_check_hypervisor(void)*/ int vmmouse_detect (struct psmouse *psmouse,bool set_properties) { -u32 response, version, dummy1, dummy2; +u32 response, version, type;if (!vmmouse_check_hypervisor ()) { psmouse_dbg(psmouse,
@@ -351,9 +319,9 @@ int vmmouse_detect(struct psmouse *psmouse, bool set_properties) }/* Check if the device is present */ - response = ~VMMOUSE_PROTO_MAGIC ; -VMMOUSE_CMD (GETVERSION ,0 , version, response, dummy1, dummy2); -if (response !=VMMOUSE_PROTO_MAGIC || version ==0xffffffffU ) + response = ~VMWARE_HYPERVISOR_MAGIC ; + version =vmware_hypercall3 (VMWARE_CMD_GETVERSION ,0 , &response, &type); +if (response !=VMWARE_HYPERVISOR_MAGIC || version ==0xffffffffU )return -ENXIO ;if (set_properties) {
Signature · 1 line
2.39.0
Simon Horman
reviewerRe: [PATCH 4/6] input/vmmouse: Use vmware_hypercall API
Quoted 4 lines · Alexey Makhalov
Switch from
VMWARE_HYPERCALLmacro tovmware_hypercallAPI. Eliminate arch specific code. No functional changes intended.Signed-off-by Alexey Makhalov <[email protected]>
Hi Alexey,
it is not strictly related to this patch, but I notice than an x86_64 allmodconfig build with W=1 using gcc-13 fails to compile this file.
It appears that the problem relates to both priv->phys and psmouse->ps2dev.serio->phys being 32 bytes.
drivers/input/mouse/vmmouse.c: In function ‘vmmouse_init’:drivers/input/mouse/vmmouse.c:455:53: error: ‘/input1’ directive output may be truncated writing 7 bytes into a region of size between 1 and 32 [-Werror=format-truncation=]
455 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1",
| ^~~~~~~drivers/input/mouse/vmmouse.c:455:9: note: ‘snprintf’ output between 8 and 39 bytes into a destination of size 32
455 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456 | psmouse->ps2dev.serio->phys);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
Re: [PATCH 4/6] input/vmmouse: Use vmware_hypercall API
Quoted 21 lines · Simon Horman
Quoted 4 lines · Alexey Makhalov
Switch from
VMWARE_HYPERCALLmacro tovmware_hypercallAPI. Eliminate arch specific code. No functional changes intended.Signed-off-by Alexey Makhalov <[email protected]>Hi Alexey,
it is not strictly related to this patch, but I notice than an
x86_64allmodconfig build with W=1 using gcc-13 fails to compile this file.It appears that the problem relates to both
priv->physandpsmouse->ps2dev.serio->physbeing 32 bytes.
drivers/input/mouse/vmmouse.c: In function ‘vmmouse_init’:drivers/input/mouse/vmmouse.c:455:53: error: ‘/input1’ directive output may be truncated writing 7 bytes into a region of size between 1 and 32 [-Werror=format-truncation=]
455 | snprintf(priv->phys,sizeof(priv->phys), "%s/input1",
| ^~~~~~~drivers/input/mouse/vmmouse.c:455:9: note: ‘snprintf’ output between 8 and 39 bytes into a destination of size 32
Quoted 6 lines
455 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 456 | psmouse->ps2dev.serio->phys); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
Hi Simon, thanks for reporting the issue.
Zack, please take a look.
—Alexey
[email protected]
maintainerRe: [PATCH 4/6] input/vmmouse: Use vmware_hypercall API
Quoted 27 lines · Alexey Makhalov
Quoted 26 lines · Simon Horman
Quoted 4 lines · Alexey Makhalov
Switch from
VMWARE_HYPERCALLmacro tovmware_hypercallAPI. Eliminate arch specific code. No functional changes intended.Signed-off-by Alexey Makhalov <[email protected]>Hi Alexey,
it is not strictly related to this patch, but I notice than an
x86_64allmodconfig build with W=1 using gcc-13 fails to compile this file.It appears that the problem relates to both
priv->physandpsmouse->ps2dev.serio->physbeing 32 bytes.
drivers/input/mouse/vmmouse.c: In function ‘vmmouse_init’:drivers/input/mouse/vmmouse.c:455:53: error: ‘/input1’ directive output may be truncated writing 7 bytes into a region of size between 1 and 32 [-Werror=format-truncation=]
455 | snprintf(priv->phys,sizeof(priv->phys), "%s/input1",
| ^~~~~~~drivers/input/mouse/vmmouse.c:455:9: note: ‘snprintf’ output between 8 and 39 bytes into a destination of size 32455 | snprintf(priv->phys, sizeof(priv->phys), "%s/input1", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 456 | psmouse->ps2dev.serio->phys); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines
Quoted 1 line
...
Hi Simon, thanks for reporting the issue.
Zack, please take a look.
We want the truncation behavior and we do not want GCC to make noise about these, that is why "format-truncation" is explicitly disabled for normal compiles. I guess we should exclude it even when we compile with W=1 instead of doing pointless changes in the drivers.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 4/6] input/vmmouse: Use vmware_hypercall API
In reply to Alexey MakhalovQuoted 4 lines · Alexey Makhalov
Switch from
VMWARE_HYPERCALLmacro tovmware_hypercallAPI. Eliminate arch specific code. No functional changes intended.Signed-off-by Alexey Makhalov <[email protected]>
Please feel free to merge with the rest of the series.
Thanks.
Signature · 1 line
Dmitry
PATCH 4/6 input/vmmouse: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended.
--- drivers/input/mouse/vmmouse.c | 76 ++++++++++------------------------- 1 file changed, 22 insertions(+), 54 deletions(-)
drivers/input/mouse/vmmouse.c +22 -54
@@ -21,19 +21,16 @@#include "psmouse.h" #include "vmmouse.h" -#define VMMOUSE_PROTO_MAGIC 0x564D5868U -/* * Main commands supported by the vmmouse hypervisor port. */ -#define VMMOUSE_PROTO_CMD_GETVERSION 10 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_DATA 39 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_STATUS 40 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND 41 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_RESTRICT 86 +#define VMWARE_CMD_ABSPOINTER_DATA 39 +#define VMWARE_CMD_ABSPOINTER_STATUS 40 +#define VMWARE_CMD_ABSPOINTER_COMMAND 41 +#define VMWARE_CMD_ABSPOINTER_RESTRICT 86/* -* Subcommands for VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND +* Subcommands for VMWARE_CMD_ABSPOINTER_COMMAND */ #define VMMOUSE_CMD_ENABLE 0x45414552U#define VMMOUSE_CMD_DISABLE 0x000000f5U
@@ -76,28 +73,6 @@ struct vmmouse_data {char dev_name[128 ]; }; -/* -* Hypervisor-specific bi-directional communication channel -* implementing the vmmouse protocol. Should never execute on -* bare metal hardware. -*/ -#define VMMOUSE_CMD (cmd, in1, out1, out2, out3, out4) \ -({ \ - unsigned long __dummy1, __dummy2; \ - __asm__ __volatile__ (VMWARE_HYPERCALL : \ - "=a"(out1), \ - "=b"(out2), \ - "=c"(out3), \ - "=d"(out4), \ - "=S"(__dummy1), \ - "=D"(__dummy2) : \ - "a"(VMMOUSE_PROTO_MAGIC), \ - "b"(in1), \ - "c"(VMMOUSE_PROTO_CMD_##cmd), \ - "d"(0) : \ - "memory"); \ -}) -/** * vmmouse_report_button - report button state on the correct input device *
@@ -145,14 +120,12 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse)struct input_dev *abs_dev = priv->abs_dev;struct input_dev *pref_dev;u32 status, x, y, z; -u32 dummy1, dummy2, dummy3;unsigned int queue_length;unsigned int count =255 ;while (count--) {/* See if we have motion data. */ -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , - status, dummy1, dummy2, dummy3); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &VMMOUSE_ERROR ) ==VMMOUSE_ERROR ) {psmouse_err (psmouse,"failed to fetch status data\n" );/*
@@ -172,7 +145,8 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse) }/* Now get it */ -VMMOUSE_CMD (ABSPOINTER_DATA ,4 , status, x, y, z); + status =vmware_hypercall4 (VMWARE_CMD_ABSPOINTER_DATA ,4 , + &x, &y, &z);/* * And report what we've got. Prefer to report button
@@ -247,14 +221,10 @@ static psmouse_ret_t vmmouse_process_byte(struct psmouse *psmouse)static void vmmouse_disable (struct psmouse *psmouse) {u32 status; -u32 dummy1, dummy2, dummy3, dummy4; - -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_DISABLE , - dummy1, dummy2, dummy3, dummy4); -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , - status, dummy1, dummy2, dummy3); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND ,VMMOUSE_CMD_DISABLE ); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &VMMOUSE_ERROR ) !=VMMOUSE_ERROR )psmouse_warn (psmouse,"failed to disable vmmouse device\n" ); }
@@ -271,26 +241,24 @@ static void vmmouse_disable(struct psmouse *psmouse)static int vmmouse_enable (struct psmouse *psmouse) {u32 status, version; -u32 dummy1, dummy2, dummy3, dummy4;/* * Try enabling the device. If successful, we should be able to * read valid version ID back from it. */ -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_ENABLE , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND ,VMMOUSE_CMD_ENABLE );/* * See if version ID can be retrieved. */ -VMMOUSE_CMD (ABSPOINTER_STATUS ,0 , status, dummy1, dummy2, dummy3); + status =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_STATUS ,0 );if ((status &0x0000ffff ) ==0 ) {psmouse_dbg (psmouse,"empty flags - assuming no device\n" );return -ENXIO ; } -VMMOUSE_CMD (ABSPOINTER_DATA ,1 /* single item */ , - version, dummy1, dummy2, dummy3); + version =vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_DATA , +1 /* single item */ );if (version !=VMMOUSE_VERSION_ID ) {psmouse_dbg (psmouse,"Unexpected version value: %u vs %u\n" , (unsigned ) version,VMMOUSE_VERSION_ID );
@@ -301,11 +269,11 @@ static int vmmouse_enable(struct psmouse *psmouse)/* * Restrict ioport access, if possible. */ -VMMOUSE_CMD (ABSPOINTER_RESTRICT ,VMMOUSE_RESTRICT_CPL0 , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_RESTRICT , +VMMOUSE_RESTRICT_CPL0 ); -VMMOUSE_CMD (ABSPOINTER_COMMAND ,VMMOUSE_CMD_REQUEST_ABSOLUTE , - dummy1, dummy2, dummy3, dummy4); +vmware_hypercall1 (VMWARE_CMD_ABSPOINTER_COMMAND , +VMMOUSE_CMD_REQUEST_ABSOLUTE );return 0 ; }
@@ -342,7 +310,7 @@ static bool vmmouse_check_hypervisor(void)*/ int vmmouse_detect (struct psmouse *psmouse,bool set_properties) { -u32 response, version, dummy1, dummy2; +u32 response, version, type;if (!vmmouse_check_hypervisor ()) { psmouse_dbg(psmouse,
@@ -351,9 +319,9 @@ int vmmouse_detect(struct psmouse *psmouse, bool set_properties) }/* Check if the device is present */ - response = ~VMMOUSE_PROTO_MAGIC ; -VMMOUSE_CMD (GETVERSION ,0 , version, response, dummy1, dummy2); -if (response !=VMMOUSE_PROTO_MAGIC || version ==0xffffffffU ) + response = ~VMWARE_HYPERVISOR_MAGIC ; + version =vmware_hypercall3 (VMWARE_CMD_GETVERSION ,0 , &response, &type); +if (response !=VMWARE_HYPERVISOR_MAGIC || version ==0xffffffffU )return -ENXIO ;if (set_properties) {
Signature · 1 line
2.39.0
PATCH 5/6 drm/vmwgfx: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code.
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant of vmware_hypercall here. To be moved to arch/arm64/include/asm/vmware.h later.
--- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 +++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++++++++------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 -------------------- 3 files changed, 197 insertions(+), 358 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +61 -112
@@ -48,8 +48,6 @@#define RETRIES 3 -#define VMW_HYPERVISOR_MAGIC 0x564D5868 -#define VMW_PORT_CMD_MSG 30#define VMW_PORT_CMD_HB_MSG 0#define VMW_PORT_CMD_OPEN_CHANNEL (MSG_TYPE_OPEN << 16 | VMW_PORT_CMD_MSG)
@@ -104,20 +102,18 @@ static const char* const mksstat_kern_name_desc[MKSSTAT_KERN_COUNT][2] =*/ static int vmw_open_channel (struct rpc_channel *channel,unsigned int protocol) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; +u32 ecx, edx, esi, edi; -VMW_PORT (VMW_PORT_CMD_OPEN_CHANNEL , - (protocol |GUESTMSG_FLAG_COOKIE ), si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall6 (VMW_PORT_CMD_OPEN_CHANNEL , + (protocol |GUESTMSG_FLAG_COOKIE ),0 , + &ecx, &edx, &esi, &edi);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )return -EINVAL ; channel->channel_id =HIGH_WORD (edx); - channel->cookie_high = si; - channel->cookie_low = di; + channel->cookie_high = esi; + channel->cookie_low = edi;return 0 ; }
@@ -133,17 +129,13 @@ static int vmw_open_channel(struct rpc_channel *channel, unsigned int protocol)*/ static int vmw_close_channel (struct rpc_channel *channel) { -unsigned long eax, ebx, ecx, edx, si, di; - -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; +u32 ecx; -VMW_PORT (VMW_PORT_CMD_CLOSE_CHANNEL , -0 , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_CLOSE_CHANNEL , +0 , channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )return -EINVAL ;
@@ -163,24 +155,18 @@ static int vmw_close_channel(struct rpc_channel *channel)static unsigned long vmw_port_hb_out (struct rpc_channel *channel,const char *msg,bool hb) { -unsigned long si, di, eax, ebx, ecx, edx; +u32 ebx, ecx;unsigned long msg_len =strlen (msg);/* HB port can't access encrypted memory. */ if (hb && !cc_platform_has (CC_ATTR_MEM_ENCRYPT )) { -unsigned long bp = channel->cookie_high; -u32 channel_id = (channel->channel_id <<16 ); - - si = (uintptr_t ) msg; - di = channel->cookie_low; - -VMW_PORT_HB_OUT ( +vmware_hypercall_hb_out ( (MESSAGE_STATUS_SUCCESS <<16 ) |VMW_PORT_CMD_HB_MSG , - msg_len, si, di, -VMWARE_HYPERVISOR_HB | channel_id | -VMWARE_HYPERVISOR_OUT , -VMW_HYPERVISOR_MAGIC , bp, - eax, ebx, ecx, edx, si, di); + msg_len, + channel->channel_id <<16 , + (uintptr_t ) msg, channel->cookie_low, + channel->cookie_high, + &ebx);return ebx; }
@@ -194,14 +180,13 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,memcpy (&word, msg, bytes); msg_len -= bytes; msg += bytes; - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_MSG | (MSG_TYPE_SENDPAYLOAD <<16 ), - word, si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); + +vmware_hypercall5 (VMW_PORT_CMD_MSG | + (MSG_TYPE_SENDPAYLOAD <<16 ), + word, channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx); }return ecx;
@@ -220,22 +205,17 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,static unsigned long vmw_port_hb_in (struct rpc_channel *channel,char *reply,unsigned long reply_len,bool hb) { -unsigned long si, di, eax, ebx, ecx, edx; +u32 ebx, ecx, edx;/* HB port can't access encrypted memory */ if (hb && !cc_platform_has (CC_ATTR_MEM_ENCRYPT )) { -unsigned long bp = channel->cookie_low; -u32 channel_id = (channel->channel_id <<16 ); - - si = channel->cookie_high; - di = (uintptr_t ) reply; - -VMW_PORT_HB_IN ( +vmware_hypercall_hb_in ( (MESSAGE_STATUS_SUCCESS <<16 ) |VMW_PORT_CMD_HB_MSG , - reply_len, si, di, -VMWARE_HYPERVISOR_HB | channel_id, -VMW_HYPERVISOR_MAGIC , bp, - eax, ebx, ecx, edx, si, di); + reply_len, + channel->channel_id <<16 , + channel->cookie_high, + (uintptr_t ) reply, channel->cookie_low, + &ebx);return ebx; }
@@ -245,14 +225,13 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,while (reply_len) { unsigned int bytes = min_t(unsigned long, reply_len, 4); - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_MSG | (MSG_TYPE_RECVPAYLOAD <<16 ), -MESSAGE_STATUS_SUCCESS , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall7 (VMW_PORT_CMD_MSG | + (MSG_TYPE_RECVPAYLOAD <<16 ), +MESSAGE_STATUS_SUCCESS , + channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )break ;
@@ -276,22 +255,18 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,*/ static int vmw_send_msg (struct rpc_channel *channel,const char *msg) { -unsigned long eax, ebx, ecx, edx, si, di; +u32 ebx, ecx;size_t msg_len =strlen (msg);int retries =0 ;while (retries <RETRIES ) { retries++; -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_SENDSIZE , - msg_len, si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_SENDSIZE , + msg_len, channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {/* Expected success. Give up. */
@@ -329,7 +304,7 @@ STACK_FRAME_NON_STANDARD(vmw_send_msg);static int vmw_recv_msg (struct rpc_channel *channel,void **msg,size_t *msg_len) { -unsigned long eax, ebx, ecx, edx, si, di; +u32 ebx, ecx, edx;char *reply;size_t reply_len;int retries =0 ;
@@ -341,15 +316,11 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,while (retries <RETRIES ) { retries++; -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_RECVSIZE , -0 , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall7 (VMW_PORT_CMD_RECVSIZE , +0 , channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {DRM_ERROR ("Failed to get reply size for host message.\n" );
@@ -384,16 +355,12 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg, reply[reply_len] ='\0' ; - -/* Ack buffer */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_RECVSTATUS , -MESSAGE_STATUS_SUCCESS , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_RECVSTATUS , +MESSAGE_STATUS_SUCCESS , + channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {kfree (reply);
@@ -652,13 +619,7 @@ static inline void reset_ppn_array(PPN64 *arr, size_t size)*/ static inline void hypervisor_ppn_reset_all (void ) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_RESET , -0 , si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_RESET ,0 ); }/**
@@ -669,13 +630,7 @@ static inline void hypervisor_ppn_reset_all(void)*/ static inline void hypervisor_ppn_add (PPN64 pfn) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_ADD_PPN , - (unsigned long )pfn, si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_ADD_PPN , (unsigned long )pfn); }/**
@@ -686,13 +641,7 @@ static inline void hypervisor_ppn_add(PPN64 pfn)*/ static inline void hypervisor_ppn_remove (PPN64 pfn) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_REMOVE_PPN , - (unsigned long )pfn, si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_REMOVE_PPN , (unsigned long )pfn); }#if IS_ENABLED (CONFIG_DRM_VMWGFX_MKSSTATS )
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h +136 -61
228 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +0 -185
191 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH 5/6 drm/vmwgfx: Use vmware_hypercall API
In reply to Alexey MakhalovSwitch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code.
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant of vmware_hypercall here. To be moved to arch/arm64/include/asm/vmware.h later.
--- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 +++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++++++++------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 -------------------- 3 files changed, 197 insertions(+), 358 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +61 -112
@@ -48,8 +48,6 @@#define RETRIES 3 -#define VMW_HYPERVISOR_MAGIC 0x564D5868 -#define VMW_PORT_CMD_MSG 30#define VMW_PORT_CMD_HB_MSG 0#define VMW_PORT_CMD_OPEN_CHANNEL (MSG_TYPE_OPEN << 16 | VMW_PORT_CMD_MSG)
@@ -104,20 +102,18 @@ static const char* const mksstat_kern_name_desc[MKSSTAT_KERN_COUNT][2] =*/ static int vmw_open_channel (struct rpc_channel *channel,unsigned int protocol) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; +u32 ecx, edx, esi, edi; -VMW_PORT (VMW_PORT_CMD_OPEN_CHANNEL , - (protocol |GUESTMSG_FLAG_COOKIE ), si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall6 (VMW_PORT_CMD_OPEN_CHANNEL , + (protocol |GUESTMSG_FLAG_COOKIE ),0 , + &ecx, &edx, &esi, &edi);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )return -EINVAL ; channel->channel_id =HIGH_WORD (edx); - channel->cookie_high = si; - channel->cookie_low = di; + channel->cookie_high = esi; + channel->cookie_low = edi;return 0 ; }
@@ -133,17 +129,13 @@ static int vmw_open_channel(struct rpc_channel *channel, unsigned int protocol)*/ static int vmw_close_channel (struct rpc_channel *channel) { -unsigned long eax, ebx, ecx, edx, si, di; - -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; +u32 ecx; -VMW_PORT (VMW_PORT_CMD_CLOSE_CHANNEL , -0 , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_CLOSE_CHANNEL , +0 , channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )return -EINVAL ;
@@ -163,24 +155,18 @@ static int vmw_close_channel(struct rpc_channel *channel)static unsigned long vmw_port_hb_out (struct rpc_channel *channel,const char *msg,bool hb) { -unsigned long si, di, eax, ebx, ecx, edx; +u32 ebx, ecx;unsigned long msg_len =strlen (msg);/* HB port can't access encrypted memory. */ if (hb && !cc_platform_has (CC_ATTR_MEM_ENCRYPT )) { -unsigned long bp = channel->cookie_high; -u32 channel_id = (channel->channel_id <<16 ); - - si = (uintptr_t ) msg; - di = channel->cookie_low; - -VMW_PORT_HB_OUT ( +vmware_hypercall_hb_out ( (MESSAGE_STATUS_SUCCESS <<16 ) |VMW_PORT_CMD_HB_MSG , - msg_len, si, di, -VMWARE_HYPERVISOR_HB | channel_id | -VMWARE_HYPERVISOR_OUT , -VMW_HYPERVISOR_MAGIC , bp, - eax, ebx, ecx, edx, si, di); + msg_len, + channel->channel_id <<16 , + (uintptr_t ) msg, channel->cookie_low, + channel->cookie_high, + &ebx);return ebx; }
@@ -194,14 +180,13 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,memcpy (&word, msg, bytes); msg_len -= bytes; msg += bytes; - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_MSG | (MSG_TYPE_SENDPAYLOAD <<16 ), - word, si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); + +vmware_hypercall5 (VMW_PORT_CMD_MSG | + (MSG_TYPE_SENDPAYLOAD <<16 ), + word, channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx); }return ecx;
@@ -220,22 +205,17 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,static unsigned long vmw_port_hb_in (struct rpc_channel *channel,char *reply,unsigned long reply_len,bool hb) { -unsigned long si, di, eax, ebx, ecx, edx; +u32 ebx, ecx, edx;/* HB port can't access encrypted memory */ if (hb && !cc_platform_has (CC_ATTR_MEM_ENCRYPT )) { -unsigned long bp = channel->cookie_low; -u32 channel_id = (channel->channel_id <<16 ); - - si = channel->cookie_high; - di = (uintptr_t ) reply; - -VMW_PORT_HB_IN ( +vmware_hypercall_hb_in ( (MESSAGE_STATUS_SUCCESS <<16 ) |VMW_PORT_CMD_HB_MSG , - reply_len, si, di, -VMWARE_HYPERVISOR_HB | channel_id, -VMW_HYPERVISOR_MAGIC , bp, - eax, ebx, ecx, edx, si, di); + reply_len, + channel->channel_id <<16 , + channel->cookie_high, + (uintptr_t ) reply, channel->cookie_low, + &ebx);return ebx; }
@@ -245,14 +225,13 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,while (reply_len) { unsigned int bytes = min_t(unsigned long, reply_len, 4); - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_MSG | (MSG_TYPE_RECVPAYLOAD <<16 ), -MESSAGE_STATUS_SUCCESS , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall7 (VMW_PORT_CMD_MSG | + (MSG_TYPE_RECVPAYLOAD <<16 ), +MESSAGE_STATUS_SUCCESS , + channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 )break ;
@@ -276,22 +255,18 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,*/ static int vmw_send_msg (struct rpc_channel *channel,const char *msg) { -unsigned long eax, ebx, ecx, edx, si, di; +u32 ebx, ecx;size_t msg_len =strlen (msg);int retries =0 ;while (retries <RETRIES ) { retries++; -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_SENDSIZE , - msg_len, si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_SENDSIZE , + msg_len, channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {/* Expected success. Give up. */
@@ -329,7 +304,7 @@ STACK_FRAME_NON_STANDARD(vmw_send_msg);static int vmw_recv_msg (struct rpc_channel *channel,void **msg,size_t *msg_len) { -unsigned long eax, ebx, ecx, edx, si, di; +u32 ebx, ecx, edx;char *reply;size_t reply_len;int retries =0 ;
@@ -341,15 +316,11 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg,while (retries <RETRIES ) { retries++; -/* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_RECVSIZE , -0 , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall7 (VMW_PORT_CMD_RECVSIZE , +0 , channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {DRM_ERROR ("Failed to get reply size for host message.\n" );
@@ -384,16 +355,12 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg, reply[reply_len] ='\0' ; - -/* Ack buffer */ - si = channel->cookie_high; - di = channel->cookie_low; - -VMW_PORT (VMW_PORT_CMD_RECVSTATUS , -MESSAGE_STATUS_SUCCESS , si, di, - channel->channel_id <<16 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall5 (VMW_PORT_CMD_RECVSTATUS , +MESSAGE_STATUS_SUCCESS , + channel->channel_id <<16 , + channel->cookie_high, + channel->cookie_low, + &ecx);if ((HIGH_WORD (ecx) &MESSAGE_STATUS_SUCCESS ) ==0 ) {kfree (reply);
@@ -652,13 +619,7 @@ static inline void reset_ppn_array(PPN64 *arr, size_t size)*/ static inline void hypervisor_ppn_reset_all (void ) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_RESET , -0 , si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_RESET ,0 ); }/**
@@ -669,13 +630,7 @@ static inline void hypervisor_ppn_reset_all(void)*/ static inline void hypervisor_ppn_add (PPN64 pfn) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_ADD_PPN , - (unsigned long )pfn, si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_ADD_PPN , (unsigned long )pfn); }/**
@@ -686,13 +641,7 @@ static inline void hypervisor_ppn_add(PPN64 pfn)*/ static inline void hypervisor_ppn_remove (PPN64 pfn) { -unsigned long eax, ebx, ecx, edx, si =0 , di =0 ; - -VMW_PORT (VMW_PORT_CMD_MKSGS_REMOVE_PPN , - (unsigned long )pfn, si, di, -0 , -VMW_HYPERVISOR_MAGIC , - eax, ebx, ecx, edx, si, di); +vmware_hypercall1 (VMW_PORT_CMD_MKSGS_REMOVE_PPN , (unsigned long )pfn); }#if IS_ENABLED (CONFIG_DRM_VMWGFX_MKSSTATS )
drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h +136 -61
228 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +0 -185
191 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH 6/6 x86/vmware: Add TDX hypercall support
In reply to Alexey MakhalovVMware 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.
--- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 9 +++++ 2 files changed, 81 insertions(+)
arch/x86/include/asm/vmware.h +72 -0
@@ -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),
arch/x86/kernel/cpu/vmware.c +9 -0
@@ -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)
Signature · 1 line
2.39.0
PATCH 6/6 x86/vmware: Add TDX hypercall support
In reply to Alexey MakhalovVMware 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.
--- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 9 +++++ 2 files changed, 81 insertions(+)
arch/x86/include/asm/vmware.h +72 -0
@@ -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),
arch/x86/kernel/cpu/vmware.c +9 -0
@@ -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)
Signature · 1 line
2.39.0