[PATCH] KVM: MMU: Introduce single thread to zap collapsible sptes

2018-12-05 Thread Wanpeng Li
From: Wanpeng Li Last year guys from huawei reported that the call of memory_global_dirty_log_start/stop() takes 13s for 4T memory and cause guest freeze too long which increases the unacceptable migration downtime. [1] [2] Guangrong pointed out: | collapsible_sptes zaps 4k mappings

Re: KASAN: use-after-free Read in kvm_write_guest_offset_cached

2018-11-26 Thread Wanpeng Li
On Tue, 27 Nov 2018 at 12:51, syzbot wrote: > > Hello, Is there beauty C codes? Regards, Wanpeng Li > > syzbot found the following crash on: > > HEAD commit:442b8cea2477 Add linux-next specific files for 20181109 > git tree: linux-next > console output: https

[PATCH] KVM: X86: Fix scan ioapic use-before-initialization

2018-11-20 Thread Wanpeng Li
From: Wanpeng Li Reported by syzkaller: BUG: unable to handle kernel NULL pointer dereference at 01c8 PGD 8003ec4da067 P4D 8003ec4da067 PUD 3f7bfa067 PMD 0 Oops: [#1] PREEMPT SMP PTI CPU: 7 PID: 5059 Comm: debug Tainted: G OE 4.19.0-rc5 #16 RIP: 0010

[PATCH] KVM: LAPIC: Fix pv ipis use-before-initialization

2018-11-19 Thread Wanpeng Li
xes it by checking whether or not apic map is NULL and bailing out immediately if that is the case. Fixes: 4180bf1b65 (KVM: X86: Implement "send IPI" hypercall) Reported-by: Wei Wu Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Wei Wu Signed-off-by: Wanpeng Li --- arch/x86/kvm/lapic.c | 5

Re: [PATCH v4] x86: load FPU registers on return to userland

2018-11-11 Thread Wanpeng Li
g the registers if the task stays in kernel and does > not return to userland > - make kernel_fpu_begin() cheaper: it only saves the registers on the > first invocation. The second invocation does not need save them again. > Do you have any performance data? Regards, Wanpeng Li &g

Re: [PATCH] KVM: VMX: enable nested virtualization by default

2018-10-16 Thread Wanpeng Li
mostly nested = 0; > +static bool __read_mostly nested = 1; Really cool, a milestone for nested. :) Regards, Wanpeng Li

Re: [PATCH] KVM: LAPIC: Tune lapic_timer_advance_ns automatically

2018-10-08 Thread Wanpeng Li
On Mon, 8 Oct 2018 at 20:04, Liran Alon wrote: > > > > > On 8 Oct 2018, at 13:59, Wanpeng Li wrote: > > > > On Mon, 8 Oct 2018 at 05:02, Liran Alon wrote: > >> > >> > >> > >>> On 28 Sep 2018, at 9:12, Wanpeng Li wro

[PATCH v2] KVM: LAPIC: Tune lapic_timer_advance_ns automatically

2018-10-08 Thread Wanpeng Li
From: Wanpeng Li In cloud environment, lapic_timer_advance_ns is needed to be tuned for every CPU generations, and every host kernel versions(the kvm-unit-tests/tscdeadline_latency.flat is 5700 cycles for upstream kernel and 9600 cycles for our 3.10 product kernel, both preemption_timer=N

Re: [PATCH] KVM: LAPIC: Tune lapic_timer_advance_ns automatically

2018-10-08 Thread Wanpeng Li
On Mon, 8 Oct 2018 at 05:02, Liran Alon wrote: > > > > > On 28 Sep 2018, at 9:12, Wanpeng Li wrote: > > > > From: Wanpeng Li > > > > In cloud environment, lapic_timer_advance_ns is needed to be tuned for > > every CPU > > generations, and

Re: [PATCH] sched/fair: vruntime should normalize when switching from fair

2018-09-28 Thread Wanpeng Li
On Sat, 29 Sep 2018 at 01:36, Dietmar Eggemann wrote: > > On 09/28/2018 06:10 PM, Steve Muckle wrote: > > On 09/27/2018 05:43 PM, Wanpeng Li wrote: > >>>> On your CPU4: > >>>> scheduler_ipi() > >>>>-> sched_ttwu_pending() >

[PATCH] KVM: LAPIC: Tune lapic_timer_advance_ns automatically

2018-09-28 Thread Wanpeng Li
From: Wanpeng Li In cloud environment, lapic_timer_advance_ns is needed to be tuned for every CPU generations, and every host kernel versions(the kvm-unit-tests/tscdeadline_latency.flat is 5700 cycles for upstream kernel and 9600 cycles for our 3.10 product kernel, both preemption_timer=N

Re: [PATCH] sched/fair: vruntime should normalize when switching from fair

2018-09-27 Thread Wanpeng Li
On Thu, 27 Sep 2018 at 21:23, Dietmar Eggemann wrote: > > On 09/27/2018 03:19 AM, Wanpeng Li wrote: > > On Thu, 27 Sep 2018 at 06:38, Dietmar Eggemann > > wrote: > >> > >> Hi, > >> > >> On 09/26/2018 11:50 AM, Wanpeng Li wrote: > &g

Re: [PATCH] sched/fair: vruntime should normalize when switching from fair

2018-09-26 Thread Wanpeng Li
On Thu, 27 Sep 2018 at 06:38, Dietmar Eggemann wrote: > > Hi, > > On 09/26/2018 11:50 AM, Wanpeng Li wrote: > > Hi Dietmar, > > On Tue, 28 Aug 2018 at 22:55, Dietmar Eggemann > > wrote: > >> > >> On 08/27/2018 12:14 PM, Peter Zijlstra wrote: >

Re: [PATCH] sched/fair: vruntime should normalize when switching from fair

2018-09-26 Thread Wanpeng Li
the fair rq's min_vruntime is added to > >>>>>> the task's vruntime, even though it wasn't subtracted earlier. Could you point out when the fair rq's min_vruntime is added to the task's vruntime in your *later* scenario? attach_task_cfs_rq will not do that the same re

Re: [PATCH v2] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-30 Thread Wanpeng Li
On Thu, 30 Aug 2018 at 19:01, Radim Krčmář wrote: > > 2018-08-30 10:03+0800, Wanpeng Li: > > From: Wanpeng Li > > > > Dan Carpenter reported that the untrusted data returns from > > kvm_register_read() > > results in the following static checker war

Re: [PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-29 Thread Wanpeng Li
On Wed, 29 Aug 2018 at 23:42, Radim Krcmar wrote: > > 2018-08-29 13:29+0300, Dan Carpenter: > > On Wed, Aug 29, 2018 at 06:23:08PM +0800, Wanpeng Li wrote: > > > On Wed, 29 Aug 2018 at 18:18, Dan Carpenter > > > wrote: > > > > > > > > O

[PATCH v2] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-29 Thread Wanpeng Li
From: Wanpeng Li Dan Carpenter reported that the untrusted data returns from kvm_register_read() results in the following static checker warning: arch/x86/kvm/lapic.c:576 kvm_pv_send_ipi() error: buffer underflow 'map->phys_map' 's32min-s32max' KVM guest can easily trigger this by execut

Re: [PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-29 Thread Wanpeng Li
On Wed, 29 Aug 2018 at 18:29, Dan Carpenter wrote: > > On Wed, Aug 29, 2018 at 06:23:08PM +0800, Wanpeng Li wrote: > > On Wed, 29 Aug 2018 at 18:18, Dan Carpenter > > wrote: > > > > > > On Wed, Aug 29, 2018 at 01:12:05PM +0300, Dan Carpenter wrote: > &

Re: [PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-29 Thread Wanpeng Li
eft. > > > > if (min > (s32)(map->max_apic_id - __fls(ipi_bitmap_low)) > > Wait, the (s32) cast doesn't make sense. We want negative min values to > be treated as invalid. In v2, how about: if (unlikely(min > map->max_apic_id || (min + __fls(ipi_bitmap_low)) > map->max_apic_id)) goto out; 0x is converted to int min = -1; Regards, Wanpeng Li

[PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-28 Thread Wanpeng Li
From: Wanpeng Li Dan Carpenter reported that the untrusted data returns from kvm_register_read() results in the following static checker warning: arch/x86/kvm/lapic.c:576 kvm_pv_send_ipi() error: buffer underflow 'map->phys_map' 's32min-s32max' KVM guest can easily trigger this by execut

[PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access

2018-08-28 Thread Wanpeng Li
From: Wanpeng Li Dan Carpenter reported that the untrusted data returns from kvm_register_read() results in the following static checker warning: arch/x86/kvm/lapic.c:576 kvm_pv_send_ipi() error: buffer underflow 'map->phys_map' 's32min-s32max' KVM guest can easily trigger this by execut

Re: [PATCH v5 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-08-02 Thread Wanpeng Li
On Thu, 2 Aug 2018 at 21:04, Paolo Bonzini wrote: > > On 23/07/2018 08:39, Wanpeng Li wrote: > > +Returns 0 if successfully delivery the IPIs and 1 if discarded. > > I'm changing this to > > "Returns the number of CPUs to which the IPIs were delivered successfull

Re: [PATCH 06/11] sched/irq: add irq utilization tracking

2018-07-30 Thread Wanpeng Li
On Tue, 31 Jul 2018 at 00:43, Vincent Guittot wrote: > > Hi Wanpeng, > > On Thu, 26 Jul 2018 at 05:09, Wanpeng Li wrote: > > > > Hi Vincent, > > On Fri, 29 Jun 2018 at 03:07, Vincent Guittot > > wrote: > > > > > > interrupt an

Re: [PATCH 06/11] sched/irq: add irq utilization tracking

2018-07-25 Thread Wanpeng Li
mance which means that e.g. schedutil governor can not cooperate with passive mode intel_pstate driver to tune the OPP. To decay the old steal time avg and add the new one just wastes cpu cycles. Regards, Wanpeng Li > #endif > } > > diff --git a/kernel/sched/fair.c b/kernel/sched

Re: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address space mapping flush support

2018-07-23 Thread Wanpeng Li
+++ > >> arch/x86/include/asm/hyperv-tlfs.h | 8 + > >> arch/x86/include/asm/kvm_host.h | 11 ++ > >> arch/x86/include/asm/mshyperv.h | 2 ++ > >> arch/x86/include/asm/trace/hyperv.h | 14 > >> arch/x86/kvm/vmx.c | 72 > >> - > >> include/linux/kvm_host.h| 7 > >> virt/kvm/kvm_main.c | 3 +- > >> 9 files changed, 183 insertions(+), 3 deletions(-) > >> create mode 100644 arch/x86/hyperv/nested.c > > > > Acked-by: K. Y. Srinivasan > > Queued, thanks! My CONFIG_HYPERV is disabled, there is a warning when compiling kvm/queue. warning: ‘hv_remote_flush_tlb’ defined but not used [-Wunused-function] static int hv_remote_flush_tlb(struct kvm *kvm) Regards, Wanpeng Li

[PATCH v5 3/6] KVM: X86: Fallback to original apic hooks when bad happens

2018-07-23 Thread Wanpeng Li
From: Wanpeng Li Fallback to original apic hooks when unlikely kvm fails to add the pending IRQ to lapic. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions

[PATCH v5 1/6] KVM: X86: Add kvm hypervisor init time platform setup callback

2018-07-23 Thread Wanpeng Li
From: Wanpeng Li Add kvm hypervisor init time platform setup callback which will be used to replace native apic hooks by pararvirtual hooks. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 10 ++ 1 file changed, 10

[PATCH v5 0/6] KVM: X86: Implement Exit-less IPIs support

2018-07-23 Thread Wanpeng Li
selftest fails * fix build errors reported by 0day Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Wanpeng Li (6): KVM: X86: Add kvm hypervisor init time platform setup callback KVM: X86: Implement PV IPIs in linux guest KVM: X86: Fallback to original apic hooks when bad happens

[PATCH v5 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-23 Thread Wanpeng Li
From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Intel guest can enter x2apic cluster mode when interrupt remmaping is enabled in qemu, however, latest AMD EPYC still just

[PATCH v5 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-23 Thread Wanpeng Li
From: Wanpeng Li Implement paravirtual apic hooks to enable PV IPIs. apic->send_IPI_mask apic->send_IPI_mask_allbutself apic->send_IPI_allbutself apic->send_IPI_all This patch lets a guest send multicast IPIs, with at most 128 destinations per hypercall in 64-bit mode and

[PATCH v5 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-23 Thread Wanpeng Li
From: Wanpeng Li The NMI delivery mode of ICR is used to deliver an NMI to the processor, and the vector information is ignored. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 15 --- arch/x86/kvm/x86.c| 16

[PATCH v5 6/6] KVM: X86: Expose PV_SEND_IPI CPUID feature bit to guest

2018-07-23 Thread Wanpeng Li
From: Wanpeng Li Expose PV_SEND_IPI feature bit to guest, the guest can check this feature bit before using paravirtualized send IPIs. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- Documentation/virtual/kvm/cpuid.txt | 4 arch/x86/kvm/cpuid.c

Re: [PATCH v4 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-23 Thread Wanpeng Li
On Mon, 23 Jul 2018 at 14:19, Paolo Bonzini wrote: > > On 23/07/2018 08:10, Wanpeng Li wrote: > >>> On 20/07/2018 18:28, Wanpeng Li wrote: > >>>> +a0: ipi_bitmap low 64 bits > >>>> +a1: ipi_bitmap high 64 bits > >>

Re: [PATCH v4 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-23 Thread Wanpeng Li
On Mon, 23 Jul 2018 at 14:00, Wanpeng Li wrote: > > On Mon, 23 Jul 2018 at 13:52, Paolo Bonzini wrote: > > > > On 20/07/2018 18:28, Wanpeng Li wrote: > > > +a0: ipi_bitmap low 64 bits > > > +a1: ipi_bitmap high 64 bits > > > +a2: the

Re: [PATCH v4 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-23 Thread Wanpeng Li
On Mon, 23 Jul 2018 at 13:52, Paolo Bonzini wrote: > > On 20/07/2018 18:28, Wanpeng Li wrote: > > +a0: ipi_bitmap low 64 bits > > +a1: ipi_bitmap high 64 bits > > +a2: the lowest APIC ID in bitmap > > +a3: APIC ICR > > + > > +The hypercall lets a gu

Re: [PATCH v3 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-22 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 21:27, Radim Krcmar wrote: > > 2018-07-20 10:04+0200, Paolo Bonzini: > > On 20/07/2018 05:53, Wanpeng Li wrote: > > >>> - ret = kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, > > >>> ipi_bitmap_high, vector); > > &

[PATCH v4 RESEND 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-22 Thread Wanpeng Li
From: Wanpeng Li The NMI delivery mode of ICR is used to deliver an NMI to the processor, and the vector information is ignored. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 15 --- arch/x86/kvm/x86.c| 16

[PATCH v4 RESEND 6/6] KVM: X86: Expose PV_SEND_IPI CPUID feature bit to guest

2018-07-22 Thread Wanpeng Li
From: Wanpeng Li Expose PV_SEND_IPI feature bit to guest, the guest can check this feature bit before using paravirtualized send IPIs. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- Documentation/virtual/kvm/cpuid.txt | 4 arch/x86/kvm/cpuid.c

[PATCH v4 RESEND 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-22 Thread Wanpeng Li
From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Intel guest can enter x2apic cluster mode when interrupt remmaping is enabled in qemu, however, latest AMD EPYC still just

[PATCH v4 RESEND 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-22 Thread Wanpeng Li
From: Wanpeng Li Implement paravirtual apic hooks to enable PV IPIs. apic->send_IPI_mask apic->send_IPI_mask_allbutself apic->send_IPI_allbutself apic->send_IPI_all This patch lets a guest which sends multicast IPIs at most can handle 128 vCPUs per hypercall on 64-bit machines

[PATCH v4 RESEND 1/6] KVM: X86: Add kvm hypervisor init time platform setup callback

2018-07-22 Thread Wanpeng Li
From: Wanpeng Li Add kvm hypervisor init time platform setup callback which will be used to replace native apic hooks by pararvirtual hooks. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 10 ++ 1 file changed, 10

[PATCH v4 RESEND 3/6] KVM: X86: Fallback to original apic hooks when bad happens

2018-07-22 Thread Wanpeng Li
From: Wanpeng Li Fallback to original apic hooks when unlikely kvm fails to add the pending IRQ to lapic. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions

[PATCH v4 RESEND 0/6] KVM: X86: Implement Exit-less IPIs support

2018-07-22 Thread Wanpeng Li
: Radim Krčmář Cc: Vitaly Kuznetsov Wanpeng Li (6): KVM: X86: Add kvm hypervisor init time platform setup callback KVM: X86: Implement PV IPIs in linux guest KVM: X86: Fallback to original apic hooks when bad happens KVM: X86: Implement PV IPIs send hypercall KVM: X86: Add NMI support to

[PATCH v4 6/6] KVM: X86: Expose PV_SEND_IPI CPUID feature bit to guest

2018-07-20 Thread Wanpeng Li
From: Wanpeng Li Expose PV_SEND_IPI feature bit to guest, the guest can check this feature bit before using paravirtualized send IPIs. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- Documentation/virtual/kvm/cpuid.txt | 4 arch/x86/kvm/cpuid.c

[PATCH v4 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-20 Thread Wanpeng Li
From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Intel guest can enter x2apic cluster mode when interrupt remmaping is enabled in qemu, however, latest AMD EPYC still just

[PATCH v4 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-20 Thread Wanpeng Li
From: Wanpeng Li Implement paravirtual apic hooks to enable PV IPIs. apic->send_IPI_mask apic->send_IPI_mask_allbutself apic->send_IPI_allbutself apic->send_IPI_all This patch lets a guest which sends multicast IPIs at most can handle 128 vCPUs per hypercall on 64-bit machines

[PATCH v4 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-20 Thread Wanpeng Li
From: Wanpeng Li The NMI delivery mode of ICR is used to deliver an NMI to the processor, and the vector information is ignored. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 15 --- arch/x86/kvm/x86.c| 16

[PATCH v4 3/6] KVM: X86: Fallback to original apic hooks when bad happens

2018-07-20 Thread Wanpeng Li
From: Wanpeng Li Fallback to original apic hooks when unlikely kvm fails to add the pending IRQ to lapic. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions

[PATCH v4 1/6] KVM: X86: Add kvm hypervisor init time platform setup callback

2018-07-20 Thread Wanpeng Li
From: Wanpeng Li Add kvm hypervisor init time platform setup callback which will be used to replace native apic hooks by pararvirtual hooks. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 10 ++ 1 file changed, 10

[PATCH v4 0/6] KVM: X86: Implement Exit-less IPIs support

2018-07-20 Thread Wanpeng Li
: Radim Krčmář Cc: Vitaly Kuznetsov Wanpeng Li (6): KVM: X86: Add kvm hypervisor init time platform setup callback KVM: X86: Implement PV IPIs in linux guest KVM: X86: Fallback to original apic hooks when bad happens KVM: X86: Implement PV IPIs send hypercall KVM: X86: Add NMI support to

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-20 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 17:51, Radim Krcmar wrote: > > 2018-07-20 11:33+0800, Wanpeng Li: > > On Fri, 20 Jul 2018 at 00:28, Radim Krčmář wrote: > > > 2018-07-03 14:21+0800, Wanpeng Li: > > > But because it is very similar to x2apic, I'd really need some real

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
s David pointed out, we need to scale to higher APIC IDs. I will add the cpu id to apic id transfer in the for loop. How about: kvm_hypercall2(KVM_HC_SEND_IPI, ipi_bitmap, vector); directly. In addition, why need to pass the 0 as the "high" bitmap even if for 128 vCPUs case? Regards, Wanpeng Li

Re: [PATCH v3 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:31, Radim Krčmář wrote: > > 2018-07-03 14:21+0800, Wanpeng Li: > > From: Wanpeng Li > > > > The NMI delivery mode of ICR is used to deliver an NMI to the processor, > > and the vector information is ignored. > > > > Cc: P

Re: [PATCH v3 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini wrote: > > On 03/07/2018 08:21, Wanpeng Li wrote: > > + > > + rcu_read_lock(); > > + map = rcu_dereference(kvm->arch.apic_map); > > + > > + for_each_set_bit(i, _bitmap_low, BITS_PER_LONG) { > >

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 07:05, David Matlack wrote: > > On Mon, Jul 2, 2018 at 11:23 PM Wanpeng Li wrote: > > > > From: Wanpeng Li > > > > Implement paravirtual apic hooks to enable PV IPIs. > > Very cool. Thanks for working on this! Thanks David! &g

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
gt; } > > We could keep the cluster size of 128, but it would be more complicated > to do the left shift in the first "else if". If the limit is 64, you > can keep the two arguments in the hypercall, and just pass 0 as the > "high" bitmap on 64-bit kernels. Cool, i will try the offset method in next version. Thanks for your review, Paolo! :) Regards, Wanpeng Li

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:28, Radim Krčmář wrote: > > 2018-07-03 14:21+0800, Wanpeng Li: > > From: Wanpeng Li > > > > Implement paravirtual apic hooks to enable PV IPIs. > > > > apic->send_IPI_mask > > apic->send_IPI_mask_allbutself >

Re: [PATCH v3 0/6] KVM: X86: Implement PV IPIs support

2018-07-17 Thread Wanpeng Li
Gentle ping, hope this series can catch up with the next merge window. :) On Tue, 3 Jul 2018 at 14:21, Wanpeng Li wrote: > > Using hypercall to send IPIs by one vmexit instead of one by one for > xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster > mode. Int

[PATCH v2] KVM: Add coalesced PIO support

2018-07-11 Thread Wanpeng Li
-by: Wanpeng Li --- v1 -> v2: * add the original author Documentation/virtual/kvm/00-INDEX | 2 ++ Documentation/virtual/kvm/api.txt | 7 +++ Documentation/virtual/kvm/coalesced-io.txt | 17 + include/uapi/linux/kvm.h | 5 +++-- virt/

Re: [PATCH] x86/kvm/vmx: don't read current->thread.{fs,gs}base of legacy tasks

2018-07-11 Thread Wanpeng Li
vm_run test > started segfaulting. Test suite: MSR switch PASS: VM entry MSR load PASS: VM exit MSR store PASS: VM exit MSR load FAIL: VM entry MSR load: try to load FS_BASE SUMMARY: 4 tests, 1 unexpected failures kvm-unit-tests fails w/ and w/o the patch, maybe it is another issue, i didn

[PATCH RESEND] KVM: Add coalesced PIO support

2018-07-10 Thread Wanpeng Li
%92.72% 67.15us ( +- 7.93% ) After patch: IO Port Access Samples Samples% Time%Avg time 0x70:POUT1750945.42%42.08% 6.37us ( +- 20.37% ) Thanks to Peng Hao's initial patch. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Eduardo Habkost Signed-off-by: Wanpeng Li

[PATCH] KVM: Add coalesced PIO support

2018-07-10 Thread Wanpeng Li
%92.72% 67.15us ( +- 7.93% ) After patch: IO Port Access Samples Samples% Time%Avg time 0x70:POUT1750945.42%42.08% 6.37us ( +- 20.37% ) Thanks to Peng Hao's initial patch. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Eduardo Habkost Signed-off-by: Wanpeng Li

[PATCH v3 1/6] KVM: X86: Add kvm hypervisor init time platform setup callback

2018-07-03 Thread Wanpeng Li
From: Wanpeng Li Add kvm hypervisor init time platform setup callback which will be used to replace native apic hooks by pararvirtual hooks. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 10 ++ 1 file changed, 10

[PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-03 Thread Wanpeng Li
From: Wanpeng Li Implement paravirtual apic hooks to enable PV IPIs. apic->send_IPI_mask apic->send_IPI_mask_allbutself apic->send_IPI_allbutself apic->send_IPI_all The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud environment currently, supporting more

[PATCH v3 3/6] KVM: X86: Fallback to original apic hooks when bad happens

2018-07-03 Thread Wanpeng Li
From: Wanpeng Li Fallback to original apic hooks when apic id is sparse and larger than 128 or kvm fails to add the pending IRQ to lapic. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 26 +++--- 1 file

[PATCH v3 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-03 Thread Wanpeng Li
From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Intel guest can enter x2apic cluster mode when interrupt remmaping is enabled in qemu, however, latest AMD EPYC still just

[PATCH v3 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-03 Thread Wanpeng Li
From: Wanpeng Li The NMI delivery mode of ICR is used to deliver an NMI to the processor, and the vector information is ignored. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 13 +++-- arch/x86/kvm/x86.c| 16

[PATCH v3 0/6] KVM: X86: Implement PV IPIs support

2018-07-03 Thread Wanpeng Li
ndles 128 vCPUs * fix KVM_FEATURE_PV_SEND_IPI doc * document hypercall * fix NMI selftest fails * fix build errors reported by 0day Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Wanpeng Li (6): KVM: X86: Add kvm hypervisor init time platform setup callback KVM: X86: Implement P

[PATCH v3 6/6] KVM: X86: Expose PV_SEND_IPI CPUID feature bit to guest

2018-07-03 Thread Wanpeng Li
From: Wanpeng Li Expose PV_SEND_IPI feature bit to guest, the guest can check this feature bit before using paravirtualized send IPIs. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- Documentation/virtual/kvm/cpuid.txt | 4 arch/x86/kvm/cpuid.c

Re: [PATCH v2 1/2] KVM: X86: Implement PV IPI in linux guest

2018-07-02 Thread Wanpeng Li
On Mon, 2 Jul 2018 at 19:32, Paolo Bonzini wrote: > > On 02/07/2018 12:14, Wanpeng Li wrote: > > + unsigned long flags, ipi_bitmap_low = 0, ipi_bitmap_high = 0, icr = 0; > > + int cpu, apic_id, ret = 1; > > + > > + if (cpumask_empty(mask))

Re: [PATCH v2 1/2] KVM: X86: Implement PV IPI in linux guest

2018-07-02 Thread Wanpeng Li
On Mon, 2 Jul 2018 at 18:26, Vitaly Kuznetsov wrote: > > Wanpeng Li writes: > > > From: Wanpeng Li > > > > Implement PV IPIs in guest kernel. > > > > Cc: Paolo Bonzini > > Cc: Radim Krčmář > > Cc: Vitaly Kuznetsov > > Signed-off-by: Wa

[PATCH v2 1/2] KVM: X86: Implement PV IPI in linux guest

2018-07-02 Thread Wanpeng Li
From: Wanpeng Li Implement PV IPIs in guest kernel. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 99 +++ include/uapi/linux/kvm_para.h | 1 + 2 files changed, 100 insertions

[PATCH v2 0/2] KVM: x86: Add PV IPIs support

2018-07-02 Thread Wanpeng Li
* fix build errors reported by 0day Wanpeng Li (2): KVM: X86: Implement PV IPI in linux guest KVM: X86: Implement PV send IPI support Documentation/virtual/kvm/cpuid.txt | 4 ++ Documentation/virtual/kvm/hypercalls.txt | 6 ++ arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/

[PATCH v2 2/2] KVM: X86: Implement PV send IPI support

2018-07-02 Thread Wanpeng Li
From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Even if enable qemu interrupt remapping and PV TLB Shootdown, I can still observe ~14% performance boost by ebizzy benchmark

Re: [PATCH 2/2] KVM: X86: Implement PV send IPI support

2018-06-30 Thread Wanpeng Li
andles 128 vCPUs. > > to remove or limit the need for the more generic hypercall. Have already done 2) in v2, will send out later. Regards, Wanpeng Li

Re: [PATCH 2/2] KVM: X86: Implement PV send IPI support

2018-06-30 Thread Wanpeng Li
On Fri, 29 Jun 2018 at 18:45, Paolo Bonzini wrote: > > On 29/06/2018 11:51, Wanpeng Li wrote: > > From: Wanpeng Li > > > > Using hypercall to send IPIs by one vmexit instead of one by one for > > xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC

Re: [PATCH 1/2] KVM: X86: Implement PV IPI in linux guest

2018-06-30 Thread Wanpeng Li
On Fri, 29 Jun 2018 at 18:10, Vitaly Kuznetsov wrote: > > Wanpeng Li writes: > > > From: Wanpeng Li > > > > Implement PV IPIs in guest kernel. > > > > Cc: Paolo Bonzini > > Cc: Radim Krčmář > > Cc: Vitaly Kuznetsov > > Signed-o

[PATCH 2/2] KVM: X86: Implement PV send IPI support

2018-06-29 Thread Wanpeng Li
From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Even if enable qemu interrupt remapping and PV TLB Shootdown, I can still observe ~14% performance boost by ebizzy benchmark

[PATCH 0/2] KVM: x86: Add PV IPIs support

2018-06-29 Thread Wanpeng Li
onzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Wanpeng Li (2): KVM: X86: Implement PV IPI in linux guest KVM: X86: Implement PV send IPI support Documentation/virtual/kvm/cpuid.txt | 4 +++ arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/kernel/kvm.c

[PATCH 1/2] KVM: X86: Implement PV IPI in linux guest

2018-06-29 Thread Wanpeng Li
From: Wanpeng Li Implement PV IPIs in guest kernel. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/kernel/kvm.c| 63 2 files changed, 64

Re: [PATCH 3/3] KVM: x86: hyperv: implement PV IPI send hypercalls

2018-06-28 Thread Wanpeng Li
ccess: > > + return HV_STATUS_SUCCESS; > > +} > > + > > bool kvm_hv_hypercall_enabled(struct kvm *kvm) > > { > > return READ_ONCE(kvm->arch.hyperv.hv_hypercall) & > > HV_X64_MSR_HYPERCALL_ENABLE; > > @@ -1526,6 +1628,20 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > > } > > ret = kvm_hv_flush_tlb(vcpu, ingpa, rep_cnt, true); > > break; > > + case HVCALL_SEND_IPI: > > + if (unlikely(rep)) { > > + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > > + break; > > + } > > + ret = kvm_hv_send_ipi(vcpu, ingpa, outgpa, false, fast); > > + break; > > + case HVCALL_SEND_IPI_EX: Hi Paolo and Radim, I have already completed the patches for linux guest/kvm/qemu w/ vCPUs <= 64, however, extra complication as the ex in hyperv should be introduced for vCPUs > 64, so do you think vCPU <=64 is enough for linux guest or should me introduce two hypercall as what hyperv does w/ ex logic? Regards, Wanpeng Li

Re: [PATCH 0/4] x86/hyper-v: optimize PV IPIs

2018-06-27 Thread Wanpeng Li
On Wed, 27 Jun 2018 at 17:25, Vitaly Kuznetsov wrote: > > Wanpeng Li writes: > > > Hi Vitaly, (fix my reply mess this time) > > On Sat, 23 Jun 2018 at 01:09, Vitaly Kuznetsov wrote: > >> > >> When reviewing my "x86/hyper-v: use cheaper HVCALL_FLUSH_V

Re: [PATCH 0/4] x86/hyper-v: optimize PV IPIs

2018-06-26 Thread Wanpeng Li
s guest can switch to cluster mode after entering x2APIC, so sending IPI per cluster. In addition, you can also post the benchmark result for this PV IPI optimization, although it also fixes the bug which you mentioned above. I can post one variant for Linux guest PV IPI if it also makes sense. :) Regards, Wanpeng Li

Re: [GIT PULL] KVM changes for 4.18 merge window

2018-06-13 Thread Wanpeng Li
r country(China), and looking forward to see you at Linux Conf. :) Regards, Wanpeng Li

Re: [GIT PULL] KVM changes for 4.18 merge window

2018-06-12 Thread Wanpeng Li
t happens before the KVM GIT PULL on Linus's tree, you will see the warning above unless you lauch the guest w/ root user, maybe other subsystems' modifications break something. Regards, Wanpeng Li

Re: [PATCH 2/2] sched/core: Consider afffinity constrain when yield to a task

2018-06-11 Thread Wanpeng Li
ll drop the two patches. Regards, Wanpeng Li

[PATCH 1/2] KVM: Fix lock holder candidate yield

2018-06-11 Thread Wanpeng Li
From: Wanpeng Li After detecting pause loop which is executed by a Lock Waiter in the guest, the pCPU will be yielded to a Lock Holder candidate, the Lock Holder candidate may have its own task affinity constrain, however, current yield logic yield to the Lock Holder condidate unconditionally

[PATCH 2/2] sched/core: Consider afffinity constrain when yield to a task

2018-06-11 Thread Wanpeng Li
From: Wanpeng Li Consider the task afffinity constrain when yield to a task. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Peter Zijlstra Cc: Ingo Molnar Signed-off-by: Wanpeng Li --- kernel/sched/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched

Re: [PATCH] KVM: VMX: Optimize tscdeadline timer latency

2018-06-01 Thread Wanpeng Li
On Wed, 30 May 2018 at 01:08, Paolo Bonzini wrote: > > On 29/05/2018 16:31, Radim Krčmář wrote: > > 2018-05-29 16:23+0200, Radim Krčmář: > >> 2018-05-29 14:53+0800, Wanpeng Li: > >>> From: Wanpeng Li > >>> > >>> 'Commit d0659d946be0 (&

Re: [PATCH] KVM: VMX: Optimize tscdeadline timer latency

2018-05-29 Thread Wanpeng Li
On Wed, 30 May 2018 at 01:08, Paolo Bonzini wrote: > On 29/05/2018 16:31, Radim Krčmář wrote: > > 2018-05-29 16:23+0200, Radim Krčmář: > >> 2018-05-29 14:53+0800, Wanpeng Li: > >>> From: Wanpeng Li > >>> > >>> 'Commit d0659d946be0 (&quo

[PATCH] KVM: VMX: Optimize tscdeadline timer latency

2018-05-29 Thread Wanpeng Li
From: Wanpeng Li 'Commit d0659d946be0 ("KVM: x86: add option to advance tscdeadline hrtimer expiration")' advances the tscdeadline (the timer is emulated by hrtimer) expiration in order that the latency which is incurred by hypervisor (apic_timer_fn -> vmentry) can be avoide

Re: [PATCH v2 0/3] Provides userspace with per-VM capability to improve latency

2018-05-23 Thread Wanpeng Li
2018-03-12 19:53 GMT+08:00 Wanpeng Li <kernel...@gmail.com>: > Provides userspace with per-VM capability(KVM_CAP_X86_DISABLE_EXITS) to > not intercept MWAIT/HLT/PAUSE in order that to improve latency in some > workloads. When running cyclictest in the guest w/ vCPU pin on host and

Re: [PATCH v4 0/8] KVM: x86: hyperv: PV TLB flush for Windows guests

2018-05-18 Thread Wanpeng Li
2018-05-18 20:42 GMT+08:00 Vitaly Kuznetsov <vkuzn...@redhat.com>: > Wanpeng Li <kernel...@gmail.com> writes: > >> 2018-05-18 19:19 GMT+08:00 Vitaly Kuznetsov <vkuzn...@redhat.com>: >>> Vitaly Kuznetsov <vkuzn...@redhat.com> writes: >>> >&

Re: [PATCH v4 0/8] KVM: x86: hyperv: PV TLB flush for Windows guests

2018-05-18 Thread Wanpeng Li
2018-05-18 19:19 GMT+08:00 Vitaly Kuznetsov <vkuzn...@redhat.com>: > Vitaly Kuznetsov <vkuzn...@redhat.com> writes: > >> Wanpeng Li <kernel...@gmail.com> writes: >> >>> Hi Vitaly, >>> 2018-05-16 23:21 GMT+08:00 Vitaly Kuznetsov <

Re: [PATCH v4 0/8] KVM: x86: hyperv: PV TLB flush for Windows guests

2018-05-18 Thread Wanpeng Li
68ed/359b18ab-05bb-460d-9b53-89505bca68ed_vda_1.qcow2 -net nic,model=virtio -net user -monitor stdio -usb -usbdevice tablet --enable-kvm --cpu host -vnc 0.0.0.0:2 Regards, Wanpeng Li

Re: [PATCH 2/3] KVM: X86: Allow userspace to disable ioport intercept

2018-05-15 Thread Wanpeng Li
2018-05-16 5:56 GMT+08:00 Jim Mattson <jmatt...@google.com>: > I'd prefer to let the kvm module have the final say as to whether or > not to allow userspace to do this. I have an IRC discussion with Paolo, it seems that he didn't like the original idea of the patchset. Regards

Re: [PATCH v3] KVM: X86: Lower the default timer frequency limit to 200us

2018-05-14 Thread Wanpeng Li
ping, 2018-05-05 19:02 GMT+08:00 Wanpeng Li <kernel...@gmail.com>: > From: Wanpeng Li <wanpen...@tencent.com> > > Anthoine reported: > The period used by Windows change over time but it can be 1 > milliseconds or less. I saw the limit_periodic_timer_frequency &

[PATCH v2] KVM: X86: Fix CR3 reserve bits

2018-05-13 Thread Wanpeng Li
From: Wanpeng Li <wanpen...@tencent.com> MSB of CR3 is a reserved bit if the PCIDE bit is not set in CR4. It should be checked when PCIDE bit is not set, however commit 'd1cd3ce900441 ("KVM: MMU: check guest CR3 reserved bits based on its physical address width")' removes the

Re: [PATCH 1/2] KVM: X86: Fix CR3 reserve bits

2018-05-13 Thread Wanpeng Li
;> 2018-05-13 15:53 GMT+08:00 Liran Alon <liran.a...@oracle.com>: >> >> > >> >> > - kernel...@gmail.com wrote: >> >> > >> >> >> From: Wanpeng Li <wanpen...@tencent.com> >> >> >> >> >> >> MSB of CR3

Re: [PATCH 1/2] KVM: X86: Fix CR3 reserve bits

2018-05-13 Thread Wanpeng Li
2018-05-13 16:28 GMT+08:00 Liran Alon <liran.a...@oracle.com>: > > - kernel...@gmail.com wrote: > >> 2018-05-13 15:53 GMT+08:00 Liran Alon <liran.a...@oracle.com>: >> > >> > - kernel...@gmail.com wrote: >> > >> >&g

  1   2   3   4   5   6   7   8   9   10   >