From: Aili Yao <yaoaili@xxxxxxxxxxxx> When we isolate some pyhiscal cores, We may not use them for kvm guests, We may use them for other purposes like DPDK, or we can make some kvm guests isolated and some not, the global judgement pi_inject_timer is not enough; We may make wrong decisions: In such a scenario, the guests without isolated cores will not be permitted to use vmx preemption timer, and tscdeadline fastpath also be disabled, both will lead to performance penalty. So check whether the vcpu->cpu is isolated, if not, don't post timer interrupt. And when qemu enable -cpu-pm feature for guests, all the available disable_exit will be set, including mwait,halt,pause,cstate, when this operation succeed, hlt_in_guest,pause_in_guest,cstate_in_guest will all be definitly set true with one special case, mwait_in_guest, this feature's enablement is depended on the HOST cpu feature support; When cpu-pm is successfully enabled, and hlt_in_guest is true and mwait_in_guest is false, the guest cant't use Monitor/Mwait instruction for idle operation, instead, the guest may use halt for that purpose, as we have enable the cpu-pm feature and hlt_in_guest is true, we will also minimize the guest exit; For such a scenario, Monitor/Mwait instruction support is totally disabled, the guest has no way to use Mwait to exit from non-root mode; For cpu-pm feature, hlt_in_guest and others except mwait_in_guest will be a good hint for it. So replace it with hlt_in_guest. Signed-off-by: Aili Yao <yaoaili@xxxxxxxxxxxx> --- arch/x86/kvm/lapic.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 759952dd1222..42aef1accd6b 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -34,6 +34,7 @@ #include <asm/delay.h> #include <linux/atomic.h> #include <linux/jump_label.h> +#include <linux/sched/isolation.h> #include "kvm_cache_regs.h" #include "irq.h" #include "ioapic.h" @@ -113,13 +114,14 @@ static inline u32 kvm_x2apic_id(struct kvm_lapic *apic) static bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu) { - return pi_inject_timer && kvm_vcpu_apicv_active(vcpu); + return pi_inject_timer && kvm_vcpu_apicv_active(vcpu) && + !housekeeping_cpu(vcpu->cpu, HK_FLAG_TIMER); } bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu) { return kvm_x86_ops.set_hv_timer - && !(kvm_mwait_in_guest(vcpu->kvm) || + && !(kvm_hlt_in_guest(vcpu->kvm) || kvm_can_post_timer_interrupt(vcpu)); } EXPORT_SYMBOL_GPL(kvm_can_use_hv_timer); -- 2.25.1