Skip to content

Commit b4dd4f6

Browse files
thomashvmwsuryasaimadhu
authored andcommitted
x86/vmware: Add a header file for hypercall definitions
The new header is intended to be used by drivers using the backdoor. Follow the KVM example using alternatives self-patching to choose between vmcall, vmmcall and io instructions. Also define two new CPU feature flags to indicate hypervisor support for vmcall- and vmmcall instructions. The new XF86_FEATURE_VMW_VMMCALL flag is needed because using XF86_FEATURE_VMMCALL might break QEMU/KVM setups using the vmmouse driver. They rely on XF86_FEATURE_VMMCALL on AMD to get the kvm_hypercall() right. But they do not yet implement vmmcall for the VMware hypercall used by the vmmouse driver. [ bp: reflow hypercall %edx usage explanation comment. ] Signed-off-by: Thomas Hellstrom <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Doug Covelli <[email protected]> Cc: Aaron Lewis <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: [email protected] Cc: Mauro Carvalho Chehab <[email protected]> Cc: Nicolas Ferre <[email protected]> Cc: Robert Hoo <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent bac7b4e commit b4dd4f6

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17206,6 +17206,7 @@ M: "VMware, Inc." <[email protected]>
1720617206
1720717207
S: Supported
1720817208
F: arch/x86/kernel/cpu/vmware.c
17209+
F: arch/x86/include/asm/vmware.h
1720917210

1721017211
VMWARE PVRDMA DRIVER
1721117212
M: Adit Ranadive <[email protected]>

arch/x86/include/asm/cpufeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@
232232
#define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer VMMCALL to VMCALL */
233233
#define X86_FEATURE_XENPV ( 8*32+16) /* "" Xen paravirtual guest */
234234
#define X86_FEATURE_EPT_AD ( 8*32+17) /* Intel Extended Page Table access-dirty bit */
235+
#define X86_FEATURE_VMCALL ( 8*32+18) /* "" Hypervisor supports the VMCALL instruction */
236+
#define X86_FEATURE_VMW_VMMCALL ( 8*32+19) /* "" VMware prefers VMMCALL hypercall instruction */
235237

236238
/* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */
237239
#define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/

arch/x86/include/asm/vmware.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* SPDX-License-Identifier: GPL-2.0 or MIT */
2+
#ifndef _ASM_X86_VMWARE_H
3+
#define _ASM_X86_VMWARE_H
4+
5+
#include <asm/cpufeatures.h>
6+
#include <asm/alternative.h>
7+
8+
/*
9+
* The hypercall definitions differ in the low word of the %edx argument
10+
* in the following way: the old port base interface uses the port
11+
* number to distinguish between high- and low bandwidth versions.
12+
*
13+
* The new vmcall interface instead uses a set of flags to select
14+
* bandwidth mode and transfer direction. The flags should be loaded
15+
* into %dx by any user and are automatically replaced by the port
16+
* number if the VMWARE_HYPERVISOR_PORT method is used.
17+
*
18+
* In short, new driver code should strictly use the new definition of
19+
* %dx content.
20+
*/
21+
22+
/* Old port-based version */
23+
#define VMWARE_HYPERVISOR_PORT "0x5658"
24+
#define VMWARE_HYPERVISOR_PORT_HB "0x5659"
25+
26+
/* Current vmcall / vmmcall version */
27+
#define VMWARE_HYPERVISOR_HB BIT(0)
28+
#define VMWARE_HYPERVISOR_OUT BIT(1)
29+
30+
/* The low bandwidth call. The low word of edx is presumed clear. */
31+
#define VMWARE_HYPERCALL \
32+
ALTERNATIVE_2("movw $" VMWARE_HYPERVISOR_PORT ", %%dx; inl (%%dx)", \
33+
"vmcall", X86_FEATURE_VMCALL, \
34+
"vmmcall", X86_FEATURE_VMW_VMMCALL)
35+
36+
/*
37+
* The high bandwidth out call. The low word of edx is presumed to have the
38+
* HB and OUT bits set.
39+
*/
40+
#define VMWARE_HYPERCALL_HB_OUT \
41+
ALTERNATIVE_2("movw $" VMWARE_HYPERVISOR_PORT_HB ", %%dx; rep outsb", \
42+
"vmcall", X86_FEATURE_VMCALL, \
43+
"vmmcall", X86_FEATURE_VMW_VMMCALL)
44+
45+
/*
46+
* The high bandwidth in call. The low word of edx is presumed to have the
47+
* HB bit set.
48+
*/
49+
#define VMWARE_HYPERCALL_HB_IN \
50+
ALTERNATIVE_2("movw $" VMWARE_HYPERVISOR_PORT_HB ", %%dx; rep insb", \
51+
"vmcall", X86_FEATURE_VMCALL, \
52+
"vmmcall", X86_FEATURE_VMW_VMMCALL)
53+
#endif

arch/x86/kernel/cpu/vmware.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <asm/hypervisor.h>
3131
#include <asm/timer.h>
3232
#include <asm/apic.h>
33+
#include <asm/vmware.h>
3334

3435
#undef pr_fmt
3536
#define pr_fmt(fmt) "vmware: " fmt
@@ -40,7 +41,6 @@
4041
#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1)
4142

4243
#define VMWARE_HYPERVISOR_MAGIC 0x564D5868
43-
#define VMWARE_HYPERVISOR_PORT 0x5658
4444

4545
#define VMWARE_CMD_GETVERSION 10
4646
#define VMWARE_CMD_GETHZ 45
@@ -164,6 +164,10 @@ static void __init vmware_set_capabilities(void)
164164
{
165165
setup_force_cpu_cap(X86_FEATURE_CONSTANT_TSC);
166166
setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
167+
if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMCALL)
168+
setup_force_cpu_cap(X86_FEATURE_VMCALL);
169+
else if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMMCALL)
170+
setup_force_cpu_cap(X86_FEATURE_VMW_VMMCALL);
167171
}
168172

169173
static void __init vmware_platform_setup(void)

0 commit comments

Comments
 (0)