From: Wanpeng Li <kernellwp@gmail.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>
Subject: [PATCH RESEND 4/5] x86/kvm: Add MSR_KVM_PREEMPT_COUNT guest support
Date: Fri, 25 Mar 2022 06:58:28 -0700 [thread overview]
Message-ID: <1648216709-44755-5-git-send-email-wanpengli@tencent.com> (raw)
In-Reply-To: <1648216709-44755-1-git-send-email-wanpengli@tencent.com>
From: Wanpeng Li <wanpengli@tencent.com>
The x86 guest passes the per-cpu preempt_count value to the hypervisor,
so the hypervisor knows whether the guest is running in the critical
section.
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
arch/x86/kernel/kvm.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 21933095a10e..e389fa4393ae 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -366,6 +366,14 @@ static void kvm_guest_cpu_init(void)
if (has_steal_clock)
kvm_register_steal_time();
+
+ if (kvm_para_has_feature(KVM_FEATURE_PREEMPT_COUNT)) {
+ u64 pa = slow_virt_to_phys(this_cpu_ptr(&__preempt_count))
+ | KVM_MSR_ENABLED;
+ wrmsrl(MSR_KVM_PREEMPT_COUNT, pa);
+
+ pr_debug("setup pv preempt_count: cpu %d\n", smp_processor_id());
+ }
}
static void kvm_pv_disable_apf(void)
@@ -442,6 +450,8 @@ static void kvm_guest_cpu_offline(bool shutdown)
if (!shutdown)
apf_task_wake_all();
kvmclock_disable();
+ if (kvm_para_has_feature(KVM_FEATURE_PREEMPT_COUNT))
+ wrmsrl(MSR_KVM_PREEMPT_COUNT, 0);
}
static int kvm_cpu_online(unsigned int cpu)
--
2.25.1
next prev parent reply other threads:[~2022-03-25 13:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-25 13:58 [PATCH RESEND 0/5] KVM: X86: Scaling Guest OS Critical Sections with boosting Wanpeng Li
2022-03-25 13:58 ` [PATCH RESEND 1/5] KVM: X86: Add MSR_KVM_PREEMPT_COUNT support Wanpeng Li
2022-03-25 13:58 ` [PATCH RESEND 2/5] KVM: X86: Add guest interrupt disable state support Wanpeng Li
2022-03-30 0:04 ` Sean Christopherson
2022-03-30 1:17 ` Wanpeng Li
2022-03-31 22:00 ` Sean Christopherson
2022-04-01 1:36 ` Wanpeng Li
2022-03-25 13:58 ` [PATCH RESEND 3/5] KVM: X86: Boost vCPU which is in critical section Wanpeng Li
2022-03-30 0:07 ` Sean Christopherson
2022-03-30 1:18 ` Wanpeng Li
2022-03-25 13:58 ` Wanpeng Li [this message]
2022-03-25 13:58 ` [PATCH RESEND 5/5] KVM: X86: Expose PREEMT_COUNT CPUID feature bit to guest 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=1648216709-44755-5-git-send-email-wanpengli@tencent.com \
--to=kernellwp@gmail.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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
all inboxes | Powered by JetHome®