[PATCH] KVM: nSVM: call nested_svm_load_cr3 on nested state load

2021-02-10 Thread Maxim Levitsky
ell. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 8 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 519fe84f2100..c209f1232928 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x8

[PATCH 0/4] RFC/WIP: KVM: separate injected and pending exception + few more fixes

2021-02-25 Thread Maxim Levitsky
clone of "kernel-starship-5.11" Maxim Levitsky (4): KVM: x86: determine if an exception has an error code only when injecting it. KVM: x86: mmu: initialize fault.async_page_fault in walk_addr_generic KVM: x86: pending exception must be be injected even with an injected e

[PATCH 1/4] KVM: x86: determine if an exception has an error code only when injecting it.

2021-02-25 Thread Maxim Levitsky
A page fault can be queued while vCPU is in real paged mode on AMD, and AMD manual asks the user to always intercept it (otherwise result is undefined). The resulting VM exit, does have an error code. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 13 + 1 file changed, 9

[PATCH 2/4] KVM: x86: mmu: initialize fault.async_page_fault in walk_addr_generic

2021-02-25 Thread Maxim Levitsky
This field was left uninitialized by a mistake. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/mmu/paging_tmpl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index d9f66cc459e84..3dc9a25772bd8 100644 --- a/arch/x86/kvm/mmu

[PATCH 3/4] KVM: x86: pending exception must be be injected even with an injected event

2021-02-25 Thread Maxim Levitsky
Injected events should not block a pending exception, but rather, should either be lost or be delivered to the nested hypervisor as part of exitintinfo/IDT_VECTORING_INFO (if nested hypervisor intercepts the pending exception) Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 7

[PATCH 4/4] kvm: WIP separation of injected and pending exception

2021-02-25 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 23 +- arch/x86/include/uapi/asm/kvm.h | 14 +- arch/x86/kvm/svm/nested.c | 62 +++--- arch/x86/kvm/svm/svm.c | 8 +- arch/x86/kvm/vmx/nested.c | 114 +- arch/x86/kvm/vmx/vmx.c | 14

Re: [PATCH 0/4] RFC/WIP: KVM: separate injected and pending exception + few more fixes

2021-02-25 Thread Maxim Levitsky
On Thu, 2021-02-25 at 17:41 +0200, Maxim Levitsky wrote: > clone of "kernel-starship-5.11" > > Maxim Levitsky (4): > KVM: x86: determine if an exception has an error code only when > injecting it. > KVM: x86: mmu: initialize fault.async_page_fault in wa

Re: [PATCH 3/4] KVM: x86: pending exception must be be injected even with an injected event

2021-02-25 Thread Maxim Levitsky
On Thu, 2021-02-25 at 17:05 +0100, Paolo Bonzini wrote: > On 25/02/21 16:41, Maxim Levitsky wrote: > > Injected events should not block a pending exception, but rather, > > should either be lost or be delivered to the nested hypervisor as part of > > exitintinfo/IDT_VECTORIN

Re: [PATCH 3/3] KVM: SVM: allow to intercept all exceptions for debug

2021-03-18 Thread Maxim Levitsky
On Thu, 2021-03-18 at 16:35 +, Sean Christopherson wrote: > On Thu, Mar 18, 2021, Joerg Roedel wrote: > > On Thu, Mar 18, 2021 at 11:24:25AM +0200, Maxim Levitsky wrote: > > > But again this is a debug feature, and it is intended to allow the user > > > t

[PATCH 2/2] KVM: nSVM: improve SYSENTER emulation on AMD

2021-03-15 Thread Maxim Levitsky
s nested migration of 32 bit nested guests which was broken due to incorrect cached values of these msrs being read if L1 changed these msrs with vmload prior to L2 entry. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 97 -- arch/x86/kvm/svm/sv

[PATCH 1/2] KVM: x86: add guest_cpuid_is_intel

2021-03-15 Thread Maxim Levitsky
This is similar to existing 'guest_cpuid_is_amd_or_hygon' Signed-off-by: Maxim Levitsky --- arch/x86/kvm/cpuid.h | 8 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 2a0c5064497f3..ded84d244f19f 100644 --- a/arch/x86/kvm/cpu

[PATCH 0/2] KVM: x86: nSVM: fixes for SYSENTER emulation

2021-03-15 Thread Maxim Levitsky
ual vmload/save is force disabled. Best regards, Maxim Levitsky Maxim Levitsky (2): KVM: x86: add guest_cpuid_is_intel KVM: nSVM: improve SYSENTER emulation on AMD arch/x86/kvm/cpuid.h | 8 arch/x86/kvm/svm/svm.c | 97 -- arch/x86/kvm

Re: [PATCH 2/2] KVM: nSVM: improve SYSENTER emulation on AMD

2021-03-15 Thread Maxim Levitsky
On Mon, 2021-03-15 at 18:56 +0100, Paolo Bonzini wrote: > On 15/03/21 18:43, Maxim Levitsky wrote: > > + if (!guest_cpuid_is_intel(vcpu)) { > > + /* > > +* If hardware supports Virtual VMLOAD VMSAVE then enable it > > +* in VMCB an

[PATCH 0/3] KVM: my debug patch queue

2021-03-15 Thread Maxim Levitsky
feature on Intel as well. Best regards, Maxim Levitsky Maxim Levitsky (3): scripts/gdb: rework lx-symbols gdb script KVM: x86: guest debug: don't inject interrupts while single stepping KVM: SVM: allow to intercept all exceptions for debug arch/x86/include/asm/kvm_host.h | 2 +

[PATCH 1/3] scripts/gdb: rework lx-symbols gdb script

2021-03-15 Thread Maxim Levitsky
st kernel panic as soon as it skips over the 'int3' instruction and executes the garbage tail of the optcode on which the breakpoint was placed. Signed-off-by: Maxim Levitsky --- kernel/module.c | 8 ++- scripts/gdb/linux/symbols.py | 106 +

[PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-15 Thread Maxim Levitsky
ge is only active when guest is debugged, it won't affect KVM running normal 'production' VMs. Signed-off-by: Maxim Levitsky Tested-by: Stefano Garzarella --- arch/x86/kvm/x86.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/

[PATCH 3/3] KVM: SVM: allow to intercept all exceptions for debug

2021-03-15 Thread Maxim Levitsky
s is based on an idea first shown here: https://patchwork.kernel.org/project/kvm/patch/20160301192822.gd22...@pd.tnic/ CC: Borislav Petkov Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/svm.c | 77 - arch/x86/kvm

Re: [PATCH 2/2] KVM: nSVM: improve SYSENTER emulation on AMD

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 09:16 +0100, Paolo Bonzini wrote: > On 15/03/21 19:19, Maxim Levitsky wrote: > > On Mon, 2021-03-15 at 18:56 +0100, Paolo Bonzini wrote: > > > On 15/03/21 18:43, Maxim Levitsky wrote: > > > > +

Re: [PATCH 3/3] KVM: SVM: allow to intercept all exceptions for debug

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 09:32 +0100, Joerg Roedel wrote: > Hi Maxim, > > On Tue, Mar 16, 2021 at 12:10:20AM +0200, Maxim Levitsky wrote: > > -static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { > > +static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { &

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Maxim Levitsky
On Mon, 2021-03-15 at 16:37 -0700, Sean Christopherson wrote: > On Tue, Mar 16, 2021, Maxim Levitsky wrote: > > This change greatly helps with two issues: > > > > * Resuming from a breakpoint is much more reliable. > > > > When resuming execution from a br

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 10:16 +0100, Jan Kiszka wrote: > On 16.03.21 00:37, Sean Christopherson wrote: > > On Tue, Mar 16, 2021, Maxim Levitsky wrote: > > > This change greatly helps with two issues: > > > > > > * Resuming from a breakpoint is much more re

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 12:27 +0100, Jan Kiszka wrote: > On 16.03.21 11:59, Maxim Levitsky wrote: > > On Tue, 2021-03-16 at 10:16 +0100, Jan Kiszka wrote: > > > On 16.03.21 00:37, Sean Christopherson wrote: > > > > On Tue, Mar 16, 2021, Maxim Levitsky wrote: > >

Re: [PATCH 1/3] scripts/gdb: rework lx-symbols gdb script

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 14:38 +0100, Jan Kiszka wrote: > On 15.03.21 23:10, Maxim Levitsky wrote: > > Fix several issues that are present in lx-symbols script: > > > > * Track module unloads by placing another software breakpoint at > > 'free_module' > >

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 14:46 +0100, Jan Kiszka wrote: > On 16.03.21 13:34, Maxim Levitsky wrote: > > On Tue, 2021-03-16 at 12:27 +0100, Jan Kiszka wrote: > > > On 16.03.21 11:59, Maxim Levitsky wrote: > > > > On Tue, 2021-03-16 at 10:16 +0100, Jan Kiszka wrote: >

Re: [PATCH 2/3] KVM: x86: guest debug: don't inject interrupts while single stepping

2021-03-16 Thread Maxim Levitsky
On Tue, 2021-03-16 at 18:01 +0100, Jan Kiszka wrote: > On 16.03.21 17:50, Sean Christopherson wrote: > > On Tue, Mar 16, 2021, Maxim Levitsky wrote: > > > On Tue, 2021-03-16 at 16:31 +0100, Jan Kiszka wrote: > > > > Back then, when I was hacking on the gdb-stub and KV

Re: [PATCH 3/3] KVM: SVM: allow to intercept all exceptions for debug

2021-03-18 Thread Maxim Levitsky
On Thu, 2021-03-18 at 10:19 +0100, Joerg Roedel wrote: > On Tue, Mar 16, 2021 at 12:51:20PM +0200, Maxim Levitsky wrote: > > I agree but what is wrong with that? > > This is a debug feature, and it only can be enabled by the root, > > and so someone might actually wan

[PATCH 3/8] KVM: SVM: refactor msr permission bitmap allocation

2020-08-20 Thread Maxim Levitsky
Replace svm_vcpu_init_msrpm with svm_vcpu_alloc_msrpm, that also allocates the msr bitmap and add svm_vcpu_free_msrpm to free it. This will be used later to move the nested msr permission bitmap allocation to nested.c No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86

[PATCH 0/8] KVM: nSVM: ondemand nested state allocation + nested guest state caching

2020-08-20 Thread Maxim Levitsky
this currently. Best regards, Maxim Levitsky Maxim Levitsky (8): KVM: SVM: rename a variable in the svm_create_vcpu KVM: nSVM: rename nested 'vmcb' to vmcb_gpa in few places KVM: SVM: refactor msr permission bitmap allocation KVM: x86: allow kvm_x86_ops.set_efer to r

[PATCH 1/8] KVM: SVM: rename a variable in the svm_create_vcpu

2020-08-20 Thread Maxim Levitsky
The 'page' is to hold the vcpu's vmcb so name it as such to avoid confusion. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 03dd7bac803

[PATCH 4/8] KVM: x86: allow kvm_x86_ops.set_efer to return a value

2020-08-20 Thread Maxim Levitsky
This will be used later to return an error when setting this msr fails. For VMX, it already has an error condition when EFER is not in the shared MSR list, so return an error in this case. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c

[PATCH 5/8] KVM: nSVM: implement ondemand allocation of the nested state

2020-08-20 Thread Maxim Levitsky
This way we don't waste memory on VMs which don't enable nesting virtualization Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 43 +++ arch/x86/kvm/svm/svm.c| 62 +++ arch/x86/kvm/svm/svm.h| 6 +++

[PATCH 6/8] SVM: nSVM: cache whole nested vmcb instead of only its control area

2020-08-20 Thread Maxim Levitsky
No functional change intended other that slightly higher memory usage, since this patch doesn't touch the data area of the cached vmcb. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 96 +++ arch/x86/kvm/svm/svm.c| 10 ++-- arch/x86/kvm/sv

[PATCH 7/8] KVM: nSVM: implement caching of nested vmcb save area

2020-08-20 Thread Maxim Levitsky
c the updated save state area of the guest, to the cache, although this is probably overkill. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 131 ++ arch/x86/kvm/svm/svm.c| 6 +- arch/x86/kvm/svm/svm.h| 4 +- 3 files changed, 97 inser

[PATCH 8/8] KVM: nSVM: read only changed fields of the nested guest data area

2020-08-20 Thread Maxim Levitsky
This allows us to only read fields that are marked as dirty by the nested guest on vmentry. I doubt that this has any perf impact but this way it is a bit closer to real hardware. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 58 +-- arch/x86

[PATCH 2/8] KVM: nSVM: rename nested 'vmcb' to vmcb_gpa in few places

2020-08-20 Thread Maxim Levitsky
No functional changes. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 10 +- arch/x86/kvm/svm/svm.c| 13 +++-- arch/x86/kvm/svm/svm.h| 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm

Re: [PATCH 2/8] KVM: nSVM: rename nested 'vmcb' to vmcb_gpa in few places

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 12:19 +0200, Paolo Bonzini wrote: > On 20/08/20 12:00, Maxim Levitsky wrote: > > > Please use vmcb12_gpa, and svm->nested.vmcb12 for the VMCB in patch 6. > > > > > > (You probably also what to have local variables named vmcb12 in patc

Re: [PATCH 8/8] KVM: nSVM: read only changed fields of the nested guest data area

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 12:18 +0200, Paolo Bonzini wrote: > On 20/08/20 12:05, Maxim Levitsky wrote: > > > You probably should set clean to 0 also if the guest doesn't have the > > > VMCBCLEAN feature (so, you first need an extra patch to add the > > > VMCBCLE

Re: [PATCH 8/8] KVM: nSVM: read only changed fields of the nested guest data area

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 12:01 +0200, Paolo Bonzini wrote: > On 20/08/20 11:13, Maxim Levitsky wrote: > > + u32 clean = nested_vmcb->control.clean; > > + > > + if (svm->nested.vmcb_gpa != vmcb_gpa) { > > + svm->nested.vmcb_gpa = vmcb_gpa; > >

Re: [PATCH 2/8] KVM: nSVM: rename nested 'vmcb' to vmcb_gpa in few places

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 12:56 +0200, Paolo Bonzini wrote: > On 20/08/20 12:23, Maxim Levitsky wrote: > > I fully agree that adding local variable is a good idea anyway. > > > > I was just noting that svm->nested.vmcb is already about the nested > > (e.g vmcb12) thus I

Re: [PATCH 2/8] KVM: nSVM: rename nested 'vmcb' to vmcb_gpa in few places

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 11:56 +0200, Paolo Bonzini wrote: > On 20/08/20 11:13, Maxim Levitsky wrote: > > No functional changes. > > > > Signed-off-by: Maxim Levitsky > > --- > > arch/x86/kvm/svm/nested.c | 10 +- > > arch/x86/kvm/svm/svm.c| 13 ++

Re: [PATCH 5/8] KVM: nSVM: implement ondemand allocation of the nested state

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 11:58 +0200, Paolo Bonzini wrote: > On 20/08/20 11:13, Maxim Levitsky wrote: > > @@ -3912,6 +3914,14 @@ static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, > > const char *smstate) > > vmcb_gpa = GET_SMSTATE(u64, smstate, 0x7ee0); &g

Re: [PATCH 8/8] KVM: nSVM: read only changed fields of the nested guest data area

2020-08-20 Thread Maxim Levitsky
On Thu, 2020-08-20 at 11:55 +0200, Paolo Bonzini wrote: > On 20/08/20 11:13, Maxim Levitsky wrote: > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > index 06668e0f93e7..f0bb7f622dca 100644 > > --- a/arch/x86/kvm/svm/svm.c > > +++ b/arch/x86/kvm/svm/s

[PATCH v2 0/7] KVM: nSVM: ondemand nested state allocation + smm fixes

2020-08-20 Thread Maxim Levitsky
ts, in one case even with L3 running, but note that due to unrelated issue, migration with nested guest running didn't work for me with or without this series. I am investigating this currently. Best regards, Maxim Levitsky Maxim Levitsky (7): KVM: SVM: rename a variable in the svm_c

[PATCH v2 7/7] KVM: nSVM: implement ondemand allocation of the nested state

2020-08-20 Thread Maxim Levitsky
This way we don't waste memory on VMs which don't enable nesting virtualization Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 43 ++ arch/x86/kvm/svm/svm.c| 56 +-- arch/x86/kvm/svm/svm.h| 6

[PATCH v2 2/7] KVM: nSVM: rename nested 'vmcb' to vmcb12_gpa in few places

2020-08-20 Thread Maxim Levitsky
No functional changes. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 10 +- arch/x86/kvm/svm/svm.c| 13 +++-- arch/x86/kvm/svm/svm.h| 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm

[PATCH v2 6/7] KVM: emulator: more strict rsm checks.

2020-08-20 Thread Maxim Levitsky
s are probably redundant, since the code sets them to fixed value, but it won't hurt to have them Signed-off-by: Maxim Levitsky --- arch/x86/kvm/emulate.c | 22 +- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emula

[PATCH v2 5/7] KVM: nSVM: more strict smm checks

2020-08-20 Thread Maxim Levitsky
indicate emulation failure which should triple fault the guest. * Check that that guest CPUID supports SVM (due to the same issue as above) Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 29 ++--- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git

[PATCH v2 1/7] KVM: SVM: rename a variable in the svm_create_vcpu

2020-08-20 Thread Maxim Levitsky
The 'page' is to hold the vcpu's vmcb so name it as such to avoid confusion. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 03dd7bac803

[PATCH v2 4/7] KVM: x86: allow kvm_x86_ops.set_efer to return a value

2020-08-20 Thread Maxim Levitsky
This will be used later to return an error when setting this msr fails. For VMX, it already has an error condition when EFER is not in the shared MSR list, so return an error in this case. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c

[PATCH v2 3/7] KVM: SVM: refactor msr permission bitmap allocation

2020-08-20 Thread Maxim Levitsky
Replace svm_vcpu_init_msrpm with svm_vcpu_alloc_msrpm, that also allocates the msr bitmap and add svm_vcpu_free_msrpm to free it. This will be used later to move the nested msr permission bitmap allocation to nested.c No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86

Re: [PATCH v2 4/7] KVM: x86: allow kvm_x86_ops.set_efer to return a value

2020-08-27 Thread Maxim Levitsky
On Thu, 2020-08-20 at 17:43 -0700, Sean Christopherson wrote: > On Thu, Aug 20, 2020 at 02:43:56PM -0700, Jim Mattson wrote: > > On Thu, Aug 20, 2020 at 6:34 AM Maxim Levitsky wrote: > > > This will be used later to return an error when setting this msr fails. > > > &g

[PATCH 0/3] Few nSVM bugfixes

2020-08-27 Thread Maxim Levitsky
never setup nesed msr bitmap on nested state load after migration. Patch #3 was 'migrated' ;-) from my other patch series to make it smaller, which is about more strict checks when we about to return to a nested guest, from SMM. Best regards, Maxim Levitsky Maxim Levitsky (3):

[PATCH 3/3] KVM: nSVM: more strict SMM checks when returning to nested guest

2020-08-27 Thread Maxim Levitsky
area, and so indicate emulation failure which should triple fault the guest. * Check that that guest CPUID supports SVM (due to the same issue as above) Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 29 ++--- 1 file changed, 18 insertions(+), 11 deletions

[PATCH 1/3] SVM: nSVM: correctly restore GIF on vmexit from nesting after migration

2020-08-27 Thread Maxim Levitsky
the vmcb). Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index fb68467e60496..95fdf068fe4c1 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/

[PATCH 2/3] SVM: nSVM: setup nested msr permission bitmap on nested state load

2020-08-27 Thread Maxim Levitsky
This code was missing and was forcing the L2 run with L1's msr permission bitmap Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 95fdf068fe4c1..e90bc436f5849 1

[PATCH 0/8] KVM: nSVM: ondemand nested state allocation + smm fixes

2020-08-27 Thread Maxim Levitsky
ested. Best regards, Maxim Levitsky Maxim Levitsky (8): KVM: SVM: rename a variable in the svm_create_vcpu KVM: nSVM: rename nested vmcb to vmcb12 KVM: SVM: refactor msr permission bitmap allocation KVM: SVM: use __GFP_ZERO instead of clear_page KVM: SVM: refactor exit labels in svm_cr

[PATCH 4/8] KVM: SVM: use __GFP_ZERO instead of clear_page

2020-08-27 Thread Maxim Levitsky
Another small refactoring. Suggested-by: Jim Mattson Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ddbb05614af4f..290b2d0cd78e3 100644 --- a/arch/x86/kvm

[PATCH 1/8] KVM: SVM: rename a variable in the svm_create_vcpu

2020-08-27 Thread Maxim Levitsky
The 'page' is to hold the vcpu's vmcb so name it as such to avoid confusion. Signed-off-by: Maxim Levitsky Reviewed-by: Jim Mattson --- arch/x86/kvm/svm/svm.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/

[PATCH 2/8] KVM: nSVM: rename nested vmcb to vmcb12

2020-08-27 Thread Maxim Levitsky
This is to be more consistient with VMX, and to support upcoming addition of vmcb02 Hopefully no functional changes. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 225 +++--- arch/x86/kvm/svm/svm.c| 10 +- arch/x86/kvm/svm/svm.h| 2

[PATCH 3/8] KVM: SVM: refactor msr permission bitmap allocation

2020-08-27 Thread Maxim Levitsky
Replace svm_vcpu_init_msrpm with svm_vcpu_alloc_msrpm, that also allocates the msr bitmap and add svm_vcpu_free_msrpm to free it. This will be used later to move the nested msr permission bitmap allocation to nested.c Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 45

[PATCH 8/8] KVM: nSVM: implement ondemand allocation of the nested state

2020-08-27 Thread Maxim Levitsky
This way we don't waste memory on VMs which don't use nesting virtualization even if it is available to them. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 42 +++ arch/x86/kvm/svm/svm.c| 52 +-- ar

[PATCH 5/8] KVM: SVM: refactor exit labels in svm_create_vcpu

2020-08-27 Thread Maxim Levitsky
Kernel coding style suggests not to use labels like error1,error2 Suggested-by: Jim Mattson Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index

[PATCH 7/8] KVM: emulator: more strict rsm checks.

2020-08-27 Thread Maxim Levitsky
s are probably redundant, since the code sets them to fixed value, but it won't hurt to have them Signed-off-by: Maxim Levitsky --- arch/x86/kvm/emulate.c | 22 +- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emula

[PATCH 6/8] KVM: x86: allow kvm_x86_ops.set_efer to return a value

2020-08-27 Thread Maxim Levitsky
This will be used later to return an error when setting this msr fails. Note that we ignore this return value for qemu initiated writes to avoid breaking backward compatibility. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c | 3

[PATCH v3 0/8] KVM: nSVM: ondemand nested state allocation + smm fixes

2020-08-27 Thread Maxim Levitsky
ested. Best regards, Maxim Levitsky Maxim Levitsky (8): KVM: SVM: rename a variable in the svm_create_vcpu KVM: nSVM: rename nested vmcb to vmcb12 KVM: SVM: refactor msr permission bitmap allocation KVM: SVM: use __GFP_ZERO instead of clear_page KVM: SVM: refactor exit labels in svm_cr

[PATCH v3 2/8] KVM: nSVM: rename nested vmcb to vmcb12

2020-08-27 Thread Maxim Levitsky
This is to be more consistient with VMX, and to support upcoming addition of vmcb02 Hopefully no functional changes. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 225 +++--- arch/x86/kvm/svm/svm.c| 10 +- arch/x86/kvm/svm/svm.h| 2

[PATCH v3 1/8] KVM: SVM: rename a variable in the svm_create_vcpu

2020-08-27 Thread Maxim Levitsky
The 'page' is to hold the vcpu's vmcb so name it as such to avoid confusion. Signed-off-by: Maxim Levitsky Reviewed-by: Jim Mattson --- arch/x86/kvm/svm/svm.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/

Re: [PATCH 0/8] KVM: nSVM: ondemand nested state allocation + smm fixes

2020-08-27 Thread Maxim Levitsky
On Thu, 2020-08-27 at 20:04 +0300, Maxim Levitsky wrote: > This patch series does some refactoring and implements on demand nested state > area > This way at least guests that don't use nesting won't waste memory > on nested state. > > This patch series is based on p

[PATCH v3 4/8] KVM: SVM: use __GFP_ZERO instead of clear_page

2020-08-27 Thread Maxim Levitsky
Another small refactoring. Suggested-by: Jim Mattson Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ddbb05614af4f..290b2d0cd78e3 100644 --- a/arch/x86/kvm

[PATCH v3 5/8] KVM: SVM: refactor exit labels in svm_create_vcpu

2020-08-27 Thread Maxim Levitsky
Kernel coding style suggests not to use labels like error1,error2 Suggested-by: Jim Mattson Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index

[PATCH v3 3/8] KVM: SVM: refactor msr permission bitmap allocation

2020-08-27 Thread Maxim Levitsky
Replace svm_vcpu_init_msrpm with svm_vcpu_alloc_msrpm, that also allocates the msr bitmap and add svm_vcpu_free_msrpm to free it. This will be used later to move the nested msr permission bitmap allocation to nested.c Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 45

[PATCH v3 6/8] KVM: x86: allow kvm_x86_ops.set_efer to return a value

2020-08-27 Thread Maxim Levitsky
This will be used later to return an error when setting this msr fails. Note that we ignore this return value for qemu initiated writes to avoid breaking backward compatibility. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c | 3

[PATCH v3 7/8] KVM: emulator: more strict rsm checks.

2020-08-27 Thread Maxim Levitsky
s are probably redundant, since the code sets them to fixed value, but it won't hurt to have them Signed-off-by: Maxim Levitsky --- arch/x86/kvm/emulate.c | 22 +- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emula

[PATCH v3 8/8] KVM: nSVM: implement ondemand allocation of the nested state

2020-08-27 Thread Maxim Levitsky
This way we don't waste memory on VMs which don't use nesting virtualization even if it is available to them. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 42 +++ arch/x86/kvm/svm/svm.c| 52 +-- ar

[PATCH] iommu/amd: fix interrupt remapping for avic

2020-09-13 Thread Maxim Levitsky
bled would eventually crash and show IOMMU errors like that: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0055 address=0xfffdf800 flags=0x0008] Fixes: e52d58d54a321 ("iommu/amd: Use cmpxchg_double() when updating 128-bit IRTE") Signed-off-by: Maxim Levitsky --- drivers/iommu/

xconfig is broken again on Qt5

2020-09-13 Thread Maxim Levitsky
that there were several bugs introduced to xconfig recently due to attempt to support both Qt4 and Qt5. Maybe we should only support one version? I tried gconfig even thinking maybe nobody uses xconfig these days but gconfig seems to lack search function. Best regards, Maxim Levitsky

Re: [PATCH v3 8/8] KVM: nSVM: implement ondemand allocation of the nested state

2020-09-13 Thread Maxim Levitsky
On Sat, 2020-09-12 at 18:32 +0200, Paolo Bonzini wrote: > On 27/08/20 19:11, Maxim Levitsky wrote: > > + hsave_page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO); > > + if (!hsave_page) > > + goto error; > > + > > I think an error here should be just

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-08 Thread Maxim Levitsky
On Mon, 2020-12-07 at 11:29 -0600, Oliver Upton wrote: > On Thu, Dec 3, 2020 at 11:12 AM Maxim Levitsky wrote: > > These two new ioctls allow to more precisly capture and > > restore guest's TSC state. > > > > Both ioctls are meant to be used to accurately migra

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-08 Thread Maxim Levitsky
On Mon, 2020-12-07 at 10:04 -0800, Andy Lutomirski wrote: > > On Dec 7, 2020, at 9:00 AM, Maxim Levitsky wrote: > > > > On Mon, 2020-12-07 at 08:53 -0800, Andy Lutomirski wrote: > > > > > On Dec 7, 2020, at 8:38 AM, Thomas Gleixner > > > > > wr

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-08 Thread Maxim Levitsky
On Mon, 2020-12-07 at 20:29 -0300, Marcelo Tosatti wrote: > On Thu, Dec 03, 2020 at 07:11:16PM +0200, Maxim Levitsky wrote: > > These two new ioctls allow to more precisly capture and > > restore guest's TSC state. > > > > Both ioctls are meant to be used to accur

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-08 Thread Maxim Levitsky
On Tue, 2020-12-08 at 17:02 +0100, Thomas Gleixner wrote: > On Tue, Dec 08 2020 at 16:50, Maxim Levitsky wrote: > > On Mon, 2020-12-07 at 20:29 -0300, Marcelo Tosatti wrote: > > > > +This ioctl allows to reconstruct the guest's IA32_TSC and TSC_ADJUST > > &

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-08 Thread Maxim Levitsky
On Tue, 2020-12-08 at 17:40 +0100, Thomas Gleixner wrote: > On Tue, Dec 08 2020 at 13:13, Maxim Levitsky wrote: > > On Mon, 2020-12-07 at 11:29 -0600, Oliver Upton wrote: > > > How would a VMM maintain the phase relationship between guest TSCs > > > using these io

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-08 Thread Maxim Levitsky
On Tue, 2020-12-08 at 09:58 -0600, Oliver Upton wrote: > +cc Sean's new handle > > On Tue, Dec 8, 2020 at 9:57 AM Oliver Upton wrote: > > On Tue, Dec 8, 2020 at 5:13 AM Maxim Levitsky wrote: > > > On Mon, 2020-12-07 at 11:29 -0600, Oliver Upton wrote: > >

Re: [PATCH 0/2] RFC: Precise TSC migration

2020-12-01 Thread Maxim Levitsky
On Mon, 2020-11-30 at 16:16 -0300, Marcelo Tosatti wrote: > Hi Maxim, > > On Mon, Nov 30, 2020 at 03:35:57PM +0200, Maxim Levitsky wrote: > > Hi! > > > > This is the first version of the work to make TSC migration more accurate, > > as was defined by Paulo at:

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-07 Thread Maxim Levitsky
On Sun, 2020-12-06 at 17:19 +0100, Thomas Gleixner wrote: > On Thu, Dec 03 2020 at 19:11, Maxim Levitsky wrote: > > + case KVM_SET_TSC_STATE: { > > + struct kvm_tsc_state __user *user_tsc_state = argp; > > + struct kvm_tsc_state tsc_state; > &g

Re: [PATCH 0/2] RFC: Precise TSC migration

2020-12-07 Thread Maxim Levitsky
On Thu, 2020-12-03 at 17:18 -0300, Marcelo Tosatti wrote: > On Thu, Dec 03, 2020 at 01:39:42PM +0200, Maxim Levitsky wrote: > > On Tue, 2020-12-01 at 16:48 -0300, Marcelo Tosatti wrote: > > > On Tue, Dec 01, 2020 at 02:30:39PM +0200, Maxim Levitsky wrote: > > > > On

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-07 Thread Maxim Levitsky
On Mon, 2020-12-07 at 08:53 -0800, Andy Lutomirski wrote: > > On Dec 7, 2020, at 8:38 AM, Thomas Gleixner wrote: > > > > On Mon, Dec 07 2020 at 14:16, Maxim Levitsky wrote: > > > > On Sun, 2020-12-06 at 17:19 +0100, Thomas Gleixner wrote: > > >

Re: [PATCH 0/2] RFC: Precise TSC migration

2020-12-03 Thread Maxim Levitsky
On Tue, 2020-12-01 at 20:35 +0100, Thomas Gleixner wrote: > On Mon, Nov 30 2020 at 15:35, Maxim Levitsky wrote: > > The idea of masterclock is that when the host TSC is synchronized > > (or as kernel call it, stable), and the guest TSC is synchronized as well, > > then we can

[PATCH 0/1] Fix for a recent regression in kvm/queue (guest using 100% cpu time)

2020-12-03 Thread Maxim Levitsky
st regards, Maxim Levitsky Maxim Levitsky (1): KVM: x86: ignore SIPIs that are received while not in wait-for-sipi state arch/x86/kvm/lapic.c | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.26.2

[PATCH 1/1] KVM: x86: ignore SIPIs that are received while not in wait-for-sipi state

2020-12-03 Thread Maxim Levitsky
ccept_events vs check_nested_events") Signed-off-by: Maxim Levitsky --- arch/x86/kvm/lapic.c | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index e3ee597ff5404..6a87623aa578e 100644 --- a/arch/x86/kvm/lapic.c +++ b/

[PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-03 Thread Maxim Levitsky
These two new ioctls allow to more precisly capture and restore guest's TSC state. Both ioctls are meant to be used to accurately migrate guest TSC even when there is a significant downtime during the migration. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- Documentation

[PATCH v2 3/3] kvm/selftests: update tsc_msrs_test to cover KVM_X86_QUIRK_TSC_HOST_ACCESS

2020-12-03 Thread Maxim Levitsky
Run the test once with quirk enabled and once disabled, and adjust the expected values accordingly. Signed-off-by: Maxim Levitsky --- .../selftests/kvm/x86_64/tsc_msrs_test.c | 79 --- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests

[PATCH v2 0/3] RFC: Precise TSC migration

2020-12-03 Thread Maxim Levitsky
pping it to 0 - updated tsc_msr_test unit test to cover this feature - refactoring Patches to enable this feature in qemu are in the process of being sent to qemu-devel mailing list. Best regards, Maxim Levitsky Maxim Levitsky (3): KVM: x86: implement KVM_{GET|SET}_TSC_STATE KVM: x

[PATCH v2 2/3] KVM: x86: introduce KVM_X86_QUIRK_TSC_HOST_ACCESS

2020-12-03 Thread Maxim Levitsky
sted-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 19 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index 8e76d

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-10 Thread Maxim Levitsky
ending this to make guest use it even when bare tsc is used, and also implement whatever logic is needed to jump the guest clock forward when this bit is set. What do you think? Best regards, Maxim Levitsky > > Paolo >

Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE

2020-12-10 Thread Maxim Levitsky
On Thu, 2020-12-10 at 12:48 +0100, Paolo Bonzini wrote: > On 08/12/20 18:08, Maxim Levitsky wrote: > > > Even if you support TSCADJUST and let the guest write to it does not > > > change the per guest offset at all. TSCADJUST is per [v]CPU and adds on > > >

Re: [PATCH 1/2] KVM: x86: implement KVM_SET_TSC_PRECISE/KVM_GET_TSC_PRECISE

2020-12-03 Thread Maxim Levitsky
On Tue, 2020-12-01 at 20:43 +0100, Thomas Gleixner wrote: > On Mon, Nov 30 2020 at 15:35, Maxim Levitsky wrote: > > + struct kvm_tsc_info { > > + __u32 flags; > > + __u64 nsec; > > + __u64 tsc; > > + __u64 tsc_adjust; > > + }; > >

Re: [PATCH 0/2] RFC: Precise TSC migration

2020-12-03 Thread Maxim Levitsky
On Tue, 2020-12-01 at 16:48 -0300, Marcelo Tosatti wrote: > On Tue, Dec 01, 2020 at 02:30:39PM +0200, Maxim Levitsky wrote: > > On Mon, 2020-11-30 at 16:16 -0300, Marcelo Tosatti wrote: > > > Hi Maxim, > > > > > > On Mon, Nov 30, 2020 at 03:35:57PM +02

Re: [PATCH 0/2] RFC: Precise TSC migration

2020-12-03 Thread Maxim Levitsky
done with new CPUID bit, or always when KVM is detected, (or even when *any* hypervisor is detected) I also don't mind if we only disable tsc sync logic or set X86_FEATURE_TSC_RELIABLE which will disable it and the clocksource watchdog. Best regards, Maxim Levitsky

Re: [PATCH 0/2] RFC: Precise TSC migration

2020-12-03 Thread Maxim Levitsky
as well. > > > > If the host TSC is not synchronized, then don't even try. > > This reminds me: if you’re adding a new kvm feature that tells the guest that > the TSC works well, could you perhaps only have one structure for all vCPUs > in the same guest? I won&

<    1   2   3   4   5   6   >