From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 5/8] firmware: arm_ffa: Introduce ffa-lend-pool
Date: Mon, 21 Sep 2026 11:48:38 +0000 [thread overview]
Message-ID: <20260921114838.B71891F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260921110050.3977591-6-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [Critical] arm64: flush_dcache_page() misuse causes potential SError
- [High] pm: ffa_lend_pool_active state corruption on aborted hibernation
- [High] cma: TOCTOU data race on dev->cma_area leading to NULL pointer dereference
- [High] pm: missing PM notifier registration bypasses hibernation prevention
- [High] cma: unconditional clearing of dev->cma_area clobbers unrelated CMA areas
- [Medium] pm: double registration of PM notifier for multiple DT nodes
--
commit 89717031e5424e454476d23e222a943cd21c32da
Author: Vincent Donnefort <vdonnefort@google.com>
firmware: arm_ffa: Introduce ffa-lend-pool
This commit introduces the arm,ffa-lend-pool reserved-memory CMA driver to
unmap pages from the kernel direct map before lending them to the Secure
world via FF-A. Devices can bind to this pool via the "memory-region" DT
property or the ffa_lend_pool_attach() function.
> diff --git a/drivers/firmware/arm_ffa/lend_pool.c b/drivers/firmware/arm_ffa/lend_pool.c
> new file mode 100644
> index 0000000000000..e4348f5c618b8
> --- /dev/null
> +++ b/drivers/firmware/arm_ffa/lend_pool.c
[ ... ]
> +static bool ffa_lend_pool_can_set_direct_map(struct device *dev, struct page *page, u64 nr_pages)
> +{
[ ... ]
> + addr = page_to_phys(page);
> + size = nr_pages << PAGE_SHIFT;
> + base = cma_get_base(dev->cma_area);
> + end = base + cma_get_size(dev->cma_area);
[Severity: High]
Can this result in a NULL pointer dereference? The compiler might reload
dev->cma_area from memory after cma_get_base() returns since it involves
an external function call. If a concurrent device detach sets dev->cma_area
to NULL at this exact moment, cma_get_size() would dereference it.
[ ... ]
> +int ffa_prepare_lend(struct device *dev, struct page *page, u64 nr_pages)
> +{
> + struct page *p, *end;
> + unsigned long addr;
> + int ret;
> +
> + if (!ffa_lend_pool_can_set_direct_map(dev, page, nr_pages))
> + return -ENODEV;
[Severity: High]
If a device doesn't have an arm,ffa-lend-pool DT node, can_set_direct_map()
can still return true here, allowing memory to be successfully lent and
unmapped. However, since the PM notifier is only registered during the CMA
pool DT node setup, hibernation wouldn't be prevented. Could this lead to a
translation fault if hibernation is attempted while memory is lent?
> +
> + /* provides full ordering */
> + if (!atomic_add_unless(&ffa_lend_pool_active, 1, FFA_LEND_POOL_DISABLED))
> + return -EBUSY;
> +
> + end = page + nr_pages;
> + for (p = page; p < end; p++)
> + flush_dcache_page(p);
[Severity: Critical]
Does flush_dcache_page() provide sufficient hardware cache maintenance here?
On ARM64, this API only clears the PG_dcache_clean bit and doesn't perform
hardware cache eviction (like DC CIVAC) for the direct map. If dirty
Non-Secure lines are evicted to the now-Secure memory region, could this
trigger an asynchronous SError panic?
[ ... ]
> +static int ffa_lend_pool_pm_notify(struct notifier_block *nb, unsigned long mode, void *data)
> +{
> + /* Prevent hibernation which would try to access lent memory */
> + switch (mode) {
> + case PM_HIBERNATION_PREPARE:
> + if (atomic_cmpxchg_acquire(&ffa_lend_pool_active, 0, FFA_LEND_POOL_DISABLED))
> + return notifier_from_errno(-EBUSY);
> + break;
> + case PM_POST_HIBERNATION:
> + atomic_set(&ffa_lend_pool_active, 0);
[Severity: High]
If hibernation preparation is rejected because memory is already lent, the
PM core broadcasts PM_POST_HIBERNATION. Will unconditionally zeroing the
active counter here lose the state of currently lent pages? If so, when
the memory is later reclaimed, the counter would underflow to
FFA_LEND_POOL_DISABLED and permanently block future lends.
[ ... ]
> +static int __init ffa_lend_pool_setup(unsigned long node, struct reserved_mem *rmem)
> +{
[ ... ]
> + register_pm_notifier(&ffa_lend_pool_pm_nb);
[Severity: Medium]
If the device tree contains multiple arm,ffa-lend-pool nodes,
ffa_lend_pool_setup() will execute for each. Could this register the same
global static ffa_lend_pool_pm_nb notifier block multiple times and trigger
a WARN stack trace?
[ ... ]
> +static void ffa_lend_pool_device_release(struct reserved_mem *rmem, struct device *dev)
> +{
> + xa_erase(&ffa_lend_pool_devices, (unsigned long)dev);
> + dev->cma_area = NULL;
[Severity: High]
If a driver calls ffa_lend_pool_detach() on a device that failed to attach
(for instance, if ffa_lend_pool_attach() returned -ENODEV), this
unconditionally zeroes dev->cma_area. Could this clobber the device's
legitimate DMA CMA area?
Additionally, this clearing occurs concurrently with the cma_get_size()
call in ffa_lend_pool_can_set_direct_map() without synchronization, which
opens the TOCTOU race mentioned earlier.
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260921110050.3977591-1-vdonnefort@google.com?part=5
next prev parent reply other threads:[~2026-09-21 11:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 11:00 [PATCH v2 0/8] arm64: Unmap FF-A lent memory from direct map Vincent Donnefort
2026-09-21 11:00 ` [PATCH v2 1/8] memblock: Introduce MEMBLOCK_PTEMAP Vincent Donnefort
2026-09-21 11:00 ` [PATCH v2 2/8] arm64: Introduce can_set_direct_map_range() Vincent Donnefort
2026-09-21 11:00 ` [PATCH v2 3/8] arm64: Introduce __set_direct_map*() Vincent Donnefort
2026-09-21 11:00 ` [PATCH v2 4/8] arm64: Add support for MEMBLOCK_PTEMAP Vincent Donnefort
2026-09-21 11:00 ` [PATCH v2 5/8] firmware: arm_ffa: Introduce ffa-lend-pool Vincent Donnefort
2026-09-21 11:48 ` sashiko-bot [this message]
2026-09-21 11:00 ` [PATCH v2 6/8] optee: Add support for arm,ffa-lend-pool Vincent Donnefort
2026-09-21 12:04 ` sashiko-bot
2026-09-21 11:00 ` [PATCH v2 7/8] dt-bindings: reserved-memory: Add Arm FF-A lend pool Vincent Donnefort
2026-09-21 15:20 ` Rob Herring (Arm)
2026-09-21 11:00 ` [PATCH v2 8/8] dt-bindings: firmware: optee: Add memory-region property Vincent Donnefort
2026-09-22 5:57 ` [PATCH v2 0/8] arm64: Unmap FF-A lent memory from direct map Sumit Garg
2026-09-22 10:57 ` Thierry Reding
2026-09-22 14:55 ` Will Deacon
2026-09-26 12:13 ` Sumit Garg
2026-09-29 11:33 ` Will Deacon
2026-10-01 12:34 ` Sumit Garg
2026-10-05 10:48 ` Vincent Donnefort
2026-10-05 11:02 ` Vincent Donnefort
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=20260921114838.B71891F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vdonnefort@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox