Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3487035rwe; Mon, 29 Aug 2022 12:48:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/nY22P8TJ7BrPICMVPTaaTsgXhCm2t2sG6+56at6OD5texAbOkpUIXT+fuG/x4wFzI0sZ X-Received: by 2002:a05:6a00:7c8:b0:537:a0f0:cacf with SMTP id n8-20020a056a0007c800b00537a0f0cacfmr18222124pfu.77.1661802539020; Mon, 29 Aug 2022 12:48:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1661802539; cv=pass; d=google.com; s=arc-20160816; b=aYOVAuuvv2b9p1otsqVP+ggJwkUZ2QhmdJdzw2neAqsuQjZ8oRgXH8M4g4O/XVVFDo 3kpb5jjG/uLSLhg1S7aGzU6LdvP2wDPIzxT6QU/ZBEKPiIHK+R9yVWlvrNuq0ePTduDg UoPQQj2ST8mfuu4K2WE4QekETFoKTp9trLP/4pavcuhB8aluFcxoVbZpOsgJ6yaCj9pc VodRI1moqaB+GO4UcE/zOJslfGe+gNdy4pqLJWcb6JVmO+o+/OPrxm17A8CNSiCXJ2zo XyNOkK4nA2mksPgO3wwekrAyr7tnU99OoxqyFJcxzej0jzw5G6jzhHRIMtS3Mg7+ND5b HK+w== 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=4l48slpfryBfxnkJVXNMwaYDBp6ehDy7EB6lPEPa8hE=; b=sri6Tks0h+9p0OcsBYvyxtbv7I3ykmarKhGVGdygMeLaZPvuFh36Mbc2WQ7J7Oxb1J 8vEa9tJll5rtGR6Nh6oRongVTfF683jd8kzvtO+/8nwzMG8OUmhPjq+1GgfZky2hCqvj b65PbEW+ySYUTZ5epHB00CLHQfu7DHAN9l7wfPtSzNv20CltTQMjDllNYHqoDzfOeF0G PBIVBtXFSWiMQWZuvbiLhob1+xgOMx/rIgPAbpbD6IVjy/9NECnrT/X1YG8A/9NWaRBp t1IoDfBvNmwEjahESBTze8o7iy0eRhydS6wkFpRTOpwpIGIkjtzN6QCA/RCe2VFVwidY taVA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=TonKaWt8; 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-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-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 e11-20020a17090301cb00b00172ea8ff31bsi10991143plh.26.2022.08.29.12.48.35; Mon, 29 Aug 2022 12:48:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=TonKaWt8; 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-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-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 S229512AbiH2Td1 (ORCPT + 99 others); Mon, 29 Aug 2022 15:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiH2Td0 (ORCPT ); Mon, 29 Aug 2022 15:33:26 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2067.outbound.protection.outlook.com [40.107.95.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23C280B79; Mon, 29 Aug 2022 12:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LI7ZuZruuT1d4/A5KGcYTsCNmlIlHfBGjfRpoByd5SORoEQEsrKO1aQjbJ/lE79wrxOh4B3BF/eNFiWgomB41uflWV8uGByARhrB/ukcqRDNVTkENqC5ud6lPLJ+m7Hm0XctgRe9JoXm0NWjpY99qeKwncha2q4gKC4ECWUi54uoR2AqPVpCKXxfyIHVVMobEWzb6rsSCnatJZrgM65CEvJz2cMRsLrc010XYYGwznVtmH5HuI+selciUI9Q2LqJkA9xrSJ1CMLHAHyvST7qbmTdnRCWkKYV4HnaT74XjQH8bwSDJsRZrLhebQPsbsg/OTgoqCG6FB3muKPx/7KnnA== 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=4l48slpfryBfxnkJVXNMwaYDBp6ehDy7EB6lPEPa8hE=; b=iEw5x7w1oouOuhXiNd6QEaj5BedQh6XQ2nduz4VjsstWIBL9m3F/kcKIVBD/XmL8Lr6lHGb/xxHXqutHuB7jN14KgTtzG1Oy878ydCQUTTfT65PjG4+KfzgZjkW4WdTnPXavBc8PKPjt93WbREpBZZJYIHkhqFDXzrwkBXQi+FJ29ZScxaI+lXR2QvlW4pb2bnj7G9NUWOxOg37iAXDxqfbxc/tJSDsypfghvBYzzT6E8DeTCBsCj/gc2XeFb0pdFqNh3EaDUdTuo+GmSRtqSViR/YgktWtDADpdaTzUzmOh9eqb/73WV1aCzisVoUZO8yhnA9SzVWfbju7V3TN19g== 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=4l48slpfryBfxnkJVXNMwaYDBp6ehDy7EB6lPEPa8hE=; b=TonKaWt8ku7R4Fcrq0JDy6LQarD7UyxcMNhpOdweg8fVNB1qVmpTGHq5Z+1jVFOGzpw/uxEhQUOCeCzTy6SxkTnWNUL6s7Z2IFTLgqBCsskVxwXCX31E7tdxveTqdcX4sCgGv3lnGAup1DLqQO+rgwXVH6OLVt6ynXcwUVBKUs2xJT3uW+cMN3SeHeaI93kJcD5K/tLg0zsVSe/IVOH1XZGMaeR5KHs/ln92mR27XGFOUTiLcWBwjGAP6WG5uClXuSJRN2DQ2S0S3AOznA/XRIeKhhLwg0EON01ZPk4l5goSRFjRuWhTU9lRqy7aOO+6MGLXwerI9S9tGQWXVifUKA== 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 CY5PR12MB6369.namprd12.prod.outlook.com (2603:10b6:930:21::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.28; Mon, 29 Aug 2022 19:33:17 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::508d:221c:9c9e:e1a5]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::508d:221c:9c9e:e1a5%8]) with mapi id 15.20.5566.021; Mon, 29 Aug 2022 19:33:17 +0000 Message-ID: Date: Mon, 29 Aug 2022 12:33:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH 1/6] mm/gup: introduce pin_user_page() Content-Language: en-US To: David Hildenbrand , Andrew Morton Cc: Jens Axboe , Alexander Viro , Miklos Szeredi , Christoph Hellwig , "Darrick J . Wong" , Trond Myklebust , Anna Schumaker , Jan Kara , Logan Gunthorpe , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, LKML References: <20220827083607.2345453-1-jhubbard@nvidia.com> <20220827083607.2345453-2-jhubbard@nvidia.com> <10a9d33a-58a3-10b3-690b-53100d4e5440@redhat.com> From: John Hubbard In-Reply-To: <10a9d33a-58a3-10b3-690b-53100d4e5440@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SJ0PR05CA0161.namprd05.prod.outlook.com (2603:10b6:a03:339::16) 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: ce52a157-6ec0-4a68-2205-08da89f5528a X-MS-TrafficTypeDiagnostic: CY5PR12MB6369:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WDKMqwD8sSjXwdzJgeDtE3haNwg2nuxWBfYEaSvYY2yS7LudABXyOWwT7T3mFVZMWFJ9PJL+9j+P2FawDDK7l1sSI3ODGNRiOriIHpFc9A//LmNa5jyPRPSZa55katAACUKYsNDH50FCvSLrQit2lq7jozO0PW04TZJOJLsgRmEHhJ0hYO+U0bNbUWfDuWl5SalAjqpxMea2MFUUD3vnfW6zXCht8GOIC0KTEKHXiK3VYs4YuPm9uD8zR3IljCTHgwsiWi3Nd5//lQ/lUgsT3fz0U3notqZvxfNuJJGRsKjz5qd1dixHM+DXDUupvq1iPeXbJ+5/WFJs7PEDU1JXYcAjI0KHIEKQbliyWdt/IGSt0wjKoj2XtyQjknXbb22WqejBfJ0vn6oT1fch1vlx2R2oYloMeK35c4hgtgzK46D2LB4sDleDpKnyiWkWhyxwqbdA0z8oR0SGznjtSEXwBJREGgq6yB3C4+okP8JHt+kyYewImfZ+vIMxyd3JWio60g708tBleVLpIFb6bjB0/TusFB+3ksxdpMgb8vPJDwD6OFu2i7uqj3NkVuibgwpUyCLIfp3Ryo7cX3jO/m1Sqnn5KiEpVuDmgEO+/qf2NR24plDfZL1Tu33u337yjaOBmP5E1mD9FZQT33qqN/ZBqBhUfqTwW9mOq0Upfk3zAnATMXfEULSHm21lb266NrQKS3sMwCuDlKnFXj39R3NVynmKag3fu9Ty5vIL1dwFQIOvIQkH+rl2QaWbjnd9B9/c9h4beYZZ9MV0gMVEwbbqIvqHO8KKyzQ/NptEs4OjzzYOieAa2fxrga2Dq9FRq3wPjiELJuS6mLsYZjhLrRgSLQI3dfFz0Py9XIuDLseoZcFUsj4vRtEESc/35EdSOyby 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)(39860400002)(346002)(136003)(396003)(376002)(366004)(186003)(38100700002)(31696002)(53546011)(2616005)(5660300002)(54906003)(316002)(6506007)(2906002)(966005)(110136005)(7416002)(6666004)(66476007)(478600001)(8936002)(41300700001)(66556008)(86362001)(36756003)(4326008)(66946007)(6486002)(31686004)(6512007)(8676002)(26005)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aUp2VG5iazVxMldMOVhKYWJSVjI3MUsvNWlYTGZJUW5nN1crNytPRFp2Z1Nv?= =?utf-8?B?V0VWZWZTNmNycFVIVkZHK3UwUzhVd01RVlptWEUyNW1FVTFOSU1lUGlBWWNr?= =?utf-8?B?SU1CZ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hlVUpiRWRsTVdJaWtmbVFlYklNOE5wQUJGcFZCb3U1UGcv?= =?utf-8?B?anBYM21MUVpmVkV5dGloNFlMZ1Byc1QycCtKL0xOTmZxbHA0UHhaQzBiamM4?= =?utf-8?B?WFY5ekQ5VlpFR3RrYjlQQ1lYN1UwNzFhTWo2YXJrVmFaN1MwZWdFMEdIb3VB?= =?utf-8?B?aVBncS84ZXlXRFQ5YzFsdVFmdzZnaVBPRTJadmtGUHJoMVo5WWhjOTY3MENM?= =?utf-8?Q?gPbx0XrjZxLJh3LuS+gxwKoCR?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce52a157-6ec0-4a68-2205-08da89f5528a X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2022 19:33:17.2675 (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: jxtor7i1vUuGYzuyP9yaSemq09fdRJuCZs2h4n3x0t7UbXmyVvrcGhg9rTwMyTwwmGqf30rUxDaFhB5DJgacBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6369 X-Spam-Status: No, score=-1.1 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-nfs@vger.kernel.org On 8/29/22 05:07, David Hildenbrand wrote: >> +/** >> + * pin_user_page() - apply a FOLL_PIN reference to a page >> + * >> + * @page: the page to be pinned. >> + * >> + * This is similar to get_user_pages(), except that the page's refcount is >> + * elevated using FOLL_PIN, instead of FOLL_GET. Actually, my commit log has a more useful documentation of this routine, and given the questions below, I think I'll change to that: * pin_user_page() is an externally-usable version of try_grab_page(), but with * semantics that match get_page(), so that it can act as a drop-in replacement * for get_page(). * * pin_user_page() elevates a page's refcount using FOLL_PIN rules. This means * that the caller must release the page via unpin_user_page(). >> + * >> + * IMPORTANT: The caller must release the page via unpin_user_page(). >> + * >> + */ >> +void pin_user_page(struct page *page) >> +{ >> + struct folio *folio = page_folio(page); >> + >> + WARN_ON_ONCE(folio_ref_count(folio) <= 0); >> + > > We should warn if the page is anon and !exclusive. That would be sort of OK, because pin_user_page() is being created specifically for file system (O_DIRECT cases) use, and so the pages should mostly be file-backed, rather than anon. Although I'm a little vague about whether all of these iov_iter cases are really always file-backed pages, especially for cases such as splice(2) to an O_DIRECT-opened file, that Al Viro mentioned [1]. Can you walk me through the reasoning for why we need to keep out anon shared pages? > > I assume the intend is to use pin_user_page() only to duplicate pins, right? > Well, yes or no, depending on your use of the term "pin": pin_user_page() is used on a page that already has a refcount >= 1 (so no worries about speculative pinning should apply here), but the page does not necessarily have any FOLL_PIN's applied to it yet (so it's not "pinned" in the FOLL_PIN sense). [1] https://lore.kernel.org/all/Ywq5VrSrY341UVpL@ZenIV/ thanks, -- John Hubbard NVIDIA