linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
@ 2020-05-04 19:05 Peter Xu
  2020-05-04 23:20 ` Gavin Shan
  2020-05-05  1:39 ` Sean Christopherson
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Xu @ 2020-05-04 19:05 UTC (permalink / raw)
  To: kvm, linux-kernel; +Cc: Paolo Bonzini, peterx

GCC 10.0.1 gives me this warning when building KVM:

  warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {

It should not happen, but silent it.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 74bdb7bf3295..2da293885a67 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2425,7 +2425,7 @@ static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots,
 	gfn_t start_gfn = gpa >> PAGE_SHIFT;
 	gfn_t end_gfn = (gpa + len - 1) >> PAGE_SHIFT;
 	gfn_t nr_pages_needed = end_gfn - start_gfn + 1;
-	gfn_t nr_pages_avail;
+	gfn_t nr_pages_avail = 0;
 
 	/* Update ghc->generation before performing any error checks. */
 	ghc->generation = slots->generation;
-- 
2.26.2


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

* Re: [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
  2020-05-04 19:05 [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init() Peter Xu
@ 2020-05-04 23:20 ` Gavin Shan
  2020-05-05  1:39 ` Sean Christopherson
  1 sibling, 0 replies; 7+ messages in thread
From: Gavin Shan @ 2020-05-04 23:20 UTC (permalink / raw)
  To: Peter Xu, kvm, linux-kernel; +Cc: Paolo Bonzini

On 5/5/20 5:05 AM, Peter Xu wrote:
> GCC 10.0.1 gives me this warning when building KVM:
> 
>    warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>    2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {
> 
> It should not happen, but silent it.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   virt/kvm/kvm_main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Gavin Shan <gshan@redhat.com>

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 74bdb7bf3295..2da293885a67 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2425,7 +2425,7 @@ static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots,
>   	gfn_t start_gfn = gpa >> PAGE_SHIFT;
>   	gfn_t end_gfn = (gpa + len - 1) >> PAGE_SHIFT;
>   	gfn_t nr_pages_needed = end_gfn - start_gfn + 1;
> -	gfn_t nr_pages_avail;
> +	gfn_t nr_pages_avail = 0;
>   
>   	/* Update ghc->generation before performing any error checks. */
>   	ghc->generation = slots->generation;
> 


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

* Re: [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
  2020-05-04 19:05 [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init() Peter Xu
  2020-05-04 23:20 ` Gavin Shan
@ 2020-05-05  1:39 ` Sean Christopherson
  2020-05-05 14:12   ` Peter Xu
  1 sibling, 1 reply; 7+ messages in thread
From: Sean Christopherson @ 2020-05-05  1:39 UTC (permalink / raw)
  To: Peter Xu; +Cc: kvm, linux-kernel, Paolo Bonzini

On Mon, May 04, 2020 at 03:05:26PM -0400, Peter Xu wrote:
> GCC 10.0.1 gives me this warning when building KVM:
> 
>   warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>   2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {
> 
> It should not happen, but silent it.

Heh, third times a charm?  This has been reported and proposed twice
before[1][2].  Are you using any custom compiler flags?  E.g. -O3 is known
to cause false positives with -Wmaybe-uninitialized.

If we do end up killing this warning, I'd still prefer to use
uninitialized_var() over zero-initializing the variable.

[1] https://lkml.kernel.org/r/20200218184756.242904-1-oupton@google.com
[2] https://bugzilla.kernel.org/show_bug.cgi?id=207173

> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  virt/kvm/kvm_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 74bdb7bf3295..2da293885a67 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2425,7 +2425,7 @@ static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots,
>  	gfn_t start_gfn = gpa >> PAGE_SHIFT;
>  	gfn_t end_gfn = (gpa + len - 1) >> PAGE_SHIFT;
>  	gfn_t nr_pages_needed = end_gfn - start_gfn + 1;
> -	gfn_t nr_pages_avail;
> +	gfn_t nr_pages_avail = 0;
>  
>  	/* Update ghc->generation before performing any error checks. */
>  	ghc->generation = slots->generation;
> -- 
> 2.26.2
> 

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

* Re: [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
  2020-05-05  1:39 ` Sean Christopherson
@ 2020-05-05 14:12   ` Peter Xu
  2020-05-11 16:05     ` Sean Christopherson
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Xu @ 2020-05-05 14:12 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm, linux-kernel, Paolo Bonzini

On Mon, May 04, 2020 at 06:39:29PM -0700, Sean Christopherson wrote:
> On Mon, May 04, 2020 at 03:05:26PM -0400, Peter Xu wrote:
> > GCC 10.0.1 gives me this warning when building KVM:
> > 
> >   warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> >   2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {
> > 
> > It should not happen, but silent it.
> 
> Heh, third times a charm?  This has been reported and proposed twice
> before[1][2].  Are you using any custom compiler flags?  E.g. -O3 is known
> to cause false positives with -Wmaybe-uninitialized.

No, what I did was only upgrading to Fedora 32 (which will auto-upgrade GCC),
so it should be using the default params of whatever provided.

> 
> If we do end up killing this warning, I'd still prefer to use
> uninitialized_var() over zero-initializing the variable.
> 
> [1] https://lkml.kernel.org/r/20200218184756.242904-1-oupton@google.com
> [2] https://bugzilla.kernel.org/show_bug.cgi?id=207173

OK, I didn't know this is a known problem and discussions going on.  But I
guess it would be good to address this sooner because it could become a common
warning very soon after people upgrades gcc.

Thanks,

-- 
Peter Xu


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

* Re: [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
  2020-05-05 14:12   ` Peter Xu
@ 2020-05-11 16:05     ` Sean Christopherson
  2020-05-11 17:04       ` Oliver Upton
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Christopherson @ 2020-05-11 16:05 UTC (permalink / raw)
  To: Peter Xu, Paolo Bonzini
  Cc: kvm, linux-kernel, Oliver Upton, Tony Cook, zoran.davidovac, euloanty

+cc a few other people that have reported this at one time or another.

On Tue, May 05, 2020 at 10:12:45AM -0400, Peter Xu wrote:
> On Mon, May 04, 2020 at 06:39:29PM -0700, Sean Christopherson wrote:
> > On Mon, May 04, 2020 at 03:05:26PM -0400, Peter Xu wrote:
> > > GCC 10.0.1 gives me this warning when building KVM:
> > > 
> > >   warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> > >   2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {
> > > 
> > > It should not happen, but silent it.
> > 
> > Heh, third times a charm?  This has been reported and proposed twice
> > before[1][2].  Are you using any custom compiler flags?  E.g. -O3 is known
> > to cause false positives with -Wmaybe-uninitialized.
> 
> No, what I did was only upgrading to Fedora 32 (which will auto-upgrade GCC),
> so it should be using the default params of whatever provided.
> 
> > 
> > If we do end up killing this warning, I'd still prefer to use
> > uninitialized_var() over zero-initializing the variable.
> > 
> > [1] https://lkml.kernel.org/r/20200218184756.242904-1-oupton@google.com
> > [2] https://bugzilla.kernel.org/show_bug.cgi?id=207173
> 
> OK, I didn't know this is a known problem and discussions going on.  But I
> guess it would be good to address this sooner because it could become a common
> warning very soon after people upgrades gcc.

Ya, others are hitting this as well.  It's especially painful with the
existence of KVM_WERROR.

Paolo, any preference on how to resolve this?  It would appear GCC 10 got
"smarter".

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

* Re: [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
  2020-05-11 16:05     ` Sean Christopherson
@ 2020-05-11 17:04       ` Oliver Upton
  2020-05-11 17:10         ` Sean Christopherson
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Upton @ 2020-05-11 17:04 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Peter Xu, Paolo Bonzini, kvm list, Linux Kernel Mailing List,
	Tony Cook, zoran.davidovac, euloanty

On Mon, May 11, 2020 at 9:05 AM Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
>
> +cc a few other people that have reported this at one time or another.
>
> On Tue, May 05, 2020 at 10:12:45AM -0400, Peter Xu wrote:
> > On Mon, May 04, 2020 at 06:39:29PM -0700, Sean Christopherson wrote:
> > > On Mon, May 04, 2020 at 03:05:26PM -0400, Peter Xu wrote:
> > > > GCC 10.0.1 gives me this warning when building KVM:
> > > >
> > > >   warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> > > >   2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {
> > > >
> > > > It should not happen, but silent it.
> > >
> > > Heh, third times a charm?  This has been reported and proposed twice
> > > before[1][2].  Are you using any custom compiler flags?  E.g. -O3 is known
> > > to cause false positives with -Wmaybe-uninitialized.
> >
> > No, what I did was only upgrading to Fedora 32 (which will auto-upgrade GCC),
> > so it should be using the default params of whatever provided.
> >
> > >
> > > If we do end up killing this warning, I'd still prefer to use
> > > uninitialized_var() over zero-initializing the variable.
> > >
> > > [1] https://lkml.kernel.org/r/20200218184756.242904-1-oupton@google.com
> > > [2] https://bugzilla.kernel.org/show_bug.cgi?id=207173
> >
> > OK, I didn't know this is a known problem and discussions going on.  But I
> > guess it would be good to address this sooner because it could become a common
> > warning very soon after people upgrades gcc.
>
> Ya, others are hitting this as well.  It's especially painful with the
> existence of KVM_WERROR.
>
> Paolo, any preference on how to resolve this?  It would appear GCC 10 got
> "smarter".

Seems that doing absolutely nothing was the fix here :) See:

78a5255ffb6a ("Stop the ad-hoc games with -Wno-maybe-initialized")

--
Thanks,
Oliver

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

* Re: [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
  2020-05-11 17:04       ` Oliver Upton
@ 2020-05-11 17:10         ` Sean Christopherson
  0 siblings, 0 replies; 7+ messages in thread
From: Sean Christopherson @ 2020-05-11 17:10 UTC (permalink / raw)
  To: Oliver Upton
  Cc: Peter Xu, Paolo Bonzini, kvm list, Linux Kernel Mailing List,
	Tony Cook, zoran.davidovac, euloanty

On Mon, May 11, 2020 at 10:04:29AM -0700, Oliver Upton wrote:
> On Mon, May 11, 2020 at 9:05 AM Sean Christopherson
> <sean.j.christopherson@intel.com> wrote:
> >
> > +cc a few other people that have reported this at one time or another.
> >
> > On Tue, May 05, 2020 at 10:12:45AM -0400, Peter Xu wrote:
> > > On Mon, May 04, 2020 at 06:39:29PM -0700, Sean Christopherson wrote:
> > > > On Mon, May 04, 2020 at 03:05:26PM -0400, Peter Xu wrote:
> > > > > GCC 10.0.1 gives me this warning when building KVM:
> > > > >
> > > > >   warning: ‘nr_pages_avail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> > > > >   2442 |  for ( ; start_gfn <= end_gfn; start_gfn += nr_pages_avail) {
> > > > >
> > > > > It should not happen, but silent it.
> > > >
> > > > Heh, third times a charm?  This has been reported and proposed twice
> > > > before[1][2].  Are you using any custom compiler flags?  E.g. -O3 is known
> > > > to cause false positives with -Wmaybe-uninitialized.
> > >
> > > No, what I did was only upgrading to Fedora 32 (which will auto-upgrade GCC),
> > > so it should be using the default params of whatever provided.
> > >
> > > >
> > > > If we do end up killing this warning, I'd still prefer to use
> > > > uninitialized_var() over zero-initializing the variable.
> > > >
> > > > [1] https://lkml.kernel.org/r/20200218184756.242904-1-oupton@google.com
> > > > [2] https://bugzilla.kernel.org/show_bug.cgi?id=207173
> > >
> > > OK, I didn't know this is a known problem and discussions going on.  But I
> > > guess it would be good to address this sooner because it could become a common
> > > warning very soon after people upgrades gcc.
> >
> > Ya, others are hitting this as well.  It's especially painful with the
> > existence of KVM_WERROR.
> >
> > Paolo, any preference on how to resolve this?  It would appear GCC 10 got
> > "smarter".
> 
> Seems that doing absolutely nothing was the fix here :) See:
> 
> 78a5255ffb6a ("Stop the ad-hoc games with -Wno-maybe-initialized")

Ah, perfect!  Thanks Oliver.

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

end of thread, other threads:[~2020-05-11 17:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 19:05 [PATCH] KVM: Fix a warning in __kvm_gfn_to_hva_cache_init() Peter Xu
2020-05-04 23:20 ` Gavin Shan
2020-05-05  1:39 ` Sean Christopherson
2020-05-05 14:12   ` Peter Xu
2020-05-11 16:05     ` Sean Christopherson
2020-05-11 17:04       ` Oliver Upton
2020-05-11 17:10         ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).