Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp520906imn; Fri, 29 Jul 2022 14:27:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v9eXFvAGHaUshhGlLUHjxHRdHO/atilR03004pRe/1BKNZhitg0ZPu2Of3UOKDJYFl5Brk X-Received: by 2002:a17:906:84f0:b0:72b:72b6:c7b2 with SMTP id zp16-20020a17090684f000b0072b72b6c7b2mr4173168ejb.642.1659130065292; Fri, 29 Jul 2022 14:27:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659130065; cv=pass; d=google.com; s=arc-20160816; b=zSeuT87WoQhECS1mzg1D+2eacAdHhwmR9lA1K0d69wciW9eBwIDcpXyvZRq3r1XVR5 YVP8K5xIQbnPYAD3xPYO5LRcxak7rQD/dFGn1KVT5jP/OVDWYTSaymCOnf/lQ4g4252x s4SpWg0K8RuFCwqC2mBlX/k0wThY30yUjHuj7Vq9Dn9q1FoA5K3M3haI7nIhG8VS+ex4 j+26tGRI02W9zCXJHW4W52JWdaOV//4s2BNpNZ7l+Y33RqYB0H18vCeRYFTkSyK1YNk1 rz90PVBA9YfbApr/obgfTZF/3nwLDMdp2AX/xBEeJqbPf75zICdE/2JmebaKa73vHJCa XozQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=KP1Zotrer1eDw/FxVIN2GehhwCHGRN1OEKxKwEyKyrw=; b=BCG373Lqt0xNLekYsdV8MOadYaKTLT9PrBF7BJlCn04HYTOaZWjZtUWowOErQBLWKi yG8DoTUtHmElRy1EMnUSzjfOkbURCGZfIdNZdFgFfZ31ysUbO0tRM1cnQSPZ32flgGNV Yged2mNgo9yO3WDHIzk2NJDJQgm1LrDAh4FVoGsZ3n2lyI4tSuW3s+oIjLTqb7J8Rjl3 XndpRX/gGwBMWK8G0/nPlfl/M9zE8dMJ8vVj3utTwWSaZRj0KQERb8VcgdD/lwY7o7aR jbaA6SB0qhgy2OMSASGmDhY4AFOslwJInm2K2ZT5XrW1BeUzHVSPXgV4bi+PCdacMi7Y 3k1g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=gUjsQjBq; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb5-20020a0564020d0500b0043a78b54d7dsi4555556edb.302.2022.07.29.14.27.18; Fri, 29 Jul 2022 14:27:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=gUjsQjBq; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239230AbiG2VWP (ORCPT + 99 others); Fri, 29 Jul 2022 17:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239237AbiG2VWL (ORCPT ); Fri, 29 Jul 2022 17:22:11 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2080.outbound.protection.outlook.com [40.107.244.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01E528BA99 for ; Fri, 29 Jul 2022 14:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FbCje0mi9ANXsfXr28nLgoRXaZObiInCbqbdKyxTf42dB946ZjESkjxqlJR+Gsqy1yQSHOOHIq6GNu9+WAQVBoToj1xzA9XA04MUvb5CHlJEPRCqDKFfClYVuDO7S3X+TL1loJfEoxue74DVi2bNISdnr3sJ3opdnMYsrNyFGbY6tPKK8zSO0I7AFKmtk8dpkKhM/Oha3FRv8Z5CygEwwGnrzvgTPmORatxvbA08/MiD+IU66RBiTEYbZxoMfILlcvnTpuWXdcotqQMiKOlKGabarEiOwXsXZCLaDWVL3IRw1cjbBfhwmVK6QDnVE6oZx7OEIFY+/ipcJKMmADvWNw== 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=KP1Zotrer1eDw/FxVIN2GehhwCHGRN1OEKxKwEyKyrw=; b=Szk+6gd/kjCyppw/7vNJXqf9LsUZ//K1lVUjm5zfzfyYHDh9bPuHEARloXJALvm5agwroHGRyIYFlozAKU1u4kTKRcdCR6qOu70FhCioCzJwIEi9t4nYdSG1r6jRrEXDHSivdSe6DlQ4n9KgyEpokGw+pYyv/WVa4fJvIfSbmjhoObA4wQyYdh3TJk+rXWhEwwO6EtaYVnJR7xupe4irbMxXQxbccuqRhjf/AKPuy9ToLdT4R77PMRqVNXwUHHafF/6GcYMZmSyJgoWNtmn79jOTJxAgkqKEaoa7fHi9ZZxurZwjcZ0mLCUjZrRmnpdT5E+6MGRodNub0HCocFsZBQ== 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=KP1Zotrer1eDw/FxVIN2GehhwCHGRN1OEKxKwEyKyrw=; b=gUjsQjBqyDxff4uar1ftRT6H9vX/lQwww6GdWW12YsXwQpjI9+1g1eCXR4uGQFI3RUm5sttyauB3o17f+5fWN9pQ5MbPkk4/3WfZc2stMX01iKfa35/GUM3zJoRv8fs5wUs1RdvhhbNIKO22kYEe3W1VxyvkuvLb2/nGCtgTLhLevxL2XsZ4rB7ijSrzG+/bsSRT+x+khZ4CwOX4Xmq9aPC78MRtx3RkgfZ7TKtiEvT5ODGWizyk5MtJXwi+Uo3W+t39/Jomlc01ckdM4aREwBXoLlTzrd4yj75aClXcEbn/DA8iccfdT7PniB9hjgei2Br+7nVZ33+45GfU8pxHiA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) by CH2PR12MB3910.namprd12.prod.outlook.com (2603:10b6:610:28::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.21; Fri, 29 Jul 2022 21:22:05 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::ad32:9c8c:9142:df53]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::ad32:9c8c:9142:df53%4]) with mapi id 15.20.5482.011; Fri, 29 Jul 2022 21:22:05 +0000 Message-ID: <8f1f3278-ce9e-e328-6a8b-a793bc7f950f@nvidia.com> Date: Fri, 29 Jul 2022 14:22:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] mm/gup.c: Simplify and fix check_and_migrate_movable_pages() return codes Content-Language: en-US To: Jason Gunthorpe , Alistair Popple Cc: akpm@linux-foundation.org, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com References: <20220729024645.764366-1-apopple@nvidia.com> From: John Hubbard In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SJ0PR13CA0036.namprd13.prod.outlook.com (2603:10b6:a03:2c2::11) To BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22da4c70-559d-417f-131b-08da71a862fb X-MS-TrafficTypeDiagnostic: CH2PR12MB3910:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vRZHGrMwY7qtMdVVsC6BHn/TPLYDWSKRybUnRiaRHugpNc8tXbVyiR3pQTvng85DctbMKcy/Ldn9d/aL8IQvJqeH4QESUzI8dfPFL6c3czI8iortdA4PY6ii4g7kqDEGhrdYQZeFOi3EVN9pt0ym6ivvNvhDY2qQh/AoefClqNPQ253dkN8aKjFZxU7D3qoQus5bHVnKcG9qiJC0T9zRCxCPchup7graGBdu/AKHhvOaMEJsr52B19RHIxIWFf60PCJG+OnezSc5k6pinzkOLnd6ihqAYe7IIw4yc7GAGpAmaXZo4VGLpDLAkOIAzhHuCLVq+tO4cWZHiSf4OgR1ID72VaZn4ZRq/UsZeSMR2M4p1gmkTYXWNIyIqhAIALYCXth/+TsC1Mxjt19benuhgTHnRuWaFipSNzoSQ/MinDeP+jSdivBJKnXG2C+k7dYtYC3qlt/8dVOl+spejnOIs7rh0QtaRoenVJl04KBzYjzA/Jpg5CDy3kMM3TwsPPmiff5vcmUW0G9oh/FjpDskIeORN1E8KkFntsrMhGsLJKSoMc00lQ/jFZC3/rwG1sN9dpGrrKV5foLFETuhXNP4Kw1kTf7H/kY90IaDDN4tOdaVNBZOXij/jgJvzQiNqjhMh3zrLdkmG4uPegI+3qRg6IGc8Mndk2v2L84wu28dHt16+HUGbPO7xh6oWbl8hvlGkjrmzm1GUPGYHCxITQVEBJt2iVSc36xiltXr6l/ZmwhB+1c34mvYYiP/aCmH5yJ3kFVf5LmijvieqfywterXxMMDSXz+4dmMhuvtioxAapVtvg8/yTzRtFpcgmQSrSdnBpY+HBa45DNBS1J8YO+94Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4130.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(346002)(136003)(39860400002)(396003)(366004)(38100700002)(316002)(2906002)(8936002)(86362001)(36756003)(31686004)(31696002)(41300700001)(5660300002)(83380400001)(66476007)(66556008)(4326008)(478600001)(110136005)(53546011)(26005)(6636002)(186003)(6486002)(8676002)(2616005)(6506007)(6512007)(66946007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ak9NMUNmaktFWDFyaTJ6cENXeHVmMWVsRE1HZXg5MVl3czBGNCtuSlpoSk1D?= =?utf-8?B?K3A4TzRXRHlWQlk1VU1qZkRhNVpNTm9vL2t2bkNoVHZUNEhCQW8zKzJPZENx?= =?utf-8?B?c1ZGejhWaXFtZmJ5a3ltSkdFS05Dc3NCeHBlK3NoRjBwQXNKZ2RqV2srYlJj?= =?utf-8?B?ek5ZUDVqc2lkbHQxU1hqOUlWeHRTdDYvcC8yMW1wdzFYb21waGFVRk54Q0ox?= =?utf-8?B?WktISU5zQU9tZzlNR3Z1bDZVaHdyNTNpaXZsUUMyV0dXVHY3ZWxBalh4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OXFmUHhqcFkxTGdmM0tkRUxrVWc1aHF0?= =?utf-8?Q?Ssddk4K+8s5EyHaIz2H5Q6juo?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22da4c70-559d-417f-131b-08da71a862fb X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2022 21:22:05.6037 (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: T7BQXN33S3AokZj67CWNVVbqP43NJtbhyqm0YQiZ21W8w4Vd0DBmiHsrws4Sw9S02+cJJf1n15GJoVqnyxMOGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3910 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/29/22 12:44, Jason Gunthorpe wrote: > I came up with this ontop: > That cleans it up even more, looks nice. I'd go just a touch further, and also (unless there is some odd reason?) stay with -EAGAIN rather than -EBUSY, because otherwise both the function's comment header, and the caller, should change from -EBUSY to -EAGAIN just for consistency. And also because the way it's used: the caller is literally "trying again". So on top of the ontop: diff --git a/mm/gup.c b/mm/gup.c index 43c1fc532842..5f04033ee0ed 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1901,10 +1901,12 @@ struct page *get_dump_page(unsigned long addr) #ifdef CONFIG_MIGRATION /* - * Check whether all pages are pinnable. If some pages are not pinnable migrate - * them and unpin all the pages. Returns -EAGAIN if pages were unpinned or zero - * if all pages are pinnable and in the right zone. Other errors indicate - * migration failure. + * Check whether all pages are pinnable. If some pages are not pinnable, migrate + * them and unpin all the pages. + * Return values: + * 0: all pages are already pinnable and in the right zone + * -EAGAIN: some pages were unpinned or were zero + * -ENOMEM: migration of some pages failed */ static long check_and_migrate_movable_pages(unsigned long nr_pages, struct page **pages, @@ -1914,11 +1916,11 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, .nid = NUMA_NO_NODE, .gfp_mask = GFP_USER | __GFP_NOWARN, }; - unsigned long i; + unsigned long i, not_migrated; struct folio *prev_folio = NULL; LIST_HEAD(movable_page_list); bool drain_allow = true, coherent_pages = false; - int ret = -EBUSY; + int ret = -EAGAIN; for (i = 0; i < nr_pages; i++) { struct folio *folio = page_folio(pages[i]); @@ -1990,7 +1992,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, /* * Unpin all pages. If device coherent pages were found - * migrate_deivce_coherent_page() will have dropped the pin and set + * migrate_device_coherent_page() will have dropped the pin and set * pages[i] == NULL. */ for (i = 0; i < nr_pages; i++) { thanks, -- John Hubbard NVIDIA