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=1796471504; b=Gpja3+UjrLfZtn9x/0dra9HVqTmw+OLp+5bRq1d+V3kAxK/hWcPQLHYan54gdh33/FBc 9IJHq2pWOwupzutF2iknXHQ6ktDgP5oDH6tUn4s6t63qqzdfMW9OnGBq5qblDfa0x+asB zUmJkxsxUZwxYUuNoHTQePeI7QEWHFCt9TqgN7GCZ7zNcXJ8K6fMEegfg5wAesO400MRi R2JVU/SQp3fTjM2Z76wWzdwTJNtOO/Hd19AXIxmQaOMX6WYihUrNPNjRFReqAp0Qdt3R5 L/dW108SD1zFneH3GIteB8X8TurRzXWWqoAaALAR21AtVq/w40HW+e+mImJdeAcFx8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796471504; 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=3a0XvYameevNc6yJX3EQ0uxBJAjxyRj5cSSWkuG9MZE=; b=lbon2ZPOoIqF0IvFvX0f6hJj+KjNsKK6/CiSClUEzWh7TX1LhSIkivE0O4n76ZJucXE9 4zU00pM1eNjg1JbLPU00+EVri573b4yKJtMKHtW7igmG3FLpwetqJT95senrR1ONpqIyx e3BQwV92c2aj57YCHH/F4iebU+KF66iRsXuk0xYri52L+4ANPVeLNWv23Czl55Gt6YOVL dfnRoLG9kkT/Vy8pIJ3h8n+KqSdmfUTRSKr1QfgFYowQ1LzjRfFB352SriZpigJocx6Cu NEXMGwyPgffglGZYDBWUFutLl1zdIbdA315EluL6zxGWBG21vqt0iv3ans4PsRqEXwA== 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=KRNviumd; 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 802A4606A32F for ; Sat, 5 Dec 2026 11:51:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 802A4606A32F 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, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=KRNviumd 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 6C93514BF; Sat, 5 Dec 2026 03:51:39 -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 5D1B23F86F; Sat, 5 Dec 2026 03:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796471502; bh=/ZBkXveTgOKsgnqnZ2h1NnLVoStqNRP9Wl0yV506Aso=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=KRNviumdCwh5LYGp7DUsUfe5ZKWesPpuh6dtARa0KNU2EDFh09Ui/6tIruVNNahRI R/KNtbKjblymrR2ajrAv+smu6PKe3zYL8iT1nN1QxSe7o58dAZnQd4IZyuJ1u8QMM5 FT7VWNOLTQxZ11tqsg3U1cbQQU3x6LpQCTgyNpqg= Message-ID: <7a6b288f-e9e8-43da-ae35-5b7f9cd7e282@arm.com> Date: Sat, 5 Dec 2026 11:51:39 +0000 X-Mailing-List: kvm@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 v6 05/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Content-Language: en-GB To: sashiko-reviews@lists.linux.dev, Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Oliver Upton , Marc Zyngier References: <20261204115725.45272-1-steven.price@arm.com> <20261204115725.45272-6-steven.price@arm.com> From: Suzuki K Poulose In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 04/12/2026 12:28, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 4 potential > issues to consider: > - [Medium] KVM: arm64: early return on undelegate error abandons private > unmap range > - [Medium] KVM: arm64: KVM_BUG_ON() warns on -ENOMEM in > realm_unmap_private_range() > - [Medium] KVM: arm64: unhandled RMI_BLOCKED in Realm RTT unmap and > create helpers > - [Low] KVM: arm64: try_topup never resets on address advance in private > unmap > -- > > commit 6a6c7236f977c112e6be13a65e7a962486113d13 > Author: Steven Price > > KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers > > This commit adds the RMI Realm Translation Table (RTT) creation and > unmapping helpers for CCA Realm stage-2 memory operations, and moves > rmi_addr_block_size_to_bytes() into include/linux/arm-rmi-cmds.h. > >> diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c >> index 6a8bff1d8d467..ee16f5364b9aa 100644 >> --- a/arch/arm64/kvm/rmi.c >> +++ b/arch/arm64/kvm/rmi.c >> @@ -16,6 +16,337 @@ u32 kvm_rmm_ipa_limit(void) > > [ ... ] > >> +static void realm_unmap_shared_range(struct kvm *kvm, >> + unsigned long start, >> + unsigned long end, >> + bool may_block, >> + struct kvm_mmu_memory_cache *mc) >> +{ > > [ ... ] > >> + ret = rmi_rtt_unprot_unmap(rd, addr, end, RMI_ADDR_TYPE_NONE, >> + 0, &next_addr, NULL, NULL); >> + if (WARN_ON(ret < 0)) >> + return; >> + >> + switch (RMI_RESULT_STATUS(ret)) { > > [ ... ] > >> + default: >> + WARN_ON(1); >> + return; >> + } > > [Severity: Medium] > Can an RMI_BLOCKED return from rmi_rtt_unprot_unmap() abort shared > unmapping mid-range? > > rmi_smccc_invoke() only retries RMI_BLOCKED twice before returning it > for the caller to handle. Hitting default here returns early from a > void invalidation callback, so callers such as MMU notifiers or > kvm_gmem_punch_hole() can reclaim or free host pages while the Realm > still has live unprotected stage-2 mappings to them (use-after-free). > > realm_unmap_private_range() has the same early return on RMI_BLOCKED, > leaving still-mapped, still-delegated granules to be freed back to the > host allocator. realm_create_rtt_levels() also warns and turns > RMI_BLOCKED into -ENXIO instead of retrying or returning -EAGAIN, > which triggers KVM_BUG_ON() in realm_unmap_private_range(). We serialize the unmap requests using the write_lock, we so don't end up in RMI_BLOCKED with another thread draining the TLBs. > > [ ... ] > >> +static void realm_unmap_private_range(struct kvm *kvm, >> + unsigned long start, >> + unsigned long end, >> + bool may_block, >> + struct kvm_mmu_memory_cache *mc) >> +{ >> + struct realm *realm = &kvm->arch.realm; >> + unsigned long rd = realm->rd_phys; >> + unsigned long next_addr, addr; >> + bool try_topup = may_block; >> + long ret; >> + >> + for (addr = start; addr < end; addr = next_addr) { >> + unsigned long out_range; >> + unsigned long flags = RMI_ADDR_TYPE_SINGLE; >> + /* TODO: Optimise using RMI_ADDR_TYPE_LIST */ >> + >> + ret = rmi_rtt_data_unmap(rd, addr, end, flags, 0, >> + &next_addr, &out_range, NULL); >> + if (WARN_ON(ret < 0)) >> + return; >> + >> + switch (RMI_RESULT_STATUS(ret)) { >> + case RMI_SUCCESS: >> + ret = undelegate_range_desc(out_range); >> + if (WARN_ON(ret)) >> + return; >> + break; > > [Severity: Medium] > Does returning here on an undelegate_range_desc() failure abandon > unmapping and undelegating [next_addr, end)? > > Because kvm_realm_unmap_range_filter() returns void, callers such as > kvm_gmem_punch_hole() still truncate and free the remaining backing > pages back to the host allocator. Leaving [next_addr, end) mapped in > a runnable Realm and still delegated risks guest use-after-free and > host Granule Protection Faults. Sure, I think we could try to complete the range. But failure to undelegate a set of pages we got from the RMM would still bite us back. > > Continuing the loop after WARN_ON(ret) would leak only the failed > range (as rmi_sro_free() does) while still unmapping the rest. The > other early returns in realm_unmap_private_range() also exit without > marking the VM bugged via KVM_BUG_ON(1, kvm). > > [ ... ] > >> + if (try_topup) { >> + bool lock_dropped; >> + >> + if (realm_unmap_cache_topup(kvm, mc, >> + level - err_level, >> + &lock_dropped)) >> + try_topup = false; >> + if (lock_dropped) { >> + /* Retry the RTT walk with mmu_lock held. */ >> + next_addr = addr; >> + break; >> + } >> + } > > [Severity: Low] > Should try_topup be reset to may_block whenever addr advances? > > Once realm_unmap_cache_topup() fails for one address, try_topup stays > false for the rest of the range. If the loop moves on (for instance > after a concurrent split/unmap while mmu_lock was dropped, or via the > atomic fallback), later splits in the same call skip sleepable topups > and rely only on GFP_ATOMIC, making a failed split and KVM_BUG_ON() > more likely. > >> + >> + ret = realm_create_rtt_levels(realm, addr, err_level, >> + level, mc); >> + if (!ret) { >> + next_addr = addr; >> + break; >> + } >> + >> + /* A failed split cannot leave the backing pages mapped. */ >> + KVM_BUG_ON(1, kvm); > > [Severity: Medium] > Can this KVM_BUG_ON(1, kvm) trigger a host WARN_ON_ONCE() on -ENOMEM? > > When realm_create_rtt_levels() fails with -ENOMEM (from a GFP_ATOMIC > allocation failure or rmi_delegate_page() failure in > alloc_delegated_granule()), KVM_BUG_ON() emits a WARN_ON_ONCE(), > tainting the kernel and panicking hosts with panic_on_warn=1 on an > out-of-memory condition rather than a kernel bug. > > Unlike realm_unmap_shared_range(), which uses WARN_ON(ret != -ENOMEM), > this warns unconditionally. Using kvm_vm_dead(kvm) on -ENOMEM and > reserving KVM_BUG_ON() for ret != -ENOMEM would still kill the VM > without firing a warning on allocation failure. Yes, this is critical, because for private ranges we can't leave things mapped and that is in turn creating issues in the host, as the pages are delegated. So, KVM_BUG_ON() is justified, unlike the shared range Suzuki >