Re: [PATCH 1/1] firmware: arm_rmm: Delay RMM activation
From: Steven Price
Date: Fri Dec 04 2026 - 04:57:22 EST
On 03/12/2026 19:05, Suzuki K Poulose wrote:
> Right now, we configure and activate the RMM at boot. This is not ideal
> if there are no users for it (e.g, KVM is not enabled in CCA mode with
> kvm-arm.mode=rmm). This disables useful features, like kexec reboot and
> hibernation. Delay the RMM activation and leave it to a user (KVM or
> PCI TSM which may use RMM as the TSM for IDE setup). Use an rmm_mutex
> to serialize the activation requests.
>
> Suggested-by: Catalin Marinas <catalin.marinas@xxxxxxx>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
> ---
> drivers/firmware/arm_rmm/rmi.c | 68 ++++++++++++++++++++++++++--------
> include/linux/arm-rmi-cmds.h | 1 +
> 2 files changed, 54 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/firmware/arm_rmm/rmi.c b/drivers/firmware/arm_rmm/rmi.c
> index 77255a90e0a6..8e53d4ff9ade 100644
> --- a/drivers/firmware/arm_rmm/rmi.c
> +++ b/drivers/firmware/arm_rmm/rmi.c
> @@ -15,9 +15,12 @@
>
> /* RMM v2.0 defines RmiFeatureRegister0 to RmiFeatureRegister4. */
> static unsigned long rmi_feat_reg_cache[5] __ro_after_init;
> +static bool rmm_ready_for_activation;
> static bool arm64_rmm_active;
> static bool arm64_rmi_is_available;
>
> +static DEFINE_MUTEX(rmm_mutex);
> +
> /* is_rmm_active: Returns if the RMM is ACTIVE */
> bool is_rmm_active(void)
> {
> @@ -804,7 +807,7 @@ static int rmi_rmm_config_set(unsigned long cfg_ptr)
> return regs.a0;
> }
>
> -static int rmi_configure(void)
> +static int __init rmi_configure(void)
> {
> unsigned long granule_feature;
> unsigned long granule_size;
> @@ -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)
> @@ -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;
Since we've now got the rmm_mutex, why do we need these READ_ONCE() calls?
* rmm_ready_for_activation is used only in this function and
arm64_init_rmi() both of which hold rmm_mutex. The write also doesn't
use WRITE_ONCE() which makes this look extra dodgy.
* The other two have some minor justification because we have the
functions is_rmm_active()/is_rmi_available() which use READ_ONCE() and
hence pair with WRITE_ONCE() when setting. Although AFAICT those
WRITE_ONCE() calls are protected by rmm_mutex (they are set in the
rmm_do_active() call below), so there's no actual need for the
READ_ONCE() here. My preference would be to switch to the helpers rather
than encode the READ_ONCE here.
Thanks,
Steve
> + ret = rmm_do_activate();
> + if (ret)
> + rmm_ready_for_activation = false;
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(rmm_activate);
> +
> +static int __init arm64_init_rmi(void)
> +{
> + int ret;
> +
> + guard(mutex)(&rmm_mutex);
> + /* 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;
> +
> + rmm_ready_for_activation = true;
>
> return 0;
> }
> diff --git a/include/linux/arm-rmi-cmds.h b/include/linux/arm-rmi-cmds.h
> index a84e50ac851c..1aa3a293af11 100644
> --- a/include/linux/arm-rmi-cmds.h
> +++ b/include/linux/arm-rmi-cmds.h
> @@ -65,6 +65,7 @@ static __always_inline void rmi_smccc_invoke_once(struct arm_smccc_1_2_regs *reg
> arm_smccc_1_2_smc(regs, regs);
> }
>
> +int rmm_activate(void);
> unsigned long rmi_feat_reg(unsigned int index);
>
> int rmi_delegate_range(phys_addr_t phys, unsigned long size,