Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp791111pxb; Thu, 15 Apr 2021 06:45:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6HnEUsWGakxczArNQScGLQQpZsQsQFhl5QIcep4MnJkT+pwcpBIjwBGJhBg1minw5Py/b X-Received: by 2002:a17:90b:3b81:: with SMTP id pc1mr3988038pjb.111.1618494344476; Thu, 15 Apr 2021 06:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618494344; cv=none; d=google.com; s=arc-20160816; b=sm76aQGbXt+4YLnYWI70NxqR1m7dN9TnyJCKtBH4MYFP3fKKkd7yTb9NEQsGZktORD 4H4JsG0iMEGJ+a0kOKPGXVaY0HQN2VQoAhxGoUTqujoYcP5+uizH1o+S4RTt5R706StF Yh5oAH5S5Dvv8Kc8xRSIGXPD+Ulbd2JFNN0tuCbMt1qRyz9X049rbxI4eRPCDbn5mEdc 5hC52BLRdkTMYtmYiHgr5L6Z3M3dxa4EAWt3L9B/KWE346Sh0DBwxo8foe+s8p/7hPk5 oZSiDYK+rhg1yvIpuSo7QLQ7jvnPzWbCZVIlYJAS8cVImzVm4RLrmTXhU7aaPKkcxCJd a/TQ== 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:dkim-filter; bh=NSl4mmuN0fWV7X9bel04RUo28vwYage3zxPQZMAmy78=; b=nkxZ/e+W96II9xVbY4nzUXbjORG61bz7ap/KN2bkmqYovC1W/cyace3hL+Nj0ZaSXq nwA+aDzH+Cj4qfFuMrkb1MNMf9A6jAlr1bWydIk9laUUffd+6aZNNUr5dymaELQP7Bgn a+k/43YeDqe7G4F1b+/THPA8Fzq2Kj5aVZSTMaSWPGtxhxfrv1P+m7YiGRi9aPy7Rbfe OXetUZBBIiEYnGGsJdgstIDbNFIprMGHilXd0G/1ZrxwiNUdHax+zdxyNzqElXfRCpJ9 A9WEp31PykXIBaOKXE0wFvANvHnxX5wsyToGXXrtRBcpSQbyHDKL94hzsFpCdAlkWeqj HoyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=LKf9rmUT; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r10si3073269pff.291.2021.04.15.06.45.31; Thu, 15 Apr 2021 06:45:44 -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=@linux.microsoft.com header.s=default header.b=LKf9rmUT; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233490AbhDONoq (ORCPT + 99 others); Thu, 15 Apr 2021 09:44:46 -0400 Received: from linux.microsoft.com ([13.77.154.182]:41626 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233410AbhDONoW (ORCPT ); Thu, 15 Apr 2021 09:44:22 -0400 Received: from viremana-dev.fwjladdvyuiujdukmejncen4mf.xx.internal.cloudapp.net (unknown [13.66.132.26]) by linux.microsoft.com (Postfix) with ESMTPSA id 2D58020B83E8; Thu, 15 Apr 2021 06:43:58 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2D58020B83E8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1618494238; bh=NSl4mmuN0fWV7X9bel04RUo28vwYage3zxPQZMAmy78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LKf9rmUTqE3FYM0jHIfhZfR9KL8EZj+xeWInM3WdjT28AKqwxw/KEubg585eNNmWI H4/OMcqu4MAelUdnxQq+T8FoIbU4SLCNRxmwQ5122MzT0eakfVdOYgF+abrOjYumLa 2WgGwi5nXq4oa7W6UVrWxe4fpaOa+4G85XI2Kh/c= From: Vineeth Pillai To: Lan Tianyu , Michael Kelley , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Wei Liu , Stephen Hemminger , Haiyang Zhang Cc: Vineeth Pillai , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "K. Y. Srinivasan" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Subject: [PATCH v2 6/7] KVM: SVM: hyper-v: Enlightened MSR-Bitmap support Date: Thu, 15 Apr 2021 13:43:41 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enlightened MSR-Bitmap as per TLFS: "The L1 hypervisor may collaborate with the L0 hypervisor to make MSR accesses more efficient. It can enable enlightened MSR bitmaps by setting the corresponding field in the enlightened VMCS to 1. When enabled, L0 hypervisor does not monitor the MSR bitmaps for changes. Instead, the L1 hypervisor must invalidate the corresponding clean field after making changes to one of the MSR bitmaps." Enable this for SVM. Related VMX changes: commit ceef7d10dfb6 ("KVM: x86: VMX: hyper-v: Enlightened MSR-Bitmap support") Signed-off-by: Vineeth Pillai --- arch/x86/kvm/svm/svm.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index de141d5ae5fb..f59f03b5c722 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -649,6 +649,27 @@ static bool msr_write_intercepted(struct kvm_vcpu *vcpu, u32 msr) return !!test_bit(bit_write, &tmp); } +#if IS_ENABLED(CONFIG_HYPERV) +static inline void hv_vmcb_dirty_nested_enlightenments(struct kvm_vcpu *vcpu) +{ + struct vmcb *vmcb = to_svm(vcpu)->vmcb; + + /* + * vmcb can be NULL if called during early vcpu init. + * And its okay not to mark vmcb dirty during vcpu init + * as we mark it dirty unconditionally towards end of vcpu + * init phase. + */ + if (vmcb && vmcb_is_clean(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS) && + vmcb->hv_enlightenments.hv_enlightenments_control.msr_bitmap) + vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS); +} +#else +static inline void hv_vmcb_dirty_nested_enlightenments(struct kvm_vcpu *vcpu) +{ +} +#endif + static void set_msr_interception_bitmap(struct kvm_vcpu *vcpu, u32 *msrpm, u32 msr, int read, int write) { @@ -680,6 +701,9 @@ static void set_msr_interception_bitmap(struct kvm_vcpu *vcpu, u32 *msrpm, write ? clear_bit(bit_write, &tmp) : set_bit(bit_write, &tmp); msrpm[offset] = tmp; + + hv_vmcb_dirty_nested_enlightenments(vcpu); + } void set_msr_interception(struct kvm_vcpu *vcpu, u32 *msrpm, u32 msr, @@ -1143,6 +1167,9 @@ static void hv_init_vmcb(struct vmcb *vmcb) if (npt_enabled && ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) hve->hv_enlightenments_control.enlightened_npt_tlb = 1; + + if (ms_hyperv.nested_features & HV_X64_NESTED_MSR_BITMAP) + hve->hv_enlightenments_control.msr_bitmap = 1; } #else static inline void hv_init_vmcb(struct vmcb *vmcb) -- 2.25.1