From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325815; b=5pNGeB1aMehivXg+P0pH0TFhmmJfGvNThDiE9UCA9d7X7iAiIIrMC48Aautnmo6sPGy1 SJcuw5/We4T1FkY+xH1f0QAbMT5g91AM9l3PK6YcYVD73AY02dKhZDWhErjHJ+ZWVzBHf JjPSljDswy7ubRNCz21Q07PODG7qhvg5CCIaPtEEvPY4nBz9URkXConXl2siNQoZ5E5Yq pVZ9OL5oXahYuk6+3C4RsrzdFRiUwUJx5JLepjapfYEjCoRHTocQwq9P7Yvv7NiqP2Mrd iwBcHzuK5f8xGyCTZZtyzewHTHK87hYR9qt1xR89It+zdmp3d0oiCpt6sk2kseSIUmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325815; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=b6Dgwa2Ye/UMElWdlStmFHH8YqJd5pLDCEXJpH6hdT4=; b=ZH0wshQO3b0kBdPFgsWBurvcmv1FZdQpcw5eKU2T3ssvP0HoAYJkMDW05x/Te4NaaUYc t5eWfP5fRCJMzMc5Rroy9xxeWwrg+O7qbOloa7LK3IencMzg+EHJX21dPR8N8WyKO3xFh Vxvv34vfNTIUqh7YBYXVK3bB1rEKOqow8zd4PqK/byD2ipXz6DTtX7EVEnXvfRa2KkSiV Vsc2UQ/x+r7mOFzKIBuybPcMNqMP/dBmCm7oRhieOYGP091uG7iKOL4t5GwGm1l4Zh8uc q9TIIwSIt6e7pTPEtnzeG8rml8KMqRPP8EDHR6kgiMJd3R3A/FB1c1M5DKUTmntgS5Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="BylSqcT/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C794C606A697 for ; Thu, 3 Dec 2026 19:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BylSqcT/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 414051F000C2; Thu, 3 Dec 2026 19:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796325815; bh=b6Dgwa2Ye/UMElWdlStmFHH8YqJd5pLDCEXJpH6hdT4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BylSqcT/aOy3eOxN/1wLWxRYRcnhoNVZbjKLqaO5x/nfk37up6Ha3gldmuyjOYBG0 PX77kR16GU1Li8OIIwCOZBiy+u0SBfVHf934BTmIMD9vNYB7NnzmaHwHJ5uzVyzvut ouKnLHoRiPTEloUZfikd8ASPmkiFJOrRlzi79xuRGLEgRnS0CsCf5RByR0sVIhAzPK UO6AJQe/Wq9lMUtrbMceMRJVKeBjFlz2plH2LB863SxNbdK5zorgEuySKuE4dZOqnS nlMatBbBIo0+nmqMniBeF3TGLJn8n07v+H3G7ptd6QrB/HqLc++2CKiZsV8Z9OVM26 EEqL9HN06LWUg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/1] firmware: arm_rmm: Delay RMM activation Reply-To: sashiko-reviews@lists.linux.dev To: "Suzuki K Poulose" Cc: kvmarm@lists.linux.dev, "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261203190500.429721-2-suzuki.poulose@arm.com> References: <20261203190500.429721-1-suzuki.poulose@arm.com> <20261203190500.429721-2-suzuki.poulose@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 19:23:34 +0000 X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/rm= i.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); > } > =20 > -static int __init arm64_init_rmi(void) > +static int rmm_do_activate(void) > { > int ret; > =20 > - /* If we can't agree on the RMI ABI version, don't proceed further */ > - ret =3D rmi_check_version(); > - if (ret) > - return ret; > - > - ret =3D rmi_read_features(); > - if (ret) > - return ret; > - > - ret =3D rmi_configure(); > - if (ret) > - return ret; > - > /* Activate the RMM */ > struct rmi_sro_state *sro __free(kfree) =3D 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=3Dy), __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 al= ready > + * 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 =3D rmm_do_activate(); > + if (ret) > + rmm_ready_for_activation =3D 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203190500.4297= 21-1-suzuki.poulose@arm.com?part=3D1