Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1432484rwb; Fri, 12 Aug 2022 00:19:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR7n5YRW2s36gWqf5rxt2H6oP10Wht/4OYCkFJ7sf1EppN9NziPhJ1RJaWNSYlC64ahcTlVP X-Received: by 2002:a05:6402:13c1:b0:43b:e330:9bbf with SMTP id a1-20020a05640213c100b0043be3309bbfmr2375031edx.417.1660288778914; Fri, 12 Aug 2022 00:19:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1660288778; cv=pass; d=google.com; s=arc-20160816; b=Aw15ADNrxJe5dhYOkUjZwBsNlC6bVvRugaEBYdGVV2o6XxEiJq8EB5jMRZ8/NdBARw 4f1QCioXNd771VW8TTwTSMDR8XjB7R6zdz5ncPEQuIAYi0g+FEzNsg45zCoW7X/2TCGt H0UZuMfq8zvn++CamX+NYfUxgqQweGRPfAX6+SxTPswn2Wq6mI1bItCZhYGvocSl9FVv JquDp7+PovQLoyOpRCMlwyca/PtslSeYHF9T1B5GlF8FvMbg0wc2HmBUm45J/r4bnRft 9vIxPkw0LjeIaCnIs/SGgAlVuoVKvAN4J7LSwKIKE6j1wHgd31uAWXwkvcYb+9Q9e3S6 Dd6A== 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=icvap4P0398fIyAi56O5O45eUzGU0GbSYxPj8aZcGPM=; b=FSlFtZggwOkF6Nj3QeUOxaWV2hF/W/KgTa+VbgXvvq9Jm1PaSSxTZEWegQaHl8/vtK 1wkmdQMInG2QQygxUknHJOWs2pk8HFmuuQdIQEZjXkMbtO5ZLLQHDW7IwAuM5iTJD/xm FxIMfAq6njzImvxyN/1mo9vWhQyOmnVjkId+2duOyp2A+nblepy17KtTMdi+FU9U08y2 +3VanLnmd4AnGNJEYRWpZQ1uh4dksxtB5xUvBGHWOqfFInPpia41byizL3Xqgqb+wVnF LG+7da1LtIFFyLXIJ5tJFQCARPQU1HVPBn8xehE4tabkNih/NVALT2d33s9OaxonxeXT EXTQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="l/dQ1t9K"; 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 r22-20020a056402035600b0043bf15dc4d2si1522894edw.131.2022.08.12.00.18.49; Fri, 12 Aug 2022 00:19:38 -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="l/dQ1t9K"; 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 S237121AbiHLHFb (ORCPT + 99 others); Fri, 12 Aug 2022 03:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiHLHF1 (ORCPT ); Fri, 12 Aug 2022 03:05:27 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2080.outbound.protection.outlook.com [40.107.92.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD9F18E1D for ; Fri, 12 Aug 2022 00:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OYwgwVVeyPFmxrPcjSzW5cp6ysnLfqKJwai1ejpMeIrdNen086VKIktGYLiR+JA7+568brRtlXFOSXHZ2ckuteUKNL06TwzvNcuhPbMT5ZdRtO5P2ihH0Bl/c0zg93mcM4aazBKhUtKr8HAmFLvWqps5RRYnvWdz4moVQtt3xFmvF4P9bYwwX7mu+5jwERYYI0DbszhNSZDR5WJUHUaVZv+Y5/WyyXzmht4Ahg2gjlRABerDpFHrqicnCezfWOj5llgs3NqQ3iDqEp020tXxWS0ucZW8S9fE2Zo/ttJJZUPkiHSnWf47hYsasDni5rFhoURJJ0fSFlBxi6rFznkEmw== 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=icvap4P0398fIyAi56O5O45eUzGU0GbSYxPj8aZcGPM=; b=Cg76D6N59uRme1r44ANXBBr4qEPgF+jhc3wfqLHtLxoJjXP9inPgAeHzdplaRG3I9h0VA/Y2UXI0pE1rHnRYczMW025MTjd+GL3JRnkq/wOMqpcSJz+kc4tYe9KgdBxBef3rLkGiint9n1wITP0bXOUWkoy/rHH+RxhnD9wCE+ignhjDR28YxW3BnSs5mqp6zEcC8KFNFi9iiVKZ+z/X2ImsgRY8xUXuME3afiECW+hoUM3E/xmYViCrcaEsOQ/EdJVqA6Qd4vE5Gi/8wB5e42hPHRBdVukfNg0b6u9treFuSK8eDX/kN0VmzUH/v29nBdcPS+8br1oDjb982kAr/g== 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=icvap4P0398fIyAi56O5O45eUzGU0GbSYxPj8aZcGPM=; b=l/dQ1t9KXuwbucvUhN9xobGQBPPOvpq59vEvu0GWypUGutt/lLFyF33kX29V04NQBQHE1RN64EsVLKgBVQavowJWxscjnOb7+mMzbnLquNPnylDVjcG9u4xTAuujlkC+M516MhjsVvJYLhJdE0Lq0HCP+H5lubloEUd6lGaGGkySGXtrCHIkuI35o4eJRSURuQri+jtJ1BQyCP224nxZXIOQy/Sl5npF+JpkJYpPYQlq+X/hIQ3iJKGexkLKSjyh3X8F7WEHtSYhwXQQ/MeHUQZFD9V7qSzR9EgxHems9TEphtlFghqMsxv23bj8w7wzeI9KOI4UxTii8fz1iL65PA== 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 MN0PR12MB6295.namprd12.prod.outlook.com (2603:10b6:208:3c0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Fri, 12 Aug 2022 07:05:21 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::508d:221c:9c9e:e1a5]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::508d:221c:9c9e:e1a5%9]) with mapi id 15.20.5525.011; Fri, 12 Aug 2022 07:05:21 +0000 Message-ID: Date: Fri, 12 Aug 2022 00:05:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v4 2/2] mm/gup.c: Refactor check_and_migrate_movable_pages() Content-Language: en-US To: Alistair Popple , 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 , Logan Gunthorpe , Miaohe Lin , Muchun Song , Ralph Campbell , David Hildenbrand , Matthew Wilcox References: <487960bf67c7273ff5606c76f73bb51271bc7b90.1660269441.git-series.apopple@nvidia.com> <6b61e9bf7c65f78524db32ba3e65a7eb6b8a76a0.1660269441.git-series.apopple@nvidia.com> From: John Hubbard In-Reply-To: <6b61e9bf7c65f78524db32ba3e65a7eb6b8a76a0.1660269441.git-series.apopple@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SJ0PR13CA0171.namprd13.prod.outlook.com (2603:10b6:a03:2c7::26) 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: 6091eca9-aa68-43bd-cb68-08da7c31053c X-MS-TrafficTypeDiagnostic: MN0PR12MB6295:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g2hB+NIOAEboisNe+hhHedwvzk4POexdhLfoGs+buTM+hlJiyAMAjlogEfCrtuZNhVjQmi1fs+WvfOvDylUHx6VpzuKq4NpMPImGU4uh//Og4iFufjN2kZu31VzDucFCocdM1VDWT/v2lwNJTre3uIBh3z/oYYfknnEsXat0+DqBeZLsX56gxehiLogvoOB+UlbGktKBmrmQZv7pyMIhbjXFpl7IYALojlEuq29EZI1a6Hfiy8UWg0+UeXx9WUK02CC7sSiEjhU93VnDPkjqb+K8uJL8X2KLn0QRTPfr1EVVkK7H+Y4MpN8+rlzuIqaz5NjI7VnPShDkG83SNf8a4TPxi3ZQ9yMgOIR0nV1PMWVUEYK4jZKvQ+2x65toIzi6diTsoDuTCVZ6SwprQu2jY1ZxUkfWfP6sQFvJdztag56XJE2NPbWgxRV3kGhU5muk/Z+oq/6Up+X02WOJDnv7WQipYwk95ZVhh2jsSxRI5/yuKVRa5wDGyFhQWf7l2QbZqa7lLmZJ9W3OHfpnRj1cuaqrx+/noSdNblYtF2RT+NMBInvtyZzlz6GYld0g1tK2BOaNKpee9YpbU756FXpd7bSxsEePv/RTS1Deje6xuJbMLj5OWrCKk7tCgPsgzCvA0E6PW7sD1aGQQkpRzxNfUgDjqIebUlte4uODHJEgGiFv7wV4T0EfiRtF1T/0Ieur8vbzCiQlIHawSVRdi1oPOEJyRlv2OvbRcdnC0sxCvdNV12swkMLcaT72RBeO4k2PTwLg8lcG+bObE8jHt4+5J3RbIG6Vg4XaX2f2B/8DU1Izs5K/gW/Xu7u0UW1R3hZVIuVCq19TcC4d8vLvhoNfeg== 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)(366004)(376002)(136003)(39860400002)(346002)(396003)(83380400001)(478600001)(31696002)(5660300002)(186003)(31686004)(6486002)(2616005)(86362001)(36756003)(54906003)(8936002)(41300700001)(7416002)(316002)(38100700002)(6512007)(2906002)(66556008)(66476007)(66946007)(26005)(4326008)(8676002)(53546011)(6666004)(6506007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eDc2ZmNXUDlGQXRVeXpLSWtQR2s3MGRrTVhEcWVrbTZyalJzSEhEK0UySVZD?= =?utf-8?B?Z0ZZQkE1eHNzQlUrbXQybmk3SXVDS2ZlS2IxakxaUExDQVk1Wnd6eUgvSVlk?= =?utf-8?B?ZUNUNWhmSGlzL1VEcCtr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XFhZG5rRjNwTUNO?= =?utf-8?B?dllBSjU2YWlGQXQwblYvWSt4U0JCQ2FaQ0VYWTdsL1ZtZzlsaGRWMEYzZS9z?= =?utf-8?B?MTRjdmRtVzg3bVBoYUdUbFhZaGh2TytzTzZjTzc4aStZOWwxeERhQTdzMXJW?= =?utf-8?B?dkNwTVFnMXRMVmV6eUpidHZBTHpCL3UyS2FRZFJienhudld4ZEFMeTN2ZUw2?= =?utf-8?Q?dmjo+WT5V9/G8Ttu13UCMOBli?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6091eca9-aa68-43bd-cb68-08da7c31053c X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2022 07:05:21.0707 (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: 7kScs9fBlbR7UDf/85S8rzvtpPW2fqZqW8HuJJ+v2lu62pILymi+YfKgtwn++S45Ud6xa8dXeLJXtmcIk8/OGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6295 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,T_SCC_BODY_TEXT_LINE 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 8/11/22 19:13, Alistair Popple wrote: > When pinning pages with FOLL_LONGTERM check_and_migrate_movable_pages() > is called to migrate pages out of zones which should not contain any > longterm pinned pages. > > When migration succeeds all pages will have been unpinned so pinning > needs to be retried. Migration can also fail, in which case the pages > will also have been unpinned but the operation should not be retried. If > all pages are in the correct zone nothing will be unpinned and no retry > is required. > > The logic in check_and_migrate_movable_pages() tracks unnecessary state > and the return codes for each case are difficult to follow. Refactor the > code to clean this up. No behaviour change is intended. > > Signed-off-by: Alistair Popple OK, I've finally convinced myself that this is a correct transformation. This cleanup does help clarify things, definitely. I've got two documentation additions (and changes) to suggest, below, and a couple of too-long lines, but the code itself looks good, so with those tweaks or something approximating them, please feel free to add: Reviewed-by: John Hubbard ... > +/* > + * 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. > + */ Instead of the above, I'd like to suggest this: /* * Check whether all pages are *allowed* to be pinned. Rather confusingly, all * pages in the range are required to be pinned via FOLL_PIN, before calling * this routine. * * If any pages in the range are not allowed to be pinned, then this routine * will migrate those pages away, unpin all the pages in the range and return * -EAGAIN. The caller should re-pin the entire range with FOLL_PIN and then * call this routine again. * * If an error other than -EAGAIN occurs, this indicates a migration failure. * The caller should give up, and propagate the error back up the call stack. * * If everything is OK and all pages in the range are allowed to be pinned, then * this routine leaves all pages pinned and returns zero for success. */ > +static long check_and_migrate_movable_pages(unsigned long nr_pages, > + struct page **pages) > +{ > + int ret; > + unsigned long collected; > + LIST_HEAD(movable_page_list); > + > + collected = collect_longterm_unpinnable_pages(&movable_page_list, nr_pages, pages); There is no reason to exceed 80 cols here. > + if (!collected) > + return 0; > + > + ret = migrate_longterm_unpinnable_pages(&movable_page_list, nr_pages, pages); Nor here. ... > @@ -2051,10 +2079,10 @@ static long __gup_longterm_locked(struct mm_struct *mm, > break; ...and in this routine, let's fortify the comment like so: @@ -2068,7 +2078,15 @@ 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 we get to this point then FOLL_LONGTERM is set. And FOLL_LONGTERM + * implies FOLL_PIN (although the reverse is not true). And that, in + * turn, makes it correct to unconditionally call + * check_and_migrate_movable_pages(), which assumes pages have been + * pinned via FOLL_PIN. + * + * Enforce the above reasoning, by asserting that FOLL_PIN is set: + */ if (WARN_ON(!(gup_flags & FOLL_PIN))) return -EINVAL; flags = memalloc_pin_save(); ...and with that, it's actually possible for the reader to work their way through this story, I think. thanks, -- John Hubbard NVIDIA