Re: [PATCH v2 1/3] KVM: x86: move kvm_vcpu_gfn_to_memslot() out of try_async_pf()

2020-09-01 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Fri, Aug 07, 2020 at 04:12:30PM +0200, Vitaly Kuznetsov wrote: >> No functional change intended. Slot flags will need to be analyzed >> prior to try_async_pf() when KVM_MEM_PCI_HOLE is implemented. > (Sorry it took me so long to reply. N

Re: [PATCH v2 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory

2020-09-01 Thread Vitaly Kuznetsov
Peter Xu writes: > On Fri, Aug 07, 2020 at 04:12:29PM +0200, Vitaly Kuznetsov wrote: >> When testing Linux kernel boot with QEMU q35 VM and direct kernel boot >> I observed 8193 accesses to PCI hole memory. When such exit is handled >> in KVM without exiting to usersp

Re: [PATCH v2 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory

2020-09-01 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Fri, Aug 07, 2020 at 04:12:31PM +0200, Vitaly Kuznetsov wrote: >> PCIe config space can (depending on the configuration) be quite big but >> usually is sparsely populated. Guest may scan it by accessing individual >> device's page which, w

Re: [PATCH] KVM: VMX: fix crash cleanup when KVM wasn't used

2020-09-01 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Aug 24, 2020 at 03:45:26PM -0700, Jim Mattson wrote: >> On Mon, Aug 24, 2020 at 11:57 AM Jim Mattson wrote: >> > >> > On Fri, Aug 21, 2020 at 8:40 PM Sean Christopherson >> > wrote: >> > > I agree the code is a mess (kvm_init() and kvm_exit() included),

Re: [RFC v2 2/2] KVM: VMX: Enable bus lock VM exit

2020-09-01 Thread Vitaly Kuznetsov
Chenyi Qiang writes: > Virtual Machine can exploit bus locks to degrade the performance of > system. Bus lock can be caused by split locked access to writeback(WB) > memory or by using locks on uncacheable(UC) memory. The bus lock is > typically >1000 cycles slower than an atomic operation

Re: [PATCH] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-09-01 Thread Vitaly Kuznetsov
Lai Jiangshan writes: > On Mon, Aug 31, 2020 at 9:09 PM Vitaly Kuznetsov wrote: >> >> Lai Jiangshan writes: >> >> > Ping @Sean Christopherson >> > >> >> Let's try 'Beetlejuice' instead :-) >> >> > On Mon, Aug 24, 2020 at 5

Re: [PATCH] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-08-31 Thread Vitaly Kuznetsov
Lai Jiangshan writes: > Ping @Sean Christopherson > Let's try 'Beetlejuice' instead :-) > On Mon, Aug 24, 2020 at 5:18 PM Lai Jiangshan wrote: >> >> From: Lai Jiangshan >> >> 8c8560b83390("KVM: x86/mmu: Use KVM_REQ_TLB_FLUSH_CURRENT for MMU specific >> flushes) >> changed it without giving

Re: [PATCH] KVM: LAPIC: Reset timer_advance_ns if timer mode switch

2020-08-31 Thread Vitaly Kuznetsov
Wanpeng Li writes: > From: Wanpeng Li > > per-vCPU timer_advance_ns should be set to 0 if timer mode is not tscdeadline > otherwise we waste cpu cycles in the function lapic_timer_int_injected(), lapic_timer_int_injected is just a test, kvm_wait_lapic_expire() (__kvm_wait_lapic_expire())

Re: WARNING in rcu_irq_exit

2020-08-10 Thread Vitaly Kuznetsov
syzbot writes: > Hello, > > syzbot found the following issue on: > > HEAD commit:47ec5303 Merge git://git.kernel.org/pub/scm/linux/kernel/g.. > git tree: upstream > console output: https://syzkaller.appspot.com/x/log.txt?x=17228c6290 > kernel config:

[PATCH v2 3/3] KVM: selftests: add KVM_MEM_PCI_HOLE test

2020-08-07 Thread Vitaly Kuznetsov
Test the newly introduced KVM_MEM_PCI_HOLE memslots: - Reads from all pages return '0xff' - Writes to all pages cause KVM_EXIT_MMIO Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/include/kvm_util.h | 1 + tools/testing

[PATCH v2 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory

2020-08-07 Thread Vitaly Kuznetsov
to the already existing KVM_MEM_READONLY, VMM doesn't need to allocate real memory and stuff it with '0xff'. Suggested-by: Michael S. Tsirkin Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/api.rst | 18 ++- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/mmu/mmu.c

[PATCH v2 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory

2020-08-07 Thread Vitaly Kuznetsov
ge stuffed with 0xff. This is omitted in this submission as the benefits are unclear: KVM will have to allocate SPTEs (either on demand or aggressively) and this also consumes time/memory. We can always take a look at possible optimizations later. Vitaly Kuznetsov (3): KVM: x86: move kvm_vcpu_gfn_to_memslot()

[PATCH v2 1/3] KVM: x86: move kvm_vcpu_gfn_to_memslot() out of try_async_pf()

2020-08-07 Thread Vitaly Kuznetsov
No functional change intended. Slot flags will need to be analyzed prior to try_async_pf() when KVM_MEM_PCI_HOLE is implemented. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 14 -- arch/x86/kvm/mmu/paging_tmpl.h | 7 +-- 2 files changed, 13 insertions

Re: [PATCH 1/1] Drivers: hv: vmbus: Only notify Hyper-V for die events that are oops

2020-08-07 Thread Vitaly Kuznetsov
Don't notify Hyper-V if the die event is other than oops */ > + if (val != DIE_OOPS) > + return NOTIFY_DONE; > + Looking at die_val enum, DIE_PANIC also sounds like something we would want to report but it doesn't get emitted anywhere and honestly I don't quite underst

[PATCH 7/7] KVM: selftests: test KVM_GET_SUPPORTED_HV_CPUID as a system ioctl

2020-08-07 Thread Vitaly Kuznetsov
KVM_GET_SUPPORTED_HV_CPUID is now supported as both vCPU and VM ioctl, test that. Signed-off-by: Vitaly Kuznetsov --- .../testing/selftests/kvm/include/kvm_util.h | 2 + tools/testing/selftests/kvm/lib/kvm_util.c| 26 +++ .../selftests/kvm/x86_64/hyperv_cpuid.c | 46

[PATCH 6/7] KVM: x86: hyper-v: allow KVM_GET_SUPPORTED_HV_CPUID as a system ioctl

2020-08-07 Thread Vitaly Kuznetsov
KVM_GET_SUPPORTED_HV_CPUID to 'dual' system/vCPU ioctl with the same meaning. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/api.rst | 4 ++-- arch/x86/kvm/x86.c | 43 -- include/uapi/linux/kvm.h | 4 ++-- 3 files changed, 30 insertions(+), 21

[PATCH 2/7] KVM: x86: hyper-v: disallow configuring SynIC timers with no SynIC

2020-08-07 Thread Vitaly Kuznetsov
Hyper-V Synthetic timers require SynIC but we don't seem to check that upon HV_X64_MSR_STIMER[X]_CONFIG/HV_X64_MSR_STIMER0_COUNT writes. Make the behavior match synic_set_msr(). Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 11 +++ 1 file changed, 11 insertions(+) diff

[PATCH 5/7] KVM: x86: hyper-v: drop now unneeded vcpu parameter from kvm_vcpu_ioctl_get_hv_cpuid()

2020-08-07 Thread Vitaly Kuznetsov
kvm_vcpu_ioctl_get_hv_cpuid() doesn't use its vcpu parameter anymore, drop it. Also, the function is now untied from vcpu, rename it accordingly. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 3 +-- arch/x86/kvm/hyperv.h | 3 +-- arch/x86/kvm/x86.c

[PATCH 0/7] KVM: x86: hyper-v: make KVM_GET_SUPPORTED_HV_CPUID more useful

2020-08-07 Thread Vitaly Kuznetsov
KVM_GET_SUPPORTED_CPUID/ KVM_GET_MSRS ioctls but Hyper-V specific features don't get in the output (as Hyper-V CPUIDs intersect with KVM's). In QEMU, CPU feature expansion happens before any KVM vcpus are created so KVM_GET_SUPPORTED_HV_CPUID can't be used in its current shape. Vitaly Kuznetsov (7

[PATCH 3/7] KVM: x86: hyper-v: make KVM_GET_SUPPORTED_HV_CPUID output independent of eVMCS enablement

2020-08-07 Thread Vitaly Kuznetsov
, make EVMCS feature bits work the same way as all other bits, nothing should break (famous last words). Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/api.rst| 3 -- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/hyperv.c

[PATCH 1/7] KVM: x86: hyper-v: Mention SynDBG CPUID leaves in api.rst

2020-08-07 Thread Vitaly Kuznetsov
We forgot to update KVM_GET_SUPPORTED_HV_CPUID's documentation in api.rst when SynDBG leaves were added. While on it, fix 'KVM_GET_SUPPORTED_CPUID' copy-paste error. Fixes: f97f5a56f597 ("x86/kvm/hyper-v: Add support for synthetic debugger interface") Signed-off-by: Vitaly

[PATCH 4/7] KVM: x86: hyper-v: always advertise HV_STIMER_DIRECT_MODE_AVAILABLE

2020-08-07 Thread Vitaly Kuznetsov
so no VMM should just blindly copy it to guest CPUIDs. Second, lapic_in_kernel() is a must for SynIC. Expose the bit unconditionally. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch

Re: [PATCH 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory

2020-08-06 Thread Vitaly Kuznetsov
"Michael S. Tsirkin" writes: > About the feature bit, I am not sure why it's really needed. A single > mmio access is cheaper than two io accesses anyway, right? So it makes > sense for a kvm guest whether host has this feature or not. > We need to be careful and limit to a specific QEMU

Re: [PATCH 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory

2020-08-06 Thread Vitaly Kuznetsov
"Michael S. Tsirkin" writes: > On Tue, Jul 28, 2020 at 04:37:38PM +0200, Vitaly Kuznetsov wrote: >> This is a continuation of "[PATCH RFC 0/5] KVM: x86: KVM_MEM_ALLONES >> memory" work: >> https://lore.kernel.org/kvm/20200514180540.52407-1-vkuzn...@redha

Re: [PATCH 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory

2020-08-06 Thread Vitaly Kuznetsov
Jim Mattson writes: > On Tue, Jul 28, 2020 at 7:38 AM Vitaly Kuznetsov wrote: >> >> PCIe config space can (depending on the configuration) be quite big but >> usually is sparsely populated. Guest may scan it by accessing individual >> device's page which, when dev

Re: [PATCH 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory

2020-08-06 Thread Vitaly Kuznetsov
Andrew Jones writes: > On Tue, Jul 28, 2020 at 04:37:40PM +0200, Vitaly Kuznetsov wrote: >> PCIe config space can (depending on the configuration) be quite big but >> usually is sparsely populated. Guest may scan it by accessing individual >> device's page which, w

Re: [PATCH v3 2/3] KVM: x86: Introduce allow list for MSR emulation

2020-08-03 Thread Vitaly Kuznetsov
Alexander Graf writes: > It's not desireable to have all MSRs always handled by KVM kernel space. Some > MSRs would be useful to handle in user space to either emulate behavior (like > uCode updates) or differentiate whether they are valid based on the CPU model. > > To allow user space to

Re: [PATCH v3 1/3] KVM: x86: Deflect unknown MSR accesses to user space

2020-08-03 Thread Vitaly Kuznetsov
Alexander Graf writes: > MSRs are weird. Some of them are normal control registers, such as EFER. > Some however are registers that really are model specific, not very > interesting to virtualization workloads, and not performance critical. > Others again are really just windows into package

Re: [PATCH] KVM: x86: Use MMCONFIG for all PCI config space accesses

2020-07-31 Thread Vitaly Kuznetsov
Andy Shevchenko writes: > On Thu, Jul 30, 2020 at 10:37 PM Julia Suvorova wrote: >> >> Using MMCONFIG instead of I/O ports cuts the number of config space >> accesses in half, which is faster on KVM and opens the door for >> additional optimizations such as Vitaly's "[PATCH 0/3] KVM: x86: KVM

Re: [PATCH v2 3/3] KVM: SVM: Fix disable pause loop exit/pause filtering capability on SVM

2020-07-30 Thread Vitaly Kuznetsov
Wanpeng Li writes: > On Wed, 29 Jul 2020 at 20:21, Vitaly Kuznetsov wrote: >> >> Wanpeng Li writes: >> >> > From: Wanpeng Li >> > >> > Commit 8566ac8b (KVM: SVM: Implement pause loop exit logic in SVM) drops >> > disable pause

Re: [PATCH v2 2/3] KVM: x86: Introduce allow list for MSR emulation

2020-07-30 Thread Vitaly Kuznetsov
Alexander Graf writes: > It's not desireable to have all MSRs always handled by KVM kernel space. Some > MSRs would be useful to handle in user space to either emulate behavior (like > uCode updates) or differentiate whether they are valid based on the CPU model. > > To allow user space to

Re: [PATCH v2 1/3] KVM: x86: Deflect unknown MSR accesses to user space

2020-07-30 Thread Vitaly Kuznetsov
Alexander Graf writes: > MSRs are weird. Some of them are normal control registers, such as EFER. > Some however are registers that really are model specific, not very > interesting to virtualization workloads, and not performance critical. > Others again are really just windows into package

Re: [PATCH v2 3/3] KVM: SVM: Fix disable pause loop exit/pause filtering capability on SVM

2020-07-29 Thread Vitaly Kuznetsov
Wanpeng Li writes: > From: Wanpeng Li > > Commit 8566ac8b (KVM: SVM: Implement pause loop exit logic in SVM) drops > disable pause loop exit/pause filtering capability completely, I guess it > is a merge fault by Radim since disable vmexits capabilities and pause > loop exit for SVM patchsets

Re: [PATCH] KVM: x86: Deflect unknown MSR accesses to user space

2020-07-29 Thread Vitaly Kuznetsov
Alexander Graf writes: > On 29.07.20 10:23, Vitaly Kuznetsov wrote: >> >> >> >> Jim Mattson writes: >> >>> On Tue, Jul 28, 2020 at 5:41 AM Alexander Graf wrote: >>>> >> >> ... >> >>>> While it does

Re: [PATCH] KVM: x86: Deflect unknown MSR accesses to user space

2020-07-29 Thread Vitaly Kuznetsov
Jim Mattson writes: > On Tue, Jul 28, 2020 at 5:41 AM Alexander Graf wrote: >> ... >> While it does feel a bit overengineered, it would solve the problem that >> we're turning in-KVM handled MSRs into an ABI. > > It seems unlikely that userspace is going to know what to do with a > large

[PATCH 3/3] KVM: selftests: add KVM_MEM_PCI_HOLE test

2020-07-28 Thread Vitaly Kuznetsov
Test the newly introduced KVM_MEM_PCI_HOLE memslots: - Reads from all pages return '0xff' - Writes to all pages cause KVM_EXIT_MMIO Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/include/kvm_util.h | 1 + tools/testing

[PATCH 1/3] KVM: x86: move kvm_vcpu_gfn_to_memslot() out of try_async_pf()

2020-07-28 Thread Vitaly Kuznetsov
No functional change intended. Slot flags will need to be analyzed prior to try_async_pf() when KVM_MEM_PCI_HOLE is implemented. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 14 -- arch/x86/kvm/mmu/paging_tmpl.h | 7 +-- 2 files changed, 13 insertions

[PATCH 0/3] KVM: x86: KVM_MEM_PCI_HOLE memory

2020-07-28 Thread Vitaly Kuznetsov
emory. We can always take a look at possible optimizations later. Vitaly Kuznetsov (3): KVM: x86: move kvm_vcpu_gfn_to_memslot() out of try_async_pf() KVM: x86: introduce KVM_MEM_PCI_HOLE memory KVM: selftests: add KVM_MEM_PCI_HOLE test Documentation/virt/kvm/api.rst| 19 +

[PATCH 2/3] KVM: x86: introduce KVM_MEM_PCI_HOLE memory

2020-07-28 Thread Vitaly Kuznetsov
to the already existing KVM_MEM_READONLY, VMM doesn't need to allocate real memory and stuff it with '0xff'. Suggested-by: Michael S. Tsirkin Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/api.rst | 19 +++- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/mmu/mmu.c

Re: [PATCH] KVM: x86: Deflect unknown MSR accesses to user space

2020-07-28 Thread Vitaly Kuznetsov
Alexander Graf writes: > MSRs are weird. Some of them are normal control registers, such as EFER. > Some however are registers that really are model specific, not very > interesting to virtualization workloads, and not performance critical. > Others again are really just windows into package

Re: [PATCH v4] kvm,x86: Exit to user space in case page fault error

2020-07-27 Thread Vitaly Kuznetsov
__gfn_to_pfn_memslot() and >> exit to user space and qemu reports error, "error: kvm run failed Bad >> address". > > Hi Vitaly, > > A gentle reminder. How does this patch look now? > Sorry, I even reviewd it but never replied. It looks good to me! Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH] x86/PCI: Use MMCONFIG by default for KVM guests

2020-07-27 Thread Vitaly Kuznetsov
Andy Shevchenko writes: > On Wed, Jul 22, 2020 at 12:47 PM Vitaly Kuznetsov wrote: >> Julia Suvorova writes: > >> > Scanning for PCI devices at boot takes a long time for KVM guests. It >> > can be reduced if KVM will handle all configuration space accesses

Re: [PATCH 5/9] KVM: x86: Pull the PGD's level from the MMU instead of recalculating it

2020-07-22 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Use the shadow_root_level from the current MMU as the root level for the > PGD, i.e. for VMX's EPTP. This eliminates the weird dependency between > VMX and the MMU where both must independently calculate the same root > level for things to work correctly.

Re: [PATCH 2/9] KVM: x86/mmu: Add separate helper for shadow NPT root page role calc

2020-07-22 Thread Vitaly Kuznetsov
kvm_calc_shadow_mmu_root_page_role(vcpu, false); > + union kvm_mmu_role new_role = kvm_calc_shadow_npt_root_page_role(vcpu); > > - new_role.base.level = vcpu->arch.tdp_level; > context->shadow_root_level = new_role.base.level; > > __kvm_mmu_new_pgd(vcpu, nested_cr3, new_role.base, false, false); Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH 1/9] KVM: nSVM: Correctly set the shadow NPT root level in its MMU role

2020-07-22 Thread Vitaly Kuznetsov
lized before __kvm_mmu_new_pgd(), which > consumes the level when attempting a fast PGD switch. > > Cc: Vitaly Kuznetsov > Fixes: 9fa72119b24db ("kvm: x86: Introduce kvm_mmu_calc_root_page_role()") > Fixes: a506fdd223426 ("KVM: nSVM: implement nested_svm_load_cr3() and use i

Re: [PATCH] x86/PCI: Use MMCONFIG by default for KVM guests

2020-07-22 Thread Vitaly Kuznetsov
Julia Suvorova writes: > Scanning for PCI devices at boot takes a long time for KVM guests. It > can be reduced if KVM will handle all configuration space accesses for > non-existent devices without going to userspace [1]. But for this to > work, all accesses must go through MMCONFIG. > This

Re: [PATCH 6/7] KVM: x86: Use common definition for kvm_nested_vmexit tracepoint

2020-07-21 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Jul 20, 2020 at 06:52:15PM +0200, Vitaly Kuznetsov wrote: >> Sean Christopherson writes: >> > +TRACE_EVENT_KVM_EXIT(kvm_nested_vmexit); >> > >> > /* >> > * Tracepoint for #VMEXIT reinjected to the guest

Re: [PATCH 2/2] KVM: LAPIC: Set the TDCR settable bits

2020-07-21 Thread Vitaly Kuznetsov
Wanpeng Li writes: > From: Wanpeng Li > > Only bits 0, 1, and 3 are settable, others are reserved for APIC_TDCR. > Let's record the settable value in the virtual apic page. > > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/lapic.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >

Re: [PATCH 1/2] KVM: LAPIC: Prevent setting the tscdeadline timer if the lapic is hw disabled

2020-07-21 Thread Vitaly Kuznetsov
Wanpeng Li writes: > From: Wanpeng Li > > Prevent setting the tscdeadline timer if the lapic is hw disabled. > > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/lapic.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index

Re: [PATCH] KVM: Using macros instead of magic values

2020-07-21 Thread Vitaly Kuznetsov
kvm_lapic_reg_write(apic, APIC_ICR, 0x4 | (val & > 0xff)); > + kvm_lapic_reg_write(apic, APIC_ICR, > + APIC_DEST_SELF | (val & > APIC_VECTOR_MASK)); > } else >

Re: [PATCH 6/7] KVM: x86: Use common definition for kvm_nested_vmexit tracepoint

2020-07-20 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Use the newly introduced TRACE_EVENT_KVM_EXIT to define the guts of > kvm_nested_vmexit so that it captures and prints the same information as > with kvm_exit. This has the bonus side effect of fixing the interrupt > info and error code printing for the case where

Re: [PATCH v3] kvm,x86: Exit to user space in case of page fault error

2020-07-17 Thread Vitaly Kuznetsov
Vivek Goyal writes: > Page fault error handling behavior in kvm seems little inconsistent when > page fault reports error. If we are doing fault synchronously > then we capture error (-EFAULT) returned by __gfn_to_pfn_memslot() and > exit to user space and qemu reports error, "error: kvm run

Re: [PATCH] KVM: x86: Don't attempt to load PDPTRs when 64-bit mode is enabled

2020-07-14 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Tue, Jul 14, 2020 at 02:00:04PM +0200, Vitaly Kuznetsov wrote: >> Sean Christopherson writes: >> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> > index 95ef629228691..5f526d94c33f3 100644 >> > --- a/arch/x86/kvm

Re: [PATCH] KVM: x86: Don't attempt to load PDPTRs when 64-bit mode is enabled

2020-07-14 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Don't attempt to load PDPTRs if EFER.LME=1, i.e. if 64-bit mode is > enabled. A recent change to reload the PDTPRs when CR0.CD or CR0.NW is > toggled botched the EFER.LME handling and sends KVM down the PDTPR path > when is_paging() is true, i.e. when the guest

Re: [PATCH v4 5/9] KVM: nSVM: introduce nested_svm_load_cr3()/nested_npt_enabled()

2020-07-14 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Fri, Jul 10, 2020 at 04:11:53PM +0200, Vitaly Kuznetsov wrote: >> As a preparatory change for implementing nested specifig PGD switch for > > s/specifig/specific > >> nSVM (following nVMX' nested_vmx_load_cr3()) instead of relying on >

[PATCH v2] KVM: nVMX: fix the layout of struct kvm_vmx_nested_state_hdr

2020-07-13 Thread Vitaly Kuznetsov
at legacy userspaces using old layout will be passing uninitialized bytes which will slip into what is now known as 'flags'. Suggested-by: Sean Christopherson Fixes: 850448f35aaf ("KVM: nVMX: Fix VMX preemption timer migration") Fixes: 83d31e5271ac ("KVM: nVMX: fixes for preemption time

Re: [PATCH] KVM: nVMX: properly pad struct kvm_vmx_nested_state_hdr

2020-07-13 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Jul 13, 2020 at 10:28:24AM +0200, Vitaly Kuznetsov wrote: >> Holes in structs which are userspace ABI are undesireable. >> >> Fixes: 83d31e5271ac ("KVM: nVMX: fixes for preemption timer migration") >

[PATCH] KVM: nVMX: properly pad struct kvm_vmx_nested_state_hdr

2020-07-13 Thread Vitaly Kuznetsov
Holes in structs which are userspace ABI are undesireable. Fixes: 83d31e5271ac ("KVM: nVMX: fixes for preemption timer migration") Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/api.rst | 2 +- arch/x86/include/uapi/asm/kvm.h | 2 +- 2 files changed, 2 insertions(+), 2

[PATCH v3] KVM: x86: move MSR_IA32_PERF_CAPABILITIES emulation to common x86 code

2020-07-10 Thread Vitaly Kuznetsov
just allow the host to read and write zero to the MSR. Fixes: 27461da31089 ("KVM: x86/pmu: Support full width counting") Suggested-by: Jim Mattson Suggested-by: Paolo Bonzini Signed-off-by: Vitaly Kuznetsov --- - This is a succesor of "[PATCH v2] KVM: SVM: emulate MSR_IA32_PERF_CAPABIL

Re: [PATCH v2] KVM: SVM: emulate MSR_IA32_PERF_CAPABILITIES

2020-07-10 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 18/06/20 14:54, Vitaly Kuznetsov wrote: >> Paolo Bonzini writes: >> >>> On 18/06/20 13:13, Vitaly Kuznetsov wrote: >>>> state_test/smm_test selftests are failing on AMD with: >>>> "Unexpected

[PATCH v4 5/9] KVM: nSVM: introduce nested_svm_load_cr3()/nested_npt_enabled()

2020-07-10 Thread Vitaly Kuznetsov
As a preparatory change for implementing nested specifig PGD switch for nSVM (following nVMX' nested_vmx_load_cr3()) instead of relying on kvm_set_cr3() introduce nested_svm_load_cr3(). No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 21

[PATCH v4 3/9] KVM: nSVM: reset nested_run_pending upon nested_svm_vmrun_msrpm() failure

2020-07-10 Thread Vitaly Kuznetsov
WARN_ON_ONCE(svm->nested.nested_run_pending) in nested_svm_vmexit() will fire if nested_run_pending remains '1' but it doesn't really need to, we are already failing and not going to run nested guest. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 2 ++ 1 file changed

[PATCH v4 6/9] KVM: nSVM: move kvm_set_cr3() after nested_svm_uninit_mmu_context()

2020-07-10 Thread Vitaly Kuznetsov
don't do kvm_set_cr3() but we're about to switch to nested_svm_load_cr3(). No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm

[PATCH v4 8/9] KVM: nSVM: use nested_svm_load_cr3() on guest->host switch

2020-07-10 Thread Vitaly Kuznetsov
_state() and the later is used to restore from 'partial' switch to L2, it always uses kvm_mmu_reset_context(). nSVM doesn't have this yet. Also, nested_svm_vmexit()'s return value is almost always ignored nowadays. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 15 ++-

[PATCH v4 2/9] KVM: MMU: stop dereferencing vcpu->arch.mmu to get the context for MMU init

2020-07-10 Thread Vitaly Kuznetsov
cpu->arch.mmu pointer. Based on a patch by Vitaly Kuznetsov . Signed-off-by: Paolo Bonzini Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 21 ++--- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c

[PATCH v4 7/9] KVM: nSVM: implement nested_svm_load_cr3() and use it for host->guest switch

2020-07-10 Thread Vitaly Kuznetsov
: 7c390d350f8b ("kvm: x86: Add fast CR3 switch code path") Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c| 2 ++ arch/x86/kvm/svm/nested.c | 38 +- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x

[PATCH v4 1/9] KVM: nSVM: split kvm_init_shadow_npt_mmu() from kvm_init_shadow_mmu()

2020-07-10 Thread Vitaly Kuznetsov
-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu.h| 3 ++- arch/x86/kvm/mmu/mmu.c| 31 --- arch/x86/kvm/svm/nested.c | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 444bb9c54548..94378ef1df54

[PATCH v4 4/9] KVM: nSVM: prepare to handle errors from enter_svm_guest_mode()

2020-07-10 Thread Vitaly Kuznetsov
Some operations in enter_svm_guest_mode() may fail, e.g. currently we suppress kvm_set_cr3() return value. Prepare the code to proparate errors. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 26 -- arch/x86/kvm/svm/svm.c

[PATCH v4 0/9] KVM: nSVM: fixes for CR3/MMU switch upon nested guest entry/exit

2020-07-10 Thread Vitaly Kuznetsov
d by running nested Hyper-V on KVM. The series doesn't seem to introduce any new issues. Paolo Bonzini (1): KVM: MMU: stop dereferencing vcpu->arch.mmu to get the context for MMU init Vitaly Kuznetsov (8): KVM: nSVM: split kvm_init_shadow_npt_mmu() from kvm_init_shadow_mmu() KVM: nSVM: res

[PATCH v4 9/9] KVM: x86: drop superfluous mmu_check_root() from fast_pgd_switch()

2020-07-10 Thread Vitaly Kuznetsov
a non-existent GFN is written to CR3 doesn't seem to mach architectural behavior. Drop the check. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 13ec3c30eda2

Re: [PATCH v3 7/9] KVM: nSVM: implement nested_svm_load_cr3() and use it for host->guest switch

2020-07-10 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 10/07/20 13:40, Vitaly Kuznetsov wrote: >> Hm, it seems I missed svm_set_nested_state() path >> completely. Surprisingly, state_test didn't fail) >> >> I'm struggling a bit to understand why we don't have kvm_set_cr3() on >

Re: [PATCH v3 7/9] KVM: nSVM: implement nested_svm_load_cr3() and use it for host->guest switch

2020-07-10 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 09/07/20 19:57, Paolo Bonzini wrote: >> On 09/07/20 16:53, Vitaly Kuznetsov wrote: >>> + if (nested_npt_enabled(svm)) >>> + nested_svm_init_mmu_context(>vcpu); >>> + >>> ret =

[PATCH v3 5/9] KVM: nSVM: introduce nested_svm_load_cr3()

2020-07-09 Thread Vitaly Kuznetsov
-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 35 +++ 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 5e6c988a4e6b..d0fd63e8d835 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm

[PATCH v3 4/9] KVM: nSVM: prepare to handle errors from enter_svm_guest_mode()

2020-07-09 Thread Vitaly Kuznetsov
Some operations in enter_svm_guest_mode() may fail, e.g. currently we suppress kvm_set_cr3() return value. Prepare the code to proparate errors. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 26 -- arch/x86/kvm/svm/svm.c

[PATCH v3 8/9] KVM: nSVM: use nested_svm_load_cr3() on guest->host switch

2020-07-09 Thread Vitaly Kuznetsov
_state() and the later is used to restore from 'partial' switch to L2, it always uses kvm_mmu_reset_context(). nSVM doesn't have this yet. Also, nested_svm_vmexit()'s return value is almost always ignored nowadays. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 15 ++-

[PATCH v3 7/9] KVM: nSVM: implement nested_svm_load_cr3() and use it for host->guest switch

2020-07-09 Thread Vitaly Kuznetsov
the job. Note: the current implementation is sub-optimal as we always do TLB flush/MMU sync but this is still an improvement as we at least stop doing kvm_mmu_reset_context(). Fixes: 7c390d350f8b ("kvm: x86: Add fast CR3 switch code path") Signed-off-by: Vitaly Kuznetsov --- arch/x

[PATCH v3 3/9] KVM: nSVM: reset nested_run_pending upon nested_svm_vmrun_msrpm() failure

2020-07-09 Thread Vitaly Kuznetsov
WARN_ON_ONCE(svm->nested.nested_run_pending) in nested_svm_vmexit() will fire if nested_run_pending remains '1' but it doesn't really need to, we are already failing and not going to run nested guest. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 2 ++ 1 file changed

[PATCH v3 9/9] KVM: x86: drop superfluous mmu_check_root() from fast_pgd_switch()

2020-07-09 Thread Vitaly Kuznetsov
a non-existent GFN is written to CR3 doesn't seem to mach architectural behavior. Drop the check. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 1c3a231f825b

[PATCH v3 1/9] KVM: nSVM: split kvm_init_shadow_npt_mmu() from kvm_init_shadow_mmu()

2020-07-09 Thread Vitaly Kuznetsov
-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu.h| 3 ++- arch/x86/kvm/mmu/mmu.c| 31 --- arch/x86/kvm/svm/nested.c | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 444bb9c54548..94378ef1df54

[PATCH v3 6/9] KVM: nSVM: move kvm_set_cr3() after nested_svm_uninit_mmu_context()

2020-07-09 Thread Vitaly Kuznetsov
don't do kvm_set_cr3() but we're about to switch to nested_svm_load_cr3(). No functional change intended. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm

[PATCH v3 2/9] KVM: nSVM: stop dereferencing vcpu->arch.mmu to get the context in kvm_init_shadow{,_npt}_mmu()

2020-07-09 Thread Vitaly Kuznetsov
Now as kvm_init_shadow_npt_mmu() is separated from kvm_init_shadow_mmu() we always know the MMU context we need to use so there is no need to dereference vcpu->arch.mmu pointer. Suggested-by: Paolo Bonzini Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 15 +++ 1 f

[PATCH v3 0/9] KVM: nSVM: fixes for CR3/MMU switch upon nested guest entry/exit

2020-07-09 Thread Vitaly Kuznetsov
making some progress. Tested with kvm selftests/kvm-unit-tests and by running nested Hyper-V on KVM. The series doesn't seem to introduce any new issues. Vitaly Kuznetsov (9): KVM: nSVM: split kvm_init_shadow_npt_mmu() from kvm_init_shadow_mmu() KVM: nSVM: stop dereferencing vcpu->arch

Re: [PATCH v2 2/3] KVM: nSVM: properly call kvm_mmu_new_pgd() upon switching to guest

2020-07-08 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 08/07/20 11:36, Vitaly Kuznetsov wrote: >> Undesired triple fault gets injected to L1 guest on SVM when L2 is >> launched with certain CR3 values. #TF is raised by mmu_check_root() >> check in fast_pgd_switch() and the root cause is that when >&

[PATCH] KVM: x86: take as_id into account when checking PGD

2020-07-08 Thread Vitaly Kuznetsov
kvm_vcpu_is_visible_gfn() and use it from mmu_check_root(). Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 2 +- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 8 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm

[PATCH v2 0/3] KVM: nSVM: fix #TF from CR3 switch when entering guest

2020-07-08 Thread Vitaly Kuznetsov
pgd_switch(). Vitaly Kuznetsov (3): KVM: nSVM: split kvm_init_shadow_npt_mmu() from kvm_init_shadow_mmu() KVM: nSVM: properly call kvm_mmu_new_pgd() upon switching to guest KVM: x86: drop superfluous mmu_check_root() from fast_pgd_switch() arch/x86/include/asm/kvm_host.h | 7 ++- arch/x86

[PATCH v2 1/3] KVM: nSVM: split kvm_init_shadow_npt_mmu() from kvm_init_shadow_mmu()

2020-07-08 Thread Vitaly Kuznetsov
-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu.h| 3 ++- arch/x86/kvm/mmu/mmu.c| 31 --- arch/x86/kvm/svm/nested.c | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 444bb9c54548..94378ef1df54

[PATCH v2 3/3] KVM: x86: drop superfluous mmu_check_root() from fast_pgd_switch()

2020-07-08 Thread Vitaly Kuznetsov
a non-existent GFN is written to CR3 doesn't seem to mach architectural behavior. Drop the check. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index ebf0cb3f1ce0

[PATCH v2 2/3] KVM: nSVM: properly call kvm_mmu_new_pgd() upon switching to guest

2020-07-08 Thread Vitaly Kuznetsov
Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 7 ++- arch/x86/kvm/mmu/mmu.c | 2 ++ arch/x86/kvm/svm/nested.c | 2 +- arch/x86/kvm/x86.c | 8 +--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h

Re: [RFC 2/2] KVM: VMX: Enable bus lock VM exit

2020-07-01 Thread Vitaly Kuznetsov
Xiaoyao Li writes: > On 7/1/2020 8:44 PM, Vitaly Kuznetsov wrote: >> Xiaoyao Li writes: >> >>> On 7/1/2020 5:04 PM, Vitaly Kuznetsov wrote: >>>> Chenyi Qiang writes: >>> [...] >>>>>static const int kvm_vmx_max_exit_handlers =

Re: [RFC 2/2] KVM: VMX: Enable bus lock VM exit

2020-07-01 Thread Vitaly Kuznetsov
Xiaoyao Li writes: > On 7/1/2020 5:04 PM, Vitaly Kuznetsov wrote: >> Chenyi Qiang writes: > [...] >>> static const int kvm_vmx_max_exit_handlers = >>> @@ -6830,6 +6838,13 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) >>> if (u

Re: [RFC 2/2] KVM: VMX: Enable bus lock VM exit

2020-07-01 Thread Vitaly Kuznetsov
Chenyi Qiang writes: > Virtual Machine can exploit bus locks to degrade the performance of > system. Bus lock can be caused by split locked access to writeback(WB) > memory or by using locks on uncacheable(UC) memory. The bus lock is > typically >1000 cycles slower than an atomic operation

Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error

2020-07-01 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Tue, Jun 30, 2020 at 05:43:54PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > On Tue, Jun 30, 2020 at 05:13:54PM +0200, Vitaly Kuznetsov wrote: >> >> >> >> > - If you retry in kernel, we will change t

Re: [PATCH] KVM: x86: drop erroneous mmu_check_root() from fast_pgd_switch()

2020-07-01 Thread Vitaly Kuznetsov
Junaid Shahid writes: > On 6/30/20 3:07 AM, Vitaly Kuznetsov wrote: >> Undesired triple fault gets injected to L1 guest on SVM when L2 is >> launched with certain CR3 values. It seems the mmu_check_root() >> check in fast_pgd_switch() is wrong: first of all we don't know >

Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error

2020-06-30 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Tue, Jun 30, 2020 at 05:43:54PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > On Tue, Jun 30, 2020 at 05:13:54PM +0200, Vitaly Kuznetsov wrote: >> >> >> >> > - If you retry in kernel, we wi

Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error

2020-06-30 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Tue, Jun 30, 2020 at 05:13:54PM +0200, Vitaly Kuznetsov wrote: >> >> > - If you retry in kernel, we will change the context completely that >> > who was trying to access the gfn in question. We want to retain >> > the rea

Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error

2020-06-30 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Tue, Jun 30, 2020 at 03:24:43PM +0200, Vitaly Kuznetsov wrote: >> >> It's probably me who's missing something important here :-) but I think >> you describe how it *should* work as I'm not seeing how we can leave the >> loop in kvm_async_pf

Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error

2020-06-30 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Mon, Jun 29, 2020 at 10:56:25PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > On Fri, Jun 26, 2020 at 11:25:19AM +0200, Vitaly Kuznetsov wrote: >> > >> > [..] >> >> > diff --git a/arch

[PATCH] KVM: x86: drop erroneous mmu_check_root() from fast_pgd_switch()

2020-06-30 Thread Vitaly Kuznetsov
o mach architecture behavior. Fixes: 7c390d350f8b ("kvm: x86: Add fast CR3 switch code path") Signed-off-by: Vitaly Kuznetsov --- - The patch fixes the immediate issue and doesn't seem to break any tests even with shadow PT but I'm not sure I properly understood why the check was th

Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error

2020-06-29 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Fri, Jun 26, 2020 at 11:25:19AM +0200, Vitaly Kuznetsov wrote: > > [..] >> > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c >> > index 76817d13c86e..a882a6a9f7a7 100644 >> > --- a/arch/x86/kvm/mmu/mmu.c >> >

Re: [PATCH] KVM: X86: Fix async pf caused null-ptr-deref

2020-06-29 Thread Vitaly Kuznetsov
Wanpeng Li writes: > From: Wanpeng Li > > Syzbot reported that: > > CPU: 1 PID: 6780 Comm: syz-executor153 Not tainted 5.7.0-syzkaller #0 > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS > Google 01/01/2011 > RIP: 0010:__apic_accept_irq+0x46/0xb80 > Call Trace:

<    1   2   3   4   5   6   7   8   9   10   >