Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1922012rwb; Fri, 2 Dec 2022 03:06:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf4YO4ufGXmjL6YdvpoVPcNdTLncdgSZscZpIQOsvfNRXnhegzQ3z8FftCoRbDHJLZuD69QY X-Received: by 2002:aa7:dbc3:0:b0:461:6b61:81ae with SMTP id v3-20020aa7dbc3000000b004616b6181aemr63163637edt.62.1669979170188; Fri, 02 Dec 2022 03:06:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669979170; cv=none; d=google.com; s=arc-20160816; b=0676kGhUAkqnvwsVAZZdMwUDh83uMODeWj5D2Oip1qmoc+z5Hfj0BHjj1LX5dmy0UL iDg7S+9FseaRJyqPQbw4bFgwRDb2tZkcXBklsabosQQe+WjKLSwGZ+HwVrEVxxDwQqEt NEErfWh1/LVhlDLJUOvIzXeRlQ0Oo48S/J151C5UuiF5KgoypkgdfZIfJhCPgzKLQrK3 vBzmt1WtH2f11E9LRqiGBCCunaaaKsEZuNQ1j9k7ERV520Or6v06gyD8xhS8WtMIHbO+ LKluvwTqugBqrSxDyIwhvQ6VlV8jaDbaqjUxx6txdX3c0Yne7HsyZkQ52W1GOoTafzJ+ vC/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=hJSM4gVvibFGELZBTl77hUPT9yZlZqQ7ZzM552mEWO0=; b=tkEoLoTv+lbg+5yYgpdf4Va5pXflmd1Vr0mRJ4jVVmpw3JqIRNLORig1tYBdDjMj7o Pv9bjtswMrLeFw/YWwZtVYOxeFmLXiv1agpX2qk4uom9kZ7WZiF0dgRp8lqtkc99KvFn 5ESaYS1DuTjsi4IF3xKuoHoMvD0BNiUPQLbq89oNIX76pQMReNg269EJlSEPYP0YbZGp 9/O3VbGZ0NYGjd2fFE2nP8d+IUjo0fmnSsex69qYLvKBXK6ld7iiEIHfvtxvBip1tAhu hgtLMPK59IWTzyGSuHLn35lZtB+Nnl6gpzaNDx4NKYrXdXiDMEZNtZOkbPP+6TSR4nkD S5BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RbszEByY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020a056402348f00b0045a3b951e8bsi7074830edc.194.2022.12.02.03.05.45; Fri, 02 Dec 2022 03:06:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RbszEByY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232743AbiLBLAE (ORCPT + 84 others); Fri, 2 Dec 2022 06:00:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbiLBLAC (ORCPT ); Fri, 2 Dec 2022 06:00:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9CCA7BC0C for ; Fri, 2 Dec 2022 02:59:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669978749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hJSM4gVvibFGELZBTl77hUPT9yZlZqQ7ZzM552mEWO0=; b=RbszEByY14J0HX5nzoTwIpNxOM1DfzSZwWJ1XozWyvtabDXQKZt0Z8iXvX1l9FT+2ytgxF 1sEvOBbC3a5pPioGLvv6EwLB5EFad6IKFNJhHi6DcyrVei81H1NjjGhIhR6Oz1VawWBCea 5//rj6XFVNHqO5aS9pJRZzOuWoZQpbA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-418-Q0X0gSc_PSy_bl-R3uZVhA-1; Fri, 02 Dec 2022 05:59:01 -0500 X-MC-Unique: Q0X0gSc_PSy_bl-R3uZVhA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F4E729324B7; Fri, 2 Dec 2022 10:59:01 +0000 (UTC) Received: from ovpn-192-33.brq.redhat.com (ovpn-192-33.brq.redhat.com [10.40.192.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89580C16922; Fri, 2 Dec 2022 10:58:57 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , coverity-bot , linux-kernel@vger.kernel.org Subject: [PATCH] KVM: x86: hyper-v: Fix 'using uninitialized value' Coverity warning Date: Fri, 2 Dec 2022 11:58:56 +0100 Message-Id: <20221202105856.434886-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In kvm_hv_flush_tlb(), 'data_offset' and 'consumed_xmm_halves' variables are used in a mutually exclusive way: in 'hc->fast' we count in 'XMM halves' and increase 'data_offset' otherwise. Coverity discovered, that in one case both variables are incremented unconditionally. This doesn't seem to cause any issues as the only user of 'data_offset'/'consumed_xmm_halves' data is kvm_hv_get_tlb_flush_entries() -> kvm_hv_get_hc_data() which also takes into account 'hc->fast' but is still worth fixing. While on it, drop the unneeded 'consumed_xmm_halves' initializer. In 'hc->fast' case the variable is always initialized and is not used otherwise, 'data_offset' is not being initialized either. Reported-by: coverity-bot Addresses-Coverity-ID: 1527764 ("Uninitialized variables") Fixes: 260970862c88 ("KVM: x86: hyper-v: Handle HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST{,EX} calls gently") Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 2c7f2a26421e..dee4961ad8ff 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1926,7 +1926,7 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc) struct kvm_vcpu *v; unsigned long i; bool all_cpus; - int consumed_xmm_halves = 0; + int consumed_xmm_halves; gpa_t data_offset; /* @@ -2021,8 +2021,10 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc) * consumed_xmm_halves to make sure TLB flush entries are read * from the correct offset. */ - data_offset += hc->var_cnt * sizeof(sparse_banks[0]); - consumed_xmm_halves += hc->var_cnt; + if (hc->fast) + consumed_xmm_halves += hc->var_cnt; + else + data_offset += hc->var_cnt * sizeof(sparse_banks[0]); } if (hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE || -- 2.38.1