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: 13318584 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 E3C03EB64DA for ; Wed, 19 Jul 2023 08:33:53 +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=lkNx0IVnL+LfXLg+BfIlvx9naZCpoc14RmKYtJNke8c=; b=wFo/4U1qF/jI5t SEZI2w2LOhj7jLRpy3U19H3rTz5S7XM8RL9CVweYjIyHlkh7A3l+Lw0Mjn3KdIb8Jw0spjrRHhYQU aeENcct/zLq3k9wB0HWmPRFOkkOJebWsRUQ7eStuJX/MEdBbu3aHGFuP+AqlKf1q/ffuOpz2lPwJK 8OwoqsXV2Y2m6m5XlG51DtBAnl25ZjsZyglKTSHktUGAtXZUxXg9dORGwcN6doet1FwJ8tkU4uxrl b3RBrMNEzhh3JnlsKNQrHkQiIoMR6CcNRgkZOL/EbT8Ao38EWmiANUIcoofN2qENtJ3pMfhZVYyTI lN5MLr8nlRwIDEgegqAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM2cm-006NfD-0C; Wed, 19 Jul 2023 08:33:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM2cj-006Ned-2t for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 08:33:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=tCuVkJ79cafyyFDauw5qSP00PO4pGeDUP6r22cJI8Nk=; b=Rf16CgQrovl5EPgz6ONVfP7eqT 4UsJsYDwNGVpTG/zKuQwczT0cSCmuueWgmlHL8tG2/y+IBmyxRQcu3ur3ht6581Ln5/8n3U75dMkd DxgRzTqYz7CkaC1duYigW+K46bw/lG5rUYXtmBDN9C0vUZWRv3FbUWwxq9mjxliH5xp9IFveqgx2e v2gUYdt7AUaOjPw/xCFwfN63hNaaILiTEYzbAVHwN3013vbhQawtBQTPsmrmXwtMPFqmCCXi/pbEn trIUgP7ycFhKC1GCMJPmlLiscCBq0pNlZiSh88vRznYhbNJDmOm7o5WqirEUMkHIIQqCwo6k+RGCm ULbiUPuA==; Received: from mail-mw2nam12on2060c.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60c] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLfaz-00BHw8-18 for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2023 07:58:13 +0000 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== 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_085811_380041_C9040AB0 X-CRM114-Status: GOOD ( 19.70 ) 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 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: 13318329 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 87ABBEB64DA for ; Wed, 19 Jul 2023 06:27:18 +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=7bYzXP5GUkJYk8NxkDJy3oM57+Cqh/dtYsM8w7ugO1w=; b=B4dhDk1ssTOE6M 9Q6l12GBO0scjWGJqUrOg0TloyMSG0kVuiIohsqouLmyCWy7L/yrgMM4iLPXwd0GSMn2YbtVB6R+X 4j/qgTJFHLnLfkvUYZG3MYo2wmZNkHbEWFz/OkgsI1CsfCAqLj3Lr6UAEtwLphR/h4sIuQBfUzHEl qmiGRoknSxobe+dADDurQhhTrvHdSi/w0iGDgoIreei3CCnNaUbnVjaZPJqOzF4czP2dBi+TxfuEJ ANaUssIyhDIXzVGj3gHK1Y9F/Kuggfy2VwiyP1GfUDLe43TFcC9ADEt9h2UsUPKVf9zfm7pFi+IKn K13EOpy2ziH7NeoJwzkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0eJ-005jKq-0u; Wed, 19 Jul 2023 06:26:59 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0eI-005jJw-28 for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 06:26:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=WvW9mlxbGnKVcvKQfEGVo3jXEFbWzwdMBMfBGVX5oxk=; b=iVG90u4R27PCnyfR73MfO/LKOm EAGHqi4spDmY6KWRE6z14qAMo9VGOIqeq4V829mcM8adGCatC/J9OGvr8xPYxchpV2Ctj/EuaBEa6 fAHQi+vLj+o1C5RFetLT6qOl8TrPATtJ2si6Q91PDpjZ2QW1zEpdWL4fYxxJwMv7nQggqzYPQHSBr VYpY/V3HCrywdr/VyI34tmQHGHAHVmxLQHELF1wHBaSis/mg4gz/CmseNiNt4+0FQxeNWh95cnBWO kIfQuFiDM50tcZFX09vgT4cBXnAa2jGwA5i8ESVATvanqdXoAqr0uyXxr9QD8ABYbUICRRf6L6ugW Q0BON4sQ==; Received: from mail-mw2nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5a::618] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLfbQ-00BHx7-0z for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2023 07:58:38 +0000 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== 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_085836_563160_4D0042F8 X-CRM114-Status: GOOD ( 15.28 ) 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 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: 13318559 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 47B7AEB64DA for ; Wed, 19 Jul 2023 08:20:34 +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=ZiFdRS0N06+qS7I/XADzDe6+DLX9TIpKvAXyGjkh2zY=; b=e5QDW0AyX034cA JUo7ujCgQGMTRBfEVaTQe1JfLGm8ABbkgsgfbSJrKa2/J4ENsDcfNo3zAd7wUVG+nnusWDbu3iRA2 ZoOvA+2AscPv15En++7VUFYbA2GK/BlskbDdZUkg6wqcleI86EX2bnnEWTTYOVfru4/8oti6SWCrR qBWvM1qhNgX90r+Rokw7QB4J+17Ps0Boe0L4l9/KqTw1mgbK8uZSzIfPL6XKjriHNDOXRm+1Tug3C Upz/PDUTowp6q0oxMwfSFsVeT8+1irKz4bhsDqcL1FwfaT1ShvhGkPeozcizeyLcIVD2oRV8xBO77 osqB9jJwxyV2hA+chtiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM2Px-006Iaw-0y; Wed, 19 Jul 2023 08:20:17 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM2Pv-006IZt-2K for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 08:20:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=t/1ZlJ6hZJaDce6b/fep0UVd3G4r1VZkyBk0pDLwBXk=; b=a1/HMtGcjxgNSp/MDpXafu5zVx M4vKxokU/AtFcNss7XMfm5p2zcUMq3dL59NHnhzxCXTClco2yhE3Q5C3RoKWsEqOSE3B6Bvn3XjHS zgUubwPEnVgXFsOJJizh1InBHn3Ikh0yGBbrwQdV/CfmZdjx973Q0GPSmwihuANMR/d5FcWVKzsea Dqv6mUb/lddyS5rt+s+nIDYNW3F2OKBN2dppybUygxGCHxzNKbWSFWswPO9sBcsMVzDrkT5AePtsK aLuCf56MWL7RzRnPKUhR8xyn7B0HwXnxv6eTpJuryg9263W2mVEbHMki/t4H4aHypadis1dv00/UL Wq48nq3Q==; Received: from mail-mw2nam12on20621.outbound.protection.outlook.com ([2a01:111:f400:fe5a::621] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLfaj-00BHtM-0d for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2023 07:57:55 +0000 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== 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_085753_458462_9A2EE51C X-CRM114-Status: GOOD ( 17.49 ) 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 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: 13318531 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 F2EDEEB64DA for ; Wed, 19 Jul 2023 08:02:16 +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=OaPsqDO0T3DGIY+Sr46+QKhsKI5zwJ47g5cdbwb3Um8=; b=aQvsNvkT5GEZZY ozd0Y4HxbPNCdhurddSA06aHz2xnMfdP6BLt2WF4EwRBYJOKtH/MPO6m1ZxaY5Vm9mx6ct6ehe3KL nfvgvZ2PIicmivlsAwktijbezKhLt5v0J43wGvmH/MwMojy6sTPc7htb89S2t/lmRuMluiujy1+lR jt8Na/0AVHmLosbNXURtSzrAZ6gSf2aKY4AhlYU51nCzyJL1svEOR+p447XxDFtCwL4ehZyteTOI3 FXtWVE/yHwcEqNTT2XpEfv7/MPBH6IU5zJE+26Lq/Ra7hLruoBIOPUtZh3ppTPojWVUyJuszFjkCO pzb9gvgGlOLQyuAaEbAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM28G-006C2U-0E; Wed, 19 Jul 2023 08:02:00 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM28E-006C1h-1B for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 08:01:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=wdUnKcYe2CSNvlJDQGklH4bL/DkXlTJSioyPKgnLYDY=; b=K13+an5ob+5bIL0Sy8jxW2v7PC zpJiL3qUjQZ6VF4w0gYiyU8DIj5AJlc48bkPFrAqagDzyJ0cNC8zPBk2b70nhk/JvCY8QqkaJju9v IK/l3QyBqg2Dw2mDPCkgl7QW0zzSlAYr1tnoCnMKdOLaC+edOANUHDFeJ6OURb/ltENmD2rM5Tbj7 +yId02CmZr3hBdP+rJY+fjUG2Wf+lWT6BnrXVs8VLQPoTsr1AnLJdGVFE94M5GpEsu1pe4pyHFgBI NoeelG8rYqL0JILkqVcQSVpKv350IUOSIdDCNkQxzKPi0Ti6P4vtFvKg2JGGLi2njczanUPZmG91O PQSambgg==; Received: from mail-mw2nam12on20621.outbound.protection.outlook.com ([2a01:111:f400:fe5a::621] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLfam-00BHtM-1Q for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2023 07:57:58 +0000 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== 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_085756_643669_5DB2A5B2 X-CRM114-Status: GOOD ( 17.70 ) 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 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();