Message ID | 20200820091327.197807-3-mlevitsk@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: nSVM: ondemand nested state allocation + nested guest state caching | expand |
On 20/08/20 11:13, Maxim Levitsky wrote: > No functional changes. > > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> > --- > 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/nested.c > index fb68467e6049..d9755eab2199 100644 > --- a/arch/x86/kvm/svm/nested.c > +++ b/arch/x86/kvm/svm/nested.c > @@ -431,7 +431,7 @@ int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > { > int ret; > > - svm->nested.vmcb = vmcb_gpa; > + svm->nested.vmcb_gpa = vmcb_gpa; > load_nested_vmcb_control(svm, &nested_vmcb->control); > nested_prepare_vmcb_save(svm, nested_vmcb); > nested_prepare_vmcb_control(svm); > @@ -568,7 +568,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) > struct vmcb *vmcb = svm->vmcb; > struct kvm_host_map map; > > - rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map); > + rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb_gpa), &map); > if (rc) { > if (rc == -EINVAL) > kvm_inject_gp(&svm->vcpu, 0); > @@ -579,7 +579,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) > > /* Exit Guest-Mode */ > leave_guest_mode(&svm->vcpu); > - svm->nested.vmcb = 0; > + svm->nested.vmcb_gpa = 0; > WARN_ON_ONCE(svm->nested.nested_run_pending); > > /* in case we halted in L2 */ > @@ -1018,7 +1018,7 @@ static int svm_get_nested_state(struct kvm_vcpu *vcpu, > > /* First fill in the header and copy it out. */ > if (is_guest_mode(vcpu)) { > - kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb; > + kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb_gpa; > kvm_state.size += KVM_STATE_NESTED_SVM_VMCB_SIZE; > kvm_state.flags |= KVM_STATE_NESTED_GUEST_MODE; > > @@ -1128,7 +1128,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, > copy_vmcb_control_area(&hsave->control, &svm->vmcb->control); > hsave->save = save; > > - svm->nested.vmcb = kvm_state->hdr.svm.vmcb_pa; > + svm->nested.vmcb_gpa = kvm_state->hdr.svm.vmcb_pa; > load_nested_vmcb_control(svm, &ctl); > nested_prepare_vmcb_control(svm); > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 562a79e3e63a..4338d2a2596e 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -1102,7 +1102,7 @@ static void init_vmcb(struct vcpu_svm *svm) > } > svm->asid_generation = 0; > > - svm->nested.vmcb = 0; > + svm->nested.vmcb_gpa = 0; > svm->vcpu.arch.hflags = 0; > > if (!kvm_pause_in_guest(svm->vcpu.kvm)) { > @@ -3884,7 +3884,7 @@ static int svm_pre_enter_smm(struct kvm_vcpu *vcpu, char *smstate) > /* FED8h - SVM Guest */ > put_smstate(u64, smstate, 0x7ed8, 1); > /* FEE0h - SVM Guest VMCB Physical Address */ > - put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb); > + put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb_gpa); > > svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX]; > svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP]; > @@ -3903,17 +3903,18 @@ static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) > struct vmcb *nested_vmcb; > struct kvm_host_map map; > u64 guest; > - u64 vmcb; > + u64 vmcb_gpa; > int ret = 0; > > guest = GET_SMSTATE(u64, smstate, 0x7ed8); > - vmcb = GET_SMSTATE(u64, smstate, 0x7ee0); > + vmcb_gpa = GET_SMSTATE(u64, smstate, 0x7ee0); > > if (guest) { > - if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb), &map) == -EINVAL) > + if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map) == -EINVAL) > return 1; > + > nested_vmcb = map.hva; > - ret = enter_svm_guest_mode(svm, vmcb, nested_vmcb); > + ret = enter_svm_guest_mode(svm, vmcb_gpa, nested_vmcb); > kvm_vcpu_unmap(&svm->vcpu, &map, true); > } > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > index a798e1731709..03f2f082ef10 100644 > --- a/arch/x86/kvm/svm/svm.h > +++ b/arch/x86/kvm/svm/svm.h > @@ -85,7 +85,7 @@ struct svm_nested_state { > struct vmcb *hsave; > u64 hsave_msr; > u64 vm_cr_msr; > - u64 vmcb; > + u64 vmcb_gpa; > u32 host_intercept_exceptions; > > /* These are the merged vectors */ > 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 patch 6 to avoid too-long lines). Paolo
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 <mlevitsk@redhat.com> > > --- > > 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/nested.c > > index fb68467e6049..d9755eab2199 100644 > > --- a/arch/x86/kvm/svm/nested.c > > +++ b/arch/x86/kvm/svm/nested.c > > @@ -431,7 +431,7 @@ int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, > > { > > int ret; > > > > - svm->nested.vmcb = vmcb_gpa; > > + svm->nested.vmcb_gpa = vmcb_gpa; > > load_nested_vmcb_control(svm, &nested_vmcb->control); > > nested_prepare_vmcb_save(svm, nested_vmcb); > > nested_prepare_vmcb_control(svm); > > @@ -568,7 +568,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) > > struct vmcb *vmcb = svm->vmcb; > > struct kvm_host_map map; > > > > - rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map); > > + rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb_gpa), &map); > > if (rc) { > > if (rc == -EINVAL) > > kvm_inject_gp(&svm->vcpu, 0); > > @@ -579,7 +579,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) > > > > /* Exit Guest-Mode */ > > leave_guest_mode(&svm->vcpu); > > - svm->nested.vmcb = 0; > > + svm->nested.vmcb_gpa = 0; > > WARN_ON_ONCE(svm->nested.nested_run_pending); > > > > /* in case we halted in L2 */ > > @@ -1018,7 +1018,7 @@ static int svm_get_nested_state(struct kvm_vcpu *vcpu, > > > > /* First fill in the header and copy it out. */ > > if (is_guest_mode(vcpu)) { > > - kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb; > > + kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb_gpa; > > kvm_state.size += KVM_STATE_NESTED_SVM_VMCB_SIZE; > > kvm_state.flags |= KVM_STATE_NESTED_GUEST_MODE; > > > > @@ -1128,7 +1128,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, > > copy_vmcb_control_area(&hsave->control, &svm->vmcb->control); > > hsave->save = save; > > > > - svm->nested.vmcb = kvm_state->hdr.svm.vmcb_pa; > > + svm->nested.vmcb_gpa = kvm_state->hdr.svm.vmcb_pa; > > load_nested_vmcb_control(svm, &ctl); > > nested_prepare_vmcb_control(svm); > > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > index 562a79e3e63a..4338d2a2596e 100644 > > --- a/arch/x86/kvm/svm/svm.c > > +++ b/arch/x86/kvm/svm/svm.c > > @@ -1102,7 +1102,7 @@ static void init_vmcb(struct vcpu_svm *svm) > > } > > svm->asid_generation = 0; > > > > - svm->nested.vmcb = 0; > > + svm->nested.vmcb_gpa = 0; > > svm->vcpu.arch.hflags = 0; > > > > if (!kvm_pause_in_guest(svm->vcpu.kvm)) { > > @@ -3884,7 +3884,7 @@ static int svm_pre_enter_smm(struct kvm_vcpu *vcpu, char *smstate) > > /* FED8h - SVM Guest */ > > put_smstate(u64, smstate, 0x7ed8, 1); > > /* FEE0h - SVM Guest VMCB Physical Address */ > > - put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb); > > + put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb_gpa); > > > > svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX]; > > svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP]; > > @@ -3903,17 +3903,18 @@ static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) > > struct vmcb *nested_vmcb; > > struct kvm_host_map map; > > u64 guest; > > - u64 vmcb; > > + u64 vmcb_gpa; > > int ret = 0; > > > > guest = GET_SMSTATE(u64, smstate, 0x7ed8); > > - vmcb = GET_SMSTATE(u64, smstate, 0x7ee0); > > + vmcb_gpa = GET_SMSTATE(u64, smstate, 0x7ee0); > > > > if (guest) { > > - if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb), &map) == -EINVAL) > > + if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map) == -EINVAL) > > return 1; > > + > > nested_vmcb = map.hva; > > - ret = enter_svm_guest_mode(svm, vmcb, nested_vmcb); > > + ret = enter_svm_guest_mode(svm, vmcb_gpa, nested_vmcb); > > kvm_vcpu_unmap(&svm->vcpu, &map, true); > > } > > > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > > index a798e1731709..03f2f082ef10 100644 > > --- a/arch/x86/kvm/svm/svm.h > > +++ b/arch/x86/kvm/svm/svm.h > > @@ -85,7 +85,7 @@ struct svm_nested_state { > > struct vmcb *hsave; > > u64 hsave_msr; > > u64 vm_cr_msr; > > - u64 vmcb; > > + u64 vmcb_gpa; > > u32 host_intercept_exceptions; > > > > /* These are the merged vectors */ > > > > 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 patch 6 > to avoid too-long lines). The limit was raised to 100 chars recently, thats why I allowed some lines to go over 80 characters to avoid adding too much noise. > > Paolo I was thinking to to this, but since this field already sits in ->nested I was thinking that this is a bit redundant, but I don't have anything against doing it. Best regards, Maxim Levitsky >
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 patch 6 >> to avoid too-long lines). > The limit was raised to 100 chars recently, thats why I allowed some lines to > go over 80 characters to avoid adding too much noise. > True, but having svm->nested.vmcb12->control repeated all over isn't pretty. :) Since you're going to touch all lines anyway, adding the local variable is a good idea. Paolo
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 patch 6 > > > to avoid too-long lines). > > The limit was raised to 100 chars recently, thats why I allowed some lines to > > go over 80 characters to avoid adding too much noise. > > > > True, but having svm->nested.vmcb12->control repeated all over isn't > pretty. :) 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 was thinking that naming this field vmcb12 would be redundant and not accepted this way. Best regards, Maxim Levitsky > > Since you're going to touch all lines anyway, adding the local variable > is a good idea. > > Paolo >
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 was thinking that naming this field vmcb12 would be > redundant and not accepted this way. We want to have both svm->nested.vmcb12 and svm->nested.vmcb02 in there, and hsave is also a VMCB of sort (somewhat like a vmcb01 that is only used while running a nested guest). So it is clearer to write _which_ vmcb it is, and it also helps by making terminology consistent between VMX and SVM. Paolo
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 was thinking that naming this field vmcb12 would be > > redundant and not accepted this way. > > We want to have both svm->nested.vmcb12 and svm->nested.vmcb02 in there, > and hsave is also a VMCB of sort (somewhat like a vmcb01 that is only > used while running a nested guest). So it is clearer to write _which_ > vmcb it is, and it also helps by making terminology consistent between > VMX and SVM. This makes sense. Best regards, Maxim Levitsky > > Paolo >
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index fb68467e6049..d9755eab2199 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -431,7 +431,7 @@ int enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa, { int ret; - svm->nested.vmcb = vmcb_gpa; + svm->nested.vmcb_gpa = vmcb_gpa; load_nested_vmcb_control(svm, &nested_vmcb->control); nested_prepare_vmcb_save(svm, nested_vmcb); nested_prepare_vmcb_control(svm); @@ -568,7 +568,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) struct vmcb *vmcb = svm->vmcb; struct kvm_host_map map; - rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map); + rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb_gpa), &map); if (rc) { if (rc == -EINVAL) kvm_inject_gp(&svm->vcpu, 0); @@ -579,7 +579,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) /* Exit Guest-Mode */ leave_guest_mode(&svm->vcpu); - svm->nested.vmcb = 0; + svm->nested.vmcb_gpa = 0; WARN_ON_ONCE(svm->nested.nested_run_pending); /* in case we halted in L2 */ @@ -1018,7 +1018,7 @@ static int svm_get_nested_state(struct kvm_vcpu *vcpu, /* First fill in the header and copy it out. */ if (is_guest_mode(vcpu)) { - kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb; + kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb_gpa; kvm_state.size += KVM_STATE_NESTED_SVM_VMCB_SIZE; kvm_state.flags |= KVM_STATE_NESTED_GUEST_MODE; @@ -1128,7 +1128,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, copy_vmcb_control_area(&hsave->control, &svm->vmcb->control); hsave->save = save; - svm->nested.vmcb = kvm_state->hdr.svm.vmcb_pa; + svm->nested.vmcb_gpa = kvm_state->hdr.svm.vmcb_pa; load_nested_vmcb_control(svm, &ctl); nested_prepare_vmcb_control(svm); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 562a79e3e63a..4338d2a2596e 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1102,7 +1102,7 @@ static void init_vmcb(struct vcpu_svm *svm) } svm->asid_generation = 0; - svm->nested.vmcb = 0; + svm->nested.vmcb_gpa = 0; svm->vcpu.arch.hflags = 0; if (!kvm_pause_in_guest(svm->vcpu.kvm)) { @@ -3884,7 +3884,7 @@ static int svm_pre_enter_smm(struct kvm_vcpu *vcpu, char *smstate) /* FED8h - SVM Guest */ put_smstate(u64, smstate, 0x7ed8, 1); /* FEE0h - SVM Guest VMCB Physical Address */ - put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb); + put_smstate(u64, smstate, 0x7ee0, svm->nested.vmcb_gpa); svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX]; svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP]; @@ -3903,17 +3903,18 @@ static int svm_pre_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) struct vmcb *nested_vmcb; struct kvm_host_map map; u64 guest; - u64 vmcb; + u64 vmcb_gpa; int ret = 0; guest = GET_SMSTATE(u64, smstate, 0x7ed8); - vmcb = GET_SMSTATE(u64, smstate, 0x7ee0); + vmcb_gpa = GET_SMSTATE(u64, smstate, 0x7ee0); if (guest) { - if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb), &map) == -EINVAL) + if (kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map) == -EINVAL) return 1; + nested_vmcb = map.hva; - ret = enter_svm_guest_mode(svm, vmcb, nested_vmcb); + ret = enter_svm_guest_mode(svm, vmcb_gpa, nested_vmcb); kvm_vcpu_unmap(&svm->vcpu, &map, true); } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index a798e1731709..03f2f082ef10 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -85,7 +85,7 @@ struct svm_nested_state { struct vmcb *hsave; u64 hsave_msr; u64 vm_cr_msr; - u64 vmcb; + u64 vmcb_gpa; u32 host_intercept_exceptions; /* These are the merged vectors */
No functional changes. Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> --- 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(-)