From patchwork Tue Jul 18 07:56:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13316827 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3B1CEB64DD for ; Tue, 18 Jul 2023 07:56:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E1996B0074; Tue, 18 Jul 2023 03:56:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 091416B0075; Tue, 18 Jul 2023 03:56:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4D698D0001; Tue, 18 Jul 2023 03:56:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D648F6B0074 for ; Tue, 18 Jul 2023 03:56:49 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 925A6B0783 for ; Tue, 18 Jul 2023 07:56:49 +0000 (UTC) X-FDA: 81023976138.22.465B4DC Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2049.outbound.protection.outlook.com [40.107.95.49]) by imf24.hostedemail.com (Postfix) with ESMTP id 94C90180002 for ; Tue, 18 Jul 2023 07:56:46 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=WrdC0KnR; spf=pass (imf24.hostedemail.com: domain of apopple@nvidia.com designates 40.107.95.49 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689667006; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tCuVkJ79cafyyFDauw5qSP00PO4pGeDUP6r22cJI8Nk=; b=JoGe8my1Goydpmn4zaDM+8y9ZEOhQwobKAQimQPvkq1QbWtCCyvAwFF5HqQx6l8emtGOUb eywNP5vap22d45eIG3tcfxL2/MjKnWZfPbxfXwe98x5RYeH68MNjEHZ8iLPAcKa3ZsvqeU rHAAZYuATcUj2rEZRFMwqJBqoJeryec= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1689667006; a=rsa-sha256; cv=pass; b=x08hLprymEYPSgbtwXvCdb6wgQzS6IaYaIjyFrMDyTDNBHAyj/mpuzl3YFNfD45eXs4njt gadkuV7aIb14JIeu9be6WaL5e83K86YE/POJaWsRDOgLIhB8yTUQPnYqPrgYSQMzJVqLoT CSBvPabPA73LyK762P2G/rIZD5mZOvk= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=WrdC0KnR; spf=pass (imf24.hostedemail.com: domain of apopple@nvidia.com designates 40.107.95.49 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lyx4z+q2yq4O5fZQnJ2TBSUsC7ZFuFfo/KRVTWpAVsO4VRlpY4gYXC0keBbVggMgxin8Gid4xrw6sqdpu703sksDHJzDxjBbcmIoeLRTvHp1sis1IHuEQxY9DmgtcJp0Smc6doosKT3lBdNg/xuf1UKpC29ZmsR6k1TlxjHJdQDYn8tYUgBy1QIZ1ZzzLG4b3YX0dqiBYQz+JTgAWpkRdNtNA/Q3F1LHffxkfIhVideuLsH6ZU1kmsd1EhZhTtiWbrzlkTp3naAUzDBsUBp7lKiGcxPdLSP9wI2hDJgA60KvXz1qUMs/retrbJDkfyP1TTmlyrqkB9noOfIX+9lfhw== 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=tCuVkJ79cafyyFDauw5qSP00PO4pGeDUP6r22cJI8Nk=; b=Ds6PJBnBNm1oxepicX8yynzrzj03CkLMcVzM1tmNJWKrlyKvsK07M8PBUdQfU2s6HzLo1EJx1EiumfOyFT6F7DtOAIOpbUkFbgTHUqFbeYutEGCSeF998mRq/a9AOPECrTYhxESUp+9R+HXcEaYKbbRlkSuPeULFJA6ALKz9HwtPSBQF84wmryZIkPgUj7Thy1NuaMj054Y0UazDKoc6QTOIdFHWF/fuedD2A+EocUHMWi2UrA1fH54uk+qQMdADbLBalRoEw+m72kLzRHXy0np/KHuH8vSpWTjELGwe+hPh23p7dMpp/KVQJkKZ3Hlp6xa/OS1TfviMyRYezLt3VA== 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=tCuVkJ79cafyyFDauw5qSP00PO4pGeDUP6r22cJI8Nk=; b=WrdC0KnRaeiag34LX8R+DiZplZxv4GVf52YtWJsMfL8tOxMEeQrNruc5Il7nwy4rnR22mTaGWj4hXx6rEsTgmQ9keWlEkdI0Jres1vUb+ZrI3LakC2go4x41JT03bTDcu1z9/OjGlXObcWRXKCk0SBIETQ6NwYI9mDtU/ZBat6ikJYaXR4NXeU9nbUUjmvUIbKX0eyTrTcswZtqON3j8jjlIeCOIXbZqtPRnktT9lJwd0DjOsjyviTtxVtjZ1aU144B5k3nJ+/5frMqJ25No5yO+sqF/UNKH9dKDvno3bEwbs7LfNqShWbwyaAQ70nv7ApLP/N8h0Vt14S4nvHEqoQ== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.32; Tue, 18 Jul 2023 07:56:43 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74%7]) with mapi id 15.20.6588.031; Tue, 18 Jul 2023 07:56:43 +0000 From: Alistair Popple To: 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, mpe@ellerman.id.au, 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 , Jason Gunthorpe Subject: [PATCH 1/4] mm_notifiers: Rename invalidate_range notifier Date: Tue, 18 Jul 2023 17:56:15 +1000 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SYYP282CA0012.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:b4::22) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d858ec6-47e1-447b-b3c0-08db87648700 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C6Ma13zNfXZcQyabukHrdtpiX7IJbnHsGTlD4QBNVh9q1npkREIEBBI1OhN0bos9cUP0+QDO5IDYzDMNNJeP2ZOaQM6SyhgU6hGWnqI9QqSSqBQ2PlTDCgSXp6RUID8Mb1pRsEfp6A1F/bKOrMs8LT0G+hBWOOCRhgAKi4wK17HId7pfHDKj73QbWu4q2z86ENHa1rltKOg/Q3zrhpjzNStaOtK9qxjYuO+FKfaX34jDuPxnPkihbQ5BjUDyyoRgMZ58xxYCLKk40Uv4U9gYhnwXvYi2mLZdbqB06pbOuQwcK+iy5Q3mzM+f5DaZNqdi04weB37qqvc75jVsCp2DN4JT4FSh6ojOApVPib/a4uRE0D+flfPi4aSGaA5JgTaI985Iik7YfVJYy75hdw8P3/PNXYxBMZ1cLGNnbiyBWkggd5Muu2xEC56scnZ0c6bv4xqK3cj8VJkcxJI0iUZwIqTFQfqsr7TB6TQn+khVRgZpw37aOU4aRai001WYUcR9gVFdoonJBa2RhTr35AbCSv1LmVms0A9oZEGF+OdF1Aptl0BQKVAORPnUw2WgvttG 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)(39860400002)(366004)(136003)(346002)(376002)(396003)(451199021)(86362001)(38100700002)(36756003)(66946007)(54906003)(478600001)(5660300002)(26005)(41300700001)(107886003)(8676002)(186003)(6506007)(6512007)(8936002)(7416002)(30864003)(2906002)(66556008)(2616005)(6916009)(83380400001)(6666004)(316002)(4326008)(6486002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yn+4TPDpngeUDz8nYC2Lw5qI08ucy2YFQ/6t9NJeYoEbEFos2HwDfnkSxpghj1H3csW2d+67EBsUATPvX1Wc023ydyyFMOzTxBLdoaOVTmK3eGfrpAozEFcjIiQuGvgvZyVoM7CNoUy3TYaQpOGOdsiN0JMZkVGDkGe9vr22FR79VU4ICQpDNkZEf8+nmNqENtIOmN5kgpVQZnMt8/Ki6x+MAGMMRPuFYoyCsGey7AhFmd9yv77Yg0YzAxMmalVLYI8buWrXP35SpQZRLOqin7X6OTC91lgGcAxetX/c/AIc9wSws1WHKuyXIhkvlEq7qJLSolcTTgSjJVOVP2R/VRe0yvQ55O+pMfsP1ENGPDiSg+JI7B9eGgp6D8U5HMBAhv8/l5pos+qA3rE1rdz3odd078Q70ZIQ31FVoRxWFC8h5gyl3Z41oBTaj2m2pp/QxTABdYKuc+bO97GrVXfBDKURKadHG+vIVCnKOjD4KdcF5lG4X166KS6ObkExNMgnwTJXHeJTr/f6MaNVsWYxJZe1C+dVuCJ1Spte0HNC4T5jqePdmmBY08KjnRfa+Bxfl6ck6AzORAC+sIxzoZND6UGF8xSfQpaK/XpYvAxa916GAY3HshWmawzenurWjrKEzBQAflPLSeZwzUu5lXIeZ6Kgca8tKpwxd+mYZsrZJ4z07YouFAr+xNq3iXCsmGwIJXl8lEbIPGfxo056h4JGUybcB6oXWx60fJFFuAIKAWFD2ncjfSr6bxkGT1jAHg5ftk34m8IC0ZTWHVITlyEfqk5ycsOSfjqVXJYi+dY5104fAvVhaT1EGDJUW1MFoanscwwPfP6JYtV3XNXvWbOuQt7lFi/yAwZ+HJW02WQAgOt0SntRmQdCNfmcp9cqJ2HO+COUFuR+1b+3wvuVOncbpU1CQQJnd88VxeY/S5ko3HZ0l2RdN9YpK0SC51SZnpXTeclpnt+jCwumsQd8mnvT2FlTfRihYx3F8mpnnUGHs7Np4LNlJVmx1NQnqa79MfhUnnaVNVvcRTa0oiIoBEmM8e2zr0j2LdYsi5nfLE3UBolbq/h3INpYS6MqEbdeCuSV4GoEetz1Re5My6slsjQvJs1naiXw7ERQuZLIeekjL0/3eH8cY/QgM1iEriAaJYWcMMUvF/vJu2qnmThPfw6pc3hyXAbsXj0DHqVfulhh3bqpquaF+yrAll0bULFQeeZt8z9LNUHJ+4irC5BOO8z0rQ1Fmqf3XNy3Mr69eMsTgvhGaoj94j7NU2Ycz+E4G+HdBqwxsrlr7xFryAhxjROfzoh0eqvqPswin/0UTz15BZRgeCg3rhiEPWKIt9xmfaKi8xEdHC+kb62toihkeugQFcoPtOFmUZILxvGKfu0kWqRU86Vc7qiD5seYPxAsu71fq40SdkTsdYrC46aI9WukzUBuGPJUb4TNzdvLZrEUMFqyGioG118yDuLa5Sso1oWwBe3o+ewhtHxMrsxtwIX6aMAvS2uqWgsPZJ4cJ4WdJXPqTgo2ayXO1F97YxspK9kTQ9pfAE7jzt86upGppFq9auLWGBMZqUj3hJl2wETL3yoi64btzzuL3c96ceBqfjYb X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d858ec6-47e1-447b-b3c0-08db87648700 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 07:56:43.7393 (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: weteWS1kfQZ0fkmLrWkZZ+Ds3GPf+r9G+AvmctpunaLuWc7tXBKxumQ4zFrufZi27AbqpPhQc+n+/1eNiKMDLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 X-Rspamd-Queue-Id: 94C90180002 X-Rspam-User: X-Stat-Signature: eonnmdc58eokyz5htrjn3s4busonpokx X-Rspamd-Server: rspam03 X-HE-Tag: 1689667006-552536 X-HE-Meta: U2FsdGVkX1/oDFGD6b5zYWLagWhn/c7Xbg/smNhoDp6aYocVXBDzYWfW+JzfRyFYmKy9yosfJzF1xFShOw/im4KDdd09XAN13/deXN/ybiOAKMo6fj0apBY1aosCgWSwo2klkKyNO1KNKeJTpEtq67RmCKnz0I1VfDJ8PEYZGNaZVEwK+6wqkvoP0WVVuySZjUIDh6dZhmM0oZ0qynTpr7kMYXYD5gbzCToLPsLSW9SatV/id9MJchpygklkykOIP+QKwfvBLd82YAkVAP8Jv44sxgm3YRyOZBLTzSeYu40PA5Bk1RGsZ2PSCL+IsJvp9oTF0l9gQmhO5QkjWasnLhGuASsPiuMyykQWdQSqMxyLQKfodq6pJN3Hypfv2NWzwWO9jY7mHlhjAmksegENymFDToUMTGV8MDNNtrg1MATGSWuEo7qB7S4+Lzw0qsoeTDBxnffWMuvN5U6HUXzBtkl+MRb0/YL+gw0/W4B1lPJ8qnXeChAMsNtDUnGcD0hqtv9y7OYQQkXe4aUVkV2lwIaetGRKfeKXVSuek4Wg9HaiLyggmDjnJpNGOrH5MDilp7rT0z52CYY10NgeBIz95/uf6oofkTYzJVmiWiSEBrgNzK5lghHckUPoaqKcjiVzYYhekWDNYNMWop5JntSz+ft4+FXBnPgUCF34Qh5U2jT2ibVFUv1gJxXrT2+HQoAs33XCJ780g4LSiH7ziWD6g4ZWvJZdkmOfCWCpQnhb+wjztUW9eqkzyx/2tneSxnlfZyqktu7de5Y/cWEoUTriibi5NH8PbSOxKcMCaa/inkl+JQlMVWZn31ehtuMqeXBMXS364OmoRQV6NCRT3y7lChEtDxlOai0gDQd2jWOpDBa7K1Bc2IRTO+E0H9mcfpf2L5bHEX1Xou9uKARyncft9BW3SavExXcgY3g+TCCwrXRsshqhqpyNKefWj1QigpOl+5vpu4CCyQ8LSfMFhQj /AonYz+K v7gQN9TA14oIVIESV8mZCpCQfc2LZUvQB8S01kf816ju37PVkBE1EweoHAQWACyT01JJTpojN9BEbZMZyC01yHRDbMjFJZ33Wf8sURcjm46POcGrH4noPXh7CyVtqso5Oys0Hbg+DNix1soPPLFkfdxjnKyfr8lTCFcZzGELwhVH+6OBvKEZwT4EiPxlGXMlYN/B14LpvxLivaPOuVorVO5WLSEVZbOE5tFlzhBPbbCqjdQtDbRFS+h19xVs3mbSIOEcX/yc7uq5MS4145gRIQwXkAy9hTMZFoTjIpWBMNXmZlnXDbt1NVqbDc0aC6FTRIHh6Q4IR7nCz16d6xffxC5g5Jg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There are two main use cases for mmu notifiers. One is by KVM which uses mmu_notifier_invalidate_range_start()/end() to manage a software TLB. The other is to manage hardware TLBs which need to use the invalidate_range() callback because HW can establish new TLB entries at any time. Hence using start/end() can lead to memory corruption as these callbacks happen too soon/late during page unmap. mmu notifier users should therefore either use the start()/end() callbacks or the invalidate_range() callbacks. To make this usage clearer rename the invalidate_range() callback to arch_invalidate_secondary_tlbs() and update documention. Signed-off-by: Alistair Popple Suggested-by: Jason Gunthorpe --- arch/x86/mm/tlb.c | 1 +- drivers/iommu/amd/iommu_v2.c | 10 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 13 ++-- drivers/iommu/intel/svm.c | 8 +-- drivers/misc/ocxl/link.c | 8 +-- include/asm-generic/tlb.h | 2 +- include/linux/mmu_notifier.h | 54 +++++++++--------- mm/huge_memory.c | 4 +- mm/hugetlb.c | 10 +-- mm/mmu_notifier.c | 52 ++++++++++------- mm/rmap.c | 42 +++++++------- 11 files changed, 110 insertions(+), 94 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 267acf2..eaefc10 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c index 261352a..2596466 100644 --- a/drivers/iommu/amd/iommu_v2.c +++ b/drivers/iommu/amd/iommu_v2.c @@ -355,9 +355,9 @@ static struct pasid_state *mn_to_state(struct mmu_notifier *mn) return container_of(mn, struct pasid_state, mn); } -static void mn_invalidate_range(struct mmu_notifier *mn, - struct mm_struct *mm, - unsigned long start, unsigned long end) +static void mn_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, unsigned long end) { struct pasid_state *pasid_state; struct device_state *dev_state; @@ -391,8 +391,8 @@ static void mn_release(struct mmu_notifier *mn, struct mm_struct *mm) } static const struct mmu_notifier_ops iommu_mn = { - .release = mn_release, - .invalidate_range = mn_invalidate_range, + .release = mn_release, + .arch_invalidate_secondary_tlbs = mn_arch_invalidate_secondary_tlbs, }; static void set_pri_tag_status(struct pasid_state *pasid_state, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index a5a63b1..aa63cff 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -186,9 +186,10 @@ static void arm_smmu_free_shared_cd(struct arm_smmu_ctx_desc *cd) } } -static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, - struct mm_struct *mm, - unsigned long start, unsigned long end) +static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, + unsigned long end) { struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); struct arm_smmu_domain *smmu_domain = smmu_mn->domain; @@ -237,9 +238,9 @@ static void arm_smmu_mmu_notifier_free(struct mmu_notifier *mn) } static const struct mmu_notifier_ops arm_smmu_mmu_notifier_ops = { - .invalidate_range = arm_smmu_mm_invalidate_range, - .release = arm_smmu_mm_release, - .free_notifier = arm_smmu_mmu_notifier_free, + .arch_invalidate_secondary_tlbs = arm_smmu_mm_arch_invalidate_secondary_tlbs, + .release = arm_smmu_mm_release, + .free_notifier = arm_smmu_mmu_notifier_free, }; /* Allocate or get existing MMU notifier for this {domain, mm} pair */ diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index e95b339..8f6d680 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -219,9 +219,9 @@ static void intel_flush_svm_range(struct intel_svm *svm, unsigned long address, } /* Pages have been freed at this point */ -static void intel_invalidate_range(struct mmu_notifier *mn, - struct mm_struct *mm, - unsigned long start, unsigned long end) +static void intel_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, unsigned long end) { struct intel_svm *svm = container_of(mn, struct intel_svm, notifier); @@ -256,7 +256,7 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) static const struct mmu_notifier_ops intel_mmuops = { .release = intel_mm_release, - .invalidate_range = intel_invalidate_range, + .arch_invalidate_secondary_tlbs = intel_arch_invalidate_secondary_tlbs, }; static DEFINE_MUTEX(pasid_mutex); diff --git a/drivers/misc/ocxl/link.c b/drivers/misc/ocxl/link.c index 4cf4c55..c06c699 100644 --- a/drivers/misc/ocxl/link.c +++ b/drivers/misc/ocxl/link.c @@ -491,9 +491,9 @@ void ocxl_link_release(struct pci_dev *dev, void *link_handle) } EXPORT_SYMBOL_GPL(ocxl_link_release); -static void invalidate_range(struct mmu_notifier *mn, - struct mm_struct *mm, - unsigned long start, unsigned long end) +static void arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, unsigned long end) { struct pe_data *pe_data = container_of(mn, struct pe_data, mmu_notifier); struct ocxl_link *link = pe_data->link; @@ -509,7 +509,7 @@ static void invalidate_range(struct mmu_notifier *mn, } static const struct mmu_notifier_ops ocxl_mmu_notifier_ops = { - .invalidate_range = invalidate_range, + .arch_invalidate_secondary_tlbs = arch_invalidate_secondary_tlbs, }; static u64 calculate_cfg_state(bool kernel) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index b466172..48c81b9 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -456,7 +456,7 @@ static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) return; tlb_flush(tlb); - mmu_notifier_invalidate_range(tlb->mm, tlb->start, tlb->end); + mmu_notifier_invalidate_secondary_tlbs(tlb->mm, tlb->start, tlb->end); __tlb_reset_range(tlb); } diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 64a3e05..a4bc818 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -187,27 +187,27 @@ struct mmu_notifier_ops { const struct mmu_notifier_range *range); /* - * invalidate_range() is either called between - * invalidate_range_start() and invalidate_range_end() when the - * VM has to free pages that where unmapped, but before the - * pages are actually freed, or outside of _start()/_end() when - * a (remote) TLB is necessary. + * arch_invalidate_secondary_tlbs() is used to manage a non-CPU TLB + * which shares page-tables with the CPU. The + * invalidate_range_start()/end() callbacks should not be implemented as + * invalidate_secondary_tlbs() already catches the points in time when + * an external TLB needs to be flushed. * - * If invalidate_range() is used to manage a non-CPU TLB with - * shared page-tables, it not necessary to implement the - * invalidate_range_start()/end() notifiers, as - * invalidate_range() already catches the points in time when an - * external TLB range needs to be flushed. For more in depth - * discussion on this see Documentation/mm/mmu_notifier.rst + * This requires arch_invalidate_secondary_tlbs() to be called while + * holding the ptl spin-lock and therefore this callback is not allowed + * to sleep. * - * Note that this function might be called with just a sub-range - * of what was passed to invalidate_range_start()/end(), if - * called between those functions. + * This is called by architecture code whenever invalidating a TLB + * entry. It is assumed that any secondary TLB has the same rules for + * when invalidations are required. If this is not the case architecture + * code will need to call this explicitly when required for secondary + * TLB invalidation. */ - void (*invalidate_range)(struct mmu_notifier *subscription, - struct mm_struct *mm, - unsigned long start, - unsigned long end); + void (*arch_invalidate_secondary_tlbs)( + struct mmu_notifier *subscription, + struct mm_struct *mm, + unsigned long start, + unsigned long end); /* * These callbacks are used with the get/put interface to manage the @@ -397,8 +397,8 @@ extern void __mmu_notifier_change_pte(struct mm_struct *mm, 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(struct mm_struct *mm, - unsigned long start, unsigned long end); +extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, + unsigned long start, unsigned long end); extern bool mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range); @@ -491,11 +491,11 @@ mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) __mmu_notifier_invalidate_range_end(range, true); } -static inline void mmu_notifier_invalidate_range(struct mm_struct *mm, - unsigned long start, unsigned long end) +static inline void mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, + unsigned long start, unsigned long end) { if (mm_has_notifiers(mm)) - __mmu_notifier_invalidate_range(mm, start, end); + __mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end); } static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm) @@ -589,7 +589,7 @@ static inline void mmu_notifier_range_init_owner( pte_t ___pte; \ \ ___pte = ptep_clear_flush(__vma, __address, __ptep); \ - mmu_notifier_invalidate_range(___mm, ___addr, \ + mmu_notifier_arch_invalidate_secondary_tlbs(___mm, ___addr, \ ___addr + PAGE_SIZE); \ \ ___pte; \ @@ -602,7 +602,7 @@ static inline void mmu_notifier_range_init_owner( pmd_t ___pmd; \ \ ___pmd = pmdp_huge_clear_flush(__vma, __haddr, __pmd); \ - mmu_notifier_invalidate_range(___mm, ___haddr, \ + mmu_notifier_arch_invalidate_secondary_tlbs(___mm, ___haddr, \ ___haddr + HPAGE_PMD_SIZE); \ \ ___pmd; \ @@ -615,7 +615,7 @@ static inline void mmu_notifier_range_init_owner( pud_t ___pud; \ \ ___pud = pudp_huge_clear_flush(__vma, __haddr, __pud); \ - mmu_notifier_invalidate_range(___mm, ___haddr, \ + mmu_notifier_arch_invalidate_secondary_tlbs(___mm, ___haddr, \ ___haddr + HPAGE_PUD_SIZE); \ \ ___pud; \ @@ -716,7 +716,7 @@ mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range) { } -static inline void mmu_notifier_invalidate_range(struct mm_struct *mm, +static inline void mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, unsigned long start, unsigned long end) { } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index eb36783..a232891 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2124,8 +2124,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, if (is_huge_zero_pmd(*pmd)) { /* * FIXME: Do we want to invalidate secondary mmu by calling - * mmu_notifier_invalidate_range() see comments below inside - * __split_huge_pmd() ? + * mmu_notifier_arch_invalidate_secondary_tlbs() see comments below + * inside __split_huge_pmd() ? * * We are going from a zero huge page write protected to zero * small page also write protected so it does not seems useful diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 64a3239..178c930 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5690,7 +5690,8 @@ 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_invalidate_range(mm, range.start, range.end); + 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)) @@ -6822,8 +6823,9 @@ long hugetlb_change_protection(struct vm_area_struct *vma, else flush_hugetlb_tlb_range(vma, start, end); /* - * No need to call mmu_notifier_invalidate_range() we are downgrading - * page table protection not changing it to point to a new page. + * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() we are + * downgrading page table protection not changing it to point to a new + * page. * * See Documentation/mm/mmu_notifier.rst */ @@ -7467,7 +7469,7 @@ static void hugetlb_unshare_pmds(struct vm_area_struct *vma, i_mmap_unlock_write(vma->vm_file->f_mapping); hugetlb_vma_unlock_write(vma); /* - * No need to call mmu_notifier_invalidate_range(), see + * No need to call mmu_notifier_arch_invalidate_secondary_tlbs(), see * Documentation/mm/mmu_notifier.rst. */ mmu_notifier_invalidate_range_end(&range); diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 50c0dde..34c5a84 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -207,7 +207,7 @@ mmu_interval_read_begin(struct mmu_interval_notifier *interval_sub) * spin_lock * seq = ++subscriptions->invalidate_seq * spin_unlock - * op->invalidate_range(): + * op->invalidate_secondary_tlbs(): * user_lock * mmu_interval_set_seq() * interval_sub->invalidate_seq = seq @@ -560,23 +560,23 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, hlist_for_each_entry_rcu(subscription, &subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { /* - * Call invalidate_range here too to avoid the need for the - * subsystem of having to register an invalidate_range_end - * call-back when there is invalidate_range already. Usually a - * subsystem registers either invalidate_range_start()/end() or - * invalidate_range(), so this will be no additional overhead - * (besides the pointer check). + * Subsystems should register either invalidate_secondary_tlbs() + * or invalidate_range_start()/end() callbacks. * - * We skip call to invalidate_range() if we know it is safe ie - * call site use mmu_notifier_invalidate_range_only_end() which - * is safe to do when we know that a call to invalidate_range() - * already happen under page table lock. + * 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_range) - subscription->ops->invalidate_range(subscription, - range->mm, - range->start, - range->end); + 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(); @@ -604,8 +604,8 @@ void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, lock_map_release(&__mmu_notifier_invalidate_range_start_map); } -void __mmu_notifier_invalidate_range(struct mm_struct *mm, - unsigned long start, unsigned long end) +void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, + unsigned long start, unsigned long end) { struct mmu_notifier *subscription; int id; @@ -614,9 +614,10 @@ void __mmu_notifier_invalidate_range(struct mm_struct *mm, hlist_for_each_entry_rcu(subscription, &mm->notifier_subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { - if (subscription->ops->invalidate_range) - subscription->ops->invalidate_range(subscription, mm, - start, end); + if (subscription->ops->arch_invalidate_secondary_tlbs) + subscription->ops->arch_invalidate_secondary_tlbs( + subscription, mm, + start, end); } srcu_read_unlock(&srcu, id); } @@ -635,6 +636,15 @@ int __mmu_notifier_register(struct mmu_notifier *subscription, mmap_assert_write_locked(mm); BUG_ON(atomic_read(&mm->mm_users) <= 0); + /* + * Subsystems should only register for invalidate_secondary_tlbs() or + * invalidate_range_start()/end() callbacks, not both. + */ + if (WARN_ON_ONCE(subscription->ops->arch_invalidate_secondary_tlbs && + (subscription->ops->invalidate_range_start || + subscription->ops->invalidate_range_end))) + return -EINVAL; + if (!mm->notifier_subscriptions) { /* * kmalloc cannot be called under mm_take_all_locks(), but we diff --git a/mm/rmap.c b/mm/rmap.c index 0c0d885..b74fc2c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -991,9 +991,9 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw) } /* - * No need to call mmu_notifier_invalidate_range() as we are - * downgrading page table protection not changing it to point - * to a new page. + * 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 */ @@ -1554,8 +1554,8 @@ 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_invalidate_range(mm, - 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 @@ -1629,7 +1629,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ dec_mm_counter(mm, mm_counter(&folio->page)); /* We have to invalidate as we cleared the pte */ - mmu_notifier_invalidate_range(mm, address, + 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) }; @@ -1643,7 +1643,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, WARN_ON_ONCE(1); ret = false; /* We have to invalidate as we cleared the pte */ - mmu_notifier_invalidate_range(mm, address, + mmu_notifier_arch_invalidate_secondary_tlbs(mm, + address, address + PAGE_SIZE); page_vma_mapped_walk_done(&pvmw); break; @@ -1676,8 +1677,9 @@ 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_invalidate_range(mm, - address, address + PAGE_SIZE); + mmu_notifier_arch_invalidate_secondary_tlbs( + mm, address, + address + PAGE_SIZE); dec_mm_counter(mm, MM_ANONPAGES); goto discard; } @@ -1733,7 +1735,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, 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_invalidate_range(mm, address, + mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, address + PAGE_SIZE); } else { /* @@ -1751,9 +1753,9 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, } discard: /* - * No need to call mmu_notifier_invalidate_range() it has be - * done above for all cases requiring it to happen under page - * table lock before mmu_notifier_invalidate_range_end() + * 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 */ @@ -1935,8 +1937,8 @@ 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_invalidate_range(mm, - range.start, range.end); + mmu_notifier_arch_invalidate_secondary_tlbs( + mm, range.start, range.end); /* * The ref count of the PMD page was @@ -2042,8 +2044,8 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, */ dec_mm_counter(mm, mm_counter(&folio->page)); /* We have to invalidate as we cleared the pte */ - mmu_notifier_invalidate_range(mm, address, - address + PAGE_SIZE); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, + address + PAGE_SIZE); } else { swp_entry_t entry; pte_t swp_pte; @@ -2108,9 +2110,9 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, } /* - * No need to call mmu_notifier_invalidate_range() it has be - * done above for all cases requiring it to happen under page - * table lock before mmu_notifier_invalidate_range_end() + * 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 */ From patchwork Tue Jul 18 07:56:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13316828 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6A09EB64DA for ; Tue, 18 Jul 2023 07:56:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5283D6B0075; Tue, 18 Jul 2023 03:56:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D78D6B0078; Tue, 18 Jul 2023 03:56:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3797D8D0001; Tue, 18 Jul 2023 03:56:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 294446B0075 for ; Tue, 18 Jul 2023 03:56:57 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E9E0B801DB for ; Tue, 18 Jul 2023 07:56:56 +0000 (UTC) X-FDA: 81023976432.10.963D2EE Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2076.outbound.protection.outlook.com [40.107.244.76]) by imf12.hostedemail.com (Postfix) with ESMTP id 1B89740018 for ; Tue, 18 Jul 2023 07:56:53 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=j4QKh8qv; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf12.hostedemail.com: domain of apopple@nvidia.com designates 40.107.244.76 as permitted sender) smtp.mailfrom=apopple@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689667014; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WvW9mlxbGnKVcvKQfEGVo3jXEFbWzwdMBMfBGVX5oxk=; b=s9rvJhX3caeyBf3QuoPawzpAs0pMSvhiEduDQFGI4ANKADKJxHeA1e+Zgk77ILywviP2lU 1nOU1PnkTIA5zc2ypVIPqSeAWc3VxcONuAzHBcOn0m+09HBR4KWibh/EDVlUui9ZVs7OOe VE+4JzHlMj+95ibI1lSpJnwuAJf1Yh0= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=j4QKh8qv; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf12.hostedemail.com: domain of apopple@nvidia.com designates 40.107.244.76 as permitted sender) smtp.mailfrom=apopple@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1689667014; a=rsa-sha256; cv=pass; b=DmVRqNEpfN30pNM2N0N6fOxiI+OR/LM/GX9lYTGTBkm0TSJS6Y5UGaTQumbyVUQrzNcX7r r0a+W+VKRxzaTUHej97fl+il7AI5DuxnNBo74/+CvD3sqjHeih8EpDXpzzHd53shU6c0DC d4NRRDYKQ6hs72nF/PyzX8RH7nLxqYk= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GwgrfyfDFouK5vcOkm1Ayk/e5XN+JiyxqVYckZfJmTIxrk9IrfKgAa4Wgpct84lo6wJtAzDZZf12zqv28UKFVEn0b/LKbO2pDj0/0vzIR+4UGNMmclQ8qIpNteJojT62/4qzS5sOPHjkxIMzbXpqaWvDUZ4wgPtIbD/E8eeQM756i5YAGZuJcbIMXhfJIHlyUAhPL6YNSJwxeTytQ5BV2EGQax6Ei3UU+HuhPeNulWhPk8gmWN6eMgvCj2mmxrHHqfuusY1hFXDxyLjJxBkrWMOaJbWeojIINosha4oNknjcK1tTvIQjdjt5aMM99IeLryr+SouarZBw41EygG3gsQ== 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=WvW9mlxbGnKVcvKQfEGVo3jXEFbWzwdMBMfBGVX5oxk=; b=DzUxocAfd9pQmzItZHuz4+WD60roqofXkDKMbXahTdaq/2ur65SNGToC8nS2Vq+6qfQ5ic/7iU0+5fOAS/wVJTE4p3XXRZi4Oko683x+xm+UU86/AjYmwfAdLcSgrphz2K7vUwhMTfaHlM1ViIstUmmBjYEQD3eDY6r8CoGVVng4de2M3Ahc/jm+XeifxZBIQB8vzo7G8NlAuCsYz2Oet785oMWmmPXU46ZTdDDRIgg/p8AFsDqx2/qOBI6B0d978UrzAw9wWOe/F9czJv8i2FIx0zLdSkscbQOSZWUqKHZG4BtnKaiNS/SrCD8P+MHJ/sXeqbfsrB1ogKugfKXEbA== 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=WvW9mlxbGnKVcvKQfEGVo3jXEFbWzwdMBMfBGVX5oxk=; b=j4QKh8qvouPOodSoSRdkI9ECVmRu7kWz4KJDJgA9XgDTpH9ZZziW/0zse1CnGXC5R9xGKTa6u3Wgq7Oef3amzElF5ruewt+woyuMN4kSU6KsaaBlYdu88CBc6z3LzG0Ow2qXb1M/DEpdNa1k7Fu+WMS3ZafvKqQHWQfXIuCcNh4ULk1Wx3kgkxBzFTSVOZxGocDP347xSVzKaG6Y9xN3DzSNTU0kM9EG/iUUR+Llbdqo/kUI6tDDhDTRCR/08c2XPNz9ohRw7CgAo8ewMzRxK3birVl0IW7B/w75kcbQNZHV/KjcsyOF5t81r+AL7U0Z806QA3m+vXFrztPa7eSqIw== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.32; Tue, 18 Jul 2023 07:56:51 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74%7]) with mapi id 15.20.6588.031; Tue, 18 Jul 2023 07:56:51 +0000 From: Alistair Popple To: 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, mpe@ellerman.id.au, 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: [PATCH 2/4] arm64/smmu: Use TLBI ASID when invalidating entire range Date: Tue, 18 Jul 2023 17:56:16 +1000 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY2PR01CA0008.ausprd01.prod.outlook.com (2603:10c6:1:14::20) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: fec065b8-87e4-41a7-3db5-08db87648bb2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vgdPwCgZpHpmWC+WVz0BXYPPiLMbjm/lQZC+2D5Mux7CQVoo3EzakekiJz3A0FxDW7FKT9FbqrPTkN9l5XDsCuxZvqb+6aM5iX5HsWx0cBPLOfiQcwPIqwQoW6CaxCLdpyUeRNJIWEyoJ1g0reLt9gHrffd032DzlCqG7mXxIFoXI6krZ+01xiwhnPkQovU++ZyohHYX+VUYVfsYRKx4ZQ85qsggzsLXeowsRPvSRLJMzD5TxN3k73HBQR8+6Ajqp7IpjbIvb1JtT4rqzAuaEp6/2xiwc1Bi7+formeo9OwlAmf8R2y58Gpldfa4cYpd33F9hiK2HJiig3T9jnjJ1Vwxk8oG3T9XoLhLuF+zgdIeXRLRmd9wQqfA2OxIqD9Jxd/dlaZy7NxihTYLMYu2jw5F2HqITns20cdSy/iMjZInxkxxz6i71rA2Fzi/KBzoD6nNbxPrWYx8bevqpV6xMiqnAflJjL3cz/9i9gdVgrdoRgxvT8HrfJfV9aauVdYcel1AtGSRZm13cy8BF5Czo/EYMkaOdnEoUqrJBqeKISuR1ts1mGVYmYEqAFCa9qS0 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)(39860400002)(366004)(136003)(346002)(376002)(396003)(451199021)(86362001)(38100700002)(36756003)(66899021)(66946007)(478600001)(5660300002)(26005)(41300700001)(107886003)(8676002)(186003)(6506007)(6512007)(8936002)(7416002)(2906002)(66556008)(2616005)(6916009)(83380400001)(6666004)(316002)(4326008)(6486002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4ivI5Nh+TWpV9Ru7dx/obF7K3a+hCLeW3c88V29AFcawzcX21qU2Jrhx6Wl0EVyg7I520/ZslZiy+M3SH+GKEWyq1g8PZgdCpeL8RNkV7+Ze4NJMPkcsnMVd6L2DMhrebLPOm06Z76shc3hw9HO49QGlTcXAUCs6UsCg1WenOiM8bSLkmxhZdI0qIHPUCyJ+fxW/JEo/Y6R/Zmw+Zst3od0qA/pfN2iujKpJDaxXkxHOtTeaA8rMpUZy7A4G79TMNz72B1oCkFgoEzAFE6CY9AVb8Pra5eROJI4RKZ33deGnRpajVib57FleyrThVXfqUR33GgAbI5lkWVB3WSYwDEgJw534UO/dbm6ZCfpHJJbk9d+HfJp3Bhvms3hWD7nyHdZsSJwne9dGSi6vLfK2GkgGds7KP+x0wneeS7pUURPsLow4X6h595991zZTYwE/ZRuMxXKR8rRT+Lwgh/B63EoWPsxXfKvYlApcs5O3Fkd0egqzTVWgtKOsLcjNtoEIFIaAPyEvfVcbF+aJ3cfljMgRutzJzL6OHeFT/CpsZSmgWEQhJoItXXiwP3xUMa7TXYqLTMlq664O82xO8N/VGmBh1LV2Xr9jPMClVmRDJbqahgz7PQZZUMNu4a750VVqc5sr6njmU3UrhJ5kdDQ4HBLjLC7rPdx1dJvL7jaRcd+HF7FrxNaUUUqg8NmbWX/+KISycHVJHNuJwdQGjMAcxhWeMkCFENoeiCdc6FTunZvpE87ux4QsO55vWBdAbReRTAvyRnHhQj/klZP9jvi41dcTfMYYFZpya4vrPWyuy93wRaZop0iYYrl33pcN+Hb4TvcMtgo3jY6OodaAYDVpzB2MSaB1TXaVVDW2ikFHm1ku6VCeBsU4hFiq4L+/DvNLgP6m3RYYdF9K6oGpXZahjriejGKU/q1NkYbgrNJBVfLrRwiXeUxLwaTgwS2KEspmDGs+T9dTwL6DDQoWwdaRGtbt1EjFziW3mbPafpXi+UrMvA1iC4kaVC/oRKE7CwnDKyfPqa8OoBZoonZgcZXmqmn5Ldjp0qdOalNpFTKndddYRA1+6bsBn5UebLy10EU/0QgofhX8XdUoEwIfeisEGijCYSujen5RqUlgl4tE7gI+HwgNpyXFtuIeU3rlVz6fE5JafbYEoLegKZ4wqPh4wl+tFjhUJViP+p9EBxVNWfyp4qQO3LQT3LtTfSBjGuiqyCTEzRBbK7NvWUJVBwqTLl8p9UHiw7OXNkWT+ypWGxMS+0XaR3/j5e/7bqJnJqgZEK+ejuMmsAoT9vJpO7wEbRmys/SOUUXi7AZuARPi3Qwt6EeQ0lZ1nn9PaQ2QqEGDh/nk6LCcB0/FK1KIN6JagORHjEp1wloneUCOd9xsfcn3DCNNa4mMXfRuV9En7I2drw8yczH3Sbat6jTsq5qRL8tPMVOXrm/Rlmm31G+L/+X5eyLhjZ6dfVET/ZxzPmsKfC4RFao0uTSvTyJSfBGe6O56PoBt1weo4OSPbSuLjC07wCFjSGsvorJqp5PwXnmPwkWs31tAA//wSA8uDXuO1n65oGgHPa6998pGSavh8btwalzh1cYVLeWmDLIa69du X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fec065b8-87e4-41a7-3db5-08db87648bb2 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 07:56:51.4227 (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: Y9rU02Z0uYoTdnuqMaRaCs67nnBgD5xEtuSoqXDfN5XFrwkkA8zdSOcxLsZpfeLX5lCANncgBsdSMYMMdRALsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1B89740018 X-Stat-Signature: ohbic5t8y9coa3jirn5ibxouhaompnhn X-Rspam-User: X-HE-Tag: 1689667013-588054 X-HE-Meta: U2FsdGVkX19aelylF45+cT3SaMchOonNfF0IWW5++m2wp0bf15WWsLKJRcCbWhw2mGu9rsY9xNv6axybG3lPVHDusj/2KQqmv9ia/ureaVT9wN38Z1kDPJeu6LSTXWNu5G14QmVSx+3tqx6L0JGADGX6x4P5Fw2OdrYakAFaRI7PLZs2qNAs6+j8Hg7bAkgZKl4UQZeV4lh/gc4UzrZV9Gvifm2ZIYLrV48scqmLorRi/V54Gxh43YVETudJX5aNxG+nxQXnVKzHTBQCb5AL352YuWkScnYDvkm0+Bo3+fkXYfIslDySat6xw3bfwb1ZbI6LD+IgAy7Dx9ZIRTDRUkLx3v9JcrXwgjteM4wpVah+F3J+ZiZfBAJbvUxVrDgL/6MJaSRyNiMfFqskHE5Q5+7DThaxsHi80BAe0ydeeGXrWopvcm5kp71NAa5xuqNKLr4AtQHNlK/pZJac+at/gYFVqklSQsjjAhzMG8vy5qikT62C4sld9kNCIFAn5ca13Dv9VS1mdjbJBvyi8z9baX0riwQplb/EZNJKCBkaOA/NGMk1QGAt07/RJbjd2GQXZwbuS/aA2+/uZ9iIvO4tMYU8QTuYUU6JowUbcRGaiV6C7ympf2eKsyZhlgUemkIB4m3vga3UYrp053CIC3h0rvs7O4IUYbTwxORxKlies1fXI2wxlhfvrIzKsP3v7XrCg0GRA725C5rkS/Qbnbyg83aYOTstgBjbLecPyOaQGuvx9YVsUcwC/a2fECCmc9okd2ebT63vEfX0wSqmqMVMGXUgFC0HO7kpxQdAezU24iealW8rk3TOPLSBanlCELbsmiqlHN0zbmyBojxBAuraYdtsGZ3eSlxK3f52vmf8zALQAj9t3FH4FnwtfKypvJHssCZ62XkTraduGrS5HmOZFjNMcM2eZXItR88YkSRT4hAmjImIw93QESzWu4SydvRNd5uHWwMP8feW6L/FLM3 aJbTJGZS RbBYjh+hQum0KukM5BF4o+t6AlxS8mLcaH7rLnqVN/sULV9R9OiTTxrdlOiy5woIYHKNz4KUxXOCCLXJEStuuJqRf6RpPzsbb9GgeYXMDcihv6qHpZ+qUcG3lGIcViuzltqZnSK1ABsEF3+LWh5eBlJYGfleUWZKg0lXDM6m7K6E8Vzo0HeoaJVMT43PvrQbVjav4DFyk+n/xP/d8mKqXAVCYRsdvctdV3UQ4q51gP3x7EUs8jYEg+GZgk7ltZENwP4nZ9EJLhUKDrZQnXSyxbBg1RxqoDHlzEmB2/Ax5dbCtWXg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The ARM SMMU has a specific command for invalidating the TLB for an entire ASID. Currently this is used for the IO_PGTABLE API but not for ATS when called from the MMU notifier. The current implementation of notifiers does not attempt to invalidate such a large address range, instead walking each VMA and invalidating each range individually during mmap removal. However in future SMMU TLB invalidations are going to be sent as part of the normal flush_tlb_*() kernel calls. To better deal with that add handling to use TLBI ASID when invalidating the entire address space. Signed-off-by: Alistair Popple --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index aa63cff..dbc812a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -201,10 +201,20 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, * range. So do a simple translation here by calculating size correctly. */ size = end - start; + if (size == ULONG_MAX) + size = 0; + + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) { + if (!size) + arm_smmu_tlb_inv_asid(smmu_domain->smmu, + smmu_mn->cd->asid); + else + arm_smmu_tlb_inv_range_asid(start, size, + smmu_mn->cd->asid, + PAGE_SIZE, false, + smmu_domain); + } - if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) - arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, - PAGE_SIZE, false, smmu_domain); arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, start, size); } From patchwork Tue Jul 18 07:56:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13316829 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B61BEB64DD for ; Tue, 18 Jul 2023 07:57:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E00AA6B0078; Tue, 18 Jul 2023 03:57:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB1CA6B007B; Tue, 18 Jul 2023 03:57:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C78A06B007D; Tue, 18 Jul 2023 03:57:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BA3916B0078 for ; Tue, 18 Jul 2023 03:57:04 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 83BD11401DE for ; Tue, 18 Jul 2023 07:57:04 +0000 (UTC) X-FDA: 81023976768.23.A64ED85 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2068.outbound.protection.outlook.com [40.107.244.68]) by imf19.hostedemail.com (Postfix) with ESMTP id 8957C1A0004 for ; Tue, 18 Jul 2023 07:57:01 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RdSTji4g; spf=pass (imf19.hostedemail.com: domain of apopple@nvidia.com designates 40.107.244.68 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689667021; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t/1ZlJ6hZJaDce6b/fep0UVd3G4r1VZkyBk0pDLwBXk=; b=nczlIc0hKcrNJQWOov0/i4p16oOKXVSi3zd0eIjDrKxjX7j8hKiTG0g3pciDY18lWnc5Q7 TrjzO1ucCm3505qSINd8yB8Ul/0VO5gctwamfS+eJRvzLTGx1NBrlEVuT84nMS68nFr0rm q24xsnjCSrL1gyXpCFq9hwyYniGfrvo= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1689667021; a=rsa-sha256; cv=pass; b=ayKlApt6dz0hMO9P7RBX2zMKtFdQmBgfEbeqxlinRz38nNI2Lw1hGN+CTwJz4u0175e2dC VJb/7aRJR3aHFeNO7MXXENLrzncq8Nncus5alIGXyLPN6+iF5VUEoNigs3yOIJJhQXM/7z ilo19kwmgndveQIFMnnaWeTOcKV4ZaQ= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RdSTji4g; spf=pass (imf19.hostedemail.com: domain of apopple@nvidia.com designates 40.107.244.68 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fr3Db1Q1p86dTkyi183SVLGv+4fFxb/Rmr44HlOcUK7xvqt5YCMV4YMyHJC0BHYKc3hx2PPCfidTj2rDb6y8k2i5zTB9d3c5RAbf1Be7X48Is98kHcrqd2TCIqmewg4JC7d+Hf7T4kZ5VhcYspoKTsavB/syuFbTl6FEHlN0DfYb/4Uogko5f0DWWWiK4ne00Z95/0k9t2RdJAaebBrquFE3T8RhCRI9K7dkrbp8xNKe3P1LaH7OkyISp+ONlBgbWZDGx1QsNNavbQ51iZULdp1AfXXA0Az8zyqak4WNfP2eyHkFCUCx74nDjyRB5K1pBEnjyoKSGbwxbYzStHscgQ== 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=t/1ZlJ6hZJaDce6b/fep0UVd3G4r1VZkyBk0pDLwBXk=; b=aqBnfrlvs8g6RMbX5cGrapxq0oZIhp/5u7XQZ0lZCU0G1kyI2ni95uLj3H/3L4qrFoHseeP14xvrXCC29z3/ppork5gtXbIJnY8DZkrKWSAPKzEEYoWqsGfCxUsZTuNo03MDGUdvQGjct25n5uDZK6UeuKqj8jlAWkeLkPBS+hx4F8cUOw7/EC7lkWGE2CmJoNlS3QBeHd/zECGUxYtT5GwUYiDIF6V53zxvq+j8nICXGHNknZCXSIqlghphi0k4WgERONSX5fQ6ISUqUreInK/olAE6CObSa2rOI8+zDyqe+pqQA8V0uqc0xO75bhB+PBw8rKHzWejpdemnZfH+EQ== 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=t/1ZlJ6hZJaDce6b/fep0UVd3G4r1VZkyBk0pDLwBXk=; b=RdSTji4gs12tJW++2iqykAh3y+LCjIMoMYtA1XKQ3ItbGQduuJ4pzafCqqoS4Bj08Qd4qQepMMkNh7HddA0VwJ/zi0/ll08CgT3rOJc0J9W0guak0lp4SgVbx86jhi4H6VMnw6Oh7aVN0gPdUGdXR37JRCVaTn2Yx3prILOqpHxQaEfQNXnMMQ/9whJsr3GyhOZiEtNr88eIxyVH3XOQ681jOjS9598d3P43Wx6JsWkiTwdCETeVxfmit71jmmHOor+Xw2gEMKD9O1r6Dfl8sSPWzhg2yw9GChVmowIO2RO7q2f+ccs3kv6HjfisF354Fh84KdnLjO1KvJXOMyRHvg== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.32; Tue, 18 Jul 2023 07:56:58 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74%7]) with mapi id 15.20.6588.031; Tue, 18 Jul 2023 07:56:58 +0000 From: Alistair Popple To: 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, mpe@ellerman.id.au, 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: [PATCH 3/4] mmu_notifiers: Call arch_invalidate_secondary_tlbs() when invalidating TLBs Date: Tue, 18 Jul 2023 17:56:17 +1000 Message-Id: <791a6c1c4a79de6f99bffc594b53a39a6234e87f.1689666760.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY5PR01CA0082.ausprd01.prod.outlook.com (2603:10c6:10:1f5::13) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: 10ac55c0-0b87-41be-7dc8-08db87649017 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d1R9HuDA+yMQ5Wua+eTSXXiX8nQzHqTrYo6f/pwpzYfA3BI22tEBKnkKDDHkAH+yGyBqZ9o27F19qDhg0W68X8ypetqlz+aE6u566GKGmvN4qvVnqAwUI9q6sMkSaBET+/dwzuoTDLrPXH3YIi2MJSQSJEnNMTKrP1HZw40Ir21u4Ax+MzQmfo7z4sxCPbxfk+h6DYN2SvHaNmhybqvkz7gdyoq6ciCvTW62yORcBizgltMZSR4ekn9IU4ENmGaEcbxyBy4pvjXcxinJvV8RbGWShJjUcyL1ySRvp7n6YP6w/SykOCAruvjNGVxLH2jBUKEzhG7WY/1E9rCQBHMniojF9q9gbsm+PrBZQ6L9c6g81guhpW7JuG9a6QU51OFe2XxNL5wX/coCvmq9sL/slerNmT8z2ooozkh0O7hwLQR+YAGNAxB8BS9uHaZ26fBg8blJHPwqGrEdVetEzfcjnNKbsQjRcfzndleArLMQDljVrqjKlZxvI9nRVDwCdQEv3vprFblG4f/SrQFRuwwQY/XvdcrEQw0DFbY25bry0hNR5UB1yKMUuBjD8wtZFetANuikqzsb2iuW37xeushnuOlR9ME2WxgWc3JQy9eOmn0= 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)(39860400002)(366004)(136003)(346002)(376002)(396003)(451199021)(86362001)(38100700002)(36756003)(66946007)(478600001)(5660300002)(26005)(41300700001)(107886003)(8676002)(186003)(6506007)(6512007)(8936002)(7416002)(2906002)(66556008)(2616005)(6916009)(83380400001)(6666004)(316002)(4326008)(6486002)(66476007)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mGy4p9tjl0pFCXp3m+7JZ4PP7jfYckvqyOl/4+CKlw8tRr1xYSBznwgsstqDwNcgtb3+AJJ39boMSMNQpa7S5tmHm3J7l3DXlw55DhbWDCSNyT26yqNdlPpgZG0mxdKHeRVgXnVd5di8hK4PQlm7uzgFrfj4f59B+HnDQnieCB0lTG6EuQrtc/WdiSq8NEnm7x42GCABie/3DJ/rv3txMUSvoXK+4XYROxazw1k2WxUA6p4e5O98wliS4QQfWncFhEz0VncpXlf/jwY/7FBIo7YNa63ad+DCBqZ3zdRR2bT9EaepHGOegFO7wVI0pbOsU6cygtskrOlnIF6xtu/OH0mqWVAmGBYC51gUqY5S5Ay211mhlG5fgdBzGVqdtnoma3I1LWX/g1VvuTBjFTL8I7z3i0BWynJcUWFesu0XZ5sd3ydp38Jche7WAi6JvyAmZEqKV0tJMZYb+SRr+NECkDWkfD0qJgK/asITLafx6QraJu4fHGnxF6x4NbQEdbBvYQ1hgchi55wCveJ3PDyCQtMnEggzPh6vTO5SUPSqipNEZFV8Qr3AlXSDBQ117IcLp1AfbpytsZpduUqac2zQOuPJgZUHrSqv8B+99DTxNahKdAQ5BSOD65tKKkFla0yBzxp7IO+coScBnq2baFT9isHO4k/3IPu+4h7XCgm0WnYPFarbeUJJIKWM09LmyUxA/avKYBqtF+0aqsT6f8wC1+IKhgX79BMXz8hYQUWvlYzJMhWi5cApCOZGSgHoitB+HuxXkvsdeRprG+2S9toxgHAmZrfN2Su3ILYjy2Vl61n6BBZGgLN/ifEvmjuSewJbHKkFjpY8ApZC7IN1IT0l2Wty2Hkf4BAcd2vkIq49+A7iRTDV7y/gqhj8tWWBjc7TNhyiN2Ut1jTJc5oF5yH2g49nzpZhtzoGVg+qra6cDZKhTrIdL3TajI81rMQM5EK3txeHUWuCv/K3xkhQ3pmlnH47t+7EVjDF0wWxKlJE/RLFsgvFsqOwfnAQw59SwRrFNOlLDbMnNcTF6J/xTVsz4p3DCC7ydvfL/s6qxOeyWZsrTKsH+lxMw4+gfuSpOe6z0qeMe8nPPDOe82qCgMKUVJD7N20eHe+2VlNspL2ISfw+0USqNvWkru0WnD90JYOmgzup5mrcarA6oiWfSKmsuZ5Rr1i5huuK7IBrYrmp8/m2jBX0btOJ84PFXSne8r/7kQS+X4MwaBqQWjd/hTgE/Yao47JdGJ2pQc7CisECVTFUG2msBSsElIHAyMGdPY0HMHA1z+iDqCaiELhn0xwfcg9FoaNdGjgFPfC9uN8R0l12WK551mNLFRMtK7nFilbfczRcMusmwAlAdazRr4BbWzZTf5AbfEOTMnrJmJ/zVZZ4wfAmXscOeqIDBn5PgDONDEjooEzApgHAfgBjD0TNSg+h13HrxEKktP++saIVppzDuu34YztUT+HYiA0xnxB05XlWMSKarhShy1xxLxCoLczR6RwGu/KGziF6XfXNKjh97d33BQ7GMAxCa8GdlGqnqfugzlzgkMSJhgS4TY5QVfVzmkTHr+yLU9o4TshrTxc+jOpA+lCT6f+sWKeRkL7M X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10ac55c0-0b87-41be-7dc8-08db87649017 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 07:56:58.8316 (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: b5oQkw+iskrQNiL2SgbsA1/hfrC74KIshAqfJ0Uf3hs3nzpb3cpHxpQ9kdS64USkXUoOF9lJUv7Uyn4nmG7nlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 X-Rspamd-Queue-Id: 8957C1A0004 X-Rspam-User: X-Stat-Signature: xoanzexutzd4rimhw6a433trwwmyydar X-Rspamd-Server: rspam03 X-HE-Tag: 1689667021-318547 X-HE-Meta: U2FsdGVkX1+H5BtKipf2jiseFaGNpRTUZVtqsgt++V3J/LDYwXn+627JMbFKzRmy22etZEWfkuDkI41OEPkB2gJUroidQZocMO3YGEWPZB7zbHms6DZokm+rmDGlKq0pgNr5z1STnJfR5KUuwx4eHpTeKhJhUN7YlpO3yAbOdCMbLdh6A4PPJ02X9fSwDKrV93zyKEX+2gMs2K781dWtugb3fDxJiktSX8+aq3KSg4UN2/nMW0jqBddeQ8gc5AeJ5cQdKmQbafRj3irWgK09kfEP+OHua9PnhmfkV/gRCqU7M80vXqZWV34Dm6BIXNFS5WjUj47RiCwHb2RKMGnZZ8DmlrCA9+vwwzMhmEKetzG2vERH9Q+HNwLxkcjTZDYk9X6mqMhnJAWctws5ZVg/PX2nY1Dw0jRoU2glCB/KaagZsmyi2Py0qiaLKafmpfiBzMfPsudJ9xMyhvU5BlBxGut6FIocE8ZVQ+ztOE/FLVNpoD+q5tmjzshcBJSag4chm21R9XhzuxTeJsucEX7gY3Lr9NZlzS1x8Xw1fPvbKwv2ir60Bc4wpsvcZI2L6NhBkOfqmfSuDIPkobcf8dzT2Wo638mdfMBgBb2fGUryyKd7jFHudQ2RsqnC8bGjaH0PvNyF0wMaQ/SzBDiKsQC+oZvOhAtyfyKMuxwtP5RIR2nm5Zw9JvNj6PfqxeQos3AXPwmqqj7Du0x8iOrmTikeKVjdLURlZQS9G4gfVeEWMjn6nV1FSlbbCejPal850sM9Sw65ZYLJYcwmbvDwnyFfhsylPZj8/qzvNlP2VK3goVFaK/S2JlHC6tTdntUcAbtuZopsaowmkMU15MhOf02xqgJGls87thVLlpNb/QUuV+E94wHB755z5hMBNKh9EJgyXSrLtaauzym1LnL3x3Wg14RWXn1w1IB4b3kOvEidvGBaTzl10tRnu76u/80iVDgRYH5arO6F71rN4i0JfN1 wTc1qjM1 0axmawsYDrSau40p/LYzopltX0hQiXUnLSQVMtOoo0Aa0A5+zifLx7pSqTdzfDMQL52QrR/dj1tEP6CKcHI5CcOKV2/7gPn8sGDNh2x413DlgKM6g4+a3OAGiTg4rCD5w8zl/p7ZQx9US9fwNuSTv/wwHVgXTq8qMn7HWcuhoiP0ZrCmsZ4pbJOzowBBIgix43tTTi4s2QF9zXuAC4/OweYz8RbeCc0nVA4WTJa687IdNT0c6JsNwbeEQ3wyIu+pdkEoR6GzA3se/cYg0OR/lHmes6z7JsziCa55EI5sFDVjlyH74JmTiDuKROHsAwKjyKBMRjxtVuj7jJCye82P4AZjLdyod7NviL6U1aEealwqcWkx5i0aQG3GIWPRQ65AS1UgkhDYEthHAztw5AjKrciDsUQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The arch_invalidate_secondary_tlbs() is 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 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 --- arch/arm64/include/asm/tlbflush.h | 5 +++++ arch/powerpc/include/asm/book3s/64/tlbflush.h | 1 + arch/powerpc/mm/book3s64/radix_hugetlbpage.c | 1 + arch/powerpc/mm/book3s64/radix_tlb.c | 6 ++++++ arch/x86/mm/tlb.c | 2 ++ include/asm-generic/tlb.h | 1 - 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h index 412a3b9..386f0f7 100644 --- a/arch/arm64/include/asm/tlbflush.h +++ b/arch/arm64/include/asm/tlbflush.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -252,6 +253,7 @@ static inline void flush_tlb_mm(struct mm_struct *mm) __tlbi(aside1is, asid); __tlbi_user(aside1is, asid); dsb(ish); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, 0, -1UL); } static inline void flush_tlb_page_nosync(struct vm_area_struct *vma, @@ -263,6 +265,8 @@ static inline void flush_tlb_page_nosync(struct vm_area_struct *vma, addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm)); __tlbi(vale1is, addr); __tlbi_user(vale1is, addr); + mmu_notifier_arch_invalidate_secondary_tlbs(vma->vm_mm, uaddr & PAGE_MASK, + (uaddr & PAGE_MASK) + PAGE_SIZE); } static inline void flush_tlb_page(struct vm_area_struct *vma, @@ -358,6 +362,7 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, scale++; } dsb(ish); + mmu_notifier_arch_invalidate_secondary_tlbs(vma->vm_mm, start, end); } static inline void flush_tlb_range(struct vm_area_struct *vma, diff --git a/arch/powerpc/include/asm/book3s/64/tlbflush.h b/arch/powerpc/include/asm/book3s/64/tlbflush.h index 0d0c144..dca0477 100644 --- a/arch/powerpc/include/asm/book3s/64/tlbflush.h +++ b/arch/powerpc/include/asm/book3s/64/tlbflush.h @@ -5,6 +5,7 @@ #define MMU_NO_CONTEXT ~0UL #include +#include #include #include diff --git a/arch/powerpc/mm/book3s64/radix_hugetlbpage.c b/arch/powerpc/mm/book3s64/radix_hugetlbpage.c index 5e31955..17075c7 100644 --- a/arch/powerpc/mm/book3s64/radix_hugetlbpage.c +++ b/arch/powerpc/mm/book3s64/radix_hugetlbpage.c @@ -39,6 +39,7 @@ void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma, unsigned long st radix__flush_tlb_pwc_range_psize(vma->vm_mm, start, end, psize); else radix__flush_tlb_range_psize(vma->vm_mm, start, end, psize); + mmu_notifier_arch_invalidate_secondary_tlbs(vma->vm_mm, start, end); } void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma, diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c b/arch/powerpc/mm/book3s64/radix_tlb.c index 0bd4866..64c11a4 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_arch_invalidate_secondary_tlbs(vma->vm_mm, vmaddr, + vmaddr + mmu_virtual_psize); } EXPORT_SYMBOL(radix__local_flush_tlb_page); @@ -987,6 +989,7 @@ void radix__flush_tlb_mm(struct mm_struct *mm) } } preempt_enable(); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, 0, -1UL); } EXPORT_SYMBOL(radix__flush_tlb_mm); @@ -1020,6 +1023,7 @@ static void __flush_all_mm(struct mm_struct *mm, bool fullmm) _tlbiel_pid_multicast(mm, pid, RIC_FLUSH_ALL); } preempt_enable(); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, 0, -1UL); } void radix__flush_all_mm(struct mm_struct *mm) @@ -1228,6 +1232,7 @@ static inline void __radix__flush_tlb_range(struct mm_struct *mm, } out: preempt_enable(); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end); } void radix__flush_tlb_range(struct vm_area_struct *vma, unsigned long start, @@ -1392,6 +1397,7 @@ static void __radix__flush_tlb_range_psize(struct mm_struct *mm, } out: preempt_enable(); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end); } void radix__flush_tlb_range_psize(struct mm_struct *mm, unsigned long start, diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index eaefc10..0b990fb 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1037,6 +1037,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, put_flush_tlb_info(); put_cpu(); + mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end); } @@ -1264,6 +1265,7 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) put_flush_tlb_info(); put_cpu(); + mmu_notifier_arch_invalidate_secondary_tlbs(current->mm, 0, -1UL); } /* diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 48c81b9..bc32a22 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -456,7 +456,6 @@ static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) return; tlb_flush(tlb); - mmu_notifier_invalidate_secondary_tlbs(tlb->mm, tlb->start, tlb->end); __tlb_reset_range(tlb); } From patchwork Tue Jul 18 07:56:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13316830 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0773AEB64DD for ; Tue, 18 Jul 2023 07:57:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E1E56B007B; Tue, 18 Jul 2023 03:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 991B06B007D; Tue, 18 Jul 2023 03:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80BC08D0001; Tue, 18 Jul 2023 03:57:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 71EC86B007B for ; Tue, 18 Jul 2023 03:57:12 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3DBB140209 for ; Tue, 18 Jul 2023 07:57:12 +0000 (UTC) X-FDA: 81023977104.28.A212394 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2052.outbound.protection.outlook.com [40.107.95.52]) by imf10.hostedemail.com (Postfix) with ESMTP id 53492C0008 for ; Tue, 18 Jul 2023 07:57:09 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Vt2TBHhs; spf=pass (imf10.hostedemail.com: domain of apopple@nvidia.com designates 40.107.95.52 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689667029; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wdUnKcYe2CSNvlJDQGklH4bL/DkXlTJSioyPKgnLYDY=; b=A3ItetdfI6kjmp8FRA8Iai8Nd0LXVO6y7vAYPIEvI24d8rlIqcFBqGL/XoXw0Bv84SZK2r Olxfk/8Ijs9cQOtNlri82eEK0DtQp4PfQyExfw9tTvX+wSXGQurRF08oezFCv+mUoNA8uU W3b2TOaxDQQAvXD+xUvWtEwX0J9//kU= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1689667029; a=rsa-sha256; cv=pass; b=IlTcof5Ms93DYnH8bDYfS3SyI6s+RSxB4I7Ws3CtWhl6YldoHCP1vtpBc9HCDggwH78y9W nJxmsKSLqTMO3dtMpcgXQkzkbkm0gPc4+iarRTBJsejrb3oqunV/m1X2Qrh+GVF9ccAyq6 o+vkvDG/Im86atXwme2Q/B43JuqboGw= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Vt2TBHhs; spf=pass (imf10.hostedemail.com: domain of apopple@nvidia.com designates 40.107.95.52 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mGijM2jHOs9HZwXL6n467Jyof44+adzz+rIVwu9dN+kiVemHMkOiBebAH/I7ha9fMqgji7L0g29AUWFKC+DXRD49CwRRz/zOXP0cXLiHcBawsNadcvDnLHVNaBBmfdxjfPPSbv7/EaMtpcuoVF01IU2Q0n0RBPm2hWDPQyc8a4IX7VgHiBDVsgJPB0emDhd4psfzbP8GIroiuBk1Sa0RIshArW3fnlTq3Xp3EWYqIhP2ayIPF2O0JUakXCW9J8fe/eAevegFD9keoHmBpYly9sTvhuGoQgaPpg2T7RnOOUk71iq4DKqInkYRndLj6TcEbq2s7rsCwCmxOCCE63DjHg== 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=wdUnKcYe2CSNvlJDQGklH4bL/DkXlTJSioyPKgnLYDY=; b=jL07cKqh47MYHOhARsWxDvUwIVR6SWuJ6KHDn1/sgTox95V+Th4RG4kmKneyVnZuRI9DgtIBiVubsoomPFeDi7sa+0b67dRTwgxnmMFKhv7u6KyAzh1bQSQfeygcD6RA1eTafO0B3ARugKLj8TiEf6OfLRuWMCM10y0NC1cwtZBk2UquihA4cVmsZD0Jw46IKTy8lMCclFhOY9SuxKGZh6yNW5+fy7/P2SY69J1PieSAKH8QwIrk6x/LoW025xvRoPV30HF3M1sGHjCr5cFnnNnuQgGl+9s98kEXCtTgPL3J2aU00x7cR43zb1n1f90z2PqPUqGl0uoqo4gUkZUvHQ== 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=wdUnKcYe2CSNvlJDQGklH4bL/DkXlTJSioyPKgnLYDY=; b=Vt2TBHhsur1WFoCnGP+NnlARhXK/3RkrjjSYOqI0C1gvIEibnBzk1LVluvfaxNDFkXuzWXcgtnFen9ggX6sTJVEP3TAPhu73y71brRUeyUqOs9rNDaL3ehgPSEIq8a0tIfDy0c3KSQmDE8Tl8f2xWfRTxQ8j2SARMq3vYTfzi6djGGmnUJFNk9GoMXOQ0fUfu2TNvhJopDKSjYO7F4IY06skEptxDC67SXYuVDaUdx0cZd9fO8XeEWkW1mdZaiOKlcEgxA8iLDSIgUucqMbQquJ3JtgDF3w11N5Co3dPvqfssAViV75JmIj3EgzL5hK11CvCdB/J+KXeLdv46qRz+Q== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.32; Tue, 18 Jul 2023 07:57:07 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74%7]) with mapi id 15.20.6588.031; Tue, 18 Jul 2023 07:57:07 +0000 From: Alistair Popple To: 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, mpe@ellerman.id.au, 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: [PATCH 4/4] mmu_notifiers: Don't invalidate secondary TLBs as part of mmu_notifier_invalidate_range_end() Date: Tue, 18 Jul 2023 17:56:18 +1000 Message-Id: <1de2f1853687c635add15a35f390ce62af36c5db.1689666760.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0010.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:208::19) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: adb2e1f4-dec7-47ce-15e9-08db8764951a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1YWXOm+cPFdwlO8e9eKCF9Aca8hnOYhrImFOxWdQf2aiWibPrcqSynwabgfZpiBO3m+7wElFIF72HsiJTDYbwHHUb/9ewQCUQdwobaJ9O/omoUl0OUYgHTdvRsu41ulSN8e9AbioCyxEaaYxyRUi0LmQMx9rb/E1Hx1spM89KKCutiTPiStUwNhSSddyDrkR1X/vZn9RC6s+TbU+bZZSFt0fsCENCbpXo3pda+2vGP347qjqe91OHfoUkBJEiQo+3v1GiK0zz3qTxkVJXkyxzt78LDkfs/NPZhHcmtefnWkpxv0WXmeSEBwa4x+tMWOP8OilxZyPqsbJbf1qfCG8KsIljCgjIG4axVsnnK2GfTZBAZ951ggVbPqdxx6ujjnUyuCR629XnE/cDmdF0l3DC4Z68NN7etKSlsvq6HJnAVXOMX4AfqPrBIbpx8Rm6JSL/Hkp+JMXnM8NJ3Hz37cKu8Ti5+0DtI+BZlLHyeHm6FhELe+N/fNPP16IXQ2j2VPo2Qt3P3zaptVPbQTOoiNr0Udwi67u6NVESUpB+BeQdS4= 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)(39860400002)(366004)(136003)(346002)(376002)(396003)(451199021)(86362001)(38100700002)(36756003)(66946007)(478600001)(5660300002)(26005)(41300700001)(107886003)(8676002)(186003)(6506007)(6512007)(8936002)(7416002)(30864003)(2906002)(66556008)(2616005)(6916009)(83380400001)(6666004)(316002)(4326008)(6486002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DbsqD9+R2Ow4fvPy1uF70/k390FL3sb49dnOYcjDwu8acrUxMP8ojPwJ3sgUZtaRHUnaiE5WOVjVuXhWmXW7bWi+wsTtV1vBLbMqHJ32/YU6gkMYFvEz9SFR3eRemTiqa1bCC/p9u8lnwEEDwkK/q2WAekT7k6o7l4rskPuv470tm/ssTEo7cYu6Qg0B+baozfhV2LP3jS2sN5rTwoFp0wFwPLdAxHiAH6u+3OseAaVmRdtu9jS6wquNy/Q3JWT9I8gO7+fRwwlMZMp2B7o/eGF9gh35D9IAMMXzYziJJ7zDK+42Xf2k1MNwMKjbYSjMKLENsBn7XqlsXuTf23KynT+WoHc1E+UrHqPHLTUHRjd9gx5Pa4LfAAiGZAbYELFrw2j2ctSbePyInfkK6e+2xepAQ7o/If0l0w2r429USbyhD9iy6zeQehx8w5PD4ItOPWChipikzFL/Uk1AdNuqZBjMKwk3HpUzD/+OYV+ZOR8nWARINSmJbtCLpNXH3fDpVqGVcS/6JPPdKv0w4U3GRGixi+8cDbihdVr+SBEGBc+P0u1xC0tAgzeX2G6kSriben/eB4+MpnLoDZHvCYZoIL70Yc7i0uof4Tcz04BcCKBOjkR2/2jH7GUuLpmoavYAK/rFq3ROfhi49/REdAQnf/bYCGzqpJd3tqvLSqsYK0utg37LYXFcDN8Q1Pa5Op3jQhcct4cwBw8GJSPAijLqzk37nk2nRyHsLlaQrwIKudJeGTiUvnG6jmxwX0yuhNEighOUCV64ehc+acwpRKYUQVBM8gfUB289L6DtNkZVvTVZ6MIYivx147rs8wpYPpKXj4FCFsKnvw/V/TpltCA65iy9qBPXHgl6HASk2ZpvpwTpmrhFxx+nURMPB+Kdn09dwV2l3IPA1BaO/pns3532Uf3qXXzreepd41lc5AVbZYPaFQGPMZKPk7aOR8upBDrqtM2m4gLQ/TV0CtYy0gb6jEoF5KBb6wupKiXBMsJEtPGSXiSmx5N0omYfazBT0PK18rc65QX52+bzIRvI4XVBBnM6LP98s4UVJ8zwVOTsxIq28ggXK35d7QjEfMpe0ZKsLeV1ZcibPliR6Tf4zVa/Gf1mf3lw6NucVjF8/kvukmrzPDYTl3eLrh0bMnsB9TRq9u7zLRklW2V79N88Y6UmhMex89Oflm7amOWaV8GHpehlmIZPW70/nAbHqueU8MjX+wszbKh0nzV+78E0Tgin6CNDejPlXw3de/KqXqfSLRdMLkeGzF+jSPk6qYJXsMPLW2X5GRGsKQZm+bpGBDneNXpTIIBosz/0nU1hi0bPD9/pxpCIs4vS96C+gzAlfAMdFy7mUcsuqGolqT3JvpFwysinC1LosrU5NHjMt5J8Ibc5ylU6AaypJryCgDNE33sNF/tN/VguSH9FRHpcdrrvkF4/h5kjyqGgLYInwMpWOL8Dy3wYm12PsKI3aX0O/5CO3FLNWVncfFnbO+Of28FUhDq2hFvx+Pkr2Xbni6iOYv5lHpySlpMva+Il0ZfAj028+5M8C6RpClbcIWChVAnWFyY6WxgySFq9ojHOcH/PZYKPYByqTmznoUhk7zsPr3H4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: adb2e1f4-dec7-47ce-15e9-08db8764951a X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 07:57:07.2235 (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: u1aeg0CygsCcNYAa4UNvE5G7AQ+HOUuS11L9qhldZU00jRgmn510GnxEh0LKO35tkEmHri5fiXOLowyz5yvdZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 X-Rspamd-Queue-Id: 53492C0008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5t7ugwwc64xsiemfppdiwcttzuh4egtx X-HE-Tag: 1689667029-48457 X-HE-Meta: U2FsdGVkX1/KYy1UZ5tyOWMjXu7Guwz7gq0tya9+5Gd0fL1e6KUsCGbW/WjyFOx78cDGO7Gz+O/31nbnwc5t4wlTOqnF0ATDmTsq0UXRFWvMNmSIPdqZu/SKXHVLgZ1zgNuSo6SAV8Lz5CqBNrLji9UYdlVG4kDkgWGEVhUFbJ4Vd/OyG3hjR+CPGJLvAjLhoGk/74zxgQ1MTMD6pGOlsS06rq6vyuO5BdkxvJw5pwr9YiVKkHCyFXUaT8TmKMiDxlhrjfQViBYE9QoEWmd8E9olSdKzd37/uIkap/W1IWrZ4VBvO9RysQJYWSoaSU9lQJ3xHTeTiHmTL68ePtqTexm/DcyYkNvpeWU1mAMtFb+H7JDSrCd4yY1Yi3kwKXlZlh1lIUV4IKRt7bpQqR7l3FVVp0Pa73yBHU9jIC4jaEtJ9VABlcSY2d0eDmqC6guG75tLyti66U3LpgHb/wsQ7FgiUUXgmsk8Mlz82tj3LJ4FSu63qPGaI3wU24r3mzvOVcLK1/d6nDzkAK06/pwZYs+cFkC7lED1tOzyslBI0cI6TY81ByfxFy5UXzTLYT8nYXjSGWvXJdGpsBMwv0HEvufN9pBEiYEpb9Z/lRFw9gzF9Z2XaNAXmCZva/BXPOkWKskBwbihR7K1bfawFStA8GkW5S6BrAtCdMZsfOcHj0hBXfe02a+Nnq8StgrL+dXQugVyvAJfIyUmb1uPcsUlU42cCxpDrmtqx6S7XsoNOH1qOa9FHH4ZONdNKx8e9iWNzB+/lY+ymarGHvBbEvRXuxsV5gC3ZF4FUDhaTqI5xIcoedPliVOkU+4aIuAUKYOhT90xRef3zsbNUGWa2pgXGbEnZOa9hrPS+9arMK/5P0jz4t6pRXPdd3S7GeB4WHeSyZ8VSXq7i33G585xMfEahpWI5EdASyYJbg/FzVI8ILLCJ1C0xfjI2s5okCU51IxSQb2+Zjlp23f+jgH4fI0 n2xVf8ff MRhxGqG7XUiBDlAHxBvxuUdLaLqwtjBD61sJw6oWGdnBg7X5mJiRwy7MwTnUxY3mhHZabeG3Wa1DSANBj5OxxlYF4DFSbQruCkcFQ0f4kztTj2ule609y3LdCCcfyvn5gSdjcg0R54f/88K11THBRBQL/bgLUCXeadSyLNTLqrpVqMBf1KwJ6yycIv6jE52zOBOUFkRgOGn42a+X0rcquOxwj8C6dvuFXghQzG55Zv3m/68ZjrKcS2EEdKtd04f3ui3nBYBoG8wPyHCiPKt07VayQzGTwUy8vtdqbtqZ9SDpSAmtx0ylMpMpJSXLc0x+eSjbyShityyOvU3QOH8D21yY0hw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 178c930..b903377 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 01f39e8..fbfcc01 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();