Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1163610ybi; Fri, 12 Jul 2019 10:47:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKYO1T0gBtEsfh0K2PvuztJiF0UKS5DW4Qiah2mFi4hZuhchnXEWxxUhSHt5Q1LTz6SQOQ X-Received: by 2002:a63:5823:: with SMTP id m35mr12390603pgb.329.1562953650504; Fri, 12 Jul 2019 10:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562953650; cv=none; d=google.com; s=arc-20160816; b=Z3oL16fdu2dD3bUhazIvz0Dfjj3EbJfVGkAd9IZer45cMLusYD6XK88mQxqqvaKEX+ YqmCylbYHP4d5IIsvW4LwD1RjLp8U8KB3O+1EtVODOsYUVQvMN+ffVo5ZS6M6JCqB7qE GMAL8E1bwFOrA6kaDPx1EQ/Gi0lUChy4VoscBd7PmhYSHcb8wKd+I+/BAf8iow8PQ2pH qdgnVhqjqVn0fLehU6I5GcBfyn7O4HgrfYihbH35amL14ydMZQhB/GiQMoPWuTgqv0s7 wLs0kCQN+Js3X2GukTy1Hy4EPX1ibUFBV9xVl0yKfJLc5X94wbM0ZVnz/R2bG6L1rEgd 476w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:openpgp:from:references:cc:to:subject; bh=5AAY/XLB5sNM5xu1cxB6MBuk0Q+am8e86PPXt5EsGZI=; b=TAuVfZOX1odunPUChWrWuxy2b8P2OgtajfI17bKlBJCJKo1VxlWnXDEMIjgHdi/fso tiJZObtf+SvRJsRpPCp0Ky7Ws0ovdeDU5lwX6XYCjHPt9pC7/pbeF+D8hi/JSStFn7py 3iRx1rXtxo5N915ccdaGVJfjAe08ujD8sujdKIVTL4teBLIN5hh23MlYXj1h4WG9ubQ8 1/qbcKWeSIil3YvU1Zbod3k8XQZD2U5zMLLu7X9Mo/HEoJz2GUFMkeK8pyc8OwTN0kme 5U53rd22j4O2TMVuc7BgHovUIjb0xILWyVZlWxfCnggt9/lEpEUcfDguQ0YFd3R9hdJb fMFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3si8745865pgl.499.2019.07.12.10.47.15; Fri, 12 Jul 2019 10:47:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727513AbfGLRqA (ORCPT + 99 others); Fri, 12 Jul 2019 13:46:00 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41453 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbfGLRp7 (ORCPT ); Fri, 12 Jul 2019 13:45:59 -0400 Received: by mail-wr1-f66.google.com with SMTP id c2so7601824wrm.8 for ; Fri, 12 Jul 2019 10:45:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5AAY/XLB5sNM5xu1cxB6MBuk0Q+am8e86PPXt5EsGZI=; b=OqdzqvfgtzdY5aRYpq5sHxRgrNyWuLZqUU/yuLxmGtoKH3cdTO+fHh4fFeaXQKgMLi URTye7w3sz3M56Ioc+Z3RUGJf/BpOqffzWoXvIsmQPtibnZorWocJ7jn/DMMJKAGVc6y z8NRP7cc1qP02NV6CFf5idilz3vDKjeUNvHfXgxEbcAK3yhYXGK2eregL1hlJhHa+L+f eePhSL2a2mcrZLaq4wIhhs5wiKGo3bOQK8JSPhBYu+uq8VcupDgrl5vIdb8a6QKbLnV8 UUtPtmhnZywQNuQYDLSuVSFORcQl3JQPYbppgvSKfXJ3IJ2BcrtE6YI0x1A5b7o1bfMF GO1Q== X-Gm-Message-State: APjAAAWbWsbwH9nkoeaYvFcjpuYGjwgsvqQaGc/XYe3znFgL8ysLIDF5 XeibS6+n/EqUwrg6NOTHuSRTIw== X-Received: by 2002:adf:a299:: with SMTP id s25mr5567669wra.74.1562953557279; Fri, 12 Jul 2019 10:45:57 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:d066:6881:ec69:75ab? ([2001:b07:6468:f312:d066:6881:ec69:75ab]) by smtp.gmail.com with ESMTPSA id y1sm7470474wma.32.2019.07.12.10.45.56 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jul 2019 10:45:56 -0700 (PDT) Subject: Re: [PATCH] [v3] x86: kvm: avoid -Wsometimes-uninitized warning To: Arnd Bergmann , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: "H. Peter Anvin" , Vitaly Kuznetsov , Roman Kagan , Liran Alon , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20190712141322.1073650-1-arnd@arndb.de> From: Paolo Bonzini Openpgp: preference=signencrypt Message-ID: Date: Fri, 12 Jul 2019 19:45:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190712141322.1073650-1-arnd@arndb.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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