mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Price <steven.price@arm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>,
	linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com,
	will@kernel.org, sudeep.holla@arm.com, maz@kernel.org,
	aneesh.kumar@kernel.org, gshan@redhat.com,
	jonathan.cameron@oss.qualcomm.com, kvmarm@lists.linux.dev,
	oupton@kernel.org, linux-coco@lists.linux.dev,
	alpergun@google.com, sdonthineni@nvidia.com,
	lpieralisi@kernel.org
Subject: Re: [PATCH 1/1] firmware: arm_rmm: Delay RMM activation
Date: Fri, 4 Dec 2026 09:57:10 +0000	[thread overview]
Message-ID: <9894b893-3911-4cb3-9ff5-3bcecca020ab@arm.com> (raw)
In-Reply-To: <20261203190500.429721-2-suzuki.poulose@arm.com>

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@arm.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  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,


  parent reply	other threads:[~2026-12-04  9:57 UTC|newest]

Thread overview: 6+ 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
2026-12-04  9:57   ` Steven Price [this message]
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=9894b893-3911-4cb3-9ff5-3bcecca020ab@arm.com \
    --to=steven.price@arm.com \
    --cc=alpergun@google.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=gshan@redhat.com \
    --cc=jonathan.cameron@oss.qualcomm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sdonthineni@nvidia.com \
    --cc=sudeep.holla@arm.com \
    --cc=suzuki.poulose@arm.com \
    --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®