Re: [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization

2020-05-14 Thread Vitaly Kuznetsov
Thomas Gleixner writes: > Vitaly Kuznetsov writes: >> Vitaly Kuznetsov writes: >> >>> This series is a successor of "[PATCH] x86/idt: Keep spurious entries unset >>> in system_vectors". >>> >>> The original issue I tried to address w

Re: [PATCH 4/8] KVM: x86: interrupt based APF page-ready event delivery

2020-05-14 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Wed, May 13, 2020 at 04:23:55PM +0200, Vitaly Kuznetsov wrote: > > [..] >> >> Also, >> >> kdump kernel may not even support APF so it will get very confused when >> >> APF events get delivered. >> > >> >

[tip: x86/entry] x86/idt: Annotate alloc_intr_gate() with __init

2020-05-13 Thread tip-bot2 for Vitaly Kuznetsov
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 4c74d51dab3dd655062a4740af150c1835e19cff Gitweb: https://git.kernel.org/tip/4c74d51dab3dd655062a4740af150c1835e19cff Author:Vitaly Kuznetsov AuthorDate:Tue, 28 Apr 2020 11:38:23 +02:00

[tip: x86/entry] x86/xen: Split HVM vector callback setup and interrupt gate allocation

2020-05-13 Thread tip-bot2 for Vitaly Kuznetsov
The following commit has been merged into the x86/entry branch of tip: Commit-ID: fad1940a6a856f59b073e8650e02052ce531154c Gitweb: https://git.kernel.org/tip/fad1940a6a856f59b073e8650e02052ce531154c Author:Vitaly Kuznetsov AuthorDate:Tue, 28 Apr 2020 11:38:22 +02:00

[tip: x86/entry] x86/idt: Keep spurious entries unset in system_vectors

2020-05-13 Thread tip-bot2 for Vitaly Kuznetsov
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 82ff351052bcc4bf49dc966960f563d25f54d22b Gitweb: https://git.kernel.org/tip/82ff351052bcc4bf49dc966960f563d25f54d22b Author:Vitaly Kuznetsov AuthorDate:Tue, 28 Apr 2020 11:38:24 +02:00

Re: [PATCH 4/8] KVM: x86: interrupt based APF page-ready event delivery

2020-05-13 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Wed, May 13, 2020 at 11:03:48AM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > On Tue, May 12, 2020 at 05:50:53PM +0200, Vitaly Kuznetsov wrote: >> >> Vivek Goyal writes: >> >> >> >> > >

Re: [PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization

2020-05-13 Thread Vitaly Kuznetsov
Vitaly Kuznetsov writes: > This series is a successor of "[PATCH] x86/idt: Keep spurious entries unset > in system_vectors". > > The original issue I tried to address was that /proc/interrupts output > was always containing all possible system vectors, including

Re: [PATCH 2/8] KVM: x86: extend struct kvm_vcpu_pv_apf_data with token info

2020-05-13 Thread Vitaly Kuznetsov
Sean Christopherson writes: > > Why bother preserving backwards compatibility? AIUI, both KVM and guest > will support async #PF iff interrupt delivery is enabled. Why not make > the interrupt delivery approach KVM_ASYNC_PF_V2 and completely redefine the > ABI? E.g. to make it compatible with

Re: [PATCH 4/8] KVM: x86: interrupt based APF page-ready event delivery

2020-05-13 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Tue, May 12, 2020 at 05:50:53PM +0200, Vitaly Kuznetsov wrote: >> Vivek Goyal writes: >> >> > >> > So if we are using a common structure "kvm_vcpu_pv_apf_data" to deliver >> > type1 and type2 events, to me it makes se

Re: [PATCH 0/8] KVM: x86: Interrupt-based mechanism for async_pf 'page present' notifications

2020-05-12 Thread Vitaly Kuznetsov
he feature gets enabled automatically. Note, guest kernel needs to be updated too. -- Vitaly >From 24d78c031f5348764f880698b01b574ca8748ea4 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Tue, 12 May 2020 18:03:53 +0200 Subject: [PATCH 1/2] linux headers: KVM_FEATURE_ASYNC_PF_INT

[PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications

2020-05-12 Thread Vitaly Kuznetsov
ons upon hibernation we need to restore them on resume. Check if hv_reenlightenment_cb was previously set and restore from hv_resume(). Signed-off-by: Vitaly Kuznetsov --- arch/x86/hyperv/hv_init.c | 19 +-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/

Re: [PATCH 4/8] KVM: x86: interrupt based APF page-ready event delivery

2020-05-12 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Mon, May 11, 2020 at 06:47:48PM +0200, Vitaly Kuznetsov wrote: >> Concerns were expressed around APF delivery via synthetic #PF exception as >> in some cases such delivery may collide with real page fault. For type 2 >> (page ready) notifications

Re: [PATCH 2/8] KVM: x86: extend struct kvm_vcpu_pv_apf_data with token info

2020-05-12 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Mon, May 11, 2020 at 06:47:46PM +0200, Vitaly Kuznetsov wrote: >> Currently, APF mechanism relies on the #PF abuse where the token is being >> passed through CR2. If we switch to using interrupts to deliver page-ready >> notifications we need a

[PATCH 5/8] KVM: x86: acknowledgment mechanism for async pf page ready notifications

2020-05-11 Thread Vitaly Kuznetsov
uce kvm_arch_async_page_present_queued() and KVM_REQ_APF_READY to do the job. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/msr.rst | 18 +++--- arch/s390/include/asm/kvm_host.h | 2 ++ arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/include/uapi/

[PATCH 6/8] KVM: x86: announce KVM_FEATURE_ASYNC_PF_INT

2020-05-11 Thread Vitaly Kuznetsov
Introduce new capability to indicate that KVM supports interrupt based delivery of type 2 APF events (page ready notifications). This includes support for both MSR_KVM_ASYNC_PF_INT and MSR_KVM_ASYNC_PF_ACK. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/cpuid.rst | 6

[PATCH 7/8] KVM: x86: Switch KVM guest to using interrupts for page ready APF delivery

2020-05-11 Thread Vitaly Kuznetsov
KVM now supports using interrupt for type 2 APF event delivery (page ready notifications) and legacy mechanism was deprecated. Switch KVM guests to the new one. Signed-off-by: Vitaly Kuznetsov --- arch/x86/entry/entry_32.S | 5 arch/x86/entry/entry_64.S | 5 arch

[PATCH 4/8] KVM: x86: interrupt based APF page-ready event delivery

2020-05-11 Thread Vitaly Kuznetsov
one. One notable difference between the two mechanisms is that interrupt may not get handled immediately so whenever we would like to deliver next event (regardless of its type) we must be sure the guest had read and cleared previous event in the slot. Signed-off-by: Vitaly Kuznetsov

[PATCH 8/8] KVM: x86: drop KVM_PV_REASON_PAGE_READY case from kvm_handle_page_fault()

2020-05-11 Thread Vitaly Kuznetsov
else this means that the underlying hypervisor is misbehaving. Leave WARN_ON_ONCE() to catch that. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/mmu/mmu.c | 10 +++--- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index

[PATCH 3/8] KVM: introduce kvm_read_guest_offset_cached()

2020-05-11 Thread Vitaly Kuznetsov
We already have kvm_write_guest_offset_cached(), introduce read analogue. Signed-off-by: Vitaly Kuznetsov --- include/linux/kvm_host.h | 3 +++ virt/kvm/kvm_main.c | 19 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/kvm_host.h b/include

[PATCH 0/8] KVM: x86: Interrupt-based mechanism for async_pf 'page present' notifications

2020-05-11 Thread Vitaly Kuznetsov
MSR_KVM_ASYNC_PF2 -> MSR_KVM_ASYNC_PF_INT [Peter Xu] - Drop 'enabled' field from MSR_KVM_ASYNC_PF_INT [Peter Xu] - Other minor changes supporting the above. Vitaly Kuznetsov (8): Revert "KVM: async_pf: Fix #DF due to inject "Page not Present" and "Page Ready" exce

[PATCH 1/8] Revert "KVM: async_pf: Fix #DF due to inject "Page not Present" and "Page Ready" exceptions simultaneously"

2020-05-11 Thread Vitaly Kuznetsov
y, we may erroneously drop two valid events. Revert the commit. Reviewed-by: Gavin Shan Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/x86.c | 23 +-- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c5835f9cb9ad.

[PATCH 2/8] KVM: x86: extend struct kvm_vcpu_pv_apf_data with token info

2020-05-11 Thread Vitaly Kuznetsov
notifications. The newly introduced apf_put_user_ready() temporary puts both reason and token information, this will be changed to put token only when we switch to interrupt based notifications. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/uapi/asm/kvm_para.h | 3 ++- arch/x86/kvm/x86.c

Re: [PATCH RFC 1/6] Revert "KVM: async_pf: Fix #DF due to inject "Page not Present" and "Page Ready" exceptions simultaneously"

2020-05-06 Thread Vitaly Kuznetsov
Vivek Goyal writes: > On Wed, Apr 29, 2020 at 11:36:29AM +0200, Vitaly Kuznetsov wrote: >> Commit 9a6e7c39810e (""KVM: async_pf: Fix #DF due to inject "Page not >> Present" and "Page Ready" exceptions simultaneously") added a protection >&g

Re: [PATCH RFC 4/6] KVM: x86: acknowledgment mechanism for async pf page ready notifications

2020-05-05 Thread Vitaly Kuznetsov
Gavin Shan writes: > Hi Vitaly, > > On 4/29/20 7:36 PM, Vitaly Kuznetsov wrote: >> If two page ready notifications happen back to back the second one is not >> delivered and the only mechanism we currently have is >> kvm_check_async_pf_completion() check in

Re: [PATCH RFC 2/6] KVM: x86: extend struct kvm_vcpu_pv_apf_data with token info

2020-05-05 Thread Vitaly Kuznetsov
Gavin Shan writes: > Hi Vitaly, > > On 4/29/20 7:36 PM, Vitaly Kuznetsov wrote: >> Currently, APF mechanism relies on the #PF abuse where the token is being >> passed through CR2. If we switch to using interrupts to deliver page-ready >> notifications we need a dif

Re: [PATCH RFC 3/6] KVM: x86: interrupt based APF page-ready event delivery

2020-04-30 Thread Vitaly Kuznetsov
Peter Xu writes: > On Thu, Apr 30, 2020 at 10:31:32AM +0200, Vitaly Kuznetsov wrote: >> as we need to write to two MSRs to configure the new mechanism ordering >> becomes important. If the guest writes to ASYNC_PF_EN first to establish >> the shared memory stucture the i

Re: [PATCH v4 2/7] KVM: X86: Enable fastpath when APICv is enabled

2020-04-30 Thread Vitaly Kuznetsov
Wanpeng Li writes: > From: Wanpeng Li > > We can't observe benefit from single target IPI fastpath when APICv is > disabled, let's just enable IPI and Timer fastpath when APICv is enabled > for now. > > Tested-by: Haiwei Li > Cc: Haiwei Li > Signed-off-by: Wanpeng Li > --- >

Re: [PATCH v4 1/7] KVM: VMX: Introduce generic fastpath handler

2020-04-30 Thread Vitaly Kuznetsov
read32(IDT_VECTORING_INFO_FIELD); > > vmx_recover_nmi_blocking(vmx); > vmx_complete_interrupts(vmx); > > + exit_fastpath = vmx_exit_handlers_fastpath(vcpu); > + > return exit_fastpath; > } Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH RFC 4/6] KVM: x86: acknowledgment mechanism for async pf page ready notifications

2020-04-30 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 30/04/20 10:40, Vitaly Kuznetsov wrote: >>> I think in that case >>> kvm_check_async_pf_completion will refuse to make progress. >>> You need to make this bit stateful (e.g. 1 = async PF in progress, 0 = >>> not in p

Re: [PATCH RFC 4/6] KVM: x86: acknowledgment mechanism for async pf page ready notifications

2020-04-30 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 29/04/20 11:36, Vitaly Kuznetsov wrote: >> +case MSR_KVM_ASYNC_PF_ACK: >> +if (data & 0x1) >> +kvm_check_async_pf_completion(vcpu); >> +break; > > Does this work if interrupts ar

Re: [PATCH RFC 3/6] KVM: x86: interrupt based APF page-ready event delivery

2020-04-30 Thread Vitaly Kuznetsov
Peter Xu writes: > Hi, Vitaly, > > On Wed, Apr 29, 2020 at 11:36:31AM +0200, Vitaly Kuznetsov wrote: >> +Type 1 page (page missing) events are currently always delivered as >> +synthetic #PF exception. Type 2 (page ready) are either delivered >> +b

Re: [PATCH RFC 6/6] KVM: x86: Switch KVM guest to using interrupts for page ready APF delivery

2020-04-29 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 29/04/20 14:44, Vitaly Kuznetsov wrote: >>>> + token = __this_cpu_read(apf_reason.token); >>>> + /* >>>> + * Make sure we read 'token' before we reset >>>>

Re: [PATCH v2] KVM: nVMX: Tweak handling of failure code for nested VM-Enter failure

2020-04-29 Thread Vitaly Kuznetsov
t_state() and > vmx_set_nested_state() to call out that they're ignored, set exit_reason > on demand on nested VM-Enter failure, and add a comment in > nested_vmx_load_msr() to call out that returning 'i + 1' can't wrap. > > No functional change intended. > > Reported-by: Vit

Re: [PATCH RFC 6/6] KVM: x86: Switch KVM guest to using interrupts for page ready APF delivery

2020-04-29 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 29/04/20 11:36, Vitaly Kuznetsov wrote: >> + >> +if (__this_cpu_read(apf_reason.enabled)) { >> +reason = __this_cpu_read(apf_reason.reason); >> +if (reason == KVM_PV_REASON_PAGE_READY) { >> +

Re: [PATCH RFC 3/6] KVM: x86: interrupt based APF page-ready event delivery

2020-04-29 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 29/04/20 11:36, Vitaly Kuznetsov wrote: >> + >> +Type 1 page (page missing) events are currently always delivered as >> +synthetic #PF exception. Type 2 (page ready) are either delivered >> +by #PF exception (when bit 3 of M

Re: [PATCH v4 4/7] KVM: PPC: clean up redundant 'kvm_run' parameters

2020-04-29 Thread Vitaly Kuznetsov
Tianjia Zhang writes: > In the current kvm version, 'kvm_run' has been included in the 'kvm_vcpu' > structure. For historical reasons, many kvm-related function parameters > retain the 'kvm_run' and 'kvm_vcpu' parameters at the same time. This > patch does a unified cleanup of these remaining

Re: [PATCH v4 3/7] KVM: PPC: Remove redundant kvm_run from vcpu_arch

2020-04-29 Thread Vitaly Kuznetsov
_hv_nested.c > +++ b/arch/powerpc/kvm/book3s_hv_nested.c > @@ -290,8 +290,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu) > r = RESUME_HOST; > break; > } > - r = kvmhv_run_single_vcpu(vcpu->arch.kvm_run, vcpu, hdec_exp, > - lpcr); > + r = kvmhv_run_single_vcpu(vcpu->run, vcpu, hdec_exp, lpcr); > } while (is_kvmppc_resume_guest(r)); > > /* save L2 state for return */ FWIW, Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v4 2/7] KVM: arm64: clean up redundant 'kvm_run' parameters

2020-04-29 Thread Vitaly Kuznetsov
kvm/arm/mmu.c > @@ -1892,7 +1892,6 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, > phys_addr_t fault_ipa) > /** > * kvm_handle_guest_abort - handles all 2nd stage aborts > * @vcpu:the VCPU pointer > - * @run: the kvm_run structure > * > * Any abort that gets to the host is almost guaranteed to be caused by a > * missing second stage translation table entry, which can mean that either > the > @@ -1901,7 +1900,7 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, > phys_addr_t fault_ipa) > * space. The distinction is based on the IPA causing the fault and whether > this > * memory region has been registered as standard RAM by user space. > */ > -int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) > { > unsigned long fault_status; > phys_addr_t fault_ipa; > @@ -1980,7 +1979,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, > struct kvm_run *run) >* of the page size. >*/ > fault_ipa |= kvm_vcpu_get_hfar(vcpu) & ((1 << 12) - 1); > - ret = io_mem_abort(vcpu, run, fault_ipa); > + ret = io_mem_abort(vcpu, fault_ipa); > goto out_unlock; > } Haven't tried to compile this but the change itself looks obviously correct, so Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v4 1/7] KVM: s390: clean up redundant 'kvm_run' parameters

2020-04-29 Thread Vitaly Kuznetsov
regs(vcpu, kvm_run); > + sync_regs(vcpu); > enable_cpu_timer_accounting(vcpu); > > might_fault(); > @@ -4393,7 +4400,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > } > > disable_cpu_timer_accounting(vcpu); > - store_regs(vcpu, kvm_run); > + store_regs(vcpu); > > kvm_sigset_deactivate(vcpu); Haven't tried to compile this but the change itself looks obviously correct, so Reviewed-by: Vitaly Kuznetsov -- Vitaly

[PATCH RFC 1/6] Revert "KVM: async_pf: Fix #DF due to inject "Page not Present" and "Page Ready" exceptions simultaneously"

2020-04-29 Thread Vitaly Kuznetsov
n theory, we may erroneously drop two valid events. Revert the commit. apf_get_user() stays as we will need it for the new 'page ready notifications via interrupt' mechanism. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/x86.c | 16 +--- 1 file changed, 1 insertion(+), 15 deletions(-)

[PATCH RFC 6/6] KVM: x86: Switch KVM guest to using interrupts for page ready APF delivery

2020-04-29 Thread Vitaly Kuznetsov
KVM now supports using interrupt for type 2 APF event delivery (page ready notifications). Switch KVM guests to using it when the feature is present. Signed-off-by: Vitaly Kuznetsov --- arch/x86/entry/entry_32.S | 5 arch/x86/entry/entry_64.S | 5 arch/x86/include

[PATCH RFC 0/6] KVM: x86: Interrupt-based mechanism for async_pf 'page present' notifications

2020-04-29 Thread Vitaly Kuznetsov
. This RFC does the later. Please let me know what you think about the idea in general and the selected approach in particular. Vitaly Kuznetsov (6): Revert "KVM: async_pf: Fix #DF due to inject "Page not Present" and "Page Ready" exceptions simultaneously&q

[PATCH RFC 2/6] KVM: x86: extend struct kvm_vcpu_pv_apf_data with token info

2020-04-29 Thread Vitaly Kuznetsov
-by: Vitaly Kuznetsov --- arch/x86/include/uapi/asm/kvm_para.h | 3 ++- arch/x86/kvm/x86.c | 10 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index 2a8e0b6b9805..df2ba34037a2 100644

[PATCH RFC 3/6] KVM: x86: interrupt based APF page-ready event delivery

2020-04-29 Thread Vitaly Kuznetsov
between the two mechanisms is that interrupt may not get handled immediately so whenever we would like to deliver next event (regardless of its type) we must be sure the guest had read and cleared previous event in the slot. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/msr.rst

[PATCH RFC 5/6] KVM: x86: announce KVM_FEATURE_ASYNC_PF_INT

2020-04-29 Thread Vitaly Kuznetsov
Introduce new capability to indicate that KVM supports interrupt based delivery of type 2 APF events (page ready notifications). This includes support for both MSR_KVM_ASYNC_PF2 and MSR_KVM_ASYNC_PF_ACK. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/cpuid.rst | 6 ++ arch

[PATCH RFC 4/6] KVM: x86: acknowledgment mechanism for async pf page ready notifications

2020-04-29 Thread Vitaly Kuznetsov
and host should check its notification queue. Mandate using it for interrupt based type 2 APF event delivery. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/msr.rst | 16 +++- arch/x86/include/uapi/asm/kvm_para.h | 1 + arch/x86/kvm/x86.c | 9

Re: [PATCH] kvm: x86: Cleanup vcpu->arch.guest_xstate_size

2020-04-29 Thread Vitaly Kuznetsov
.c > @@ -9358,8 +9358,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) > } > fx_init(vcpu); > > - vcpu->arch.guest_xstate_size = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET; > - > vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); > > vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT; Reviewed-by: Vitaly Kuznetsov -- Vitaly

[PATCH v2 2/3] x86/idt: Annotate alloc_intr_gate() with __init

2020-04-28 Thread Vitaly Kuznetsov
Signed-off-by: Vitaly Kuznetsov --- arch/x86/kernel/idt.c | 16 +--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c index 87ef69a72c52..f95c3be00e5a 100644 --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -51,6

[PATCH v2 0/3] x86/idt: Minor alloc_intr_gate() sanitization

2020-04-28 Thread Vitaly Kuznetsov
s' on bare metal). Thomas suggested to expand this cosmetic change to making alloc_intr_gate() __init. Vitaly Kuznetsov (3): x86/xen: Split HVM vector callback setup and interrupt gate allocation x86/idt: Annotate alloc_intr_gate() with __init x86/idt: Keep spurious entries unset in system_vect

[PATCH v2 1/3] x86/xen: Split HVM vector callback setup and interrupt gate allocation

2020-04-28 Thread Vitaly Kuznetsov
resume from xen_hvm_post_suspend(). alloc_intr_gate() only needs to be called once. Suggested-by: Thomas Gleixner Signed-off-by: Vitaly Kuznetsov --- arch/x86/xen/suspend_hvm.c | 2 +- arch/x86/xen/xen-ops.h | 2 +- drivers/xen/events/events_base.c | 28

[PATCH v2 3/3] x86/idt: Keep spurious entries unset in system_vectors

2020-04-28 Thread Vitaly Kuznetsov
lled after init, it is possible to leave unused entries in 'system_vectors' unset to fix the issues. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kernel/idt.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c index f9

Re: [PATCH v7 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks

2019-10-22 Thread Vitaly Kuznetsov
Zhenzhong Duan writes: > Hi Vitaly, > > On 2019/10/22 19:36, Vitaly Kuznetsov wrote: > >> Zhenzhong Duan writes: >> > ...snip > >>> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c >>> index 249f14a..3945aa5 100644 >>> --

Re: [PATCH v7 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks

2019-10-22 Thread Vitaly Kuznetsov
quot; to disable > PV spinlocks for KVM guest. > > The new 'nopvspin' parameter will also replace Xen and Hyper-V specific > parameters in future patches. > > Define variable nopvsin as global because it will be used in future > patches as above. > > Signed-off-by: Zhen

Re: [PATCH v6 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks

2019-10-21 Thread Vitaly Kuznetsov
ng Duan > Cc: Jonathan Corbet > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Paolo Bonzini > Cc: Radim Krcmar > Cc: Sean Christopherson > Cc: Vitaly Kuznetsov > Cc: Wanpeng Li > Cc: Jim Mattson > Cc

Re: [PATCH] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update

2019-10-17 Thread Vitaly Kuznetsov
linmiaohe writes: > Vitaly Kuznetsov writes: > >>> Guest physical APIC ID may not equal to vcpu->vcpu_id in some case. >>> We may set the wrong physical id in avic_handle_ldr_update as we >>> always use vcpu->vcpu_id. > > Hi, Vitaly, thanks for yo

Re: [PATCH] kvm: clear kvmclock MSR on reset

2019-10-16 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > After resetting the vCPU, the kvmclock MSR keeps the previous value but it is > not enabled. This can be confusing, so fix it. > > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 6 ++ > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git

Re: [PATCH] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update

2019-10-16 Thread Vitaly Kuznetsov
Miaohe Lin writes: > Guest physical APIC ID may not equal to vcpu->vcpu_id in some case. > We may set the wrong physical id in avic_handle_ldr_update as we > always use vcpu->vcpu_id. > > Signed-off-by: Miaohe Lin > --- > arch/x86/kvm/svm.c | 4 +++- > 1 file changed, 3 insertions(+), 1

Re: [PATCH] KVM: X86: Make fpu allocation a common function

2019-10-15 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 15/10/19 12:53, Vitaly Kuznetsov wrote: >> A very theoretical question: why do we have 'struct vcpu' embedded in >> vcpu_vmx/vcpu_svm and not the other way around (e.g. in a union)? That >> would've allowed us to allocate memory in comm

Re: [PATCH] KVM: X86: Make fpu allocation a common function

2019-10-15 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Oct 14, 2019 at 06:58:49PM +0200, Vitaly Kuznetsov wrote: >> Xiaoyao Li writes: >> >> > They are duplicated codes to create vcpu.arch.{user,guest}_fpu in VMX >> > and SVM. Make them common functions. >> > >&g

Re: [PATCH] KVM: X86: Make fpu allocation a common function

2019-10-14 Thread Vitaly Kuznetsov
Xiaoyao Li writes: > They are duplicated codes to create vcpu.arch.{user,guest}_fpu in VMX > and SVM. Make them common functions. > > No functional change intended. Would it rather make sense to move this code to kvm_arch_vcpu_create()/kvm_arch_vcpu_destroy() instead? > > Signed-off-by:

Re: [PATCH v5 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks

2019-10-14 Thread Vitaly Kuznetsov
Zhenzhong Duan writes: > On 2019/10/13 17:02, Vitaly Kuznetsov wrote: >> Zhenzhong Duan writes: > ...snip >> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c >> index ef836d6..6e14bd4 100644 >> --- a/arch/x86/kernel/kvm.c >> +++ b/arch/x8

Re: [PATCH v5 1/5] Revert "KVM: X86: Fix setup the virt_spin_lock_key before static key get initialized"

2019-10-13 Thread Vitaly Kuznetsov
the original simpler code > again. > > The similar change for XEN is in commit 090d54bcbc54 ("Revert > "x86/paravirt: Set up the virt_spin_lock_key after static keys get > initialized"") > > Signed-off-by: Zhenzhong Duan > Cc: Paolo Bonzini > Cc: Radim

Re: [PATCH v5 2/5] x86/kvm: Change print code to use pr_*() format

2019-10-13 Thread Vitaly Kuznetsov
r > Cc: Sean Christopherson > Cc: Vitaly Kuznetsov > Cc: Wanpeng Li > Cc: Jim Mattson > Cc: Joerg Roedel > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > --- > arch/x86/kernel/kvm.c | 30 -

Re: [PATCH v5 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks

2019-10-13 Thread Vitaly Kuznetsov
ng Duan > Cc: Jonathan Corbet > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Paolo Bonzini > Cc: Radim Krcmar > Cc: Sean Christopherson > Cc: Vitaly Kuznetsov > Cc: Wanpeng Li > Cc: Jim Mattson > Cc

Re: [RFC v2 2/2] x86/kvmclock: Introduce kvm-hostclock clocksource.

2019-10-10 Thread Vitaly Kuznetsov
Suleiman Souhlal writes: > When kvm-hostclock is selected, and the host supports it, update our > timekeeping parameters to be the same as the host. > This lets us have our time synchronized with the host's, > even in the presence of host NTP or suspend. > > Signed-off-by: Suleiman Souhlal >

Re: [RFC v2 1/2] kvm: Mechanism to copy host timekeeping parameters into guest.

2019-10-10 Thread Vitaly Kuznetsov
Suleiman Souhlal writes: > This is used to synchronize time between host and guest. > The guest can request the (guest) physical address it wants the > data in through the MSR_KVM_TIMEKEEPER_EN MSR. > > It currently assumes the host timekeeper is "tsc". > > Signed-off-by: Suleiman Souhlal > ---

Re: [PATCH v3] x86/hyperv: make vapic support x2apic mode

2019-10-09 Thread Vitaly Kuznetsov
+ if (!x2apic_enabled()) { > + apic->read = hv_apic_read; > + apic->write = hv_apic_write; > + apic->icr_write = hv_apic_icr_write; > + apic->icr_read = hv_apic_icr_read; > + } > } > } Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH] selftests: kvm: fix sync_regs_test with newer gccs

2019-10-09 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 09/10/19 12:42, Vitaly Kuznetsov wrote: >> Paolo Bonzini writes: >>> There is no practical difference with Vitaly's patch. The first >>> _vcpu_run has no pre-/post-conditions on the value of %rbx: >> >> I think what Sea

Re: [PATCH v2 6/8] KVM: x86: Fold 'enum kvm_ex_reg' definitions into 'enum kvm_reg'

2019-10-09 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 30/09/19 11:25, Vitaly Kuznetsov wrote: >>> -enum kvm_reg_ex { >>> VCPU_EXREG_PDPTR = NR_VCPU_REGS, >> (Personally, I would've changed that to NR_VCPU_REGS + 1) >> > > Why? > Just so every entry in the enum is dif

Re: [PATCH] selftests: kvm: fix sync_regs_test with newer gccs

2019-10-09 Thread Vitaly Kuznetsov
Paolo Bonzini writes: > On 08/10/19 20:36, Sean Christopherson wrote: >> On Tue, Oct 08, 2019 at 08:08:08PM +0200, Vitaly Kuznetsov wrote: >>> Commit 204c91eff798a ("KVM: selftests: do not blindly clobber registers in >>> guest asm") was intended to make tes

Re: [PATCH 0/2] Drivers: hv: vmbus: Miscellaneous improvements

2019-10-08 Thread Vitaly Kuznetsov
Andrea Parri writes: > On Mon, Oct 07, 2019 at 05:41:10PM +, Dexuan Cui wrote: >> > From: linux-hyperv-ow...@vger.kernel.org >> > On Behalf Of Andrea Parri >> > Sent: Monday, October 7, 2019 9:31 AM >> > >> > Hi all, >> > >> > The patchset: >> > >> > - simplifies/refactors the VMBus

[PATCH 3/3] selftests: kvm: vmx_dirty_log_test: skip the test when VMX is not supported

2019-10-08 Thread Vitaly Kuznetsov
vmx_dirty_log_test fails on AMD and this is no surprise as it is VMX specific. Bail early when nested VMX is unsupported. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm

[PATCH 2/3] selftests: kvm: consolidate VMX support checks

2019-10-08 Thread Vitaly Kuznetsov
vmx_* tests require VMX and three of them implement the same check. Move it to vmx library. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 ++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 10 ++ .../selftests/kvm/x86_64

[PATCH 0/3] selftests: kvm: improvements to VMX support check

2019-10-08 Thread Vitaly Kuznetsov
vmx_dirty_log_test fails on AMD and this is no surprise as it is VMX specific. Consolidate checks from other VMX tests into a library routine and add a check to skip the test when !VMX. Vitaly Kuznetsov (3): selftests: kvm: vmx_set_nested_state_test: don't check for VMX support twice

[PATCH 1/3] selftests: kvm: vmx_set_nested_state_test: don't check for VMX support twice

2019-10-08 Thread Vitaly Kuznetsov
vmx_set_nested_state_test() checks if VMX is supported twice: in the very beginning (and skips the whole test if it's not) and before doing test_vmx_nested_state(). One should be enough. Signed-off-by: Vitaly Kuznetsov --- .../selftests/kvm/x86_64/vmx_set_nested_state_test.c | 7

[PATCH] selftests: kvm: fix sync_regs_test with newer gccs

2019-10-08 Thread Vitaly Kuznetsov
is still free to play games with registers even when they have variables attaches. Re-write guest code with 'asm volatile' by embedding ucall there and making sure rbx is preserved. Fixes: 204c91eff798a ("KVM: selftests: do not blindly clobber registers in guest asm") Signed-o

RE: [PATCH 1/2] x86/hyperv: Allow guests to enable InvariantTSC

2019-10-08 Thread Vitaly Kuznetsov
Michael Kelley writes: > From: Vitaly Kuznetsov Sent: Friday, October 4, 2019 > 9:57 AM >> >> Andrea Parri writes: >> >> > If the hardware supports TSC scaling, Hyper-V will set bit 15 of the >> > HV_PARTITION_PRIVILEGE_MASK in guest VMs with a com

[PATCH RFC] selftests: kvm: fix sync_regs_test with newer gccs

2019-10-08 Thread Vitaly Kuznetsov
.rst" I can think of an 'ultimate' solution to open code ucall() in a single asm block making sure the register we need is preserved but this looks like an overkill. Fixes: 204c91eff798a ("KVM: selftests: do not blindly clobber registers in guest asm") Signed-off-by: Vitaly Kuznetsov

Re: [PATCH 1/2] Drivers: hv: vmbus: Introduce table of VMBus protocol versions

2019-10-08 Thread Vitaly Kuznetsov
Andrea Parri writes: >> > @@ -244,21 +234,18 @@ int vmbus_connect(void) >> > * version. >> > */ >> > >> > - version = VERSION_CURRENT; >> > + for (i = 0; ; i++) { >> > + version = vmbus_versions[i]; >> > + if (version == VERSION_INVAL) >> > + goto

Re: [PATCH 1/2] Drivers: hv: vmbus: Introduce table of VMBus protocol versions

2019-10-07 Thread Vitaly Kuznetsov
Andrea Parri writes: > The technique used to get the next VMBus version seems increasisly > clumsy as the number of VMBus versions increases. Performance is > not a concern since this is only done once during system boot; it's > just that we'll end up with more lines of code than is really

[PATCH] selftests: kvm: synchronize .gitignore to Makefile

2019-10-07 Thread Vitaly Kuznetsov
Because "Untracked files:" are annoying. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index b35da375530a..409c1fa75

Re: [PATCH 1/2] x86/hyperv: Allow guests to enable InvariantTSC

2019-10-04 Thread Vitaly Kuznetsov
Andrea Parri writes: > If the hardware supports TSC scaling, Hyper-V will set bit 15 of the > HV_PARTITION_PRIVILEGE_MASK in guest VMs with a compatible Hyper-V > configuration version. Bit 15 corresponds to the > AccessTscInvariantControls privilege. If this privilege bit is set, > guests can

Re: [PATCH v2] x86/hyperv: make vapic support x2apic mode

2019-10-03 Thread Vitaly Kuznetsov
Roman Kagan writes: > Now that there's Hyper-V IOMMU driver, Linux can switch to x2apic mode > when supported by the vcpus. > > However, the apic access functions for Hyper-V enlightened apic assume > xapic mode only. > > As a result, Linux fails to bring up secondary cpus when run as a guest >

Re: [PATCH 1/3] KVM: X86: Add "nopvspin" parameter to disable PV spinlocks

2019-10-01 Thread Vitaly Kuznetsov
Zhenzhong Duan writes: > On 2019/9/30 23:41, Vitaly Kuznetsov wrote: >> Zhenzhong Duan writes: >> >>> There are cases where a guest tries to switch spinlocks to bare metal >>> behavior (e.g. by setting "xen_nopvspin" on XEN platform and >>

Re: [PATCH v2 4/8] KVM: VMX: Optimize vmx_set_rflags() for unrestricted guest

2019-09-30 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Sep 30, 2019 at 10:57:17AM +0200, Vitaly Kuznetsov wrote: >> Sean Christopherson writes: >> >> > Rework vmx_set_rflags() to avoid the extra code need to handle emulation >> > of real mode and invalid state wh

Re: [PATCH 1/3] KVM: X86: Add "nopvspin" parameter to disable PV spinlocks

2019-09-30 Thread Vitaly Kuznetsov
Corbet > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Paolo Bonzini > Cc: Radim Krcmar > Cc: Sean Christopherson > Cc: Vitaly Kuznetsov > Cc: Wanpeng Li > Cc: Jim Mattson > Cc: Joerg Roedel

Re: [PATCH v2 8/8] KVM: x86: Fold decache_cr3() into cache_reg()

2019-09-30 Thread Vitaly Kuznetsov
Sean Christopherson writes: > On Mon, Sep 30, 2019 at 12:58:53PM +0200, Vitaly Kuznetsov wrote: >> Sean Christopherson writes: >> >> > Handle caching CR3 (from VMX's VMCS) into struct kvm_vcpu via the common >> > cache_reg() callback and drop the d

Re: [PATCH v2 8/8] KVM: x86: Fold decache_cr3() into cache_reg()

2019-09-30 Thread Vitaly Kuznetsov
/* From paging/starting to nonpaging */ > exec_controls_setbit(vmx, CPU_BASED_CR3_LOAD_EXITING | > @@ -7792,7 +7790,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = > { > .get_cpl = vmx_get_cpl, > .get_cs_db_l_bits = vmx_get_cs_db_l_bits, > .decache_cr0_guest_bits = vmx_decache_cr0_guest_bits, > - .decache_cr3 = vmx_decache_cr3, > .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits, > .set_cr0 = vmx_set_cr0, > .set_cr3 = vmx_set_cr3, Reviewed (and Tested-On-Amd-By:): Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 7/8] KVM: x86: Add helpers to test/mark reg availability and dirtiness

2019-09-30 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Add helpers to prettify code that tests and/or marks whether or not a > register is available and/or dirty. > > Suggested-by: Vitaly Kuznetsov > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/

Re: [PATCH v2 6/8] KVM: x86: Fold 'enum kvm_ex_reg' definitions into 'enum kvm_reg'

2019-09-30 Thread Vitaly Kuznetsov
XREG_PDPTR, > (unsigned long *)>arch.regs_avail)) > - kvm_x86_ops->cache_reg(vcpu, (enum kvm_reg)VCPU_EXREG_PDPTR); > + kvm_x86_ops->cache_reg(vcpu, VCPU_EXREG_PDPTR); > > return vcpu->arch.walk_mmu->pdptrs[index]; > } Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 5/8] KVM: x86: Add WARNs to detect out-of-bounds register indices

2019-09-30 Thread Vitaly Kuznetsov
_register_readl(struct kvm_vcpu *vcpu, > -enum kvm_reg reg) > +static inline unsigned long kvm_register_readl(struct kvm_vcpu *vcpu, int > reg) > { > unsigned long val = kvm_register_read(vcpu, reg); > > @@ -247,8 +246,7 @@ st

Re: [PATCH v2 4/8] KVM: VMX: Optimize vmx_set_rflags() for unrestricted guest

2019-09-30 Thread Vitaly Kuznetsov
flags); We're doing vmcs_writel() in both branches so it could've stayed here, right? > - > - if ((old_rflags ^ vmx->rflags) & X86_EFLAGS_VM) > - vmx->emulation_required = emulation_required(vcpu); > } > > u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu) Reviewed-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH v2 3/8] KVM: VMX: Consolidate to_vmx() usage in RFLAGS accessors

2019-09-30 Thread Vitaly Kuznetsov
p; X86_EFLAGS_VM) > - to_vmx(vcpu)->emulation_required = emulation_required(vcpu); > + if ((old_rflags ^ vmx->rflags) & X86_EFLAGS_VM) > + vmx->emulation_required = emulation_required(vcpu); > } > > u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu) Reviewed-by: Vitaly Kuznetsov -- Vitaly

[PATCH] KVM: selftests: x86: clarify what is reported on KVM_GET_MSRS failure

2019-09-27 Thread Vitaly Kuznetsov
Christopherson Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index c53dbc6bc568..6698cb741e10

Re: [PATCH 0/2] KVM: nVMX: Bug fix for consuming stale vmcs02.GUEST_CR3

2019-09-27 Thread Vitaly Kuznetsov
s of GUEST_CR3 ownership in VMX is a nightmare, so fixing this > purely within the context of nested VMX turned out to be the cleanest fix. > > Sean Christopherson (2): > KVM: nVMX: Always write vmcs02.GUEST_CR3 during nested VM-Enter > KVM: VMX: Skip GUEST_CR3 VMREAD+VMWRITE if the VMCS is up-to-date > Series: Tested-by: Vitaly Kuznetsov -- Vitaly

Re: [PATCH 2/2] KVM: VMX: Skip GUEST_CR3 VMREAD+VMWRITE if the VMCS is up-to-date

2019-09-27 Thread Vitaly Kuznetsov
Sean Christopherson writes: > Skip the VMWRITE to update GUEST_CR3 if CR3 is not available, i.e. has > not been read from the VMCS since the last VM-Enter. If vcpu->arch.cr3 > is stale, kvm_read_cr3(vcpu) will refresh vcpu->arch.cr3 from the VMCS, > meaning KVM will do a VMREAD and then VMWRITE

RE: [PATCH v5 1/3] x86/hyper-v: Suspend/resume the hypercall page for hibernation

2019-09-27 Thread Vitaly Kuznetsov
Dexuan Cui writes: >> From: Vitaly Kuznetsov >> Sent: Thursday, September 26, 2019 3:44 AM >> > [...] >> > +static int hv_suspend(void) >> > +{ >> > + union hv_x64_msr_hypercall_contents hypercall_msr; >> > + >> > +

Re: [PATCH v5 1/3] x86/hyper-v: Suspend/resume the hypercall page for hibernation

2019-09-26 Thread Vitaly Kuznetsov
Dexuan Cui writes: > This is needed for hibernation, e.g. when we resume the old kernel, we need > to disable the "current" kernel's hypercall page and then resume the old > kernel's. > > Signed-off-by: Dexuan Cui > Reviewed-by: Michael Kelley > --- > arch/x86/hyperv/hv_init.c | 33

[PATCH v2] KVM: vmx: fix build warnings in hv_enable_direct_tlbflush() on i386

2019-09-25 Thread Vitaly Kuznetsov
. evmcs->hv_vm_id can use 'unsigned long' instead of 'u64'. Also, simplify the code a little bit. Reported-by: kbuild test robot Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 14 +- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.

RE: [PATCH] KVM: vmx: fix a build warning in hv_enable_direct_tlbflush() on i386

2019-09-25 Thread Vitaly Kuznetsov
Tianyu Lan writes: > There is another warning in the report. > > arch/x86/kvm/vmx/vmx.c: In function 'hv_enable_direct_tlbflush': > arch/x86/kvm/vmx/vmx.c:507:20: warning: cast from pointer to integer of > different size [-Wpointer-to-int-cast] > evmcs->hv_vm_id = (u64)vcpu->kvm; >

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