From: sashiko-bot@kernel.org
To: "Suzuki K Poulose" <suzuki.poulose@arm.com>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH 1/1] firmware: arm_rmm: Delay RMM activation
Date: Thu, 03 Dec 2026 19:23:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-248492@kernel.org> (raw)
In-Reply-To: <20261203190500.429721-2-suzuki.poulose@arm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] firmware: arm_rmm: rmm_activate() bypasses kexec and kdump RMM
guard
- [High] firmware: arm_rmm: rmm_activate() races with hibernation and
/dev/snapshot
- [Medium] firmware: arm_rmm: rmi_init_memory() lacks mem_hotplug_lock
at runtime
- [Medium] firmware: arm_rmm: rmi_init_metadata() fails on hotplugged
movable/offline RAM
--
commit 3e173959956ecb18d9c76645df94a185af047180
Author: Suzuki K Poulose <suzuki.poulose@arm.com>
firmware: arm_rmm: Delay RMM activation
This commit delays RMM activation from subsys_initcall(arm64_init_rmi) to
an on-demand rmm_activate() call serialized by rmm_mutex, leaving boot-time
initialization to version negotiation, feature reading, and configuration.
> diff --git a/drivers/firmware/arm_rmm/rmi.c b/drivers/firmware/arm_rmm/rmi.c
> index 77255a90e0a65..8e53d4ff9ade7 100644
> --- a/drivers/firmware/arm_rmm/rmi.c
> +++ b/drivers/firmware/arm_rmm/rmi.c
[ ... ]
> @@ -1081,23 +1084,10 @@ static int rmi_init_memory(void)
> return register_memory_notifier(&rmi_memory_nb);
> }
>
> -static int __init arm64_init_rmi(void)
> +static int rmm_do_activate(void)
> {
> int ret;
>
> - /* If we can't agree on the RMI ABI version, don't proceed further */
> - ret = rmi_check_version();
> - if (ret)
> - return ret;
> -
> - ret = rmi_read_features();
> - if (ret)
> - return ret;
> -
> - ret = rmi_configure();
> - if (ret)
> - return ret;
> -
> /* Activate the RMM */
> struct rmi_sro_state *sro __free(kfree) = kmalloc_obj(*sro);
> if (!sro)
[Severity: Medium]
Can rmi_init_memory() race with memory hotplug now that rmm_do_activate()
runs it at runtime?
On arm64 (CONFIG_ARCH_KEEP_MEMBLOCK=y), __add_memory_resource() updates
memblock.memory under mem_hotplug_lock, while rmi_init_metadata() walks it
with for_each_mem_region() without holding get_online_mems():
CPU0 CPU1
rmm_do_activate()
rmi_init_memory()
rmi_init_metadata()
for_each_mem_region(r)
rmi_prepare_memory(...)
__add_memory_resource()
mem_hotplug_begin()
memblock_add_node(...)
memblock_double_array()
kfree(old_array)
r++ / dereference r <-- use-after-free
Because for_each_mem_region() also re-reads memblock.memory.regions on
each iteration, comparing the old pointer against the new array bounds
results in an out-of-bounds walk.
Separately, memory hot-added and onlined via online_pages() between
rmi_init_metadata() and register_memory_notifier(&rmi_memory_nb) misses
MEM_GOING_ONLINE and bypasses rmi_prepare_memory(). Holding
get_online_mems() / put_online_mems() across both calls in
rmi_init_memory() would close both races.
[Severity: Medium]
Does running rmi_init_metadata() at runtime regress systems with memory
hot-added before rmm_activate() is called?
On arm64, __add_memory_resource() inserts hotplugged and driver-managed
memory (such as CXL or DAX kmem) into memblock.memory even when it stays
offline or is onlined into ZONE_MOVABLE. Commit 06898e5320b5 ("firmware:
arm_rmm: hotplug: Skip memory added to ZONE_MOVABLE") exempted
ZONE_MOVABLE ranges in rmi_memory_notifier(), but rmi_init_metadata()
only skips memblock_is_nomap(r) and calls rmi_prepare_memory() on every
other memblock.memory region.
If any pre-activation offline or ZONE_MOVABLE region lacks RMM fine
granule tracking or firmware-managed L1 GPTs, rmi_prepare_memory() fails
and rmm_activate() clears rmm_ready_for_activation, permanently disabling
RMM for the rest of the boot.
> @@ -1123,6 +1113,54 @@ static int __init arm64_init_rmi(void)
> /* Mark the RMM is usable */
> WRITE_ONCE(arm64_rmi_is_available, true);
> pr_info("RMI configured\n");
> + return 0;
> +}
> +
> +
> +/*
> + * rmm_activate - Activate the RMM if it is usable.
> + *
> + * Returns 0 on success. i.e., when the RMM has been activated (or is already
> + * ACTIVE).
> + */
> +int rmm_activate(void)
> +{
> + int ret;
> +
> + guard(mutex)(&rmm_mutex);
> +
> + if (!READ_ONCE(rmm_ready_for_activation))
> + return -ENXIO;
> + if (READ_ONCE(arm64_rmi_is_available))
> + return 0;
> + if (READ_ONCE(arm64_rmm_active))
> + return -ENXIO;
> + ret = rmm_do_activate();
> + if (ret)
> + rmm_ready_for_activation = false;
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(rmm_activate);
[Severity: High]
Can rmm_activate() bypass the kexec and kdump guard when an image is
preloaded before RMM activation?
Commit fe4a24613bc2 ("arm64: Block hibernate and kexec while RMM is
active") only checks is_rmm_active() in machine_kexec_prepare() at image
load time. With activation delayed past boot, kdump.service (or kexec -l)
can load kexec_crash_image or kexec_image while arm64_rmm_active is still
false. Because rmm_activate() neither synchronizes with kexec_trylock()
nor checks for loaded images, and kernel_kexec() / __crash_kexec() /
machine_kexec() never re-check is_rmm_active(), entering the preloaded
kernel with active RMM and delegated Realm PAS pages will cause fatal
Granule Protection Faults.
There is also a concurrent race between unlocked is_rmm_active() in
machine_kexec_prepare() and rmm_do_activate(), which donates granules in
SMC_RMI_RMM_ACTIVATE before setting arm64_rmm_active to true.
[Severity: High]
Does rmm_activate() race with hibernation and /dev/snapshot now that
arm64_rmm_active can transition to true at runtime?
arch_hibernation_available() returns !is_rmm_active(), but hibernate()
checks hibernation_available() once before lock_system_sleep(),
pm_sleep_fs_sync(), and freeze_processes(), and never re-checks it before
hibernation_snapshot():
CPU0 CPU1
hibernate()
hibernation_available() -> true
lock_system_sleep()
pm_sleep_fs_sync()
rmm_activate()
SMC_RMI_RMM_ACTIVATE
arm64_rmm_active = true
hibernation_snapshot() <-- fatal GPF on Realm PAS pages
Similarly, snapshot_open() checks hibernation_available() only when
/dev/snapshot is opened, so a subsequent SNAPSHOT_CREATE_IMAGE or
SNAPSHOT_ATOMIC_RESTORE ioctl proceeds after rmm_activate() has already
donated or delegated pages. Synchronizing rmm_activate() with
lock_system_sleep() / hibernation_in_progress() (or a PM notifier for
PM_HIBERNATION_PREPARE and PM_RESTORE_PREPARE) would prevent RMM
activation from overlapping hibernation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203190500.429721-1-suzuki.poulose@arm.com?part=1
next prev parent reply other threads:[~2026-12-03 19:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:04 [PATCH 0/1] firmware: arm_rmm: Delay RMM activation Suzuki K Poulose
2026-12-03 19:05 ` [PATCH 1/1] " Suzuki K Poulose
2026-12-03 19:23 ` sashiko-bot [this message]
2026-12-03 22:51 ` Suzuki K Poulose
2026-12-04 9:57 ` Steven Price
2026-12-04 11:25 ` Kohei Enju
2026-12-04 16:14 ` Suzuki K Poulose
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=sashiko-outbox-248492@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=suzuki.poulose@arm.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.