From patchwork Fri Aug 12 02:13:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12941865 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 CD385C25B06 for ; Fri, 12 Aug 2022 02:13:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30ADF8E0002; Thu, 11 Aug 2022 22:13:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B9D28E0001; Thu, 11 Aug 2022 22:13:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 132C78E0002; Thu, 11 Aug 2022 22:13:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 054828E0001 for ; Thu, 11 Aug 2022 22:13:23 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C76C712078E for ; Fri, 12 Aug 2022 02:13:22 +0000 (UTC) X-FDA: 79789318644.27.63FA484 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2056.outbound.protection.outlook.com [40.107.92.56]) by imf03.hostedemail.com (Postfix) with ESMTP id D56FF2003D for ; Fri, 12 Aug 2022 02:13:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NlxUQuUHPTfAQXt87WeEuy8yiwlJ0K0szr+ekoCOg+clcVrRu1L2utbf4wjW8LLnx/F/L8nPDEuNFSHxmomktAgLwWWdOwWiB209y16PR32xMjXHju6qTHaD7hq0N1PZBGj4UPaQxln/7BBQvQymq6mWfnE9RdvXNF7hv2JjZki7mn6VHIeKh5KGZL/JLPYRoZRrNjMdqwr9ZGIlKQNLne+eXA73IX6i39Rcc7Uz1YcX0WZC8gWorpPlvjplOqfqb+QvGzGFUpMkQl0jCOw19gp1XxA6ydvdQmDcfswNfdNcEcE7QIE4yGHSfWyKLNiUK31p02SUTCzwHa1sH2vJ1g== 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=76IQdPubhMWITmpzgq+05WjE3ITgDSyIf3LKiC1ibmU=; b=jBf60yD1+PuMLbyDNfAaZuGB/1Xg3HAA+8fghioEJqVBmO+2Pqg676oOTd6VAsC39JONZZ/uG2iejfN3Gck/wWocruz8MbNXglvYJ5Np/wyMopPipUr/HM+k0pXLzDW15aqqo0J2Beh1Bn3OF8ih52w4THwP01mS/LwUHEsUFHAqiFQKJ1bESNJxIHUULmzf0ZLB73M5akDmbbQk1SEjuTPiUV8/sAw+vn9qnW6Q0uqSqjGgfBKAtUjWSQgTI3PMfNK5KUYDYW6KM/4Ktg8WH/Xo95PqjKu55HggqZcqQGGIJF3aVIKVGJbfPhcQo79dx3qA1+FE1L3P0a9ryhRsgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=76IQdPubhMWITmpzgq+05WjE3ITgDSyIf3LKiC1ibmU=; b=RsuRrj4F1s0/uA3qA1+/nVfNxbuhlo/gKY826xlpuRIZ4STdy4+NsxJ39O5mqPYhj1w8VNaLpDSCGY9FRwEJi1n8RRVWSAfk/CByA6598ZpGodKOY+a/AGYtwYe19Ie7Goma4a+b57rHrMV20iSlHf0LoJDljsW1eUEZwutWIcJwVV/8EEH8hTXHlxUABxYWU4m6i+RXetV7FAvXSDLbMjxaN+PHP6uZwpkg+FpDFzcu8uO2LoOyCZP7/03S+TvC/Oqk9rXFsYn3i2rCvwlppVqQktTQIoN3KYgc9MeK0YT5JFutezV5A9ZYLNt16H1vmS6VHkG7La3P622usqw9mw== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH0PR12MB7080.namprd12.prod.outlook.com (2603:10b6:510:21d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.22; Fri, 12 Aug 2022 02:13:19 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::eca6:a4a7:e2b2:27e7]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::eca6:a4a7:e2b2:27e7%5]) with mapi id 15.20.5504.025; Fri, 12 Aug 2022 02:13:19 +0000 From: Alistair Popple To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, "Sierra Guiza, Alejandro (Alex)" , Chaitanya Kulkarni , Dan Williams , Felix Kuehling , Jason Gunthorpe , John Hubbard , Logan Gunthorpe , Miaohe Lin , Muchun Song , Ralph Campbell , David Hildenbrand , Matthew Wilcox , Alistair Popple Subject: [PATCH v4 1/2] mm/gup.c: Don't pass gup_flags to check_and_migrate_movable_pages() Date: Fri, 12 Aug 2022 12:13:08 +1000 Message-Id: <487960bf67c7273ff5606c76f73bb51271bc7b90.1660269441.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: BYAPR01CA0072.prod.exchangelabs.com (2603:10b6:a03:94::49) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4efa3f19-3662-4f26-b234-08da7c08396b X-MS-TrafficTypeDiagnostic: PH0PR12MB7080:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CJRm16v0BSlOmCIxdyJgKOfVGv/q7yd7F5TG2w0IDC6aNPEgJX9ewY+ajlY1lwacy3tMlKifxS7f4qRoqbmNejVV58Q/YCK4Baqyh0RYNyAOkPyg/zoJzCJRaqCIntxiyMjX0elsJxoPfW3PXnWUI4SDZNIoJ1kDWS7BzeLXEa6KAtnYjnXJHZnR7NW1ru7nWKDxwnJmO2hp6VN9kYXZZwWxj2nYH5W6JyQ+AYJ5tc5HSd0UAqa4gd7e0LuYLbo+kutA7+nQSNfDZ22BerQFdwT5O94zoMy0tbntscaOY8ZRU5r3bzDZHNWDPpsDCTl+Hh3gTXz7E5lgQeUb9iF+OR97MPw15prtTuro/gQJU7DAgDEoZdJ47B/uPfpt4aN0pj4BUDLNaUQZqzDBdgxa0B+E/eiqenW+0UOioukAC7w91zO3laFHGn0aG3QCxMeZOGEtTQem/qd9gCa8eVjXmveq738FfyDlXINy0HkrcCu+bLV3IzFjY3lxHp9ZwAMy62MTsW3CcCeGA9FCPnI0rPAQDTbevlLw1wmG7pmNOTXIQOXuqMSEt1EQJIGnY+V1rW5aNAIkigR75DbVfSlqpvZfYkgxs3kccbpfYIfY60Ro+NgTbYkfaST8xLq17NYNqCYbeEH+t4H6LzI2hDSOGMQAiD00g4G5ciTpScGrRPZ7LurYiIfQT9fup/cPJYHz2zKmA1r3EKNOoD0XzguiiN2imaqZFFP3/EGSR6DcdtlnfQVb4Pzdj34uyvQ+onBz X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(396003)(346002)(366004)(136003)(39860400002)(376002)(186003)(86362001)(6666004)(107886003)(6512007)(26005)(38100700002)(6506007)(2906002)(36756003)(83380400001)(478600001)(6486002)(7416002)(66946007)(8936002)(66476007)(66556008)(316002)(4326008)(2616005)(8676002)(5660300002)(54906003)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PfQnMyF3gt1v0ElSBgHDsz4BzqNtxcRRGVJYnfl6caaJpwqjwinmJyy1jZLFo+zZ3m81FgN10Ljlvm5xUrwLq2j03fcz3wCUe9fcoaRg7Gtk+EGvZo0deBogsMeqCVt3TBjd+eEGRrKcuMOGYdWrHuHfFT5uOiPdFRTbjgEyfxr1aS0VQa4OHahypoCilSLyUpmi9lD//QzEPe5nsBlU1P++ILlfbBh04Q9l6GGHeRBWojS+uknw+1vxdJfFkhDxf8/mnXaWw7n2rVx/igUFo+Vb6NbKMpZQYxTLmhGxBDP49vpzRM5ZgR5lQ0q6cOCqNAkmiT3UfbdcAf7iUEk7/t3VJMaCCdZ2I99TIgTwt23Ue+EfSm8pQQBW8VbwPIOH8dX0w9VK9ijGsL6pzbPh3xfE22alOH1N4XxuKd8Pd4cPeKUsYPLCMBiXO19nuU1XDDdOrTTWEstmX3knGpLEseQMTfZROPeUcMCgA44j92JtQEmPMYIMvpKeFUKYrPngLlAAaB/sd/TTisYl3G6I48JkC0k1ZNSG+FFDvR7gUZKhcfIrhJZo7so4niLyoIjTtKW76OAL89R5sIuMsv8ckJGEt+MkmUWfMb+rsd/fvSozcjtrG4e5qT7HkNK1G8qbILCxholocce12f5QYh06xVHWJVc5iLv5ICFXn3ChShETef9Ps5hA4C33bhqf+U1Q9YEIEm6RO6ntrc41eZ3DqWBov//vD0uqMozx4LthEz+bNMpgRuNRdTSYim+B6SVpLlQcGuMSFBzJ2kJnJg7nAIjx1k+65Gs+TETPgKEnHsUqP31nbF1cYFu9ssRgz78ru8rSIf5xCGvhgXsbSMu923SclUQysaJTqA4mlub4hXmLdFCs4cpsc/Xl4UyZfg+XTG1ssS4IjUpMt0B6RiGEImVpGO1MHXz/T1ZYachB/QDKk6HUrzMa5j0QO023sRzRpxpSmcRcj3VWY+9eouDq5TzqQAUrOdtAUH4TZ9ZahQtC4ITzK81uM9YXxi1yKILVLzxEbEJ7iMcGWe13GxoTuBsEokwbWn/fxKLi8pbZA0QFflEQHDvxpcxBbnyxGSd8o0acB2jkNIFtO2gMIjpoVNxaYXhvpIdxeOvpOFJnREIb6V7UYXXyz6j0feLyDtNP7ln8Kw8gBu20+/w8RJ6aTaao1Cj5YCObgVm3gYXf9xBrWUT07do4AM9KWpUZkPvBa7gZvkyJd/NnyJFfGmDgH8tBjrbBhIL13EQG3y9ly5daBPuy0tLu2olb2nxVE7HEVf14kRdRad6lAMyDwbaFKnNC6DwGdZ2JF/FPfWv/Z6+GZV7FZlROU1opZGHuld71xN8D5KDKgy36spumGQdcMTcprCMZoqj/i58xpaPjmz7UmYypu2chC6StApPj1mcsZilHM9hq8p8bVm1yNDnnhyf+9mC/xDjofF4xbzihHEDriaG3GyUpNTsqn1LBXG0aPUNJdko9v2eLfEnlrUc4aqLwDH1I2mcfC/mohUWcWHLQ1F5FYQDQw40VdKGIQyPGwfODhrqYvkK+P48LkUOmp/gnsSNhBvSeEC/5mmP6UCJidEG9nXQy6UnrNkRQo3uJ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4efa3f19-3662-4f26-b234-08da7c08396b X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2022 02:13:19.4100 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tuPUU6JNl4d3asujeZPeCACiS/aXyHsNyzPMPKkGuDvohLIq7OHvAiYjtbbkhNfvhYODZLaJsXexS+sOlIdKWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7080 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1660270402; a=rsa-sha256; cv=pass; b=sZk3Gw5+iS75FmXwPB8MmhuSi+ig3BHJdm7bXimFxIX7hcSAcE1dSM9fRNVCIgfd4S2Q7M F2WXwOJf1t3Q5JudCEUItIsBUiMmUdZYiEfeKhWJb0/E9Ro1OeMrH+w3mG4tx5IUW7gu2H 6L3+i0JMtGG1pfY7i5q3gshbeSKeWrQ= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RsuRrj4F; spf=pass (imf03.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.56 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660270402; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=76IQdPubhMWITmpzgq+05WjE3ITgDSyIf3LKiC1ibmU=; b=lbw3qw29pw4hhzhVl5HGMudnlnLUcC/iCnwchPEs/nSjGCV2xgqHz62I/Au5zlUN0VpVrJ TO4r3yYOaqEsK23TaUV3zCAPgAjYx67Uly9b5mrqVSCmusQHsDPQfp5TEo74yOiZ9xCQq5 z2GL3jfsA2WKsdw/XwHoQ3w/zgGQ1L8= X-Rspam-User: X-Stat-Signature: h9w8knp89n6ne1q7u5rxigfu1qfind51 X-Rspamd-Queue-Id: D56FF2003D Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RsuRrj4F; spf=pass (imf03.hostedemail.com: domain of apopple@nvidia.com designates 40.107.92.56 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Rspamd-Server: rspam01 X-HE-Tag: 1660270401-998013 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: gup_flags is passed to check_and_migrate_movable_pages() so that it can call either put_page() or unpin_user_page() to drop the page reference. However check_and_migrate_movable_pages() is only called for FOLL_LONGTERM, which implies FOLL_PIN so there is no need to pass gup_flags. Signed-off-by: Alistair Popple Reviewed-by: David Hildenbrand Reviewed-by: John Hubbard --- Changes for v3: - Move WARN_ON() out of loop --- mm/gup.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) base-commit: 360614c01f81f48a89d8b13f8fa69c3ae0a1f5c7 diff --git a/mm/gup.c b/mm/gup.c index c6d060d..a2baa8b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1907,8 +1907,7 @@ struct page *get_dump_page(unsigned long addr) * Return negative error if migration fails. */ static long check_and_migrate_movable_pages(unsigned long nr_pages, - struct page **pages, - unsigned int gup_flags) + struct page **pages) { unsigned long isolation_error_count = 0, i; struct folio *prev_folio = NULL; @@ -1941,10 +1940,8 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, * Migration will fail if the page is pinned, so convert * the pin on the source page to a normal reference. */ - if (gup_flags & FOLL_PIN) { - get_page(&folio->page); - unpin_user_page(&folio->page); - } + get_page(&folio->page); + unpin_user_page(&folio->page); ret = migrate_device_coherent_page(&folio->page); if (ret) @@ -1998,10 +1995,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, if (!pages[i]) continue; - if (gup_flags & FOLL_PIN) - unpin_user_page(pages[i]); - else - put_page(pages[i]); + unpin_user_page(pages[i]); } if (!list_empty(&movable_page_list)) { @@ -2023,8 +2017,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, } #else static long check_and_migrate_movable_pages(unsigned long nr_pages, - struct page **pages, - unsigned int gup_flags) + struct page **pages) { return nr_pages; } @@ -2047,13 +2040,17 @@ static long __gup_longterm_locked(struct mm_struct *mm, if (!(gup_flags & FOLL_LONGTERM)) return __get_user_pages_locked(mm, start, nr_pages, pages, vmas, NULL, gup_flags); + /* check_and_migrate_movable_pages() assumes pages have been pinned. */ + if (WARN_ON(!(gup_flags & FOLL_PIN))) + return -EINVAL; flags = memalloc_pin_save(); do { rc = __get_user_pages_locked(mm, start, nr_pages, pages, vmas, NULL, gup_flags); if (rc <= 0) break; - rc = check_and_migrate_movable_pages(rc, pages, gup_flags); + + rc = check_and_migrate_movable_pages(rc, pages); } while (!rc); memalloc_pin_restore(flags);