KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
PATCH 1/1 KVM: Fix a warning in __kvm_gfn_to_hva_cache_init()
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.
--- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
@@ -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;
Signature · 1 line
2.26.2
Quoted 5 lines · Peter Xu
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) {
Quoted 7 lines
It should not happen, but silent it.
Signed-off-by Peter Xu <[email protected]>--- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
virt/kvm/kvm_main.c +1
-1@@ -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;
Quoted 6 lines · Peter Xu
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/[email protected]
[2] https://bugzilla.kernel.org/show_bug.cgi?id=207173
Quoted 22 lines
Signed-off-by Peter Xu <[email protected]>--- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)virt/kvm/kvm_main.c +1
-1@@ -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;Signature · 1 line
2.26.2
Quoted 11 lines · Sean Christopherson
Quoted 6 lines · Peter Xu
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.
Quoted 6 lines
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/[email protected]
[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,
Signature · 1 line
Peter Xu
+cc a few other people that have reported this at one time or another.
Quoted 20 lines · Peter Xu
Quoted 11 lines · Sean Christopherson
Quoted 6 lines · Peter Xu
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.
Quoted 4 lines
If we do end up killing this warning, I'd still prefer to use
uninitialized_var()over zero-initializing the variable.
Quoted 6 lines
Quoted 2 lines
[1] https://lkml.kernel.org/r/[email protected]
[2] https://bugzilla.kernel.org/show_bug.cgi?id=207173OK, 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".
Quoted 31 lines · Sean Christopherson
+cc a few other people that have reported this at one time or another.
Quoted 20 lines · Peter Xu
Quoted 11 lines · Sean Christopherson
Quoted 6 lines · Peter Xu
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.
Quoted 4 lines
If we do end up killing this warning, I'd still prefer to use
uninitialized_var()over zero-initializing the variable.Quoted 6 lines
Quoted 2 lines
[1] https://lkml.kernel.org/r/[email protected]
[2] https://bugzilla.kernel.org/show_bug.cgi?id=207173OK, 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.
Quoted 5 lines
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
Quoted 36 lines · Oliver Upton
Quoted 34 lines · Sean Christopherson
+cc a few other people that have reported this at one time or another.
Quoted 20 lines · Peter Xu
Quoted 11 lines · Sean Christopherson
Quoted 6 lines · Peter Xu
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.
Quoted 4 lines
If we do end up killing this warning, I'd still prefer to use
uninitialized_var()over zero-initializing the variable.Quoted 6 lines
Quoted 2 lines
[1] https://lkml.kernel.org/r/[email protected]
[2] https://bugzilla.kernel.org/show_bug.cgi?id=207173OK, 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.
Quoted 6 lines
Quoted 2 lines
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.