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=1796338287; b=cIXU8uGh1FgTYbz+oyNddGbB1nmW65Hlha1RvoJ5/IDgNXRF0qWk/VcULmZ/458pL4hJ odHNe1Cu4hyWkIiwL2QT1w/ubyAmgamJbYF95HlB/eJ/HXYYeW+CtE/yq7liLY1vAkxT7 tntEkCe1uSgmDGYpv+BQ++mka+MwJu2p2/inxkyLJUTn56kFLPzbTeONSfcoDvRTPuooV W8e1OgxnKix69tKBKuMjCxqeSjUOrKILNBJQWDS5R7wqmI+i8PkoH6axbY4EUVwHP2r7O TD2S3OsmZwpNdvM8HKEVdKR9JcVMUM28hFHmBcFRdKHZ0sbsfc3pTNNsZiZuiSirlWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796338287; 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=EMHHjxhnkjCc0c4Zqu6sQMCxHzZoGIMY5rDt4ubTSks=; b=HrUX79LyWf/OtNWhqWTLi+Xz1jJja//NXYE+sqpqA7z3jRBAdCcJQvmPt3ssbObN2kDT brcqW87R4ABhUgzvLSnUqMscXu4H9rdL8LP/UBUrH1X5xqrnrD9mNws7AZvl+SU/P8j7T B0Weh5J59npssQYbVgs0Q0GgNY9VPbIYElmeHJ0O80g9xAyfOC8JpZ0O0GGRxPDPNAft9 XGEVBiyfXIQHDL9eOPI9Z8ha+V3s/MbsFSkGNqQu4Xz06TjkSLQO7vCcfRkzlpuLgw3L4 AuPAyJ7Cox9EV3V1VvlqlIiNLJwy+uAIVNzOvheBpgm+DBspSSn/nVhgnvle37OoWHA== 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=HqPlfEvp; 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 AA737606A322 for ; Thu, 3 Dec 2026 22:51:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AA737606A322 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=HqPlfEvp 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 B27501477; Thu, 3 Dec 2026 14:51:15 -0800 (PST) Received: from [10.57.33.131] (unknown [10.57.33.131]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF7253F7D8; Thu, 3 Dec 2026 14:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796338278; bh=EhyAAXq6dB5nS+jseEPtIrjljqqU7/VT2A0QRghZVWQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=HqPlfEvpsdoV3aGMZd2vv9PvIQy83brpS59WQynT8ZRMJSxxq7yvWs/E2FF95NhcR /8wk+hd5kKClXztm9MqFwSjv/ju/zCuN6Fe0JvYM5UvRUQ7RIhFCpqJ3y7At2SGtRL 27RlHrpQqZjlvNDlh6ptAmP43LVz9c4jaLM37Vp0= Message-ID: Date: Thu, 3 Dec 2026 22:51:14 +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: sashiko-reviews@lists.linux.dev Cc: kvmarm@lists.linux.dev, Oliver Upton , Marc Zyngier , Catalin Marinas , "linux-kernel@vger.kernel.org" , Will Deacon , Gavin Shan References: <20261203190500.429721-1-suzuki.poulose@arm.com> <20261203190500.429721-2-suzuki.poulose@arm.com> From: Suzuki K Poulose In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > > 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. >