KVM: x86: Spring cleaning, part 2
Subsystems (4)
Sean Christopherson
maintainercover KVM: x86: Spring cleaning, part 2
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
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Sean Christopherson
maintainerPATCH 1/9 KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
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.
--- arch/x86/include/asm/kvm_host.h | 10 ---------- arch/x86/kvm/lapic.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -10
@@ -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 ;
arch/x86/kvm/lapic.c +10 -0
@@ -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 );
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
Quoted 7 lines · Sean Christopherson
Move the macros that define the mostly-obsolete
apic_attentionbits intolapic.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 <[email protected]>
The code movement LGTM:
Quoted 14 lines
--- arch/x86/include/asm/kvm_host.h | 10 ---------- arch/x86/kvm/lapic.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)arch/x86/include/asm/kvm_host.h +0
-1@@ -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 */
arch/x86/include/asm/kvm_host.h enum x86_intercept_stage; · line 293
Quoted 10 lines
arch/x86/include/asm/kvm_host.h +0
-9-#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)?
Sean Christopherson
maintainerRe: [PATCH 1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
Quoted 32 lines · Kai Huang
Quoted 14 lines · Sean Christopherson
--- arch/x86/include/asm/kvm_host.h | 10 ---------- arch/x86/kvm/lapic.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)arch/x86/include/asm/kvm_host.h +0
-1@@ -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 */ arch/x86/include/asm/kvm_host.h enum x86_intercept_stage; · line 293
Quoted 10 lines
arch/x86/include/asm/kvm_host.h +0
-9-#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 whenPV_EOIwas initially added in commitae7a2a3fb6f8b("KVM: host side for eoi optimization").
Quoted 5 lines
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.
Sean Christopherson
maintainerPATCH 2/9 KVM: x86/mmu: Annotate tdp_enabled as being read-mostly
In reply to Sean ChristophersonTag 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.
--- arch/x86/kvm/mmu.h | 6 +++--- arch/x86/kvm/mmu/mmu.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu.h +3 -3
@@ -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
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -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;
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly
Quoted 4 lines · Sean Christopherson
Tag
tdp_enabledwith__read_mostlyas the variable is only ever written during vendor module load, same as all the other global MMU variables that are handled bykvm_configure_mmu().
Quoted 9 lines
Opportunistically annotate the
tdp_mmu_enabledandeager_page_splitdeclarations 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 <[email protected]>
Sean Christopherson
maintainerPATCH 3/9 KVM: x86: Pluralize the macro guard name for msrs.h
In reply to Sean ChristophersonAdd an 'S' to msrs.h's macro guard so that both the file and guard names are plural.
No functional change intended.
--- arch/x86/kvm/msrs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/msrs.h +2 -2
@@ -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>
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 3/9] KVM: x86: Pluralize the macro guard name for msrs.h
Quoted 10 lines · Sean Christopherson
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 <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Sean Christopherson
maintainerPATCH 4/9 KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h
In reply to Sean ChristophersonRelocate 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.
--- arch/x86/include/asm/kvm_host.h | 40 --------------------------------- arch/x86/kvm/regs.h | 38 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 40 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -40
@@ -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 | \
arch/x86/kvm/regs.h +38 -0
@@ -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);
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h
Quoted 8 lines · Sean Christopherson
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 <[email protected]>
Sean Christopherson
maintainerPATCH 5/9 KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c
In reply to Sean ChristophersonMove 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.
--- arch/x86/include/asm/kvm_host.h | 9 --------- arch/x86/kvm/x86.c | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -9
@@ -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)
arch/x86/kvm/x86.c +9 -0
@@ -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 | \
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c
Quoted 11 lines · Sean Christopherson
Move
KVM_GUESTDBG_VALID_MASKintox86.cso that it's not globally visible. As explained by commit462474588b19("KVM: x86: Move misc "VALID MASK" defines fromkvm_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 <[email protected]>
Sean Christopherson
maintainerPATCH 6/9 KVM: x86: Add static asserts to document connection b/w TSS structs and macros
In reply to Sean ChristophersonAdd 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.
--- arch/x86/kvm/tss.h | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/kvm/tss.h +7 -0
@@ -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
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros
Quoted 11 lines · Sean Christopherson
Add static asserts to sanity check the I/O permission map and TSS size macros against
tss_segment_32. Alternatively, the macros could simply useoffsetof()andsizeof(), 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.hself sufficient.No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>
Sean Christopherson
maintainerPATCH 7/9 KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h
In reply to Sean ChristophersonRelocate 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.
--- arch/x86/include/asm/kvm_host.h | 7 ------- arch/x86/kvm/x86.h | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -7
@@ -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
arch/x86/kvm/x86.h +6 -0
@@ -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);
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h
Quoted 5 lines · Sean Christopherson
Relocate KVM's TASK_SWITCH_<reason> enums from
kvm_host.htox86.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 invokingkvm_task_switch().
Quoted 7 lines
Opportunistically name the overall enum to help document the role of the values.
No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>
Sean Christopherson
maintainerPATCH 8/9 KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h
In reply to Sean ChristophersonMove 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.
--- arch/x86/include/asm/kvm_host.h | 35 ++------------------------------- arch/x86/kvm/lapic.h | 33 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 33 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -33
@@ -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 {
arch/x86/kvm/lapic.h +33 -0
@@ -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 ,
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h
Quoted 10 lines · Sean Christopherson
Move the definition of "struct
kvm_apic_map", a.k.a. the optimized local APIC map, tolapic.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 <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Sean Christopherson
maintainerPATCH 9/9 KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h
In reply to Sean ChristophersonMove "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.
--- arch/x86/include/asm/kvm_host.h | 91 +-------------------------------- arch/x86/kvm/hyperv.h | 90 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 89 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -89
@@ -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;
arch/x86/kvm/hyperv.h +90 -0
96 lines not on this page · raw message
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Re: [PATCH 9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h
Quoted 9 lines · Sean Christopherson
Move "struct
kvm_vcpu_hv" and all of its child structures tohyperv.h, guarded byCONFIG_KVM_HYPERV=y, as "structkvm_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 <[email protected]>
FWIW, build tested both KVM_HYPERV=y and KVM_HYPERV=n worked fine.
Quoted 16 lines · Sean Christopherson
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 fromkvm_host.h=>lapic.c
KVM: x86/mmu: Annotatetdp_enabledas being read-mostly
KVM: x86: Pluralize the macro guard name formsrs.h
KVM: x86: Move CR and DR macro definitions fromkvm_host.h=>regs.h
KVM: x86: MoveKVM_GUESTDBG_VALID_MASKfromkvm_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 tox86.h
KVM: x86: Move "structkvm_apic_map" definition fromkvm_host.h=>
lapic.h
KVM: x86: Move "structkvm_vcpu_hv" and all children fromkvm_host.h
Quoted 3 lines
=> hyperv.h[...]
Applied to kvm-x86 misc, thanks!
[1/9] KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.c
https://github.com/kvm-x86/linux/commit/26c877c70b57 [2/9] KVM: x86/mmu: Annotate tdp_enabled as being read-mostly https://github.com/kvm-x86/linux/commit/eb4b67c93472 [3/9] KVM: x86: Pluralize the macro guard name for msrs.h https://github.com/kvm-x86/linux/commit/8821646e292d [4/9] KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.h https://github.com/kvm-x86/linux/commit/eb42c91b6546 [5/9] KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.c https://github.com/kvm-x86/linux/commit/eb7313b66c59 [6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros https://github.com/kvm-x86/linux/commit/de28ef6548a2 [7/9] KVM: x86: Move KVM's arbitrary task switch reason enums to x86.h https://github.com/kvm-x86/linux/commit/0bc5f998e18d [8/9] KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.h https://github.com/kvm-x86/linux/commit/c3d35340a337 [9/9] KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.h https://github.com/kvm-x86/linux/commit/ed6ee602bceb