[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 03/50] x86/svm: introduce SVM_MAP_VMCB() and SVM_UNMAP_VMCB()



On Mon, Nov 23, 2026 at 1:59 PM Jan Beulich <jbeulich@xxxxxxxx> wrote:
>
> On 19.11.2026 22:06, George Dunlap wrote:
> > @@ -531,10 +547,13 @@ static void cf_check svm_set_interrupt_shadow(
> >
> >          vmcb_set_general1_intercepts(vmcb, gen1);
> >      }
> > +
> > +    SVM_UNMAP_VMCB(v, vmcb);
> >  }
> >
> >  static int cf_check svm_guest_x86_mode(struct vcpu *v)
> >  {
> > +    /* Current only (see guest_cpu_user_regs() below): no mapping needed. 
> > */
> >      struct vmcb *vmcb = v->arch.hvm.svm.vmcb;
> >
> >      if ( unlikely(!(v->arch.hvm.guest_cr[0] & X86_CR0_PE)) )
>
> The pre-existing guest_cpu_user_regs() makes clear that one may better have
> been here already before, but might this new comment perhaps warrant adding
> a corresponding assertion here now?
>
> > @@ -602,13 +621,18 @@ void svm_sync_vmcb(struct vcpu *v, enum 
> > vmcb_sync_state new_state)
> >
> >  static unsigned int cf_check svm_get_cpl(struct vcpu *v)
> >  {
> > -    return vmcb_get_cpl(v->arch.hvm.svm.vmcb);
> > +    const struct vmcb *vmcb = SVM_MAP_VMCB(v);
>
> Much like you have it here (or below, e.g. in svm_get_guest_pat()), ...
>
> > +    unsigned int cpl = vmcb_get_cpl(vmcb);
> > +
> > +    SVM_UNMAP_VMCB(v, vmcb);
> > +
> > +    return cpl;
> >  }
> >
> >  static void cf_check svm_get_segment_register(
> >      struct vcpu *v, enum x86_segment seg, struct segment_register *reg)
> >  {
> > -    struct vmcb *vmcb = v->arch.hvm.svm.vmcb;
> > +    struct vmcb *vmcb = SVM_MAP_VMCB(v);
>
> ... it looks as if this could also be pointer-to-const.
>
> > @@ -754,25 +789,36 @@ static void cf_check svm_set_tsc_offset(struct vcpu 
> > *v, uint64_t offset)
> >      if ( !nestedhvm_enabled(d) )
> >      {
> >          vmcb_set_tsc_offset(vmcb, offset);
> > +        SVM_UNMAP_VMCB(v, vmcb);
> >          return;
> >      }
> >
> > -    n1vmcb = vcpu_nestedhvm(v).nv_n1vmcx;
> > -    n2vmcb = vcpu_nestedhvm(v).nv_n2vmcx;
>
> While moving these assignments, it might be a good idea to also move the
> declarations ...
>
> > +    /*
> > +     * A vCPU stays in nested guest mode across a deschedule or a pause, so
> > +     * this can run remotely with the L2 VMCB active: map both explicitly.
> > +     */
> >      if ( nestedhvm_vcpu_in_guestmode(v) )
> >      {
> > +        const struct nestedvcpu *nv = &vcpu_nestedhvm(v);
>
> ... into this scope, making ...
>
> > +        n1vmcb = SVM_MAP_VMCB_ONE(v, nv->nv_n1vmcx, nv->nv_n1vmcx_pa);
> > +        n2vmcb = SVM_MAP_VMCB_ONE(v, nv->nv_n2vmcx, nv->nv_n2vmcx_pa);
>
> ... these their initializers.
>
> >          n2_tsc_offset = vmcb_get_tsc_offset(n2vmcb) -
> >                          vmcb_get_tsc_offset(n1vmcb);
> >          vmcb_set_tsc_offset(n1vmcb, offset);
> > +
> > +        SVM_UNMAP_VMCB(v, n2vmcb);
> > +        SVM_UNMAP_VMCB(v, n1vmcb);
> >      }
> >
> >      vmcb_set_tsc_offset(vmcb, offset + n2_tsc_offset);
> > +    SVM_UNMAP_VMCB(v, vmcb);
> >  }
>
> It might also help a little to fold both exit paths. n2_tsc_offset is set to
> 0 already initially, so inverting the first conditional looks to easily allow
> that, saving the need to keep both paths in sync cleanup-wise.
>
> In fact both if() can be combined, i.e. there also shouldn't be any need to
> re-indent the 2nd one's body.
>
> > @@ -407,6 +425,7 @@ static void cf_check vmcb_dump(unsigned char ch)
> >  {
> >      struct domain *d;
> >      struct vcpu *v;
> > +    struct vmcb *vmcb;
>
> Can this please move ...
>
> > @@ -425,7 +444,9 @@ static void cf_check vmcb_dump(unsigned char ch)
> >                  continue;
> >              }
> >              printk("\tVCPU %d\n", v->vcpu_id);
> > -            svm_vmcb_dump("key_handler", v->arch.hvm.svm.vmcb);
> > +            vmcb = SVM_MAP_VMCB(v);
> > +            svm_vmcb_dump("key_handler", vmcb);
> > +            SVM_UNMAP_VMCB(v, vmcb);
> >
> >              process_pending_softirqs();
> >          }
>
> ... into the innermost scope it's needed in? Also again pointer-to-const?

All of that sounds good; thanks for the review.

 -George



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.