Skip to content

Commit 44bfe1f

Browse files
committed
KVM: SVM: Make svm_x86_ops globally visible, clean up on-HyperV usage
Make svm_x86_ops globally visible in anticipation of modifying the struct in avic.c, and clean up the KVM-on-HyperV usage, as declaring _and using_ a local variable in a header that's only defined in one specific .c-file is all kinds of ugly. Opportunistically make svm_hv_enable_l2_tlb_flush() local to svm_onhyperv.c, as the only reason it was visible was due to the aforementioned shenanigans in svm_onhyperv.h. Alternatively, svm_x86_ops could be explicitly passed to svm_hv_hardware_setup() as a parameter. While that approach is slightly safer, e.g. avoids "hidden" updates, for better or worse, the Intel side of KVM has already chosen to expose vt_x86_ops (and vt_init_ops). Given that svm_x86_ops is only truly consumed by kvm_ops_update, the odds of a "hidden" update causing problems are extremely low. So, absent a strong reason to rework the VMX/TDX code, make svm_x86_ops visible, as having all updates use exactly "svm_x86_ops." is advantageous in its own right. No functional change intended. Link: https://lore.kernel.org/r/20250919215934.1590410-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 29da8c8 commit 44bfe1f

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5012,7 +5012,7 @@ static void *svm_alloc_apic_backing_page(struct kvm_vcpu *vcpu)
50125012
return page_address(page);
50135013
}
50145014

5015-
static struct kvm_x86_ops svm_x86_ops __initdata = {
5015+
struct kvm_x86_ops svm_x86_ops __initdata = {
50165016
.name = KBUILD_MODNAME,
50175017

50185018
.check_processor_compatibility = svm_check_processor_compat,

arch/x86/kvm/svm/svm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ extern int lbrv;
5454

5555
extern int tsc_aux_uret_slot __ro_after_init;
5656

57+
extern struct kvm_x86_ops svm_x86_ops __initdata;
58+
5759
/*
5860
* Clean bits in VMCB.
5961
* VMCB_ALL_CLEAN_MASK might also need to

arch/x86/kvm/svm/svm_onhyperv.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "kvm_onhyperv.h"
1616
#include "svm_onhyperv.h"
1717

18-
int svm_hv_enable_l2_tlb_flush(struct kvm_vcpu *vcpu)
18+
static int svm_hv_enable_l2_tlb_flush(struct kvm_vcpu *vcpu)
1919
{
2020
struct hv_vmcb_enlightenments *hve;
2121
hpa_t partition_assist_page = hv_get_partition_assist_page(vcpu);
@@ -35,3 +35,29 @@ int svm_hv_enable_l2_tlb_flush(struct kvm_vcpu *vcpu)
3535
return 0;
3636
}
3737

38+
__init void svm_hv_hardware_setup(void)
39+
{
40+
if (npt_enabled &&
41+
ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
42+
pr_info(KBUILD_MODNAME ": Hyper-V enlightened NPT TLB flush enabled\n");
43+
svm_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs;
44+
svm_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range;
45+
}
46+
47+
if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) {
48+
int cpu;
49+
50+
pr_info(KBUILD_MODNAME ": Hyper-V Direct TLB Flush enabled\n");
51+
for_each_online_cpu(cpu) {
52+
struct hv_vp_assist_page *vp_ap =
53+
hv_get_vp_assist_page(cpu);
54+
55+
if (!vp_ap)
56+
continue;
57+
58+
vp_ap->nested_control.features.directhypercall = 1;
59+
}
60+
svm_x86_ops.enable_l2_tlb_flush =
61+
svm_hv_enable_l2_tlb_flush;
62+
}
63+
}

arch/x86/kvm/svm/svm_onhyperv.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#include "kvm_onhyperv.h"
1414
#include "svm/hyperv.h"
1515

16-
static struct kvm_x86_ops svm_x86_ops;
17-
18-
int svm_hv_enable_l2_tlb_flush(struct kvm_vcpu *vcpu);
16+
__init void svm_hv_hardware_setup(void);
1917

2018
static inline bool svm_hv_is_enlightened_tlb_enabled(struct kvm_vcpu *vcpu)
2119
{
@@ -40,33 +38,6 @@ static inline void svm_hv_init_vmcb(struct vmcb *vmcb)
4038
hve->hv_enlightenments_control.msr_bitmap = 1;
4139
}
4240

43-
static inline __init void svm_hv_hardware_setup(void)
44-
{
45-
if (npt_enabled &&
46-
ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
47-
pr_info(KBUILD_MODNAME ": Hyper-V enlightened NPT TLB flush enabled\n");
48-
svm_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs;
49-
svm_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range;
50-
}
51-
52-
if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) {
53-
int cpu;
54-
55-
pr_info(KBUILD_MODNAME ": Hyper-V Direct TLB Flush enabled\n");
56-
for_each_online_cpu(cpu) {
57-
struct hv_vp_assist_page *vp_ap =
58-
hv_get_vp_assist_page(cpu);
59-
60-
if (!vp_ap)
61-
continue;
62-
63-
vp_ap->nested_control.features.directhypercall = 1;
64-
}
65-
svm_x86_ops.enable_l2_tlb_flush =
66-
svm_hv_enable_l2_tlb_flush;
67-
}
68-
}
69-
7041
static inline void svm_hv_vmcb_dirty_nested_enlightenments(
7142
struct kvm_vcpu *vcpu)
7243
{

0 commit comments

Comments
 (0)