From: Mostafa Saleh <smostafa@google.com>
To: Sebastian Ene <sebastianene@google.com>
Cc: catalin.marinas@arm.com, maz@kernel.org, oupton@kernel.org,
sudeep.holla@kernel.org, will@kernel.org, joey.gouly@arm.com,
korneld@google.com, kvmarm@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, android-kvm@google.com,
mrigendra.chaubey@gmail.com, perlarsen@google.com,
suzuki.poulose@arm.com, vdonnefort@google.com,
yuzenghui@huawei.com
Subject: Re: [PATCH v3 1/2] firmware: arm_ffa: Fix Endpoint Memory Access Descriptor offset calculation
Date: Wed, 13 May 2026 13:34:42 +0000 [thread overview]
Message-ID: <agR98uWCHQBHuGNg@google.com> (raw)
In-Reply-To: <20260512124442.1899107-2-sebastianene@google.com>
On Tue, May 12, 2026 at 12:44:41PM +0000, Sebastian Ene wrote:
> Use the descriptor's `ep_mem_offset` to calculate the start of the endpoint
> memory access array and to comply with the FF-A spec instead of defaulting
> to `sizeof(struct ffa_mem_region)`.
> This requires moving `ffa_mem_region_additional_setup()` earlier in the setup
> flow.
> Also, add sanity checks to ensure the calculated descriptor offsets do not
> exceed `max_fragsize`.
>
> Signed-off-by: Sebastian Ene <sebastianene@google.com>
> ---
> drivers/firmware/arm_ffa/driver.c | 14 ++++++++++----
> include/linux/arm_ffa.h | 2 +-
> 2 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
> index eb2782848283..56b166290b24 100644
> --- a/drivers/firmware/arm_ffa/driver.c
> +++ b/drivers/firmware/arm_ffa/driver.c
> @@ -685,18 +685,25 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize,
> struct ffa_composite_mem_region *composite;
> struct ffa_mem_region_addr_range *constituents;
> struct ffa_mem_region_attributes *ep_mem_access;
> - u32 idx, frag_len, length, buf_sz = 0, num_entries = sg_nents(args->sg);
> + u32 idx, frag_len, length, buf_sz = 0, num_entries = sg_nents(args->sg), ep_offset;
>
> mem_region->tag = args->tag;
> mem_region->flags = args->flags;
> mem_region->sender_id = drv_info->vm_id;
> mem_region->attributes = ffa_memory_attributes_get(func_id);
> +
> + ffa_mem_region_additional_setup(drv_info->version, mem_region);
> composite_offset = ffa_mem_desc_offset(buffer, args->nattrs,
> drv_info->version);
> + if (composite_offset > max_fragsize - sizeof(struct ffa_composite_mem_region))
> + return -ENXIO;
nit: This driver seems to use sizeof() with variable name rather than
type (except for one place) so it may be good to keep that.
>
> for (idx = 0; idx < args->nattrs; idx++) {
> - ep_mem_access = buffer +
> - ffa_mem_desc_offset(buffer, idx, drv_info->version);
> + ep_offset = ffa_mem_desc_offset(buffer, idx, drv_info->version);
> + if (ep_offset > max_fragsize - sizeof(struct ffa_mem_region_attributes))
> + return -ENXIO;
> +
> + ep_mem_access = buffer + ep_offset;
> ep_mem_access->receiver = args->attrs[idx].receiver;
> ep_mem_access->attrs = args->attrs[idx].attrs;
> ep_mem_access->composite_off = composite_offset;
> @@ -708,7 +715,6 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize,
> }
> mem_region->handle = 0;
> mem_region->ep_count = args->nattrs;
> - ffa_mem_region_additional_setup(drv_info->version, mem_region);
>
> composite = buffer + composite_offset;
> composite->total_pg_cnt = ffa_get_num_pages_sg(args->sg);
> diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h
> index 81e603839c4a..62d67dae8b70 100644
> --- a/include/linux/arm_ffa.h
> +++ b/include/linux/arm_ffa.h
> @@ -445,7 +445,7 @@ ffa_mem_desc_offset(struct ffa_mem_region *buf, int count, u32 ffa_version)
> if (!FFA_MEM_REGION_HAS_EP_MEM_OFFSET(ffa_version))
> offset += offsetof(struct ffa_mem_region, ep_mem_offset);
> else
> - offset += sizeof(struct ffa_mem_region);
> + offset += buf->ep_mem_offset;
Does it make sense to also set buf->ep_mem_offset for the other
case in ffa_mem_region_additional_setup() and then add this
unconditionally here?
Thanks,
Mostafa
>
> return offset;
> }
> --
> 2.54.0.563.g4f69b47b94-goog
>
next prev parent reply other threads:[~2026-05-13 13:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 12:44 [PATCH v3 0/2] arm_ffa, KVM: Fix FF-A emad offset calculations Sebastian Ene
2026-05-12 12:44 ` [PATCH v3 1/2] firmware: arm_ffa: Fix Endpoint Memory Access Descriptor offset calculation Sebastian Ene
2026-05-13 13:34 ` Mostafa Saleh [this message]
2026-05-13 17:19 ` Sudeep Holla
2026-05-12 12:44 ` [PATCH v3 2/2] KVM: arm64: Validate the offset to the mem access descriptor Sebastian Ene
2026-05-13 13:53 ` Mostafa Saleh
2026-05-13 17:23 ` [PATCH v3 0/2] arm_ffa, KVM: Fix FF-A emad offset calculations Sudeep Holla
2026-05-18 13:45 ` Sudeep Holla
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=agR98uWCHQBHuGNg@google.com \
--to=smostafa@google.com \
--cc=android-kvm@google.com \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=korneld@google.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mrigendra.chaubey@gmail.com \
--cc=oupton@kernel.org \
--cc=perlarsen@google.com \
--cc=sebastianene@google.com \
--cc=sudeep.holla@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.