public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error
@ 2023-02-22 16:25 Randy Dunlap
  2023-02-22 16:46 ` Sean Christopherson
  2023-02-22 17:27 ` Vitaly Kuznetsov
  0 siblings, 2 replies; 6+ messages in thread
From: Randy Dunlap @ 2023-02-22 16:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Randy Dunlap, Vineeth Pillai, Paolo Bonzini, Vitaly Kuznetsov,
	Sean Christopherson, kvm

modpost reports section mismatch errors/warnings:
WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)

Marking svm_hv_hardware_setup() as __init fixes the warnings.

I don't know why this should be needed -- it seems like a compiler
problem to me since the calling function is marked as __init.

This "(unknown) (section: .init.data)" all refer to svm_x86_ops.

Fixes: 1e0c7d40758b ("KVM: SVM: hyper-v: Remote TLB flush for SVM")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Vineeth Pillai <viremana@linux.microsoft.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org
---
v2: also make the empty stub function be __init (Vitaly)

 arch/x86/kvm/svm/svm_onhyperv.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -- a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h
--- a/arch/x86/kvm/svm/svm_onhyperv.h
+++ b/arch/x86/kvm/svm/svm_onhyperv.h
@@ -30,7 +30,7 @@ static inline void svm_hv_init_vmcb(stru
 		hve->hv_enlightenments_control.msr_bitmap = 1;
 }
 
-static inline void svm_hv_hardware_setup(void)
+static inline __init void svm_hv_hardware_setup(void)
 {
 	if (npt_enabled &&
 	    ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
@@ -84,7 +84,7 @@ static inline void svm_hv_init_vmcb(stru
 {
 }
 
-static inline void svm_hv_hardware_setup(void)
+static inline __init void svm_hv_hardware_setup(void)
 {
 }
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error
  2023-02-22 16:25 [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error Randy Dunlap
@ 2023-02-22 16:46 ` Sean Christopherson
  2023-02-22 18:32   ` Paolo Bonzini
  2023-02-22 17:27 ` Vitaly Kuznetsov
  1 sibling, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2023-02-22 16:46 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: linux-kernel, Vineeth Pillai, Paolo Bonzini, Vitaly Kuznetsov,
	kvm

On Wed, Feb 22, 2023, Randy Dunlap wrote:
> modpost reports section mismatch errors/warnings:
> WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
> WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
> WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
> 
> Marking svm_hv_hardware_setup() as __init fixes the warnings.
> 
> I don't know why this should be needed -- it seems like a compiler
> problem to me since the calling function is marked as __init.

It's not a compiler issue.  __initdata is freed after init and so must not be
accessed by __init-less functions.

This as a changelog?

  Tag svm_hv_hardware_setup() with __init to fix a modpost warning as the
  non-stub implementation accesses __initdata (svm_x86_ops), i.e. would
  generate a use-after-free if svm_hv_hardware_setup() were actually invoked
  post-init.  The helper is only called from svm_hardware_setup(), which is
  also __init, i.e. other than the modpost warning, lack of __init is benign.

With that (in case Paolo grabs this directly):

Reviewed-by: Sean Christopherson <seanjc@google.com>
  
> This "(unknown) (section: .init.data)" all refer to svm_x86_ops.
> 
> Fixes: 1e0c7d40758b ("KVM: SVM: hyper-v: Remote TLB flush for SVM")
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Vineeth Pillai <viremana@linux.microsoft.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> Cc: Sean Christopherson <seanjc@google.com>
> Cc: kvm@vger.kernel.org
> ---
> v2: also make the empty stub function be __init (Vitaly)
> 
>  arch/x86/kvm/svm/svm_onhyperv.h |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff -- a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h
> --- a/arch/x86/kvm/svm/svm_onhyperv.h
> +++ b/arch/x86/kvm/svm/svm_onhyperv.h
> @@ -30,7 +30,7 @@ static inline void svm_hv_init_vmcb(stru
>  		hve->hv_enlightenments_control.msr_bitmap = 1;
>  }
>  
> -static inline void svm_hv_hardware_setup(void)
> +static inline __init void svm_hv_hardware_setup(void)
>  {
>  	if (npt_enabled &&
>  	    ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
> @@ -84,7 +84,7 @@ static inline void svm_hv_init_vmcb(stru
>  {
>  }
>  
> -static inline void svm_hv_hardware_setup(void)
> +static inline __init void svm_hv_hardware_setup(void)
>  {
>  }
>  
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error
  2023-02-22 16:25 [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error Randy Dunlap
  2023-02-22 16:46 ` Sean Christopherson
@ 2023-02-22 17:27 ` Vitaly Kuznetsov
  1 sibling, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2023-02-22 17:27 UTC (permalink / raw)
  To: Randy Dunlap, linux-kernel
  Cc: Vineeth Pillai, Paolo Bonzini, Sean Christopherson, kvm

Randy Dunlap <rdunlap@infradead.org> writes:

> modpost reports section mismatch errors/warnings:
> WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
> WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
> WARNING: modpost: vmlinux.o: section mismatch in reference: svm_hv_hardware_setup (section: .text) -> (unknown) (section: .init.data)
>
> Marking svm_hv_hardware_setup() as __init fixes the warnings.
>
> I don't know why this should be needed -- it seems like a compiler
> problem to me since the calling function is marked as __init.
>
> This "(unknown) (section: .init.data)" all refer to svm_x86_ops.
>
> Fixes: 1e0c7d40758b ("KVM: SVM: hyper-v: Remote TLB flush for SVM")
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Vineeth Pillai <viremana@linux.microsoft.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> Cc: Sean Christopherson <seanjc@google.com>
> Cc: kvm@vger.kernel.org
> ---
> v2: also make the empty stub function be __init (Vitaly)

Thanks!

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

>
>  arch/x86/kvm/svm/svm_onhyperv.h |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff -- a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h
> --- a/arch/x86/kvm/svm/svm_onhyperv.h
> +++ b/arch/x86/kvm/svm/svm_onhyperv.h
> @@ -30,7 +30,7 @@ static inline void svm_hv_init_vmcb(stru
>  		hve->hv_enlightenments_control.msr_bitmap = 1;
>  }
>  
> -static inline void svm_hv_hardware_setup(void)
> +static inline __init void svm_hv_hardware_setup(void)
>  {
>  	if (npt_enabled &&
>  	    ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
> @@ -84,7 +84,7 @@ static inline void svm_hv_init_vmcb(stru
>  {
>  }
>  
> -static inline void svm_hv_hardware_setup(void)
> +static inline __init void svm_hv_hardware_setup(void)
>  {
>  }
>  
>

-- 
Vitaly


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error
  2023-02-22 16:46 ` Sean Christopherson
@ 2023-02-22 18:32   ` Paolo Bonzini
  2023-02-23 21:11     ` Zhi Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2023-02-22 18:32 UTC (permalink / raw)
  To: Sean Christopherson, Randy Dunlap
  Cc: linux-kernel, Vineeth Pillai, Vitaly Kuznetsov, kvm

On 2/22/23 17:46, Sean Christopherson wrote:
>    Tag svm_hv_hardware_setup() with __init to fix a modpost warning as the
>    non-stub implementation accesses __initdata (svm_x86_ops), i.e. would
>    generate a use-after-free if svm_hv_hardware_setup() were actually invoked
>    post-init.  The helper is only called from svm_hardware_setup(), which is
>    also __init, i.e. other than the modpost warning, lack of __init is benign.

Done.  It's caused by the compiler deciding not to inline the function, 
probably.

Also Cc'ed stable.

Paolo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error
  2023-02-22 18:32   ` Paolo Bonzini
@ 2023-02-23 21:11     ` Zhi Wang
  2023-02-23 21:20       ` Sean Christopherson
  0 siblings, 1 reply; 6+ messages in thread
From: Zhi Wang @ 2023-02-23 21:11 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Randy Dunlap, linux-kernel, Vineeth Pillai,
	Vitaly Kuznetsov, kvm

On Wed, 22 Feb 2023 19:32:53 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

Maybe we can use __always_inline? I just noticed this thread today by chance.

https://lore.kernel.org/all/20210624095147.880513802@infradead.org/

> On 2/22/23 17:46, Sean Christopherson wrote:
> >    Tag svm_hv_hardware_setup() with __init to fix a modpost warning as the
> >    non-stub implementation accesses __initdata (svm_x86_ops), i.e. would
> >    generate a use-after-free if svm_hv_hardware_setup() were actually invoked
> >    post-init.  The helper is only called from svm_hardware_setup(), which is
> >    also __init, i.e. other than the modpost warning, lack of __init is benign.
> 
> Done.  It's caused by the compiler deciding not to inline the function, 
> probably.
> 
> Also Cc'ed stable.
> 
> Paolo
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error
  2023-02-23 21:11     ` Zhi Wang
@ 2023-02-23 21:20       ` Sean Christopherson
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-02-23 21:20 UTC (permalink / raw)
  To: Zhi Wang
  Cc: Paolo Bonzini, Randy Dunlap, linux-kernel, Vineeth Pillai,
	Vitaly Kuznetsov, kvm

On Thu, Feb 23, 2023, Zhi Wang wrote:
> On Wed, 22 Feb 2023 19:32:53 +0100
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> Maybe we can use __always_inline? I just noticed this thread today by chance.

Using __always_inline will "fix" the problem, but it's not necessary in this case,
and in some ways it's less correct.  The noinstr case you linked is different
because the helpers in question can (and are) be used in noinstr and regular
sections, i.e. shouldn't be tagged noinstr.  In this case, svm_hv_hardware_setup()
must be called from __init functions, i.e. doesn't need to be unopinionated.

And FWIW, svm_hv_hardware_setup() really doesn't need to be inlined.

> https://lore.kernel.org/all/20210624095147.880513802@infradead.org/
> 
> > On 2/22/23 17:46, Sean Christopherson wrote:
> > >    Tag svm_hv_hardware_setup() with __init to fix a modpost warning as the
> > >    non-stub implementation accesses __initdata (svm_x86_ops), i.e. would
> > >    generate a use-after-free if svm_hv_hardware_setup() were actually invoked
> > >    post-init.  The helper is only called from svm_hardware_setup(), which is
> > >    also __init, i.e. other than the modpost warning, lack of __init is benign.
> > 
> > Done.  It's caused by the compiler deciding not to inline the function, 
> > probably.
> > 
> > Also Cc'ed stable.
> > 
> > Paolo
> > 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-23 21:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-22 16:25 [PATCH v2] KVM: SVM: hyper-v: placate modpost section mismatch error Randy Dunlap
2023-02-22 16:46 ` Sean Christopherson
2023-02-22 18:32   ` Paolo Bonzini
2023-02-23 21:11     ` Zhi Wang
2023-02-23 21:20       ` Sean Christopherson
2023-02-22 17:27 ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox