From: "Longpeng (Mike)" <longpeng2@huawei.com>
To: "\"Jan H. Schönherr\"" <jschoenh@amazon.de>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Joerg Roedel" <joro@8bytes.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"KarimAllah Ahmed" <karahmed@amazon.de>,
kvm@vger.kernel.org
Subject: Re: [PATCH 3/3] KVM: Add capability to not exit on PAUSE
Date: Tue, 28 Nov 2017 11:37:00 +0800 [thread overview]
Message-ID: <5A1CD9DC.7050804@huawei.com> (raw)
In-Reply-To: <1511615373-32615-4-git-send-email-jschoenh@amazon.de>
On 2017/11/25 21:09, Jan H. Schönherr wrote:
> Allow to disable pause loop exit/pause filtering on a per VM basis.
>
> If some VMs have dedicated host CPUs, they won't be negatively affected
> due to needlessly intercepted PAUSE instructions.
>
Hi Jan,
Is there any difference between 'disable PLE in vmcs' and 'make ple_gap per
VM/VCPU and set ple_gap=0 for vcpus which is dedicated' ?
> Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de>
> ---
> Note: AMD code paths are only compile tested
> ---
> Documentation/virtual/kvm/api.txt | 8 ++++++++
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/svm.c | 3 ++-
> arch/x86/kvm/vmx.c | 17 +++++++++++++----
> arch/x86/kvm/x86.c | 5 +++++
> arch/x86/kvm/x86.h | 5 +++++
> include/uapi/linux/kvm.h | 1 +
> 7 files changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
> index c06bb41..42a54d1 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -4184,6 +4184,14 @@ This capability indicates that a guest using HLT to stop a virtual CPU will not
> cause a VM exit. As such, time spent while a virtual CPU is halted in this way
> will then be accounted for as guest running time on the host.
>
> +7.15 KVM_CAP_X86_GUEST_PAUSE
> +
> +Architectures: x86
> +Parameters: none
> +Returns: 0 on success
> +
> +This capability indicates that a guest using PAUSE will not cause a VM exit.
> +
> 8. Other capabilities.
> ----------------------
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 3197c2d..0d4ea32 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -782,6 +782,7 @@ struct kvm_arch {
> gpa_t wall_clock;
>
> bool hlt_in_guest;
> + bool pause_in_guest;
> bool mwait_in_guest;
>
> bool ept_identity_pagetable_done;
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index c135b98..a5eb60a 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1314,7 +1314,8 @@ static void init_vmcb(struct vcpu_svm *svm)
> svm->nested.vmcb = 0;
> svm->vcpu.arch.hflags = 0;
>
> - if (boot_cpu_has(X86_FEATURE_PAUSEFILTER)) {
> + if (boot_cpu_has(X86_FEATURE_PAUSEFILTER) &&
> + !kvm_pause_in_guest(svm->vcpu.kvm)) {
> control->pause_filter_count = 3000;
> set_intercept(svm, INTERCEPT_PAUSE);
> }
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 1b67433..5f8c33b 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -5352,7 +5352,7 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)
> }
> if (!enable_unrestricted_guest)
> exec_control &= ~SECONDARY_EXEC_UNRESTRICTED_GUEST;
> - if (!ple_gap)
> + if (kvm_pause_in_guest(vmx->vcpu.kvm))
> exec_control &= ~SECONDARY_EXEC_PAUSE_LOOP_EXITING;
> if (!kvm_vcpu_apicv_active(vcpu))
> exec_control &= ~(SECONDARY_EXEC_APIC_REGISTER_VIRT |
> @@ -5519,7 +5519,7 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
> vmcs_write64(POSTED_INTR_DESC_ADDR, __pa((&vmx->pi_desc)));
> }
>
> - if (ple_gap) {
> + if (!kvm_pause_in_guest(vmx->vcpu.kvm)) {
> vmcs_write32(PLE_GAP, ple_gap);
> vmx->ple_window = ple_window;
> vmx->ple_window_dirty = true;
> @@ -6975,7 +6975,7 @@ static __exit void hardware_unsetup(void)
> */
> static int handle_pause(struct kvm_vcpu *vcpu)
> {
> - if (ple_gap)
> + if (!kvm_pause_in_guest(vcpu->kvm))
> grow_ple_window(vcpu);
>
> /*
> @@ -9730,6 +9730,13 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
> return ERR_PTR(err);
> }
>
> +static int vmx_vm_init(struct kvm *kvm)
> +{
> + if (!ple_gap)
> + kvm->arch.pause_in_guest = true;
> + return 0;
> +}
> +
> static void __init vmx_check_processor_compat(void *rtn)
> {
> struct vmcs_config vmcs_conf;
> @@ -11793,7 +11800,7 @@ static void vmx_cancel_hv_timer(struct kvm_vcpu *vcpu)
>
> static void vmx_sched_in(struct kvm_vcpu *vcpu, int cpu)
> {
> - if (ple_gap)
> + if (!kvm_pause_in_guest(vcpu->kvm))
> shrink_ple_window(vcpu);
> }
>
> @@ -12152,6 +12159,8 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = {
> .cpu_has_accelerated_tpr = report_flexpriority,
> .cpu_has_high_real_mode_segbase = vmx_has_high_real_mode_segbase,
>
> + .vm_init = vmx_vm_init,
> +
> .vcpu_create = vmx_create_vcpu,
> .vcpu_free = vmx_free_vcpu,
> .vcpu_reset = vmx_vcpu_reset,
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f17c520..e13df00 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2756,6 +2756,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> case KVM_CAP_SPLIT_IRQCHIP:
> case KVM_CAP_IMMEDIATE_EXIT:
> case KVM_CAP_X86_GUEST_HLT:
> + case KVM_CAP_X86_GUEST_PAUSE:
> r = 1;
> break;
> case KVM_CAP_ADJUST_CLOCK:
> @@ -4073,6 +4074,10 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> kvm->arch.hlt_in_guest = true;
> r = 0;
> break;
> + case KVM_CAP_X86_GUEST_PAUSE:
> + kvm->arch.pause_in_guest = true;
> + r = 0;
> + break;
> default:
> r = -EINVAL;
> break;
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index b2066aa..56297c4 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -271,4 +271,9 @@ static inline bool kvm_hlt_in_guest(struct kvm *kvm)
> return kvm->arch.hlt_in_guest;
> }
>
> +static inline bool kvm_pause_in_guest(struct kvm *kvm)
> +{
> + return kvm->arch.pause_in_guest;
> +}
> +
> #endif
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index ff8f266..bc2b654 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -933,6 +933,7 @@ struct kvm_ppc_resize_hpt {
> #define KVM_CAP_HYPERV_VP_INDEX 149
> #define KVM_CAP_S390_AIS_MIGRATION 150
> #define KVM_CAP_X86_GUEST_HLT 151
> +#define KVM_CAP_X86_GUEST_PAUSE 152
>
> #ifdef KVM_CAP_IRQ_ROUTING
>
--
Regards,
Longpeng(Mike)
next prev parent reply other threads:[~2017-11-28 3:37 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-25 13:09 [PATCH 0/3] KVM: Tie MWAIT/HLT/PAUSE interception to initially disabled capabilities Jan H. Schönherr
2017-11-25 13:09 ` [PATCH 1/3] KVM: Don't enable MWAIT in guest by default Jan H. Schönherr
2017-11-27 18:13 ` Jim Mattson
[not found] ` <82e1f7c8-fdd6-835e-319a-bec72d771ef9@redhat.com>
2017-11-27 18:32 ` Jim Mattson
2017-11-28 23:58 ` Jan H. Schönherr
2017-11-29 16:58 ` Radim Krčmář
2017-11-27 20:46 ` Michael S. Tsirkin
2017-11-27 22:36 ` Jan H. Schönherr
2017-11-28 14:00 ` Michael S. Tsirkin
2017-11-27 20:50 ` Michael S. Tsirkin
[not found] ` <90f7f081-95d7-f573-8b57-5c6e86fd2a8d@redhat.com>
2017-11-27 20:57 ` Michael S. Tsirkin
2017-11-25 13:09 ` [PATCH 2/3] KVM: Add capability to not exit on HLT Jan H. Schönherr
2017-11-27 1:32 ` Wanpeng Li
2017-11-27 1:47 ` Wanpeng Li
[not found] ` <a2f4cf7f-5d7b-a1cc-30d5-d18df4d49173@redhat.com>
2017-11-27 12:29 ` Jan H. Schönherr
[not found] ` <421c71fd-6dff-c01e-9e78-42f114711ea9@redhat.com>
2017-11-27 15:27 ` Jan H. Schönherr
[not found] ` <e17ea420-c141-18b6-2622-e33a3f540c61@redhat.com>
2017-11-27 16:12 ` Jan H. Schönherr
2017-11-27 20:45 ` Michael S. Tsirkin
[not found] ` <8ce45bad-b43c-4e97-aa69-74d7fc9cecb5@redhat.com>
2017-11-27 20:55 ` Michael S. Tsirkin
2017-11-28 1:34 ` Longpeng (Mike)
2017-11-28 14:04 ` Michael S. Tsirkin
2017-11-25 13:09 ` [PATCH 3/3] KVM: Add capability to not exit on PAUSE Jan H. Schönherr
2017-11-27 20:48 ` Michael S. Tsirkin
2017-11-28 3:37 ` Longpeng (Mike) [this message]
2017-11-29 0:09 ` Jan H. Schönherr
2017-11-29 4:34 ` Longpeng (Mike)
2017-11-29 12:20 ` Jan H. Schönherr
[not found] ` <a3c80a22-ff69-fa51-ea90-48f039eb449a@redhat.com>
2017-11-28 0:15 ` [PATCH 0/3] KVM: Tie MWAIT/HLT/PAUSE interception to initially disabled capabilities Jan H. Schönherr
[not found] ` <8971d9e0-388c-9934-1ab2-33508cbbeb8f@redhat.com>
2017-11-28 10:42 ` Jan H. Schönherr
2017-11-28 14:08 ` Michael S. Tsirkin
[not found] ` <e61d93f0-17d9-d182-83ae-b7165ae3dcb0@redhat.com>
2017-11-29 0:20 ` Michael S. Tsirkin
2017-11-29 0:24 ` Michael S. Tsirkin
[not found] ` <8e559062-e459-5a85-a4a3-72a4baf7764c@redhat.com>
2017-11-29 15:13 ` Michael S. Tsirkin
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=5A1CD9DC.7050804@huawei.com \
--to=longpeng2@huawei.com \
--cc=joro@8bytes.org \
--cc=jschoenh@amazon.de \
--cc=karahmed@amazon.de \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--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