From: Wanpeng Li <kernellwp@gmail.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Subject: [PATCH v2 3/5] KVM: X86: setup residency msrs during vCPU creation
Date: Tue, 11 Jun 2019 15:34:09 +0800 [thread overview]
Message-ID: <1560238451-19495-4-git-send-email-wanpengli@tencent.com> (raw)
In-Reply-To: <1560238451-19495-1-git-send-email-wanpengli@tencent.com>
From: Wanpeng Li <wanpengli@tencent.com>
To setup core residency msrs during vCPU creation. Allowing guest reads
CORE cstate when exposing host CPU power management capabilities to the
guest. PKG cstate is restricted currently to avoid a guest to get the
whole package information in multi-tenant scenario.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
arch/x86/kvm/vmx/vmx.c | 2 ++
arch/x86/kvm/x86.c | 21 +++++++++++++++++++++
arch/x86/kvm/x86.h | 5 +++++
3 files changed, 28 insertions(+)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 4dc2459..2ebaa90 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6663,6 +6663,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
if (!vmx->vcpu.arch.core_cstate_msrs)
goto free_vmcs;
+ kvm_core_residency_setup(&vmx->vcpu);
+
if (nested)
nested_vmx_setup_ctls_msrs(&vmx->nested.msrs,
vmx_capability.ept,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 841a794..36905cd 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1376,6 +1376,16 @@ void kvm_residency_write(struct kvm_vcpu *vcpu,
}
EXPORT_SYMBOL_GPL(kvm_residency_write);
+static void kvm_residency_setup(struct kvm_vcpu *vcpu, struct kvm_residency_msr *msr,
+ u16 index, bool count_with_host)
+{
+ /* Preserve value on calls after the first */
+ u64 value = msr->index ? kvm_residency_read(vcpu, msr->index) : 0;
+ msr->delta_from_host = msr->count_with_host = count_with_host;
+ msr->index = index;
+ kvm_residency_write(vcpu, msr->index, value);
+}
+
/*
* Writes msr value into into the appropriate "register".
* Returns 0 on success, non-0 otherwise.
@@ -3311,6 +3321,17 @@ static bool need_emulate_wbinvd(struct kvm_vcpu *vcpu)
return kvm_arch_has_noncoherent_dma(vcpu->kvm);
}
+void kvm_core_residency_setup(struct kvm_vcpu *vcpu)
+{
+ kvm_residency_setup(vcpu, &vcpu->arch.core_cstate_msrs[0],
+ MSR_CORE_C3_RESIDENCY, kvm_mwait_in_guest(vcpu->kvm));
+ kvm_residency_setup(vcpu, &vcpu->arch.core_cstate_msrs[1],
+ MSR_CORE_C6_RESIDENCY, kvm_mwait_in_guest(vcpu->kvm));
+ kvm_residency_setup(vcpu, &vcpu->arch.core_cstate_msrs[2],
+ MSR_CORE_C7_RESIDENCY, kvm_mwait_in_guest(vcpu->kvm));
+}
+EXPORT_SYMBOL_GPL(kvm_core_residency_setup);
+
void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
{
/* Address WBINVD may be executed by guest */
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index dc61dbd..123fc8d 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -284,6 +284,11 @@ bool kvm_vector_hashing_enabled(void);
int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2,
int emulation_type, void *insn, int insn_len);
+u64 kvm_residency_read(struct kvm_vcpu *vcpu, u32 msr_index);
+void kvm_residency_write(struct kvm_vcpu *vcpu,
+ u32 msr_index, u64 value);
+void kvm_core_residency_setup(struct kvm_vcpu *vcpu);
+
#define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \
| XFEATURE_MASK_YMM | XFEATURE_MASK_BNDREGS \
| XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \
--
2.7.4
next prev parent reply other threads:[~2019-06-11 7:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-11 7:34 [PATCH v2 0/5] KVM: X86: Add virtual C-states residency msrs support Wanpeng Li
2019-06-11 7:34 ` [PATCH v2 1/5] KVM: X86: Dynamic allocate core residency msr state Wanpeng Li
2019-06-12 16:01 ` Sean Christopherson
2019-06-13 0:43 ` Wanpeng Li
2019-06-11 7:34 ` [PATCH v2 2/5] KVM: X86: Introduce residency msrs read/write operations Wanpeng Li
2019-06-11 7:34 ` Wanpeng Li [this message]
2019-06-11 7:34 ` [PATCH v2 4/5] KVM: VMX: Add get/set residency msrs logic Wanpeng Li
2019-06-11 7:34 ` [PATCH v2 5/5] KVM: X86: Save/restore residency values when vCPU migrations Wanpeng Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1560238451-19495-4-git-send-email-wanpengli@tencent.com \
--to=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).