kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] x86: kvm: avoid -Wsometimes-uninitized warning
@ 2019-07-12  9:12 Arnd Bergmann
  2019-07-12  9:12 ` [PATCH 2/2] x86: kvm: avoid constant-conversion warning Arnd Bergmann
  2019-07-12 12:02 ` [PATCH 1/2] x86: kvm: avoid -Wsometimes-uninitized warning Roman Kagan
  0 siblings, 2 replies; 8+ messages in thread
From: Arnd Bergmann @ 2019-07-12  9:12 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86
  Cc: Arnd Bergmann, H. Peter Anvin, Vitaly Kuznetsov, Roman Kagan,
	Liran Alon, kvm, linux-kernel, clang-built-linux

clang points out that running a 64-bit guest on a 32-bit host
would lead to uninitialized variables:

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]

Since that combination is not supported anyway, change the condition
to tell the compiler how the code is actually executed.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/x86/kvm/hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index a39e38f13029..950436c502ba 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1607,7 +1607,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 
 	longmode = is_64_bit_mode(vcpu);
 
-	if (!longmode) {
+	if (!IS_ENABLED(CONFIG_X86_64) || !longmode) {
 		param = ((u64)kvm_rdx_read(vcpu) << 32) |
 			(kvm_rax_read(vcpu) & 0xffffffff);
 		ingpa = ((u64)kvm_rbx_read(vcpu) << 32) |
-- 
2.20.0


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

end of thread, other threads:[~2019-07-12 17:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-12  9:12 [PATCH 1/2] x86: kvm: avoid -Wsometimes-uninitized warning Arnd Bergmann
2019-07-12  9:12 ` [PATCH 2/2] x86: kvm: avoid constant-conversion warning Arnd Bergmann
2019-07-12  9:30   ` Sedat Dilek
2019-07-12 17:47   ` Paolo Bonzini
2019-07-12 12:02 ` [PATCH 1/2] x86: kvm: avoid -Wsometimes-uninitized warning Roman Kagan
2019-07-12 13:02   ` Arnd Bergmann
2019-07-12 13:14     ` Paolo Bonzini
2019-07-12 13:32       ` Arnd Bergmann

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