From patchwork Fri Jul 7 07:14:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13304489 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 24D01EB64DA for ; Fri, 7 Jul 2023 07:14:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF24F8D0003; Fri, 7 Jul 2023 03:14:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B7B198D0001; Fri, 7 Jul 2023 03:14:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A60F8D0003; Fri, 7 Jul 2023 03:14:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 86CA08D0001 for ; Fri, 7 Jul 2023 03:14:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5917B160C8B for ; Fri, 7 Jul 2023 07:14:48 +0000 (UTC) X-FDA: 80983953456.30.E4263A6 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 67AE640009 for ; Fri, 7 Jul 2023 07:14:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Vmdfrf2t; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf07.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.44 as permitted sender) smtp.mailfrom=apopple@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=1688714085; 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=KgEGSQwOnp8v3pdN1FhL3pXG/ec1md9gcb2/Z5r+vBk=; b=z8/eGqVUHMyosGQbCIvJLvP3sD+lLjPOm8QTVr5TQ+G9kiLZlT7EWi9Dbe0UTgC0aITKut TRJt2psiT4yx3LWZVNOIIdTG1wGhurdkl+rlzQYBiMuJyx3MrRfbDTTHpaxAULAK4EuSZH aW51TX2hFow3TNiw1naljGJI5USQYPc= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Vmdfrf2t; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf07.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.44 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1688714085; a=rsa-sha256; cv=pass; b=6kCP9bWUV3R8tn+rFsirHMvayUsuvoZ15pMlihHA/MG9bmxcXsf70p8YBSzSZC+4oaGim6 J83QtI3eC2TTAa02hA+zqVZpxBDi+s8gOZrgmIYGFqOdjWgNhkjpGMIxTorcU2vMRNcBRp 4veMdnAfFW64DbYEqcXv1fiH8u3BNO0= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KdT2zNvB8OsQyqR1+TYXHwBi6GBGllkXIuSrOF8tV+xRyAkNkX3xPjCah1txhnblBGvh0nJ4rP4N1TWISogM8Cf/isszjb+toaO/WlBqp7dPeuYM8yR6JRVqtzdVhgsHRpSPifVwULvmm7LDt6kWZBoYa4tS0ve3FkZgU8F9edYFstFqIrThux1tOOpaaZNQljjJ46r2t39YowVRFus9VjnBnwvreP7NxhOmjLbvpEBmN3a2tJ8EhCsAlgsyXIR2SO1j9EmgH1/I2ZqHjR71QEAXZOibCkjoXSvrkAaCHlxp9mnbbc6g7Bv5iVtw2pBCzid0zLjAFxMFcEKOyH3YOA== 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=KgEGSQwOnp8v3pdN1FhL3pXG/ec1md9gcb2/Z5r+vBk=; b=WMCY+4/nGJTagLJZaldbK7Pnp0PUJ+dO6plRACeRT7oGIwmO41naW18ixuqrdCngwpPo6F0ccCnOGD4K2+gV/fmmkOrLKu5DNX1tu4UCn9NSUlWXjXoMVF99esgW6IJEP6hCcg5z3nvx39LAaTJjJdk6i6padXlpcyW2IJen48hq1i40OVduObz4howoB14Oc+50zNycz40N4REKwZsF2mbYuQGPGmiVBxRSHMJF69hGRlA5IhZD34vw1F28cfdny8FInXA2ivshDh6JGmvMo8sVx31Q+s6bG4i/sby5+JEII6ZG4IZXX08RFSrNiIZVfizsb6AbfCp69IE4QgxNYQ== 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=KgEGSQwOnp8v3pdN1FhL3pXG/ec1md9gcb2/Z5r+vBk=; b=Vmdfrf2tcNhFquK8HTQ9qTAqTRWd4utYe5JDL9GL//79GIMbLfXfpOGz+9gDJEFGtfwXPqxbLy2vzFXxSkgYioz9+soFPtWvx7slcVMIO73agFf3l9ZhrcOzf3QcmAdSEDFgD+vulYLmcXUkOWZjHOSDVgmr+Prs9et2W4GRMCt3WnsGuyY//GVNGevpbWStZvpqVVnJsuNwGW5h6EU055obTAR+0X8zgMZyGOoc6goWwiK+hA9r40r864Z6RG7lIZlD9/9xwmYsuLe1MMFUrDM8nl/uy6h9kZVzI8slahc81Yp1wg6weM4RG/nDniqIAUCCvsVoqJYgS8GJV4lxhA== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by SA0PR12MB7075.namprd12.prod.outlook.com (2603:10b6:806:2d5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Fri, 7 Jul 2023 07:14:42 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7%6]) with mapi id 15.20.6565.025; Fri, 7 Jul 2023 07:14:42 +0000 From: Alistair Popple To: akpm@linux-foundation.org Cc: jgg@ziepe.ca, npiggin@gmail.com, catalin.marinas@arm.com, jhubbard@nvidia.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nicolinc@nvidia.com, robin.murphy@arm.com, seanjc@google.com, will@kernel.org, zhi.wang.linux@gmail.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, rtummala@nvidia.com, kevin.tian@intel.com, iommu@lists.linux.dev, x86@kernel.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, Alistair Popple , Jason Gunthorpe Subject: [RFC PATCH v2 1/3] mm_notifiers: Rename invalidate_range notifier Date: Fri, 7 Jul 2023 17:14:23 +1000 Message-Id: <863a7b3bdba88ff6a72b20a35026e07bdd709b31.1688714027.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0012.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:208::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_|SA0PR12MB7075:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a822612-f60a-4800-8587-08db7eb9d599 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aPI9CEo5cMT+navft+Gu1JTL1IJKRHihZPS+HJtm6CmJKHcDEEwGub81bRW6cqToxHvdII1whlr3y8GQa+uzcSl8OKt1dvd6mzJZGVh17XPqzqeC1x6VCN4sElWrS0roaZcGsrCqMuErAaw6Uga6YmXkBjkOYABR2ouEAUZSiwLykeCOsTQz6JCvmv6iqrSrEs9dbLtZ10intc3OeCLdtUvR6meVwOV4c7AKmJ2rJJ/s97Zm929D/1/GSBo1SgXvDrNiLfrbLyI15vbnrapZtCtlvIN/S2zY6+OF6dx83AUazskuG2DxD7kWokdvmXqICXIagxhNhwQjBLZ5QqbhCOe4wd4EQBBnntdrzuZWtL9WhzGiewfKClAhGNndMPZAuxfQZiXlUsFxJx5pL5FbRctgO+/xJvGfUPHFvEpxvYrVI/+gBMFzUnkZ2c+chOUDpmcen1nsLnnoBbHrwMy/YpvNlAnfjeP6h6to0ePGRSCyjj2xCoizH9deR/R5/9ZQz/rPGzmrHbSEX7SMxrcZJBHhL3tIflMUWAa6aYJSPSIvmh1XUcvySwdnX5KfJDN1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199021)(6916009)(38100700002)(66476007)(4326008)(66946007)(66556008)(2616005)(6666004)(186003)(6486002)(36756003)(107886003)(54906003)(86362001)(478600001)(6506007)(26005)(6512007)(8676002)(8936002)(30864003)(5660300002)(7416002)(41300700001)(2906002)(316002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mrr1SiygMY2vt/UOIsxRcBFdR90+NVPUAg/j5rr1OowH6UEcbFFXNY3bxTGN/tmguhMGl9/VleAwJbT+jZdOYDcQ2VbjaabfHUcUP3ZXtmMRZMhNBaVxaQOWtP+9VlisOe46pHRKCRnyKFV8EejSMzrbMJXZ8FeHDKQj9rsOeB6499OaelVXOEoiFttAxKQotnKvlgdHfkDisP4Ff/J2uvtIDBwpAHf7qZuqQcQYRiXZ63lI5/bp52iN6fqRRkzQm9qF3pYrs94Os0CdHi5SKIr+2CrGPZATAjFb0Br7S1CqTlf6Kwn5xz2Hz8Dqph5N+HUcWzhVVpSCEeWwUMpJ9ameX7jhQ15lJt/VaDODB0ksmtuKi2j21bxmNLqErtp2CI2jU2J+oPFVc8DTKFHZua3mjFHrjHWd1Z6LeD9tisExGUi0mOCpUXpmbj5z2AALpCsEFuy3CHIupkHqAJ+1J1BZc0QgM8vpE3H2RDMwAhEasJ4IC3vsYwF/AVTZLnbMVQdqZn8y6WrlpsRWoYXTsgAHSZUbWwINBDHfaDh9PqJZ37LQ2XMAt4cd8Y4V24uf3dDycPfctRyCbDLwUkCaC8lPt+cJclu8CNCL3lxlsueNr4RNuGPFpmmadz3iY0iBiQVjte5ubdyKpM535wJEWLfAMuG4nnvjm5FimQPHsJSqID9bAn9tzhI82YliYfIUTeg9sypGW5GrPJu8mGWunIxASxY7QCXg2siMdnoarYKWtlUkKYBxrtuW0avqqQVu5VJ0yfAfyHVgrARU4nDYf30lNr0x9XRBOzJfJhe7ViA99a2AfZBKV7UImob36P59auh6drqYRSCrwE5ILQGxlu7ExVss8ewxaTomX7Y7SsqslRIgthxzmsLOHcesynPTQ2jDJ9xjUeyF9zF0EDpTYCONlc7hLglT65tRgGcrLFysgkOq0dvIbCC2j1vyReiO/MtbB5oSXtxbQIXtGO3q0Shr7ikoOOzQXnB3g7mcYYpWd49P9LRQE0Mubrr3nkD+xlgRZwEZclB6qXLFYXFIHVRtcOwsBc16/2v6oMYBNRTuGUCSj0p/sDtM/eiYkOvmSf4QqNkZrrnAOWWqlsMX1qgx32+cXRuFtgID6uMCT5fsW9u8yijpVGf7H7AH6P+r7ywRFzxQkbCmkOk9gqexJpy2WWnwAU83Di99/xL98duaJ1uwzeDqAKFEdj57bBUlIUelovGxf7lTNxQTGS0IeHhOnwrGhC2kt4ZuoCa5YxM4KkhF8hZHhPfQ7dKAIPGt7GeOrjBP5H9XwtwPVuMOeMxyFJ2KfN3qlmB8Si3UZca0QKsYFzmgMg7589EKeqOBfAH9BQgxgFFU/T1ClrPKHdbooLkko4TMBtNwT7xP2ibJwAG5e4kV7E4DxwaPm9bcTfVCmPhPT6YhlCIqxDX90wQJehwVW4x31HjwjTBfz49SXdzS7ZyHF5N0n0kS3tuIBxWOLncNnleMqq0bF2HDJ6ac47kV+Kywkl3q+pfbWxBjk5oQimVDmCkMucIGzlmgGoUTeGxriWFjAKn3FtXnQ+m+I6kAEyZsrbLSPe/GWYpQ+afiXyMddoQFZpZHxqbP X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a822612-f60a-4800-8587-08db7eb9d599 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2023 07:14:42.3415 (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: er254UfUPsDPYjTKotUeXDg4Y9DK9L1y8WC5zgPwutkI4Cd9LenBmrSmNlVhyybi4LkwGreSYfbatZ2qzYh2rA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7075 X-Rspamd-Queue-Id: 67AE640009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zyan1h3c68pomh39rh7bd9qjbk4545b6 X-HE-Tag: 1688714085-33087 X-HE-Meta: U2FsdGVkX1+k9RV0Y43g4ADbYlC60EFIaSe9LdLQy7XmAdWX6+OeJ9aoN9lX5WGjFsoFK0i5YrY7mhUak427Fdea0dcK2M2IEjvk4DS1d6lGRXl754eZvW1wCLTXL+GUlK4XscYfXBcaEV3UZOFg/dWUFSoemQ/E8stZfcL3CbSnVw1J1rF6wyh+VNq1983gzv+KX0ThgARpoY8yD5E1EKKqRH1moIG7jtxWskjWyYygomQhlVZphu2yCOQ+du/9Yp0VLpt/KpB5fXjLyiVJI5CSShvp8aQSi/yBhbosg+8U8cpKjZDb6fNFnPZzpP2CHWDSQ7a71+zVM538tHUQR+Lzdmhh9qqRd4mgJwN53jFbxMR1p3C1QF8+bMjXxaug6Wt7cZ8LOtNWlX50/Z4eKI+XhDssbDzH0YJQbiNignNF/hd391cxgkW13y5jBDsL40PHnuby3Gt9f7aLu2+xeUfGAzW+o2HBxl5rXFDDKYYLDiPYCy4nGm38m6veqrsHKvPVKIHyZRmzXgokV1mphrN+jKFF192xprChE/02BI5EsZ+arVYP78A8iWDKih1tS3iPKMuzmVM3+WMTWQB+FMgYqKu/yWLk1P9qRgqI75up06ZgAe/EisjgZNsN4wgYpClVcY5EGHPjKVb5rC0rpqU9uLJZoj46YbLmK6ntiCRJJBcbQDxd+hk8FyQr37H25hVYhjgqDC/KLE0tYdHjvvFj85V/IOdHPX1SpWquMSwDgDuEjmH8t9XGmhiQUKMaX1N6/lnXOz/qMaGrqlD8BmtDN6HcFDKOBRSzJSGvMKQhVg4W99BooVyNkdqsJGeoeXJFDbrUNDeGBAepMHoCfV54Ubn7/XHx7WTpTAofZG5DhWo/KUfCTNRxClq3ZA55RJ0bwOerUyhxRkv/lg8Eo2Uz3ImoTh5SxRvoDNOHh8eCIqx1vBw+bwtfXwWKmHecw4A0xaf+3dUdBjKMjBo +q5jFdOX oCB2KdhuKBM3tF3y8PqHW9b0lFJZTPPkAXOJ5un2nZwODqaBQjFeTIqUa2JaZvHmva9GHY0oTLWol6VNsOqOQpkCggYCe4eMkEWYcghKdxQNeAd4OCnRvDk3LQxHNiiITwaxGYZ6+i75Bva+73eD8cEAOy/KXbSedhG2lQGxip1oil3WbewY3z94SOp13atIrlhw+17P6ELF0E/CbE85Nu2DCiTyK36YS3l7riACLnTDDyU28MuAQBImOYb2HT+Xnlojb8G7R2TN6YwYvDDn40zavm+fcwDB+qWorIn1ZmHmvmV17l64XS5wT2c2yo+OuXBFit1HeaDVh3M5LrXZSy6h1DA== 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 bce28cc..ba689e0 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 */ @@ -7462,7 +7464,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 Fri Jul 7 07:14:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13304490 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 AE0B4EB64D9 for ; Fri, 7 Jul 2023 07:14:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 479678D0005; Fri, 7 Jul 2023 03:14:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 400798D0001; Fri, 7 Jul 2023 03:14:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 254498D0005; Fri, 7 Jul 2023 03:14:56 -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 1191A8D0001 for ; Fri, 7 Jul 2023 03:14:56 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B6D8E1406D8 for ; Fri, 7 Jul 2023 07:14:55 +0000 (UTC) X-FDA: 80983953750.11.75D08B4 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) by imf03.hostedemail.com (Postfix) with ESMTP id ECD9820012 for ; Fri, 7 Jul 2023 07:14:51 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="d1s/gYJS"; spf=pass (imf03.hostedemail.com: domain of apopple@nvidia.com designates 40.107.237.53 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688714092; 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=Ie/6dGZIaxWVb38tF3O7WHptuZ4OzJ/YX3NdirM7l9E=; b=2lXnfaO/xg9gYYiwLO8wNyd8v1GcW/8/xIBubQwd9D9rSfI7kkjQuhYYGmNKQgVnRIGQDp jb4xbCRjpnTJIc6IAjDorVfrfwWMrYDjrDJ+lbLxpG4WNQ1vlb/ooANSr6Nn5In5z9+hNJ ifBbJCAbCR+KlLdn3E2bOH8NhL8Ddw8= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="d1s/gYJS"; spf=pass (imf03.hostedemail.com: domain of apopple@nvidia.com designates 40.107.237.53 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1688714092; a=rsa-sha256; cv=pass; b=LYruasu9VCb40nkGM9jlzOPF7A7Pm0dHdeLPaRvyZLZImoF1HFVPB7C42XVpAQF/6Kxxvd K9FAuOTDkHvV1yWM8Bt31vpYQSlAOaIoSB/pIjczHBMroWi/nA2wwrd6NTX0p4ADeWuG/B /7sqOTU6+citZEDRF1fWnAsw1zM+NPk= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TjVJfC3vLnaLuuL6R7s3+n1WfwUfQhaMYUvSGQn2Kvm6N6lDfLKYAgauDDlNuxN+mVJTbF6sdLE3SpXkI1Jm0nZrQQnigY+xK8RV6sZAlkNQSugFFWlcf4lbn28+EJDmHphyzG89plQt92mZuSL+fViqoAA53fn4q3Tcm1U91/ZsGAQNMCDbvx3+HBcK0a72eLbVq8+4supQeUYVbNr4Jpy+T6b591c8n/ly14Y68bQlXlY9ETGY/ZJ2zStk1bLIO1eSvHBww7C9VoXkDqEdUTTVt4Mk04Pm2X7RcxsBKZTgrAg3mhZ6kf9Q4UIyOtt4nwKCX55Hd/9LHkchCmA+qg== 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=Ie/6dGZIaxWVb38tF3O7WHptuZ4OzJ/YX3NdirM7l9E=; b=dmk+qekaXsaa6+qht/4nC94uTE/0sYeouX8fZPZ7VdK4zYVnLp4Q59UboBu/cbbzzD+ZX0TqDRq/fDlGyyBwrD9Eu+jly3ZyBhWRfcXDSepvgfKG5mqpzj9cQWJyGLs7zWV9nVhLj3/LM9hYCLCP8ydvXZ7FGQ0ky5svAmVryMycTFgXY5qSqZQbqScS3SOtpe70Jc3qOCaZcEgDrlhX9ZDF6t2V8gzaM+qc+z/a0ZCUENtyE0DK0AHuo45tGyAGa3CqK4YfNU2eKRfVyowG+u9C1xod8sUfV1sCLbzET02/9eKeQSCeUKrVyy+Ykueb1ELN6zVNIpdbOSwLOHfYmA== 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=Ie/6dGZIaxWVb38tF3O7WHptuZ4OzJ/YX3NdirM7l9E=; b=d1s/gYJS+Ou0HEElwhXKMmoIA0n1QI2tpwYLI5/kJmOv3mzY2JakqIqdcmS8OBIjQ31jUJa9O4ZSb3gJ4w8aO17zhc+AinVzoi/CfNL8J3j5VM/vOOlauveHg6fJFMFErsY1cNarolP1zoNw7Kvx+vS4A1AoYxm+G4530F5m7q1DU/RwTae+cQNPGl6qsSq6JEIip9dOOgHN5nyFTXHpPdAea2Z9wXPyQkKhhn5U9taDdXN2QkjYeeXvYitxd+o7wyOCBGSjEQAG1Bp5O9tfIoFOtthca9KwINemav3Qvm/T8nKij1VZGbck9D66OxyXy+tOqUhmkEaxRV5jFArdUA== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by SA0PR12MB7075.namprd12.prod.outlook.com (2603:10b6:806:2d5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Fri, 7 Jul 2023 07:14:49 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7%6]) with mapi id 15.20.6565.025; Fri, 7 Jul 2023 07:14:49 +0000 From: Alistair Popple To: akpm@linux-foundation.org Cc: jgg@ziepe.ca, npiggin@gmail.com, catalin.marinas@arm.com, jhubbard@nvidia.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nicolinc@nvidia.com, robin.murphy@arm.com, seanjc@google.com, will@kernel.org, zhi.wang.linux@gmail.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, rtummala@nvidia.com, kevin.tian@intel.com, iommu@lists.linux.dev, x86@kernel.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, Alistair Popple Subject: [RFC PATCH v2 2/3] mmu_notifiers: Call arch_invalidate_secondary_tlbs() when invalidating TLBs Date: Fri, 7 Jul 2023 17:14:24 +1000 Message-Id: <6a230ed312333f7937ecbf6bfe7c19b6e9e96792.1688714027.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY2PR01CA0045.ausprd01.prod.outlook.com (2603:10c6:1:15::33) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|SA0PR12MB7075:EE_ X-MS-Office365-Filtering-Correlation-Id: 5236dc85-ea6c-40a7-6750-08db7eb9d9be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vf0SBT6q4TOTrwR+/UxF6zMHA5rw/HKY9wrxRC9WhMdFDsbk34Bub9CTwgcGdHyC/1lXiHX0gXSZCXEnyLZtEmmAWNTrhdrZJYAk++vZv+nPzv4TRGl3OksXU5cepvMjPm/om8gt03RZVCdJ2X5E7oT5u7smoN1SgmE+pc0SVjO7N7itRjlqHhH2a4V6aBlVOu2JUBGXj8JS3xdPDtaRAUkbqDaj7qCYkgb/8iqeLfucYd/opjlSBltm8Zx18mHgwuzk0MB2vMxJF9y9WLSQu4+v8oVuPdabSORuivRS0GSb9/M5cC7rv9JR/7PbJJ+NapxYLHdFtM2DmCsIHcHYHbzWdgoxlexCdmuKtdprfdolLe/8FxnhT/yCZxYluAennILLwKtKX399SsszO/8rfZQ6DwmQsR0Hv+Pqk0wa8y2gJolzNb1VUpz0GqpsOUsWtPZpAZRMSuotHdnzeAn17ZAnnm3IqCCxU3PqdR00UPTNilu4mHJSouMTksqYr3sdZEqS3p1BZSgbNWZ7iZy25wkh6dSodS4yghLUPOF1eZ5H3/s8cIYcu9npcQg8iScKU+Df72NH037v3fm9CBKjBPTo1WVqKiRaUhH9q9xsMXo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199021)(6916009)(38100700002)(66476007)(4326008)(66946007)(66556008)(2616005)(6666004)(186003)(6486002)(36756003)(107886003)(86362001)(478600001)(6506007)(26005)(6512007)(8676002)(8936002)(5660300002)(7416002)(41300700001)(2906002)(316002)(83380400001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tf3CVIlA1nOARJ7gZIaJEFfcJonxLGQNatSVgkqyZqIPMuRMIY6WMv9XOry5QE1i+s3v5I5QoSt4sZ6Vqr4mACeWqsTtDStvpX+H38AwVc/2XE+NNcGy4XRtjPhR1e3bFQ6AofXoSeHcdo9c5mZYcSOxA5NU0RQw5cSU/R7DqKEH/NEEcsGp3U+A61WAXBEsMt5wGbsCfJXH1aDoWAjJYbBOc2NAfyj3cnGbEp4wuyweRA10yaE49/Re/ZNE5Fl4edK+DyRDoo71/fv56ktrN/zmbpMMJvoSkWgjPLMIckovhTzc8/hNIPkysr4oHuQGugKnt98w7uKGoFUqOMVIZY/CMMyu9T73XVjp0/m/sOc+UsYGzmrwMG3gdKg2f/cnisZJQ9OW9h3DIpg05t+qZElGNWWbuGPDWOV/m59/BRHEvO1m796zJRiLVeLfVVXkIvSc3z3e4aI9O6dmsCrZsKpDPfVyOYXCfQvONWjO9KkoFSdFbMNYBv627L2YG9ODJ4NWcud00KUV7Ao9rOXLS2ELROVNSOD86kuWwCohYjWlzCQ9cSMi69aash8mU2Z1ilaAlmsdlthoA3wif+1K87AQXA4B00FxqiFTjyTtyTmaFW/fWNs6lHu6V+k7IAveOZnhE60jCJ6/8TFdsys7kCJrvXCq0crlS2nwSecH2U7IFysWFrCOC+tPZr9IeWHjAn9UojCdDYxGlFL7ApSr0pS/7q0aWx2k9Gd9QfB5A6OrJW0+QPYXfro4muqlsTx1TGbx+FaMPWtW+xubI+g5eNHuUXrdz/Bojs8LivI/2+UoQYiqzuY5a2svGJ5/T8G71mYjGxXr+aYIeQ3XncA1P0bfNzi5ecYgyZ3cTetw0SZtrjACGPzJMj4ai8VPBVY9AjgNEXat9ByavtK+N1/jEg3a82v0zVlBLjvKdI+EaZVZ3D68PDh2wWcWpuUi0scI3JHy+SjwLNR/vGdKsVvPest9p/1Mo0LdEavVvJgmQS+qk2uh9zngEV2jUnsjJ/AkL2tkoQUhragLQNPbGlX1WHtCrWmpCU96OmlOvD3h5vwHdfa5GrcXiov4zkXxLzsa2lH42MwBgzhszNNE+dnRyxCKC9jyTvBhsYDphmKPEqanfHxjbPBY1TKgodtlX/V1Cpq8CWj3f/eB0HZXRDDtmSAW/5RmEWjVGgV80pVAMhHMlPm1F8pv4J5NHENPVH0DeZe9Vcw5HRcppZ0nyH2nJYCvT4RfE4IbaLtPYlFQBB1dpqBIYMaGkl5DAOWreSqZaIZNW8ze3fPmtqsz6T17PvSQkgpDR3XyXlFpVRzP7SJBlyPBSARjFUr4F2amSmtnJTBKgblVCEYGgDiqone8ZxtM0eVfDI5M+B9yCTZ4586m9Vv44hJLA5gxUr7VP9XPgZm6Or7rbLRINQi6vORnYCv+cAm8g9blt6c2XEuWXC5X74rP4NFTjI0Di9Wyf3vru87uPb1Kxp+2bJH8EG9yqB9hygWa+r93qVFSxzxS0trKZiXwSundX+26MlcdY4lBRtvaS0OfUmns8KCsAE0PZ6wGUfmcFunOtq26MHggXLppTzBddUJvfFPq9nLh5M4R X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5236dc85-ea6c-40a7-6750-08db7eb9d9be X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2023 07:14:49.3254 (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: iwYKiiEoDwVhh7ccVOBtfqwwU05oPpe/LTokLMr+LJbziaJt2Xn4pS/89IT137gQTzV9KaHE6fH56AcGYwNc/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7075 X-Rspamd-Queue-Id: ECD9820012 X-Rspam-User: X-Stat-Signature: d4me5b4heehrbfxiqbsa9riha5ykh66u X-Rspamd-Server: rspam01 X-HE-Tag: 1688714091-866722 X-HE-Meta: U2FsdGVkX195+8wJ1DLMbTCbij+Djxspg7Kv+PrT8W/1tC1wvpeAC/HgSOdrE5MgdFQ1JEN8t8Fv/3D3L8hnbqoiPQmPtTuPTtZbjB98+tsuPNnNf/AX7xOvIinC5/DhRCrWOBDZ/YzJ0FjtKgV0FmD1gg+NbX14LpYrFiy4Np/bJCVPHd5c4+ju0vbti1OUY/+O6Vw2zG4k19F9UovIoPCH+ysb4MRGAwGg12u8ZHcSWO22jzEVNm/GJIbm8B5KHJ+jUdtpC1w525Bcqq/ttJyKc/Ut3CE/lsRay76cC9x+dLXKYap8JZKXY+p+pFhU3Q0yIUY5jGs/AqODaLTbk5SwqtYGV9vKDx9HCJ6EqwL3yn4TiTbTr1hN1wuPzMnqQ5uMCnFlbjqDuKrfSE1NVrqtoUumSDKWlxcE/PsGPAj2988vU5Uys1JOPCDtGe/hO6/IhifKb5o1EP0uYz7ICQwBrlI3AdQNbHyKC0DhBqwxi/Zejq1zq8fVhcefEmbxBnvfqORy9/FBV+EKmx6rzRJaZSjzNuTIksBfIkKp73M1Tnf+PjagQ0aCg0U2Z006LBkteGIDyWj28DlJM9d2S/sfLUgP9PpL6l0wgcH8d+eZKHlNMmcRbiGkxDL47j44dS0YAFy2TGfjTzMOw7LWfUfE69Lna6+W3bshPEtH4gFvd3teIiDLOj0kyq75DQarXZhUG7brkoHBOPcfuJvHX0GSVfcA56E3BQH6kqIwwwlvBWdI+PeNkxNsrmpaSC6xjkrwJAih5e6eGaCoYpexnm9+8Reqv5F2bSTMqQtmS1Y9pXwDkrZ3QByMtGY8Xgrp4rPFGll3qY2vKFBnzALX0q23vymYiqGaT7JokldYxMMixdSciHMJ32wEyB58CDdvol+A3WWcMe5CJmBXOtilK6TM69oxQiDT5XaYbXUMRBBprgI78ur42pwh4uhKkjm8HoMOjoLuYs1sd/48K0m 1Tg8xmQg WisLDTN8Nd5J9VRZ6o+tv9ACwMCZ+WrTemUGXOjBEgioFP1DPS+Fsav/zpYl/vwKOaXqOupZNe0QFFoggqYOW6B0uaqrWHrPzagx2JVc89VeB8ut1DtwBFO0KTJgjm91AKm2I3OqUdBfR6kT/JyD1ge2MANSIc5JizFZK3wOmMslw7Vk+oErFTmbemwgAMqEuZOtRAYrMbTyVHbBc7iKUOPIiS5ObpO49fbCr1SPYZ1XrNtnNx89g7rDYCN+m5F6FcD1BT/Db3+aotEkb2d8CHf6FBVqMtQ8cmQGvkwRlU+SnhyL7oNR+BJG92IDtywBImrIfY6RVgiRMWyfL+5palaEdoC/kv7r1JJxd4d+C3eepD1j93SMUFFxLZKYW+0NpX+ypgD85/QHuVCHWFFp8f61rbQ== 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 a architecture specific mmu notifier use 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 is 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 as required. For now the notifier is not called from flush_tlb_all() as it is only used to invalidate kernel mappings and the notifier callback requires a non-NULL mm_struct. Therefore these invalidations are already not happening and it is assumed they are not required because IOMMUs are only attached to userspace memory maps. Signed-off-by: Alistair Popple Suggested-by: Jason Gunthorpe --- As this is an RFC I haven't yet fixed the last assumption for flush_tlb_all() because it's a bit more involved. If this solution to the ARM bug is acceptable I can investigate fixing it if required, please comment. Evidentally I have also missed some call sites that require an invalidation call as some existing testing that relies on correct notifier behaviour fails with this change applied. Obviously I will clean that up when posting the non-RFC version if we go with this approach of moving the notifier call sites. --- 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 Fri Jul 7 07:14:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13304491 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 53722C001B0 for ; Fri, 7 Jul 2023 07:15:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E14508D0006; Fri, 7 Jul 2023 03:15:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9DB88D0001; Fri, 7 Jul 2023 03:15:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF1C08D0006; Fri, 7 Jul 2023 03:15:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AB1688D0001 for ; Fri, 7 Jul 2023 03:15:04 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7C93080CFB for ; Fri, 7 Jul 2023 07:15:04 +0000 (UTC) X-FDA: 80983954128.07.F1DB248 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2082.outbound.protection.outlook.com [40.107.223.82]) by imf11.hostedemail.com (Postfix) with ESMTP id 911C240003 for ; Fri, 7 Jul 2023 07:15:01 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ulKP5n0f; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf11.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.82 as permitted sender) smtp.mailfrom=apopple@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=1688714101; 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=7Sgw6A8l9bBmw2H/FjPUicVghu7vSsXL6mgL4AvDIH0=; b=CF7uToIA9j8T5jRqmj7GyXXduRcj5IVxyeBXITS2Y7KaijFcfJXtaDxPi3cMNKcHLPupnJ kIK8jOgJpvpaoOBJbciwasKmtBEo/1QKRarsrWTmASVWqKnaMGWUjJ+Q0UQmS47lSoSNUD u7a1praSkcSlstFCvtVg21Vz2YN7Dus= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ulKP5n0f; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf11.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.82 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1688714101; a=rsa-sha256; cv=pass; b=kjgZYM4dRamQ2tq2Iynsp5QrLO9OvzPsu3TgJEOGKre+WHpzhSBYNjJBW/xaGFLUkuUVlU crsRSlAwVb2j1nxwMc+cZvpe7wtP4vxIPyUEXOVHPeLkdhppBYHKOtmV1EzKAYHwF8NMr5 gtmlAIfU/mpwusANhskQ6D6LeXd0uXU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/K54ONH+C4hy2b9tyT5x8YP/nknwhSILRIKBUVWc7tjZP38igZLOCvcdzuA16S00RzgWDu0CvMsK9FT68oeorFr10OFE7CVG5xBYuhq3sAIz0Td7atsxT8vX5os2pvMBK8mWR2ZKo32YFjoMdUnbKwhRXdCJdBRjCedSpevKyaROk5RXzFoB2rm8FU4onBKdm6aXT6nORFh0DGRI/1ROupzM/kKJeYIaU8XRk8FXqaCmB/xjO+hu1BQ/wnk+BQxBLHZvwCuZbBGhrKX9SbM1FI2KTBuMdJPo2mBl0KanGbkQ1j7Ih4HVwalk39e0r2hK4LfpMGEYfaeM8ZRLtas+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7Sgw6A8l9bBmw2H/FjPUicVghu7vSsXL6mgL4AvDIH0=; b=iIL2Vowy7tkzD4rPql+xCYaRYkJhJkxT4qmJEJMqTu67he2JpgmSQ7qsnOi3UOytmFXI/fzQQpUaNljKwf3dS3NWQmGOC56IXFBFHmT+dw4OSRDoB69ru+rnzFA0hGj/Whbf4BzS2N/24N5WcMIMsgOhgMOOi16Cus2MeTX2nZrokJ90G0ROVG6aFWjKbWBYkal86avRFi0YN5FmJ2XI9hibMhVNO2VkPqCOVj1dZ5dXzQpabGqyqLir7hHj3cHFotdRd2wv5PCBd5fh356+S+BxcoOrFQ97LHA8aplsH5KExa9wIAAfxyKqRXuqk/z2adA6SM9yCchTQbFcC48QyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7Sgw6A8l9bBmw2H/FjPUicVghu7vSsXL6mgL4AvDIH0=; b=ulKP5n0f73JQwqjIYiFpM4yXa0b9aBa/Wizqb2bPna9LCMi2H+iDHaXGH5iwevEBKhwAuVuiBgCqG/bVANveMr8Gy3VTw8p18mWxWZO2AvEc1WD/J5L7iRzNFShJe+ASLvSw4ny5Ig26Oka1BX6Ahx27PZRlKowgpN2jwNiuZbvTr/KN0SZUwlVWN3htpN/KGDN1amsfDa2QX+PMgO3SqIFjSyjc35MsSUflAiO1BPeUH2GQYx51nhhc1VdChn7UiuvXMCi2gnyfmK+qWBUSR5pT3S7oeR/Pv+ZUcQ0WrMdsxSaGJQkCIdmI1SHux1cGua8PKCnz/cUiTm5Ud6jEug== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by SA0PR12MB7075.namprd12.prod.outlook.com (2603:10b6:806:2d5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Fri, 7 Jul 2023 07:14:59 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::6cea:921f:eb00:c1e7%6]) with mapi id 15.20.6565.025; Fri, 7 Jul 2023 07:14:59 +0000 From: Alistair Popple To: akpm@linux-foundation.org Cc: jgg@ziepe.ca, npiggin@gmail.com, catalin.marinas@arm.com, jhubbard@nvidia.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nicolinc@nvidia.com, robin.murphy@arm.com, seanjc@google.com, will@kernel.org, zhi.wang.linux@gmail.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, rtummala@nvidia.com, kevin.tian@intel.com, iommu@lists.linux.dev, x86@kernel.org, fbarrat@linux.ibm.com, ajd@linux.ibm.com, Alistair Popple Subject: [RFC PATCH v2 3/3] mmu_notifiers: Don't invalidate secondary TLBs as part of mmu_notifier_invalidate_range_end() Date: Fri, 7 Jul 2023 17:14:25 +1000 Message-Id: <1fd481392ca173c301de3edef4dcc79dea0619c2.1688714027.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0097.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:204::7) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|SA0PR12MB7075:EE_ X-MS-Office365-Filtering-Correlation-Id: 300ca14e-eff8-4e54-8aa7-08db7eb9dfd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KToJcQD8Z5SdXKKM0fLqXJ519Q1H3jjjdnLVpwGUiqHz3JsNsw1RITRwI2bmjHZxcg8QfH1ar9/tYrKKnP771IsEC69PM9TaNI8OmRSPGH9zdAQcEf2pHV/Gd3ueQAgQ8fcU2LV/yYTbIh5G+fV71/OoU+zPVSGwLphHOh3VnRUTaBADM87dyRjIFm78e+861K6/rKSOOQk+UjWbLc+T1njQyD915aZpSe/5be3a5i0pxiTaWrb0iXtVhpYlgsuzFBFOGSGXpQt6E54ARctabPTj1Uw/8+dkTdJfB176r2qGWBzlnohdkpqHaRkgH7IBYsIPjbCdsAZDSNhdgMalTR8xVz+CZXsbt5f/rVV72N0lSPqDvFjoAOrfIS3h837VIVUovukuc1tGUj5PC0TEeKOAfQKiBcm6yEZ+GwBGwEXQ3ozkxB3sP4PMafBXTzONeienjbj4JBN8sHP5PTNd5Er+LBKIwBmbtdKq4h8oQTWufZgaNe8Fd7Mf8TNVG1IamJvE54stkl5y8V/G7xMfYaUdgBz1nvA3jG9iJwrypUc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199021)(6916009)(38100700002)(66476007)(4326008)(66946007)(66556008)(2616005)(6666004)(186003)(6486002)(36756003)(107886003)(86362001)(478600001)(6506007)(26005)(6512007)(8676002)(8936002)(30864003)(5660300002)(7416002)(41300700001)(2906002)(316002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XELrW64RTgdJphHb1XHlIvFI2BM3JhssINlE7O4aAxU4XJt3DAYxf1AtCR5oYhfX+xiMCOlTRfMACFybgznROB9x7AYPAChGiVapFEmlpLa1Fx1oZvpptLZP5xvmhbtwe6P7bODhkFYTGiQE73ggpFeenChnGxwN7+oOSpwBug7oL2dCwwzxGqFatTY8tqVkCwyd2PeVAEE7IwUmIxIiRG8snTsx73pupm6YTRX7BTGTdaebiq8Tedv7yx4tXQA7q3mhGf61qriZ/PX6deJ07yaa0i3qTUQI2flPBdLtfY1QReh3v3HvuhEefImK/O5ji5/siOQaMy346ZigFNDtcIaeLs/29rVrohRwijUccF6ORB5ZrTJpXyEkO/1Y3kRPS+e7l/sA2wA+RqW4lfSLKJGJpFw/vhgjp+sKaTzKscr85moJeqypIRal5ax5STd0h/pwx3P0O8uCIU7NfljeWtvzaLhuO/hnXzs5b6lUmEwyQFanlMwsJnLBH68tRnSqSEnE9Mmsfpg1qNEeS8RjFOxthA2hsPNJ7ci4urw6G2R5ZMW26q/50TqNBeFL0H1Hr8yfCDz7H12yOufIKvdmJMriUsj66SAdAK52oY5zH3Ozsw63kEL4LVntfLLxtQ7sIp0HgNJIvv93nuSjD/soManay4KaOXZeSt/Oq5u0XfdseAYQEV8pxC6vhWedTxuAV/OODhsZsgB0xOoNhM4iz8yoD3Ic2tn8Mj8fGMw8JVE1W2Zzc41fjzwF0JQVbzamwgisZtr0CtAZwALOhi8yPotJFXiadNrgoYx5VtHQnCj436vyGwwANqdhcjNU717js6k17roQSfxG20pL/RRQjJnMnVnp/uZtXDrQUIPgqtYxbqYFqCiGoYKO4OMcHx+cFA4WKkPzknuOT32SCVSliJpJUbVH0aSSZxo40HIuNF9pcvvixaYIOIGuRZ5ETCAzsE79njfBORsTwRflybjKr+/LwK/DCaVMxTLhHz/zp1QpODtU1X9BwFh0TuDvMeQKDCEgptkdXv0mVm3jH3+BxpeXrgeVWEkXesopsJ+O9GFTs8VD8NNzkO6KEq6atAl1Fe5ElnNI+PRlwvpYkwhqJqBQCoks99xvEghJupVU13tU+K/x9LOXcrt7dVEEKjuY6GYqmP4K/OMdArQrwHwagzbET3Cefz9Co4hKdKOl7i4UrTD1lrD051wpoTboP84XldfdJuGrLSZEsTh2xHUbYtsnphUodUbKDPE2vU/CYQwsKSgc51DI1qFO1suSDrD48VFmX1tyKEBFtwfW41/8L0+eoN9qfxBQ6+NOwEUpjvQMqYHylXTsInt7s0u/tN5BgdAzaxfAHYM1PvYFOzHaDcWwUz0PuOCyUBDU7YtuKlrjgTZLH8N9JLBZRdY6f30EiCQ28EWzrKd9onw4xoV1NHix+d4kKlbm39joQjaq0d6vDvxtP985MjATtqPXLlynQKPPFWADTmHfXGiIh/l3WiFX7z/zg2jrd8J5GVLFXcHT7eX+vfTialp4IhqfpRuNVOm4aGBIgErOnl3p8k2XfOYKvncx5AW4aJpldFdDGw0EjaQWy/lOOPhWhJi0QGyp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 300ca14e-eff8-4e54-8aa7-08db7eb9dfd5 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2023 07:14:59.3764 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U4P1vmAhyAikg3BR91McV+g1IeyjogpyRaScLwWIcof05Gu6t0c8r5hGiT/zPoCX0OW0IQmBdMjnyGFalBRBRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7075 X-Rspamd-Queue-Id: 911C240003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: cpte5smjwao8fr96y6rqwpoz4z1ma1u7 X-HE-Tag: 1688714101-841646 X-HE-Meta: U2FsdGVkX1+aKrEMrasH/cdscfc2e+dXn0uWezvF6SmQ0/Edz4aPRqKCEGQH9IbsW5DMsEVXQXeZvatjVYc8DCIs7Zg+9pYEHwG2jttfiWmU3GO+vW/JcY4UAasObp/6HbD270NW4jlwODErryeqjJTgLXTUkkPK3miN0valEs/pJJOt1YlLcn+46RvZiRSl9rdLp9UMRrrI6mSfSBcSH9lN6Yw5Yh0D7I5/JrHZ0+9OG1NjjryUusZtFAH2GHkTxDEuB0ZwDu6dyPsQrihMUX5SG3RwpFYd9xlAErVV4VcSzagKf1jZ27bIjqeeQeRh0jRt0yhwrQw1t0Etovv1FMQtqXZJeQRR9fGRf9R7iySKOyB1VOkRcZR7JzOVpQwjuE5AvXFdpaM/uq2LTjbGv/IPFDV0wjigxN8CsvIOV2alvYasv0AswPn2BlsJfzTOrPyCIXewYG8yr6ZCxMTnaQQzzEaICw1bZWWbW8wbqVaxHdEqt+QdcSr1bnvatD/sLjLsD17RnTHYVHcVWzJhI4XzeS9vfsxcVtiAxgt6RAvGrTdL/HrDDYOvznP2RcPdAv9ON5FBCBMBZfEZ/mPXaHxm27c7d3eG23fJ8hCErSUtG0LaxohSw2TCk70yz4VzsPo5Fltwx0+7HXCQn3PA1suN9/s6qregDNB9it+56XfhCkVyCIHZvE5RLjn1nvbh43JrsDY6SzDi4ZI147meJUBw3L1slnxYy1o2AWiXyhGBoongz2hmtqAhYjaGv1GnxQIb7xQk5kKqwS6KQdukUKdLa8OxyZkeaAjvgcstKjze7VEGawx5MHaHrVx4P/AG5k85EayFOogUEtM/f4ht7VxadBjCgpoxbjOifPSR1fFDG7MXPrnmWmLp2L/FkJGFMGkolP7DkoncmESBMa+4SyLUeCwCuR+Sm2aL5sL/H8PP7MhELzDGBY2+d5OYSl+6D80qZBeMUCJGcLzb4eJ o8P1Gr36 qxjaRCX7bFYpwUIIAi+egub+uPvny0FvLmLQM7abNJ05F0ctO81FlbCwUDQ7we6NoXYFdV8Ch8XnJnuxRLICgG5yi0TyWJldrRlxltApJXnp3uR05rmG3XgbUuyYdFBLiE9/+7EWPZwRVuI8ZLpM0ODMiIOK73+QLTnstqYE8EBKEPntyJ8/N1QEAt+j8Jx5p6Vv+vMGm4Zo3egO+B8mOSyK1csXcUqvs1u638VLcfStpsitJM2kk7Vlq4ue28vRqDjfsCwV3+mH/z6SiRPbopIOjq65sUhjzMD3CUT4TpRlwNQcaVYhRRH+9Ljf48p95OMQtkp4dSRUB4lIG9w1DZlUjow== 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 ba689e0..941a11c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5690,8 +5690,6 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, /* Break COW or unshare */ huge_ptep_clear_flush(vma, haddr, ptep); - mmu_notifier_arch_invalidate_secondary_tlbs(mm, range.start, - range.end); page_remove_rmap(&old_folio->page, vma, true); hugepage_add_new_anon_rmap(new_folio, vma, haddr); if (huge_pte_uffd_wp(pte)) diff --git a/mm/memory.c b/mm/memory.c index 0ae5947..5736367 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3149,7 +3149,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * that left a window where the new PTE could be loaded into * some TLBs while the old PTE remains in others. */ - ptep_clear_flush_notify(vma, vmf->address, vmf->pte); + ptep_clear_flush(vma, vmf->address, vmf->pte); folio_add_new_anon_rmap(new_folio, vma, vmf->address); folio_add_lru_vma(new_folio, vma); /* @@ -3195,11 +3195,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); } - /* - * No need to double call mmu_notifier->invalidate_range() callback as - * the above ptep_clear_flush_notify() did already call it. - */ - mmu_notifier_invalidate_range_only_end(&range); + mmu_notifier_invalidate_range_end(&range); if (new_folio) folio_put(new_folio); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 8365158..9ce8214 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -658,7 +658,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, if (flush) { flush_cache_page(vma, addr, pte_pfn(orig_pte)); - ptep_clear_flush_notify(vma, addr, ptep); + ptep_clear_flush(vma, addr, ptep); set_pte_at_notify(mm, addr, ptep, entry); update_mmu_cache(vma, addr, ptep); } else { @@ -754,13 +754,8 @@ static void __migrate_device_pages(unsigned long *src_pfns, src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; } - /* - * No need to double call mmu_notifier->invalidate_range() callback as - * the above ptep_clear_flush_notify() inside migrate_vma_insert_page() - * did already call it. - */ if (notified) - mmu_notifier_invalidate_range_only_end(&range); + mmu_notifier_invalidate_range_end(&range); } /** diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 34c5a84..42bcc0a 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -551,7 +551,7 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) static void mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, - struct mmu_notifier_range *range, bool only_end) + struct mmu_notifier_range *range) { struct mmu_notifier *subscription; int id; @@ -559,24 +559,6 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, id = srcu_read_lock(&srcu); hlist_for_each_entry_rcu(subscription, &subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { - /* - * Subsystems should register either invalidate_secondary_tlbs() - * or invalidate_range_start()/end() callbacks. - * - * We call invalidate_secondary_tlbs() here so that subsystems - * can use larger range based invalidations. In some cases - * though invalidate_secondary_tlbs() needs to be called while - * holding the page table lock. In that case call sites use - * mmu_notifier_invalidate_range_only_end() and we know it is - * safe to skip secondary TLB invalidation as it will have - * already been done. - */ - if (!only_end && subscription->ops->invalidate_secondary_tlbs) - subscription->ops->invalidate_secondary_tlbs( - subscription, - range->mm, - range->start, - range->end); if (subscription->ops->invalidate_range_end) { if (!mmu_notifier_range_blockable(range)) non_block_start(); @@ -589,8 +571,7 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions, srcu_read_unlock(&srcu, id); } -void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, - bool only_end) +void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range) { struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; @@ -600,7 +581,7 @@ void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range, mn_itree_inv_end(subscriptions); if (!hlist_empty(&subscriptions->list)) - mn_hlist_invalidate_end(subscriptions, range, only_end); + mn_hlist_invalidate_end(subscriptions, range); lock_map_release(&__mmu_notifier_invalidate_range_start_map); } diff --git a/mm/rmap.c b/mm/rmap.c index b74fc2c..1fbe83e 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -990,13 +990,6 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw) #endif } - /* - * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() as - * we are downgrading page table protection not changing it to - * point to a new page. - * - * See Documentation/mm/mmu_notifier.rst - */ if (ret) cleaned++; } @@ -1554,8 +1547,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, hugetlb_vma_unlock_write(vma); flush_tlb_range(vma, range.start, range.end); - mmu_notifier_arch_invalidate_secondary_tlbs( - mm, range.start, range.end); /* * The ref count of the PMD page was * dropped which is part of the way map @@ -1628,9 +1619,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, * copied pages. */ dec_mm_counter(mm, mm_counter(&folio->page)); - /* We have to invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, - address + PAGE_SIZE); } else if (folio_test_anon(folio)) { swp_entry_t entry = { .val = page_private(subpage) }; pte_t swp_pte; @@ -1642,10 +1630,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, folio_test_swapcache(folio))) { WARN_ON_ONCE(1); ret = false; - /* We have to invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, - address, - address + PAGE_SIZE); page_vma_mapped_walk_done(&pvmw); break; } @@ -1676,10 +1660,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ if (ref_count == 1 + map_count && !folio_test_dirty(folio)) { - /* Invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs( - mm, address, - address + PAGE_SIZE); dec_mm_counter(mm, MM_ANONPAGES); goto discard; } @@ -1734,9 +1714,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, if (pte_uffd_wp(pteval)) swp_pte = pte_swp_mkuffd_wp(swp_pte); set_pte_at(mm, address, pvmw.pte, swp_pte); - /* Invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, - address + PAGE_SIZE); } else { /* * This is a locked file-backed folio, @@ -1752,13 +1729,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, dec_mm_counter(mm, mm_counter_file(&folio->page)); } discard: - /* - * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() it - * has be done above for all cases requiring it to happen under - * page table lock before mmu_notifier_invalidate_range_end() - * - * See Documentation/mm/mmu_notifier.rst - */ page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); @@ -1937,8 +1907,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, hugetlb_vma_unlock_write(vma); flush_tlb_range(vma, range.start, range.end); - mmu_notifier_arch_invalidate_secondary_tlbs( - mm, range.start, range.end); /* * The ref count of the PMD page was @@ -2043,9 +2011,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, * copied pages. */ dec_mm_counter(mm, mm_counter(&folio->page)); - /* We have to invalidate as we cleared the pte */ - mmu_notifier_arch_invalidate_secondary_tlbs(mm, address, - address + PAGE_SIZE); } else { swp_entry_t entry; pte_t swp_pte; @@ -2109,13 +2074,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, */ } - /* - * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() it - * has be done above for all cases requiring it to happen under - * page table lock before mmu_notifier_invalidate_range_end() - * - * See Documentation/mm/mmu_notifier.rst - */ page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); if (vma->vm_flags & VM_LOCKED) mlock_drain_local();