From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9895E606A323 for ; Wed, 25 Nov 2026 12:10:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=vMp7/DeZ; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=szuKiBZe DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=ksJzZnRlzZFG+0L0HtrVowwMj9Uu8+WpRfdThQfAKGI=; b=vMp7/DeZMHGtHV cB3gsIu1o/hYpZF+PIIfM3yTy3jOa2KJVVWEmIrobHrWS39ARjtqd7S93DYb79COgHuZDONS01erx uVhV15Wvmy3dtQ5VcrJ7/TKid/GJkFAn73R9QnVQfHDnq1zXS2gKzyYBClPdTtPtiTh71az4P3cUP ZJulW7MhM4zzHFqtGKo/u2VOFjBPxZLX28k84X8SR6W9kvsso0KwrNwi5i+u8ArFQm4TUrcSRfqZN xMTOfTCY2r5nM4xeNw+MLU1TzTaGA13uSw+j1tEGPAN8cay0dAJ2QBDGB1GppqI8TXKNtOzW668S5 1HBbBo73ROgTkwkFnJOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xWBFD-00000009eCH-10vP; Wed, 25 Nov 2026 11:32:59 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xWBFA-00000009eBi-08NF for linux-arm-kernel@lists.infradead.org; Wed, 25 Nov 2026 11:32:57 +0000 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 A33E814BF; Wed, 25 Nov 2026 03:32:49 -0800 (PST) Received: from [10.57.32.107] (unknown [10.57.32.107]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C86FA3F86F; Wed, 25 Nov 2026 03:32:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1795606372; bh=qbHqyTNnWLNOTc00I4CKxD9wPZ5SwAvyohqcO63rleg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=szuKiBZefxrXLITi7F/BtWnWCMmSSJ8eLaNdaeL9KzYCLZa6WKUoAgn86sC0E/54J CNj2pUjlBDOuClnSbnoIso25v9NAL0kFkb32fa8/Z6MK1KiVqw1oG6eXP3NTCVgH1j msYmDvDId5dj2TAsEjj4yh/XakAspLYTUQTgX1rk= Message-ID: <7bd5427d-9078-4b79-bce6-3bbf801ec766@arm.com> Date: Wed, 25 Nov 2026 11:32:46 +0000 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 04/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor To: Suzuki K Poulose , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo Pieralisi , Kohei Enju References: <20261123104233.95710-1-steven.price@arm.com> <20261123104233.95710-5-steven.price@arm.com> <0d031484-d394-47e3-be49-7c85004dbb83@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: <0d031484-d394-47e3-be49-7c85004dbb83@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261125_033256_167934_7C49713F X-CRM114-Status: GOOD ( 18.80 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 23/11/2026 11:23, Suzuki K Poulose wrote: > On 23/11/2026 10:42, Steven Price wrote: >> Select the stage-2 destruction functions through the VM's stage-2 >> operations. This keeps the native and pKVM paths explicit and lets a >> Realm provide its own destruction callback when Realm stage-2 >> operations are registered. >> >> The Realm callback will only free the root RTT pages, because RMI >> teardown destroys the non-root RTTs separately. >> > > minor nit: The second paragraph may be omitted as we introduce the > Realm stuff in a later patch. Ack > >> Signed-off-by: Steven Price > > > Reviewed-by: Suzuki K Poulose Thanks! Steve > >> >> --- >> Changes since v3: >> - Move before basic Realm infrastructure and declare the page-table >>    type for the new callback. >> >> Changes since v2: >> - New patch in v3; split stage-2 destruction dispatch out of the >>    Realm stage-2 MMU operations patch. >> --- >>   arch/arm64/include/asm/kvm_host.h |  2 ++ >>   arch/arm64/kvm/mmu.c              | 30 +++++++++++++++++++++++------- >>   2 files changed, 25 insertions(+), 7 deletions(-) >> >> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/ >> asm/kvm_host.h >> index 9d6258b213d1..3ddeddfacd06 100644 >> --- a/arch/arm64/include/asm/kvm_host.h >> +++ b/arch/arm64/include/asm/kvm_host.h >> @@ -234,6 +234,7 @@ struct kvm_vcpu_ops { >>     struct kvm_gfn_range; >>   enum kvm_gfn_range_filter; >> +struct kvm_pgtable; >>   struct kvm_s2_fault_desc; >>     struct kvm_vm_s2_ops { >> @@ -242,6 +243,7 @@ struct kvm_vm_s2_ops { >>       int (*vm_flush_remote_tlbs)(struct kvm *kvm); >>       int (*vm_flush_remote_tlbs_range)(struct kvm *kvm, gfn_t gfn, >>                         u64 nr_pages); >> +    void (*vm_stage2_destroy)(struct kvm_pgtable *pgt); >>       void (*vm_stage2_unmap_range)(struct kvm_s2_mmu *mmu, >>                         phys_addr_t start, u64 size, >>                         bool may_block, >> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c >> index 8a9a80c7cfab..fab915ddeaab 100644 >> --- a/arch/arm64/kvm/mmu.c >> +++ b/arch/arm64/kvm/mmu.c >> @@ -1018,26 +1018,39 @@ static int kvm_init_ipa_range(struct >> kvm_s2_mmu *mmu, unsigned long type) >>    * cond_resched() periodically to prevent hogging the CPU for a long >> time >>    * and schedule something else, if required. >>    */ >> -static void stage2_destroy_range(struct kvm_pgtable *pgt, phys_addr_t >> addr, >> -                   phys_addr_t end) >> +static void stage2_destroy_range(struct kvm_pgtable *pgt, >> +                 void (*destroy_range)(struct kvm_pgtable *pgt, >> +                               u64 addr, u64 size)) >>   { >> +    u64 addr = 0; >> +    u64 end = BIT(VTCR_EL2_IPA(pgt->mmu->vtcr)); >>       u64 next; >>         do { >>           next = stage2_range_addr_end(addr, end); >> -        KVM_PGT_FN(kvm_pgtable_stage2_destroy_range)(pgt, addr, >> -                                 next - addr); >> +        destroy_range(pgt, addr, next - addr); >>           if (next != end) >>               cond_resched(); >>       } while (addr = next, addr != end); >>   } >>   +static void kvm_vm_stage2_destroy(struct kvm_pgtable *pgt) >> +{ >> +    stage2_destroy_range(pgt, kvm_pgtable_stage2_destroy_range); >> +    kvm_pgtable_stage2_destroy_pgd(pgt); >> +} >> + >> +static void pkvm_stage2_destroy(struct kvm_pgtable *pgt) >> +{ >> +    stage2_destroy_range(pgt, pkvm_pgtable_stage2_destroy_range); >> +    pkvm_pgtable_stage2_destroy_pgd(pgt); >> +} >> + >>   static void kvm_stage2_destroy(struct kvm_pgtable *pgt) >>   { >> -    unsigned int ia_bits = VTCR_EL2_IPA(pgt->mmu->vtcr); >> +    struct kvm *kvm = kvm_s2_mmu_to_kvm(pgt->mmu); >>   -    stage2_destroy_range(pgt, 0, BIT(ia_bits)); >> -    KVM_PGT_FN(kvm_pgtable_stage2_destroy_pgd)(pgt); >> +    kvm->arch.vm_s2_ops->vm_stage2_destroy(pgt); >>   } >>     /** >> @@ -3146,6 +3159,7 @@ long kvm_arch_vcpu_pre_fault_memory(struct >> kvm_vcpu *vcpu, >>   } >>     static const struct kvm_vm_s2_ops protected_pkvm_vm_s2_ops = { >> +    .vm_stage2_destroy        = pkvm_stage2_destroy, >>       .vm_flush_remote_tlbs        = pkvm_flush_remote_tlbs, >>       .vm_flush_remote_tlbs_range    = pkvm_flush_remote_tlbs_range, >>       .vm_age_gfn            = no_age_gfn, >> @@ -3155,6 +3169,7 @@ static const struct kvm_vm_s2_ops >> protected_pkvm_vm_s2_ops = { >>   }; >>     static const struct kvm_vm_s2_ops pkvm_vm_s2_ops = { >> +    .vm_stage2_destroy        = pkvm_stage2_destroy, >>       .vm_flush_remote_tlbs        = pkvm_flush_remote_tlbs, >>       .vm_flush_remote_tlbs_range    = pkvm_flush_remote_tlbs_range, >>       .vm_age_gfn            = pkvm_age_gfn, >> @@ -3164,6 +3179,7 @@ static const struct kvm_vm_s2_ops pkvm_vm_s2_ops >> = { >>   }; >>     static const struct kvm_vm_s2_ops kvm_default_vm_s2_ops = { >> +    .vm_stage2_destroy        = kvm_vm_stage2_destroy, >>       .vm_flush_remote_tlbs        = kvm_vm_flush_remote_tlbs, >>       .vm_flush_remote_tlbs_range    = kvm_vm_flush_remote_tlbs_range, >>       .vm_age_gfn            = kvm_vm_age_gfn, >