Re: [PATCH v19 4/7] firmware: arm_rmm: Add support for SRO
From: Catalin Marinas
Date: Mon Sep 28 2026 - 05:30:52 EST
On Thu, Sep 24, 2026 at 02:51:58PM +0100, Suzuki K Poulose wrote:
> +long rmi_sro_memxfer_execute(struct rmi_sro_state *sro, gfp_t gfp)
> +{
> + struct arm_smccc_1_2_regs *regs = &sro->regs;
> + bool cancelled = false;
> + unsigned long sro_handle;
> +
> + rmi_smccc_invoke(regs);
> +
> + sro_handle = regs->a1;
> + while (RMI_RESULT_STATUS(regs->a0) == RMI_INCOMPLETE) {
> + bool can_cancel = RMI_RESULT_CAN_CANCEL(regs->a0) == RMI_OP_CAN_CANCEL;
> + int ret = 0;
> +
> + switch (RMI_RESULT_MEMREQ(regs->a0)) {
> + case RMI_OP_MEM_REQ_NONE:
> + rmi_op_continue(sro_handle, RMI_CONTINUE_KEEP_GOING,
> + regs);
> + break;
> + case RMI_OP_MEM_REQ_DONATE:
> + ret = rmi_sro_donate(sro, sro_handle, regs->a2, regs,
> + gfp);
> + break;
> + case RMI_OP_MEM_REQ_RECLAIM:
> + ret = rmi_sro_reclaim(sro, sro_handle, regs);
> + break;
> + default:
> + WARN_ON_ONCE(1);
> + ret = -ENXIO;
> + break;
> + }
Another thing I came across while looking whether we can defer the
activation. It seems that the spec (I_JVYCH) lists some SROs as
PE-bound. Nothing here or in rmi_sro_execute() disables migration and
the memory allocation paths can even sleep with GFP_KERNEL.
Do we need to disable preemption (only for rmi_sro_execute()) or at
least migration (the memxfer path)? We did something similar for the RSI
attestation token loop, commit 24f55f511b9e ("virt: arm-cca-guest: use
migrate_disable() for attestation token requests").
With only migration disabled, another thread on the same CPU
issuing a PE-bound SRO would get RMI_BLOCKED (R_NDXSG). In theory, we
can get a priority inversion case (maybe this doesn't happen with the
current implementation, just looking at the API design). The RMI_BLOCKED
fix not to loop forever probably saves us but the caller would have to
actively sleep or give up before retrying (i.e. don't move the busy loop
higher app the call stack).
Another option is to have a per-CPU mutex here and serialise the SROs
which are PE-bound (there are some precedents for per-CPU mutexes in the
kernel).
--
Catalin