From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: kvmarm@lists.linux.dev, Oliver Upton <oupton@kernel.org>,
Marc Zyngier <maz@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Will Deacon <will@kernel.org>, Gavin Shan <gshan@redhat.com>
Subject: Re: [PATCH 1/1] firmware: arm_rmm: Delay RMM activation
Date: Thu, 3 Dec 2026 22:51:14 +0000 [thread overview]
Message-ID: <b58dd64c-58fa-47e8-b9f5-649b806e890c@arm.com> (raw)
In-Reply-To: <sashiko-outbox-248492@kernel.org>
On 03/12/2026 19:23, sashiko-bot@kernel.org wrote:
> 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.
>
Ack
> [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?
We expect the users, KVM to activate at boot. On arm64,
KVM is always builtin. The PCI TSM IDE driver, not sure if that can
be built as a module and can be used without KVM. Anyways, I can
make this safe by using something like a refcount on RMM activation
"blockers"
Suzuki
>
> 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.
>
prev parent reply other threads:[~2026-12-03 22:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:04 [PATCH 0/1] " Suzuki K Poulose
2026-12-03 19:05 ` [PATCH 1/1] " Suzuki K Poulose
[not found] ` <sashiko-outbox-248492@kernel.org>
2026-12-03 22:51 ` Suzuki K Poulose [this message]
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=b58dd64c-58fa-47e8-b9f5-649b806e890c@arm.com \
--to=suzuki.poulose@arm.com \
--cc=catalin.marinas@arm.com \
--cc=gshan@redhat.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®