From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>,
kvm@vger.kernel.org, Oliver Upton <oupton@kernel.org>,
kvmarm@lists.linux.dev
Subject: Re: [PATCH v21 4/9] firmware: arm_rmm: Add support for SRO
Date: Thu, 1 Oct 2026 10:14:37 +0100 [thread overview]
Message-ID: <38cb4a33-7313-4115-b3c4-d01b3f5d5643@arm.com> (raw)
In-Reply-To: <20261001090150.1F3381F000FF@smtp.kernel.org>
On 01/10/2026 10:01, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] arm_rmm: spurious SRO cancellation when contig donate cache fills up
> - [Medium] arm_rmm: infinite loop in SRO execution if RMM consumes zero granules
> --
>
> commit 11de55b0945f49bf7651f24a6bc346b286810815
> Author: Steven Price <steven.price@arm.com>
>
> firmware: arm_rmm: Add support for SRO
>
> The commit introduces support for Stateful RMI Operations (SRO) in RMM v2.0.
> It adds logic to handle memory donate and reclaim operations, allowing SMCs
> to return in progress and track state using an rmi_sro_state structure.
> Wrappers for SRO RMI commands are also provided to integrate with the stateful
> command infrastructure.
>
>> diff --git a/drivers/firmware/arm_rmm/rmi.c b/drivers/firmware/arm_rmm/rmi.c
>> index b558965a05a2c..7d4e04a5d7c0a 100644
>> --- a/drivers/firmware/arm_rmm/rmi.c
>> +++ b/drivers/firmware/arm_rmm/rmi.c
> [ ... ]
>> +static int rmi_sro_donate_contig(struct rmi_sro_state *sro,
>> + unsigned long sro_handle,
>> + unsigned long donatereq,
>> + struct arm_smccc_1_2_regs *out_regs,
>> + gfp_t gfp)
>> +{
> [ ... ]
>> + /* Reuse the cached address range if we have one */
>> + for (int i = 0; i < sro->addr_count; i++) {
>> + unsigned long entry = sro->addr_list[i];
>> +
>> + if (RMI_ADDR_RANGE_BLOCK_SIZE(entry) == block_size_fld &&
>> + RMI_ADDR_RANGE_COUNT(entry) == count &&
>> + RMI_ADDR_RANGE_STATE(entry) == state &&
>> + IS_ALIGNED(RMI_ADDR_RANGE_ADDR(entry), size)) {
>> + sro->addr_count--;
>> + swap(sro->addr_list[sro->addr_count],
>> + sro->addr_list[i]);
>> +
>> + goto mem_donate;
>> + }
>> + }
>> +
>> + ret = rmi_sro_ensure_capacity(sro, 1);
>> + if (ret)
>> + return ret;
>
> [Severity: Medium]
> When the cache fills up with unconsumed fragments, rmi_sro_ensure_capacity()
> returns -ENOSPC. Does returning the error here cause a valid SRO command to be
> spuriously cancelled?
Agree, we could handle this better like we do for the noncontig case
with the following hunk:
diff --git a/drivers/firmware/arm_rmm/rmi.c b/drivers/firmware/arm_rmm/rmi.c
index a01ab69a64c7c..0941cd8c34d66 100644
--- a/drivers/firmware/arm_rmm/rmi.c
+++ b/drivers/firmware/arm_rmm/rmi.c
@@ -343,8 +343,9 @@ static int rmi_sro_donate_contig(struct
rmi_sro_state *sro,
}
ret = rmi_sro_ensure_capacity(sro, 1);
+ /* In the odd case we have filled up the cache, free up the
entire list */
if (ret)
- return ret;
+ rmi_sro_free(sro);
>
> Unlike rmi_sro_donate_noncontig() which handles a full cache by calling
> rmi_sro_free() to flush the unconsumed fragments, the contiguous path simply
> bails out. Could this be triggered if the firmware requests memory in patterns
> that fragment the cache?
>
>> +
>> + virt = alloc_pages_exact(size, gfp);
>> + if (!virt)
>> + return -ENOMEM;
> [ ... ]
>> +mem_donate:
>> + rmi_op_mem_donate(sro_handle,
>> + virt_to_phys(&sro->addr_list[sro->addr_count]), 1,
>> + 0, out_regs);
>> + donated_size = out_regs->a1 << PAGE_SHIFT;
>> +
>> + if (WARN_ON(out_regs->a1 > (size >> PAGE_SHIFT)))
>> + donated_size = size;
>> +
>> + /* All granules consumed by the RMM */
>> + if (donated_size == size)
>> + return 0;
>> + /* No granules were consumed by the RMM, cache them */
>> + if (donated_size == 0) {
>> + sro->addr_count++;
>> + return 0;
>> + }
>
> [Severity: Medium]
> If a buggy or interrupted RMM consumes 0 granules, does caching the block and
> returning 0 here create an infinite loop?
>
> Because 0 is a success return code, the execution loop in
> rmi_sro_memxfer_execute() will skip the cancellation logic and re-issue the
> same request, as shown below:
RMM not consuming any granules is a valid case, where another thread of
host donated the memory that we were also trying to donate. Thus RMM
could report 0. Also, as for the infinite loop, there are other ways the
buggy RMM could trigger this. Keep on asking the host to continue
(forever) ! So, I wouldn't worry about this pathological case.
Suzuki
next prev parent reply other threads:[~2026-10-01 9:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 8:45 [PATCH v21 0/9] firmware: arm_rmm: Add RMM v2.0 base RMI support Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 1/9] firmware: arm_rmm: Add SMC definitions for calling the RMM Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 2/9] firmware: arm_rmm: Check for RMI support at init Suzuki K Poulose
2026-10-01 10:50 ` Catalin Marinas
2026-10-01 8:45 ` [PATCH v21 3/9] firmware: arm_rmm: Configure the RMM with the host's page size Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 4/9] firmware: arm_rmm: Add support for SRO Suzuki K Poulose
2026-10-01 9:01 ` sashiko-bot
2026-10-01 9:14 ` Suzuki K Poulose [this message]
2026-10-01 8:45 ` [PATCH v21 5/9] firmware: arm_rmm: Activate the RMM Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 6/9] firmware: arm_rmm: Ensure the RMM has GPT entries for memory Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 7/9] arm64: Block hibernate and kexec while RMM is active Suzuki K Poulose
2026-10-01 11:05 ` Catalin Marinas
2026-10-01 11:39 ` Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 8/9] firmware: arm_rmm: Add wrappers for Realm related RMI commands Suzuki K Poulose
2026-10-01 9:04 ` sashiko-bot
2026-10-01 9:11 ` Suzuki K Poulose
2026-10-01 12:58 ` Catalin Marinas
2026-10-01 13:31 ` Suzuki K Poulose
2026-10-01 8:45 ` [PATCH v21 9/9] firmware: arm_rmm: hotplug: Skip memory added to ZONE_MOVABLE Suzuki K Poulose
2026-10-01 13:10 ` Gavin Shan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=38cb4a33-7313-4115-b3c4-d01b3f5d5643@arm.com \
--to=suzuki.poulose@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox