From nobody Sun Feb 8 22:58:27 2026 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 25556C433F5 for ; Fri, 25 Mar 2022 13:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353490AbiCYNXe (ORCPT ); Fri, 25 Mar 2022 09:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355495AbiCYNXb (ORCPT ); Fri, 25 Mar 2022 09:23:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E97B1D1CD0 for ; Fri, 25 Mar 2022 06:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648214516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aGcphh+FSCJkCtquixHZ+Ppqf8dAW6dwu2JqKDu/J40=; b=bQdIqX7d+6k/7g+4sPEb25j8DVrbCt55pZ3l1jlVoaUMjsH7iKLZHAFrf8THaeyNEikCI4 vlJ5NqI3KIMYXB4K/FxpHNrBMa5jLpj2GVeK/SK/5tLUTJz+rhgpOpCFzqCYoiQRiCKOxB bVLvGS7R78hU3N7y3GgJ8TdyGjMFBhE= 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-456-AWhCHrn_OLuKCMj93ui8aw-1; Fri, 25 Mar 2022 09:21:50 -0400 X-MC-Unique: AWhCHrn_OLuKCMj93ui8aw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E40802A59540; Fri, 25 Mar 2022 13:21:49 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.194.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BED52166B16; Fri, 25 Mar 2022 13:21:48 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated Date: Fri, 25 Mar 2022 14:21:40 +0100 Message-Id: <20220325132140.25650-4-vkuznets@redhat.com> In-Reply-To: <20220325132140.25650-1-vkuznets@redhat.com> References: <20220325132140.25650-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- arch/x86/kvm/hyperv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index a79a094c1266..123b677111c5 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -243,7 +243,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *syni= c, struct kvm_vcpu *vcpu =3D hv_synic_to_vcpu(synic); int ret; =20 - if (!synic->active && !host) + if (!synic->active && (!host || data)) return 1; =20 trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host); @@ -289,6 +289,9 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *syni= c, case HV_X64_MSR_EOM: { int i; =20 + if (!synic->active) + break; + for (i =3D 0; i < ARRAY_SIZE(synic->sint); i++) kvm_hv_notify_acked_sint(vcpu, i); break; @@ -668,7 +671,7 @@ static int stimer_set_config(struct kvm_vcpu_hv_stimer = *stimer, u64 config, struct kvm_vcpu_hv *hv_vcpu =3D to_hv_vcpu(vcpu); struct kvm_vcpu_hv_synic *synic =3D to_hv_synic(vcpu); =20 - if (!synic->active && !host) + if (!synic->active && (!host || config)) return 1; =20 if (unlikely(!host && hv_vcpu->enforce_cpuid && new_config.direct_mode && @@ -697,7 +700,7 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *= stimer, u64 count, struct kvm_vcpu *vcpu =3D hv_stimer_to_vcpu(stimer); struct kvm_vcpu_hv_synic *synic =3D to_hv_synic(vcpu); =20 - if (!synic->active && !host) + if (!synic->active && (!host || count)) return 1; =20 trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id, --=20 2.35.1