From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB960C38145 for ; Fri, 2 Sep 2022 14:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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-Owner; bh=0WQ1oEoktJtGlUs5JehmDRaQ8n5m6Pqu6SAvzDeE7Ig=; b=QbbWrZs7zfD4Uf WD7lEoLNoLHBpL4PgwtV6kNAlLZWzarZ7xDB5lMXMJ6BzhlxaLvewgv44lPWq4/oad1f8NFTc83zK BaCeelZ5ifmt9FUlw2p+kw4Blh+YXKhDqH9MLCCDTP2SFRcWnvu67Uq9xFl0ZpHVeHFZxf/z9/Pen w2j6TtkUyhy00QvQOdEeUqCJ/A5x9gRXD65TMxel6VI6V7cXY0MgUXXvedFz/uiXO5JgFmfQkKpee c31Ut93BgIIRBRiWDbJZw5YL/N6hYRwOrI1Erzmt9QN48UXDGdw2ZOi5/0WMsoJLhVWlHyfw2Ljdy LbDoU4sw/ny8EGjfAYNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU7xp-005kR8-7N; Fri, 02 Sep 2022 14:48:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU7xM-005k5A-OZ for linux-arm-kernel@lists.infradead.org; Fri, 02 Sep 2022 14:47:43 +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 A1DAAED1; Fri, 2 Sep 2022 07:47:40 -0700 (PDT) Received: from [10.57.45.3] (unknown [10.57.45.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5DCF83F766; Fri, 2 Sep 2022 07:47:32 -0700 (PDT) Message-ID: <54b979fc-5cb3-6eb4-47d4-e07e99359db9@arm.com> Date: Fri, 2 Sep 2022 15:47:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3 2/7] KVM: arm64: Simplify the sanitise_mte_tags() logic Content-Language: en-GB To: Peter Collingbourne , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Catalin Marinas , Cornelia Huck , Will Deacon , Marc Zyngier , Evgenii Stepanov , kvm@vger.kernel.org, Vincenzo Frascino References: <20220810193033.1090251-1-pcc@google.com> <20220810193033.1090251-3-pcc@google.com> From: Steven Price In-Reply-To: <20220810193033.1090251-3-pcc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220902_074740_967703_C922DC58 X-CRM114-Status: GOOD ( 28.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/08/2022 20:30, Peter Collingbourne wrote: > From: Catalin Marinas > > Currently sanitise_mte_tags() checks if it's an online page before > attempting to sanitise the tags. Such detection should be done in the > caller via the VM_MTE_ALLOWED vma flag. Since kvm_set_spte_gfn() does > not have the vma, leave the page unmapped if not already tagged. Tag > initialisation will be done on a subsequent access fault in > user_mem_abort(). Looks correct to me. Reviewed-by: Steven Price > Signed-off-by: Catalin Marinas > Cc: Will Deacon > Cc: Marc Zyngier > Cc: Steven Price > Cc: Peter Collingbourne > --- > arch/arm64/kvm/mmu.c | 40 +++++++++++++++------------------------- > 1 file changed, 15 insertions(+), 25 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index c9012707f69c..1a3707aeb41f 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1056,23 +1056,14 @@ static int get_vma_page_shift(struct vm_area_struct *vma, unsigned long hva) > * - mmap_lock protects between a VM faulting a page in and the VMM performing > * an mprotect() to add VM_MTE > */ > -static int sanitise_mte_tags(struct kvm *kvm, kvm_pfn_t pfn, > - unsigned long size) > +static void sanitise_mte_tags(struct kvm *kvm, kvm_pfn_t pfn, > + unsigned long size) > { > unsigned long i, nr_pages = size >> PAGE_SHIFT; > - struct page *page; > + struct page *page = pfn_to_page(pfn); > > if (!kvm_has_mte(kvm)) > - return 0; > - > - /* > - * pfn_to_online_page() is used to reject ZONE_DEVICE pages > - * that may not support tags. > - */ > - page = pfn_to_online_page(pfn); > - > - if (!page) > - return -EFAULT; > + return; > > for (i = 0; i < nr_pages; i++, page++) { > if (!page_mte_tagged(page)) { > @@ -1080,8 +1071,6 @@ static int sanitise_mte_tags(struct kvm *kvm, kvm_pfn_t pfn, > set_page_mte_tagged(page); > } > } > - > - return 0; > } > > static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > @@ -1092,7 +1081,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > bool write_fault, writable, force_pte = false; > bool exec_fault; > bool device = false; > - bool shared; > unsigned long mmu_seq; > struct kvm *kvm = vcpu->kvm; > struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; > @@ -1142,8 +1130,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > vma_shift = get_vma_page_shift(vma, hva); > } > > - shared = (vma->vm_flags & VM_SHARED); > - > switch (vma_shift) { > #ifndef __PAGETABLE_PMD_FOLDED > case PUD_SHIFT: > @@ -1264,12 +1250,13 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > > if (fault_status != FSC_PERM && !device && kvm_has_mte(kvm)) { > /* Check the VMM hasn't introduced a new VM_SHARED VMA */ > - if (!shared) > - ret = sanitise_mte_tags(kvm, pfn, vma_pagesize); > - else > + if ((vma->vm_flags & VM_MTE_ALLOWED) && > + !(vma->vm_flags & VM_SHARED)) { > + sanitise_mte_tags(kvm, pfn, vma_pagesize); > + } else { > ret = -EFAULT; > - if (ret) > goto out_unlock; > + } > } > > if (writable) > @@ -1491,15 +1478,18 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) > bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range) > { > kvm_pfn_t pfn = pte_pfn(range->pte); > - int ret; > > if (!kvm->arch.mmu.pgt) > return false; > > WARN_ON(range->end - range->start != 1); > > - ret = sanitise_mte_tags(kvm, pfn, PAGE_SIZE); > - if (ret) > + /* > + * If the page isn't tagged, defer to user_mem_abort() for sanitising > + * the MTE tags. The S2 pte should have been unmapped by > + * mmu_notifier_invalidate_range_end(). > + */ > + if (kvm_has_mte(kvm) && !page_mte_tagged(pfn_to_page(pfn))) > return false; > > /* _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel