Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3165277pxb; Mon, 18 Apr 2022 17:49:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPZK8Vwm+8UFvTAlKtCH869CSVgtogIA74SCMmb3OhhbWKF3Q1ffrUJeFsJP5fNFuXVcsu X-Received: by 2002:a63:5b04:0:b0:39d:6f6c:2c5d with SMTP id p4-20020a635b04000000b0039d6f6c2c5dmr12283406pgb.189.1650329394530; Mon, 18 Apr 2022 17:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650329394; cv=none; d=google.com; s=arc-20160816; b=fDJiOLXMn/DfQmUyv1c8+j4aoEAEQw1LP4MZaCK2+cS2aWuDA231HqMN02OXOT/C+d rvryuHfv5916l2jxaKgk0aBIKlqkon+lDaz0t/o5n2UBFGt9JZXG9THo8hw1qe2RgjMg PqrwYCaPntkLI1kKSyjqi44H1n2xY1Yo3KBV0b4s3TMINvK59gJnHiTHCBIMVphTRbun WVG5bQpVqagw9X3IaiARa2s/CZGbj53o4UpCnb0OalRk9IIG7HNd3lrYjZ552ilcCo7u 7N0heuz9HBmHgegK58qnCsbCXdNRQ9UeI+vaxW4cOHuNOTCKzZ/t5jAjPgLrpPg99eE1 covA== 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=Vu9pHXAhsUkB4nrywl//gQnHJhcUp11ag8u8QhXX01s=; b=xAnyHvae8oA8hPudUyrTH5Vohh3jcI2iLQJFYcRePypAUIkxR1cRY1iNlI0yE0fmgO L3B+g0SCsiYsZHId4ZNV2cUrYEBm/sA3Dn+mXSGUmlvsdNvFUCPXAlC5ulMbGIIPkiFc B0c78lAbEzaK15bJVCeC2mMp+I195H3TeGs7VPSKM55WteXj50vYmN2X33tjPyxDIAgz QZ28v3XeYnc0y50yeAgqsAD+tHJTJRuESTyQtty1pNV6Sq4PI5+wx6e6Do9UHAnBgRis ASm9J7Wfa2wOs8FKinBDjTJfwbCwjFFHYXy04Aa71yhksUsd1k8SQY0cDuV6jBOfbV3j RIwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tAPZ3SwD; 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 s205-20020a632cd6000000b0039e0b605012si10651059pgs.19.2022.04.18.17.49.38; Mon, 18 Apr 2022 17:49:54 -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=tAPZ3SwD; 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 S244935AbiDRN6P (ORCPT + 99 others); Mon, 18 Apr 2022 09:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244923AbiDRNbB (ORCPT ); Mon, 18 Apr 2022 09:31:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F5CBDF66; Mon, 18 Apr 2022 05:57:36 -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 E9F4360FD9; Mon, 18 Apr 2022 12:57:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCFF8C385A1; Mon, 18 Apr 2022 12:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286655; bh=hiYEUHsjVTfyC/Qj6abe6K8KOS/q552yo4+BC+2Uqcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAPZ3SwD60OS7eMd03Snybt3DnmmyaPT0sB8qD9Rx//VaD6PZ1DuXd5Gr8ThgYkoR Myo3RETJ1Y0HkIzyl+LoV6ABiOO988Bi6WLmeASTyPpFdVzXCiV9XlKBJirYTTh45n N3LPAAtQVGgExQcVJkKtY6fuXxIMNaJewkv31uY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH 4.14 202/284] KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasnt activated Date: Mon, 18 Apr 2022 14:13:03 +0200 Message-Id: <20220418121217.469428260@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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.7 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -260,6 +260,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; @@ -520,6 +523,12 @@ static int stimer_start(struct kvm_vcpu_ static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config, bool host) { + struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer); + struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu); + + if (!synic->active && (!host || config)) + return 1; + trace_kvm_hv_stimer_set_config(stimer_to_vcpu(stimer)->vcpu_id, stimer->index, config, host); @@ -534,6 +543,12 @@ static int stimer_set_config(struct kvm_ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, bool host) { + struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer); + struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu); + + if (!synic->active && (!host || count)) + return 1; + trace_kvm_hv_stimer_set_count(stimer_to_vcpu(stimer)->vcpu_id, stimer->index, count, host);