Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4005088rwo; Mon, 24 Jul 2023 22:05:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlFqnhBegaaV6kUcBp5xc53MejpJlDlYOtjqpUfpbCW7ie858dB0pxk1olzdCUe6/a4LY4dD X-Received: by 2002:a17:90b:1b11:b0:25e:a8ab:9157 with SMTP id nu17-20020a17090b1b1100b0025ea8ab9157mr11318598pjb.22.1690261518832; Mon, 24 Jul 2023 22:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690261518; cv=none; d=google.com; s=arc-20160816; b=Xu2ke2bCb9rMQvqmXAPKhjj2s5CkV4rH5V7ftcpkHX6KgaUaDO2kTApetWcHrCuWQl 087hNIu2R3R9lPsWiPRQQTHmhPSYf1ttx8hpnoh0nqK5ieyC1caCvxqGY3+YPGdbnBSW xc6qYK9qbBN1lGKKkqiUhrjeZ9+SSpBSYwV55Y4QF5ZymtHbUsnoGx9/N+9czu0I+kin GGWN/EqdmC4ZthdvbNRYGQgEEKgLP5mLV9TESnq0hARB/ZwR3UdPl+FpV7MJnWwzPPqt OCVIwJznH0cUAtBy9tTycMI7hR/WBt/7SpQ4n9Kq43BSV1AUrqD3qy73vIXxu23AZzNu n+DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=fqZhhu1PD0i+4g0TKatkfYBNa6Ta8n6gN3J4CmEr6Ls=; fh=dI58ZAAIKz8+ZqZGBThi5fvNVEQN0zC6wQN9uYYVUVE=; b=aIs6wdqYu2XBF4NH3pnNOVlhrr8ZFj/pwNuIjCV5a3cq505vmrPg0vnaO2SNuI3DD7 qATo1EJ2m5Vv4pFMWBptFjgK8F6FM982jxjOsaERrb99z5rZWwjhA0s/1trVDpGLTkxq e9vDAjj45prxdy3rePTJ98VhcRg2er5901B9a4DnvPJTfTzmAwXJpd7iBuMji78C9Cqj 5RBoCGEMp/ZpC1eapePV9tEqRbqLiw3prXaqsmYO7OoWJGoDxQ7p8FtXdXSRKe91/kzd AcI3swj7F6/bZ0h1/tOq4QKpHWmr65XQz+/DaQsv/kf+rabbIFD2by6xoEORI6coTK9h prQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=C+5P9aFT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu10-20020a17090b1b0a00b0026764aac11bsi13915649pjb.29.2023.07.24.22.05.06; Mon, 24 Jul 2023 22:05:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=C+5P9aFT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbjGYDmM (ORCPT + 99 others); Mon, 24 Jul 2023 23:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjGYDmG (ORCPT ); Mon, 24 Jul 2023 23:42:06 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 729091725; Mon, 24 Jul 2023 20:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1690256521; bh=fqZhhu1PD0i+4g0TKatkfYBNa6Ta8n6gN3J4CmEr6Ls=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=C+5P9aFTM3Wjbzg0OpyrP37MMtgmILxrNCL0SBekDUGnLmL2hbYoY/Whcme+sowb+ jj0g8pEh3Ja+StlLshqWdLwAovENk3HP9UoEWOZg5dYPNwU82WAsrEYjqFeIQeIe/Q aWyqJDMnour5OZE732UMTJFRgFodBjF+n6U9w/9phMH2/C6BChsF7G9XJJtu0dFlj8 hjM9emqPQqJJDDkxyaLgOk1nc8xDUCmEqzoXxwIw86tbWobOCe5SbyOHqATQBKlgxl aXy3n1WqIiGtc2/Z2uFQC5qdhp/sG1INDLRVaLZ5lkrlMPTpl+l8bbtjUNgJ1GbqDQ jqtHWF6biKMbg== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4R92s426wJz4wxy; Tue, 25 Jul 2023 13:42:00 +1000 (AEST) From: Michael Ellerman To: Alistair Popple , akpm@linux-foundation.org Cc: ajd@linux.ibm.com, catalin.marinas@arm.com, fbarrat@linux.ibm.com, iommu@lists.linux.dev, jgg@ziepe.ca, jhubbard@nvidia.com, kevin.tian@intel.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, nicolinc@nvidia.com, npiggin@gmail.com, robin.murphy@arm.com, seanjc@google.com, will@kernel.org, x86@kernel.org, zhi.wang.linux@gmail.com, Alistair Popple Subject: Re: [PATCH v2 3/5] mmu_notifiers: Call invalidate_range() when invalidating TLBs In-Reply-To: <8f293bb51a423afa71ddc3ba46e9f323ee9ffbc7.1689768831.git-series.apopple@nvidia.com> References: <8f293bb51a423afa71ddc3ba46e9f323ee9ffbc7.1689768831.git-series.apopple@nvidia.com> Date: Tue, 25 Jul 2023 13:41:59 +1000 Message-ID: <87y1j4y7w8.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Alistair Popple writes: > The invalidate_range() is going to become an architecture specific mmu > notifier used to keep the TLB of secondary MMUs such as an IOMMU in > sync with the CPU page tables. Currently it is called from separate > code paths to the main CPU TLB invalidations. This can lead to a > secondary TLB not getting invalidated when required and makes it hard > to reason about when exactly the secondary TLB is invalidated. > > To fix this move the notifier call to the architecture specific TLB > maintenance functions for architectures that have secondary MMUs > requiring explicit software invalidations. > > This fixes a SMMU bug on ARM64. On ARM64 PTE permission upgrades > require a TLB invalidation. This invalidation is done by the > architecutre specific ptep_set_access_flags() which calls ^ architecture > flush_tlb_page() if required. However this doesn't call the notifier > resulting in infinite faults being generated by devices using the SMMU > if it has previously cached a read-only PTE in it's TLB. > > Moving the invalidations into the TLB invalidation functions ensures > all invalidations happen at the same time as the CPU invalidation. The > architecture specific flush_tlb_all() routines do not call the > notifier as none of the IOMMUs require this. > > Signed-off-by: Alistair Popple > Suggested-by: Jason Gunthorpe > ... > diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c b/arch/powerpc/mm/book3s64/radix_tlb.c > index 0bd4866..9724b26 100644 > --- a/arch/powerpc/mm/book3s64/radix_tlb.c > +++ b/arch/powerpc/mm/book3s64/radix_tlb.c > @@ -752,6 +752,8 @@ void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmadd > return radix__local_flush_hugetlb_page(vma, vmaddr); > #endif > radix__local_flush_tlb_page_psize(vma->vm_mm, vmaddr, mmu_virtual_psize); > + mmu_notifier_invalidate_range(vma->vm_mm, vmaddr, > + vmaddr + mmu_virtual_psize); > } > EXPORT_SYMBOL(radix__local_flush_tlb_page); I think we can skip calling the notifier there? It's explicitly a local flush. cheers