From patchwork Tue Feb 1 10:11:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12731508 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 4CA13C4332F for ; Tue, 1 Feb 2022 10:11:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEBEA6B0184; Tue, 1 Feb 2022 05:11:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D9C1A6B0185; Tue, 1 Feb 2022 05:11:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3C4D6B0186; Tue, 1 Feb 2022 05:11:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id B57046B0184 for ; Tue, 1 Feb 2022 05:11:18 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 77999972F5 for ; Tue, 1 Feb 2022 10:11:18 +0000 (UTC) X-FDA: 79093793436.05.8240367 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2047.outbound.protection.outlook.com [40.107.220.47]) by imf06.hostedemail.com (Postfix) with ESMTP id 5E976180005 for ; Tue, 1 Feb 2022 10:11:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OahcomE6jhL9fbEQ3QRtJxiMBaTGaraJyw2EZQ3eC703yAjjN6nQrZNjO001iQBL1d7BYmNA3uCS8Dgr3ZmyxvH/eRHBSWXNb0pQQTXs5gXb1YJmlw10g/PtPAfcGFBDMC5y9qUYrWpbGmEAngRcL7iZIU2lhFaMnk2B32j72tDX2VFQ9HiHS31VTh0ihlfj/LzoP802Ep+celFp5KxIs2O+5TB1Kmfv3tuyewQu20MraWMYE75GYS1wRC8yUgcwkU4hu7Ov2WVbVsM99ALnGE+avKsUFzRcS3d4tHuvxdvI58PKQY1HMpGWIYwYV8WdLrpCMqdMXEvjWnL9dpyhEg== 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=kyMU6TmMl5wkPP3kDvsxlk2/mNsd6Nh//tpGH/3US8s=; b=Jw7DhTbHHPLEoRzc0qzHZqVoHbJ40WgW4hk2q1yxeutd5rS2d2HSpxbkSDZk6tmSf8BW5zX7h85a7EJXB4PpcwlyKRdMNzgs4nf8pe5rmwfegE/czc8VBdTZUz+PaTw5k7vR4zj2cC6lGR2jpXdcvKXI6XIdhJhSO9LPGZuz2Ppd+BtBAn+95vRaTxUk/PGRBLRouMRadZGpoHEUEYZKoXCbnT3mcblly3cJmvxe1dGNRmCzVHClVeLWPR47YPX1D4pR+JPxP4/XmXZJIg9SvweN/8VLQSDy2o4y64mn6dXaYHNsz+uQs100/8f6uibXheuPM6dd3JycMtL6CuT6Lw== 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=kyMU6TmMl5wkPP3kDvsxlk2/mNsd6Nh//tpGH/3US8s=; b=plccGIfPQRa+v2hy6IQh1Oe+PnNCINzKql1DTJoZRYeWfkRYdHtZj26AQP+8GaNswJEsjEGM1LpdeLA7xQMd3sXmNYvy7nK4FKau5NIyxmAQpPYDyR+cWBv6cTyYYNpxfrxuOJm3VKfH3vDlmD5fTjdajL5QcjARp8IviuKSOFLHXGSTAxnzayda41cdeA33LAxwd6W//F0QbHQ8+A4fQBjeKkF9l52wPMyEQPkEYAzH90D0uQfs6Hp3PHrR19K5JR74Yx8oNP/f4nLlvy7uwfq2a9zL2DKZDvczrV5z/aWQxdMp0NStO9AjugR+LzXi8IBXNyS5J1MbPBfqlhpQkQ== Received: from MW4PR04CA0312.namprd04.prod.outlook.com (2603:10b6:303:82::17) by DM5PR12MB1803.namprd12.prod.outlook.com (2603:10b6:3:10d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21; Tue, 1 Feb 2022 10:11:13 +0000 Received: from CO1NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:303:82:cafe::21) by MW4PR04CA0312.outlook.office365.com (2603:10b6:303:82::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 10:11:13 +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 CO1NAM11FT052.mail.protection.outlook.com (10.13.174.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 10:11:13 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 1 Feb 2022 10:11:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Tue, 1 Feb 2022 02:11:10 -0800 Received: from sandstorm.attlocal.net (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Tue, 1 Feb 2022 02:11:10 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: David Hildenbrand , Jan Kara , "Claudio Imbrenda" , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , LKML , , John Hubbard Subject: [PATCH v2 1/4] mm: Fix invalid page pointer returned with FOLL_PIN gups Date: Tue, 1 Feb 2022 02:11:05 -0800 Message-ID: <20220201101108.306062-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220201101108.306062-1-jhubbard@nvidia.com> References: <20220201101108.306062-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a8a7d000-7709-425d-5290-08d9e56b2d25 X-MS-TrafficTypeDiagnostic: DM5PR12MB1803: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: /QbbfltBK0JFcjnciCnUmsT3OFeRAmP3ozB8AetX8iEVI4K7qUfMZaTcRRDuUS7Pyq6NsVkKIfDuY3o+eL7KQy18q80lH8gLmyuiCp8lO9vFB9cZQHg4q6UDkmd28CSiJvQL56JWqwsWTI9im0OlQYandOcXQh2EUdG0JM0hqcMpn+MqqHgKkEni2ymRofXG7F2cdrzm1n5BPffz6jcSXzNo9cj1ZFsJiQYOBTZSE1zvBr5s1rqOIYllseAGP96Uqg3GeFN8iFEznTqZBWoiUZ8bH4hdeI2eGlVA0VLqc2dlixi5xdDSa31jX7VSYmKrn3U3TmZBAFcxeA2bw4HHs3ZtQSvZgpJx0YyZUjOG59ANm+/55AI92s+5gFTg2k71u2ULzqWwTUaujrOqYb5UnhiWmp4fcRihWrQKn6OqhwOyYAIyBVzxYUmOJC3HYfhFocESnzg8PnGqm/teTQ9EQBwfIXWdLYkwQHEMEYalb6GgoUUC8jahaMPMgfmU8PTOPXZLzJoqc15wUUnlQqMCmTdN9PnW+X1Pio9ebYSNWu5XER9BuUv6Hu2cRFEggYhB9iaNK4b5A5uIuDB3hC4sO5Sd6cPIsWZ3DxDGaothzx1jV3u6r8wGsVdmkjgBdIQEgn6QuBWixtEatJe/idfpbtDf535LZRwVXSpm7z3VqtmfxRmmzVN2mBaw3hzFoDl3Q0ok/F9eKop8fuYRNm2SZA== 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)(40470700004)(36840700001)(4326008)(54906003)(83380400001)(426003)(2616005)(82310400004)(110136005)(2906002)(186003)(1076003)(26005)(336012)(316002)(8676002)(107886003)(8936002)(5660300002)(36860700001)(40460700003)(6666004)(36756003)(7416002)(508600001)(86362001)(81166007)(70206006)(356005)(70586007)(47076005)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 10:11:13.0067 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8a7d000-7709-425d-5290-08d9e56b2d25 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: CO1NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1803 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5E976180005 X-Stat-Signature: 1kzx83xuujpsgxxwe5d1s8yfs3qcxha9 X-Rspam-User: nil Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=plccGIfP; spf=none (imf06.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.220.47) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-HE-Tag: 1643710275-356674 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: 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 Signed-off-by: John Hubbard --- 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 Tue Feb 1 10:11:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12731509 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 1FC88C433EF for ; Tue, 1 Feb 2022 10:11:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B06866B0185; Tue, 1 Feb 2022 05:11:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB5206B0186; Tue, 1 Feb 2022 05:11:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 956786B0187; Tue, 1 Feb 2022 05:11:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 8816E6B0185 for ; Tue, 1 Feb 2022 05:11:24 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4A5DE8297CDC for ; Tue, 1 Feb 2022 10:11:24 +0000 (UTC) X-FDA: 79093793688.22.537D31F Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2063.outbound.protection.outlook.com [40.107.212.63]) by imf04.hostedemail.com (Postfix) with ESMTP id 9C9B040006 for ; Tue, 1 Feb 2022 10:11:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gGvDE4pprtXXtnvG5HtB5fg7s5V8Yp/AOEOwUgNgh6MPRwboLKbzolZSppyOniedocMG8kSz8tjtjx20pPYilSo94Vaxleptx30BSOZNuvB4rPkHHTRCpg4yVHftz1o7APBZn7BvAK0WjC/nuAlR6ek2zQyqF/Cm6WzVlvabZbEDTiYemVoRV+8o4HW/3hnGymrNGSg0YAZGKjSbSCHyIGq4zhUitMEBCBgJXxxexFLp1rNo82e2/4bcs8C9JwG+NvCm3WRW1BcLF04QNQ9ul/1l4yvwVffhBnoo2F7Kb1Nj+dHKy3XKnP/KpKwJFtSDgOI5iprU8U0wczStypM5ow== 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=ImU9JElfSTWSoTAyJBE5pMoIuGpDo/2NrB8B1A9HU6A=; b=MrJgt4zH06DhtFJvfFusNrai7bp3Q3dI555Cwsx+FJua3e9ZyynvaVfLKPUVaZGBUnh+ytQpigBTXoMEX5Uq38WBmxQW/5JNlwEDmRkxw9KuuJcr7WFmysv8xDhj6D72nCuqN2NIL2w5bkfSbXD1efgaB5gxDJ0dxar8alVhIXK2MpGCcDLfhkpAjDGhiTkLUhPhdjm4gvg2r1nNl16oB81D+HSotL4bVix7BBxw6LDxI7hUn5RqKt1FV9uV3FdCyyrXNk/t6R1IAM3s9KIl/MARQsFo8l71L/zudrAWHx7CwZo/q4XHeXoMCd9a56T0yEK1YRyJjPJEsRWYsRS/2w== 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=ImU9JElfSTWSoTAyJBE5pMoIuGpDo/2NrB8B1A9HU6A=; b=gdATogZbpHduYjNjUpe4nHgQc27DwfflDV1I/AADet0kpB/Ax5gJ/tiRlfXtCO9agQxnBQtmcmz5wNJkoZa9fUKhSlKkQweZ8eyZl2vwEaT7cNxAqfQdLEtOrpGKyLCBtHktuw36sow0Vc7JIc60UAo6n6czVbR6Be9Iu63i4sd2r6FtU3WGavmCys5WF5OVeiKsZgWJVXsPwHAaKKMcMcSclm4khp+iPWjYQxwit1mrHEadAeXAY7HzXiKU6Q/XQpvfEWzK6Sn4xrb95PRisWWm+an+MeaUIAA1QvmfRMfqxRAfxKZfd00hNnST79m0gJX2vpakZRO1QuAUFD4kYg== Received: from DM5PR07CA0150.namprd07.prod.outlook.com (2603:10b6:3:ee::16) by PH0PR12MB5465.namprd12.prod.outlook.com (2603:10b6:510:ec::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Tue, 1 Feb 2022 10:11:20 +0000 Received: from DM6NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ee:cafe::d0) by DM5PR07CA0150.outlook.office365.com (2603:10b6:3:ee::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.22 via Frontend Transport; Tue, 1 Feb 2022 10:11:19 +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 DM6NAM11FT041.mail.protection.outlook.com (10.13.172.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 10:11:19 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 1 Feb 2022 10:11:12 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Tue, 1 Feb 2022 02:11:11 -0800 Received: from sandstorm.attlocal.net (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Tue, 1 Feb 2022 02:11:11 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: David Hildenbrand , Jan Kara , "Claudio Imbrenda" , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , LKML , , John Hubbard , Jason Gunthorpe Subject: [PATCH v2 2/4] mm/gup: clean up follow_pfn_pte() slightly Date: Tue, 1 Feb 2022 02:11:06 -0800 Message-ID: <20220201101108.306062-3-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220201101108.306062-1-jhubbard@nvidia.com> References: <20220201101108.306062-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7a0d12b9-23c4-492f-4609-08d9e56b30d1 X-MS-TrafficTypeDiagnostic: PH0PR12MB5465: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: H5xyQ9AB0cFXcO1q4b9tkLRQe74Wai3d9giYgPkRiqMDJzPvQUiC6jtuBqSDMbitep8LvZXxqCcWg8FPfo1obBYK5sE+A2D49dQ4cP1glNo9qqwe1lCPgWZwzf6BHG18P275jLctq+xELk38Jm9ZdV4QmStSQWSLPv6HgEgu325iM+WDML59jqnmoEPZ7KdDeMgA+CKSHnqBKR5eY4t5WdIiy1r8PtlNMVXJFy9UFAm2wgo3dIXIVpsUC6gNQd/qnk0KFtQmuloXSgV63ovpQIKN6e3v97V8xrue2weqt2N2vv4O4xfjew0/aTav29hku6mxTUo7ZdMjw0hCPK0rnf4JNPa51kgFjD9+BQrBYW+pjQhd9/iKoLueRV1yfbvAaHzcv/3PVC458Q+P75XSOEAHpKhDk5F1AhNPlZTZb1DbzS5UzJgTkxMdouOkCzpoAcGeLHUMGnzaqcY+M3b+Fx7GI5nISZSjvIfmNS9a3ZvSlg0uPKanSN9xRHeFBGbG4Dxnb3VJlwNH8QgkxKQK9O73txPbJhO4mxhF4qJMCQQHq3Go2n5dyrOMPOw98iBJwyFD+RsLlTs3bj8tn5+kv9L58OcPlknI2WPHdk4q5QN3jUyaad+yyNhjJCtfHRoTK/gAY1YVPWLkWMeg3+iqt1WvyWWIrGsiStcDDYT9erNkUNP8ChEcHNuH+5eQpk+4uuwj1kQ0MR7OWKxiPKtoWA== 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)(46966006)(40470700004)(36840700001)(356005)(83380400001)(26005)(316002)(36756003)(110136005)(81166007)(186003)(1076003)(54906003)(7416002)(6666004)(107886003)(8936002)(5660300002)(2616005)(8676002)(2906002)(70586007)(70206006)(4326008)(47076005)(40460700003)(508600001)(336012)(426003)(36860700001)(86362001)(82310400004)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 10:11:19.1512 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a0d12b9-23c4-492f-4609-08d9e56b30d1 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: DM6NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5465 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9C9B040006 X-Stat-Signature: c16ru9kntpco6jh3zgi98iq3c5cu76d6 X-Rspam-User: nil Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=gdATogZb; spf=none (imf04.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.212.63) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-HE-Tag: 1643710283-625198 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 Reviewed-by: Jason Gunthorpe Signed-off-by: John Hubbard --- 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 Tue Feb 1 10:11:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12731506 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 D74FFC4332F for ; Tue, 1 Feb 2022 10:11:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B0C56B0182; Tue, 1 Feb 2022 05:11:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 514126B0183; Tue, 1 Feb 2022 05:11:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 389296B0184; Tue, 1 Feb 2022 05:11:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0029.hostedemail.com [216.40.44.29]) by kanga.kvack.org (Postfix) with ESMTP id 2C26A6B0182 for ; Tue, 1 Feb 2022 05:11:17 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E83F3181C98FF for ; Tue, 1 Feb 2022 10:11:16 +0000 (UTC) X-FDA: 79093793352.22.EE517F6 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2045.outbound.protection.outlook.com [40.107.236.45]) by imf02.hostedemail.com (Postfix) with ESMTP id 54AE980010 for ; Tue, 1 Feb 2022 10:11:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mVnnAb/Zcz8tdIPHy4ue5t10WGFIzSZNpJ4azCET/hZcumXAklLRwYZQqgZp+TyUm5IkyVckBMiSvLNJRpH/+2ir/ISGq6wdtX8QIt8DCLjMMyaKCtB6v4WYlHOvcdZa2GME7VpOtSx/GveCNo/S+rJZl2+lf1xs13UELrW5HfWZhmsaO0EXqD4hTe+2Xq0QCkIolEYYvHhX2lncBZux/FIrDNVQb5pUFQf3fSG0dbrInEArL8IFMI/XM5+DjrEz6DhDwj87yRzMCr3WwmpHa3oM2Wyh5jJjQ4wHp7gN4OYIObRLzRx90GXHEYSjU9MVwddxyh/RHzESG1UDi0+sdg== 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=1e7PiNZFM2eNqSK1J9SWg52wP/aW6SD39jEPyP8maQo=; b=Nfuz2UU6vJP3lG8jtxALjoYsMUah0fflGJVtLBt+4cPSLnvTp8ZbT4dN4QCTpVfpLMpqEXwaVW1MLqjT0SyxfDIJO0Vte/qvjYd181CAWBpQr1R7xkM8GUf79SerA06KEWws1VtfMx08ODKutLFWUgVpXhLqNQDfo/lR/3Y3/cz5iV4/E74RXYS7+M/zPtQ2VIgV28BBQdf7v9JDNJfELqOThaAwp7XV7ei0h0kc+GJol8Z0/9DNl6ODgq4ZiEmYoRLA+206mJfKcg+dItxQQfabZFqKwM+F5x3+0I5FppqCb0SMG5sCaQbFCU1d6XxJxdWz6+UAd+v06RDp+HDgSw== 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=1e7PiNZFM2eNqSK1J9SWg52wP/aW6SD39jEPyP8maQo=; b=YFrOdSSTRF9XIAkhTbNBdKjQRG0Ld2FdH+15gj+6oCAiuAjdj5CtQDMjdpP9sGfJxpVe4ZiT0H4Vw25Co56itseXWes3x5wwrTG5ztAz1X12Kt/7PqQZYpn+umDSQDkIGe0Kngtz34D1f22n0JQFIoXutGfyA1VOrgti0UoptKgpjvTfXEJb5/ehiccs00hs2THpX8wK1E1/2oAexCezyn8mVNDBd4I1ARVnbx5nnQQYa9fLN0FQgQzNYDu4BCc922Oooi5/ZEEr4k9ibFB/g5SRHbYdfcul118zq4EdUHy7FUeC1LBcKurZHW6Mroj8iMsGOwqTRQIIlf9ftzbvQg== Received: from BN0PR03CA0038.namprd03.prod.outlook.com (2603:10b6:408:e7::13) by DM5PR12MB1561.namprd12.prod.outlook.com (2603:10b6:4:b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Tue, 1 Feb 2022 10:11:14 +0000 Received: from BN8NAM11FT043.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::77) by BN0PR03CA0038.outlook.office365.com (2603:10b6:408:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 10:11:14 +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 BN8NAM11FT043.mail.protection.outlook.com (10.13.177.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 10:11:13 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 1 Feb 2022 10:11:12 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Tue, 1 Feb 2022 02:11:12 -0800 Received: from sandstorm.attlocal.net (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Tue, 1 Feb 2022 02:11:11 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: David Hildenbrand , Jan Kara , "Claudio Imbrenda" , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , LKML , , John Hubbard , Jason Gunthorpe Subject: [PATCH v2 3/4] mm/gup: remove unused pin_user_pages_locked() Date: Tue, 1 Feb 2022 02:11:07 -0800 Message-ID: <20220201101108.306062-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220201101108.306062-1-jhubbard@nvidia.com> References: <20220201101108.306062-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 334b0d05-58a3-4e55-feeb-08d9e56b2d8b X-MS-TrafficTypeDiagnostic: DM5PR12MB1561: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: jOaZ4K3fNRr6duDz9p8I5dHX3GmZoZoV2oFdaDy7xfrkBccTKMuk+0pxocc82j9ThPJYd77j9XoTAXyjniqLFsm+lKfb/apUJ6PZXbFG5YCT2iusuuTC2uK7hkWvJLS5t2rVw8mXcFSyXBs8N3sAQx6cJjCq4U4jbECBaR5ugPfWsjRkrxkfKRdXnokiXobMAoT5KecLPStOzMSQ9IJmvqLf226FiasfIWrJkIAZDnmwUV55dd9EwsfMpQecFMB/KsVq4SiqmLKs85x22DlSZYSSFFWvg2u5B8/CgGC1Q3PVw+3XYTXTPlU1d6Yov28i94q/eHp4+uJL+tK4+EF7Qs5LVOJ6j260xym0gyKmoYirSm2iEojU/I87u3GL9UmxArpqzTTezPVBvgwDwnImXNHxM6e1F0j83r/aYjhJJ0zciX6xKEMg3I1kBkrSgEkZiP+lXZSV31boL/qa9UMD2rpciuVVxx9bOM1vJWx/abN2rgagOaNCM3rrM7+9XU16VLLDiJqkBH+5K8ZVpkUzzz/2Tr5txPcx8Na7jDeNSYi8Z/3JWg5zgZ9dFrueToPYfO0dC5eruj/wn5EpnFvpGMGw9eUQFPby9VnHCx2C2SwRO+DCF3FUtJq3ITIMb7PvgurGk64yrfIMrXYMlrYo6OAvRX14iI1Vt0eIg4IDBbzQ//NqFQfczFczFsTdb3QrHSkbdcoOqMsZoQ01zt5e1A== 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)(46966006)(40470700004)(54906003)(508600001)(86362001)(2906002)(83380400001)(110136005)(7416002)(82310400004)(5660300002)(70586007)(70206006)(47076005)(36756003)(36860700001)(26005)(1076003)(186003)(8936002)(4326008)(8676002)(6666004)(40460700003)(336012)(2616005)(426003)(107886003)(81166007)(316002)(356005)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 10:11:13.6484 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 334b0d05-58a3-4e55-feeb-08d9e56b2d8b 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: BN8NAM11FT043.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1561 X-Rspamd-Queue-Id: 54AE980010 X-Rspam-User: nil Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=YFrOdSST; dmarc=pass (policy=reject) header.from=nvidia.com; spf=none (imf02.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.236.45) smtp.mailfrom=jhubbard@nvidia.com X-Stat-Signature: gnoajuz8yy3w4ekgfueg4we4eizk86fc X-Rspamd-Server: rspam08 X-HE-Tag: 1643710276-134801 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. Reviewed-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Signed-off-by: John Hubbard Reviewed-by: Jan Kara --- 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 Tue Feb 1 10:11:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 12731507 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 6DC62C433F5 for ; Tue, 1 Feb 2022 10:11:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB8F36B0183; Tue, 1 Feb 2022 05:11:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A69BB6B0184; Tue, 1 Feb 2022 05:11:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E0FE6B0185; Tue, 1 Feb 2022 05:11:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay033.a.hostedemail.com [64.99.140.33]) by kanga.kvack.org (Postfix) with ESMTP id 791936B0184 for ; Tue, 1 Feb 2022 05:11:17 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 2A6D160EC0 for ; Tue, 1 Feb 2022 10:11:17 +0000 (UTC) X-FDA: 79093793394.03.708556A Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2074.outbound.protection.outlook.com [40.107.243.74]) by imf08.hostedemail.com (Postfix) with ESMTP id C0BED160003 for ; Tue, 1 Feb 2022 10:11:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ioHUEBZOcK4sN4eHXwdYgm1tJZETSjinW28t6DC/RPiOhwywqMs9PNRADQmF80dRc4+5oH9ULKVdGerElGdE8qpN9BXpSglOavWa6USQF3i46qEwOi+Xc5PSyOXjia+3xU/WNNcJN/WRmnY7j8qNqdCchTD+V39F5NSSjuDOyFtI31AUg0r2GTMPswMY+6uUaHTTnxKIEOnxEd1VbNpX2oqHLooZyHhLGxmeuZ6YgTvj7pS1KMlohw7z3r474Jw8JneAPnv37eiIyONMMbzPOdMBzvRcw60BvmLVwf2nGy6HE6K3M6lNC25PVEhtrZwKl1QK+2qIY2F2slrY2jJHdw== 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=bVK+Q2hRvNDiHPDLJbuTJ8EUAlC1wW1dJUMEVYIcSr8=; b=CvLR/EUz7b1WASM/tXRFdF4ASeEcsi4kbod2wVqmKU2c0jhC8hpFhNpO2TEGshwiGhtTfgS8NJXDAr1dJbMIZS640xX2OvXG8veRYtwOSX7/fnGsFK1I9VLSW+B0pZKeClFaRMvvhuzvbIaPa7pO/ZFTjjdhTZBT3ymA+oydbATqMlN+WpCFFswxzS003rYVAu021SLoS3DxuwbeOgO9dXA/WD8NF3/OHRo0TpcmkAIbA53Yl6ypm6rlBp+69m/rWZQ1YGzkobdalJJ9xVQoS/EllNVmjW0SUGt+7u9xB8F58fStW913mVmK9/alOO1jUP8JiFMglv1Xdj92qRnyfQ== 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=bVK+Q2hRvNDiHPDLJbuTJ8EUAlC1wW1dJUMEVYIcSr8=; b=PpJBWmoGUYOLHHTSfruLUkSiPLWypRWca3OsX0WD7K2B5jGTOl7fgm3SmuKSdgfWgcuK0kIY1oVGc1LuBy/wgmx3K0RNsOGka/qot5O+vAt51PHJZ0TrefkYGrd8ETtIcy3wZ0WbJY05vHsFqbOEynF6IYKrQ2dl+93yJj2YrS1tWUJnqAPK4xE6p/vnb9023eNCbzxoIs5MGwwCak/EGgRo3FjrMQtltnun6hLX3OLmBurnMFRSJdxsMqIt7zAK49wRa9F90yfdB/oWZeWAAl2aG1/cmff0X0vQhtAS9c+NiSHS/86hPPG11xqRw3iD0032roDD3ruGdAiihl76qQ== Received: from MWHPR12CA0046.namprd12.prod.outlook.com (2603:10b6:301:2::32) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.19; Tue, 1 Feb 2022 10:11:14 +0000 Received: from CO1NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:301:2:cafe::23) by MWHPR12CA0046.outlook.office365.com (2603:10b6:301:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.22 via Frontend Transport; Tue, 1 Feb 2022 10:11:13 +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 CO1NAM11FT024.mail.protection.outlook.com (10.13.174.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4930.15 via Frontend Transport; Tue, 1 Feb 2022 10:11:13 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 1 Feb 2022 10:11:12 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Tue, 1 Feb 2022 02:11:12 -0800 Received: from sandstorm.attlocal.net (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Tue, 1 Feb 2022 02:11:12 -0800 From: John Hubbard To: Andrew Morton , Peter Xu , Jason Gunthorpe CC: David Hildenbrand , Jan Kara , "Claudio Imbrenda" , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , LKML , , John Hubbard Subject: [PATCH v2 4/4] mm/gup: remove get_user_pages_locked() Date: Tue, 1 Feb 2022 02:11:08 -0800 Message-ID: <20220201101108.306062-5-jhubbard@nvidia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220201101108.306062-1-jhubbard@nvidia.com> References: <20220201101108.306062-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a96c0c2-1171-419f-f22a-08d9e56b2d73 X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: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: Vj/PkckrSjGwtu6epH9C155uyleUB0svapf+8nvMAYLByL4hmtZTta3Fs59HnLSwKhxHRZo97WKyA1ES0o5zJVlclaF6vgC69Gu0xc1kKBIxtsToRCFhvsfIOYCi/moxsjRg0I104KLky8qdxAz/1dM8CBKaSx4L7g1rSHeOC2gHorg5RlXPKNEtYYCMQ0C0xiEAC7MhN0DQ2l7FAY3M3d+JNW8LQGFhnYU/bJ7q01EORZZxi5zdUOcEGXlwMxyi+rJCodDLApOnvV5Shz/OxU5M1vBymM1LQ4hlsux5wgFR0fOzSFQJHlE0cIRRImtjcPpj3pkmdjeXtx5aShVguPMgfNlDWAHQGqoIaI8cmq2Z8J6IBYMOYjCHIMo5Ts4s3qEf97SIo4ul3/NPUAs31hgQv6R0hEv4sf99q1Ra2waS0Q1cCPDhkM/o0nbdQslsH03voRJdqbl22Nye500W7J/EShhbofjkSnnj5BuMAsLVKh5YGPM08Tplzc58lKNBJintH5uLfPffQZleiH51hgjba1tHj4/m6DbT0U/1XcJ4/prLByLdpW/xFiCYJbPVSowwP2jwsxqhDH/fcCBLSMfeRO2+doBmB3+ZleJHry8F8on4xHLM+PJNGvPs9Wp+2MV6fEkYb91RQFVHx2mioC5jgGler+HAOdlO8wJWdhY39kQB5RdbFSgnKlUyjYUkcFzKDpi3K7hAGqTa7/pVig== 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)(46966006)(36840700001)(40470700004)(36756003)(4326008)(6666004)(110136005)(8676002)(83380400001)(5660300002)(70206006)(70586007)(2906002)(316002)(54906003)(8936002)(356005)(81166007)(7416002)(40460700003)(1076003)(186003)(2616005)(26005)(82310400004)(107886003)(47076005)(426003)(336012)(508600001)(36860700001)(86362001)(36900700001)(20210929001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 10:11:13.5220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5a96c0c2-1171-419f-f22a-08d9e56b2d73 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: CO1NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 X-Rspam-User: nil X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C0BED160003 X-Stat-Signature: f553wxe8rkn5umw1gmjxixe4fp5kx57d Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=PpJBWmoG; spf=none (imf08.hostedemail.com: domain of jhubbard@nvidia.com has no SPF policy when checking 40.107.243.74) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com X-HE-Tag: 1643710275-647182 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 is only one caller of get_user_pages_locked(). The purpose of get_user_pages_locked() is to allow for unlocking the mmap_lock when reading a page from the disk during a page fault (hidden behind VM_FAULT_RETRY). The idea is to reduce contention on the heavily-used mmap_lock. (Thanks to Jan Kara for clearly pointing that out, and in fact I've used some of his wording here.) However, it is unlikely for lookup_node() to take a page fault. With that in mind, change over to calling get_user_pages_fast(). This simplifies the code, runs a little faster in the expected case, and allows removing get_user_pages_locked() entirely. Cc: Jan Kara Suggested-by: Jason Gunthorpe Signed-off-by: John Hubbard Reviewed-by: Jan Kara Reviewed-by: Jason Gunthorpe --- include/linux/mm.h | 2 -- mm/gup.c | 59 ---------------------------------------------- mm/mempolicy.c | 21 +++++++---------- 3 files changed, 9 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..3f8dc58da3e8 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -907,17 +907,14 @@ 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); + ret = get_user_pages_fast(addr & PAGE_MASK, 1, 0, &p); + 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,14 +965,14 @@ 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); + mmap_read_unlock(mm); err = lookup_node(mm, addr); if (err < 0) goto out;