From patchwork Fri Jul 7 07:14:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13304499 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 9F269EB64D9 for ; Fri, 7 Jul 2023 07:15:40 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HsDs3IbNXHslluz4B+Qib7fG+VC/r9pbXvTUAImqkxw=; b=m7OxY4UyUSUofh G7LvjDQJ5+1FplE+mOLFWx1ADJTWjZxklJNfkRp7mLk0UbUnpUFr45oYav+i/d7vkw4WPz31Zt4Dr D9T2tDSz3ewdN5jbJpq+EjlZQc4PWZvdJWojSJmG8pVQ0BvqdQjIL2Mx9eFRFtSOdZuBFseWU4Og7 /MNZY5JDSCfhF1eqVeoy8G9IEj6xfHHxPooyKGrjWLLMwBYxrl3h9aAx0ZuDenq2P2lxnDMUGULPb 3ZwmeoMzPE1A/Kl2aWm6c5uyfT13u79VuAUBu8fmb0uzE/hrXdTNmeuQ1rrLGTgY0gs3kDRAwPACK NIQBvc/Xn4+HCKqXbGjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHfgL-003q9v-1A; Fri, 07 Jul 2023 07:15:09 +0000 Received: from mail-bn8nam12on2060e.outbound.protection.outlook.com ([2a01:111:f400:fe5b::60e] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHfgH-003q7X-1J for linux-arm-kernel@lists.infradead.org; Fri, 07 Jul 2023 07:15:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/K54ONH+C4hy2b9tyT5x8YP/nknwhSILRIKBUVWc7tjZP38igZLOCvcdzuA16S00RzgWDu0CvMsK9FT68oeorFr10OFE7CVG5xBYuhq3sAIz0Td7atsxT8vX5os2pvMBK8mWR2ZKo32YFjoMdUnbKwhRXdCJdBRjCedSpevKyaROk5RXzFoB2rm8FU4onBKdm6aXT6nORFh0DGRI/1ROupzM/kKJeYIaU8XRk8FXqaCmB/xjO+hu1BQ/wnk+BQxBLHZvwCuZbBGhrKX9SbM1FI2KTBuMdJPo2mBl0KanGbkQ1j7Ih4HVwalk39e0r2hK4LfpMGEYfaeM8ZRLtas+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7Sgw6A8l9bBmw2H/FjPUicVghu7vSsXL6mgL4AvDIH0=; b=iIL2Vowy7tkzD4rPql+xCYaRYkJhJkxT4qmJEJMqTu67he2JpgmSQ7qsnOi3UOytmFXI/fzQQpUaNljKwf3dS3NWQmGOC56IXFBFHmT+dw4OSRDoB69ru+rnzFA0hGj/Whbf4BzS2N/24N5WcMIMsgOhgMOOi16Cus2MeTX2nZrokJ90G0ROVG6aFWjKbWBYkal86avRFi0YN5FmJ2XI9hibMhVNO2VkPqCOVj1dZ5dXzQpabGqyqLir7hHj3cHFotdRd2wv5PCBd5fh356+S+BxcoOrFQ97LHA8aplsH5KExa9wIAAfxyKqRXuqk/z2adA6SM9yCchTQbFcC48QyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7Sgw6A8l9bBmw2H/FjPUicVghu7vSsXL6mgL4AvDIH0=; b=ulKP5n0f73JQwqjIYiFpM4yXa0b9aBa/Wizqb2bPna9LCMi2H+iDHaXGH5iwevEBKhwAuVuiBgCqG/bVANveMr8Gy3VTw8p18mWxWZO2AvEc1WD/J5L7iRzNFShJe+ASLvSw4ny5Ig26Oka1BX6Ahx27PZRlKowgpN2jwNiuZbvTr/KN0SZUwlVWN3htpN/KGDN1amsfDa2QX+PMgO3SqIFjSyjc35MsSUflAiO1BPeUH2GQYx51nhhc1VdChn7UiuvXMCi2gnyfmK+qWBUSR5pT3S7oeR/Pv+ZUcQ0WrMdsxSaGJQkCIdmI1SHux1cGua8PKCnz/cUiTm5Ud6jEug== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by SA0PR12MB7075.namprd12.prod.outlook.com (2603:10b6:806:2d5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Fri, 7 Jul 2023 07:14:59 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7%6]) with mapi id 15.20.6565.025; Fri, 7 Jul 2023 07:14:59 +0000 From: Alistair Popple To: akpm@linux-foundation.org Cc: jgg@ziepe.ca, npiggin@gmail.com, catalin.marinas@arm.com, jhubbard@nvidia.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nicolinc@nvidia.com, robin.murphy@arm.com, seanjc@google.com, will@kernel.org, zhi.wang.linux@gmail.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, rtummala@nvidia.com, kevin.tian@intel.com, iommu@lists.linux.dev, x86@kernel.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, Alistair Popple Subject: [RFC PATCH v2 3/3] mmu_notifiers: Don't invalidate secondary TLBs as part of mmu_notifier_invalidate_range_end() Date: Fri, 7 Jul 2023 17:14:25 +1000 Message-Id: <1fd481392ca173c301de3edef4dcc79dea0619c2.1688714027.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0097.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:204::7) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|SA0PR12MB7075:EE_ X-MS-Office365-Filtering-Correlation-Id: 300ca14e-eff8-4e54-8aa7-08db7eb9dfd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KToJcQD8Z5SdXKKM0fLqXJ519Q1H3jjjdnLVpwGUiqHz3JsNsw1RITRwI2bmjHZxcg8QfH1ar9/tYrKKnP771IsEC69PM9TaNI8OmRSPGH9zdAQcEf2pHV/Gd3ueQAgQ8fcU2LV/yYTbIh5G+fV71/OoU+zPVSGwLphHOh3VnRUTaBADM87dyRjIFm78e+861K6/rKSOOQk+UjWbLc+T1njQyD915aZpSe/5be3a5i0pxiTaWrb0iXtVhpYlgsuzFBFOGSGXpQt6E54ARctabPTj1Uw/8+dkTdJfB176r2qGWBzlnohdkpqHaRkgH7IBYsIPjbCdsAZDSNhdgMalTR8xVz+CZXsbt5f/rVV72N0lSPqDvFjoAOrfIS3h837VIVUovukuc1tGUj5PC0TEeKOAfQKiBcm6yEZ+GwBGwEXQ3ozkxB3sP4PMafBXTzONeienjbj4JBN8sHP5PTNd5Er+LBKIwBmbtdKq4h8oQTWufZgaNe8Fd7Mf8TNVG1IamJvE54stkl5y8V/G7xMfYaUdgBz1nvA3jG9iJwrypUc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199021)(6916009)(38100700002)(66476007)(4326008)(66946007)(66556008)(2616005)(6666004)(186003)(6486002)(36756003)(107886003)(86362001)(478600001)(6506007)(26005)(6512007)(8676002)(8936002)(30864003)(5660300002)(7416002)(41300700001)(2906002)(316002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XELrW64RTgdJphHb1XHlIvFI2BM3JhssINlE7O4aAxU4XJt3DAYxf1AtCR5oYhfX+xiMCOlTRfMACFybgznROB9x7AYPAChGiVapFEmlpLa1Fx1oZvpptLZP5xvmhbtwe6P7bODhkFYTGiQE73ggpFeenChnGxwN7+oOSpwBug7oL2dCwwzxGqFatTY8tqVkCwyd2PeVAEE7IwUmIxIiRG8snTsx73pupm6YTRX7BTGTdaebiq8Tedv7yx4tXQA7q3mhGf61qriZ/PX6deJ07yaa0i3qTUQI2flPBdLtfY1QReh3v3HvuhEefImK/O5ji5/siOQaMy346ZigFNDtcIaeLs/29rVrohRwijUccF6ORB5ZrTJpXyEkO/1Y3kRPS+e7l/sA2wA+RqW4lfSLKJGJpFw/vhgjp+sKaTzKscr85moJeqypIRal5ax5STd0h/pwx3P0O8uCIU7NfljeWtvzaLhuO/hnXzs5b6lUmEwyQFanlMwsJnLBH68tRnSqSEnE9Mmsfpg1qNEeS8RjFOxthA2hsPNJ7ci4urw6G2R5ZMW26q/50TqNBeFL0H1Hr8yfCDz7H12yOufIKvdmJMriUsj66SAdAK52oY5zH3Ozsw63kEL4LVntfLLxtQ7sIp0HgNJIvv93nuSjD/soManay4KaOXZeSt/Oq5u0XfdseAYQEV8pxC6vhWedTxuAV/OODhsZsgB0xOoNhM4iz8yoD3Ic2tn8Mj8fGMw8JVE1W2Zzc41fjzwF0JQVbzamwgisZtr0CtAZwALOhi8yPotJFXiadNrgoYx5VtHQnCj436vyGwwANqdhcjNU717js6k17roQSfxG20pL/RRQjJnMnVnp/uZtXDrQUIPgqtYxbqYFqCiGoYKO4OMcHx+cFA4WKkPzknuOT32SCVSliJpJUbVH0aSSZxo40HIuNF9pcvvixaYIOIGuRZ5ETCAzsE79njfBORsTwRflybjKr+/LwK/DCaVMxTLhHz/zp1QpODtU1X9BwFh0TuDvMeQKDCEgptkdXv0mVm3jH3+BxpeXrgeVWEkXesopsJ+O9GFTs8VD8NNzkO6KEq6atAl1Fe5ElnNI+PRlwvpYkwhqJqBQCoks99xvEghJupVU13tU+K/x9LOXcrt7dVEEKjuY6GYqmP4K/OMdArQrwHwagzbET3Cefz9Co4hKdKOl7i4UrTD1lrD051wpoTboP84XldfdJuGrLSZEsTh2xHUbYtsnphUodUbKDPE2vU/CYQwsKSgc51DI1qFO1suSDrD48VFmX1tyKEBFtwfW41/8L0+eoN9qfxBQ6+NOwEUpjvQMqYHylXTsInt7s0u/tN5BgdAzaxfAHYM1PvYFOzHaDcWwUz0PuOCyUBDU7YtuKlrjgTZLH8N9JLBZRdY6f30EiCQ28EWzrKd9onw4xoV1NHix+d4kKlbm39joQjaq0d6vDvxtP985MjATtqPXLlynQKPPFWADTmHfXGiIh/l3WiFX7z/zg2jrd8J5GVLFXcHT7eX+vfTialp4IhqfpRuNVOm4aGBIgErOnl3p8k2XfOYKvncx5AW4aJpldFdDGw0EjaQWy/lOOPhWhJi0QGyp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 300ca14e-eff8-4e54-8aa7-08db7eb9dfd5 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2023 07:14:59.3764 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U4P1vmAhyAikg3BR91McV+g1IeyjogpyRaScLwWIcof05Gu6t0c8r5hGiT/zPoCX0OW0IQmBdMjnyGFalBRBRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7075 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230707_001505_521906_CE506EE3 X-CRM114-Status: GOOD ( 18.23 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Secondary TLBs are now invalidated from the architecture specific TLB invalidation functions. Therefore there is no need to explicitly notify or invalidate as part of the range end functions. This means we can remove mmu_notifier_invalidate_range_end_only() and some of the ptep_*_notify() functions. Signed-off-by: Alistair Popple --- include/linux/mmu_notifier.h | 56 +------------------------------------ kernel/events/uprobes.c | 2 +- mm/huge_memory.c | 25 ++--------------- mm/hugetlb.c | 2 +- mm/memory.c | 8 +---- mm/migrate_device.c | 9 +----- mm/mmu_notifier.c | 25 ++--------------- mm/rmap.c | 42 +---------------------------- 8 files changed, 14 insertions(+), 155 deletions(-) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index a4bc818..6e3c857 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -395,8 +395,7 @@ extern int __mmu_notifier_test_young(struct mm_struct *mm, extern void __mmu_notifier_change_pte(struct mm_struct *mm, unsigned long address, pte_t pte); extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r); -extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r, - bool only_end); +extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r); extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, unsigned long start, unsigned long end); extern bool @@ -481,14 +480,7 @@ mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) might_sleep(); if (mm_has_notifiers(range->mm)) - __mmu_notifier_invalidate_range_end(range, false); -} - -static inline void -mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) -{ - if (mm_has_notifiers(range->mm)) - __mmu_notifier_invalidate_range_end(range, true); + __mmu_notifier_invalidate_range_end(range); } static inline void mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, @@ -582,45 +574,6 @@ static inline void mmu_notifier_range_init_owner( __young; \ }) -#define ptep_clear_flush_notify(__vma, __address, __ptep) \ -({ \ - unsigned long ___addr = __address & PAGE_MASK; \ - struct mm_struct *___mm = (__vma)->vm_mm; \ - pte_t ___pte; \ - \ - ___pte = ptep_clear_flush(__vma, __address, __ptep); \ - mmu_notifier_arch_invalidate_secondary_tlbs(___mm, ___addr, \ - ___addr + PAGE_SIZE); \ - \ - ___pte; \ -}) - -#define pmdp_huge_clear_flush_notify(__vma, __haddr, __pmd) \ -({ \ - unsigned long ___haddr = __haddr & HPAGE_PMD_MASK; \ - struct mm_struct *___mm = (__vma)->vm_mm; \ - pmd_t ___pmd; \ - \ - ___pmd = pmdp_huge_clear_flush(__vma, __haddr, __pmd); \ - mmu_notifier_arch_invalidate_secondary_tlbs(___mm, ___haddr, \ - ___haddr + HPAGE_PMD_SIZE); \ - \ - ___pmd; \ -}) - -#define pudp_huge_clear_flush_notify(__vma, __haddr, __pud) \ -({ \ - unsigned long ___haddr = __haddr & HPAGE_PUD_MASK; \ - struct mm_struct *___mm = (__vma)->vm_mm; \ - pud_t ___pud; \ - \ - ___pud = pudp_huge_clear_flush(__vma, __haddr, __pud); \ - mmu_notifier_arch_invalidate_secondary_tlbs(___mm, ___haddr, \ - ___haddr + HPAGE_PUD_SIZE); \ - \ - ___pud; \ -}) - /* * set_pte_at_notify() sets the pte _after_ running the notifier. * This is safe to start by updating the secondary MMUs, because the primary MMU @@ -711,11 +664,6 @@ void mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) { } -static inline void -mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) -{ -} - static inline void mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, unsigned long start, unsigned long end) { diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index f0ac5b8..3048589 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -193,7 +193,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, } flush_cache_page(vma, addr, pte_pfn(ptep_get(pvmw.pte))); - ptep_clear_flush_notify(vma, addr, pvmw.pte); + ptep_clear_flush(vma, addr, pvmw.pte); if (new_page) set_pte_at_notify(mm, addr, pvmw.pte, mk_pte(new_page, vma->vm_page_prot)); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a232891..c80d0f9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2003,7 +2003,7 @@ static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud, count_vm_event(THP_SPLIT_PUD); - pudp_huge_clear_flush_notify(vma, haddr, pud); + pudp_huge_clear_flush(vma, haddr, pud); } void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, @@ -2023,11 +2023,7 @@ void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, out: spin_unlock(ptl); - /* - * No need to double call mmu_notifier->invalidate_range() callback as - * the above pudp_huge_clear_flush_notify() did already call it. - */ - mmu_notifier_invalidate_range_only_end(&range); + mmu_notifier_invalidate_range_end(&range); } #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ @@ -2094,7 +2090,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, count_vm_event(THP_SPLIT_PMD); if (!vma_is_anonymous(vma)) { - old_pmd = pmdp_huge_clear_flush_notify(vma, haddr, pmd); + old_pmd = pmdp_huge_clear_flush(vma, haddr, pmd); /* * We are going to unmap this huge page. So * just go ahead and zap it @@ -2304,20 +2300,7 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, out: spin_unlock(ptl); - /* - * No need to double call mmu_notifier->invalidate_range() callback. - * They are 3 cases to consider inside __split_huge_pmd_locked(): - * 1) pmdp_huge_clear_flush_notify() call invalidate_range() obvious - * 2) __split_huge_zero_page_pmd() read only zero page and any write - * fault will trigger a flush_notify before pointing to a new page - * (it is fine if the secondary mmu keeps pointing to the old zero - * page in the meantime) - * 3) Split a huge pmd into pte pointing to the same page. No need - * to invalidate secondary tlb entry they are all still valid. - * any further changes to individual pte will notify. So no need - * to call mmu_notifier->invalidate_range() - */ - mmu_notifier_invalidate_range_only_end(&range); + mmu_notifier_invalidate_range_end(&range); } void split_huge_pmd_address(struct vm_area_struct *vma, unsigned long address, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ba689e0..941a11c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5690,8 +5690,6 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, /* Break COW or unshare */ huge_ptep_clear_flush(vma, haddr, ptep); - mmu_notifier_arch_invalidate_secondary_tlbs(mm, range.start, - range.end); page_remove_rmap(&old_folio->page, vma, true); hugepage_add_new_anon_rmap(new_folio, vma, haddr); if (huge_pte_uffd_wp(pte)) diff --git a/mm/memory.c b/mm/memory.c index 0ae5947..5736367 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3149,7 +3149,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * that left a window where the new PTE could be loaded into * some TLBs while the old PTE remains in others. */ - ptep_clear_flush_notify(vma, vmf->address, vmf->pte); + ptep_clear_flush(vma, vmf->address, vmf->pte); folio_add_new_anon_rmap(new_folio, vma, vmf->address); folio_add_lru_vma(new_folio, vma); /* @@ -3195,11 +3195,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); } - /* - * No need to double call mmu_notifier->invalidate_range() callback as - * the above ptep_clear_flush_notify() did already call it. - */ - mmu_notifier_invalidate_range_only_end(&range); + mmu_notifier_invalidate_range_end(&range); if (new_folio) folio_put(new_folio); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 8365158..9ce8214 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -658,7 +658,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, if (flush) { flush_cache_page(vma, addr, pte_pfn(orig_pte)); - ptep_clear_flush_notify(vma, addr, ptep); + ptep_clear_flush(vma, addr, ptep); set_pte_at_notify(mm, addr, ptep, entry); update_mmu_cache(vma, addr, ptep); } else { @@ -754,13 +754,8 @@ static void __migrate_device_pages(unsigned long *src_pfns, src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; } - /* - * No need to double call mmu_notifier->invalidate_range() callback as - * the above ptep_clear_flush_notify() inside migrate_vma_insert_page() - * did already call it. - */ if (notified) - mmu_notifier_invalidate_range_only_end(&range); + mmu_notifier_invalidate_range_end(&range); } /** diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 34c5a84..42bcc0a 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -551,7 +551,7 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) static void mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, - struct mmu_notifier_range *range, bool only_end) + struct mmu_notifier_range *range) { struct mmu_notifier *subscription; int id; @@ -559,24 +559,6 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, id = srcu_read_lock(&srcu); hlist_for_each_entry_rcu(subscription, &subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { - /* - * Subsystems should register either invalidate_secondary_tlbs() - * or invalidate_range_start()/end() callbacks. - * - * We call invalidate_secondary_tlbs() here so that subsystems - * can use larger range based invalidations. In some cases - * though invalidate_secondary_tlbs() needs to be called while - * holding the page table lock. In that case call sites use - * mmu_notifier_invalidate_range_only_end() and we know it is - * safe to skip secondary TLB invalidation as it will have - * already been done. - */ - if (!only_end && subscription->ops->invalidate_secondary_tlbs) - subscription->ops->invalidate_secondary_tlbs( - subscription, - range->mm, - range->start, - range->end); if (subscription->ops->invalidate_range_end) { if (!mmu_notifier_range_blockable(range)) non_block_start(); @@ -589,8 +571,7 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, srcu_read_unlock(&srcu, id); } -void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, - bool only_end) +void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) { struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; @@ -600,7 +581,7 @@ void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, mn_itree_inv_end(subscriptions); if (!hlist_empty(&subscriptions->list)) - mn_hlist_invalidate_end(subscriptions, range, only_end); + mn_hlist_invalidate_end(subscriptions, range); lock_map_release(&__mmu_notifier_invalidate_range_start_map); } diff --git a/mm/rmap.c b/mm/rmap.c index b74fc2c..1fbe83e 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -990,13 +990,6 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw) #endif } - /* - * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() as - * we are downgrading page table protection not changing it to - * point to a new page. - * - * See Documentation/mm/mmu_notifier.rst - */ if (ret) cleaned++; } @@ -1554,8 +1547,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, hugetlb_vma_unlock_write(vma); flush_tlb_range(vma, range.start, range.end); - mmu_notifier_arch_invalidate_secondary_tlbs( - mm, range.start, range.end); /* * The ref count of the PMD page was * dropped which is part of the way map @@ -1628,9 +1619,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, * copied pages. */ dec_mm_counter(mm, mm_counter(&folio->page)); - /* We have to invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, - address + PAGE_SIZE); } else if (folio_test_anon(folio)) { swp_entry_t entry = { .val = page_private(subpage) }; pte_t swp_pte; @@ -1642,10 +1630,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, folio_test_swapcache(folio))) { WARN_ON_ONCE(1); ret = false; - /* We have to invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, - address, - address + PAGE_SIZE); page_vma_mapped_walk_done(&pvmw); break; } @@ -1676,10 +1660,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ if (ref_count == 1 + map_count && !folio_test_dirty(folio)) { - /* Invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs( - mm, address, - address + PAGE_SIZE); dec_mm_counter(mm, MM_ANONPAGES); goto discard; } @@ -1734,9 +1714,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, if (pte_uffd_wp(pteval)) swp_pte = pte_swp_mkuffd_wp(swp_pte); set_pte_at(mm, address, pvmw.pte, swp_pte); - /* Invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, - address + PAGE_SIZE); } else { /* * This is a locked file-backed folio, @@ -1752,13 +1729,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, dec_mm_counter(mm, mm_counter_file(&folio->page)); } discard: - /* - * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() it - * has be done above for all cases requiring it to happen under - * page table lock before mmu_notifier_invalidate_range_end() - * - * See Documentation/mm/mmu_notifier.rst - */ page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); @@ -1937,8 +1907,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, hugetlb_vma_unlock_write(vma); flush_tlb_range(vma, range.start, range.end); - mmu_notifier_arch_invalidate_secondary_tlbs( - mm, range.start, range.end); /* * The ref count of the PMD page was @@ -2043,9 +2011,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, * copied pages. */ dec_mm_counter(mm, mm_counter(&folio->page)); - /* We have to invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, - address + PAGE_SIZE); } else { swp_entry_t entry; pte_t swp_pte; @@ -2109,13 +2074,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, */ } - /* - * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() it - * has be done above for all cases requiring it to happen under - * page table lock before mmu_notifier_invalidate_range_end() - * - * See Documentation/mm/mmu_notifier.rst - */ page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); if (vma->vm_flags & VM_LOCKED) mlock_drain_local();