Re: [PATCH] x86/kvm/hyper-v: Don't deactivate APICv unconditionally when Hyper-V SynIC enabled

2020-11-05 Thread Vitaly Kuznetsov
junjiehua0...@gmail.com writes: > From: Junjie Hua > > The current implementation of Hyper-V SynIC[1] request to deactivate > APICv when SynIC is enabled, since the AutoEOI feature of SynIC is not > compatible with APICv[2]. > > Actually, windows doesn't use AutoEOI if deprecating AutoEOI bit

Re: [PATCH] KVM: x86: Filter out more Intel-specific PMU MSRs in kvm_init_msr_list()

2020-10-30 Thread Vitaly Kuznetsov
Vitaly Kuznetsov writes: > When running KVM selftest in a Hyper-V VM they stumble upon > > Unexpected result from KVM_GET_MSRS, r: 14 (failed MSR was 0x309) > > MSR_ARCH_PERFMON_FIXED_CTR[0..3] along with MSR_CORE_PERF_FIXED_CTR_CTRL, > MSR_CORE_PERF_GLOBAL_STATUS, MSR_COR

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

2020-10-26 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 | 87

[PATCH v4 1/2] KVM: x86: hyper-v: allow KVM_GET_SUPPORTED_HV_CPUID as a system ioctl

2020-10-26 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 | 16 arch/x86/kvm/hyperv.c | 6 ++--- arch/x86/kvm/hyperv.h | 4 +-- arch/x86/kvm/vmx/evmcs.c | 3 +-- arch/x86/kvm/x86.c

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

2020-10-26 Thread Vitaly Kuznetsov
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 (2): KVM: x86: hyper-v: allow KVM_GET_SUPPORTED_HV_CPUID as a system ioctl KVM

Re: [PATCH 2/2] KVM: X86: Fix null pointer reference for KVM_GET_MSRS

2020-10-26 Thread Vitaly Kuznetsov
Peter Xu writes: > kvm_msr_ignored_check() could trigger a null pointer reference 'dereference' but I'd also clarify that 'vcpu' is NULL. > if ignore_msrs=Y > and report_ignore_msrs=Y when try to fetch an invalid feature msr using the > global KVM_GET_MSRS. Degrade the error report to not

Re: [PATCH 1/2] KVM: selftests: Add get featured msrs test case

2020-10-26 Thread Vitaly Kuznetsov
Peter Xu writes: > Try to fetch any supported featured msr. Currently it won't fail, so at least > we can check against valid ones (which should be >0). > > This reproduces [1] too by trying to fetch one invalid msr there. > > [1] https://bugzilla.kernel.org/show_bug.cgi?id=209845 > >

Re: [RFCv2 00/16] KVM protected memory extension

2020-10-23 Thread Vitaly Kuznetsov
"Kirill A. Shutemov" writes: > On Wed, Oct 21, 2020 at 04:46:48PM +0200, Vitaly Kuznetsov wrote: >> "Kirill A. Shutemov" writes: >> >> > Maybe it would be cleaner to handle reboot in userspace? If we got the VM >> > rebooted, just r

Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID

2020-10-22 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 22/10/20 03:34, Wanpeng Li wrote: >> From: Wanpeng Li >> >> Per KVM_GET_SUPPORTED_CPUID ioctl documentation: >> >> This ioctl returns x86 cpuid features which are supported by both the >> hardware and kvm in its default configuration. >> >> A well-behaved

Re: [PATCH v2 05/10] KVM: VMX: Invalidate hv_tlb_eptp to denote an EPTP mismatch

2020-10-22 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Wed, Oct 21, 2020 at 02:39:20PM +0200, Vitaly Kuznetsov wrote: >> Sean Christopherson writes: >> >> > Drop the dedicated 'ept_pointers_match' field in favor of stuffing >> > 'hv_tlb_eptp' with INVALID_PAGE to m

Re: [RFCv2 00/16] KVM protected memory extension

2020-10-21 Thread Vitaly Kuznetsov
"Kirill A. Shutemov" writes: > On Tue, Oct 20, 2020 at 09:46:11AM +0200, Vitaly Kuznetsov wrote: >> "Kirill A. Shutemov" writes: >> >> > == Background / Problem == >> > >> > There are a number of hardware features (MKTME, SEV) whic

Re: [PATCH v2 09/10] KVM: VMX: Skip additional Hyper-V TLB EPTP flushes if one fails

2020-10-21 Thread Vitaly Kuznetsov
gt; + if (ret && mismatch) > + break; > } > if (mismatch) > kvm_vmx->hv_tlb_eptp = INVALID_PAGE; In case my suggestion on PATCH5 gets dismissed, Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 08/10] KVM: VMX: Define Hyper-V paravirt TLB flush fields iff Hyper-V is enabled

2020-10-21 Thread Vitaly Kuznetsov
; > > +#if IS_ENABLED(CONFIG_HYPERV) > hpa_t hv_tlb_eptp; > spinlock_t ept_pointer_lock; > +#endif > }; > > bool nested_vmx_allowed(struct kvm_vcpu *vcpu); Assuming this compiles without CONFIG_HYPERV, Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 06/10] KVM: VMX: Don't invalidate hv_tlb_eptp if the new EPTP matches

2020-10-21 Thread Vitaly Kuznetsov
> to_vmx(vcpu)->ept_pointer = eptp; > - to_kvm_vmx(kvm)->hv_tlb_eptp = INVALID_PAGE; > + if (eptp != to_kvm_vmx(kvm)->hv_tlb_eptp) > + to_kvm_vmx(kvm)->hv_tlb_eptp = INVALID_PAGE; >

Re: [PATCH v2 05/10] KVM: VMX: Invalidate hv_tlb_eptp to denote an EPTP mismatch

2020-10-21 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Drop the dedicated 'ept_pointers_match' field in favor of stuffing > 'hv_tlb_eptp' with INVALID_PAGE to mark it as invalid, i.e. to denote > that there is at least one EPTP mismatch. Use a local variable to > track whether or not a mismatch is detected so that

Re: [PATCH v2 04/10] KVM: VMX: Do Hyper-V TLB flush iff vCPU's EPTP hasn't been flushed

2020-10-21 Thread Vitaly Kuznetsov
> request. */ > - if (VALID_PAGE(to_vmx(vcpu)->ept_pointer)) > - ret |= > hv_remote_flush_eptp(to_vmx(vcpu)->ept_pointer, > - range); > + ret |= hv_remote_

Re: [PATCH v2 03/10] KVM: VMX: Fold Hyper-V EPTP checking into it's only caller

2020-10-21 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Fold check_ept_pointer_match() into hv_remote_flush_tlb_with_range() in > preparation for combining the kvm_for_each_vcpu loops of the ==CHECK and > !=MATCH statements. > > No functional change intended. > > Signed-off-by: Sean Christopherson > --- >

Re: [PATCH v2 02/10] KVM: VMX: Stash kvm_vmx in a local variable for Hyper-V paravirt TLB flush

2020-10-21 Thread Vitaly Kuznetsov
spin_unlock(_kvm_vmx(kvm)->ept_pointer_lock); > + spin_unlock(_vmx->ept_pointer_lock); > return ret; > } > static int hv_remote_flush_tlb(struct kvm *kvm) Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 01/10] KVM: VMX: Track common EPTP for Hyper-V's paravirt TLB flush

2020-10-21 Thread Vitaly Kuznetsov
lock); > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h > index 5961cb897125..3d557a065c01 100644 > --- a/arch/x86/kvm/vmx/vmx.h > +++ b/arch/x86/kvm/vmx/vmx.h > @@ -301,6 +301,7 @@ struct kvm_vmx { > bool ept_identity_pagetable_done; > gpa_t ept_identity_map_addr; > > + hpa_t hv_tlb_eptp; > enum ept_pointers_status ept_pointers_match; > spinlock_t ept_pointer_lock; > }; Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 00/10] KVM: VMX: Clean up Hyper-V PV TLB flush

2020-10-21 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Clean up KVM's PV TLB flushing when running with EPT on Hyper-V, i.e. as > a nested VMM. The terminology we use is a bit confusing and I'd like to use the opportunity to enlighten myself on how to call "PV TLB flushing" properly :-) Hyper-V supports two types of

Re: [RFCv2 00/16] KVM protected memory extension

2020-10-20 Thread Vitaly Kuznetsov
"Kirill A. Shutemov" writes: > == Background / Problem == > > There are a number of hardware features (MKTME, SEV) which protect guest > memory from some unauthorized host access. The patchset proposes a purely > software feature that mitigates some of the same host-side read-only > attacks. > >

Re: [PATCH v4] KVM: Check the allocation of pv cpu mask

2020-10-19 Thread Vitaly Kuznetsov
Haiwei Li writes: > And 'pv_ops.mmu.tlb_remove_table = tlb_remove_table' should not > be set either. AFAIU by looking at the commit which added it (48a8b97cfd80 "x86/mm: Only use tlb_remove_table() for paravirt") it sholdn't hurt much. We could've avoided the assignment but it happens much

Re: [PATCH v4] KVM: Check the allocation of pv cpu mask

2020-10-19 Thread Vitaly Kuznetsov
lihaiwei.ker...@gmail.com writes: > From: Haiwei Li > > check the allocation of per-cpu __pv_cpu_mask. Init > 'send_IPI_mask_allbutself' only when successful and check the allocation > of __pv_cpu_mask in 'kvm_flush_tlb_others'. > > Suggested-by: Vitaly Kuznetsov >

[PATCH v2] KVM: VMX: eVMCS: make evmcs_sanitize_exec_ctrls() work again

2020-10-14 Thread Vitaly Kuznetsov
CPU so we don't really need it to. Switch to checking 'enlightened_vmcs' instead, it is supposed to be in sync with 'enable_evmcs'. Opportunistically make evmcs_sanitize_exec_ctrls '__init' and drop unneeded extra newline from it. Reported-by: Yang Weijiang Signed-off-by: Vitaly Kuznetsov

[PATCH] KVM: x86: Filter out more Intel-specific PMU MSRs in kvm_init_msr_list()

2020-10-14 Thread Vitaly Kuznetsov
PU PMU setup depends on guest CPUIDs which can always be altered. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/x86.c | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ce856e0ece84..85d72b125fba 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x

[PATCH] KVM: VMX: eVMCS: make evmcs_sanitize_exec_ctrls() work again

2020-10-14 Thread Vitaly Kuznetsov
CPU so we don't really need it to. Switch to checking 'enlightened_vmcs' instead, it is supposed to be in sync with 'enable_evmcs'. Opportunistically make evmcs_sanitize_exec_ctrls '__init' and drop unneeded extra newline from it. Reported-by: Yang Weijiang Signed-off-by: Vitaly Kuznetsov

Re: [PATCH v3 0/2] KVM: x86: hyper-v: make KVM_GET_SUPPORTED_HV_CPUID more useful

2020-10-12 Thread Vitaly Kuznetsov
Vitaly Kuznetsov writes: > Changes since v2: > - Keep vCPU version of the ioctl intact but make it 'deprecated' in > api.rst [Paolo Bonzini] > - First two patches of v2 series already made it to kvm/queue > > QEMU series using the feature: > https://lists.gnu.org/archive

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

2020-10-06 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Tue, Oct 06, 2020 at 05:24:54PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> > So you will have to report token (along with -EFAULT) to user space. So >> > this >> > is basically the 3rd proposal which is exten

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

2020-10-06 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Tue, Oct 06, 2020 at 04:50:44PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > On Tue, Oct 06, 2020 at 04:05:16PM +0200, Vitaly Kuznetsov wrote: >> >> Vivek Goyal writes: >> >> >> >>

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

2020-10-06 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Tue, Oct 06, 2020 at 04:05:16PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > A. Just exit to user space with -EFAULT (using kvm request) and don't >> >wait for the accessing task to run on vcpu again. >>

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

2020-10-06 Thread Vitaly Kuznetsov
Vivek Goyal writes: > A. Just exit to user space with -EFAULT (using kvm request) and don't >wait for the accessing task to run on vcpu again. What if we also save the required information (RIP, GFN, ...) in the guest along with the APF token so in case of -EFAULT we can just 'crash' the

Re: [PATCH] KVM: x86: filter guest NX capability for cpuid2

2020-10-06 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Oct 05, 2020 at 05:29:47PM +0200, Vitaly Kuznetsov wrote: >> Tianjia Zhang writes: >> >> > Original KVM_SET_CPUID has removed NX on non-NX hosts as it did >> > before. but KVM_SET_CPUID2 does not. The two should be

Re: [PATCH] KVM: x86: filter guest NX capability for cpuid2

2020-10-05 Thread Vitaly Kuznetsov
Tianjia Zhang writes: > Original KVM_SET_CPUID has removed NX on non-NX hosts as it did > before. but KVM_SET_CPUID2 does not. The two should be consistent. > > Signed-off-by: Tianjia Zhang > --- > arch/x86/kvm/cpuid.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git

Re: [PATCH 1/3] KVM: x86: disconnect kvm_check_cpuid() from vcpu->arch.cpuid_entries

2020-10-05 Thread Vitaly Kuznetsov
Maxim Levitsky writes: > On Thu, 2020-10-01 at 15:05 +0200, Vitaly Kuznetsov wrote: >> As a preparatory step to allocating vcpu->arch.cpuid_entries dynamically >> make kvm_check_cpuid() check work with an arbitrary 'struct kvm_cpuid_entry2' >> array. >> >

Re: [PATCH] x86/kvm: Update the comment about asynchronous page fault in exc_page_fault()

2020-10-05 Thread Vitaly Kuznetsov
Vitaly Kuznetsov writes: > KVM was switched to interrupt-based mechanism for 'page ready' event > delivery in Linux-5.8 (see commit 2635b5c4a0e4 ("KVM: x86: interrupt based > APF 'page ready' event delivery")) and #PF (ab)use for 'page ready' event > delivery was removed

[PATCH] x86/kvm: Update the comment about asynchronous page fault in exc_page_fault()

2020-10-02 Thread Vitaly Kuznetsov
xclusively in 5.9 (see commit b1d405751cd5 ("KVM: x86: Switch KVM guest to using interrupts for page ready APF delivery")) so it is not possible to get older KVM (APF mechanism won't be enabled). Update the comment in exc_page_fault() to reflect the new reality. Signed-off-by: Vitaly Kuznets

Re: [PATCH] x86/kvm: hide KVM options from menuconfig when KVM is not compiled

2020-10-01 Thread Vitaly Kuznetsov
; # We use the dependency on !COMPILE_TEST to not be enabled > # blindly in allmodconfig or allyesconfig configurations > + depends on KVM > depends on (X86_64 && !KASAN) || !COMPILE_TEST > depends on EXPERT > help Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH] x86/hyper-v: guard against cpu mask changes in hyperv_flush_tlb_others()

2020-10-01 Thread Vitaly Kuznetsov
Wei Liu writes: > On Thu, Oct 01, 2020 at 11:40:04AM +0200, Vitaly Kuznetsov wrote: >> Sasha Levin writes: >> >> > cpumask can change underneath us, which is generally safe except when we >> > call into hv_cpu_number_to_vp_number(): if cpumask ends up em

[PATCH 3/3] KVM: x86: bump KVM_MAX_CPUID_ENTRIES

2020-10-01 Thread Vitaly Kuznetsov
ary value '256' as the new limit. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 7d259e21ea04..f6d6df64e63a 100644 --- a/arch/x86/include/

[PATCH 2/3] KVM: x86: allocate vcpu->arch.cpuid_entries dynamically

2020-10-01 Thread Vitaly Kuznetsov
ntries so no changes are made in case the check fails. Opportunistically remove unneeded 'out' labels from kvm_vcpu_ioctl_set_cpuid()/kvm_vcpu_ioctl_set_cpuid2() and return directly whenever possible. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kv

[PATCH 1/3] KVM: x86: disconnect kvm_check_cpuid() from vcpu->arch.cpuid_entries

2020-10-01 Thread Vitaly Kuznetsov
the same in kvm_vcpu_ioctl_set_cpuid() as we'll have to copy 'struct kvm_cpuid_entry' entries first. The change will be made when vcpu->arch.cpuid_entries[] array becomes allocated dynamically. Suggested-by: Sean Christopherson Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/

[PATCH 0/3] KVM: x86: allow for more CPUID entries

2020-10-01 Thread Vitaly Kuznetsov
y. Very mildly tested with selftests/kvm-unit-tests and nothing seems to break. I also don't have access to the system where the original issue was reported but chances we're fixing it are very good IMO as just the second patch alone was reported to be sufficient. Reported-by: Dr. David Alan Gilbert Vital

Re: [PATCH RFC 1/2] KVM: x86: allocate vcpu->arch.cpuid_entries dynamically

2020-10-01 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Tue, Sep 15, 2020 at 05:43:05PM +0200, Vitaly Kuznetsov wrote: >> The current limit for guest CPUID leaves (KVM_MAX_CPUID_ENTRIES, 80) >> is reported to be insufficient but before we bump it let's switch to >> allocating vcpu->arch.c

Re: [PATCH] x86/hyper-v: guard against cpu mask changes in hyperv_flush_tlb_others()

2020-10-01 Thread Vitaly Kuznetsov
uot;x86/hyper-v: Use cheaper > HVCALL_FLUSH_VIRTUAL_ADDRESS_{LIST,SPACE} hypercalls when possible") > Cc: Vitaly Kuznetsov > Cc: sta...@kernel.org > Signed-off-by: Sasha Levin > --- > arch/x86/hyperv/mmu.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) >

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

2020-09-29 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 | 87

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

2020-09-29 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 (2

[PATCH v3 1/2] KVM: x86: hyper-v: allow KVM_GET_SUPPORTED_HV_CPUID as a system ioctl

2020-09-29 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 | 16 arch/x86/kvm/hyperv.c | 6 ++--- arch/x86/kvm/hyperv.h | 4 +-- arch/x86/kvm/vmx/evmcs.c | 3 +-- arch/x86/kvm/x86.c

Re: [PATCH v3] KVM: Check the allocation of pv cpu mask

2020-09-29 Thread Vitaly Kuznetsov
lihaiwei.ker...@gmail.com writes: > From: Haiwei Li > > check the allocation of per-cpu __pv_cpu_mask. > > Suggested-by: Vitaly Kuznetsov > Signed-off-by: Haiwei Li > --- > v1 -> v2: > * add CONFIG_SMP for kvm_send_ipi_mask_allbutself to prevent build error

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

2020-09-29 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 29/09/20 12:36, Vitaly Kuznetsov wrote: >>> Sorry for the late reply. I think this is making things worse. It's >>> obviously okay to add a system KVM_GET_SUPPORTED_HV_CPUID, and I guess >>> it makes sense to have bits in there that requ

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

2020-09-29 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 24/09/20 16:57, Vitaly Kuznetsov wrote: >> HV_STIMER_DIRECT_MODE_AVAILABLE is the last conditionally set feature bit >> in KVM_GET_SUPPORTED_HV_CPUID but it doesn't have to be conditional: first, >> this bit is only an indication to userspace

Re: [PATCH] KVM: VMX: Explicitly check for hv_remote_flush_tlb when loading pgd()

2020-09-25 Thread Vitaly Kuznetsov
defined iff CONFIG_HYPERV!=n. > > Short term, the explicit check makes it more obvious why a non-NULL > tlb_remote_flush() triggers EPTP shenanigans. Long term, this will > allow TDX to define its own implementation of tlb_remote_flush() without > running afoul of Hyper-V. > > C

Re: [RFC PATCH 3/3] KVM: x86: Use KVM_BUG/KVM_BUG_ON to handle bugs that are fatal to the VM

2020-09-25 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Thu, Sep 24, 2020 at 02:34:14PM +0200, Vitaly Kuznetsov wrote: >> Sean Christopherson writes: >> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >> > index 6f9a0c6d5dc5..810d46ab0a47 100644 >> > --- a/arch/x86/k

Re: [PATCH] hv: clocksource: Add notrace attribute to read_hv_sched_clock_*() functions

2020-09-24 Thread Vitaly Kuznetsov
x10/0x10 > [69703.123035] ? sched_clock+0x5/0x10 > [69703.123044] ? ftrace_graph_caller+0x6b/0xa0 > [69703.123059] ? read_hv_clock_tsc_cs+0x10/0x10 > [69703.123068] ? sched_clock+0x5/0x10 Obviously we're seeing a recursion, we can trim this log a bit. > > Setting the

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

2020-09-24 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

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

2020-09-24 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 | 3 ++- 3 files changed, 30 insertions(+), 20

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

2020-09-24 Thread Vitaly Kuznetsov
put (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): KVM: x86: hyper-v: Mention SynDBG CPUID leaves in api.rst KVM: x86: hyper-v: disal

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

2020-09-24 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 v2 3/7] KVM: x86: hyper-v: make KVM_GET_SUPPORTED_HV_CPUID output independent of eVMCS enablement

2020-09-24 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 v2 7/7] KVM: selftests: test KVM_GET_SUPPORTED_HV_CPUID as a system ioctl

2020-09-24 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 v2 5/7] KVM: x86: hyper-v: drop now unneeded vcpu parameter from kvm_vcpu_ioctl_get_hv_cpuid()

2020-09-24 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 v2 2/7] KVM: x86: hyper-v: disallow configuring SynIC timers with no SynIC

2020-09-24 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

Re: [PATCH] KVM: SVM: Add a dedicated INVD intercept routine

2020-09-24 Thread Vitaly Kuznetsov
Tom Lendacky writes: > From: Tom Lendacky > > The INVD instruction intercept performs emulation. Emulation can't be done > on an SEV guest because the guest memory is encrypted. > > Provide a dedicated intercept routine for the INVD intercept. Within this > intercept routine just skip the

Re: [PATCH] KVM: x86/mmu: Stash 'kvm' in a local variable in kvm_mmu_free_roots()

2020-09-24 Thread Vitaly Kuznetsov
; > - spin_unlock(>kvm->mmu_lock); > + kvm_mmu_commit_zap_page(kvm, _list); > + spin_unlock(>mmu_lock); > } > EXPORT_SYMBOL_GPL(kvm_mmu_free_roots); What about kvm_mmu_get_page(), make_mmu_pages_available(), mmu_alloc_root(), kvm_mmu_sync_roots(), direct_page_fault(), kvm_mmu_pte_write() which seem to be using the same ugly pattern? :-) Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [RFC PATCH 3/3] KVM: x86: Use KVM_BUG/KVM_BUG_ON to handle bugs that are fatal to the VM

2020-09-24 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Add support for KVM_REQ_VM_BUGG in x86, and replace a variety of WARNs > with KVM_BUG() and KVM_BUG_ON(). Return -EIO if a KVM_BUG is hit to > align with the common KVM behavior of rejecting iocts() with -EIO if the > VM is bugged. > > Signed-off-by: Sean

RE: [EXTERNAL] Re: [PATCH RFC v1 08/18] x86/hyperv: handling hypercall page setup for root

2020-09-17 Thread Vitaly Kuznetsov
Sunil Muthuswamy writes: >> >> On Tue, Sep 15, 2020 at 12:32:29PM +0200, Vitaly Kuznetsov wrote: >> > Wei Liu writes: >> > >> > > When Linux is running as the root partition, the hypercall page will >> > > have already been setup by Hyper

Re: [PATCH] Revert "KVM: Check the allocation of pv cpu mask"

2020-09-16 Thread Vitaly Kuznetsov
Haiwei Li writes: > On 20/9/16 17:03, Vitaly Kuznetsov wrote: >> The commit 0f990222108d ("KVM: Check the allocation of pv cpu mask") we >> have in 5.9-rc5 has two issue: >> 1) Compilation fails for !CONFIG_SMP, see: >> https://bugzilla.kernel.org/show_bu

Re: [PATCH RFC v1 06/18] x86/hyperv: allocate output arg pages if required

2020-09-16 Thread Vitaly Kuznetsov
Wei Liu writes: > On Tue, Sep 15, 2020 at 12:43:18PM +, Wei Liu wrote: >> On Tue, Sep 15, 2020 at 12:16:58PM +0200, Vitaly Kuznetsov wrote: >> > Wei Liu writes: >> > >> > > When Linux runs as the root partition, it will need to make hypercalls >&

[PATCH] Revert "KVM: Check the allocation of pv cpu mask"

2020-09-16 Thread Vitaly Kuznetsov
87y2lrnnyf@vitty.brq.redhat.com/ The allocation problem is likely a theoretical one, if we don't have memory that early in boot process we're likely doomed anyway. Let's solve it properly later. This reverts commit 0f990222108d214a0924d920e6095b58107d7b59. Signed-off-by: Vitaly Kuznetsov ---

Re: [PATCH RFC 0/2] KVM: x86: allow for more CPUID entries

2020-09-16 Thread Vitaly Kuznetsov
Wei Huang writes: > On 09/15 05:51, Dr. David Alan Gilbert wrote: >> * Vitaly Kuznetsov (vkuzn...@redhat.com) wrote: >> > With QEMU and newer AMD CPUs (namely: Epyc 'Rome') the current limit for > > Could you elaborate on this limit? On Rome, I counted ~35 CPUID func

Re: [PATCH RFC v1 10/18] x86/hyperv: implement and use hv_smp_prepare_cpus

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > Microsoft Hypervisor requires the root partition to make a few > hypercalls to setup application processors before they can be used. > > Signed-off-by: Lillian Grassin-Drake > Signed-off-by: Sunil Muthuswamy > Co-Developed-by: Lillian Grassin-Drake > Co-Developed-by: Sunil

Re: [PATCH RFC v1 13/18] asm-generic/hyperv: introduce hv_device_id and auxiliary structures

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > We will need to identify the device we want Microsoft Hypervisor to > manipulate. Introduce the data structures for that purpose. > > They will be used in a later patch. > > Signed-off-by: Sunil Muthuswamy > Co-Developed-by: Sunil Muthuswamy > Signed-off-by: Wei Liu > --- >

[PATCH RFC 2/2] KVM: x86: bump KVM_MAX_CPUID_ENTRIES

2020-09-15 Thread Vitaly Kuznetsov
ary value '256' as the new limit. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 0c5f2ca3e838..c1d942c9eb58 100644 --- a/arch/x86/include/

[PATCH RFC 1/2] KVM: x86: allocate vcpu->arch.cpuid_entries dynamically

2020-09-15 Thread Vitaly Kuznetsov
for 1/4 of the whole 'struct kvm_vcpu_arch' but having it pre-allocated (for all vCPUs which we also pre-allocate) gives us no benefits. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/cpuid.c| 55 - arch/x86/k

[PATCH RFC 0/2] KVM: x86: allow for more CPUID entries

2020-09-15 Thread Vitaly Kuznetsov
ery good IMO as just the second patch alone was reported to be sufficient. Reported-by: Dr. David Alan Gilbert Vitaly Kuznetsov (2): KVM: x86: allocate vcpu->arch.cpuid_entries dynamically KVM: x86: bump KVM_MAX_CPUID_ENTRIES arch/x86/include/asm/kvm_host.h | 4 +-- arch/x86/kvm/c

Re: [PATCH RFC v1 08/18] x86/hyperv: handling hypercall page setup for root

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > On Tue, Sep 15, 2020 at 01:02:08PM +0200, Vitaly Kuznetsov wrote: >> Wei Liu writes: >> >> > On Tue, Sep 15, 2020 at 12:32:29PM +0200, Vitaly Kuznetsov wrote: >> >> Wei Liu writes: >> >> >> >> >

Re: [PATCH RFC v1 08/18] x86/hyperv: handling hypercall page setup for root

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > On Tue, Sep 15, 2020 at 12:32:29PM +0200, Vitaly Kuznetsov wrote: >> Wei Liu writes: >> >> > When Linux is running as the root partition, the hypercall page will >> > have already been setup by Hyper-V. Copy the content over to the >>

Re: [PATCH RFC v1 09/18] x86/hyperv: provide a bunch of helper functions

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > They are used to deposit pages into Microsoft Hypervisor and bring up > logical and virtual processors. > > Signed-off-by: Lillian Grassin-Drake > Signed-off-by: Sunil Muthuswamy > Signed-off-by: Nuno Das Neves > Co-Developed-by: Lillian Grassin-Drake > Co-Developed-by:

Re: [PATCH RFC v1 08/18] x86/hyperv: handling hypercall page setup for root

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > When Linux is running as the root partition, the hypercall page will > have already been setup by Hyper-V. Copy the content over to the > allocated page. And we can't setup a new hypercall page by writing something different to HV_X64_MSR_HYPERCALL, right? > > The suspend,

Re: [PATCH RFC v1 07/18] x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > We will need the partition ID for executing some hypercalls later. > > Signed-off-by: Lillian Grassin-Drake > Co-Developed-by: Sunil Muthuswamy > Signed-off-by: Wei Liu > --- > arch/x86/hyperv/hv_init.c | 26 ++ >

Re: [PATCH RFC v1 06/18] x86/hyperv: allocate output arg pages if required

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > When Linux runs as the root partition, it will need to make hypercalls > which return data from the hypervisor. > > Allocate pages for storing results when Linux runs as the root > partition. > > Signed-off-by: Lillian Grassin-Drake > Co-Developed-by: Lillian Grassin-Drake >

Re: [PATCH RFC v1 05/18] clocksource/hyperv: use MSR-based access if running as root

2020-09-15 Thread Vitaly Kuznetsov
Wei Liu writes: > Signed-off-by: Wei Liu > --- > drivers/clocksource/hyperv_timer.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/clocksource/hyperv_timer.c > b/drivers/clocksource/hyperv_timer.c > index 09aa44cb8a91..fe96082ce85e 100644 > ---

Re: [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()

2020-09-14 Thread Vitaly Kuznetsov
Joerg Roedel writes: > From: Joerg Roedel > > The save and ctl pointers need to be initialized to NULL because there > is a way through the function in which there is no memory allocated > for the pointers but where they are freed in the end. > > This involves the 'goto out_set_gif' before the

[tip: x86/seves] KVM: nSVM: Avoid freeing uninitialized pointers in svm_set_nested_state()

2020-09-14 Thread tip-bot2 for Vitaly Kuznetsov
The following commit has been merged into the x86/seves branch of tip: Commit-ID: e6eb15c9ba3165698488ae5c34920eea20eaa38e Gitweb: https://git.kernel.org/tip/e6eb15c9ba3165698488ae5c34920eea20eaa38e Author:Vitaly Kuznetsov AuthorDate:Mon, 14 Sep 2020 15:37:25 +02:00

[PATCH tip] KVM: nSVM: avoid freeing uninitialized pointers in svm_set_nested_state()

2020-09-14 Thread Vitaly Kuznetsov
orted-by: Colin King Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 598a769f1961..67e6d053985d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/

Re: [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()

2020-09-14 Thread Vitaly Kuznetsov
Joerg Roedel writes: > Hi Vitaly, > > On Mon, Sep 14, 2020 at 02:04:27PM +0200, Vitaly Kuznetsov wrote: >> this was previously reported by Colin: >> https://lore.kernel.org/kvm/2020090730.24238-1-colin.k...@canonical.com/ >> >> the fix itself looks go

Re: ** POTENTIAL FRAUD ALERT - RED HAT ** [PATCH 1/1] Drivers: hv: vmbus: Add timeout to vmbus_wait_for_unload

2020-09-14 Thread Vitaly Kuznetsov
10 seconds so that the panic path can't get > + * hung forever in case the response message isn't seen. >*/ > - while (1) { > + for (i = 0; i < 1000; i++) { > if (completion_done(_connection.unload_event)) > break; LGTM, Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH][next] KVM: SVM: nested: fix free of uninitialized pointers save and ctl

2020-09-11 Thread Vitaly Kuznetsov
Colin King writes: > From: Colin Ian King > > Currently the error exit path to outt_set_gif will kfree on > uninitialized typo: out_set_gif > pointers save and ctl. Fix this by ensuring these pointers are > inintialized to NULL to avoid garbage pointer freeing. > > Addresses-Coverity:

[PATCH] KVM: x86: always allow writing '0' to MSR_KVM_ASYNC_PF_EN

2020-09-11 Thread Vitaly Kuznetsov
async pf caused null-ptr-deref") Reported-by: Dr. David Alan Gilbert Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/x86.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d39d6cf1d473..44a86f7f2397 100644 --- a/arch/x86

Re: [PATCH 3/3] KVM: SVM: Reenable handle_fastpath_set_msr_irqoff() after complete_interrupts()

2020-09-09 Thread Vitaly Kuznetsov
kvm_after_interrupt(>vcpu); > @@ -3529,6 +3533,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct > kvm_vcpu *vcpu) > svm_handle_mce(svm); > > svm_complete_interrupts(svm); > + exit_fastpath = svm_exit_handlers_fastpath(vcpu); > > vmcb_mark_all_clean(svm->vmcb); > return exit_fastpath; Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH 2/3] KVM: SVM: Move svm_complete_interrupts() into svm_vcpu_run()

2020-09-09 Thread Vitaly Kuznetsov
turn exit_fastpath; > } This seems to be the right thing to do, however, the amount of code between kvm_x86_ops.run() and kvm_x86_ops.handle_exit() is non-trivial, hope it won't blow up in testing... Reviewed-by: Vitaly Kuznetsov One more thing: VMX version does vmx_complete_interrupt

Re: [PATCH 1/3] KVM: SVM: Get rid of handle_fastpath_set_msr_irqoff()

2020-09-09 Thread Vitaly Kuznetsov
the whole seeries seems to be appropriate, so: Reviewed-by: Vitaly Kuznetsov > > Reported-by: Paul K. > Suggested-by: Sean Christopherson > Cc: Paul K. > Cc: # v5.8-rc1+ > Fixes: 404d5d7bff0d (KVM: X86: Introduce more exit_fastpath_completion enum > values) > Signed-off-by: Wa

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

2020-09-07 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Fri, Sep 04, 2020 at 09:29:05AM +0200, Gerd Hoffmann wrote: >> Hi, >> >> > Unless I'm mistaken, microvm doesn't even support PCI, does it? >> >> Correct, no pci support right now. >> >> We could probably wire up ecam (arm/virt style) for pcie support, once

Re: [PATCH v2] KVM: fix memory leak in kvm_io_bus_unregister_dev()

2020-09-04 Thread Vitaly Kuznetsov
d iterate over all other devices linked to it and call >> > kvm_iodevice_destructor() for them >> > >> > Reported-and-tested-by: >> > syzbot+f196caa45793d6374...@syzkaller.appspotmail.com >> > Link: https://syzkaller.appspot.com/bug?extid=f196caa45793d6374707 >>

Re: [PATCH] KVM: SVM: Add tracepoint for cr_interception

2020-09-04 Thread Vitaly Kuznetsov
efault:' case above does 'return 1;' so we won't get the trace but I understand you put trace_kvm_cr_read() here so you can log the returned 'val', #UD should be clearly visible. > } > return kvm_complete_insn_gp(>vcpu, err); > } > -- > 2.18.4 > Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2] KVM: Check the allocation of pv cpu mask

2020-09-04 Thread Vitaly Kuznetsov
Haiwei Li writes: > On 20/9/3 18:39, Vitaly Kuznetsov wrote: >> Haiwei Li writes: >> >>> From: Haiwei Li >>> >>> check the allocation of per-cpu __pv_cpu_mask. Initialize ops only when >>> successful. >>> >>>

Re: [PATCH v2] KVM: Check the allocation of pv cpu mask

2020-09-03 Thread Vitaly Kuznetsov
Haiwei Li writes: > From: Haiwei Li > > check the allocation of per-cpu __pv_cpu_mask. Initialize ops only when > successful. > > Signed-off-by: Haiwei Li > --- > arch/x86/kernel/kvm.c | 24 > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git

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

2020-09-02 Thread Vitaly Kuznetsov
hunks changed > nearby KVM_REQ_MMU_SYNC instead. > > The this patch changes it back. > > Link: > https://lore.kernel.org/lkml/20200320212833.3507-26-sean.j.christopher...@intel.com/ > Cc: Sean Christopherson > Cc: Vitaly Kuznetsov > Signed-off-by: Lai Jiangshan > ---

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

2020-09-02 Thread Vitaly Kuznetsov
Peter Xu writes: > On Tue, Sep 01, 2020 at 04:43:25PM +0200, Vitaly Kuznetsov wrote: >> 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 &

Re: [PATCH] KVM: fix memory leak in kvm_io_bus_unregister_dev()

2020-09-01 Thread Vitaly Kuznetsov
_count; j++) { if (j == i) continue; kvm_iodevice_destructor(bus->range[j].dev); } rcu_assign_pointer(kvm->buses[bus_idx], new_bus); synchronize_srcu_expedited(>srcu); kfree(bus); return; > } None of the above should block the fix IMO, so: Reviewed-by: Vitaly Kuznetsov -- Vitaly

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

2020-09-01 Thread Vitaly Kuznetsov
Vitaly Kuznetsov writes: > KVM_GET_SUPPORTED_HV_CPUID was initially implemented as a vCPU ioctl but > this is not very useful when VMM is just trying to query which Hyper-V > features are supported by the host prior to creating VM/vCPUs. The data > in KVM_GET_SUPPORTED_HV_CPUID is m

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