Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2818582pxb; Tue, 13 Apr 2021 10:52:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM6ANKl4PdFLDiZUyZ/fC/8krDzhYAWAXW2wfkQnwQ8Y++di+QfmWrAmGNOBHYIi3ZQ9A9 X-Received: by 2002:a17:906:c143:: with SMTP id dp3mr32015135ejc.499.1618336378512; Tue, 13 Apr 2021 10:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618336378; cv=none; d=google.com; s=arc-20160816; b=TX4KdUwsEM6txWB7JAXdhbUYwahkOW3NmnHNPhssk7tvrh3LrXA0chS1Bc9IT9ZV3r r4b4yZIUWw2R4iHH+eMGjF6fcPNhVAHR+5YyNO7+Kfn6AlupJ7K2RRU6Xmqq/spKSBx6 9kbjl8Wk5dfQ/cXVYsqXiQiS07K8ymQ/y3itoL9KfuUFH9VUuO0KscwK+mHTkHdfYUH+ gUWLfDivkgixGW6hRJIOc4epjUc3ggapbt2HblGiEforY8mWYoKm6VEoNTSdJMYq07AP Q/4ZpF2U5rNR37RF5E2duMj+j+uVJyw3bFCbMq4w8meMkZMrNqbUeSMMzqyRxmmlcLi8 KqRA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nN+KjQNXh47kMIiCTZej4CSQDx8Hemm8xXr2LbcGx30=; b=mz9S8BGwAACgj9Ged8aTMLk0CtwnfSsCg8ugvQ2BjR15wKCCiGiNP7ljhxuo7hyOOy U5AP2F5g7ZTwyicsPcdpd28kotqQfA91PWyePJh1QIDJ/e+32ioSvWj1vwPyu81X7/fK w+xWKUO/Up+2sdI4CwoJN2UJ/xBCN2lt6HM+NBEQmKKThRD7c47igT9Y3paUAbeM0oDN ws8TrhiXuIjs49EmJwirvgAcrJDtxMuQ0dcU3CwCNPGugH0pVrMMh5VWNCrZCbSvZ9X1 GakF1RwxLQ0hQEJ9GHGQnWOgwpxyeqZl5mNHUxQur6+F/69c8FIzSSCk+CoMcFDXANnH JSGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VeOGBuUV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v21si11449198ejg.244.2021.04.13.10.52.35; Tue, 13 Apr 2021 10:52:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VeOGBuUV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345770AbhDMM2R (ORCPT + 99 others); Tue, 13 Apr 2021 08:28:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57088 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345634AbhDMM1f (ORCPT ); Tue, 13 Apr 2021 08:27:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618316835; 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=nN+KjQNXh47kMIiCTZej4CSQDx8Hemm8xXr2LbcGx30=; b=VeOGBuUVsFbNMO/ft/n/6n3ffcgwjSzJSGCt3Cxpoh/6yCg76YNJ3sqoKIY7AcMMFZwsY8 fW+WF8bwlF1/lRraBlqhJ6eEO18nImIhI76FOsgSJHBpk3v9Yi0YtsJTuwLyObT04ka1hq 4GTR/2x4DuQWXwJvcMHDRTzmyRjalsQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-15-V2wxoPDpOlGZZoYvLeUrYQ-1; Tue, 13 Apr 2021 08:27:12 -0400 X-MC-Unique: V2wxoPDpOlGZZoYvLeUrYQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 240C719611A0; Tue, 13 Apr 2021 12:27:11 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B61E60C04; Tue, 13 Apr 2021 12:27:08 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Siddharth Chandrasekaran , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Subject: [PATCH RFC 11/22] KVM: x86: hyper-v: Honor HV_MSR_APIC_ACCESS_AVAILABLE privilege bit Date: Tue, 13 Apr 2021 14:26:19 +0200 Message-Id: <20210413122630.975617-12-vkuznets@redhat.com> In-Reply-To: <20210413122630.975617-1-vkuznets@redhat.com> References: <20210413122630.975617-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HV_X64_MSR_EOI, HV_X64_MSR_ICR, HV_X64_MSR_TPR, and HV_X64_MSR_VP_ASSIST_PAGE are only available to guest when HV_MSR_APIC_ACCESS_AVAILABLE bit is exposed. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 032305ad5615..9c4454873e00 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1401,6 +1401,10 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host) u64 gfn; unsigned long addr; + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + if (!(data & HV_X64_MSR_VP_ASSIST_PAGE_ENABLE)) { hv_vcpu->hv_vapic = data; if (kvm_lapic_enable_pv_eoi(vcpu, 0, 0)) @@ -1428,10 +1432,22 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host) break; } case HV_X64_MSR_EOI: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data); case HV_X64_MSR_ICR: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data); case HV_X64_MSR_TPR: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data); case HV_X64_MSR_VP_RUNTIME: if (!host) @@ -1564,12 +1580,28 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, data = hv_vcpu->vp_index; break; case HV_X64_MSR_EOI: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata); case HV_X64_MSR_ICR: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata); case HV_X64_MSR_TPR: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata); case HV_X64_MSR_VP_ASSIST_PAGE: + if (unlikely(!host && !(hv_vcpu->cpuid_cache.features_eax & + HV_MSR_APIC_ACCESS_AVAILABLE))) + return 1; + data = hv_vcpu->hv_vapic; break; case HV_X64_MSR_VP_RUNTIME: -- 2.30.2