|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v2 12/39] xen/riscv: implement vCPU context switching
On 2026-09-04 10:33 +0200, Jan Beulich wrote:
> On 04.09.2026 10:26, Baptiste Le Duc wrote:
> >> @@ -329,6 +333,169 @@ int arch_domain_create(struct domain *d,
> >> return rc;
> >> }
> >>
> >> +static void save_csr_regs(struct vcpu *vcpu)
> >> +{
> >> + /*
> >> + * There is no need to save these CSRs as only hypervisor writes them
> >> in
> >> + * restore_csr_regs() and guest can't access them so they shouldn't be
> >> + * stored here. Keep them commented here just for symmetry with the
> >> + * restore CSRs register part.
> >> + *
> >> + * vcpu->arch.hedeleg = csr_read(CSR_HEDELEG);
> >> + * vcpu->arch.hideleg = csr_read(CSR_HIDELEG);
> >> + * vcpu->arch.henvcfg = csr_read64(CSR_HENVCFG);
> >> + * vcpu->arch.hcounteren = csr_read(CSR_HCOUNTEREN);
> >> + * vcpu->arch.htimedelta = csr_read64(CSR_HTIMEDELTA);
> >> + *
> >> + * if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_smstateen) )
> >> + * vcpu->arch.hstateen0 = csr_read(CSR_HSTATEEN0);
> >> + */
> >> +
> >> + vcpu->arch.hvip = csr_read(CSR_HVIP);
> >> +
> >> + vcpu->arch.vsstatus = csr_read(CSR_VSSTATUS);
> >> + vcpu->arch.vsie = csr_read(CSR_VSIE);
> >
> >
> >> + vcpu->arch.vstvec = csr_read(CSR_VSTVEC);
> >> + vcpu->arch.vsscratch = csr_read(CSR_VSSCRATCH);
> >> + vcpu->arch.vscause = csr_read(CSR_VSCAUSE);
> >> + vcpu->arch.vstval = csr_read(CSR_VSTVAL);
> >> + vcpu->arch.vsepc = csr_read(CSR_VSEPC);
> >> +}
> >> +
> >> +static void restore_csr_regs(struct vcpu *vcpu)
> >> +{
> >> + csr_write(CSR_HEDELEG, vcpu->arch.hedeleg);
> >> + csr_write(CSR_HIDELEG, vcpu->arch.hideleg);
> >> + csr_write(CSR_HVIP, vcpu->arch.hvip);
> >> + csr_write64(CSR_HENVCFG, vcpu->arch.henvcfg);
> >> + csr_write(CSR_HCOUNTEREN, vcpu->arch.hcounteren);
> >> + csr_write64(CSR_HTIMEDELTA, vcpu->arch.htimedelta);
> >> +
> >> + if ( riscv_isa_extension_available(NULL, RISCV_ISA_EXT_smstateen) )
> >> + csr_write(CSR_HSTATEEN0, vcpu->arch.hstateen0);
> >> +
> >> + csr_write(CSR_VSSTATUS, vcpu->arch.vsstatus);
> >> + csr_write(CSR_VSIE, vcpu->arch.vsie);
> >
> >
> >> + csr_write(CSR_VSTVEC, vcpu->arch.vstvec);
> >> + csr_write(CSR_VSSCRATCH, vcpu->arch.vsscratch);
> >> + csr_write(CSR_VSCAUSE, vcpu->arch.vscause);
> >> + csr_write(CSR_VSTVAL, vcpu->arch.vstval);
> >> + csr_write(CSR_VSEPC, vcpu->arch.vsepc);
> >> +}
> >> +
> >> +static void ctxt_switch_from(struct vcpu *p)
> > Is it expected to have diverse names for the vcpu arg? Above it's vcpu,
> > here it's p (I assume it's for `previous` but I think the _from alone is
> > enough to understand) and below it's n. Shouldn't be better to keep the
> > same name?
>
> Context switch code is special, and using p and n can be warranted there.
> Everywhere else it should be v, nothing else (and I said so to Oleksii
> more than once before). Unless, of course, multiple vCPU-s come into play
> at the same time.
>
Ok noted, thanks for clarifying that.
> Jan
>
>
>
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |