From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65DFC4AE138 for ; Tue, 15 Sep 2026 15:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487009; cv=none; b=USjYd7mT9GSP5P6VtF3BsEH3tqyW3skVlx1DP71HigOHufEQeeZL+g9pGlRrY8MNGox4d7X9FPZYqp7iifEr8gS/1GoL/cTk+j1ssvT/XDGf5Xq3icXVIr/797U9OKt7Yyx5J8EaSBOiIy6jjIWDqRFIME6P1Ab+J9AXCKv+Ixs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487009; c=relaxed/simple; bh=bZH0Iynr6p+MO32RA+61Q08tGhF1f84xWPwOzk0oSQg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XiJCUcGZSEJnIE8QNDkauUsyCXUBazt5qyrny9DoTd3+H7AbeKnw3cZNz51kWzbslwYXZ6x6pKWvtWGo3Zn04Wp/ri3hmlbSHkSH8QXmdGxJ1yi4kzr1dVCN1c6XbIMZudFtVPflZxjjaTU321iMg6fU1Rc1jrOwPAdrzzwZZXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=a9zfF35p; arc=none smtp.client-ip=217.140.110.172 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.b="a9zfF35p" 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 0754F15A1; Tue, 15 Sep 2026 08:43:22 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0DE353F882; Tue, 15 Sep 2026 08:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487005; bh=bZH0Iynr6p+MO32RA+61Q08tGhF1f84xWPwOzk0oSQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a9zfF35ptiQKPV6uAEtV4LGz/dwzssa8UXO1LXm+fFsAt50zgS1WS0p9R9WtTP0mv ILZKF6wXaHJ4ubXDjbEBeJ2jpQbWYpqbllmxP7vXTiGTrU7rzgOAUfAlOXmt/UDVyS enKUPDKPdh86GkKeqeortrsS7pg0S6hVelAx8/yA= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 1/7] KVM: arm64: Use a variable for the canonical IPA in kvm_s2_fault_map() Date: Tue, 15 Sep 2026 16:42:59 +0100 Message-ID: <20260915154305.3852871-2-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create a variable to store the canonical IPA, instead of calculating it when needed. This will be useful when we need to use the canonical IPA for guest stage-2 tracking later. Signed-off-by: Wei-Lin Chang Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue --- arch/arm64/kvm/mmu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 9ba86450fe4a..671e2941d619 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2021,6 +2021,7 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault= _desc *s2fd, enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_SHARED; bool writable =3D prot & KVM_PGTABLE_PROT_W; struct kvm *kvm =3D s2fd->vcpu->kvm; + phys_addr_t canonical_ipa; struct kvm_pgtable *pgt; long perm_fault_granule; long mapping_size; @@ -2039,6 +2040,7 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault= _desc *s2fd, mapping_size =3D s2vi->vma_pagesize; pfn =3D s2vi->pfn; gfn =3D s2vi->gfn; + canonical_ipa =3D gfn_to_gpa(get_canonical_gfn(s2fd, s2vi)); =20 /* * If we are not forced to use page mapping, check if we are @@ -2057,6 +2059,7 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault= _desc *s2fd, goto out_unlock; } } + canonical_ipa =3D ALIGN_DOWN(canonical_ipa, mapping_size); } =20 if (!perm_fault_granule && !s2vi->map_non_cacheable && kvm_has_mte(kvm)) @@ -2090,11 +2093,9 @@ static int kvm_s2_fault_map(const struct kvm_s2_faul= t_desc *s2fd, * making sure we adjust the canonical IPA if the mapping size has * been updated (via a THP upgrade, for example). */ - if (writable && !ret) { - phys_addr_t ipa =3D gfn_to_gpa(get_canonical_gfn(s2fd, s2vi)); - ipa &=3D ~(mapping_size - 1); - mark_page_dirty_in_slot(kvm, s2fd->memslot, gpa_to_gfn(ipa)); - } + if (writable && !ret) + mark_page_dirty_in_slot(kvm, s2fd->memslot, + gpa_to_gfn(canonical_ipa)); =20 if (ret !=3D -EAGAIN) return ret; --=20 2.43.0 From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AEC64A8A12 for ; Tue, 15 Sep 2026 15:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487015; cv=none; b=V0MKocrxQ/TtH/lKjGSbnWG1f/dPm97pFI0pNOY5k7hqAsxGsYALziOD+sUW+xBtBkJhXs3lNfPBFQ9XeGu7QoFTgpseZa5WaIripMX3JwHwbDkhXAXRngk2Gatf9OllDCLo/rnmygEuqTX/nHazVOuyvtw+c8dePZrJWzk0nK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487015; c=relaxed/simple; bh=eZi0YOrnOLSovTu30sPts42LqDHKJiClC5gUuLSflSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5rWUI4jHFpHyVc+dyAcR4WJFJRJSjS+YwmJLO+GwTxMtfurqCXOkdzWpD0W9lfj2NVsXH3C9rt/Nyd5iv1mVgvUQfIH0BxvXSyX2+ZL64mot+mIFftSyp/HC8w2sTiQIGeBKKp/UjbaOGJH8fLj7lGLbja7hgAbBVTakjAkEUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=HTmx64G9; arc=none smtp.client-ip=217.140.110.172 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.b="HTmx64G9" 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 E88A8169E; Tue, 15 Sep 2026 08:43:24 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EB8B73F882; Tue, 15 Sep 2026 08:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487008; bh=eZi0YOrnOLSovTu30sPts42LqDHKJiClC5gUuLSflSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTmx64G9LOeaRQY06AYRfv2R9UcGo7zFxMq21gHcUf+6r9pEwBDPHJW0uGwC/2f6t aiR/3AhQeu3xbxabtRQSt457EnzjWt0jFzaPF3fboYdMOR4Il9+rQE6bkNL798KR5A sbvHwAjIe9ezOBTK4X+K//kIJkzbNi4nXapUk98M= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 2/7] KVM: arm64: nv: Introduce guest stage-2 tracking structures Date: Tue, 15 Sep 2026 16:43:00 +0100 Message-ID: <20260915154305.3852871-3-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to avoid unmapping all shadow stage-2 mappings when KVM receives a MMU notifier unmap call, we have to keep track of the canonical IPA -> nested IPA relationship of the shadow mappings created. This essentially means tracking the guest's stage-2. To do this, represent each mapping by struct kvm_guest_s2_mapping. It stores the mapping's canonical IPA range and the nested IPA range using two interval tree nodes. Both nodes will be inserted into their respective interval trees called guest_s2_mappings. The canonical IPA ranges will be stored in the tree within the canonical MMU, and the nested IPA ranges will be stored in the corresponding nested MMU's tree. For example: struct kvm_guest_s2_mapping mapping1, mapping2; ---------------------> mapping2.canonical | mapping1.canonical | ^ (both stored in canonical mmu's tree) | | --*****-----------------------*****----------- CIPA \\\\\ ||||| mapping1.nested_mmu \\\\\ \\\\\ | \\\\\ \\\\\ v Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue ------\\\\\---------------------*****--------- NIPA #1 (nested mmu #1) \\\\\ | \\\\\ -> mapping1.nested \\\\\ (stored in nested mmu #1's tree) \\\\\ -----------*****------------------------------ NIPA #2 (nested mmu #2) | ^ -> mapping2.nested | (stored in nested mmu #2's tree) mapping2.nested_mmu Using the trees we can look up nodes in either of the IPA spaces, and for each node, find the corresponding range in the other IPA space from the other node in the enclosing kvm_guest_s2_mapping. Define kvm_guest_s2_mapping and the interval tree here. Guest stage-2 mapping tracking will come in subsequent patches. Signed-off-by: Wei-Lin Chang --- arch/arm64/include/asm/kvm_host.h | 17 +++++++++++++++++ arch/arm64/kvm/mmu.c | 24 ++++++++++++++++++++++++ arch/arm64/kvm/nested.c | 1 + 3 files changed, 42 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index cd9b9d2462f9..365ec57d6d7a 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -150,6 +151,16 @@ struct kvm_vmid { atomic64_t id; }; =20 +/* + * Record of a guest stage-2 mapping, storing canonical and nested IPA + * ranges. Both ranges have the same size. + */ +struct kvm_guest_s2_mapping { + struct interval_tree_node canonical; + struct interval_tree_node nested; + struct kvm_s2_mmu *nested_mmu; +}; + struct kvm_s2_mmu { struct kvm_vmid vmid; =20 @@ -227,6 +238,9 @@ struct kvm_s2_mmu { */ bool pending_unmap; =20 + /* Guest s2 mapping records indexed in this MMU's IPA space. */ + struct rb_root_cached guest_s2_mappings; + /* * 0: Nobody is currently using this, check vttbr for validity * >0: Somebody is actively using this. @@ -326,6 +340,9 @@ struct kvm_arch { size_t nested_mmus_size; int nested_mmus_next; =20 + /* Guest s2 tracking trees access serialization. */ + spinlock_t guest_s2_tracking_lock; + /* Interrupt controller */ struct vgic_dist vgic; =20 diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 671e2941d619..061cd1e09af2 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1033,6 +1034,8 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s= 2_mmu *mmu, unsigned long t =20 mmu->pgd_phys =3D __pa(pgt->pgd); =20 + mmu->guest_s2_mappings =3D RB_ROOT_CACHED; + if (kvm_is_nested_s2_mmu(kvm, mmu)) kvm_init_nested_s2_mmu(mmu); =20 @@ -1122,10 +1125,25 @@ void stage2_unmap_vm(struct kvm *kvm) srcu_read_unlock(&kvm->srcu, idx); } =20 +static void guest_s2_tracking_destroy(struct rb_root_cached *tree) +{ + struct kvm_guest_s2_mapping *mapping; + struct interval_tree_node *node; + + while ((node =3D interval_tree_iter_first(tree, 0, ULONG_MAX))) { + interval_tree_remove(node, tree); + mapping =3D container_of(node, struct kvm_guest_s2_mapping, + canonical); + kfree(mapping); + cond_resched(); + } +} + void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) { struct kvm *kvm =3D kvm_s2_mmu_to_kvm(mmu); struct kvm_pgtable *pgt =3D NULL; + struct rb_root_cached mappings_tree; =20 write_lock(&kvm->mmu_lock); pgt =3D mmu->pgt; @@ -1138,12 +1156,18 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) if (kvm_is_nested_s2_mmu(kvm, mmu)) kvm_init_nested_s2_mmu(mmu); =20 + mappings_tree =3D mmu->guest_s2_mappings; + mmu->guest_s2_mappings =3D RB_ROOT_CACHED; + write_unlock(&kvm->mmu_lock); =20 if (pgt) { kvm_stage2_destroy(pgt); kfree(pgt); } + + if (!kvm_is_nested_s2_mmu(kvm, mmu)) + guest_s2_tracking_destroy(&mappings_tree); } =20 static void hyp_mc_free_fn(void *addr, void *mc) diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index d60f6f69e293..b7bed02e38f7 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -52,6 +52,7 @@ int kvm_init_nested(struct kvm *kvm) GFP_KERNEL_ACCOUNT); kvm->arch.nested_mmus_size =3D 0; atomic_set(&kvm->arch.vncr_tlb_count, 0); + spin_lock_init(&kvm->arch.guest_s2_tracking_lock); =20 return kvm->arch.nested_mmus ? 0 : -ENOMEM; } --=20 2.43.0 From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8B514AE133 for ; Tue, 15 Sep 2026 15:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487016; cv=none; b=tytuWLOAmwjXfz0yRJSolfmRPA7Elc+X5Rv3GVcmW18Q1egLcgrWbMjXoGRLknf+9jNNjlHv8HcPtKzHpLSU5BTepU+ZFT3Q83u3kzpMzzz5R7CXWfBK/k6j4E1JGHQcjmyjujwrFCPPJmcU2qmxe6gPNtBiUALG69hIZkaxJ70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487016; c=relaxed/simple; bh=rqDS6V7DvqdfA5AoACvmacEkIMzAVYCsbPwYHmwBTAQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mjpqohnm1SdlXzy9tkvJOEUZHjKBXTcCotAbbtnPMZ+/rORKVLL5sRdC//bVyygSmJCUvQS7PE/WGGre8VaoiiCzyZ0Ujx49JLaVetD8T+bjPj4mNhz4uhc3vBbK3tyQ374E6leUlbuChlkBEaP4XO3mgbSO4eqVXQThx4j5iGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=nrP6SZfe; arc=none smtp.client-ip=217.140.110.172 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.b="nrP6SZfe" 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 CDDDD1570; Tue, 15 Sep 2026 08:43:27 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D516A3F882; Tue, 15 Sep 2026 08:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487011; bh=rqDS6V7DvqdfA5AoACvmacEkIMzAVYCsbPwYHmwBTAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nrP6SZfeoPQ0keW6mYi+VmmTXacW6AkR5tsVkPJ1X7tw5qUchAykTFF8HhscaoxyQ pXalQd3xN7yJcFwMeu4ql+yO4tFejHdAanobVdkbrmHJBkdVi+LFpraHRpFjYgUwDL 059ypKflXgWoyxOIGOeYGfJ9ExplrzONy202uFl0= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 3/7] KVM: arm64: nv: Track guest stage-2 mapping creation Date: Tue, 15 Sep 2026 16:43:01 +0100 Message-ID: <20260915154305.3852871-4-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During shadow stage-2 faults, in addition to creating mappings in the shadow page tables, also allocate kvm_guest_s2_mapping objects, record the mapping ranges, and insert them into the canonical and nested mmu's guest_s2_mappings tree. Note that because we allow parallel faulting, the interval trees could store mappings that are not live in the shadow page tables. Storing a superset of the live mappings is fine because we will only over-unmap when we use this information later to do the targeted MMU notifier unmap. The mapping is also added to the interval trees if kvm_pgtable_stage2_map() returns -EAGAIN. This is required for example, when a 2M block map (A) races with a 4K page map (B): 1. (A) maps the 2M block in kvm_pgtable_visitor_cb() 2. (B) breaks that block into a table and maps 4K 3. (A) reloads and finds the table after kvm_pgtable_visitor_cb(), then descends into it. 4. (A) maps some 4K, but before it finishes it reads the entry mapped by (B). 5. (A) returns -EAGAIN although it had mapped a few pages. In this case, we don't know what subrange is mapped, just track the whole requested mapping range. Signed-off-by: Wei-Lin Chang Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue --- arch/arm64/include/asm/kvm_nested.h | 3 +++ arch/arm64/kvm/mmu.c | 39 +++++++++++++++++++++++++++++ arch/arm64/kvm/nested.c | 25 ++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/k= vm_nested.h index 586026e85903..2d71f686064a 100644 --- a/arch/arm64/include/asm/kvm_nested.h +++ b/arch/arm64/include/asm/kvm_nested.h @@ -78,6 +78,9 @@ extern void kvm_s2_mmu_iterate_by_vmid(struct kvm *kvm, u= 16 vmid, const union tlbi_info *info, void (*)(struct kvm_s2_mmu *, const union tlbi_info *)); +extern void kvm_record_guest_s2_mapping(struct kvm_s2_mmu *mmu, gpa_t cano= nical_ipa, + gpa_t nested_ipa, size_t map_size, + struct kvm_guest_s2_mapping *mapping); extern void kvm_vcpu_load_hw_mmu(struct kvm_vcpu *vcpu); extern void kvm_vcpu_put_hw_mmu(struct kvm_vcpu *vcpu); =20 diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 061cd1e09af2..9bc799553ce9 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1636,6 +1636,7 @@ static int gmem_abort(const struct kvm_s2_fault_desc = *s2fd) enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_SHARED; enum kvm_pgtable_prot prot =3D KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt =3D s2fd->vcpu->arch.hw_mmu->pgt; + struct kvm_guest_s2_mapping *mapping =3D NULL; unsigned long mmu_seq; struct page *page; struct kvm *kvm =3D s2fd->vcpu->kvm; @@ -1649,6 +1650,11 @@ static int gmem_abort(const struct kvm_s2_fault_desc= *s2fd) ret =3D topup_mmu_memcache(s2fd->vcpu, memcache); if (ret) return ret; + if (kvm_is_nested_s2_mmu(kvm, pgt->mmu)) { + mapping =3D kmalloc_obj(struct kvm_guest_s2_mapping, GFP_KERNEL_ACCOUNT= ); + if (!mapping) + return -ENOMEM; + } } =20 if (s2fd->nested) @@ -1669,6 +1675,7 @@ static int gmem_abort(const struct kvm_s2_fault_desc = *s2fd) if (ret) { kvm_prepare_memory_fault_exit(s2fd->vcpu, s2fd->fault_ipa, PAGE_SIZE, write_fault, exec_fault, false); + kfree(mapping); return ret; } =20 @@ -1702,11 +1709,22 @@ static int gmem_abort(const struct kvm_s2_fault_des= c *s2fd) ret =3D KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, s2fd->fault_ipa, PAGE_SI= ZE, __pfn_to_phys(pfn), prot, memcache, flags); + /* + * -EAGAIN from kvm_pgtable_stage2_map() can install mappings. + * We don't know which subrange is installed, track the whole + * thing. + */ + if ((ret =3D=3D 0 || ret =3D=3D -EAGAIN) && kvm_is_nested_s2_mmu(kvm, pg= t->mmu)) { + kvm_record_guest_s2_mapping(pgt->mmu, gfn << PAGE_SHIFT, + s2fd->fault_ipa, PAGE_SIZE, mapping); + mapping =3D NULL; + } } =20 out_unlock: kvm_release_faultin_page(kvm, page, !!ret, prot & KVM_PGTABLE_PROT_W); kvm_fault_unlock(kvm); + kfree(mapping); =20 if ((prot & KVM_PGTABLE_PROT_W) && !ret) mark_page_dirty_in_slot(kvm, s2fd->memslot, gfn); @@ -2043,6 +2061,7 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault= _desc *s2fd, void *memcache) { enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_SHARED; + struct kvm_guest_s2_mapping *mapping =3D NULL; bool writable =3D prot & KVM_PGTABLE_PROT_W; struct kvm *kvm =3D s2fd->vcpu->kvm; phys_addr_t canonical_ipa; @@ -2053,6 +2072,15 @@ static int kvm_s2_fault_map(const struct kvm_s2_faul= t_desc *s2fd, gfn_t gfn; int ret; =20 + if (kvm_is_nested_s2_mmu(kvm, s2fd->vcpu->arch.hw_mmu)) { + mapping =3D kmalloc_obj(struct kvm_guest_s2_mapping, + GFP_KERNEL_ACCOUNT); + if (!mapping) { + kvm_release_page_unused(s2vi->page); + return -ENOMEM; + } + } + kvm_fault_lock(kvm); pgt =3D s2fd->vcpu->arch.hw_mmu->pgt; ret =3D -EAGAIN; @@ -2106,11 +2134,22 @@ static int kvm_s2_fault_map(const struct kvm_s2_fau= lt_desc *s2fd, ret =3D KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, gfn_to_gpa(gfn), mapping= _size, __pfn_to_phys(pfn), prot, memcache, flags); + /* + * -EAGAIN from kvm_pgtable_stage2_map() can install mappings. + * We don't know which subrange is installed, track the whole + * thing. + */ + if ((ret =3D=3D 0 || ret =3D=3D -EAGAIN) && kvm_is_nested_s2_mmu(kvm, pg= t->mmu)) { + kvm_record_guest_s2_mapping(pgt->mmu, canonical_ipa, + gfn_to_gpa(gfn), mapping_size, mapping); + mapping =3D NULL; + } } =20 out_unlock: kvm_release_faultin_page(kvm, s2vi->page, !!ret, writable); kvm_fault_unlock(kvm); + kfree(mapping); =20 /* * Mark the page dirty only if the fault is handled successfully, diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index b7bed02e38f7..d9acff507fd2 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -5,6 +5,7 @@ */ =20 #include +#include #include #include =20 @@ -872,6 +873,30 @@ static struct kvm_s2_mmu *get_s2_mmu_nested(struct kvm= _vcpu *vcpu) return s2_mmu; } =20 +void kvm_record_guest_s2_mapping(struct kvm_s2_mmu *mmu, gpa_t canonical_i= pa, + gpa_t nested_ipa, size_t map_size, + struct kvm_guest_s2_mapping *mapping) +{ + struct kvm *kvm =3D kvm_s2_mmu_to_kvm(mmu); + + lockdep_assert_held_read(&kvm->mmu_lock); + + canonical_ipa =3D ALIGN_DOWN(canonical_ipa, map_size); + nested_ipa =3D ALIGN_DOWN(nested_ipa, map_size); + + mapping->canonical.start =3D canonical_ipa; + mapping->canonical.last =3D canonical_ipa + map_size - 1; + + mapping->nested.start =3D nested_ipa; + mapping->nested.last =3D nested_ipa + map_size - 1; + + mapping->nested_mmu =3D mmu; + + guard(spinlock)(&kvm->arch.guest_s2_tracking_lock); + interval_tree_insert(&mapping->nested, &mmu->guest_s2_mappings); + interval_tree_insert(&mapping->canonical, &kvm->arch.mmu.guest_s2_mapping= s); +} + void kvm_init_nested_s2_mmu(struct kvm_s2_mmu *mmu) { /* CnP being set denotes an invalid entry */ --=20 2.43.0 From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 961F74AE8C1 for ; Tue, 15 Sep 2026 15:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487019; cv=none; b=rsPmxWRWAs2udTzFtuNnN4AebgE1ukhdxpUZVpaXjHbvI99fw6A14r3CW7G4pD2r39vtqb4txXE6QZmMyOKmyYX6wePcq6FUoEZzyi2/ixfac0ikFefFneOvjMFMH+YMPDEOCARiyqa++coQ4/ODh/0J3LglWTlg5EEb4BpSXLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487019; c=relaxed/simple; bh=E3MnILg53mlr4G1yo77+YKy7GVbSgPTcUYGivxV5F98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jX5JRSvowAms4ZhzecEOi1Cg0j4jtjhfBquO/prLxltMwWfi4zagHFPap+s0QIhUIWFP1Slz4dqJLjThHkswhMihb7FHE+pMHRjlEQI2K0fmc1onrpwXhCwU7jEtqsTdGQI6eJTohIbSmA4/zKREMIYn6DHCRhEMUFXdx1NBUdw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=mzx1fa8p; arc=none smtp.client-ip=217.140.110.172 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.b="mzx1fa8p" 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 BB10A15A1; Tue, 15 Sep 2026 08:43:30 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BDA633F882; Tue, 15 Sep 2026 08:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487014; bh=E3MnILg53mlr4G1yo77+YKy7GVbSgPTcUYGivxV5F98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mzx1fa8pzN8/JLf9ZvF+Dm6cP90s9jDOH69MfvNPqpZetn3gnq61Lhd8D1ReXsGyV 6bXhGoKKlFycdpXrTdkwfezNghzLl+9rFunvqA0IbGiMAZGeJAoxAb5fArUAoaRQC3 zMWV2dgEj+6Yvo72y/SeVLg64X/8/R+jtSDTGpFg= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 4/7] KVM: arm64: nv: Track guest stage-2 mapping removal Date: Tue, 15 Sep 2026 16:43:02 +0100 Message-ID: <20260915154305.3852871-5-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" kvm_stage2_unmap_range() is the helper to remove mappings from the stage-2 page tables. It is called during guest TLBI handling, memslot removal, nested mmu reuse, etc. Teach it about the guest stage-2 tracking trees and remove mappings from there when shadow mappings are removed. This keeps the tracking trees from having stale mappings pile up. Don't remove tracked mappings from the interval trees if they only partially overlap the removal range. For instance we can have a 4K shadow mapping tracked as a 2M range in the interval trees. It would be wrong to remove the tracked 2M range when a guest TLBI doesn't touch the 4K mapped. Signed-off-by: Wei-Lin Chang Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue --- arch/arm64/include/asm/kvm_host.h | 5 ++++- arch/arm64/include/asm/kvm_nested.h | 2 ++ arch/arm64/kvm/mmu.c | 23 +++++++++++++++++-- arch/arm64/kvm/nested.c | 34 +++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 365ec57d6d7a..f12883a42081 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -340,7 +340,10 @@ struct kvm_arch { size_t nested_mmus_size; int nested_mmus_next; =20 - /* Guest s2 tracking trees access serialization. */ + /* + * Serializes guest s2 tracking trees access when the mmu_lock + * is only held for read. + */ spinlock_t guest_s2_tracking_lock; =20 /* Interrupt controller */ diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/k= vm_nested.h index 2d71f686064a..954f532bc11b 100644 --- a/arch/arm64/include/asm/kvm_nested.h +++ b/arch/arm64/include/asm/kvm_nested.h @@ -81,6 +81,8 @@ extern void kvm_s2_mmu_iterate_by_vmid(struct kvm *kvm, u= 16 vmid, extern void kvm_record_guest_s2_mapping(struct kvm_s2_mmu *mmu, gpa_t cano= nical_ipa, gpa_t nested_ipa, size_t map_size, struct kvm_guest_s2_mapping *mapping); +extern void kvm_remove_guest_s2_mappings(struct kvm_s2_mmu *mmu, + gpa_t nipa, size_t size); extern void kvm_vcpu_load_hw_mmu(struct kvm_vcpu *vcpu); extern void kvm_vcpu_put_hw_mmu(struct kvm_vcpu *vcpu); =20 diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 9bc799553ce9..c46e92d67f04 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -314,6 +314,19 @@ static void invalidate_icache_guest_page(void *va, siz= e_t size) * we then fully enforce cacheability of RAM, no matter what the guest * does. */ + +static int kvm_pgtable_stage2_unmap_tracked(struct kvm_pgtable *pgt, u64 a= ddr, u64 size) +{ + int ret; + + ret =3D kvm_pgtable_stage2_unmap(pgt, addr, size); + if (ret) + return ret; + + kvm_remove_guest_s2_mappings(pgt->mmu, addr, size); + return 0; +} + /** * __unmap_stage2_range -- Clear stage2 page table entries to unmap a range * @mmu: The KVM stage-2 MMU pointer @@ -331,11 +344,17 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *m= mu, phys_addr_t start, u64 { struct kvm *kvm =3D kvm_s2_mmu_to_kvm(mmu); phys_addr_t end =3D start + size; + int (*fn)(struct kvm_pgtable *, u64, u64); =20 lockdep_assert_held_write(&kvm->mmu_lock); WARN_ON(size & ~PAGE_MASK); - WARN_ON(stage2_apply_range(mmu, start, end, KVM_PGT_FN(kvm_pgtable_stage2= _unmap), - may_block)); + + if (kvm_is_nested_s2_mmu(kvm, mmu)) + fn =3D kvm_pgtable_stage2_unmap_tracked; + else + fn =3D KVM_PGT_FN(kvm_pgtable_stage2_unmap); + + WARN_ON(stage2_apply_range(mmu, start, end, fn, may_block)); } =20 void kvm_stage2_unmap_range(struct kvm_s2_mmu *mmu, phys_addr_t start, diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index d9acff507fd2..92a9a32f9f2b 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -897,6 +897,40 @@ void kvm_record_guest_s2_mapping(struct kvm_s2_mmu *mm= u, gpa_t canonical_ipa, interval_tree_insert(&mapping->canonical, &kvm->arch.mmu.guest_s2_mapping= s); } =20 +void kvm_remove_guest_s2_mappings(struct kvm_s2_mmu *mmu, gpa_t nipa, + size_t size) +{ + struct kvm *kvm =3D kvm_s2_mmu_to_kvm(mmu); + struct interval_tree_node *node, *next; + struct kvm_guest_s2_mapping *mapping; + gpa_t nipa_end =3D nipa + size - 1; + + /* + * Guest s2 tracking interval trees are only accessed while holding the + * mmu_lock, hence we don't have to take guest_s2_tracking_lock if the + * mmu_lock is held for write. + */ + lockdep_assert_held_write(&kvm->mmu_lock); + + node =3D interval_tree_iter_first(&mmu->guest_s2_mappings, nipa, nipa_end= ); + while (node) { + next =3D interval_tree_iter_next(node, nipa, nipa_end); + mapping =3D container_of(node, struct kvm_guest_s2_mapping, + nested); + /* + * Tracking must be conservative on removal, only remove + * mappings that are within the unmap range. + */ + if (nipa <=3D mapping->nested.start && nipa_end >=3D mapping->nested.las= t) { + interval_tree_remove(&mapping->nested, &mmu->guest_s2_mappings); + interval_tree_remove(&mapping->canonical, + &kvm->arch.mmu.guest_s2_mappings); + kfree(mapping); + } + node =3D next; + } +} + void kvm_init_nested_s2_mmu(struct kvm_s2_mmu *mmu) { /* CnP being set denotes an invalid entry */ --=20 2.43.0 From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 352944AEBDA for ; Tue, 15 Sep 2026 15:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487020; cv=none; b=Sz4oxaQBI75UnPpfZcrBghM/hCQxdlsnhkRdOm/YrKOcH2u/SnKuoSim9mlktt90USBpfFMdw0svMTMq8gCo+sMuKynljc6WD18lt25FAkIcD+fg2bzJ9RZXBqFbLdXwjWPVBKpNGfN/R0XzDL0SpYrsNHaqWd2S2f0pfv6QdHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487020; c=relaxed/simple; bh=tfSyeTEKhMgIr2WJ2UOq+ZLRU580pd9eUWgwdsIJlT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eU8HrsDONsTuICm6fjfznB/ldWImN4VhML5LHA1EE7u4JPiiD0C9dwgnasA6HpaayakL/EixzV5wIq4emMCxhdInskuykYaPFXuEqOodvrYHqvUVHIwdOo3ZUzaZVSv33MgBdnqu1nzDmAxtd0cBdJ5GjtKT3wm0A8JmD4HBn1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=BttJjvIg; arc=none smtp.client-ip=217.140.110.172 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.b="BttJjvIg" 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 9F349169E; Tue, 15 Sep 2026 08:43:33 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A630B3F882; Tue, 15 Sep 2026 08:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487017; bh=tfSyeTEKhMgIr2WJ2UOq+ZLRU580pd9eUWgwdsIJlT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BttJjvIg/rpdGLg/BCbqiUIZvf9gneIEp6IsL8+WZGUrRw7/aaYlwoR0NnwpSYuvv zLu4fSGaj6PiOoTyWIjUxlEfFULgzxz41h9ODxukVWtdmFBPc55et/hID76TU9f46K gdYcRIulRp0fJUc+e7erQ/6cHKgcUId9tCPjaAs4= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 5/7] KVM: arm64: nv: Avoid full shadow stage-2 unmap Date: Tue, 15 Sep 2026 16:43:03 +0100 Message-ID: <20260915154305.3852871-6-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With guest stage-2 tracking in place, we can improve MMU notifier unmaps from unmapping all existing shadow stage-2 mappings to only unmapping the ones affected by the given canonical IPA range. Signed-off-by: Wei-Lin Chang Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue --- arch/arm64/include/asm/kvm_nested.h | 2 ++ arch/arm64/kvm/mmu.c | 7 ++-- arch/arm64/kvm/nested.c | 50 +++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/k= vm_nested.h index 954f532bc11b..0f899addafa8 100644 --- a/arch/arm64/include/asm/kvm_nested.h +++ b/arch/arm64/include/asm/kvm_nested.h @@ -171,6 +171,8 @@ extern int kvm_s2_handle_perm_fault(struct kvm_vcpu *vc= pu, struct kvm_s2_trans *trans); extern int kvm_inject_s2_fault(struct kvm_vcpu *vcpu, u64 esr_el2); extern void kvm_nested_s2_wp(struct kvm *kvm); +extern void kvm_nested_unmap_cipa_range(struct kvm *kvm, gpa_t cipa, + size_t unmap_size, bool may_block); extern void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block); extern void kvm_nested_s2_flush(struct kvm *kvm); =20 diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index c46e92d67f04..b8ba2d09ed96 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2525,8 +2525,9 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_= gfn_range *range) __unmap_stage2_range(&kvm->arch.mmu, range->start << PAGE_SHIFT, (range->end - range->start) << PAGE_SHIFT, range->may_block); - - kvm_nested_s2_unmap(kvm, range->may_block); + kvm_nested_unmap_cipa_range(kvm, range->start << PAGE_SHIFT, + (range->end - range->start) << PAGE_SHIFT, + range->may_block); return false; } =20 @@ -2808,7 +2809,7 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm, =20 write_lock(&kvm->mmu_lock); kvm_stage2_unmap_range(&kvm->arch.mmu, gpa, size, true); - kvm_nested_s2_unmap(kvm, true); + kvm_nested_unmap_cipa_range(kvm, gpa, size, true); write_unlock(&kvm->mmu_lock); } =20 diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index 92a9a32f9f2b..4cbb4f1b8b35 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -906,9 +906,8 @@ void kvm_remove_guest_s2_mappings(struct kvm_s2_mmu *mm= u, gpa_t nipa, gpa_t nipa_end =3D nipa + size - 1; =20 /* - * Guest s2 tracking interval trees are only accessed while holding the - * mmu_lock, hence we don't have to take guest_s2_tracking_lock if the - * mmu_lock is held for write. + * See kvm_nested_unmap_cipa_range() for why guest_s2_tracking_lock + * isn't taken here. */ lockdep_assert_held_write(&kvm->mmu_lock); =20 @@ -1342,6 +1341,51 @@ void kvm_nested_s2_wp(struct kvm *kvm) kvm_invalidate_vncr_ipa(kvm, 0, BIT(kvm->arch.mmu.pgt->ia_bits)); } =20 +void kvm_nested_unmap_cipa_range(struct kvm *kvm, gpa_t cipa, size_t unmap= _size, + bool may_block) +{ + gpa_t cipa_end =3D cipa + unmap_size - 1; + struct kvm_guest_s2_mapping *mapping; + struct interval_tree_node *node; + size_t mapping_size; + + /* + * Guest s2 tracking interval trees are only accessed while holding the + * mmu_lock, hence we don't have to take guest_s2_tracking_lock if the + * mmu_lock is held for write. This saves us from having to manually + * lock/unlock guest_s2_tracking_lock below around + * cond_resched_rwlock_write(). + */ + lockdep_assert_held_write(&kvm->mmu_lock); + + if (!kvm->arch.nested_mmus_size) + return; + + while ((node =3D interval_tree_iter_first(&kvm->arch.mmu.guest_s2_mapping= s, + cipa, cipa_end))) { + mapping =3D container_of(node, struct kvm_guest_s2_mapping, canonical); + mapping_size =3D mapping->nested.last - mapping->nested.start + 1; + + /* We could race against MMU teardown, which frees mmu->pgt. */ + if (mapping->nested_mmu->pgt) { + if (WARN_ON_ONCE(kvm_pgtable_stage2_unmap(mapping->nested_mmu->pgt, + mapping->nested.start, + mapping_size))) + return; + + interval_tree_remove(&mapping->nested, + &mapping->nested_mmu->guest_s2_mappings); + } + interval_tree_remove(node, &kvm->arch.mmu.guest_s2_mappings); + kfree(mapping); + + if (may_block) + cond_resched_rwlock_write(&kvm->mmu_lock); + } + + kvm_invalidate_vncr_ipa(kvm, cipa, cipa + unmap_size); +} + void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block) { int i; --=20 2.43.0 From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8EA7E4AF158 for ; Tue, 15 Sep 2026 15:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487025; cv=none; b=eMch2WeLO6yezhaqXKImdzaFzkQYU/tfmNZmc0IbU7ygpAtzV8xCedMHyTQ2eQK62pAfkBHvxUljcJ9AmxXNnl2pOkuX48gu3lTAIrqcmhjwUC1jPc8dFALMGPbn71eDO1X41Io8EzIzHNAdr63YqmaS2s0jQ+KFxGuVUvz+Sb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487025; c=relaxed/simple; bh=BxubJhJnwe6/0bJ2MGHy009TjXa9UajkeWAN2/J4vkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IYc0+9nAZsfbWk7NXMfFUYanSp4ssxzFPLhkNazNeHkcIv1NV3bHFf9ulCq25UxvwxImPswch67BjO4mHk+m35OmZTSKJmUTtzcs12uGzZewPzbBSKq1FxNKQu7LyKIzT1lGGz8aL2O/Gzp7zDyt03g8Lw0az6hRc5m47T4f76A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=LQUq6r98; arc=none smtp.client-ip=217.140.110.172 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.b="LQUq6r98" 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 8DBCC15A1; Tue, 15 Sep 2026 08:43:36 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8F0083F882; Tue, 15 Sep 2026 08:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487020; bh=BxubJhJnwe6/0bJ2MGHy009TjXa9UajkeWAN2/J4vkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LQUq6r98ixMf6dnQmOincG/BdRjm+KsxyMA2DkfvrVw5uLeyLHr6+81sZJFx/TUgv sJ3P9BcBXG+ZvS4UI1RRdrxP6gF9hNxmLtOOyDBXg7OoxL0aqMKlosbO0+jgaEYosv k6uCESPCOgMRKBReS5d6dWHnmKQJQrMyEkK9QlXI= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 6/7] KVM: arm64: nv: Drop kvm_s2_mmu pointer from kvm_guest_s2_mapping Date: Tue, 15 Sep 2026 16:43:04 +0100 Message-ID: <20260915154305.3852871-7-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Marc Zyngier As it appears that the kvm_guest_s2_mapping structure is quite large, and results in a 128 byte slab allocation, there is some incentive to shrink a bit. For this, replace the S2 MMU back-pointer with an index tucked into the low bits of the nested.start field. This allows us to shrink the structure by 8 bytes, and therefore to fit in a 96 byte slab. The index is also stored in the S2 MMU structure itself, which comes for free as it fits in an existing hole. The structure is also repacked to avoid other disgracious holes. Signed-off-by: Marc Zyngier Signed-off-by: Wei-Lin Chang Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue --- arch/arm64/include/asm/kvm_host.h | 19 ++++++----- arch/arm64/kvm/nested.c | 54 ++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index f12883a42081..8dfaa33c6cd5 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -153,12 +153,12 @@ struct kvm_vmid { =20 /* * Record of a guest stage-2 mapping, storing canonical and nested IPA - * ranges. Both ranges have the same size. + * ranges. Both ranges have the same size. The lower bits of nested.start + * store the index of the nested mmu this mapping belongs to. */ struct kvm_guest_s2_mapping { struct interval_tree_node canonical; struct interval_tree_node nested; - struct kvm_s2_mmu *nested_mmu; }; =20 struct kvm_s2_mmu { @@ -222,30 +222,33 @@ struct kvm_s2_mmu { u64 tlb_vttbr; u64 tlb_vtcr; =20 + /* Guest s2 mapping records indexed in this MMU's IPA space. */ + struct rb_root_cached guest_s2_mappings; + /* * true when this represents a nested context where virtual * HCR_EL2.VM =3D=3D 1 */ bool nested_stage2_enabled; =20 -#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS - struct dentry *shadow_pt_debugfs_dentry; -#endif - /* * true when this MMU needs to be unmapped before being used for a new * purpose. */ bool pending_unmap; =20 - /* Guest s2 mapping records indexed in this MMU's IPA space. */ - struct rb_root_cached guest_s2_mappings; + /* Index in the S2 MMU array, only valid for a shadow S2 */ + u16 s2_mmu_idx; =20 /* * 0: Nobody is currently using this, check vttbr for validity * >0: Somebody is actively using this. */ atomic_t refcnt; + +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS + struct dentry *shadow_pt_debugfs_dentry; +#endif }; =20 struct kvm_arch_memory_slot { diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index 4cbb4f1b8b35..61d4dae6be6a 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -45,11 +45,12 @@ struct vncr_tlb { * will invalidate them more often). */ #define S2_MMU_PER_VCPU 2 +#define S2_MMU_PER_VM (KVM_MAX_VCPUS * S2_MMU_PER_VCPU) =20 int kvm_init_nested(struct kvm *kvm) { kvm->arch.nested_mmus =3D kvmalloc_objs(struct kvm_s2_mmu *, - KVM_MAX_VCPUS * S2_MMU_PER_VCPU, + S2_MMU_PER_VM, GFP_KERNEL_ACCOUNT); kvm->arch.nested_mmus_size =3D 0; atomic_set(&kvm->arch.vncr_tlb_count, 0); @@ -128,8 +129,10 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu) =20 guard(write_lock)(&kvm->mmu_lock); =20 - for (i =3D 0; i < S2_MMU_PER_VCPU; i++) + for (i =3D 0; i < S2_MMU_PER_VCPU; i++) { + tmp[i].s2_mmu_idx =3D i + kvm->arch.nested_mmus_size; kvm->arch.nested_mmus[i + kvm->arch.nested_mmus_size] =3D &tmp[i]; + } =20 kvm->arch.nested_mmus_size +=3D S2_MMU_PER_VCPU; } @@ -873,6 +876,27 @@ static struct kvm_s2_mmu *get_s2_mmu_nested(struct kvm= _vcpu *vcpu) return s2_mmu; } =20 +#define S2_MMU_IDX_MASK GENMASK_ULL(11, 0) + +static void tag_s2_mapping_mmu(struct kvm_guest_s2_mapping *mapping, + struct kvm_s2_mmu *mmu) +{ + BUILD_BUG_ON(S2_MMU_PER_VM > SZ_4K); + mapping->nested.start &=3D ~S2_MMU_IDX_MASK; + mapping->nested.start |=3D mmu->s2_mmu_idx; +} + +static struct kvm_s2_mmu *s2_mapping_to_mmu(struct kvm *kvm, + struct kvm_guest_s2_mapping *mapping) +{ + return kvm->arch.nested_mmus[mapping->nested.start & S2_MMU_IDX_MASK]; +} + +static unsigned long s2_mapping_to_nested_start(struct kvm_guest_s2_mappin= g *mapping) +{ + return mapping->nested.start & ~S2_MMU_IDX_MASK; +} + void kvm_record_guest_s2_mapping(struct kvm_s2_mmu *mmu, gpa_t canonical_i= pa, gpa_t nested_ipa, size_t map_size, struct kvm_guest_s2_mapping *mapping) @@ -890,7 +914,7 @@ void kvm_record_guest_s2_mapping(struct kvm_s2_mmu *mmu= , gpa_t canonical_ipa, mapping->nested.start =3D nested_ipa; mapping->nested.last =3D nested_ipa + map_size - 1; =20 - mapping->nested_mmu =3D mmu; + tag_s2_mapping_mmu(mapping, mmu); =20 guard(spinlock)(&kvm->arch.guest_s2_tracking_lock); interval_tree_insert(&mapping->nested, &mmu->guest_s2_mappings); @@ -913,6 +937,8 @@ void kvm_remove_guest_s2_mappings(struct kvm_s2_mmu *mm= u, gpa_t nipa, =20 node =3D interval_tree_iter_first(&mmu->guest_s2_mappings, nipa, nipa_end= ); while (node) { + unsigned long nested_start; + next =3D interval_tree_iter_next(node, nipa, nipa_end); mapping =3D container_of(node, struct kvm_guest_s2_mapping, nested); @@ -920,7 +946,8 @@ void kvm_remove_guest_s2_mappings(struct kvm_s2_mmu *mm= u, gpa_t nipa, * Tracking must be conservative on removal, only remove * mappings that are within the unmap range. */ - if (nipa <=3D mapping->nested.start && nipa_end >=3D mapping->nested.las= t) { + nested_start =3D s2_mapping_to_nested_start(mapping); + if (nipa <=3D nested_start && nipa_end >=3D mapping->nested.last) { interval_tree_remove(&mapping->nested, &mmu->guest_s2_mappings); interval_tree_remove(&mapping->canonical, &kvm->arch.mmu.guest_s2_mappings); @@ -1363,18 +1390,23 @@ void kvm_nested_unmap_cipa_range(struct kvm *kvm, g= pa_t cipa, size_t unmap_size, =20 while ((node =3D interval_tree_iter_first(&kvm->arch.mmu.guest_s2_mapping= s, cipa, cipa_end))) { - mapping =3D container_of(node, struct kvm_guest_s2_mapping, canonical); - mapping_size =3D mapping->nested.last - mapping->nested.start + 1; + unsigned long nested_start; + struct kvm_s2_mmu *mmu; + + mapping =3D container_of(node, struct kvm_guest_s2_mapping, + canonical); + nested_start =3D s2_mapping_to_nested_start(mapping); + mmu =3D s2_mapping_to_mmu(kvm, mapping); =20 /* We could race against MMU teardown, which frees mmu->pgt. */ - if (mapping->nested_mmu->pgt) { - if (WARN_ON_ONCE(kvm_pgtable_stage2_unmap(mapping->nested_mmu->pgt, - mapping->nested.start, + if (mmu->pgt) { + mapping_size =3D mapping->nested.last - nested_start + 1; + + if (WARN_ON_ONCE(kvm_pgtable_stage2_unmap(mmu->pgt, nested_start, mapping_size))) return; =20 - interval_tree_remove(&mapping->nested, - &mapping->nested_mmu->guest_s2_mappings); + interval_tree_remove(&mapping->nested, &mmu->guest_s2_mappings); } interval_tree_remove(node, &kvm->arch.mmu.guest_s2_mappings); kfree(mapping); --=20 2.43.0 From nobody Fri Sep 25 07:22:11 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2ACE4AD4B4 for ; Tue, 15 Sep 2026 15:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487026; cv=none; b=i9SurdkFMFvzzcm+Oa7+hm5+UR/vRHtCo2yfU3wVDowzZ4MnF3cyt1iQ0ZcVd2F48rS0sktumwHUL/+FXxlUF6rY7qp9Sc1xc1pm8goz9DYWyLQrYn8YSauxhz2yqrWBhIZtJN/ImZ/y1UFxjErWft2uyYhbRK0SGLC5B0o02nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789487026; c=relaxed/simple; bh=B3XXboLvPkx6dcOeOmoMJEVAmJvgwTkHHDv9chNx8vk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XuBJtDvOd4OnZGvGa63B5fYILgZRNk63r3YmAzRxn/PeFgz+KLiSu1HQ8g7oo8FG6NIsdJZnYzmWblXt/BKbTC8uv7oUOP6HILHHkR1s+ICBnXtJoQA0AikwcT/wLpuNJF0yJbl1IKXAgRPkVah/6LwsP/UN1ausbGITvYwJX40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=s7+YPBFQ; arc=none smtp.client-ip=217.140.110.172 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.b="s7+YPBFQ" 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 773FC1570; Tue, 15 Sep 2026 08:43:39 -0700 (PDT) Received: from workstation-e142269.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 786C73F882; Tue, 15 Sep 2026 08:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789487023; bh=B3XXboLvPkx6dcOeOmoMJEVAmJvgwTkHHDv9chNx8vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s7+YPBFQT58OoE1Uxuggw3iFQzbJZ1gHumDNW7y2cUr1H96wbIklTYGLDCUreTNwy 3YxqtanquhJiQlt1Hm5COhOvwhGsfFvypLyKZbYNBCqia/ZvJ5S+CkK8IiGsy1YYsR g3BdfsnOW6b9cBwj9KEV1rMbNS23eRn816xN4xN4= From: Wei-Lin Chang To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Itaru Kitayama , Wang Han , Shuai Xue , "Lorenzo Stoakes (ARM)" , Wei-Lin Chang Subject: [PATCH v6 7/7] KVM: arm64: Refactor kvm_unmap_gfn_range() with common variables Date: Tue, 15 Sep 2026 16:43:05 +0100 Message-ID: <20260915154305.3852871-8-weilin.chang@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260915154305.3852871-1-weilin.chang@arm.com> References: <20260915154305.3852871-1-weilin.chang@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __unmap_stage2_range() and kvm_nested_unmap_cipa_range() are using the same arguments. Clean this up by using local variables. Signed-off-by: Wei-Lin Chang Reviewed-by: Oliver Upton Tested-by: Itaru Kitayama Tested-by: Shuai Xue --- arch/arm64/kvm/mmu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index b8ba2d09ed96..3c3bc231eab7 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2519,15 +2519,16 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) =20 bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) { + gpa_t gpa =3D range->start << PAGE_SHIFT; + size_t size =3D (range->end - range->start) << PAGE_SHIFT; + bool may_block =3D range->may_block; + if (!kvm->arch.mmu.pgt || kvm_vm_is_protected(kvm)) return false; =20 - __unmap_stage2_range(&kvm->arch.mmu, range->start << PAGE_SHIFT, - (range->end - range->start) << PAGE_SHIFT, - range->may_block); - kvm_nested_unmap_cipa_range(kvm, range->start << PAGE_SHIFT, - (range->end - range->start) << PAGE_SHIFT, - range->may_block); + __unmap_stage2_range(&kvm->arch.mmu, gpa, size, may_block); + kvm_nested_unmap_cipa_range(kvm, gpa, size, may_block); + return false; } =20 --=20 2.43.0