Re: [PATCH v20 4/9] firmware: arm_rmm: Add support for SRO

From: Suzuki K Poulose

Date: Wed Sep 30 2026 - 10:52:29 EST


On 30/09/2026 14:15, Catalin Marinas wrote:
On Tue, Sep 29, 2026 at 11:16:18PM +0100, Suzuki K Poulose wrote:
+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)
+{
+ unsigned long block_size_fld = RMI_DONATE_BLOCK_SIZE(donatereq);
+ unsigned long block_size = rmi_addr_block_size_to_bytes(block_size_fld);
+ unsigned long count = RMI_DONATE_COUNT(donatereq);
+ unsigned long state = RMI_DONATE_STATE(donatereq);
+ unsigned long size = block_size * count;
+ unsigned long addr_range;
+ unsigned long donated_size;
+ int ret;
+ void *virt;
+ phys_addr_t phys;
+
+ /*
+ * The RMM specification requires contiguous allocations are always a
+ * power of 2
+ */
+ if (WARN_ON_ONCE(!is_power_of_2(size)))
+ return -EINVAL;
+ /*
+ * RMM clamps the Maximum value of RmiOpMemDonateReq:count to prevent
+ * overflow in the RMI_ADDR_RANGE_COUNT field.
+ */
+ if (WARN_ON_ONCE(count > (BIT(PAGE_SHIFT - 2) - 1)))
+ return -EINVAL;

Nit: it might be easier to read as FIELD_MAX(RMI_ADDR_RANGE_COUNT_MASK)
as that's what we want to limit it to.

Thanks, that is neat. I will update this.


Reviewed-by: Catalin Marinas <catalin.marinas@xxxxxxx>

(Sashiko seems to have more findings but the rest looks alright to me)

I have updated the code to address the issues.

Thanks Catalin.

Suzuki