2022-11-14 10:06:47

by Like Xu

[permalink] [raw]
Subject: [PATCH 00/14] 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(-)

--
2.38.1



2022-11-14 10:06:55

by Like Xu

[permalink] [raw]
Subject: [PATCH 04/14] KVM: x86: Remove unnecessary export of kvm_set_apic_base()

From: Like Xu <[email protected]>

Don't export x86's kvm_set_apic_base(), the helper isn't used by
KVM x86's vendor modules.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1c5a675dc04a..38a42ca86ab2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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.
--
2.38.1


2022-11-14 10:06:59

by Like Xu

[permalink] [raw]
Subject: [PATCH 12/14] KVM: x86: Remove unnecessary export of kvm_can_use_hv_timer()

From: 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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/lapic.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 1bb63746e991..5243e619fb0d 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -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)
{
--
2.38.1


2022-11-14 10:08:48

by Like Xu

[permalink] [raw]
Subject: [PATCH 08/14] KVM: x86: Remove unnecessary export of kvm_emulate_as_nop()

From: Like Xu <[email protected]>

Don't export x86's kvm_emulate_as_nop(), the helper isn't used by
KVM x86's vendor modules.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ee63b5ab507d..41b6361dde62 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)
{
--
2.38.1


2022-11-14 10:09:24

by Like Xu

[permalink] [raw]
Subject: [PATCH 06/14] KVM: x86: Remove unnecessary export of kvm_inject_nmi()

From: 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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
arch/x86/kvm/x86.h | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 818aff135261..c03e599166b8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)
{
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 69811b4f3eac..c5ff5b05af49 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -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;
--
2.38.1


2022-11-14 10:09:28

by Like Xu

[permalink] [raw]
Subject: [PATCH 07/14] KVM: x86: Remove unnecessary export of kvm_require_cpl()

From: Like Xu <[email protected]>

Don't export x86's kvm_require_cpl(), the helper isn't used by
KVM x86's vendor modules.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c03e599166b8..ee63b5ab507d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)
{
--
2.38.1


2022-11-14 10:09:30

by Like Xu

[permalink] [raw]
Subject: [PATCH 03/14] KVM: x86: Remove unnecessary export of kvm_get_apic_base()

From: Like Xu <[email protected]>

Don't export x86's kvm_get_apic_base(), the helper isn't used by
KVM x86's vendor modules.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e46e458c5b08..1c5a675dc04a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)
{
--
2.38.1


2022-11-14 10:09:58

by Like Xu

[permalink] [raw]
Subject: [PATCH 05/14] KVM: x86: Remove unnecessary export of kvm_inject_page_fault()

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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
arch/x86/kvm/x86.h | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 38a42ca86ab2..818aff135261 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 9de72586f406..69811b4f3eac 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -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;
--
2.38.1


2022-11-14 10:12:33

by Like Xu

[permalink] [raw]
Subject: [PATCH 01/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.

Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/irq.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index d8d50558f165..04a009fbdf8a 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -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
--
2.38.1


2022-11-14 10:32:49

by Like Xu

[permalink] [raw]
Subject: [PATCH 11/14] KVM: x86: Remove unnecessary export of kvm_hv_assist_page_enabled()

From: 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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/hyperv.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 0adf4a437e85..072303aa4e42 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -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)
--
2.38.1


2022-11-14 10:32:52

by Like Xu

[permalink] [raw]
Subject: [PATCH 09/14] KVM: x86: Remove unnecessary export of kvm_scale_tsc()

From: Like Xu <[email protected]>

Don't export x86's kvm_scale_tsc(), the helper isn't used by
KVM x86's vendor modules.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 41b6361dde62..f325710a4f25 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)
{
--
2.38.1


2022-11-14 10:35:58

by Like Xu

[permalink] [raw]
Subject: [PATCH 13/14] KVM: x86: Remove unnecessary export of kvm_lapic_hv_timer_in_use()

From: 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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/lapic.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 5243e619fb0d..f59e7db2af2f 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -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)
{
--
2.38.1


2022-11-14 10:36:10

by Like Xu

[permalink] [raw]
Subject: [PATCH 02/14] KVM: x86: Remove unnecessary export of kvm_inject_pending_timer_irqs()

From: 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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/irq.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index 04a009fbdf8a..a70952eca905 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -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)
{
--
2.38.1


2022-11-14 10:47:39

by Like Xu

[permalink] [raw]
Subject: [PATCH 14/14] KVM: x86: Remove unnecessary export of kvm_apic_update_apicv()

From: Like Xu <[email protected]>

Don't export x86's kvm_apic_update_apicv(), the helper isn't used by
KVM x86's vendor modules.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/lapic.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index f59e7db2af2f..b55042462d39 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -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)
{
--
2.38.1


2022-11-14 10:50:18

by Like Xu

[permalink] [raw]
Subject: [PATCH 10/14] KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()

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.

Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/x86.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f325710a4f25..f3cb3e02bfa6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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;
--
2.38.1


2022-12-01 02:38:18

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 06/14] KVM: x86: Remove unnecessary export of kvm_inject_nmi()

On Mon, Nov 14, 2022, Like Xu wrote:
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 69811b4f3eac..c5ff5b05af49 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -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.

2022-12-01 02:47:26

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 10/14] KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()

On Mon, Nov 14, 2022, Like Xu wrote:
> 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.

> Signed-off-by: Like Xu <[email protected]>
> ---
> arch/x86/kvm/x86.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f325710a4f25..f3cb3e02bfa6 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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;
> --
> 2.38.1
>

2022-12-01 03:02:05

by Like Xu

[permalink] [raw]
Subject: Re: [PATCH 05/14] KVM: x86: Remove unnecessary export of kvm_inject_page_fault()

On 1/12/2022 10:04 am, Sean Christopherson wrote:
> On Mon, Nov 14, 2022, Like Xu wrote:
>> 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.
>
> ...
>
>> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
>> index 9de72586f406..69811b4f3eac 100644
>> --- a/arch/x86/kvm/x86.h
>> +++ b/arch/x86/kvm/x86.h
>> @@ -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).

Great, we may need more decoupling at the code level.

2022-12-01 03:47:33

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 05/14] KVM: x86: Remove unnecessary export of kvm_inject_page_fault()

On Mon, Nov 14, 2022, Like Xu wrote:
> 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.

...

> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 9de72586f406..69811b4f3eac 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -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).

2022-12-02 19:31:55

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH 00/14] KVM: x86: Remove unnecessary exported symbols

On 11/14/22 10:55, Like Xu wrote:
> 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]/

I'll squash everything in a single patch and limit the change to just
removing EXPORT_SYMBOL_GPL().

Paolo

> 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(-)
>

2022-12-02 19:47:01

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH 10/14] KVM: x86: Remove unnecessary export of kvm_vcpu_is_reset_bsp()

On 11/14/22 10:56, Like Xu wrote:
>
> 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