Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp694361pxb; Tue, 5 Apr 2022 19:05:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfY4hqPWZfVvQZ4OmfD0ixKnoOe7OgLqZbI5XPjs/Q8j0doKK7as6kfVr8xpDbNxEPUdxs X-Received: by 2002:a17:90a:8417:b0:1c7:85c9:96b1 with SMTP id j23-20020a17090a841700b001c785c996b1mr7323017pjn.8.1649210590879; Tue, 05 Apr 2022 19:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210590; cv=none; d=google.com; s=arc-20160816; b=GqqyM8rmY/X8R+XKX7+QT/f2Geqlb5ccL5dZW1psrYaEu+CbSKpA0P74+PVzB8+i9s BNGjqj0XThE0EqxU9HxAPcL8AygIwv/ITInppS1bz0wMCWb4MoDEfYRPHHUnqgrTITSp Vjd9v+K63opv1igkDwtn3AKJIL3Lb1Uvgv5O1htoavLdsvfd1NgsFB2YOgKUFDuHqQgD /cRR+uMrJDvKO7Txb8mPmsB9EuaelEcMPbcLjahLCw+Ayj0SWaEjZc22tcbI2CoD9chh 0LGl2S1vTTUa+KMzbN9vWSEwPtNySBi86Es81SaBjnAlOExOfEPACNX3dEqG3+uMv5FG BODw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vQQBFFZtlQ8deXQomtuamGVOAni78ocZ3kcQch4/SKk=; b=UCR3BNsC1Gu2kwLSfdpW7H/PpYoVbnsFxyKG0HCcRpnbwXyBCaVFUjVQMexiC35yW0 cs1gzKO94rSqnLn+WokGJYnlEB7A4imBSX+yQsz0aVal7WVplWqp1UKCiSI8MJ4w85Bl FnfTTiQwIe0e8bBYMTTSup7XDuoeXlEyiXG5xGdnttRp70fcmyrTFqh3v5h65r/JY0qN x8EE2Ef8weRcWViLb8fePnTA2g9L3+UraANrjD9aflhisx3ci2fB27+gCntxbmER1dnf hQLthIqspLpCkjyBiy0mItznX8cHlezA7kMn9fFeaRnrxgVdTz6VCeRXtDZoE4ur6xJt cACA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vMS6rOtv; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q26-20020a638c5a000000b003816043ee4csi14843249pgn.65.2022.04.05.19.02.53; Tue, 05 Apr 2022 19:03:10 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=vMS6rOtv; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243556AbiDEKhB (ORCPT + 99 others); Tue, 5 Apr 2022 06:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240745AbiDEIc3 (ORCPT ); Tue, 5 Apr 2022 04:32:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B227084ECB; Tue, 5 Apr 2022 01:24:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 38E9560FFC; Tue, 5 Apr 2022 08:24:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FAFAC385A2; Tue, 5 Apr 2022 08:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147093; bh=uwEM9yJd8yQV8YVnMIu1YlcaI8etPYsnFYaOdz+jFvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vMS6rOtvgPDUkRb+WKZe5MR/87aVcUxviIJRaXGJgdZs3tTlsMNUAUqxZBPkkxNu4 CNiSJI6TVeKY7pjMgS92Efz9BjD/AquGKUUj5ohlkGAhirvQccrTFJ9dg6CJ8mqV4i fum1kTaHCtI3d2bJJf4INSeH8nax+XHg516bbDz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH 5.17 0998/1126] KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasnt activated Date: Tue, 5 Apr 2022 09:29:05 +0200 Message-Id: <20220405070436.785764964@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Vitaly Kuznetsov commit b1e34d325397a33d97d845e312d7cf2a8b646b44 upstream. Setting non-zero values to SYNIC/STIMER MSRs activates certain features, this should not happen when KVM_CAP_HYPERV_SYNIC{,2} was not activated. Note, it would've been better to forbid writing anything to SYNIC/STIMER MSRs, including zeroes, however, at least QEMU tries clearing HV_X64_MSR_STIMER0_CONFIG without SynIC. HV_X64_MSR_EOM MSR is somewhat 'special' as writing zero there triggers an action, this also should not happen when SynIC wasn't activated. Signed-off-by: Vitaly Kuznetsov Message-Id: <20220325132140.25650-4-vkuznets@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/hyperv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -236,7 +236,7 @@ static int synic_set_msr(struct kvm_vcpu struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic); int ret; - if (!synic->active && !host) + if (!synic->active && (!host || data)) return 1; trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host); @@ -282,6 +282,9 @@ static int synic_set_msr(struct kvm_vcpu case HV_X64_MSR_EOM: { int i; + if (!synic->active) + break; + for (i = 0; i < ARRAY_SIZE(synic->sint); i++) kvm_hv_notify_acked_sint(vcpu, i); break; @@ -661,7 +664,7 @@ static int stimer_set_config(struct kvm_ struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu); - if (!synic->active && !host) + if (!synic->active && (!host || config)) return 1; if (unlikely(!host && hv_vcpu->enforce_cpuid && new_config.direct_mode && @@ -690,7 +693,7 @@ static int stimer_set_count(struct kvm_v struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu); - if (!synic->active && !host) + if (!synic->active && (!host || count)) return 1; trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id,