* [PATCH 0/9] KVM: x86: Spring cleaning, part 2
@ 2026-06-25 22:04 Sean Christopherson
2026-06-25 22:04 ` [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c Sean Christopherson
` (8 more replies)
0 siblings, 9 replies; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
A few more cleanups that I wasn't able to get out in time to catch kvm/next
(almost all of these are the result of code review feedback). The main theme
is again trimming down x86's kvm_host.h.
Sean Christopherson (9):
KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
KVM: x86/mmu: Annotate tdp_enabled as being read-mostly
KVM: x86: Pluralize the macro guard name for msrs.h
KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h
KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c
KVM: x86: Add static asserts to document connection b/w TSS structs
and macros
KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h
KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h =>
lapic.h
KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h
=> hyperv.h
arch/x86/include/asm/kvm_host.h | 192 +-------------------------------
arch/x86/kvm/hyperv.h | 90 +++++++++++++++
arch/x86/kvm/lapic.c | 10 ++
arch/x86/kvm/lapic.h | 33 ++++++
arch/x86/kvm/mmu.h | 6 +-
arch/x86/kvm/mmu/mmu.c | 2 +-
arch/x86/kvm/msrs.h | 4 +-
arch/x86/kvm/regs.h | 38 +++++++
arch/x86/kvm/tss.h | 7 ++
arch/x86/kvm/x86.c | 9 ++
arch/x86/kvm/x86.h | 6 +
11 files changed, 203 insertions(+), 194 deletions(-)
base-commit: a204badd8432f93b7e862e7dac6db0fe3d65f370
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:10 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly Sean Christopherson
` (7 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Move the macros that define the mostly-obsolete apic_attention bits into
lapic.c, as the gory details of PV EOIs and the pre-APICv TPR acceleration
are 100% internal to KVM's local APIC emulation.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 10 ----------
arch/x86/kvm/lapic.c | 10 ++++++++++
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index b517257a6315..9ba8aa739f93 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -290,16 +290,6 @@ enum x86_intercept_stage;
#define PFERR_PRIVATE_ACCESS BIT_ULL(49)
#define PFERR_SYNTHETIC_MASK (PFERR_IMPLICIT_ACCESS | PFERR_PRIVATE_ACCESS)
-/* apic attention bits */
-#define KVM_APIC_CHECK_VAPIC 0
-/*
- * The following bit is set with PV-EOI, unset on EOI.
- * We detect PV-EOI changes by guest by comparing
- * this bit with PV-EOI in guest memory.
- * See the implementation in apic_update_pv_eoi.
- */
-#define KVM_APIC_PV_EOI_PENDING 1
-
struct kvm_kernel_irqfd;
struct kvm_kernel_irq_routing_entry;
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 6f30bbdddb5a..0354db0f2c0f 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -75,6 +75,16 @@ module_param(lapic_timer_advance, bool, 0444);
/* step-by-step approximation to mitigate fluctuation */
#define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8
+/* apic attention bits */
+#define KVM_APIC_CHECK_VAPIC 0
+/*
+ * The following bit is set with PV-EOI, unset on EOI.
+ * We detect PV-EOI changes by guest by comparing
+ * this bit with PV-EOI in guest memory.
+ * See the implementation in apic_update_pv_eoi.
+ */
+#define KVM_APIC_PV_EOI_PENDING 1
+
static bool __read_mostly vector_hashing_enabled = true;
module_param_named(vector_hashing, vector_hashing_enabled, bool, 0444);
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
2026-06-25 22:04 ` [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:14 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h Sean Christopherson
` (6 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Tag tdp_enabled with __read_mostly as the variable is only ever written
during vendor module load, same as all the other global MMU variables that
are handled by kvm_configure_mmu().
Opportunistically annotate the tdp_mmu_enabled and eager_page_split
declarations with __read_mostly, to match their definitions. The compiler
will warn if there are conflicting annotations, i.e. there's minimal risk
of the declaration annotation becoming stale.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mmu.h | 6 +++---
arch/x86/kvm/mmu/mmu.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index c9f628b97dae..85bc503de1b6 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -6,14 +6,14 @@
#include "regs.h"
#include "cpuid.h"
-extern bool tdp_enabled;
+extern bool __read_mostly tdp_enabled;
#ifdef CONFIG_X86_64
-extern bool tdp_mmu_enabled;
+extern bool __read_mostly tdp_mmu_enabled;
#else
#define tdp_mmu_enabled false
#endif
extern bool __read_mostly enable_mmio_caching;
-extern bool eager_page_split;
+extern bool __read_mostly eager_page_split;
#define KVM_MEMSLOT_PAGES_TO_MMU_PAGES_RATIO 50
#define KVM_MIN_ALLOC_MMU_PAGES 64UL
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 6c13da942bfc..af3820136f7c 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -104,7 +104,7 @@ module_param_named(flush_on_reuse, force_flush_and_sync_on_reuse, bool, 0644);
* 2. while doing 1. it walks guest-physical to host-physical
* If the hardware supports that we don't need to do shadow paging.
*/
-bool tdp_enabled = false;
+bool __read_mostly tdp_enabled = false;
static bool __ro_after_init tdp_mmu_allowed;
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
2026-06-25 22:04 ` [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c Sean Christopherson
2026-06-25 22:04 ` [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:14 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h Sean Christopherson
` (5 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Add an 'S' to msrs.h's macro guard so that both the file and guard names
are plural.
No functional change intended.
Fixes: 7a2683080158 ("KVM: x86: Move the bulk of MSR specific code from x86.c to msrs.{c,h}")
Reported-by: Binbin Wu <binbin.wu@linux.intel.com>
Closes: https://lore.kernel.org/all/ead7d7fd-aa4e-4c18-b399-90fb448e0af6@linux.intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/msrs.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/msrs.h b/arch/x86/kvm/msrs.h
index b698983e37fb..9c5c6b33e58f 100644
--- a/arch/x86/kvm/msrs.h
+++ b/arch/x86/kvm/msrs.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef ARCH_X86_KVM_MSR_H
-#define ARCH_X86_KVM_MSR_H
+#ifndef ARCH_X86_KVM_MSRS_H
+#define ARCH_X86_KVM_MSRS_H
#include <linux/kvm_host.h>
#include <linux/user-return-notifier.h>
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
` (2 preceding siblings ...)
2026-06-25 22:04 ` [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:37 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c Sean Christopherson
` (4 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Relocate a variety of Control/Debug Register macros that unintentionally
got left behind when the related helper function prototypes were moved to
regs.h.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 40 ---------------------------------
arch/x86/kvm/regs.h | 38 +++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 40 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 9ba8aa739f93..fd712f604636 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -125,24 +125,6 @@
#define KVM_REQ_UPDATE_PROTECTED_GUEST_STATE \
KVM_ARCH_REQ_FLAGS(34, KVM_REQUEST_WAIT)
-#define CR0_RESERVED_BITS \
- (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
- | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \
- | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
-
-#define CR4_RESERVED_BITS \
- (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
- | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
- | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \
- | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \
- | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_VMXE \
- | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP \
- | X86_CR4_LAM_SUP | X86_CR4_CET))
-
-#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
-
-
-
#define INVALID_PAGE (~(hpa_t)0)
#define VALID_PAGE(x) ((x) != INVALID_PAGE)
@@ -230,28 +212,6 @@ enum x86_intercept_stage;
#define KVM_NR_DB_REGS 4
-#define DR6_BUS_LOCK (1 << 11)
-#define DR6_BD (1 << 13)
-#define DR6_BS (1 << 14)
-#define DR6_BT (1 << 15)
-#define DR6_RTM (1 << 16)
-/*
- * DR6_ACTIVE_LOW combines fixed-1 and active-low bits.
- * We can regard all the bits in DR6_FIXED_1 as active_low bits;
- * they will never be 0 for now, but when they are defined
- * in the future it will require no code change.
- *
- * DR6_ACTIVE_LOW is also used as the init/reset value for DR6.
- */
-#define DR6_ACTIVE_LOW 0xffff0ff0
-#define DR6_VOLATILE 0x0001e80f
-#define DR6_FIXED_1 (DR6_ACTIVE_LOW & ~DR6_VOLATILE)
-
-#define DR7_BP_EN_MASK 0x000000ff
-#define DR7_GE (1 << 9)
-#define DR7_GD (1 << 13)
-#define DR7_VOLATILE 0xffff2bff
-
#define KVM_GUESTDBG_VALID_MASK \
(KVM_GUESTDBG_ENABLE | \
KVM_GUESTDBG_SINGLESTEP | \
diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h
index 94fd86728fed..447f0ec3e63e 100644
--- a/arch/x86/kvm/regs.h
+++ b/arch/x86/kvm/regs.h
@@ -16,6 +16,44 @@
static_assert(!(KVM_POSSIBLE_CR0_GUEST_BITS & X86_CR0_PDPTR_BITS));
+#define CR0_RESERVED_BITS \
+ (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
+ | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \
+ | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
+
+#define CR4_RESERVED_BITS \
+ (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
+ | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
+ | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \
+ | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \
+ | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_VMXE \
+ | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP \
+ | X86_CR4_LAM_SUP | X86_CR4_CET))
+
+#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
+
+#define DR6_BUS_LOCK (1 << 11)
+#define DR6_BD (1 << 13)
+#define DR6_BS (1 << 14)
+#define DR6_BT (1 << 15)
+#define DR6_RTM (1 << 16)
+/*
+ * DR6_ACTIVE_LOW combines fixed-1 and active-low bits.
+ * We can regard all the bits in DR6_FIXED_1 as active_low bits;
+ * they will never be 0 for now, but when they are defined
+ * in the future it will require no code change.
+ *
+ * DR6_ACTIVE_LOW is also used as the init/reset value for DR6.
+ */
+#define DR6_ACTIVE_LOW 0xffff0ff0
+#define DR6_VOLATILE 0x0001e80f
+#define DR6_FIXED_1 (DR6_ACTIVE_LOW & ~DR6_VOLATILE)
+
+#define DR7_BP_EN_MASK 0x000000ff
+#define DR7_GE (1 << 9)
+#define DR7_GD (1 << 13)
+#define DR7_VOLATILE 0xffff2bff
+
void kvm_post_set_cr0(struct kvm_vcpu *vcpu, unsigned long old_cr0, unsigned long cr0);
void kvm_post_set_cr4(struct kvm_vcpu *vcpu, unsigned long old_cr4, unsigned long cr4);
int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
` (3 preceding siblings ...)
2026-06-25 22:04 ` [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:38 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros Sean Christopherson
` (3 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Move KVM_GUESTDBG_VALID_MASK into x86.c so that it's not globally visible.
As explained by commit 462474588b19 ("KVM: x86: Move misc "VALID MASK"
defines from kvm_host.h => x86.c"), which unintentionally missed GUESTDBG,
the set of valid flags/bits is very much a KVM-internal detail, as the
values from the hardcoded #defines are often captured and massaged by KVM's
setup code, i.e. *directly* using the macros outside of KVM x86 would be
actively dangerous.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 9 ---------
arch/x86/kvm/x86.c | 9 +++++++++
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index fd712f604636..f24e0de00692 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -212,15 +212,6 @@ enum x86_intercept_stage;
#define KVM_NR_DB_REGS 4
-#define KVM_GUESTDBG_VALID_MASK \
- (KVM_GUESTDBG_ENABLE | \
- KVM_GUESTDBG_SINGLESTEP | \
- KVM_GUESTDBG_USE_HW_BP | \
- KVM_GUESTDBG_USE_SW_BP | \
- KVM_GUESTDBG_INJECT_BP | \
- KVM_GUESTDBG_INJECT_DB | \
- KVM_GUESTDBG_BLOCKIRQ)
-
#define PFERR_PRESENT_MASK BIT(0)
#define PFERR_WRITE_MASK BIT(1)
#define PFERR_USER_MASK BIT(2)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0626e835e9eb..5ee6d0c33009 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -115,6 +115,15 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_host);
#define KVM_CAP_PMU_VALID_MASK KVM_PMU_CAP_DISABLE
+#define KVM_GUESTDBG_VALID_MASK \
+ (KVM_GUESTDBG_ENABLE | \
+ KVM_GUESTDBG_SINGLESTEP | \
+ KVM_GUESTDBG_USE_HW_BP | \
+ KVM_GUESTDBG_USE_SW_BP | \
+ KVM_GUESTDBG_INJECT_BP | \
+ KVM_GUESTDBG_INJECT_DB | \
+ KVM_GUESTDBG_BLOCKIRQ)
+
#define KVM_X2APIC_API_VALID_FLAGS (KVM_X2APIC_API_USE_32BIT_IDS | \
KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK | \
KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST | \
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
` (4 preceding siblings ...)
2026-06-25 22:04 ` [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:43 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h Sean Christopherson
` (2 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Add static asserts to sanity check the I/O permission map and TSS size
macros against tss_segment_32. Alternatively, the macros could simply use
offsetof() and sizeof(), but having literal numbers makes it easier to
understand the bigger picture, and provides a good excuse for the sanity
checks.
Opportunistically add the necessary includes to make tss.h self sufficient.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/tss.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/kvm/tss.h b/arch/x86/kvm/tss.h
index 117bf8bec07d..55ced8975840 100644
--- a/arch/x86/kvm/tss.h
+++ b/arch/x86/kvm/tss.h
@@ -2,6 +2,10 @@
#ifndef __TSS_SEGMENT_H
#define __TSS_SEGMENT_H
+#include <linux/build_bug.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
+
struct tss_segment_32 {
u32 prev_task_link;
u32 esp0;
@@ -64,4 +68,7 @@ struct tss_segment_16 {
#define RMODE_TSS_SIZE \
(TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
+static_assert(offsetof(struct tss_segment_32, io_map) == TSS_IOPB_BASE_OFFSET);
+static_assert(sizeof(struct tss_segment_32) == TSS_BASE_SIZE);
+
#endif
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
` (5 preceding siblings ...)
2026-06-25 22:04 ` [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:46 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h Sean Christopherson
2026-06-25 22:04 ` [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h Sean Christopherson
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Relocate KVM's TASK_SWITCH_<reason> enums from kvm_host.h to x86.h, as the
enums are arbitrary values, i.e. not architectural, and are intended to be
used only to translate vendor specific information to a common x86 reason
when invoking kvm_task_switch().
Opportunistically name the overall enum to help document the role of the
values.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 7 -------
arch/x86/kvm/x86.h | 6 ++++++
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f24e0de00692..c7d53d46763b 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1960,13 +1960,6 @@ static inline unsigned long read_msr(unsigned long msr)
}
#endif
-enum {
- TASK_SWITCH_CALL = 0,
- TASK_SWITCH_IRET = 1,
- TASK_SWITCH_JMP = 2,
- TASK_SWITCH_GATE = 3,
-};
-
#define HF_GUEST_MASK (1 << 0) /* VCPU is in guest-mode */
#ifdef CONFIG_KVM_SMM
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 8ece468087a8..494d97e9a9c9 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -482,6 +482,12 @@ int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu);
void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
+enum kvm_task_switch_reason {
+ TASK_SWITCH_CALL = 0,
+ TASK_SWITCH_IRET = 1,
+ TASK_SWITCH_JMP = 2,
+ TASK_SWITCH_GATE = 3,
+};
int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
int reason, bool has_error_code, u32 error_code);
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
` (6 preceding siblings ...)
2026-06-25 22:04 ` [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:50 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h Sean Christopherson
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Move the definition of "struct kvm_apic_map", a.k.a. the optimized local
APIC map, to lapic.h, as it is very nearly an implementation details that's
internal to KVM's local APIC emulation (KVM also uses the map to do quick
lookups when a vCPU is yielding to a different vCPU).
No functional change intended.
Suggested-by: Kai Huang <kai.huang@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 35 ++-------------------------------
arch/x86/kvm/lapic.h | 33 +++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c7d53d46763b..90efc3c90b41 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -244,6 +244,8 @@ enum x86_intercept_stage;
struct kvm_kernel_irqfd;
struct kvm_kernel_irq_routing_entry;
+struct kvm_apic_map;
+
struct kvm_x86_msr_filter;
struct kvm_x86_pmu_event_filter;
@@ -1122,39 +1124,6 @@ struct kvm_arch_memory_slot {
unsigned short *gfn_write_track;
};
-/*
- * Track the mode of the optimized logical map, as the rules for decoding the
- * destination vary per mode. Enabling the optimized logical map requires all
- * software-enabled local APIs to be in the same mode, each addressable APIC to
- * be mapped to only one MDA, and each MDA to map to at most one APIC.
- */
-enum kvm_apic_logical_mode {
- /* All local APICs are software disabled. */
- KVM_APIC_MODE_SW_DISABLED,
- /* All software enabled local APICs in xAPIC cluster addressing mode. */
- KVM_APIC_MODE_XAPIC_CLUSTER,
- /* All software enabled local APICs in xAPIC flat addressing mode. */
- KVM_APIC_MODE_XAPIC_FLAT,
- /* All software enabled local APICs in x2APIC mode. */
- KVM_APIC_MODE_X2APIC,
- /*
- * Optimized map disabled, e.g. not all local APICs in the same logical
- * mode, same logical ID assigned to multiple APICs, etc.
- */
- KVM_APIC_MODE_MAP_DISABLED,
-};
-
-struct kvm_apic_map {
- struct rcu_head rcu;
- enum kvm_apic_logical_mode logical_mode;
- u32 max_apic_id;
- union {
- struct kvm_lapic *xapic_flat_map[8];
- struct kvm_lapic *xapic_cluster_map[16][4];
- };
- struct kvm_lapic *phys_map[];
-};
-
/* Hyper-V synthetic debugger (SynDbg)*/
struct kvm_hv_syndbg {
struct {
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 58dbb94f980d..bd1098c89d99 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -32,6 +32,39 @@ enum lapic_mode {
LAPIC_MODE_X2APIC = MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE,
};
+/*
+ * Track the mode of the optimized logical map, as the rules for decoding the
+ * destination vary per mode. Enabling the optimized logical map requires all
+ * software-enabled local APIs to be in the same mode, each addressable APIC to
+ * be mapped to only one MDA, and each MDA to map to at most one APIC.
+ */
+enum kvm_apic_logical_mode {
+ /* All local APICs are software disabled. */
+ KVM_APIC_MODE_SW_DISABLED,
+ /* All software enabled local APICs in xAPIC cluster addressing mode. */
+ KVM_APIC_MODE_XAPIC_CLUSTER,
+ /* All software enabled local APICs in xAPIC flat addressing mode. */
+ KVM_APIC_MODE_XAPIC_FLAT,
+ /* All software enabled local APICs in x2APIC mode. */
+ KVM_APIC_MODE_X2APIC,
+ /*
+ * Optimized map disabled, e.g. not all local APICs in the same logical
+ * mode, same logical ID assigned to multiple APICs, etc.
+ */
+ KVM_APIC_MODE_MAP_DISABLED,
+};
+
+struct kvm_apic_map {
+ struct rcu_head rcu;
+ enum kvm_apic_logical_mode logical_mode;
+ u32 max_apic_id;
+ union {
+ struct kvm_lapic *xapic_flat_map[8];
+ struct kvm_lapic *xapic_cluster_map[16][4];
+ };
+ struct kvm_lapic *phys_map[];
+};
+
enum lapic_lvt_entry {
LVT_TIMER,
LVT_THERMAL_MONITOR,
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
` (7 preceding siblings ...)
2026-06-25 22:04 ` [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h Sean Christopherson
@ 2026-06-25 22:04 ` Sean Christopherson
2026-06-26 0:57 ` Huang, Kai
8 siblings, 1 reply; 20+ messages in thread
From: Sean Christopherson @ 2026-06-25 22:04 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Vitaly Kuznetsov
Cc: kvm, linux-kernel, Binbin Wu, Kai Huang
Move "struct kvm_vcpu_hv" and all of its child structures to hyperv.h,
guarded by CONFIG_KVM_HYPERV=y, as "struct kvm_vcpu_arch" holds a pointer
to the structure, i.e. only needs the structure to be declared, not fully
defined.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 91 +--------------------------------
arch/x86/kvm/hyperv.h | 90 ++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 89 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 90efc3c90b41..fdb8953aeeb1 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -648,95 +648,6 @@ struct kvm_mtrr {
u64 deftype;
};
-/* Hyper-V SynIC timer */
-struct kvm_vcpu_hv_stimer {
- struct hrtimer timer;
- int index;
- union hv_stimer_config config;
- u64 count;
- u64 exp_time;
- struct hv_message msg;
- bool msg_pending;
-};
-
-/* Hyper-V synthetic interrupt controller (SynIC)*/
-struct kvm_vcpu_hv_synic {
- u64 version;
- u64 control;
- u64 msg_page;
- u64 evt_page;
- atomic64_t sint[HV_SYNIC_SINT_COUNT];
- atomic_t sint_to_gsi[HV_SYNIC_SINT_COUNT];
- DECLARE_BITMAP(auto_eoi_bitmap, 256);
- DECLARE_BITMAP(vec_bitmap, 256);
- bool active;
- bool dont_zero_synic_pages;
-};
-
-/* The maximum number of entries on the TLB flush fifo. */
-#define KVM_HV_TLB_FLUSH_FIFO_SIZE (16)
-/*
- * Note: the following 'magic' entry is made up by KVM to avoid putting
- * anything besides GVA on the TLB flush fifo. It is theoretically possible
- * to observe a request to flush 4095 PFNs starting from 0xfffffffffffff000
- * which will look identical. KVM's action to 'flush everything' instead of
- * flushing these particular addresses is, however, fully legitimate as
- * flushing more than requested is always OK.
- */
-#define KVM_HV_TLB_FLUSHALL_ENTRY ((u64)-1)
-
-enum hv_tlb_flush_fifos {
- HV_L1_TLB_FLUSH_FIFO,
- HV_L2_TLB_FLUSH_FIFO,
- HV_NR_TLB_FLUSH_FIFOS,
-};
-
-struct kvm_vcpu_hv_tlb_flush_fifo {
- spinlock_t write_lock;
- DECLARE_KFIFO(entries, u64, KVM_HV_TLB_FLUSH_FIFO_SIZE);
-};
-
-/* Hyper-V per vcpu emulation context */
-struct kvm_vcpu_hv {
- struct kvm_vcpu *vcpu;
- u32 vp_index;
- u64 hv_vapic;
- s64 runtime_offset;
- struct kvm_vcpu_hv_synic synic;
- struct kvm_hyperv_exit exit;
- struct kvm_vcpu_hv_stimer stimer[HV_SYNIC_STIMER_COUNT];
- DECLARE_BITMAP(stimer_pending_bitmap, HV_SYNIC_STIMER_COUNT);
- bool enforce_cpuid;
- struct {
- u32 features_eax; /* HYPERV_CPUID_FEATURES.EAX */
- u32 features_ebx; /* HYPERV_CPUID_FEATURES.EBX */
- u32 features_edx; /* HYPERV_CPUID_FEATURES.EDX */
- u32 enlightenments_eax; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EAX */
- u32 enlightenments_ebx; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EBX */
- u32 syndbg_cap_eax; /* HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX */
- u32 nested_eax; /* HYPERV_CPUID_NESTED_FEATURES.EAX */
- u32 nested_ebx; /* HYPERV_CPUID_NESTED_FEATURES.EBX */
- } cpuid_cache;
-
- struct kvm_vcpu_hv_tlb_flush_fifo tlb_flush_fifo[HV_NR_TLB_FLUSH_FIFOS];
-
- /*
- * Preallocated buffers for handling hypercalls that pass sparse vCPU
- * sets (for high vCPU counts, they're too large to comfortably fit on
- * the stack).
- */
- u64 sparse_banks[HV_MAX_SPARSE_VCPU_BANKS];
- DECLARE_BITMAP(vcpu_mask, KVM_MAX_VCPUS);
-
- struct hv_vp_assist_page vp_assist_page;
-
- struct {
- u64 pa_page_gpa;
- u64 vm_id;
- u32 vp_id;
- } nested;
-};
-
struct kvm_hypervisor_cpuid {
u32 base;
u32 limit;
@@ -767,6 +678,8 @@ struct kvm_vcpu_xen {
};
#endif
+struct kvm_vcpu_hv;
+
struct kvm_queued_exception {
bool pending;
bool injected;
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index 1c8f7aaab063..6258ed277a7b 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -27,6 +27,96 @@
#ifdef CONFIG_KVM_HYPERV
+
+/* Hyper-V SynIC timer */
+struct kvm_vcpu_hv_stimer {
+ struct hrtimer timer;
+ int index;
+ union hv_stimer_config config;
+ u64 count;
+ u64 exp_time;
+ struct hv_message msg;
+ bool msg_pending;
+};
+
+/* Hyper-V synthetic interrupt controller (SynIC)*/
+struct kvm_vcpu_hv_synic {
+ u64 version;
+ u64 control;
+ u64 msg_page;
+ u64 evt_page;
+ atomic64_t sint[HV_SYNIC_SINT_COUNT];
+ atomic_t sint_to_gsi[HV_SYNIC_SINT_COUNT];
+ DECLARE_BITMAP(auto_eoi_bitmap, 256);
+ DECLARE_BITMAP(vec_bitmap, 256);
+ bool active;
+ bool dont_zero_synic_pages;
+};
+
+/* The maximum number of entries on the TLB flush fifo. */
+#define KVM_HV_TLB_FLUSH_FIFO_SIZE (16)
+/*
+ * Note: the following 'magic' entry is made up by KVM to avoid putting
+ * anything besides GVA on the TLB flush fifo. It is theoretically possible
+ * to observe a request to flush 4095 PFNs starting from 0xfffffffffffff000
+ * which will look identical. KVM's action to 'flush everything' instead of
+ * flushing these particular addresses is, however, fully legitimate as
+ * flushing more than requested is always OK.
+ */
+#define KVM_HV_TLB_FLUSHALL_ENTRY ((u64)-1)
+
+enum hv_tlb_flush_fifos {
+ HV_L1_TLB_FLUSH_FIFO,
+ HV_L2_TLB_FLUSH_FIFO,
+ HV_NR_TLB_FLUSH_FIFOS,
+};
+
+struct kvm_vcpu_hv_tlb_flush_fifo {
+ spinlock_t write_lock;
+ DECLARE_KFIFO(entries, u64, KVM_HV_TLB_FLUSH_FIFO_SIZE);
+};
+
+/* Hyper-V per vcpu emulation context */
+struct kvm_vcpu_hv {
+ struct kvm_vcpu *vcpu;
+ u32 vp_index;
+ u64 hv_vapic;
+ s64 runtime_offset;
+ struct kvm_vcpu_hv_synic synic;
+ struct kvm_hyperv_exit exit;
+ struct kvm_vcpu_hv_stimer stimer[HV_SYNIC_STIMER_COUNT];
+ DECLARE_BITMAP(stimer_pending_bitmap, HV_SYNIC_STIMER_COUNT);
+ bool enforce_cpuid;
+ struct {
+ u32 features_eax; /* HYPERV_CPUID_FEATURES.EAX */
+ u32 features_ebx; /* HYPERV_CPUID_FEATURES.EBX */
+ u32 features_edx; /* HYPERV_CPUID_FEATURES.EDX */
+ u32 enlightenments_eax; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EAX */
+ u32 enlightenments_ebx; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EBX */
+ u32 syndbg_cap_eax; /* HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX */
+ u32 nested_eax; /* HYPERV_CPUID_NESTED_FEATURES.EAX */
+ u32 nested_ebx; /* HYPERV_CPUID_NESTED_FEATURES.EBX */
+ } cpuid_cache;
+
+ struct kvm_vcpu_hv_tlb_flush_fifo tlb_flush_fifo[HV_NR_TLB_FLUSH_FIFOS];
+
+ /*
+ * Preallocated buffers for handling hypercalls that pass sparse vCPU
+ * sets (for high vCPU counts, they're too large to comfortably fit on
+ * the stack).
+ */
+ u64 sparse_banks[HV_MAX_SPARSE_VCPU_BANKS];
+ DECLARE_BITMAP(vcpu_mask, KVM_MAX_VCPUS);
+
+ struct hv_vp_assist_page vp_assist_page;
+
+ struct {
+ u64 pa_page_gpa;
+ u64 vm_id;
+ u32 vp_id;
+ } nested;
+};
+
/* "Hv#1" signature */
#define HYPERV_CPUID_SIGNATURE_EAX 0x31237648
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
2026-06-25 22:04 ` [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c Sean Christopherson
@ 2026-06-26 0:10 ` Huang, Kai
2026-06-26 14:36 ` Sean Christopherson
0 siblings, 1 reply; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:10 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Move the macros that define the mostly-obsolete apic_attention bits into
> lapic.c, as the gory details of PV EOIs and the pre-APICv TPR acceleration
> are 100% internal to KVM's local APIC emulation.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
The code movement LGTM:
Reviewed-by: Kai Huang <kai.huang@intel.com>
> ---
> arch/x86/include/asm/kvm_host.h | 10 ----------
> arch/x86/kvm/lapic.c | 10 ++++++++++
> 2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index b517257a6315..9ba8aa739f93 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -290,16 +290,6 @@ enum x86_intercept_stage;
> #define PFERR_PRIVATE_ACCESS BIT_ULL(49)
> #define PFERR_SYNTHETIC_MASK (PFERR_IMPLICIT_ACCESS | PFERR_PRIVATE_ACCESS)
>
> -/* apic attention bits */
> -#define KVM_APIC_CHECK_VAPIC 0
> -/*
> - * The following bit is set with PV-EOI, unset on EOI.
> - * We detect PV-EOI changes by guest by comparing
> - * this bit with PV-EOI in guest memory.
> - * See the implementation in apic_update_pv_eoi.
> - */
> -#define KVM_APIC_PV_EOI_PENDING 1
> -
>
Nit:
'apic_update_pv_eoi' is a typo. AFAICT it even didn't exist either when PV_EOI
was initially added in commit ae7a2a3fb6f8b ("KVM: host side for eoi
optimization").
I think it's a typo which was introduced by that commit, and my best guessing is
the correct one should be apic_sync_pv_eoi_from_guest().
Btw, the comment isn't easy to understand either IMHO. Maybe just delete it (in
another patch perhaps, if it's worth)?
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly
2026-06-25 22:04 ` [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly Sean Christopherson
@ 2026-06-26 0:14 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:14 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Tag tdp_enabled with __read_mostly as the variable is only ever written
> during vendor module load, same as all the other global MMU variables that
> are handled by kvm_configure_mmu().
>
> Opportunistically annotate the tdp_mmu_enabled and eager_page_split
> declarations with __read_mostly, to match their definitions. The compiler
> will warn if there are conflicting annotations, i.e. there's minimal risk
> of the declaration annotation becoming stale.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h
2026-06-25 22:04 ` [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h Sean Christopherson
@ 2026-06-26 0:14 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:14 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Add an 'S' to msrs.h's macro guard so that both the file and guard names
> are plural.
>
> No functional change intended.
>
> Fixes: 7a2683080158 ("KVM: x86: Move the bulk of MSR specific code from x86.c to msrs.{c,h}")
> Reported-by: Binbin Wu <binbin.wu@linux.intel.com>
> Closes: https://lore.kernel.org/all/ead7d7fd-aa4e-4c18-b399-90fb448e0af6@linux.intel.com
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h
2026-06-25 22:04 ` [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h Sean Christopherson
@ 2026-06-26 0:37 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:37 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Relocate a variety of Control/Debug Register macros that unintentionally
> got left behind when the related helper function prototypes were moved to
> regs.h.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c
2026-06-25 22:04 ` [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c Sean Christopherson
@ 2026-06-26 0:38 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:38 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Move KVM_GUESTDBG_VALID_MASK into x86.c so that it's not globally visible.
> As explained by commit 462474588b19 ("KVM: x86: Move misc "VALID MASK"
> defines from kvm_host.h => x86.c"), which unintentionally missed GUESTDBG,
> the set of valid flags/bits is very much a KVM-internal detail, as the
> values from the hardcoded #defines are often captured and massaged by KVM's
> setup code, i.e. *directly* using the macros outside of KVM x86 would be
> actively dangerous.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros
2026-06-25 22:04 ` [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros Sean Christopherson
@ 2026-06-26 0:43 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:43 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Add static asserts to sanity check the I/O permission map and TSS size
> macros against tss_segment_32. Alternatively, the macros could simply use
> offsetof() and sizeof(), but having literal numbers makes it easier to
> understand the bigger picture, and provides a good excuse for the sanity
> checks.
>
> Opportunistically add the necessary includes to make tss.h self sufficient.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h
2026-06-25 22:04 ` [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h Sean Christopherson
@ 2026-06-26 0:46 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:46 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Relocate KVM's TASK_SWITCH_<reason> enums from kvm_host.h to x86.h, as the
> enums are arbitrary values, i.e. not architectural, and are intended to be
> used only to translate vendor specific information to a common x86 reason
> when invoking kvm_task_switch().
>
> Opportunistically name the overall enum to help document the role of the
> values.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h
2026-06-25 22:04 ` [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h Sean Christopherson
@ 2026-06-26 0:50 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:50 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Move the definition of "struct kvm_apic_map", a.k.a. the optimized local
> APIC map, to lapic.h, as it is very nearly an implementation details that's
> internal to KVM's local APIC emulation (KVM also uses the map to do quick
> lookups when a vCPU is yielding to a different vCPU).
>
> No functional change intended.
>
> Suggested-by: Kai Huang <kai.huang@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h
2026-06-25 22:04 ` [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h Sean Christopherson
@ 2026-06-26 0:57 ` Huang, Kai
0 siblings, 0 replies; 20+ messages in thread
From: Huang, Kai @ 2026-06-26 0:57 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
binbin.wu@linux.intel.com
On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> Move "struct kvm_vcpu_hv" and all of its child structures to hyperv.h,
> guarded by CONFIG_KVM_HYPERV=y, as "struct kvm_vcpu_arch" holds a pointer
> to the structure, i.e. only needs the structure to be declared, not fully
> defined.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Reviewed-by: Kai Huang <kai.huang@intel.com>
FWIW, build tested both KVM_HYPERV=y and KVM_HYPERV=n worked fine.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
2026-06-26 0:10 ` Huang, Kai
@ 2026-06-26 14:36 ` Sean Christopherson
0 siblings, 0 replies; 20+ messages in thread
From: Sean Christopherson @ 2026-06-26 14:36 UTC (permalink / raw)
To: Kai Huang
Cc: pbonzini@redhat.com, vkuznets@redhat.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, binbin.wu@linux.intel.com
On Fri, Jun 26, 2026, Kai Huang wrote:
> On Thu, 2026-06-25 at 15:04 -0700, Sean Christopherson wrote:
> > ---
> > arch/x86/include/asm/kvm_host.h | 10 ----------
> > arch/x86/kvm/lapic.c | 10 ++++++++++
> > 2 files changed, 10 insertions(+), 10 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > index b517257a6315..9ba8aa739f93 100644
> > --- a/arch/x86/include/asm/kvm_host.h
> > +++ b/arch/x86/include/asm/kvm_host.h
> > @@ -290,16 +290,6 @@ enum x86_intercept_stage;
> > #define PFERR_PRIVATE_ACCESS BIT_ULL(49)
> > #define PFERR_SYNTHETIC_MASK (PFERR_IMPLICIT_ACCESS | PFERR_PRIVATE_ACCESS)
> >
> > -/* apic attention bits */
> > -#define KVM_APIC_CHECK_VAPIC 0
> > -/*
> > - * The following bit is set with PV-EOI, unset on EOI.
> > - * We detect PV-EOI changes by guest by comparing
> > - * this bit with PV-EOI in guest memory.
> > - * See the implementation in apic_update_pv_eoi.
> > - */
> > -#define KVM_APIC_PV_EOI_PENDING 1
> > -
> >
>
> Nit:
>
> 'apic_update_pv_eoi' is a typo. AFAICT it even didn't exist either when PV_EOI
> was initially added in commit ae7a2a3fb6f8b ("KVM: host side for eoi
> optimization").
>
> I think it's a typo which was introduced by that commit, and my best guessing is
> the correct one should be apic_sync_pv_eoi_from_guest().
>
> Btw, the comment isn't easy to understand either IMHO. Maybe just delete it (in
> another patch perhaps, if it's worth)?
I'll "Opportunistically" update the comment as part of this code movement; the
formatting is also all kinds of funky.
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2026-06-26 14:36 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 22:04 [PATCH 0/9] KVM: x86: Spring cleaning, part 2 Sean Christopherson
2026-06-25 22:04 ` [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c Sean Christopherson
2026-06-26 0:10 ` Huang, Kai
2026-06-26 14:36 ` Sean Christopherson
2026-06-25 22:04 ` [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly Sean Christopherson
2026-06-26 0:14 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h Sean Christopherson
2026-06-26 0:14 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h Sean Christopherson
2026-06-26 0:37 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c Sean Christopherson
2026-06-26 0:38 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros Sean Christopherson
2026-06-26 0:43 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h Sean Christopherson
2026-06-26 0:46 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h Sean Christopherson
2026-06-26 0:50 ` Huang, Kai
2026-06-25 22:04 ` [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h Sean Christopherson
2026-06-26 0:57 ` Huang, Kai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox