Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8375BC433EF for ; Tue, 7 Dec 2021 14:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238129AbhLGOu7 (ORCPT ); Tue, 7 Dec 2021 09:50:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbhLGOu7 (ORCPT ); Tue, 7 Dec 2021 09:50:59 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35D5C061574 for ; Tue, 7 Dec 2021 06:47:28 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id z18so17405295iof.5 for ; Tue, 07 Dec 2021 06:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a4XDkf6jRy1vMACR88gzWrg9j5LSKF31lp3FcsFdRpc=; b=e0rzYW5Iwwfb+4uDbxdWA+e1W9+Z4bqBBG9ibsB6m6GwS/nRfQlc3O9iElDSU57Jsa YjEeikN4/W8Ul4mPDI+l4OOjG9ggQFOeDdkcLbKzQNjAk9tzKmNTUj7h+PlCmATp/ue0 AF2r6++TlLIh1xf0W41Y7ggCDL+wTCAdmkeNM30ciVWpNq54WdceXI6Vyz5+m3NJ/T35 YhGnxJ8j5dPQ3X0Xv29DevDnnBoi754wNgJP3P5AqnESIK+DOWszx196ROgHZYOPzBku P/gw0LaES4kcoicSd6uunUs4H6QTmBnQjJZg1mA4JbYSUl3GVBig7omotr/MGRvlHUGP 7W4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=a4XDkf6jRy1vMACR88gzWrg9j5LSKF31lp3FcsFdRpc=; b=WykeTUsQMhrGXtbRU6oITFPMlHArm8BKG+d12qfVi2YNTsUul0MsJiabDchFaZX7Ms bt9nU2MUW0NXcXRWTqkRXd+6N+sNR+GiPP0K+ub9OxAXZLr9lqgKEjnkYbvG0Suz3umJ 3oPt4vHKxe9+aIljh+Uv5lgPo3mZ2ADK3EhZu5xwKGtNAIwahLMDDXk4Chgxi5N/ilUi wKblIjlGNkeR2AjKCwTTTq2/CyNRAhK1GnadHuGVkuSYS+rj+pamzvX+5StYaxy2JRMR 9p4wPTIMeSU4EYvd6WvrqiePPr+x+7LnhU8CDz3uPWAC2mzbQRPca+jh/r52SIcmRQH2 3lnQ== X-Gm-Message-State: AOAM5333eOGpELBNfLaXgxurlxej+FMyzPWNao1bLKPeNDX8nT2bGdAE kfEEEZCDXymZ1QPdhAIjw7gO6+tbu/cIfKOCKRJJ9w== X-Google-Smtp-Source: ABdhPJwnGMcu2rI4em8EZHcweqOJLB9x+xndjQX7DQQZmXunsP8UoC+LbyZ5mPLcHi2luPhvoZ9SUSPZZw5WlhZST3I= X-Received: by 2002:a05:6638:150d:: with SMTP id b13mr50067001jat.101.1638888447871; Tue, 07 Dec 2021 06:47:27 -0800 (PST) MIME-Version: 1.0 References: <20211201170411.1561936-1-qperret@google.com> <20211201170411.1561936-7-qperret@google.com> In-Reply-To: <20211201170411.1561936-7-qperret@google.com> From: Andrew Walbran Date: Tue, 7 Dec 2021 14:47:14 +0000 Message-ID: Subject: Re: [PATCH v3 06/15] KVM: arm64: Implement kvm_pgtable_hyp_unmap() at EL2 To: Quentin Perret Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000cab34c05d28f73e8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --000000000000cab34c05d28f73e8 Content-Type: text/plain; charset="UTF-8" On Wed, 1 Dec 2021 at 17:04, 'Quentin Perret' via kernel-team wrote: > > From: Will Deacon > > Implement kvm_pgtable_hyp_unmap() which can be used to remove hypervisor > stage-1 mappings at EL2. > > Signed-off-by: Will Deacon > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_pgtable.h | 21 ++++++++++ > arch/arm64/kvm/hyp/pgtable.c | 63 ++++++++++++++++++++++++++++ > 2 files changed, 84 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > index 027783829584..9d076f36401d 100644 > --- a/arch/arm64/include/asm/kvm_pgtable.h > +++ b/arch/arm64/include/asm/kvm_pgtable.h > @@ -251,6 +251,27 @@ void kvm_pgtable_hyp_destroy(struct kvm_pgtable *pgt); > int kvm_pgtable_hyp_map(struct kvm_pgtable *pgt, u64 addr, u64 size, u64 phys, > enum kvm_pgtable_prot prot); > > +/** > + * kvm_pgtable_hyp_unmap() - Remove a mapping from a hypervisor stage-1 page-table. > + * @pgt: Page-table structure initialised by kvm_pgtable_hyp_init(). > + * @addr: Virtual address from which to remove the mapping. > + * @size: Size of the mapping. > + * > + * The offset of @addr within a page is ignored, @size is rounded-up to > + * the next page boundary and @phys is rounded-down to the previous page > + * boundary. > + * > + * TLB invalidation is performed for each page-table entry cleared during the > + * unmapping operation and the reference count for the page-table page > + * containing the cleared entry is decremented, with unreferenced pages being > + * freed. The unmapping operation will stop early if it encounters either an > + * invalid page-table entry or a valid block mapping which maps beyond the range > + * being unmapped. How is the caller expected to break up the block mapping? Why not handle that within this function? > > + * > + * Return: Number of bytes unmapped, which may be 0. > + */ > +u64 kvm_pgtable_hyp_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size); > + > /** > * kvm_get_vtcr() - Helper to construct VTCR_EL2 > * @mmfr0: Sanitized value of SYS_ID_AA64MMFR0_EL1 register. > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 768a58835153..6ad4cb2d6947 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -463,6 +463,69 @@ int kvm_pgtable_hyp_map(struct kvm_pgtable *pgt, u64 addr, u64 size, u64 phys, > return ret; > } > > +struct hyp_unmap_data { > + u64 unmapped; > + struct kvm_pgtable_mm_ops *mm_ops; > +}; > + > +static int hyp_unmap_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, > + enum kvm_pgtable_walk_flags flag, void * const arg) > +{ > + kvm_pte_t pte = *ptep, *childp = NULL; > + u64 granule = kvm_granule_size(level); > + struct hyp_unmap_data *data = arg; > + struct kvm_pgtable_mm_ops *mm_ops = data->mm_ops; > + > + if (!kvm_pte_valid(pte)) > + return -EINVAL; > + > + if (kvm_pte_table(pte, level)) { > + childp = kvm_pte_follow(pte, mm_ops); > + > + if (mm_ops->page_count(childp) != 1) > + return 0; > + > + kvm_clear_pte(ptep); > + dsb(ishst); > + __tlbi_level(vae2is, __TLBI_VADDR(addr, 0), level); > + } else { > + if (end - addr < granule) > + return -EINVAL; > + > + kvm_clear_pte(ptep); > + dsb(ishst); > + __tlbi_level(vale2is, __TLBI_VADDR(addr, 0), level); > + data->unmapped += granule; > + } > + > + dsb(ish); > + isb(); > + mm_ops->put_page(ptep); > + > + if (childp) > + mm_ops->put_page(childp); > + > + return 0; > +} > + > +u64 kvm_pgtable_hyp_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size) > +{ > + struct hyp_unmap_data unmap_data = { > + .mm_ops = pgt->mm_ops, > + }; > + struct kvm_pgtable_walker walker = { > + .cb = hyp_unmap_walker, > + .arg = &unmap_data, > + .flags = KVM_PGTABLE_WALK_LEAF | KVM_PGTABLE_WALK_TABLE_POST, > + }; > + > + if (!pgt->mm_ops->page_count) > + return 0; > + > + kvm_pgtable_walk(pgt, addr, size, &walker); > + return unmap_data.unmapped; > +} > + > int kvm_pgtable_hyp_init(struct kvm_pgtable *pgt, u32 va_bits, > struct kvm_pgtable_mm_ops *mm_ops) > { > -- > 2.34.0.rc2.393.gf8c9666880-goog > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. > --000000000000cab34c05d28f73e8 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIPmgYJKoZIhvcNAQcCoIIPizCCD4cCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg ggz0MIIEtjCCA56gAwIBAgIQeAMYYHb81ngUVR0WyMTzqzANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFsU2lnbjAeFw0yMDA3MjgwMDAwMDBaFw0yOTAzMTgwMDAwMDBaMFQxCzAJBgNVBAYT AkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSowKAYDVQQDEyFHbG9iYWxTaWduIEF0bGFz IFIzIFNNSU1FIENBIDIwMjAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvLe9xPU9W dpiHLAvX7kFnaFZPuJLey7LYaMO8P/xSngB9IN73mVc7YiLov12Fekdtn5kL8PjmDBEvTYmWsuQS 6VBo3vdlqqXZ0M9eMkjcKqijrmDRleudEoPDzTumwQ18VB/3I+vbN039HIaRQ5x+NHGiPHVfk6Rx c6KAbYceyeqqfuJEcq23vhTdium/Bf5hHqYUhuJwnBQ+dAUcFndUKMJrth6lHeoifkbw2bv81zxJ I9cvIy516+oUekq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