Message ID | 20190712141322.1073650-1-arnd@arndb.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3] x86: kvm: avoid -Wsometimes-uninitized warning | expand |
On Fri, Jul 12, 2019 at 04:13:09PM +0200, Arnd Bergmann wrote: > Clang notices a code path in which some variables are never > initialized, but fails to figure out that this can never happen > on i386 because is_64_bit_mode() always returns false. > > arch/x86/kvm/hyperv.c:1610:6: error: variable 'ingpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > if (!longmode) { > ^~~~~~~~~ > arch/x86/kvm/hyperv.c:1632:55: note: uninitialized use occurs here > trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa); > ^~~~~ > arch/x86/kvm/hyperv.c:1610:2: note: remove the 'if' if its condition is always true > if (!longmode) { > ^~~~~~~~~~~~~~~ > arch/x86/kvm/hyperv.c:1595:18: note: initialize the variable 'ingpa' to silence this warning > u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; > ^ > = 0 > arch/x86/kvm/hyperv.c:1610:6: error: variable 'outgpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > arch/x86/kvm/hyperv.c:1610:6: error: variable 'param' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > > Flip the condition around to avoid the conditional execution on i386. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > v3: reword commit log, simplify patch again > v2: make the change inside of is_64_bit_mode(). > --- > arch/x86/kvm/hyperv.c | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
On Fri, Jul 12, 2019 at 04:13:09PM +0200, Arnd Bergmann wrote: > Clang notices a code path in which some variables are never > initialized, but fails to figure out that this can never happen > on i386 because is_64_bit_mode() always returns false. > > arch/x86/kvm/hyperv.c:1610:6: error: variable 'ingpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > if (!longmode) { > ^~~~~~~~~ > arch/x86/kvm/hyperv.c:1632:55: note: uninitialized use occurs here > trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa); > ^~~~~ > arch/x86/kvm/hyperv.c:1610:2: note: remove the 'if' if its condition is always true > if (!longmode) { > ^~~~~~~~~~~~~~~ > arch/x86/kvm/hyperv.c:1595:18: note: initialize the variable 'ingpa' to silence this warning > u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; > ^ > = 0 > arch/x86/kvm/hyperv.c:1610:6: error: variable 'outgpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > arch/x86/kvm/hyperv.c:1610:6: error: variable 'param' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > > Flip the condition around to avoid the conditional execution on i386. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
On 12/07/19 16:13, Arnd Bergmann wrote: > Clang notices a code path in which some variables are never > initialized, but fails to figure out that this can never happen > on i386 because is_64_bit_mode() always returns false. > > arch/x86/kvm/hyperv.c:1610:6: error: variable 'ingpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > if (!longmode) { > ^~~~~~~~~ > arch/x86/kvm/hyperv.c:1632:55: note: uninitialized use occurs here > trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa); > ^~~~~ > arch/x86/kvm/hyperv.c:1610:2: note: remove the 'if' if its condition is always true > if (!longmode) { > ^~~~~~~~~~~~~~~ > arch/x86/kvm/hyperv.c:1595:18: note: initialize the variable 'ingpa' to silence this warning > u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; > ^ > = 0 > arch/x86/kvm/hyperv.c:1610:6: error: variable 'outgpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > arch/x86/kvm/hyperv.c:1610:6: error: variable 'param' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > > Flip the condition around to avoid the conditional execution on i386. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > v3: reword commit log, simplify patch again > v2: make the change inside of is_64_bit_mode(). > --- > arch/x86/kvm/hyperv.c | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index a39e38f13029..c10a8b10b203 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -1594,7 +1594,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > { > u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; > uint16_t code, rep_idx, rep_cnt; > - bool fast, longmode, rep; > + bool fast, rep; > > /* > * hypercall generates UD from non zero cpl and real mode > @@ -1605,9 +1605,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > return 1; > } > > - longmode = is_64_bit_mode(vcpu); > - > - if (!longmode) { > +#ifdef CONFIG_X86_64 > + if (is_64_bit_mode(vcpu)) { > + param = kvm_rcx_read(vcpu); > + ingpa = kvm_rdx_read(vcpu); > + outgpa = kvm_r8_read(vcpu); > + } else > +#endif > + { > param = ((u64)kvm_rdx_read(vcpu) << 32) | > (kvm_rax_read(vcpu) & 0xffffffff); > ingpa = ((u64)kvm_rbx_read(vcpu) << 32) | > @@ -1615,13 +1620,6 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > outgpa = ((u64)kvm_rdi_read(vcpu) << 32) | > (kvm_rsi_read(vcpu) & 0xffffffff); > } > -#ifdef CONFIG_X86_64 > - else { > - param = kvm_rcx_read(vcpu); > - ingpa = kvm_rdx_read(vcpu); > - outgpa = kvm_r8_read(vcpu); > - } > -#endif > > code = param & 0xffff; > fast = !!(param & HV_HYPERCALL_FAST_BIT); > Queued, thanks. Paolo
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index a39e38f13029..c10a8b10b203 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1594,7 +1594,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) { u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; uint16_t code, rep_idx, rep_cnt; - bool fast, longmode, rep; + bool fast, rep; /* * hypercall generates UD from non zero cpl and real mode @@ -1605,9 +1605,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) return 1; } - longmode = is_64_bit_mode(vcpu); - - if (!longmode) { +#ifdef CONFIG_X86_64 + if (is_64_bit_mode(vcpu)) { + param = kvm_rcx_read(vcpu); + ingpa = kvm_rdx_read(vcpu); + outgpa = kvm_r8_read(vcpu); + } else +#endif + { param = ((u64)kvm_rdx_read(vcpu) << 32) | (kvm_rax_read(vcpu) & 0xffffffff); ingpa = ((u64)kvm_rbx_read(vcpu) << 32) | @@ -1615,13 +1620,6 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) outgpa = ((u64)kvm_rdi_read(vcpu) << 32) | (kvm_rsi_read(vcpu) & 0xffffffff); } -#ifdef CONFIG_X86_64 - else { - param = kvm_rcx_read(vcpu); - ingpa = kvm_rdx_read(vcpu); - outgpa = kvm_r8_read(vcpu); - } -#endif code = param & 0xffff; fast = !!(param & HV_HYPERCALL_FAST_BIT);
Clang notices a code path in which some variables are never initialized, but fails to figure out that this can never happen on i386 because is_64_bit_mode() always returns false. arch/x86/kvm/hyperv.c:1610:6: error: variable 'ingpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] if (!longmode) { ^~~~~~~~~ arch/x86/kvm/hyperv.c:1632:55: note: uninitialized use occurs here trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa); ^~~~~ arch/x86/kvm/hyperv.c:1610:2: note: remove the 'if' if its condition is always true if (!longmode) { ^~~~~~~~~~~~~~~ arch/x86/kvm/hyperv.c:1595:18: note: initialize the variable 'ingpa' to silence this warning u64 param, ingpa, outgpa, ret = HV_STATUS_SUCCESS; ^ = 0 arch/x86/kvm/hyperv.c:1610:6: error: variable 'outgpa' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] arch/x86/kvm/hyperv.c:1610:6: error: variable 'param' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] Flip the condition around to avoid the conditional execution on i386. Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- v3: reword commit log, simplify patch again v2: make the change inside of is_64_bit_mode(). --- arch/x86/kvm/hyperv.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)