KVM: x86: Remove unnecessary exported symbols
Subsystems (4)
cover KVM: x86: Remove unnecessary exported symbols
Inspired by the Sean's minor fix [1], more unnecessary (from a GPL developer's perspective) exported symbols could be cleaned up (automation to find out true positives is possible). This move helps reduce the attack surface of KVM modules and guides more developers to practice the principle of low coupling in the KVM context.
[1] https://lore.kernel.org/kvm/[email protected]/
Like Xu (13):
KVM: x86: Remove unnecessary export of kvm_inject_pending_timer_irqs()
KVM: x86: Remove unnecessary export of kvm_get_apic_base()
KVM: x86: Remove unnecessary export of kvm_set_apic_base()
KVM: x86: Remove unnecessary export of kvm_inject_page_fault()
KVM: x86: Remove unnecessary export of kvm_inject_nmi()
KVM: x86: Remove unnecessary export of kvm_require_cpl()
KVM: x86: Remove unnecessary export of kvm_emulate_as_nop()
KVM: x86: Remove unnecessary export of kvm_scale_tsc()
KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()
KVM: x86: Remove unnecessary export of kvm_hv_assist_page_enabled()
KVM: x86: Remove unnecessary export of kvm_can_use_hv_timer()
KVM: x86: Remove unnecessary export of kvm_lapic_hv_timer_in_use()
KVM: x86: Remove unnecessary export of kvm_apic_update_apicv()
Sean Christopherson (1):
KVM: x86: Remove unnecessary export of kvm_cpu_has_pending_timer()
arch/x86/kvm/hyperv.c | 1 - arch/x86/kvm/irq.c | 2 -- arch/x86/kvm/lapic.c | 3 --- arch/x86/kvm/x86.c | 18 +++++------------- arch/x86/kvm/x86.h | 2 ++ 5 files changed, 7 insertions(+), 19 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/14 KVM: x86: Remove unnecessary export of kvm_cpu_has_pending_timer()
From: Sean Christopherson <[email protected]>
Don't export x86's kvm_cpu_has_pending_timer(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/irq.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/irq.c +0 -1
@@ -31,7 +31,6 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)return r; } -EXPORT_SYMBOL (kvm_cpu_has_pending_timer);/* * check if there is a pending userspace external interrupt
Signature · 1 line
2.38.1
PATCH 2/14 KVM: x86: Remove unnecessary export of kvm_inject_pending_timer_irqs()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_inject_pending_timer_irqs(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/irq.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/irq.c +0 -1
@@ -149,7 +149,6 @@ void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu)if (kvm_xen_timer_enabled (vcpu))kvm_xen_inject_timer_irqs (vcpu); } -EXPORT_SYMBOL_GPL (kvm_inject_pending_timer_irqs);void __kvm_migrate_timers (struct kvm_vcpu *vcpu) {
Signature · 1 line
2.38.1
PATCH 3/14 KVM: x86: Remove unnecessary export of kvm_get_apic_base()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_get_apic_base(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/x86.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -463,7 +463,6 @@ u64 kvm_get_apic_base(struct kvm_vcpu *vcpu) {return vcpu->arch.apic_base; } -EXPORT_SYMBOL_GPL (kvm_get_apic_base);enum lapic_mode kvm_get_apic_mode (struct kvm_vcpu *vcpu) {
Signature · 1 line
2.38.1
PATCH 4/14 KVM: x86: Remove unnecessary export of kvm_set_apic_base()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_set_apic_base(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/x86.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -490,7 +490,6 @@ int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info)kvm_recalculate_apic_map (vcpu->kvm);return 0 ; } -EXPORT_SYMBOL_GPL (kvm_set_apic_base);/* * Handle a fault on a hardware virtualization (VMX or SVM) instruction.
Signature · 1 line
2.38.1
PATCH 5/14 KVM: x86: Remove unnecessary export of kvm_inject_page_fault()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_inject_page_fault(), the helper isn't used by KVM x86's vendor modules. Add declaration to header file out of existing callers' need.
--- arch/x86/kvm/x86.c | 1 - arch/x86/kvm/x86.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -774,7 +774,6 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault)kvm_queue_exception_e_p (vcpu,PF_VECTOR , fault->error_code, fault->address); } -EXPORT_SYMBOL_GPL (kvm_inject_page_fault);void kvm_inject_emulated_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault)
arch/x86/kvm/x86.h +1 -0
@@ -307,6 +307,7 @@ int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type,int x86_emulate_instruction (struct kvm_vcpu *vcpu,gpa_t cr2_or_gpa,int emulation_type,void *insn,int insn_len);fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu); +void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault);extern u64 host_xcr0;extern u64 host_xss;
Signature · 1 line
2.38.1
Sean Christopherson
maintainerRe: [PATCH 05/14] KVM: x86: Remove unnecessary export of kvm_inject_page_fault()
Quoted 5 lines · Like Xu
From: Like Xu <[email protected]>
Don't export x86's
kvm_inject_page_fault(), the helper isn't used by KVM x86's vendor modules. Add declaration to header file out of existing callers' need.
...
arch/x86/kvm/x86.h int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type, · line 310
Quoted 9 lines
arch/x86/kvm/x86.h +1
-0@@ -307,6 +307,7 @@ int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type,int x86_emulate_instruction (struct kvm_vcpu *vcpu,gpa_t cr2_or_gpa,int emulation_type,void *insn,int insn_len);fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu); +void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault);
arch/x86/include/asm/kvm_host.h already has a definition, no need for one here. The definition could obviously be moved, but I'd prefer not to bother at this time as I want to move _all_ of kvm_host.h out of the "public" include directories (WIP).
Re: [PATCH 05/14] KVM: x86: Remove unnecessary export of kvm_inject_page_fault()
Quoted 9 lines · Sean Christopherson
Quoted 5 lines · Like Xu
From: Like Xu <[email protected]>
Don't export x86's
kvm_inject_page_fault(), the helper isn't used by KVM x86's vendor modules. Add declaration to header file out of existing callers' need....
Quoted 13 lines
arch/x86/kvm/x86.h int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type, · line 310
Quoted 9 lines
arch/x86/kvm/x86.h +1
-0@@ -307,6 +307,7 @@ int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type,int x86_emulate_instruction (struct kvm_vcpu *vcpu,gpa_t cr2_or_gpa,int emulation_type,void *insn,int insn_len);fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu); +void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault);
arch/x86/include/asm/kvm_host.halready has a definition, no need for one here. The definition could obviously be moved, but I'd prefer not to bother at this time as I want to move _all_ ofkvm_host.hout of the "public" include directories (WIP).
Great, we may need more decoupling at the code level.
PATCH 6/14 KVM: x86: Remove unnecessary export of kvm_inject_nmi()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_inject_nmi(), the helper isn't used by KVM x86's vendor modules. Add declaration to header file out of existing callers' need.
--- arch/x86/kvm/x86.c | 1 - arch/x86/kvm/x86.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -802,7 +802,6 @@ void kvm_inject_nmi(struct kvm_vcpu *vcpu)atomic_inc (&vcpu->arch.nmi_queued);kvm_make_request (KVM_REQ_NMI , vcpu); } -EXPORT_SYMBOL_GPL (kvm_inject_nmi);void kvm_queue_exception_e (struct kvm_vcpu *vcpu,unsigned nr,u32 error_code) {
arch/x86/kvm/x86.h +1 -0
@@ -308,6 +308,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, int emulation_type, void *insn, int insn_len);fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu);void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault); +void kvm_inject_nmi (struct kvm_vcpu *vcpu);extern u64 host_xcr0;extern u64 host_xss;
Signature · 1 line
2.38.1
Sean Christopherson
maintainerRe: [PATCH 06/14] KVM: x86: Remove unnecessary export of kvm_inject_nmi()
arch/x86/kvm/x86.h int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, · line 311
Quoted 9 lines · Like Xu
arch/x86/kvm/x86.h +1
-0@@ -308,6 +308,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, int emulation_type, void *insn, int insn_len);fastpath_t handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu);void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault); +void kvm_inject_nmi (struct kvm_vcpu *vcpu);
Same as the previous patch, kvm_inject_nmi() is declared by kvm_host.h.
PATCH 7/14 KVM: x86: Remove unnecessary export of kvm_require_cpl()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_require_cpl(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/x86.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -826,7 +826,6 @@ bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl)kvm_queue_exception_e (vcpu,GP_VECTOR ,0 );return false; } -EXPORT_SYMBOL_GPL (kvm_require_cpl);bool kvm_require_dr (struct kvm_vcpu *vcpu,int dr) {
Signature · 1 line
2.38.1
PATCH 8/14 KVM: x86: Remove unnecessary export of kvm_emulate_as_nop()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_emulate_as_nop(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/x86.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -2058,7 +2058,6 @@ int kvm_emulate_as_nop(struct kvm_vcpu *vcpu) {return kvm_skip_emulated_instruction (vcpu); } -EXPORT_SYMBOL_GPL (kvm_emulate_as_nop);int kvm_emulate_invd (struct kvm_vcpu *vcpu) {
Signature · 1 line
2.38.1
PATCH 9/14 KVM: x86: Remove unnecessary export of kvm_scale_tsc()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_scale_tsc(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/x86.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/x86.c +0 -1
@@ -2503,7 +2503,6 @@ u64 kvm_scale_tsc(u64 tsc, u64 ratio)return _tsc; } -EXPORT_SYMBOL_GPL (kvm_scale_tsc);static u64 kvm_compute_l1_tsc_offset (struct kvm_vcpu *vcpu,u64 target_tsc) {
Signature · 1 line
2.38.1
PATCH 10/14 KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_vcpu_is_reset_bsp(), the helper isn't used by KVM x86's vendor modules. Move up the code block out of existing callers' need.
--- arch/x86/kvm/x86.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
arch/x86/kvm/x86.c +5 -6
@@ -11496,6 +11496,11 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)return static_call (kvm_x86_vcpu_precreate)(kvm); } +bool kvm_vcpu_is_reset_bsp (struct kvm_vcpu *vcpu) +{ +return vcpu->kvm->arch.bsp_vcpu_id == vcpu->vcpu_id; +} +int kvm_arch_vcpu_create (struct kvm_vcpu *vcpu) {struct page *page;
@@ -11993,12 +11998,6 @@ int kvm_arch_check_processor_compat(void *opaque)return ops->check_processor_compatibility (); } -bool kvm_vcpu_is_reset_bsp (struct kvm_vcpu *vcpu) -{ -return vcpu->kvm->arch.bsp_vcpu_id == vcpu->vcpu_id; -} -EXPORT_SYMBOL_GPL (kvm_vcpu_is_reset_bsp); -bool kvm_vcpu_is_bsp (struct kvm_vcpu *vcpu) {return (vcpu->arch.apic_base &MSR_IA32_APICBASE_BSP ) !=0 ;
Signature · 1 line
2.38.1
Sean Christopherson
maintainerRe: [PATCH 10/14] KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()
Quoted 5 lines · Like Xu
From: Like Xu <[email protected]>
Don't export x86's
kvm_vcpu_is_reset_bsp(), the helper isn't used by KVM x86's vendor modules. Move up the code block out of existing callers' need.
Again, no. kvm_vcpu_is_reset_bsp() is declared by kvm_vcpu_is_reset_bsp(). The lack of "static" is the first clue, and the fact that KVM compiles without issue today is the second clue. EXPORT_SYMBOL_GPL() only affects resolving module dependencies, it doesn't provide any information to the compiler about function prototypes.
Quoted 37 lines
Signed-off-by Like Xu <[email protected]>--- arch/x86/kvm/x86.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)arch/x86/kvm/x86.c +5
-6@@ -11496,6 +11496,11 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)return static_call (kvm_x86_vcpu_precreate)(kvm); } +bool kvm_vcpu_is_reset_bsp (struct kvm_vcpu *vcpu) +{ +return vcpu->kvm->arch.bsp_vcpu_id == vcpu->vcpu_id; +} +int kvm_arch_vcpu_create (struct kvm_vcpu *vcpu) {struct page *page;@@ -11993,12 +11998,6 @@ int kvm_arch_check_processor_compat(void *opaque)return ops->check_processor_compatibility (); } -bool kvm_vcpu_is_reset_bsp (struct kvm_vcpu *vcpu) -{ -return vcpu->kvm->arch.bsp_vcpu_id == vcpu->vcpu_id; -} -EXPORT_SYMBOL_GPL (kvm_vcpu_is_reset_bsp); -bool kvm_vcpu_is_bsp (struct kvm_vcpu *vcpu) {return (vcpu->arch.apic_base &MSR_IA32_APICBASE_BSP ) !=0 ;Signature · 1 line
2.38.1
Paolo Bonzini
maintainerRe: [PATCH 10/14] KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()
In reply to Like XuQuoted 4 lines · Like Xu
Don't export x86's
kvm_vcpu_is_reset_bsp(), the helper isn't used by KVM x86's vendor modules. Move up the code block out of existing callers' need.
I'm not sure why to move the code up?
Paolo
PATCH 11/14 KVM: x86: Remove unnecessary export of kvm_hv_assist_page_enabled()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_hv_assist_page_enabled(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/hyperv.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/hyperv.c +0 -1
@@ -895,7 +895,6 @@ bool kvm_hv_assist_page_enabled(struct kvm_vcpu *vcpu)return false;return vcpu->arch.pv_eoi.msr_val &KVM_MSR_ENABLED ; } -EXPORT_SYMBOL_GPL (kvm_hv_assist_page_enabled);bool kvm_hv_get_assist_page (struct kvm_vcpu *vcpu,struct hv_vp_assist_page *assist_page)
Signature · 1 line
2.38.1
PATCH 12/14 KVM: x86: Remove unnecessary export of kvm_can_use_hv_timer()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_can_use_hv_timer(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/lapic.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/lapic.c +0 -1
@@ -160,7 +160,6 @@ bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu) && !(kvm_mwait_in_guest (vcpu->kvm) ||kvm_can_post_timer_interrupt (vcpu)); } -EXPORT_SYMBOL_GPL (kvm_can_use_hv_timer);static bool kvm_use_posted_timer_interrupt (struct kvm_vcpu *vcpu) {
Signature · 1 line
2.38.1
PATCH 13/14 KVM: x86: Remove unnecessary export of kvm_lapic_hv_timer_in_use()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_lapic_hv_timer_in_use(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/lapic.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/lapic.c +0 -1
@@ -1913,7 +1913,6 @@ bool kvm_lapic_hv_timer_in_use(struct kvm_vcpu *vcpu)return vcpu->arch.apic->lapic_timer.hv_timer_in_use; } -EXPORT_SYMBOL_GPL (kvm_lapic_hv_timer_in_use);static void cancel_hv_timer (struct kvm_lapic *apic) {
Signature · 1 line
2.38.1
PATCH 14/14 KVM: x86: Remove unnecessary export of kvm_apic_update_apicv()
In reply to Like XuFrom: Like Xu <[email protected]>
Don't export x86's kvm_apic_update_apicv(), the helper isn't used by KVM x86's vendor modules.
--- arch/x86/kvm/lapic.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kvm/lapic.c +0 -1
@@ -2430,7 +2430,6 @@ void kvm_apic_update_apicv(struct kvm_vcpu *vcpu) apic->isr_count =count_vectors (apic->regs +APIC_ISR ); } } -EXPORT_SYMBOL_GPL (kvm_apic_update_apicv);void kvm_lapic_reset (struct kvm_vcpu *vcpu,bool init_event) {
Signature · 1 line
2.38.1
Paolo Bonzini
maintainerQuoted 7 lines · Like Xu
Inspired by the Sean's minor fix [1], more unnecessary (from a GPL developer's perspective) exported symbols could be cleaned up (automation to find out true positives is possible). This move helps reduce the attack surface of KVM modules and guides more developers to practice the principle of low coupling in the KVM context.
I'll squash everything in a single patch and limit the change to just removing EXPORT_SYMBOL_GPL().
Paolo
Quoted 25 lines
Like Xu (13):
KVM: x86: Remove unnecessary export ofkvm_inject_pending_timer_irqs()
KVM: x86: Remove unnecessary export ofkvm_get_apic_base()
KVM: x86: Remove unnecessary export ofkvm_set_apic_base()
KVM: x86: Remove unnecessary export ofkvm_inject_page_fault()
KVM: x86: Remove unnecessary export ofkvm_inject_nmi()
KVM: x86: Remove unnecessary export ofkvm_require_cpl()
KVM: x86: Remove unnecessary export ofkvm_emulate_as_nop()
KVM: x86: Remove unnecessary export ofkvm_scale_tsc()
KVM: x86: Remove unnecessary export ofkvm_vcpu_is_reset_bsp()
KVM: x86: Remove unnecessary export ofkvm_hv_assist_page_enabled()
KVM: x86: Remove unnecessary export ofkvm_can_use_hv_timer()
KVM: x86: Remove unnecessary export ofkvm_lapic_hv_timer_in_use()
KVM: x86: Remove unnecessary export ofkvm_apic_update_apicv()Sean Christopherson (1):
KVM: x86: Remove unnecessary export ofkvm_cpu_has_pending_timer()arch/x86/kvm/hyperv.c | 1 - arch/x86/kvm/irq.c | 2 -- arch/x86/kvm/lapic.c | 3 --- arch/x86/kvm/x86.c | 18 +++++------------- arch/x86/kvm/x86.h | 2 ++ 5 files changed, 7 insertions(+), 19 deletions(-)