From nobody Thu Dec 18 23:46:27 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B28EEC47088 for ; Fri, 2 Dec 2022 11:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232768AbiLBLAF (ORCPT ); Fri, 2 Dec 2022 06:00:05 -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-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_ADDRES= S_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, st= ruct kvm_hv_hcall *hc) struct kvm_vcpu *v; unsigned long i; bool all_cpus; - int consumed_xmm_halves =3D 0; + int consumed_xmm_halves; gpa_t data_offset; =20 /* @@ -2021,8 +2021,10 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, s= truct kvm_hv_hcall *hc) * consumed_xmm_halves to make sure TLB flush entries are read * from the correct offset. */ - data_offset +=3D hc->var_cnt * sizeof(sparse_banks[0]); - consumed_xmm_halves +=3D hc->var_cnt; + if (hc->fast) + consumed_xmm_halves +=3D hc->var_cnt; + else + data_offset +=3D hc->var_cnt * sizeof(sparse_banks[0]); } =20 if (hc->code =3D=3D HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE || --=20 2.38.1