From patchwork Mon Jan 31 05:17:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12730423 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 6A6A7C433EF for ; Mon, 31 Jan 2022 05:18:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53BC46B0093; Mon, 31 Jan 2022 00:18:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E9746B0095; Mon, 31 Jan 2022 00:18:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33C086B0099; Mon, 31 Jan 2022 00:18:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 1D7E46B0093 for ; Mon, 31 Jan 2022 00:18:04 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D5DDB182229F3 for ; Mon, 31 Jan 2022 05:18:03 +0000 (UTC) X-FDA: 79089425646.14.61B28EC Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2043.outbound.protection.outlook.com [40.107.212.43]) by imf10.hostedemail.com (Postfix) with ESMTP id 3CC92C0002 for ; Mon, 31 Jan 2022 05:17:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q+OciI1BuSx5XasxyycErc2LreWYx2BwZ8JNvNCUv7KCcEYxMyBm6pSyWqDy5smtYHey8FNq4raFu+Y95P5iJPtrD34gDDo7DKWMWkco2Nj0NXBb+mknmny8o5K9kZYdoxwvfMvvCGEQmS+vUNs3ov5nk08pZEYj4yVSa6hjhvN7ingBcreMbU5NqTIu/UD7GwZIZP2nA4hF5BrgOjwwHnQT6T3IJoqzAy8jTIx4m6AzMbdtp5QbDPHzF0vjwUufGJFoQwG5UL3WCpaD6ZgFjsbhXTFhnl/rWGKhxBmPPulkfN05JyMudTAAx/L4S4+WYP+EtYEmZUT1WH6o/BtzXA== 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=X9byx9sl0k994OaiaZa3X5PdM5tM/l2ZQYd7CkJD4zo=; b=XavBqYYAERrpXk+HaOQZFQAUdl204QJsTGYkDO5mgthTOaSVVkbzqvGqlkGWUsm8nlI57TrjekrIcAp2/tLDcE+MQQ0VKHHZAtQPWQe8xvvFyIgvC4UrsQhK7nOjEFU6iLmR4037KqR1/sH0NZZ2FVSygX656XEqqoslv+cOQzI3I7Fy4UliyF3WZ6SD8qpxocEgKdOghBXo2sZfphSAh2k8QDBdAsxGgrB6Q4UdAgHMF+ojawL2+FqABzOOOVe28jWxTgBSeBc84yYE0r6Eh/+nGLao/3VoEKQNWYMPDVQEvmi64jzrROXezbl6j9UulsZDp6Oh91YQgNP2iV61wA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=X9byx9sl0k994OaiaZa3X5PdM5tM/l2ZQYd7CkJD4zo=; b=NbwnEqdXzZDo2SMPXCD2jsu2Jkv875iVhR7MNdIJbUUJknbSKH46+tPtWSkiwYKXrwqF1KBPImbe88Qy5JctDnfjxibrww1ar8YuEBSYPqc36mdzdvg5/Ytp+Qm+oYsXnlAaavK8TVz61BLyKwzkxvDRwScc2trPGCK09geC3dVg8t3n/5J9Fh4YEpDhdLfQ6SLMbAeuNGWYl6u8BIm9NwggReIn+SXF/I00UHVBLiYoVPJgWXGfgxICfGiXEsoPj5IFOGxDv+B7XnTJO/OikflxAfWk0D5veVuU5dZ45L/Bp5NmOJF/n+TN6nJ96hAyEqghs60K6n3LrO9rDkUEyg== Received: from DM5PR08CA0041.namprd08.prod.outlook.com (2603:10b6:4:60::30) by DM5PR12MB1609.namprd12.prod.outlook.com (2603:10b6:4:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21; Mon, 31 Jan 2022 05:17:55 +0000 Received: from DM6NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:4:60:cafe::a7) by DM5PR08CA0041.outlook.office365.com (2603:10b6:4:60::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Mon, 31 Jan 2022 05:17:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT029.mail.protection.outlook.com (10.13.173.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Mon, 31 Jan 2022 05:17:55 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 31 Jan 2022 05:17:54 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Sun, 30 Jan 2022 21:17:53 -0800 Received: from sandstorm.attlocal.net (10.127.8.9) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Sun, 30 Jan 2022 21:17:53 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: Jan Kara , Claudio Imbrenda , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , LKML , , John Hubbard Subject: [PATCH 1/4] mm: Fix invalid page pointer returned with FOLL_PIN gups Date: Sun, 30 Jan 2022 21:17:49 -0800 Message-ID: <20220131051752.447699-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220131051752.447699-1-jhubbard@nvidia.com> References: <20220131051752.447699-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d31aa22-28cd-4fcf-8285-08d9e47909a8 X-MS-TrafficTypeDiagnostic: DM5PR12MB1609:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:264; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2Oul+W9OedlhtS31kz09qqhDURaiqMBieCoygRcZTBy5++bMbAXuI9+twG9Ac/WH6VLrxyZMfJobiyNVrrXExrjBXJN/vAiUs4etnKK+vPe9YDoxob3AsEnt0hOX9m5IIM2v9x1fZy6i/xid5NIqZ95Zjv8ao8mf0C4V4l7EUfBrts071kZdO++A1lCK0IEqEsfC9EbgTzq074HuGCFEcmUbCPnDnGl1M6kGkh+DwyMSRvd5AekjhwH0RPKXHXTB1fS6SwJeLbq7JR0O/szjEJ0pPHEadN8N1IpbIGFHiHMnWu7Dj+CsTu8MIb3Mnyjy0PKL5WyUdvcniM6VMz+8tUDGZY5K3J/xT4kozASjzRR7IDfvQML1gFZcXfRzT1n6IBvxNe7udNPM5j7Vaifqf7uNOhO0gNeI3uaseE6rHXowMUgQEyIg+66n/ESQDs5M2xVCUujdSoO/fzodpSJvNVsUtqP2oIpC1KQG5L22ycV49tQGM430BmWHdnNTqAGNrb1a8lPcmxlFMwo2iwSGdjitVJvbZp0blVw74RpBSLj1j7HBGC84LMt2ee0q1+0fJapTGGEyQ6p1QiSPte3ga9BQ8lfqc0evKecnVEiHaINMU24wdnlmLNn/tS4U66e6dGE3zj6ABzeUJLSkJoHzsX1zk93HNEPcyG3/ldrsFXgXkBkTe4LY8uu/zEjoqDyRR6KFQgEWQqtr/9lAK4UiNw== X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(47076005)(40460700003)(356005)(66574015)(6666004)(508600001)(2616005)(2906002)(1076003)(107886003)(7416002)(186003)(70586007)(86362001)(316002)(8936002)(4326008)(70206006)(336012)(83380400001)(36860700001)(81166007)(36756003)(110136005)(82310400004)(26005)(54906003)(8676002)(5660300002)(426003)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2022 05:17:55.2443 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d31aa22-28cd-4fcf-8285-08d9e47909a8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1609 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3CC92C0002 X-Stat-Signature: xpohqxf8okjouo5wkmgqqdr1aswsei5e Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=NbwnEqdX; dmarc=pass (policy=reject) header.from=nvidia.com; spf=none (imf10.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.212.43) smtp.mailfrom=jhubbard@nvidia.com X-Rspam-User: nil X-HE-Tag: 1643606278-955472 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: From: Peter Xu Alex reported invalid page pointer returned with pin_user_pages_remote() from vfio after upstream commit 4b6c33b32296 ("vfio/type1: Prepare for batched pinning with struct vfio_batch"). This problem breaks NVIDIA vfio mdev. It turns out that it's not the fault of the vfio commit; however after vfio switches to a full page buffer to store the page pointers it starts to expose the problem easier. The problem is for VM_PFNMAP vmas we should normally fail with an -EFAULT then vfio will carry on to handle the MMIO regions. However when the bug triggered, follow_page_mask() returned -EEXIST for such a page, which will jump over the current page, leaving that entry in **pages untouched. However the caller is not aware of it, hence the caller will reference the page as usual even if the pointer data can be anything. We had that -EEXIST logic since commit 1027e4436b6a ("mm: make GUP handle pfn mapping unless FOLL_GET is requested") which seems very reasonable. It could be that when we reworked GUP with FOLL_PIN we could have overlooked that special path in commit 3faa52c03f44 ("mm/gup: track FOLL_PIN pages"), even if that commit rightfully touched up follow_devmap_pud() on checking FOLL_PIN when it needs to return an -EEXIST. Attaching the Fixes to the FOLL_PIN rework commit, as it happened later than 1027e4436b6a. Cc: Andrea Arcangeli Cc: Andrew Morton Cc: Jan Kara Cc: Jérôme Glisse Cc: Kirill A. Shutemov Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages") Reviewed-by: John Hubbard Reported-by: Alex Williamson Debugged-by: Alex Williamson Tested-by: Alex Williamson Signed-off-by: Peter Xu --- mm/gup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/gup.c b/mm/gup.c index f0af462ac1e2..65575ae3602f 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -440,7 +440,7 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, unsigned int flags) { /* No page to get reference */ - if (flags & FOLL_GET) + if (flags & (FOLL_GET | FOLL_PIN)) return -EFAULT; if (flags & FOLL_TOUCH) { From patchwork Mon Jan 31 05:17:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12730422 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 3FE9FC43217 for ; Mon, 31 Jan 2022 05:18:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B88696B0098; Mon, 31 Jan 2022 00:18:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B2F856B0095; Mon, 31 Jan 2022 00:18:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957236B0098; Mon, 31 Jan 2022 00:18:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 871346B0093 for ; Mon, 31 Jan 2022 00:18:03 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3AE8598C0F for ; Mon, 31 Jan 2022 05:18:03 +0000 (UTC) X-FDA: 79089425646.10.2DF275E Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2068.outbound.protection.outlook.com [40.107.102.68]) by imf09.hostedemail.com (Postfix) with ESMTP id 95008140002 for ; Mon, 31 Jan 2022 05:18:02 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XOpzvs8yBaMidb/quJNuERyw/E2sH4FNu1cCmo0gafWqnZEmBC/rRFx6/kggLByhwABOSUCuzLLnEzDMQVMX8GBItylfWH3AkUw0XY9MpZICEBfBcmmKfplxjRbfnGLJaYzsvJ2OCbe2LlVzNxmOoTUvK/KxY0aC4sJdi3xIF5vKQ4bZ91K4gkWbBZ1CUsP6XH9Ob+oxZyKIYfe7iv0100N1Ws0KdLxkfixJAKKJbuFEXm48nvWjB9Qfwg/r0chutb8TE7n0P8HAllyxXOmLk+DHJo69dG8Nz91ECbXTNVdq8TncRi/Ud8VlinDJ30n3vSuChx+Ct2GYfy2g7mjC+w== 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=c7xQ7coTmXR1ejOtu/2zz56yYo0Rs9naSy458p5QBjU=; b=P/Byc2XoiAkmd5a94bdNpuAqksI1bTlakXWoBxe5Yuizb0e5FyTYVyAWawjMzcQmE4auy+IDB+ZhOuUNwvaxztuY+Orrxoe4NCo/ZF+2X0mo2m713qSBI+1xIc0zOaq7az/aB2PXWhQMo8PT5re3XUmkkgj6n2Hc8LZGiVMX2MTMyxvw6RwklwCWpIoBIwO4HM/+yDNACsK2FH2zOB21WkLlmZ1yAHNIGb/o8NbMW8PFZAQCwBS6yxBoQegK7A/oZpS7CPN/0HRraG7bH4y6X67IyStHsnpABGYlYlg0sR8sXoXY2tuHjnkuhQfpJ6nZ//meCgN8yeJLWkIpVLGIUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=c7xQ7coTmXR1ejOtu/2zz56yYo0Rs9naSy458p5QBjU=; b=Y40rHM0ayuxmsyhoe3Cw+pyW7aV0KOW3rX0Xz+my7stDsqLsn5Kcq/nb0Bc2UIGHhyzj9OJImYyDjiTWxFFmQEYgY+ErM3yF3x0mK+TWcAhEjejtp/IIBvYFs4tsh1LR0dzOcUtb9vMVaM1+Y+OgB4WMeSdezqAtWW6GCSF2WRXr20vZ8+UiD1Rpd/wVILUAmbjhnv+XBwAM2KtljZHIBCvOPSfM4ThymnIVbWC7IaFmARWX414m2qd8wlTw3o74jM62dxkr2FvG1mM+6/jqfZkpyR4uzGfe+TRKCVlIzfaA6/5Q9ONLot3q1nueG7GMH9XlZW4IWmkp8cpv6d7Dhw== Received: from BN6PR1401CA0023.namprd14.prod.outlook.com (2603:10b6:405:4b::33) by BN8PR12MB3537.namprd12.prod.outlook.com (2603:10b6:408:6d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Mon, 31 Jan 2022 05:17:59 +0000 Received: from BN8NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:405:4b:cafe::2f) by BN6PR1401CA0023.outlook.office365.com (2603:10b6:405:4b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.18 via Frontend Transport; Mon, 31 Jan 2022 05:17:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT033.mail.protection.outlook.com (10.13.177.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Mon, 31 Jan 2022 05:17:59 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 31 Jan 2022 05:17:54 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Sun, 30 Jan 2022 21:17:54 -0800 Received: from sandstorm.attlocal.net (10.127.8.9) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Sun, 30 Jan 2022 21:17:54 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: Jan Kara , Claudio Imbrenda , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , LKML , , John Hubbard Subject: [PATCH 2/4] mm/gup: clean up follow_pfn_pte() slightly Date: Sun, 30 Jan 2022 21:17:50 -0800 Message-ID: <20220131051752.447699-3-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220131051752.447699-1-jhubbard@nvidia.com> References: <20220131051752.447699-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41b0f511-fe5a-4557-0024-08d9e4790c1b X-MS-TrafficTypeDiagnostic: BN8PR12MB3537:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1RBG7HNrhcYeEjPxUMsFwTImecF/ZMl603mDrx0F2PkNkAiBbX5A0E1DgtAFykPXQM370bvgzHD+n1vS5OoriONkonlmnp7pqBu9zsohe2t5Gz7BMTBQuGgp7BmVdMpe24gvpQEqJpYyu+QJx8ksB/xnedcgFl1WvJxC3rGxCAcWV5LSgb9ZVHli85van0dTfCa2OZfeQgfILZBYSbfQWyIyZyG9NC8lztOEeeonHY+X1qt9s5Y/MAjwRiYNXIO7lM5800qPVevP2xnbNnW18eo7efVJzESHWTvYmkw1sERPjkG/eC1XWnFS4x9+JVp8V0ma9dybR3mojUR8lmoTU3DnlSPuMN9bRcj+GPMAVAP3H9vApOIq+YXUQoi0GeUHhrQ2aA2YRW/24gn08AZs8DTgXygVfOxastqIW4sQ8b7D544SQtM2Z8gIIoys9Ak/sYOPIxjSeKsfirY02pTxhu1ZJHbYp+kBHjBZunHAxGy5KX1mVNtg59oS426KcKuLULTHzKrUWcceWaYuc9CbBwsFP2ijX/nLCBgIEjImXwz9MIJ5npNLCJfgutTWLtwtBw/DthGip3msLDpl0BzLju9U1hClmnRL2JnBKT6uykVqIywe0dpkmI1Md6LFwKowuCGHCGjhFcep/zqJQmND9ih4I97VWLa/7J7N9vXQeb4zmdlXTWPt0IeNdWW3tddhBqZXHEgHCQT3jLX7csNbdA== X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(7416002)(5660300002)(1076003)(186003)(26005)(83380400001)(336012)(36860700001)(82310400004)(2616005)(2906002)(107886003)(426003)(47076005)(86362001)(316002)(40460700003)(110136005)(54906003)(508600001)(4326008)(356005)(6666004)(36756003)(70586007)(70206006)(81166007)(8936002)(8676002)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2022 05:17:59.3189 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41b0f511-fe5a-4557-0024-08d9e4790c1b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3537 X-Stat-Signature: kah8hedrssxf6zb7c9gbc8qxqw8zcazn X-Rspam-User: nil Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Y40rHM0a; spf=none (imf09.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.102.68) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 95008140002 X-HE-Tag: 1643606282-96254 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: Regardless of any FOLL_* flags, get_user_pages() and its variants should handle PFN-only entries by stopping early, if the caller expected **pages to be filled in. This makes for a more reliable API, as compared to the previous approach of skipping over such entries (and thus leaving them silently unwritten). Cc: Peter Xu Suggested-by: Jason Gunthorpe Signed-off-by: John Hubbard Reviewed-by: Jason Gunthorpe --- mm/gup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 65575ae3602f..8633bca12eab 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -439,10 +439,6 @@ static struct page *no_page_table(struct vm_area_struct *vma, static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, unsigned int flags) { - /* No page to get reference */ - if (flags & (FOLL_GET | FOLL_PIN)) - return -EFAULT; - if (flags & FOLL_TOUCH) { pte_t entry = *pte; @@ -1180,8 +1176,14 @@ static long __get_user_pages(struct mm_struct *mm, } else if (PTR_ERR(page) == -EEXIST) { /* * Proper page table entry exists, but no corresponding - * struct page. + * struct page. If the caller expects **pages to be + * filled in, bail out now, because that can't be done + * for this page. */ + if (pages) { + page = ERR_PTR(-EFAULT); + goto out; + } goto next_page; } else if (IS_ERR(page)) { ret = PTR_ERR(page); From patchwork Mon Jan 31 05:17:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12730420 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 A0BC8C433F5 for ; Mon, 31 Jan 2022 05:18:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB4E76B0089; Mon, 31 Jan 2022 00:17:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEEBD6B008A; Mon, 31 Jan 2022 00:17:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A19AC6B008C; Mon, 31 Jan 2022 00:17:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 9246B6B0089 for ; Mon, 31 Jan 2022 00:17:59 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 48445182221F3 for ; Mon, 31 Jan 2022 05:17:59 +0000 (UTC) X-FDA: 79089425478.23.C9095ED Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2069.outbound.protection.outlook.com [40.107.93.69]) by imf14.hostedemail.com (Postfix) with ESMTP id D061A100005 for ; Mon, 31 Jan 2022 05:17:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fhuMiGMpcpiWqpdUMIAo++6/E+e5PxTkyVzDuhSHXzVGAn+H5ZNSv/ZY0e+OBDAOPTXLjdjFd2W0r5N61IzupJ2OTkfZeV7r81c/s7+bjmsWNoewTiuNosE40bXrTMfn4g89kX8HfSFu0GxDPBlQa7Ma66DpG4IC6/h2XInuLsVpyjpsgp1RJVBtaLgqD+vb6eviB2HKlj/14SyJifzv/QpWVLRoZLBJVjdPrVoP4RoQlJiDnVflxFHbrht3EpieSmOb3POUEjJK0s9v6W+14kD1PzW0XmKg6cFoYCJl7wSYjd5gCB+UC3fQxQpfJ7OGPUxip8BkOAftLBSMc+GhBg== 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=1Bva+42+DrgUu9Uyzfxq4atkGyvBDi9x3N5e1IWPCg8=; b=aALaoV4MywgPkHu7/eJwfhjYjMmXRRck1IabIyFovnOSzIEOIhTsopnBImEtGgwHJKft9LSv/EtFqf0lmY3EB3cz9jtaTd/zSFm0vcRkdXKnvpWmokISsllojZMH8zlZpYvkndg1d6NGi0bcsVR+1o/M28TLR9Gb45TtdsI1EFVI2qt1j9QMDcoyafzImkGfQYpL93B/QjiTt8SlZUbZD/L7H5++r37AFmc6pjZna7OhReI2+tmy/BpY60m6jtn07HFBbyLTkEVDq1TbHZ0eoqAZMjKJwmFMkeRyp4agmEJQwfGYMhtqZBUPwqPY0yYGwNbLJTTN0hLzcysvMR/sPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=1Bva+42+DrgUu9Uyzfxq4atkGyvBDi9x3N5e1IWPCg8=; b=oy1U0pRAwcVzcsxBVuzvFFtgJuv5l9OuF4sEg1cl56abeNSVlwYgswPDoRTUAiqqTNxDaY5SSIjRfhOJdjAOIjLaX7ADR8WVg5sDBm4UJyCUBAhHKmN8XJEdPbaKLavl70bqLjm+Zg9GR4h2vSKz8n7fa5KEinT1O8rzsdWxwG0aUr9WulGz97pQ4TcCwNKeazAfSJmaID6HZURtnX69+PpVNnNYfqZ00ekxL2Vdnwo6cUBmQrv78cstU0gHLsGHw0gUQnoFRfPNIZcaP7YWe8PWNzUT+uE+zCuDyiz+T21ZHmMVFrD0BClItfHrQDlXXJvBo8ounudIZcwLLlh8rA== Received: from BN0PR04CA0141.namprd04.prod.outlook.com (2603:10b6:408:ed::26) by DM6PR12MB3499.namprd12.prod.outlook.com (2603:10b6:5:11e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.19; Mon, 31 Jan 2022 05:17:56 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ed:cafe::1) by BN0PR04CA0141.outlook.office365.com (2603:10b6:408:ed::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Mon, 31 Jan 2022 05:17:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Mon, 31 Jan 2022 05:17:56 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 31 Jan 2022 05:17:55 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Sun, 30 Jan 2022 21:17:54 -0800 Received: from sandstorm.attlocal.net (10.127.8.9) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Sun, 30 Jan 2022 21:17:54 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: Jan Kara , Claudio Imbrenda , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , LKML , , John Hubbard Subject: [PATCH 3/4] mm/gup: remove unused pin_user_pages_locked() Date: Sun, 30 Jan 2022 21:17:51 -0800 Message-ID: <20220131051752.447699-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220131051752.447699-1-jhubbard@nvidia.com> References: <20220131051752.447699-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2ad92a4d-b3fd-4aba-beb2-08d9e4790a26 X-MS-TrafficTypeDiagnostic: DM6PR12MB3499:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kDnoVvv9r0CbU3sNsSjeZIVQfi7BEGkDBDukLpghIiZuY3OEIVuyEQSe6M9SrJpI5U3E78YCOfvG0LkD4w0upDlzSKUsebrQiUn7Av/uzI2URRCXW3y2EIZQxosVVDNL2pXmfKuHW28ofcD44vX67+tRAyBcIXE9IJDC+55LlF1glkVVkXdB4gFuREwiHla+g/SA00BWePpKF9C79aUk9ODyX6e1/tIVnU5CMOiV2Qn6Gs+xMikZaRJg/Q4+yY13l3ks8ij4+TZDAzhVEUaWigyX4ms1Oy9PyL5plKS4bJQRiYnd50tKzTcB3SKVQbCmEySW/iMKmtQUK3FHdzjws3/IFmyfi0LWj7Fb3d9c4PDfkQlLkEzMTwOAzjPCv0LJR1adFR3pmUp62+lBQP0amuOeBWAAsRhM5byWo07N0XZWkcCLkrpsWD1CVPmqNnzCADKI+BKMXAmIF23VAd7NmYs1272kSULV54a5GEuDB/sUFBd5SDJNCzyqoA09iCDcQcEDmWpBemA4zNjN84p7zRMx5N1tlwFxRwPENUoE7k/lECHw06Hfoo9MJWjv2Vv/i5Xda/Ukrr3UFqdBYcwk+R21PPq2oEuWZcHEmWXyerRjLaS2yEBSlOalm9htyRcx23AW+QHBTPAT1a1AILjzwpWcixSrBDxQ0vwsPsr8NIa5g/hhOH6BLwtO6POIxI/9QiEtbYz1qZBySeui6lc4cg== X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(356005)(2906002)(86362001)(107886003)(54906003)(110136005)(6666004)(81166007)(2616005)(83380400001)(36756003)(40460700003)(4326008)(8676002)(5660300002)(70206006)(70586007)(426003)(336012)(508600001)(26005)(186003)(1076003)(8936002)(7416002)(47076005)(36860700001)(82310400004)(316002)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2022 05:17:56.0404 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ad92a4d-b3fd-4aba-beb2-08d9e4790a26 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3499 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D061A100005 X-Stat-Signature: wdea4mjk5hpn5h5hd9za7hjoz46wqcjt X-Rspam-User: nil Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=oy1U0pRA; spf=none (imf14.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.93.69) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-HE-Tag: 1643606278-946961 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: This routine was used for a short while, but then the calling code was refactored and the only caller was removed. Signed-off-by: John Hubbard Reviewed-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- include/linux/mm.h | 2 -- mm/gup.c | 29 ----------------------------- 2 files changed, 31 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 213cc569b192..80c540c17d83 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1918,8 +1918,6 @@ long pin_user_pages(unsigned long start, unsigned long nr_pages, struct vm_area_struct **vmas); long get_user_pages_locked(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, int *locked); -long pin_user_pages_locked(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, int *locked); long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, struct page **pages, unsigned int gup_flags); long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, diff --git a/mm/gup.c b/mm/gup.c index 8633bca12eab..58d01a96ab30 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3120,32 +3120,3 @@ long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, return get_user_pages_unlocked(start, nr_pages, pages, gup_flags); } EXPORT_SYMBOL(pin_user_pages_unlocked); - -/* - * pin_user_pages_locked() is the FOLL_PIN variant of get_user_pages_locked(). - * Behavior is the same, except that this one sets FOLL_PIN and rejects - * FOLL_GET. - */ -long pin_user_pages_locked(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - int *locked) -{ - /* - * FIXME: Current FOLL_LONGTERM behavior is incompatible with - * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on - * vmas. As there are no users of this flag in this call we simply - * disallow this option for now. - */ - if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM)) - return -EINVAL; - - /* FOLL_GET and FOLL_PIN are mutually exclusive. */ - if (WARN_ON_ONCE(gup_flags & FOLL_GET)) - return -EINVAL; - - gup_flags |= FOLL_PIN; - return __get_user_pages_locked(current->mm, start, nr_pages, - pages, NULL, locked, - gup_flags | FOLL_TOUCH); -} -EXPORT_SYMBOL(pin_user_pages_locked); From patchwork Mon Jan 31 05:17:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12730421 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 AF555C433F5 for ; Mon, 31 Jan 2022 05:18:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0436B0092; Mon, 31 Jan 2022 00:18:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29F736B0093; Mon, 31 Jan 2022 00:18:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F3EB6B0095; Mon, 31 Jan 2022 00:18:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay029.a.hostedemail.com [64.99.140.29]) by kanga.kvack.org (Postfix) with ESMTP id 0069B6B0092 for ; Mon, 31 Jan 2022 00:18:02 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 92508C5E for ; Mon, 31 Jan 2022 05:18:02 +0000 (UTC) X-FDA: 79089425604.03.283AAF1 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2067.outbound.protection.outlook.com [40.107.220.67]) by imf16.hostedemail.com (Postfix) with ESMTP id 054FA180003 for ; Mon, 31 Jan 2022 05:18:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YiGqts87PS8Kn5xxihaXGCVJqpUcapPrjW+Y/caV7pCoZk5xsvfXyMLcMITVna4BQunIO4LCYqByqv3PNDzxuFx0LL8V7xK6ofjahxHZvbuKTPpLAkLKqAgFzDEdIY0lHG5Jfgs7AK/cpc8HrR3jZsbskhSwes2zASuPT5wllciZzagLNlUh7Ea4FX8PQ7+77aLESX7lBvXYiYBFN0eMuIFn8CQYVsAU4QCkZ6WT9CZJ/sBwgoZtHMNuNyQcigktY7GOiS11rqPiHk9YziAVXtNrSjtmLSDVLq+19ARYFxwNXO+CPgJGeNraWApC+PTa2yF9MpPEjuXkbPAGuEiltQ== 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=9Kk9+4kEkcKxj6kf0o9k3q2cGrwV89GKLhSq1i0xxEE=; b=EbVs3wrP8oAnIRoDZwwGosmhcZvFctKf+UblTf/YnskZSAZf6/GBY319N7BWKI3M0AGp2DnNnqb4bG9Lm0zQvir6WHRIHOXdCmAl0toVUAytQeU9+tGZskV85uCfLpLsqLQ3mizgalXkuRbVbXCL3+GOV4sU0Qew13SJB/Mg4o9bc/sVdqPe26XQVCjRYC8RA1JBBdtRbhFqdCOjPtG1SGhphItqHnKZemyE2tTwN0a+0ZAfJ9GsJNO9OSG49MHr0KamCmv8S+vp4irhZVjTNF/u4yW0Z+YUJoXDD9ptlLSsr5HXqUfEWIGNy1LY3GHW4Q0IIsBGhBoEuXqshldMUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=9Kk9+4kEkcKxj6kf0o9k3q2cGrwV89GKLhSq1i0xxEE=; b=J+1oh2cyjLJJhtsNXxotlz2zs6bClB2LmqktcgAZat1TB1nQ69EEbziXTuyXpJQj1gyVV4hNFEJst/ZzV3Glc7+S/GHFPSWmZW0ug+Nbee4IDah7Y3z/c4HopW+USy5i36j0Vo/4p7qv6WW7A3I9JjLSjxi53ex/we2SXG0J00/esi5FiJ2BN+T2BPiXfEndFn1IcfHmg/+F1XwbAmvACqqZD8crOcehifYla8CtT3suIh1L0rLnrmA6cpq9DIUDu+FDoL0mB/7o5r29BZgfwiaG+v6wONXtrpcNL+rU55tep4UeAfDBUWOWK96TY4Mqbi5ZF/zCfDpvTZonhkxTpg== Received: from BN9PR03CA0570.namprd03.prod.outlook.com (2603:10b6:408:138::35) by BY5PR12MB3698.namprd12.prod.outlook.com (2603:10b6:a03:194::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Mon, 31 Jan 2022 05:17:57 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:408:138:cafe::2c) by BN9PR03CA0570.outlook.office365.com (2603:10b6:408:138::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17 via Frontend Transport; Mon, 31 Jan 2022 05:17:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT046.mail.protection.outlook.com (10.13.177.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Mon, 31 Jan 2022 05:17:56 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 31 Jan 2022 05:17:55 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Sun, 30 Jan 2022 21:17:54 -0800 Received: from sandstorm.attlocal.net (10.127.8.9) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Sun, 30 Jan 2022 21:17:54 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: Jan Kara , Claudio Imbrenda , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , LKML , , John Hubbard Subject: [PATCH 4/4] mm/gup: remove get_user_pages_locked() Date: Sun, 30 Jan 2022 21:17:52 -0800 Message-ID: <20220131051752.447699-5-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220131051752.447699-1-jhubbard@nvidia.com> References: <20220131051752.447699-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 058af1f6-fcc0-49da-1c64-08d9e4790a60 X-MS-TrafficTypeDiagnostic: BY5PR12MB3698:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Htr9nMywcMjGFOxARl6uVx0g9YyQHdCQBV0CmdDV0l2aEEQq0P8THGdHNJ42D1oTYXB9ixPVhyAdQ11pt7qtQHbok9oTz/lzPz0QNUWFgyVaBsfpiBJUvvYk8aVBJD+9Sm4pcTjbHBbyQioJc3WkQfU6TfCVWoZ7t+sUjiOwDmIcF3Ua4Z7i5VqlEyglD8uyfmFUDlSGGwxfXlBNei3I5iMzNJb3FypwnnnHF47HHE4UYse9ulYaKCABZAJri7fqrigYA4AaigMeOoFiEJyzp2Zoqhvz5ZaKh8tr/6whGqB3AKugbR9M7P2CDDu/Ah93+GGw75LS7DSQi78igwt/Tcg0YMfgacuMS6J0VBhNL4tC+nbtxUYyUxGLn0pWqluUgvsWiDHkzxmyzLxi4LQ5BJ88Kr/U2BnTvA7QSAtSlgVcKKKSMv4i5bogaoXGJmIDT2AOPKSfMK+4Jm2b54o5SrruyRnwFSKxmyGQjf0qJt3kOGbfCRZ/vEFUoF3AInt1V+j17FD+2dDG5+9xG2dQ0ckVNoxUQKCtHDp+ksq0ZqSaDmQ1GWHzkFmxLdnC8ZPV9O+kJTF6QbdkgQ7quxWbBuwxUcNWfgWYdgaRZaOK296Cp3Q/eJ8CH/u+rlQ+dQa3qGQELr/nGQnjhyktZdZO3/1MZ2cAxxnA7e/ExgAPwycfA604359CfL9nCtMk4y4Ecve5FvKP02xKxNLyh9WkMw== X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(8936002)(8676002)(2906002)(508600001)(356005)(81166007)(316002)(54906003)(110136005)(4326008)(426003)(1076003)(336012)(107886003)(186003)(2616005)(86362001)(26005)(7416002)(47076005)(5660300002)(36756003)(70586007)(70206006)(83380400001)(40460700003)(82310400004)(36860700001)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2022 05:17:56.4163 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 058af1f6-fcc0-49da-1c64-08d9e4790a60 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3698 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 054FA180003 X-Stat-Signature: ph71ohyjd139a79ppbtdd6si9ouraohb X-Rspam-User: nil Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=J+1oh2cy; spf=none (imf16.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.220.67) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-HE-Tag: 1643606281-820188 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: Unraveling the rat's nest set of APIs in mm/gup.c a bit more. get_user_pages_locked() was not helping at all, so remove it. Also, lookup_node() has only a single caller, but it is still worth having a clearer locking policy there. Changing it so that the caller both takes and releases the mmap_lock, thus leaving lookup_node() with the sole job of translating a virtual address into a numa node ID. Signed-off-by: John Hubbard --- include/linux/mm.h | 2 -- mm/gup.c | 59 ---------------------------------------------- mm/mempolicy.c | 22 ++++++++--------- 3 files changed, 10 insertions(+), 73 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 80c540c17d83..528ef1cb4f3a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1916,8 +1916,6 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, long pin_user_pages(unsigned long start, unsigned long nr_pages, unsigned int gup_flags, struct page **pages, struct vm_area_struct **vmas); -long get_user_pages_locked(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, int *locked); long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages, struct page **pages, unsigned int gup_flags); long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages, diff --git a/mm/gup.c b/mm/gup.c index 58d01a96ab30..4a43c79f0972 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2119,65 +2119,6 @@ long get_user_pages(unsigned long start, unsigned long nr_pages, } EXPORT_SYMBOL(get_user_pages); -/** - * get_user_pages_locked() - variant of get_user_pages() - * - * @start: starting user address - * @nr_pages: number of pages from start to pin - * @gup_flags: flags modifying lookup behaviour - * @pages: array that receives pointers to the pages pinned. - * Should be at least nr_pages long. Or NULL, if caller - * only intends to ensure the pages are faulted in. - * @locked: pointer to lock flag indicating whether lock is held and - * subsequently whether VM_FAULT_RETRY functionality can be - * utilised. Lock must initially be held. - * - * It is suitable to replace the form: - * - * mmap_read_lock(mm); - * do_something() - * get_user_pages(mm, ..., pages, NULL); - * mmap_read_unlock(mm); - * - * to: - * - * int locked = 1; - * mmap_read_lock(mm); - * do_something() - * get_user_pages_locked(mm, ..., pages, &locked); - * if (locked) - * mmap_read_unlock(mm); - * - * We can leverage the VM_FAULT_RETRY functionality in the page fault - * paths better by using either get_user_pages_locked() or - * get_user_pages_unlocked(). - * - */ -long get_user_pages_locked(unsigned long start, unsigned long nr_pages, - unsigned int gup_flags, struct page **pages, - int *locked) -{ - /* - * FIXME: Current FOLL_LONGTERM behavior is incompatible with - * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on - * vmas. As there are no users of this flag in this call we simply - * disallow this option for now. - */ - if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM)) - return -EINVAL; - /* - * FOLL_PIN must only be set internally by the pin_user_pages*() APIs, - * never directly by the caller, so enforce that: - */ - if (WARN_ON_ONCE(gup_flags & FOLL_PIN)) - return -EINVAL; - - return __get_user_pages_locked(current->mm, start, nr_pages, - pages, NULL, locked, - gup_flags | FOLL_TOUCH); -} -EXPORT_SYMBOL(get_user_pages_locked); - /* * get_user_pages_unlocked() is suitable to replace the form: * diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 028e8dd82b44..040d88354cfa 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -907,17 +907,15 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes) static int lookup_node(struct mm_struct *mm, unsigned long addr) { struct page *p = NULL; - int err; + int ret; - int locked = 1; - err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked); - if (err > 0) { - err = page_to_nid(p); + mmap_assert_locked(mm); + ret = get_user_pages(addr & PAGE_MASK, 1, 0, &p, NULL); + if (ret > 0) { + ret = page_to_nid(p); put_page(p); } - if (locked) - mmap_read_unlock(mm); - return err; + return ret; } /* Retrieve NUMA policy */ @@ -968,15 +966,15 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, if (flags & MPOL_F_NODE) { if (flags & MPOL_F_ADDR) { /* - * Take a refcount on the mpol, lookup_node() - * will drop the mmap_lock, so after calling - * lookup_node() only "pol" remains valid, "vma" - * is stale. + * Take a refcount on the mpol, because we are about to + * drop the mmap_lock, after which only "pol" remains + * valid, "vma" is stale. */ pol_refcount = pol; vma = NULL; mpol_get(pol); err = lookup_node(mm, addr); + mmap_read_unlock(mm); if (err < 0) goto out; *policy = err;