From patchwork Wed May 24 01:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13253202 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B15B6C7EE23 for ; Wed, 24 May 2023 01:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239048AbjEXBrt (ORCPT ); Tue, 23 May 2023 21:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbjEXBrs (ORCPT ); Tue, 23 May 2023 21:47:48 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2061.outbound.protection.outlook.com [40.107.93.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1DF5184; Tue, 23 May 2023 18:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U+kwTUz6DI9duXVNyaE7fYHGfbJ5MQASbhkyHG19lKMIToqIS702wFEg7AQEJ6Tj7TXI+i68xbDdGiNIFNFm0pW9KsSJkgdvitZEhIbXn4ZQXwHtpdklU3N6z5rS/1juenYQUGwQUcDNsi4m6Ds/MSZsBAxnzbabwK+BetCE5x1EfqHrWkkVZUgaAv4OFRzNrwjoeZsBLA/6yWdZMwTSM+ys1KVeMXXB3gyVJOtz1xFWCOUXhkZierMH5ai3F1v/JiJaNSImrIcAWcJOe7977BSt7Daqm2OMtfr5vti7Q3LrESx9XzS3RXYhh4GfzEI1DEE/xSP5m6Xt2hP6ZwcSEw== 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=qgJbIcZKx5v84WwaaAM08aQe3wh+Sms6OGgmvrl2w3s=; b=UIB7IbvLJMU8YFG37dadNldFyBGWUk/QlnIydC5MaLkr0mXwTmlOszrelMfMWUSAjSX0kmFTMG/yOJrcZWWWsJSQGZ2TOxRfI62EOd+pvSS2vXJbb3S22tKGyM06NkySCjFNX9vAcCyeeBsSad9u8XUEzy1pXT67H4lM9KUQTzPNYW8u1dxI98DXVyPSFu2dwGdfJeNM0rtkKlvmNOsE8tGb+dPphTiLUbT5T9qHIbyNYiCZMOp0pgGYrINL5argURm9KRgC7IbDlhQsLlUxqfaAkqOx8JwGZu0GVK+EksO7mu83qgG/0YsVdsVL/OEKjJUQAIv+8V3P5xv7cgf87w== 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=qgJbIcZKx5v84WwaaAM08aQe3wh+Sms6OGgmvrl2w3s=; b=g2uGb6WGtw3C6wRd4u2QWlwdZqrXpX6O8bS01j4Sj5Hu8JpX01bt47qqAfAEZ6Ocl5EB/zgbgHBQ+JhkW8mDR0emmf+BD458pMt9SHxkYZXeQQypcDN3R/h7pff2ZG+jE7eNbHXGa44in0nblVDGvronvHwg6cEqldC2dAM7+FC6T14a5OX/QZwbkIcbXRq4M7iinFIS2Z8mXNmsS4+P/6nGN4mdRSE2r9WIwc6ibteROAlZJn3t/koUTqXxJ8O7pULzO/Ir298UavTtltYE6IFstvWBLMv7Yr5bElo7F5WOEUyhz7SUxBk08FHC0L0VLz8ek96Ix33Jq66BFikZhw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB3181.namprd12.prod.outlook.com (2603:10b6:208:ae::27) by CY8PR12MB7492.namprd12.prod.outlook.com (2603:10b6:930:93::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.14; Wed, 24 May 2023 01:47:43 +0000 Received: from MN2PR12MB3181.namprd12.prod.outlook.com ([fe80::f0b5:271f:a7dd:9e2f]) by MN2PR12MB3181.namprd12.prod.outlook.com ([fe80::f0b5:271f:a7dd:9e2f%5]) with mapi id 15.20.6411.028; Wed, 24 May 2023 01:47:43 +0000 From: Alistair Popple To: Andrew Morton , will@kernel.org, catalin.marinas@arm.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, robin.murphy@arm.com, nicolinc@nvidia.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, jgg@nvidia.com, John Hubbard , zhi.wang.linux@gmail.com, Sean Christopherson , Alistair Popple Subject: [PATCH 1/2] mmu_notifiers: Restore documentation for .invalidate_range() Date: Wed, 24 May 2023 11:47:28 +1000 Message-Id: <3cece716fc09724793aa832e755abfc9d70a8bb3.1684892404.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 X-ClientProxiedBy: SYXPR01CA0146.ausprd01.prod.outlook.com (2603:10c6:0:30::31) To MN2PR12MB3181.namprd12.prod.outlook.com (2603:10b6:208:ae::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB3181:EE_|CY8PR12MB7492:EE_ X-MS-Office365-Filtering-Correlation-Id: 296ad4dd-298e-4f03-37cd-08db5bf8dd9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D0OENjXts2es4bMNlg2aFE+gZ4jCjkAXHmoalV76JqMzGBYHMgECf0yOUKSjl/UV8FOYB0cdYJx48EID53jQATtNZh6W90WEOXQDUyia3apKoaSAc2MPaUIfN70kCJVuhMutz0KIsZBkjphqqwN1LfJtuDdCXozTv+tIALZJbRMLXC8gAnbEfqXlFvBhrl3rsLC9ITPGEMEZHWk/TIxI80jxJgZ+AtXgBQJao0WNEH9IuEtex3S3bpHxFjosONrq4DgwNK+tjnZYGQolBjH1WTOMQjCkeHBRbDChO/qu6fxrlWdRjoz9WKuEPJT7MgaTRns1b0rqKzSGFqzDLTZyZNZSaOaf3Cog4t0npC3ghj1qa/a01MmyerwRLYkwF36H8dN1q7e6R5H0MYhv0/FYpBvD6nEMYWZDibEaBiKR2OO3phJqw7Uzql818Ava/diXPu3Q24YFUBNaw1biAC74XMOWILdDNTS6JWsq0mskEeWQVqFJYrOhKKUfbfkcBWKaupWLeKlIuzzSmdGPtKK+eWZi1y7WGlvfoSH/OhNRYMOEnLrr92P/7TqpqqZXZc2Aqi7wSaxZVfZy/VOP73AmXw1nRTFkvwima8L+sefTi7uCRVhMPUQDZOwew09nKiM9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3181.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(376002)(136003)(366004)(396003)(451199021)(8676002)(8936002)(5660300002)(7416002)(186003)(83380400001)(107886003)(26005)(6506007)(6512007)(38100700002)(86362001)(2616005)(41300700001)(6486002)(66946007)(66556008)(66476007)(4326008)(6666004)(478600001)(36756003)(316002)(54906003)(2906002)(142923001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Tl4A7wJneCaa4i0pkAyAA72UG0+OEGzvuvwm7SCqnucodfDKxvb2dZtkehKgrfG9FetBUZtIy1iq9CtkK8TpSTbS9YgonJIcAEQzi5WK56K62thkYhPCc0gX6FJw3ScThBxBXi1o1tOe+GCoIXLOflvfw8ToKWwj9QTGpFf7qwjRRwj5Z2kFysZutmYp2GavjPmkAG0R+yl4KwPMdRTBIRDfMzAwZjtqEYyXxQy58nizg3oCng0SyUQNFuFgbtWXRVyH+OLT4EyP5OYCmRDe3hEBmjfGm7N7EZ6L6TBtbWwAOEB19/BnpyhX4cB9KcS/izYbavohOXnesdHazj5polC7s5sT+GCPpQANy17C70vulZy2qgwGcWIimTa1r7U+D6bwtHItMxcXtCAN0ged0q/GQH5n65K5zyfG/NLvB6MCeKujg0R6opF2UvwRfzS6bzqQdxWpHT3K6etb4ei5UKuGukZESWRV++ac6kA0umy7nAJH78z+h3O0KYdz7XffUliDuUYukGZzXDvLKiCSi0l/cl6+2aT3txhxtU7sn1JBAeOUIidF+Rkb9n+cKbtAZSzG3Z1N81axUE8tzBjO4FzUIM5MtJN4yKCu8qXRTeWGx7sH7VKFWNLexfk45kPORLf3qbbydna63FaR9FSjoRMVfAusgVeXcFgVGVQdwhBW6kGvkPbFYg7LjP9YWfu9aEhJDTAw5FFhtvZ4A+qKFbKQ7haBy3X7XZ4rkd+++lyiuKZuQ82CIELpY+dx7lFoqOxgHlvoVvv7cB4F9ERTnA59qPeyt/gEsXzGtut6+qg4jLTwYbD2+HxJyl6g2xjtCvJ9rkCNfmwjhBS5wJtG4/T99DO6HHln1K/45tv5MLX90kmJpNHO6/Tywh5Gc/gWlKNIz6qzxM8+zo1m0vtChm5UakqoowempNSOe//w4MeDmNU/yy5kvt9nLC90yalEwzkTrjWhRDPsst5APCWZmBpHTG+t7aRCGVxUyrhvwVzMxu4gLRhl+0s283Pw6vs/ZzQoSmJDoBCrbVMtwhnRDrSEisHFypqpuEVZSVzUwNTi3JexY81D9PUl3IizYE1083evc9fivyLzZwo71Ysgo2ACztur8wXFrfv4sJDf3WEkS7xsCg1BW3FVNJOSIfw9+iSmpKnuYx+BGwreYY8gB0/OPNmo7DmhOYonHMGR7/+bsEWoCKHshVw9FeEwRI4MfrKfvSgjwSUTGOMrkHydJH1LgOFDyrZaE7dFa6sLVfQwvuuKn4lKgxsZyOE4GmlbGEwEFFCFrZm3V0CVommIGC3zyYEroV1156QZg+xMarsrWovLAI/zhYwUmfvGsSpAszDIOBLWoBv5B/huPV7FViZICHvOwXg4wJT9Nur+duMaXwyKiQlAZ+8Miv0fYavh22zQEll1i3qdeCFGsFNtE/nNpR1rR6eN6HIheVAPU92GDmER2gVeLlHXoN0pt4HAqxE0mU4NXP6LNtSkQ9QhlgXzMpUTvLQi2Av0oXZIefkSQuqrdD8xvXQgWgmZ8AnpHrzNDiGW4QJXlLBje31a1hxu8OiDzirVSIUqjOHYU0Pm662N4Tk98j6LHYlZ7aQy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 296ad4dd-298e-4f03-37cd-08db5bf8dd9c X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2023 01:47:43.3322 (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: o8nzlMl1N86IZpbrrpOE23VRaBtxSTgVMaTXhzqKgky2yc/PjvPLZPmIznMHUzOSmTQ3/JiAcmcxMvDwkw90uQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7492 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The .invalidate_range() callback is called by mmu_notifier_invalidate_range() which is often called while holding the ptl spin-lock. Therefore any implementations of this callback must not sleep. This was originally documented when the call back was added in commit 0f0a327fa12c ("mmu_notifier: add the callback for mmu_notifier_invalidate_range()") but appears to have been inadvertently removed by commit 5ff7091f5a2c ("mm, mmu_notifier: annotate mmu notifiers with blockable invalidate callbacks"). Restore the comment to make it clear that .invalidate_range() callbacks may not sleep. Signed-off-by: Alistair Popple --- include/linux/mmu_notifier.h | 3 +++ 1 file changed, 3 insertions(+) base-commit: 44c026a73be8038f03dbdeef028b642880cf1511 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 64a3e05..447d757 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -200,6 +200,9 @@ struct mmu_notifier_ops { * external TLB range needs to be flushed. For more in depth * discussion on this see Documentation/mm/mmu_notifier.rst * + * The invalidate_range() function is called under the ptl + * spin-lock and 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. From patchwork Wed May 24 01:47:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13253203 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 683BBC77B7E for ; Wed, 24 May 2023 01:47:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239057AbjEXBrz (ORCPT ); Tue, 23 May 2023 21:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbjEXBry (ORCPT ); Tue, 23 May 2023 21:47:54 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2054.outbound.protection.outlook.com [40.107.93.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 265E5184; Tue, 23 May 2023 18:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S3Klz7185BB23Ywi5kcAG+hsDsGD0zsYYPEmUQJBse/8l7PURrjv38PuzfULx+HOcKBgGbIUXncloZFwZKo+WhJXUyDITIvpAyaPUsffFhokumIzkhe0AVu6Z6b+FlBKeWEWtxiCfWqW9zvMgEVbv44FGpXSJw70mM3myHOXfIU1tivO2KfGC4l3+t96ru65uT8u9rEMwQosRQesc3Vflit0SLeQ9SOWJ5qAcEQ9dWR3owcovByb4SKyGGYMHLUgt5HGf4U5FGqEbXt99CSXzHBGTOP0NttkcZbwo4IkbjSfnYNJVEKVBNoK0T71N1nSxxaWzYzmp4imx4miqsexVw== 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=v0pu+6uwCEupTE/Vp/j9b7E3tO0/gX54NU2icWTyJ/I=; b=L4JjP3zEGhqg8efRuYMcbkW9JW4W3VgswUTs1HO4cskb+DcEW946RXo04dTsJZ4f9aZEe4lmPHkbrnL912kIp1hOMQnya6HDPgX86/79EHOaRqd8t5IFHlmqMyJ+U8AmSn8AxRXUomhSBVkzdozshYOswpCP63Bk2lklvRahomTGcoritqQzs2tCwH7nTXjZM9/E+WfQ6ZpCjvejzMl/jEbGalPNUZheSnf8ahf4sm61QACMZoMyHyCAXCNTkvj7dHIGoapTPiHd422BOwaOiKbJdKOjq3Ym1oNUYxI/jvaR99VL6nyjkqD9/qNj/Ec8eZ4XzbxXjeSHvbWgJY64JA== 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=v0pu+6uwCEupTE/Vp/j9b7E3tO0/gX54NU2icWTyJ/I=; b=EgU9z4o7CN2t4A5NsxeA59QI90rIZokpR8n5/VmrVFSEH+GaedPXhguTWSySWjCk/dMpAPB/E5KWVU4bTjUWBPnOuuSWMfo4QC6bNjqQWbs4LSLjqhSBbMe3wAS/7tGu+Z+QOu75A+6jZft2vWYK6YWSpLv4AM63mAQ+dcrJRSh3vI5zjvvvd+kU89qmWk2qlKINj+YpCHpaJV1ggRbbSGeYr70u17TenRVZKIQ7lYvJbDjd+BLTo4GZIEddnCdELiwutiBzgLq31CzIvLKfxGTlQdac+POqPlKH1Iqm8OYl7WWHMAJj2mCdDONOIKxYON9/EhStlKQzy+AraJw5gA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB3181.namprd12.prod.outlook.com (2603:10b6:208:ae::27) by CY8PR12MB7492.namprd12.prod.outlook.com (2603:10b6:930:93::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.14; Wed, 24 May 2023 01:47:51 +0000 Received: from MN2PR12MB3181.namprd12.prod.outlook.com ([fe80::f0b5:271f:a7dd:9e2f]) by MN2PR12MB3181.namprd12.prod.outlook.com ([fe80::f0b5:271f:a7dd:9e2f%5]) with mapi id 15.20.6411.028; Wed, 24 May 2023 01:47:51 +0000 From: Alistair Popple To: Andrew Morton , will@kernel.org, catalin.marinas@arm.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, robin.murphy@arm.com, nicolinc@nvidia.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, jgg@nvidia.com, John Hubbard , zhi.wang.linux@gmail.com, Sean Christopherson , Alistair Popple Subject: [PATCH 2/2] arm64: Notify on pte permission upgrades Date: Wed, 24 May 2023 11:47:29 +1000 Message-Id: <5d8e1f752051173d2d1b5c3e14b54eb3506ed3ef.1684892404.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <3cece716fc09724793aa832e755abfc9d70a8bb3.1684892404.git-series.apopple@nvidia.com> References: <3cece716fc09724793aa832e755abfc9d70a8bb3.1684892404.git-series.apopple@nvidia.com> X-ClientProxiedBy: SYAPR01CA0045.ausprd01.prod.outlook.com (2603:10c6:1:1::33) To MN2PR12MB3181.namprd12.prod.outlook.com (2603:10b6:208:ae::27) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB3181:EE_|CY8PR12MB7492:EE_ X-MS-Office365-Filtering-Correlation-Id: f9449404-5998-4bf7-901c-08db5bf8e252 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hy36ZKSiMTOnSjGoyuau+MeWoFJ80Um/81u/lmfEjEDv5uQ6EPNXY+YZl7zMBKrmvWQ2qkIFdWsLdvSX/iXIAuB9EBt0akXleagCbHQ2ENphFsgJ6oGicms2dZ8YRcxlxgcJ4/yS0xq//pIVKRozD9uYuh6KGKyL4HvLdqYBZtjCsHQkUWL8pTjno8GqZeDtg5aysEr6YT7V+um5+dX0Mri8k/LlzUJpETbqRdL39wIPGHMaqIdHsd63oS66Oru0ByDG8zhmEMOtmPJKFok1gJ4MXJoMpUdRN2b1dfRK2WHpCec+j4L4HU/cCpOMzT8QQCQYfr2rsAWnw+j9zPeU5spSMOIRVrE7cHZEv4wVpQk4KOTT+7BvEPzXYcUW13OPJbEB2ACYXqc6sJhDfxbdvTReHA8ErJwNm3Ab7BCzifG0Pyd58ktB27YwmvBeteoxUO2g7XzeYvcz1hl/mIFj0ocUQe6PKkf0fOOpwE/DXTiCLSh5MFRixqSgyBYUEjH2U866tk5zMVTwK5XvmFKrndnFxNnL72W9y3bX8VIF/2gy7b3moa1ejX8nNttVw2OpJ0CpoD2Q5F21xze6A1kQjNZ2ksbJ4idMj0de9tFEl1Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3181.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(376002)(136003)(366004)(396003)(451199021)(8676002)(8936002)(5660300002)(7416002)(186003)(83380400001)(107886003)(26005)(6506007)(6512007)(38100700002)(86362001)(2616005)(41300700001)(6486002)(966005)(66946007)(66556008)(66476007)(4326008)(6666004)(478600001)(36756003)(316002)(54906003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xM/cr1Cl3aJDRb4TgNiMzYmMk+0Y6wjzbCgFgcCqijcQD0mtjbwv2mfBASAWGe0EEYs/F2OCB0M8jY/fMU+nqrF+De06WMgcvgWyoRY90dUot/fhc1a/LtP+xOXi1sG0UeubZ+uJRs+Nld1tazbCy+qJu3yhNGWUaRLY91U+aasVKB3dtf+Z2l9tXIIwfDpomJ2oUjyTQnmlSD2EjeeXujtJLhGkXavHFqB1af2RCy4x0h3uBtm9o8/8eGZuFxyskhVcLxlGB0IQnYpFrKKB4LYdR0yzcM3lC44B/vr6z4PD08JxW0o+WTdif+yeyYY0acpLsC5x1gYijiPYHS0JwLGQV4spQNJ9cI++dsMd/kRKJvbQ7pouu1UHSSqMobonUlmWnkbhmj7O53jtO11LYVVXb6w27LAkgYJ/cOMWNHOerpoFlEp2WYrOB1azbsTVPRmyIF4Dyam7FXK77/D5t3xNBY5jyP3/OvjUJdSL3dknWGk82EwLHJHhH1ATyluEO10nFwKajxdY22ZkyKp2gOik0j6W0aobmqk54w0zFVw77mRpCiFm6GJPH72dOoequUtyI5dklSj3C88Di3C5RhQLhQAmkmOsk6e3ozSJ+fyqiYwjUUhpqKf/iWdxbNjuferpstV6vkTwN+IChLlt4WAkRkTCM3Z1X6xgeQiZjMBNZHcA8oHBAansLU8iNMzvHb+iidkhKorBkaMRT4t9DaX/9riTu38Ss4lkD1nlpaJAMLNsCuvnpJ/KcVT5u5xmrlYSPKGcCOz5FxF+oTOs/S9up4HC7CZGjopbiBoHAAvtm3/CcLY6ncz80d91NC9cod5aYsC/dgTU+Vkj08jV0elhhg96N+DTBq5DN86bC+82Ox37gsny8Wt06KPl/YjE5DDAfiPe1OiueZDM9PhAa8Zt4TKgXlUnO7qTdgFLy9GLyzcqwMDygjztco57FwIQ4LeXHj4zAwkWWTVjkiTMP/pMiOIr8q/P+5jprkVpS/k8Pvvb1TzTUzUMvPL9n6/SUlpPVWyJ3sSH0wsZcwjiLdpgtq63ti+F4c2DUHjVNMdIM7W4bZP0oSlBeshBfvIyuQ/+IqNb9PsDbNDoiRPhtAPmOmf2L0CWv7GSklhloKbU5DCCyEc/SkHLMI/XSwZiAKMFCCQgMBSxMYPBXSGDSF4b6UM/Fx4+DNF0IOibNPt361dmqWvzle0nYOv4hnn8aHKUzzaCMtGcyWw3S5yINdGIVqqEIOmoHOCfg6/lBD30mUtKa/yj0Zhy5CZvEVNLp7IKKMrYwS167ljyWvXymMy8/7ui9L3mfoBgqMDabM22vCg46+hOjJOZ7eEubemKFat5xizdRefDJR0XNDiSngHgdlmZ6bjdubhiV/INLy5YRPMU9bxR3mCqbdTMTSijIkXNYQ+MYn41sDNY0WE3mHE/k0zuShyAkg4IlwVSmyHKoHSDw5V3xJKBLCF726oTnrUKT103+x2afbpfZzfl22/DRkTA6qM6v4ao23givcfcMEfR1KVYFuCCVlfq433vAtFSrdx1eXHPQksbhVvhSrPGKWsj6GFpkF71eO9y8YY/oiVHn2fAvVpu58YYKd6G X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9449404-5998-4bf7-901c-08db5bf8e252 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2023 01:47:51.1495 (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: 1nhejWHcB6xGC5KlNF5h12IBbyY85kk33gGUsam5jrG52WqEVJMbCyZqsqVy6E0qQe2Coqd7g6arsjomMDOamA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7492 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org ARM64 requires TLB invalidates when upgrading pte permission from read-only to read-write. However mmu_notifiers assume upgrades do not need notifications and none are sent. This causes problems when a secondary TLB such as implemented by an ARM SMMU doesn't support broadcast TLB maintenance (BTM) and caches a read-only PTE. As no notification is sent and the SMMU does not snoop TLB invalidates it will continue to return read-only entries to a device even though the CPU page table contains a writable entry. This leads to a continually faulting device and no way of handling the fault. The ARM SMMU driver already registers for mmu notifier events to keep any secondary TLB synchronised. Therefore sending a notifier on permission upgrade fixes the problem. Rather than adding notifier calls to generic architecture independent code where it may cause performance regressions on architectures that don't require it add it to the architecture specific ptep_set_access_flags() where the CPU TLB is invalidated. Signed-off-by: Alistair Popple --- A version of this fix was previously posted here: https://lore.kernel.org/linux-mm/ZGxg+I8FWz3YqBMk@infradead.org/T/ That fix updated generic architecture independent code by adding a new mmu notifier range event that would allow filtering by architectures/drivers that didn't require flushing for upgrades. This was done because calling notifiers from architecture specific code requires calling the notifier while holding the ptl. It wasn't immediately obvious that that was safe, but review comments and git history suggests it must be hence the updated approach here. --- arch/arm64/mm/fault.c | 6 +++++- arch/arm64/mm/hugetlbpage.c | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index cb21ccd..1ee45a8 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -225,8 +226,11 @@ int ptep_set_access_flags(struct vm_area_struct *vma, } while (pteval != old_pteval); /* Invalidate a stale read-only entry */ - if (dirty) + if (dirty) { flush_tlb_page(vma, address); + mmu_notifier_invalidate_range(vma->vm_mm, address & PAGE_MASK, + (address & PAGE_MASK) + PAGE_SIZE); + } return 1; } diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 95364e8..677f0d1 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -487,6 +488,14 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, orig_pte = get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); + /* + * Make sure any cached read-only entries are removed from + * secondary TLBs. + */ + if (dirty) + mmu_notifier_invalidate_range(mm, addr, + addr + (pgsize + ncontig)); + /* Make sure we don't lose the dirty or young state */ if (pte_dirty(orig_pte)) pte = pte_mkdirty(pte);