From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduardo Habkost Subject: Re: [PATCH RESEND v2] i386/kvm: add support for KVM_CAP_X86_DISABLE_EXITS Date: Tue, 17 Apr 2018 17:59:13 -0300 Message-ID: <20180417205913.GC29865@localhost.localdomain> References: <1523953455-28053-1-git-send-email-wanpengli@tencent.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: Paolo Bonzini , qemu-devel@nongnu.org, kvm@vger.kernel.org, Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Return-path: Content-Disposition: inline In-Reply-To: <1523953455-28053-1-git-send-email-wanpengli@tencent.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel2=m.gmane.org@nongnu.org Sender: "Qemu-devel" List-Id: kvm.vger.kernel.org On Tue, Apr 17, 2018 at 01:24:15AM -0700, Wanpeng Li wrote: > From: Wanpeng Li >=20 > This patch adds support for KVM_CAP_X86_DISABLE_EXITS. Provides userspa= ce with=20 > per-VM capability(KVM_CAP_X86_DISABLE_EXITS) to not intercept MWAIT/HLT= /PAUSE=20 > in order that to improve latency in some workloads. >=20 > Cc: Paolo Bonzini > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 =20 > Cc: Eduardo Habkost > Signed-off-by: Wanpeng Li > --- >=20 > linux-headers/linux/kvm.h | 6 +++++- > target/i386/cpu.h | 2 ++ > target/i386/kvm.c | 16 ++++++++++++++++ > 3 files changed, 23 insertions(+), 1 deletion(-) >=20 > diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h > index a167be8..857df15 100644 > --- a/linux-headers/linux/kvm.h > +++ b/linux-headers/linux/kvm.h > @@ -925,7 +925,7 @@ struct kvm_ppc_resize_hpt { > #define KVM_CAP_S390_GS 140 > #define KVM_CAP_S390_AIS 141 > #define KVM_CAP_SPAPR_TCE_VFIO 142 > -#define KVM_CAP_X86_GUEST_MWAIT 143 > +#define KVM_CAP_X86_DISABLE_EXITS 143 > #define KVM_CAP_ARM_USER_IRQ 144 > #define KVM_CAP_S390_CMMA_MIGRATION 145 > #define KVM_CAP_PPC_FWNMI 146 > @@ -1508,6 +1508,10 @@ struct kvm_assigned_msix_entry { > #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0) > #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1) > =20 > +#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0) > +#define KVM_X86_DISABLE_EXITS_HLT (1 << 1) > +#define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2) > + > /* Available with KVM_CAP_ARM_USER_IRQ */ > =20 > /* Bits for run->s.regs.device_irq_level */ > diff --git a/target/i386/cpu.h b/target/i386/cpu.h > index 1b219fa..965de1b 100644 > --- a/target/i386/cpu.h > +++ b/target/i386/cpu.h > @@ -685,6 +685,8 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; > #define CPUID_7_0_EDX_AVX512_4FMAPS (1U << 3) /* AVX512 Multiply Accum= ulation Single Precision */ > #define CPUID_7_0_EDX_SPEC_CTRL (1U << 26) /* Speculation Control = */ > =20 > +#define KVM_PV_UNHALT (1U << 7) > + > #define KVM_HINTS_DEDICATED (1U << 0) > =20 > #define CPUID_8000_0008_EBX_IBPB (1U << 12) /* Indirect Branch Pred= iction Barrier */ > diff --git a/target/i386/kvm.c b/target/i386/kvm.c > index 6c49954..3e99830 100644 > --- a/target/i386/kvm.c > +++ b/target/i386/kvm.c > @@ -1029,6 +1029,22 @@ int kvm_arch_init_vcpu(CPUState *cs) > } > } > =20 > + if (env->features[FEAT_KVM_HINTS] & KVM_HINTS_DEDICATED) { > + int disable_exits =3D kvm_check_extension(cs->kvm_state, KVM_C= AP_X86_DISABLE_EXITS); > + > + if (disable_exits) { > + disable_exits &=3D (KVM_X86_DISABLE_EXITS_MWAIT | > + KVM_X86_DISABLE_EXITS_HLT | > + KVM_X86_DISABLE_EXITS_PAUSE); > + if (env->user_features[FEAT_KVM] & KVM_PV_UNHALT) { > + disable_exits &=3D ~KVM_X86_DISABLE_EXITS_HLT; > + } In the future, if we decide to enable kvm-pv-unhalt by default, should "-cpu ...,kvm-hint-dedicated=3Don" disable kvm-pv-unhalt automatically, or should we require an explicit "kvm-hint-dedicated=3Don,kvm-pv-unhalt=3Doff" option? For today's defaults, this patch solves the problem, only one thing is missing before I give my R-b: we need to clearly document what exactly are the consequences and requirements of setting kvm-hint-dedicated=3Don (I'm not sure if the best place for this is qemu-options.hx, x86_cpu_list(), or somewhere else). > + } > + if (kvm_vm_enable_cap(cs->kvm_state, KVM_CAP_X86_DISABLE_EXITS= , 0, disable_exits)) { > + error_report("kvm: DISABLE EXITS not supported"); > + } > + } > + > qemu_add_vm_change_state_handler(cpu_update_state, env); > =20 > c =3D cpuid_find_entry(&cpuid_data.cpuid, 1, 0); > --=20 > 2.7.4 >=20 --=20 Eduardo