Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4767281rwr; Sun, 23 Apr 2023 12:50:59 -0700 (PDT) X-Google-Smtp-Source: AKy350acFXLVlImV8rzFRDooGvLfJAnzepFHRwKrwSRuHOWIzbGZweXYjT4eKxth1ii1eXf6IOBJ X-Received: by 2002:a17:902:e752:b0:1a6:955c:6329 with SMTP id p18-20020a170902e75200b001a6955c6329mr16147917plf.22.1682279459325; Sun, 23 Apr 2023 12:50:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682279459; cv=pass; d=google.com; s=arc-20160816; b=m7+ZWDhxUC5IyOFag/7LSvKpZuYKV6qwxzKa+bvR8fjtEddRUEEMh3OTUQ0pGPcS8Q x78B8qnaMin+pAx4mLgnkjl+hLIEuvbDHLjCHNh8iXzjh4ZdQvFrP/ip5NYfAQzPDySD Z2qda0N+AIxZZgHhwRSYgCxXCpZmc8NV2uIAI4xMxRqp12Eg+gpL/C9oCZIMGZdz/ete q9Xptcb9Q5S1u0tvwsOfUG2RZpcOSBuqRQ3/mUf4XxSBtcWbL/srWhOEEVKodCVuXwMm 9oVCahad5fZ83ir3g61ZA3OSpKboKbljzBVnfhnMVMhdF/X3QIxzruuHz4qKa2StYnCu w0fQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sRzijtC3r3OzRdihsIEasZUOnkrBMe3AX/H3bgylpds=; b=wrPEKtwQjhc7OOe455Z11W50qm1TzvSUx12qzA+Rf9uPPuONtRg7QClZiiOQMD+Yco Rxq2y+RUo6TLuTrScbP1rEgBtrlwRyOLONhzvBAtcJYwp3PY1oUcw0qB1r5PgkSf3f1E uKXJMFX2ksiROt1UCvv83DjZtXMacnAasHC10eUngWs+BXSZu8IGuFPaLOtGbCBSznUE hqn++O/DmUwwO38KWprgAIyxKUFBDlCBK5Q7g5sohRDL3pw2/O/Hyn/BITD2IPEJTTk1 krd+I4Cn0NQO5PNnyTeRQt1La8je/yTBJwtrka+6ZtmfAgnbwQgvQCnl+gfnkoPHzqG3 x5ww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@corigine.onmicrosoft.com header.s=selector2-corigine-onmicrosoft-com header.b=L1JbxueJ; arc=pass (i=1 spf=pass spfdomain=corigine.com dkim=pass dkdomain=corigine.com dmarc=pass fromdomain=corigine.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=corigine.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a170902eb8a00b001a63e1de408si10147781plg.353.2023.04.23.12.50.42; Sun, 23 Apr 2023 12:50:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@corigine.onmicrosoft.com header.s=selector2-corigine-onmicrosoft-com header.b=L1JbxueJ; arc=pass (i=1 spf=pass spfdomain=corigine.com dkim=pass dkdomain=corigine.com dmarc=pass fromdomain=corigine.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=corigine.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbjDWTh5 (ORCPT + 99 others); Sun, 23 Apr 2023 15:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjDWThy (ORCPT ); Sun, 23 Apr 2023 15:37:54 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20718.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eab::718]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E6E10FB; Sun, 23 Apr 2023 12:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VdrNQfMXW4BnPsgAU36uAVRGEVprou6dT/7+YmD7qMAxEnZmKtmI8674Wa8mBuqstHrBGKSrO2Q/a3LpYfCKmEE9NsbXJO8qg8xbQWv0/DA7oxnsuICG0mKPSA4yinZXqK7MgXSUNJvzpTnzl+GAyYwye8ohQlixS1Jcy3ROiT7kiLWceD4M7iiv5YmIUMil397C4mbm3m9r1tmpDVDTSCOjnjRkpTzE/DqxCMc3dOVUEg7LrdKEg+NT5FJEF1u1J8szECUrq4h9OsetOo+79JwsWYUtfQ8v7OPEZJGrFOa8C68s16Jz92hfG19ptDBFNbl4MefJKfqGOiKCWkOMSQ== 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=sRzijtC3r3OzRdihsIEasZUOnkrBMe3AX/H3bgylpds=; b=fP7DVpQErGBk/sKyjegyyA7UdxUK1007ND5zRUOj/0lluS8P4caSpWkVhsPmEdUMIKenFirdSCGceVQCu54esXrPc0JbHfz9LbMHbtzJTi3FxGsfrDR0lWZ6MQNAUMa8J67N0pJBzuGjhz0IrLvTv0QojJFRmaIsGSdewr6zNLnt3g17yYF9oozz5AZzFiPWpCNKtcHkRSuNJsWA6PnW/1K/Pa54lziXWoJ1X92jke+Oasp/xQcpg/nB2XiAg3zBry42/4wkzXsR8FrIAkhOiPUCjOkmGDW+39inZPd8xQehalJ3G9FmDP1ap2J4tM3kMs6jqIFXwRSCvdpfT26sIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sRzijtC3r3OzRdihsIEasZUOnkrBMe3AX/H3bgylpds=; b=L1JbxueJWtb7mA3YIouSAblWKIFujkmLty+fLA9tXr4cnPvK6tfH2tEPE1oJKMsYMce/ClEeLMcU7/KfU+A7SG8eDFBQc24VQ+2xja4fWZMbg61Ba9gS2ZKtRyDUMN7tc5lQ7UrG+FdqMsZGmtu4h54TcHYYoY1rjRP6H/BWfLc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by BN0PR13MB5167.namprd13.prod.outlook.com (2603:10b6:408:152::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.33; Sun, 23 Apr 2023 19:32:13 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::f416:544d:18b7:bb34]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::f416:544d:18b7:bb34%5]) with mapi id 15.20.6319.033; Sun, 23 Apr 2023 19:32:12 +0000 Date: Sun, 23 Apr 2023 21:32:01 +0200 From: Simon Horman To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jason Gunthorpe , Jens Axboe , Matthew Wilcox , Dennis Dalessandro , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner , Richard Cochran , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: References: Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: AM0PR04CA0054.eurprd04.prod.outlook.com (2603:10a6:208:1::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR13MB4842:EE_|BN0PR13MB5167:EE_ X-MS-Office365-Filtering-Correlation-Id: fa9b4082-ee29-4fc5-1889-08db44316fdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XzWs/2NUR1TtAefCnHvOBHeTRqcNSC6OnsJ2bEoGkSFoBIhsUToo1VVw2+IPtKvV5jEfk3HBahaXEYf02TVGBjhdaj4e5DEEnNfVW9cZ2z6q73kGm9eYlBVuZWlGYikPIA4iFKlSc33X0424KTu69lYQ0Y6+5+Hj1o03iBJspy+3dgV06slw2uFe0xNpkhXtxFaRPHStwjyXeCErOvctMYtWMGQmiWGL+BwCrCHygucXCg55CdAIafOz2FFcZ7Bt2ycgumXY3FzND7DxOLG7lcZNvHc00rXpuxkCF2/vbKQx86bclIedi2Wd3P4eKwf8CSEDfflBQuu2zJt4pqqd2HN5nBKASv6eKrpDB26IL8w6m1yo75Wp9Y+iaDYlFFoxxqtUSL9rfjzfKhPcGQIqPhpX01Szm1BBZwhS1kLDkMfwpn/DW3qjuqyT721J05CPjPN4z0xdpMJayohcpkNdbmqPMpxHpFrZdMtaMknYqyo/E4n/MhDr3SrdRo9VogLvBhFbJXtL4c5vPUGmvAH+U6j7dqQ2ZymHLPrGp72gpRKCOVQ0/cR4itQXX4NKfxe+ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(136003)(39840400004)(366004)(451199021)(2906002)(6486002)(2616005)(6666004)(6512007)(6506007)(186003)(66946007)(66556008)(66476007)(8676002)(8936002)(316002)(41300700001)(6916009)(4326008)(478600001)(44832011)(7406005)(5660300002)(7416002)(54906003)(38100700002)(36756003)(86362001)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?soUJBCApcfQiwe2/wueHCc+O3gLCqZ5gZHGeFPDXIY38IsF7qEnMq7Ojs4dL?= =?us-ascii?Q?eoO/U4r95pOCClO5ZeLkdvlz/85ZoY/UvJPSafyyzbnytcrr+YjG6HEgjDup?= =?us-ascii?Q?Xwc4+rAtFSXQ9eMfFJFNUo04PkF5Qawhej+V9OMEZPMX7L4Bpgj4sFPKcfTJ?= =?us-ascii?Q?k75HNGJJq2xAbY3jCU75YNvrJwulGjZAvj2kO1kjrtpkXbHGYFiZBaijRNGK?= =?us-ascii?Q?HODiG/O+Nvd5Y5bf7qnCs2/V1hnRyBnwn/C6GDLxl5n7N9tLEN8HhLs60896?= =?us-ascii?Q?GEnxQSymou6uc/0PK23+9qdCq33RuDHb39uazAi5nkjLJict9Q+1W+NP+gOA?= =?us-ascii?Q?Tdpsp/5K4GgQ5Cg0+vYgHHz4cpRFd+TEPC1OiGD6jBbtyDX8UCPgEt5rX7r8?= =?us-ascii?Q?0GqPRg0v/CrNaKgm0gmqO8x1vcTXekZa6kTBmf8qBzsm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FPZuLQVo/1IABm/iU6GQw4+vCi+So8zJDqKiT03eTrE9Lyh?= =?us-ascii?Q?junML99Dyoei+ZBN3KH/tVGneN4BodK17cLLJWoQ25RDXwEGIGlnpr3qCbCO?= =?us-ascii?Q?7yqJVhXU/qH7MwlAa7HFFCg8XbLRJR/2rNwJYMV4VcriJaMUxQ7p2Xqh3yyb?= =?us-ascii?Q?UOce6UXTfEzhJoxNfrE+WEht12hiSkAOrE83qFnKgxpXPLR+nA+6Zrcxa7Jw?= =?us-ascii?Q?nQ/2pXagGtZRbk8vMW6a3qKyBPQg+nm5mth4z+ZZod02G957v746gNfZpry8?= =?us-ascii?Q?1+LpMMCMmgJSUp1NTD2tN8BmH3kTxt07P+BSg+8FDPKZMsyQfjp31mqc3Eg/?= =?us-ascii?Q?41Xkxw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa9b4082-ee29-4fc5-1889-08db44316fdd X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2023 19:32:12.6120 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +OuMxX14iuVMZDcdKLA6Yvyg2x4IqIEeKuBn7df6TpANh9Mmtb/5WPFX4EwIujMoafFJLY2Xf5Nzwj3agMXe7fk1taHjN+UqBIjpOn1ZiRI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR13MB5167 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 22, 2023 at 02:37:05PM +0100, Lorenzo Stoakes wrote: > It isn't safe to write to file-backed mappings as GUP does not ensure that > the semantics associated with such a write are performed correctly, for > instance filesystems which rely upon write-notify will not be correctly > notified. > > There are exceptions to this - shmem and hugetlb mappings are (in effect) > anonymous mappings by other names so we do permit this operation in these > cases. > > In addition, if no pinning takes place (neither FOLL_GET nor FOLL_PIN is > specified and neither flags gets implicitly set) then no writing can occur > so we do not perform the check in this instance. > > This is an important exception, as populate_vma_page_range() invokes > __get_user_pages() in this way (and thus so does __mm_populate(), used by > MAP_POPULATE mmap() and mlock() invocations). > > There are GUP users within the kernel that do nevertheless rely upon this > behaviour, so we introduce the FOLL_ALLOW_BROKEN_FILE_MAPPING flag to > explicitly permit this kind of GUP access. > > This is required in order to not break userspace in instances where the > uAPI might permit file-mapped addresses - a number of RDMA users require > this for instance, as do the process_vm_[read/write]v() system calls, > /proc/$pid/mem, ptrace and SDT uprobes. Each of these callers have been > updated to use this flag. > > Making this change is an important step towards a more reliable GUP, and > explicitly indicates which callers might encouter issues moving forward. nit: s/encouter/encounter/