Re: [RFC PATCH v2 14/15] misc/arm-cla: Support exclusive context assignment

From: Linus Walleij

Date: Wed Nov 25 2026 - 05:09:34 EST


Hi Ryan, Jean-Philippe,

On Thu, Oct 15, 2026 at 4:27 PM Ryan Roberts <ryan.roberts@xxxxxxx> wrote:

> From: Jean-Philippe Brucker <jpb@xxxxxxxxxx>
>
> Introduce a nr_contexts members to cla_domain to count the mapped
> contexts. At the moment PL0 contexts share the domain, while PL1
> contexts require exclusive assignment, since there is no context
> save/restore.

Do you mean to say there is no context save/restore for the
virtualiuzed users? Because there seems to be for the ordinary
(kernel arbitrated) ones.

> A negative count indicates the domain is exclusive.

Exclusive to what? Please be more specific.

> Signed-off-by: Jean-Philippe Brucker <jpb@xxxxxxxxxx>

(...)

> diff --git a/drivers/misc/arm-cla/arm-cla.h b/drivers/misc/arm-cla/arm-cla.h
> index c9ecab5ab6bf..43a58a329525 100644
> --- a/drivers/misc/arm-cla/arm-cla.h
> +++ b/drivers/misc/arm-cla/arm-cla.h
> @@ -105,6 +105,7 @@ struct cla_dev {
> * @lock: Protects the following members.
> * @ctxs: All live contexts, keyed on cla_ctx_key.
> * @queued_ctxs: Queue of contexts waiting for assignment.
> + * @nr_ctxs: Context count. Negative value for exclusive assignment.

Describe here what it means if a context is excludive,

> +static int cla_domain_get(struct cla_domain *domain, bool share)
> +{
> + lockdep_assert_held(&domain->lock);
> +
> + if (share) {
> + /* Time share the domain with other contexts. */
> + if (domain->nr_ctxs < 0)
> + return -EBUSY;
> + domain->nr_ctxs++;
> + WARN_ON(domain->nr_ctxs < 0); /* LONG_MAX contexts?! */
> + } else {
> + /* Reserve the domain for exclusive assignment. */
> + if (domain->nr_ctxs != 0)
> + return -EBUSY;
> + domain->nr_ctxs--;

Maybe:
domain->nr_ctxs = -1;

So it is clear what is going on?

> + }
> + return 0;
> +}

Notice that here the _get() semantics are reference counting as is
proper, compared to the other _get() in the series that I complained about.

> +/* Undo cla_domain_get() */
> +static void cla_domain_put(struct cla_domain *domain)
> +{
> + lockdep_assert_held(&domain->lock);
> +
> + if (domain->nr_ctxs == -1)
> + domain->nr_ctxs = 0;
> + else if (domain->nr_ctxs > 0)
> + domain->nr_ctxs--;nr_c
> + else
> + WARN(1, "invalid domain refcount %ld\n", domain->nr_ctxs);

Looks good

> @@ -53,7 +85,7 @@ struct cla_ctx *cla_ctx_create(struct cla_domain *domain,
> struct cla_ctx_key *key)
> {
> struct cla_ctx *ctx;
> - int ret = -ENOMEM;
> + int ret;
>
> mutex_lock(&domain->lock);
> ctx = cla_domain_lookup_ctx(domain, key);
> @@ -68,9 +100,14 @@ struct cla_ctx *cla_ctx_create(struct cla_domain *domain,
> goto err_unlock;
> }
>
> + ret = cla_domain_get(domain, key->type == CLA_CTX_PL0);

Add a comment that we can share PL0 domains only.

Yours,
Linus Walleij