Hi Ryan, Jean-Philippe, On Thu, Oct 15, 2026 at 4:27 PM Ryan Roberts <[email protected]> wrote:
> From: Jean-Philippe Brucker <[email protected]> > > Add functions to switch the guest MTC. Reset the accelerators and CLA > registers on switch. No save/restore of accelerators at the moment, we > only restore the kernel's PL0CTL. > > Signed-off-by: Jean-Philippe Brucker <[email protected]> (...) > +/** > + * struct cla_regs_pl1 - Saved CLA register state (PL1) > + * @pl0ctrl: Host PL0 control register > + * > + * Most registers are simply reset when transitionning to and from VMs, > since we > + * don't support shared assignment. > + */ > +struct cla_regs_pl1 { > + u64 pl0ctrl; > +}; > + > +enum cla_ctx_type { > + CLA_CTX_PL0, > + CLA_CTX_PL1, > +}; Please add authoritative definitions of the these two context states here so we know exactly what they are for. > * Mutable, written by domain reassignment, device work, and CPU hotplug: > * @regs: State for each device in domain. > * @asid: Pinned ASID of live context. > + * @guest_mmu: Stage 2 translation configuration. Since they are now in a union there is some information missing here, asid for PL0, guest_mmu for PL1? > */ > struct cla_ctx { > struct kref refcnt; > @@ -191,7 +220,10 @@ struct cla_ctx { > refcount_t users; > struct list_head queue_node; > void **regs; > - unsigned int asid; > + union { > + unsigned int asid; > + struct kvm_arch_guest_mmu *guest_mmu; > + }; > wait_queue_head_t waitq; > }; (...) > /** > * cla_ctx_create - Create a context or increase its user count > * @domain: CLA domain > @@ -48,8 +79,12 @@ struct cla_ctx *cla_ctx_create(struct cla_domain *domain, > INIT_LIST_HEAD(&ctx->queue_node); > init_waitqueue_head(&ctx->waitq); > > - mmgrab(key->mm); > - get_file(key->file); > + if (cla_ctx_is_pl0(ctx)) { > + mmgrab(key->mm); > + get_file(key->file); > + } else { > + WARN_ON(!cla_ctx_get_pl1(ctx)); > + } This WARN_ON looks more like an assert() of some kind? Since it's an enum and assigned from those everywher this is basically a check for memory corruption...? Well maybe better safe than sorry. If you want to employ this pattern, and especially if there will be PL2, PL3 etc in the future, do a switch? switch (ctx->key.type) { case CLA_CTX_PL0: mmgrab(key->mm); get_file(key->file); break; case CLA_CTX_PL1: break; default: WARN_ON(1); /* Should never happen */ break; } So you would then use that pattern also here: > - mmdrop(key->mm); > - fput(key->file); > + if (cla_ctx_is_pl0(ctx)) { > + mmdrop(key->mm); > + fput(key->file); > + } else { > + cla_ctx_put_pl1(ctx); > + } And here: > - mmdrop(ctx->key.mm); > - fput(ctx->key.file); > + if (cla_ctx_is_pl0(ctx)) { > + mmdrop(ctx->key.mm); > + fput(ctx->key.file); > + } else { > + cla_ctx_put_pl1(ctx); > + } > #define cla_kernel_mtc \ > (cla_kernel_pl == 2 ? CLA_MTC_REGIDX_PL2 : CLA_MTC_REGIDX_PL1) > > +/** > + * struct cla_mtc_s2 - Stage 2 MTC configuration for the host or a VM. > + * @hcr: HCR_EL2 register value. > + * @vttbr: VTTBR_EL2 register value. > + * @vtcr: VTCR_EL2 register value. > + */ > +struct cla_mtc_s2 { > + u64 hcr; > + u64 vttbr; > + u64 vtcr; > +}; At this point I have no idea what "stage 1" and "stage 2" is, but I just assume it is something everyone working on virtualization knows about. Maybe it could be explained briefly in the commit message for the rest of us? Yours, Linus Walleij
