[PATCH v3 02/12] KVM: x86: Move VMware backdoor support to separate files
From: Zack Rusin
Date: Wed Nov 11 2026 - 01:02:14 EST
Move the enable_vmware_backdoor module parameter, the VMware backdoor
port and pseudo-PMC definitions, and the VMware pseudo-PMC and opcode
helpers out of x86.c, emulate.c and pmu.{c,h} into new vmware.{c,h}
files, and add a MAINTAINERS entry for the new files.
KVM's VMware emulation is spread across the emulator, the PMU code and
x86.c, and both vendor modules read the module parameter directly. The
following patches make the VMware interfaces a per-VM setting, add a
userspace exit for VMware hypercalls and allow compiling the emulation
out. Collect the code in one place first, as KVM already does for
Hyper-V and Xen emulation, so that those changes stay local and the
code movement can be reviewed on its own.
No functional change intended.
Link: https://lore.kernel.org/r/aIEgVpjXDR0BXgHq@xxxxxxxxxx
Link: https://lore.kernel.org/r/aIEwOToiAkKfQA-4@xxxxxxxxxx
Signed-off-by: Zack Rusin <zack.rusin@xxxxxxxxxxxx>
---
MAINTAINERS | 9 +++++
arch/x86/kvm/Makefile | 3 +-
arch/x86/kvm/emulate.c | 4 +--
arch/x86/kvm/pmu.c | 35 +-----------------
arch/x86/kvm/pmu.h | 5 ---
arch/x86/kvm/svm/svm.c | 1 +
arch/x86/kvm/vmware.c | 81 ++++++++++++++++++++++++++++++++++++++++++
arch/x86/kvm/vmware.h | 22 ++++++++++++
arch/x86/kvm/vmx/vmx.c | 1 +
arch/x86/kvm/x86.c | 36 +------------------
arch/x86/kvm/x86.h | 2 --
11 files changed, 119 insertions(+), 80 deletions(-)
create mode 100644 arch/x86/kvm/vmware.c
create mode 100644 arch/x86/kvm/vmware.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 222b7fc2c3aa..017053e8f76e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15042,6 +15042,15 @@ F: arch/x86/kvm/svm/hyperv.*
F: arch/x86/kvm/svm/svm_onhyperv.*
F: arch/x86/kvm/vmx/hyperv.*
+KVM X86 VMWARE (KVM/VMware)
+M: Zack Rusin <zack.rusin@xxxxxxxxxxxx>
+M: Doug Covelli <doug.covelli@xxxxxxxxxxxx>
+L: kvm@xxxxxxxxxxxxxxx
+S: Supported
+T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git
+T: git https://github.com/kvm-x86/linux.git
+F: arch/x86/kvm/vmware.*
+
KVM X86 Xen (KVM/Xen)
M: David Woodhouse <dwmw2@xxxxxxxxxxxxx>
M: Paul Durrant <paul@xxxxxxx>
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index c6bf463f5032..0cb47cfc1162 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -6,7 +6,8 @@ ccflags-$(CONFIG_KVM_WERROR) += -Werror
include $(srctree)/virt/kvm/Makefile.kvm
kvm-y += x86.o emulate.o irq.o lapic.o cpuid.o msrs.o pmu.o regs.o \
- mtrr.o debugfs.o mmu/mmu.o mmu/page_track.o mmu/spte.o
+ mtrr.o debugfs.o mmu/mmu.o mmu/page_track.o mmu/spte.o \
+ vmware.o
kvm-$(CONFIG_X86_64) += mmu/tdp_iter.o mmu/tdp_mmu.o
kvm-$(CONFIG_KVM_IOAPIC) += i8259.o i8254.o ioapic.o
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c1b21282187f..a7bcde6f0359 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -33,6 +33,7 @@
#include "tss.h"
#include "mmu.h"
#include "pmu.h"
+#include "vmware.h"
/*
* Operand types
@@ -2523,9 +2524,6 @@ static bool emulator_bad_iopl(struct x86_emulate_ctxt *ctxt)
return ctxt->ops->cpl(ctxt) > iopl;
}
-#define VMWARE_PORT_VMPORT (0x5658)
-#define VMWARE_PORT_VMRPC (0x5659)
-
static bool emulator_io_port_access_allowed(struct x86_emulate_ctxt *ctxt,
u16 port, u16 len)
{
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index ca6dfb44949f..ae7000c44677 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -23,6 +23,7 @@
#include "cpuid.h"
#include "lapic.h"
#include "pmu.h"
+#include "vmware.h"
/* This is enough to filter the vast majority of currently defined events. */
#define KVM_PMU_EVENT_FILTER_MAX_EVENTS 300
@@ -716,40 +717,6 @@ int kvm_pmu_check_rdpmc_early(struct kvm_vcpu *vcpu, unsigned int idx)
return kvm_pmu_call(check_rdpmc_early)(vcpu, idx);
}
-bool is_vmware_backdoor_pmc(u32 pmc_idx)
-{
- switch (pmc_idx) {
- case VMWARE_BACKDOOR_PMC_HOST_TSC:
- case VMWARE_BACKDOOR_PMC_REAL_TIME:
- case VMWARE_BACKDOOR_PMC_APPARENT_TIME:
- return true;
- }
- return false;
-}
-
-static int kvm_pmu_rdpmc_vmware(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
-{
- u64 ctr_val;
-
- switch (idx) {
- case VMWARE_BACKDOOR_PMC_HOST_TSC:
- ctr_val = rdtsc();
- break;
- case VMWARE_BACKDOOR_PMC_REAL_TIME:
- ctr_val = ktime_get_boottime_ns();
- break;
- case VMWARE_BACKDOOR_PMC_APPARENT_TIME:
- ctr_val = ktime_get_boottime_ns() +
- vcpu->kvm->arch.kvmclock_offset;
- break;
- default:
- return 1;
- }
-
- *data = ctr_val;
- return 0;
-}
-
int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
{
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
index 090c9bbb74f4..3fc2ce713b6f 100644
--- a/arch/x86/kvm/pmu.h
+++ b/arch/x86/kvm/pmu.h
@@ -17,10 +17,6 @@
#define fixed_ctrl_field(ctrl_reg, idx) \
(((ctrl_reg) >> ((idx) * INTEL_FIXED_BITS_STRIDE)) & INTEL_FIXED_BITS_MASK)
-#define VMWARE_BACKDOOR_PMC_HOST_TSC 0x10000
-#define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001
-#define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002
-
#define KVM_FIXED_PMC_BASE_IDX INTEL_PMC_IDX_FIXED
struct kvm_pmu_ops {
@@ -287,7 +283,6 @@ void kvm_pmu_branch_retired(struct kvm_vcpu *vcpu);
void kvm_mediated_pmu_load(struct kvm_vcpu *vcpu);
void kvm_mediated_pmu_put(struct kvm_vcpu *vcpu);
-bool is_vmware_backdoor_pmc(u32 pmc_idx);
bool kvm_need_perf_global_ctrl_intercept(struct kvm_vcpu *vcpu);
bool kvm_need_rdpmc_intercept(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 721dc5e7e13a..980841d153f3 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -9,6 +9,7 @@
#include "smm.h"
#include "cpuid.h"
#include "pmu.h"
+#include "vmware.h"
#include <linux/module.h>
#include <linux/kernel.h>
diff --git a/arch/x86/kvm/vmware.c b/arch/x86/kvm/vmware.c
new file mode 100644
index 000000000000..772f295f8ff5
--- /dev/null
+++ b/arch/x86/kvm/vmware.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * KVM VMware emulation support
+ *
+ * Copyright (C) 2025-2026 Broadcom. All Rights Reserved. The term
+ * "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
+ */
+
+#include <linux/moduleparam.h>
+
+#include "kvm_emulate.h"
+#include "vmware.h"
+
+bool __read_mostly enable_vmware_backdoor;
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(enable_vmware_backdoor);
+module_param(enable_vmware_backdoor, bool, 0444);
+
+bool is_vmware_backdoor_pmc(u32 pmc_idx)
+{
+ switch (pmc_idx) {
+ case VMWARE_BACKDOOR_PMC_HOST_TSC:
+ case VMWARE_BACKDOOR_PMC_REAL_TIME:
+ case VMWARE_BACKDOOR_PMC_APPARENT_TIME:
+ return true;
+ }
+ return false;
+}
+
+int kvm_pmu_rdpmc_vmware(struct kvm_vcpu *vcpu, unsigned int idx, u64 *data)
+{
+ u64 ctr_val;
+
+ switch (idx) {
+ case VMWARE_BACKDOOR_PMC_HOST_TSC:
+ ctr_val = rdtsc();
+ break;
+ case VMWARE_BACKDOOR_PMC_REAL_TIME:
+ ctr_val = ktime_get_boottime_ns();
+ break;
+ case VMWARE_BACKDOOR_PMC_APPARENT_TIME:
+ ctr_val = ktime_get_boottime_ns() +
+ vcpu->kvm->arch.kvmclock_offset;
+ break;
+ default:
+ return 1;
+ }
+
+ *data = ctr_val;
+ return 0;
+}
+
+bool is_vmware_backdoor_opcode(struct x86_emulate_ctxt *ctxt)
+{
+ switch (ctxt->opcode_len) {
+ case 1:
+ switch (ctxt->b) {
+ case 0xe4: /* IN */
+ case 0xe5:
+ case 0xec:
+ case 0xed:
+ case 0xe6: /* OUT */
+ case 0xe7:
+ case 0xee:
+ case 0xef:
+ case 0x6c: /* INS */
+ case 0x6d:
+ case 0x6e: /* OUTS */
+ case 0x6f:
+ return true;
+ }
+ break;
+ case 2:
+ switch (ctxt->b) {
+ case 0x33: /* RDPMC */
+ return true;
+ }
+ break;
+ }
+
+ return false;
+}
diff --git a/arch/x86/kvm/vmware.h b/arch/x86/kvm/vmware.h
new file mode 100644
index 000000000000..debabaff9654
--- /dev/null
+++ b/arch/x86/kvm/vmware.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __KVM_X86_VMWARE_H
+#define __KVM_X86_VMWARE_H
+
+#include <linux/kvm_host.h>
+
+struct x86_emulate_ctxt;
+
+#define VMWARE_BACKDOOR_PMC_HOST_TSC 0x10000
+#define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001
+#define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002
+
+#define VMWARE_PORT_VMPORT (0x5658)
+#define VMWARE_PORT_VMRPC (0x5659)
+
+extern bool enable_vmware_backdoor;
+
+bool is_vmware_backdoor_pmc(u32 pmc_idx);
+int kvm_pmu_rdpmc_vmware(struct kvm_vcpu *vcpu, unsigned int idx, u64 *data);
+bool is_vmware_backdoor_opcode(struct x86_emulate_ctxt *ctxt);
+
+#endif /* __KVM_X86_VMWARE_H */
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 68fa251dda60..d407eecf1034 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -68,6 +68,7 @@
#include "trace.h"
#include "vmcs.h"
#include "vmcs12.h"
+#include "vmware.h"
#include "vmx.h"
#include "x86.h"
#include "x86_ops.h"
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2cd9ee316aad..389ae6213c85 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -31,6 +31,7 @@
#include "pmu.h"
#include "hyperv.h"
#include "lapic.h"
+#include "vmware.h"
#include "xen.h"
#include "smm.h"
@@ -191,10 +192,6 @@ module_param(min_timer_period_us, uint, 0644);
static u32 __read_mostly tsc_tolerance_ppm = 250;
module_param(tsc_tolerance_ppm, uint, 0644);
-bool __read_mostly enable_vmware_backdoor = false;
-module_param(enable_vmware_backdoor, bool, 0444);
-EXPORT_SYMBOL_FOR_KVM_INTERNAL(enable_vmware_backdoor);
-
/*
* Flags to manipulate forced emulation behavior (any non-zero value will
* enable forced emulation).
@@ -6291,37 +6288,6 @@ static bool kvm_vcpu_check_code_breakpoint(struct kvm_vcpu *vcpu,
return false;
}
-static bool is_vmware_backdoor_opcode(struct x86_emulate_ctxt *ctxt)
-{
- switch (ctxt->opcode_len) {
- case 1:
- switch (ctxt->b) {
- case 0xe4: /* IN */
- case 0xe5:
- case 0xec:
- case 0xed:
- case 0xe6: /* OUT */
- case 0xe7:
- case 0xee:
- case 0xef:
- case 0x6c: /* INS */
- case 0x6d:
- case 0x6e: /* OUTS */
- case 0x6f:
- return true;
- }
- break;
- case 2:
- switch (ctxt->b) {
- case 0x33: /* RDPMC */
- return true;
- }
- break;
- }
-
- return false;
-}
-
static bool is_soft_int_instruction(struct x86_emulate_ctxt *ctxt,
int emulation_type)
{
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 43850b524774..4d0a8558d931 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -718,8 +718,6 @@ static inline bool kvm_mpx_supported(void)
extern unsigned int min_timer_period_us;
-extern bool enable_vmware_backdoor;
-
extern int pi_inject_timer;
static inline u64 nsec_to_cycles(struct kvm_vcpu *vcpu, u64 nsec)
--
2.53.0