Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp920361pxb; Wed, 6 Apr 2022 04:19:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQizzovizZxMus07TfwHuRVjWyuRtTzIWH+4VqndgHPF+ReG31Epv4LVjV8+09H+m05Qy+ X-Received: by 2002:a17:90b:4d85:b0:1c7:3933:d810 with SMTP id oj5-20020a17090b4d8500b001c73933d810mr9352239pjb.129.1649243953797; Wed, 06 Apr 2022 04:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649243953; cv=none; d=google.com; s=arc-20160816; b=wIYM7gqv1k4hEi1drI5Zhrw+kvSt0RbC+KikqwEX3QiUl9LqAces3bTUX6ZLoLJE8T I0TKe5fdAkNNQv6PSih0XSdWiVmn336zBUHHBp0Q+9wzGU17tgfSPyCOtibhmzgP8q6l 8xD+kano2xWcEnWn7kKZKPP1y3ljHqlsLAtDUvhkJxIZxMeCCXf2bq8XoKXsub2VkvrZ 9xYvMlV4dgvNHkVJhq1JTSfubdEaGsV/+5VydeojP4coMbUcagSvIVo6uo4PrIiiF3a5 R7ohEOpCY28RBDFuWxhb0FnPqA+dlYLPkjSFZjBPTJmxumv+OFACk1+BRrgrPU2eMyfa Foqg== 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=4rgPvu8HrMjIAtOB1mlLgvIF8BBOyYJdI1RLVX9Bp/o=; b=g2G0iIDPSKYPIQL8Zg2cmFQsfzrNhQsQnWetD4sHVYrKO0CvSoUSP9O33ag1jobVJI Lv8Sf6uRdEP6cF9AaLW8da3CMKyIP/QaUrRgzKU3xEHJPD8CH2CLYCZIeoQBHxOd2lgy zliwTpzt7F5Dm5CcB1o+WI+bBidNGy3LEddwBCLchaYf+eMSh74IDw1nE+/OiIhPycEj rJL0B/Bimd2BrjBN4t6+5fOouS/r1nQ36bFvZR5tZENq9v8XI5KKu+mXrekER+FAgrMG aQNKUZjnMhy39GR6qYKxvkV4gJZEcGCAYDbNOwfhZORFODYDohrWSDqckQiJe+7azrAx 7v6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vL9ZEHV+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i18-20020a170902c95200b00155c6577751si17310844pla.33.2022.04.06.04.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:19:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vL9ZEHV+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C3AC4DFA84; Wed, 6 Apr 2022 02:42:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1583315AbiDEXwR (ORCPT + 99 others); Tue, 5 Apr 2022 19:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348215AbiDEKqE (ORCPT ); Tue, 5 Apr 2022 06:46:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D6436163; Tue, 5 Apr 2022 03:26:59 -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 E08456142E; Tue, 5 Apr 2022 10:26:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED22DC385A0; Tue, 5 Apr 2022 10:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649154418; bh=y84qgXsxoEUAikPwoR4Mbefb/6Lca7pkYMZB4UujyCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vL9ZEHV+hMWsLeRsr+yzJtY3SrfZlmF7HO9cEkPNEwdsqzilRQsmVTDmg6a2xA++z O+fNFjdkRmYJjuISgRMgnpFK8m+HfcrvIPkDzcRZubdy/2CJZXhZca43DkrIJ2sAZF JxtqPUzWSPsu7EF6pClsXlZqTIMukocu4ighCwXU= 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.10 533/599] KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasnt activated Date: Tue, 5 Apr 2022 09:33:47 +0200 Message-Id: <20220405070314.702100323@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070258.802373272@linuxfoundation.org> References: <20220405070258.802373272@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 @@ -207,7 +207,7 @@ static int synic_set_msr(struct kvm_vcpu struct kvm_vcpu *vcpu = 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); @@ -253,6 +253,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; @@ -636,7 +639,7 @@ static int stimer_set_config(struct kvm_ struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer); struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu); - if (!synic->active && !host) + if (!synic->active && (!host || config)) return 1; trace_kvm_hv_stimer_set_config(stimer_to_vcpu(stimer)->vcpu_id, @@ -660,7 +663,7 @@ static int stimer_set_count(struct kvm_v struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer); struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu); - if (!synic->active && !host) + if (!synic->active && (!host || count)) return 1; trace_kvm_hv_stimer_set_count(stimer_to_vcpu(stimer)->vcpu_id,