From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400851; b=xvADRk+IWD31PHgEHkzo6HmiQ45yverm7i0mBDcybxcINu52xGJYJkQHOtCkz7ZVFp6W SOZZhhoDmlrESpGWiJ+jYQ3O9xS6tVqmLyQiaKwSDLfAH+JJtq/AR7p/gJPTFP3CSz1wA mEM1Xkdru1pH+jIUJxrmj/039kvGhnVJJ/gFiWjVD1TLjl9NPyPp8AhX4qgYVmfWVs5NA YApY0g1RmVm3+k5Qe+9J9Ioo0TiPuZpOAMGlFR8rCiGpj83Jwe/8HSnz2WvsZygplI0/7 xxtkrMoSznvgFpRe19Yhs1HXoHUDlhH75BizZs1PWl7v5Gl3gOdeyD9Ikh36guV0e4w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400851; h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:Content-Language:To:Cc:References: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=59Fg9iQtCj0dDjyPr1mm9m1gVc+ZeaFOqCn7VU0Oack=; b=M0mor4rlZdZRMaJGHCWv2D0JZGVOg2al0HBBY0rzjh6VZmXtLAYUEDOF1Dbm2xX0goon lYAgFCOoa693xYxfxpsOc6yF6Bk9QDTU4Jwgj2b16TtHI3yKa6bpb2EEHdI/nijlxgy/x CQrGbhDz9jEqC4tOsZzcs3LzqUZqAh6lz93wjK0ormfWObeGGfSR4QZahMqGD25AUQHqC YmqH6xQrjrRMvdG0LuZBcrGH/KB+0xqzdsZdscQQrb83xzmqlfYeQzIKcsFBt19TdPBgi NYhd4mxi7PhY+V1ZxTqXU8gaAC50UyxVKYBfWpP271C54pIaTBKclFbtBK1v2Au431A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=T3+nS59f; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28125606A32D for ; Fri, 4 Dec 2026 16:14:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 28125606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=T3+nS59f Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A9EA914BF; Fri, 4 Dec 2026 08:14:06 -0800 (PST) Received: from [10.57.33.215] (unknown [10.57.33.215]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 394283F632; Fri, 4 Dec 2026 08:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796400849; bh=up2LwmC+kbc0RMX3F9F5Mgqlr6/3U2c4eeInFvCZZ2w=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=T3+nS59fUO5/l0prg5emTj09FQy5wUdJM1zfLkREnBW847Qdn+J945jIy2oWMuKlt 7Mqj1DsvKSUyq6ci7yJkmC+czWce1Wgvhkn0z0er5UejiVM1GFCxJ7PVGYg25vk/pG Y9aPsr0kNr6jND9Cc04fPf91Rs2CYbSzx69H7HVc= Message-ID: <74a2d187-d5e2-4721-8dc5-6b529de12733@arm.com> Date: Fri, 4 Dec 2026 16:14:05 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] firmware: arm_rmm: Delay RMM activation Content-Language: en-GB To: Steven Price , 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 References: <20261203190500.429721-1-suzuki.poulose@arm.com> <20261203190500.429721-2-suzuki.poulose@arm.com> <9894b893-3911-4cb3-9ff5-3bcecca020ab@arm.com> From: Suzuki K Poulose In-Reply-To: <9894b893-3911-4cb3-9ff5-3bcecca020ab@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 04/12/2026 09:57, Steven Price wrote: > 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 >> Signed-off-by: Suzuki K Poulose >> --- >> 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. Good suggestion, I will switch to using the helpers. Cheers Suzuki > > 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, >