From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: Fuad Tabba <fuad.tabba@linux.dev>, Marc Zyngier <maz@kernel.org>,
Oliver Upton <oupton@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Raghavendra Rao Ananta <rananta@google.com>,
Fuad Tabba <tabba@google.com>
Subject: Re: [PATCH 3/3] KVM: arm64: Move stage-2 teardown into kvm_vm_s2_ops
Date: Tue, 3 Nov 2026 09:37:37 +0000 [thread overview]
Message-ID: <29e7d214-b7b0-403a-a40f-dbc5b6951e22@arm.com> (raw)
In-Reply-To: <20261103084742.1302597-4-fuad.tabba@linux.dev>
Hi Fuad
On 03/11/2026 08:47, Fuad Tabba wrote:
> Replace kvm_stage2_destroy()'s is_protected_kvm_enabled() and
> KVM_PGT_FN() dispatch with a vm_stage2_destroy hook in kvm_vm_s2_ops,
> like the other stage-2 operations. Both pKVM flavors share
> pkvm_stage2_destroy(). Like kvm_vm_stage2_destroy(), it takes the range
> from kvm_phys_size().
>
> No functional change intended.
Someone beat you on this (well almost) ;-)
https://lore.kernel.org/all/4304d0c7-2220-4add-9c71-e6dc6b4fbc11@arm.com
>
> Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
> ---
> arch/arm64/include/asm/kvm_host.h | 2 ++
> arch/arm64/kvm/mmu.c | 24 +++++++++++++-----------
> 2 files changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index 97332ffcb1300..b36779bafae9b 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -233,6 +233,7 @@ struct kvm_vcpu_ops {
>
> struct kvm_gfn_range;
> struct kvm_s2_fault_desc;
> +struct kvm_pgtable;
>
> struct kvm_vm_s2_ops {
> bool (*vm_age_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
> @@ -243,6 +244,7 @@ struct kvm_vm_s2_ops {
> void (*vm_stage2_unmap_range)(struct kvm_s2_mmu *mmu,
> phys_addr_t start, u64 size,
> bool may_block);
> + void (*vm_stage2_destroy)(struct kvm_pgtable *pgt);
> int (*vm_mem_abort)(const struct kvm_s2_fault_desc *s2fd);
> };
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 10b425a0141be..9df3c80a5acd1 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -1029,17 +1029,16 @@ static void stage2_destroy_range(struct kvm_pgtable *pgt, phys_addr_t addr,
> } while (addr = next, addr != end);
> }
>
> -static void kvm_stage2_destroy(struct kvm_pgtable *pgt)
> +static void kvm_vm_stage2_destroy(struct kvm_pgtable *pgt)
> {
> - unsigned int ia_bits = VTCR_EL2_IPA(pgt->mmu->vtcr);
> + stage2_destroy_range(pgt, 0, kvm_phys_size(pgt->mmu));
> + kvm_pgtable_stage2_destroy_pgd(pgt);
> +}
>
> - /* pKVM walks its mapping tree, not the IPA space, and reschedules per mapping */
> - if (is_protected_kvm_enabled())
> - pkvm_pgtable_stage2_destroy_range(pgt, 0, BIT(ia_bits));
> - else
> - stage2_destroy_range(pgt, 0, BIT(ia_bits));
> -
> - KVM_PGT_FN(kvm_pgtable_stage2_destroy_pgd)(pgt);
> +static void pkvm_stage2_destroy(struct kvm_pgtable *pgt)
> +{
> + pkvm_pgtable_stage2_destroy_range(pgt, 0, kvm_phys_size(pgt->mmu));
> + pkvm_pgtable_stage2_destroy_pgd(pgt);
> }
>
> /**
> @@ -1126,7 +1125,7 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long t
> return 0;
>
> out_destroy_pgtable:
> - kvm_stage2_destroy(pgt);
> + kvm->arch.vm_s2_ops->vm_stage2_destroy(pgt);
minor nit: should we retain the kvm_stage2_destroy() to dispatch the
callback ?
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Cheers
Suzuki
> mmu->pgt = NULL;
> out_free_pgtable:
> kfree(pgt);
> @@ -1246,7 +1245,7 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu)
> write_unlock(&kvm->mmu_lock);
>
> if (pgt) {
> - kvm_stage2_destroy(pgt);
> + kvm->arch.vm_s2_ops->vm_stage2_destroy(pgt);
> kfree(pgt);
> }
>
> @@ -3152,6 +3151,7 @@ static const struct kvm_vm_s2_ops protected_pkvm_vm_s2_ops = {
> .vm_age_gfn = no_age_gfn,
> .vm_test_age_gfn = no_age_gfn,
> .vm_stage2_unmap_range = no_stage2_unmap_range,
> + .vm_stage2_destroy = pkvm_stage2_destroy,
> .vm_mem_abort = protected_pkvm_mem_abort,
> };
>
> @@ -3161,6 +3161,7 @@ static const struct kvm_vm_s2_ops pkvm_vm_s2_ops = {
> .vm_age_gfn = pkvm_age_gfn,
> .vm_test_age_gfn = pkvm_test_age_gfn,
> .vm_stage2_unmap_range = pkvm_stage2_unmap_range,
> + .vm_stage2_destroy = pkvm_stage2_destroy,
> .vm_mem_abort = kvm_vm_mem_abort,
> };
>
> @@ -3170,6 +3171,7 @@ static const struct kvm_vm_s2_ops kvm_default_vm_s2_ops = {
> .vm_age_gfn = kvm_vm_age_gfn,
> .vm_test_age_gfn = kvm_vm_test_age_gfn,
> .vm_stage2_unmap_range = kvm_vm_stage2_unmap_range,
> + .vm_stage2_destroy = kvm_vm_stage2_destroy,
> .vm_mem_abort = kvm_vm_mem_abort,
> };
>
next prev parent reply other threads:[~2026-11-03 9:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:47 [PATCH 0/3] KVM: arm64: Stop stage-2 teardown scaling with the IPA size Fuad Tabba
2026-11-03 8:47 ` [PATCH 1/3] KVM: arm64: Don't walk the whole IPA space when destroying a pKVM stage-2 Fuad Tabba
2026-11-03 14:52 ` Vincent Donnefort
2026-11-03 16:15 ` Fuad Tabba
2026-11-03 16:26 ` Marc Zyngier
2026-11-03 16:27 ` Fuad Tabba
2026-11-03 16:37 ` Vincent Donnefort
2026-11-03 16:47 ` Oliver Upton
2026-11-03 16:48 ` Oliver Upton
2026-11-03 8:47 ` [PATCH 2/3] KVM: arm64: Skip empty IPA ranges when destroying stage-2 page-tables Fuad Tabba
2026-11-03 10:27 ` Suzuki K Poulose
2026-11-03 16:19 ` Fuad Tabba
2026-11-03 16:55 ` Oliver Upton
2026-11-03 8:47 ` [PATCH 3/3] KVM: arm64: Move stage-2 teardown into kvm_vm_s2_ops Fuad Tabba
2026-11-03 9:37 ` Suzuki K Poulose [this message]
2026-11-03 10:33 ` Suzuki K Poulose
2026-11-03 16:22 ` Fuad Tabba
2026-11-03 17:03 ` [PATCH 0/3] KVM: arm64: Stop stage-2 teardown scaling with the IPA size Oliver Upton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29e7d214-b7b0-403a-a40f-dbc5b6951e22@arm.com \
--to=suzuki.poulose@arm.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=rananta@google.com \
--cc=seiden@linux.ibm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®