Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3085798rwe; Mon, 29 Aug 2022 05:42:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR72MGDLMpUQaqDWvt4h2XLe19tfMTm15T5dyC9uo4PwZyE7WDrdq+4Z27u8an45fG6XJE1T X-Received: by 2002:a17:903:32d2:b0:172:f62a:2f33 with SMTP id i18-20020a17090332d200b00172f62a2f33mr16253286plr.16.1661776964652; Mon, 29 Aug 2022 05:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776964; cv=none; d=google.com; s=arc-20160816; b=cBw5Z5Exa2r9XhKqx7/4VPvbSKtiNzKyUugd4AFEUBIH7K7s2WjMpRIfNoj7IIBg/R +MdhEkaUiFueZ8uLuVUw0GqWFYm0Q4iK8y09mS30DTaXjjhiBQQa0nVqozmJNIkRcmGy Lp5KxipEBcA5hxeE18pbDf15QqCv7gddtj6CY8p3jPk0N7sxhJR2gqYVpP9hyVcvfIab 8IvDtmWoV4ItP+1GR90XmUO2tL69cBHcf2UbO/PZULe1xWhp1yYISE7IoLdtvLugh0Te nDURzRUX8HBoB9FwNPVGX8UkrTwE835WT4IEHhdI8+xQTlfvRzUWKk+aVdRZUjzqo/+u JXOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=xvRlmqs214Dpgefm9SAxkwz6k6CnKHpZ0dlz408l89w=; b=ofWkGglR3eqgYpAaj5hkD+3LHKca6Nmk/YduJK2eMrzJ8X590kuX4cdw/kUfvyr25v B8MNem5iMhI6kWQr+/1G4TFyStlEB4d5hxiDY2tTVrMc4P6Wd+Frln0ELoh0dcFiNuhr 8izb2Unc+CL0Oqot/IMrFnkBkHyM6JxChfQ4auBqe0X9mM44hRUmYmpaI7i0fUrIs9YM bAfxfyFqdCMox9Uu6CPqhasHs0BsLfkPS33uPQ9liFEjAj1NMWyeNJDNrBepUVTQ+CBV mDc+BgiXaDxP18T/fnduymQffJRgTb607BU3EtiZKgE0eXpm+w5ApJA1dbhUiQ2cm1ga m0dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MnYWh0iT; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a17090301d000b0016f16417f6dsi10130201plh.16.2022.08.29.05.41.59; Mon, 29 Aug 2022 05:42:44 -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=@redhat.com header.s=mimecast20190719 header.b=MnYWh0iT; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232225AbiH2MZT (ORCPT + 99 others); Mon, 29 Aug 2022 08:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232234AbiH2MYu (ORCPT ); Mon, 29 Aug 2022 08:24:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C573923C1 for ; Mon, 29 Aug 2022 05:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661774876; h=from:from: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:in-reply-to:references:references; bh=xvRlmqs214Dpgefm9SAxkwz6k6CnKHpZ0dlz408l89w=; b=MnYWh0iTijYG8gktzzxr5ACnR8os9vvoHWNMrgvPIgN0UNT1LJezzaeKIEE9SZ1zs5G+B+ srY1bt7GnCWZ8ZSf50J0DQ3clQ4TlWYo4VLMMgl4O7N7WN055rQTXIeA/AgZJCJNMdAsBn 9A8alDvVjTe4CVXi5VdG30BlDY/PEzU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-357-R4e40__UOfSXaEdtrhpOyw-1; Mon, 29 Aug 2022 08:07:54 -0400 X-MC-Unique: R4e40__UOfSXaEdtrhpOyw-1 Received: by mail-wm1-f70.google.com with SMTP id 203-20020a1c02d4000000b003a5f5bce876so8367498wmc.2 for ; Mon, 29 Aug 2022 05:07:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=xvRlmqs214Dpgefm9SAxkwz6k6CnKHpZ0dlz408l89w=; b=O3PzbgKlpK2ghDiDpn/epTQdWgHx6V0t96Deh5ujQAXbUfhvBPZW1fCKSVcTtqtd4J g8HmfaycoLxPBbjNb27yTgc6usgTu6xV3Ji8pBbUXsX4Rr04wToHfMws8jkipu9wVmS4 vKv/ZUIM6p/d3Y3LdoWTQrl2HJhhMCtaFEkBXMXQgvLoWsGIwZ2zvb8bDJ4omZFUTNId ZyBJ09E4c9wv+YNhhwHzsNSpbmBrtZsv7yhY1dLp6RBA9zxqBkEl9SLl+ONdKgBndqhG JTQyHwWnME9lV68uzyWArWgAP6XvLL72QwPOjn2RKl27mI/fIGXu8brYi/5TUAOtliKW xAiw== X-Gm-Message-State: ACgBeo25KoJ+AHNgNG/jCoyrsdBMVGWS05povbbBx2x+Z+yGYow1D33G B6AhB50VJgw9jyMGX2J9DZoXLOLj+XMwAOMCMbWHlKn2OpnRDiSTQX4xBkWdiyNv0l/FHJ1vRQ6 Qgj1U8cVGfv7BBnmSCHty X-Received: by 2002:a5d:68c9:0:b0:225:330b:2d0 with SMTP id p9-20020a5d68c9000000b00225330b02d0mr5809299wrw.243.1661774873806; Mon, 29 Aug 2022 05:07:53 -0700 (PDT) X-Received: by 2002:a5d:68c9:0:b0:225:330b:2d0 with SMTP id p9-20020a5d68c9000000b00225330b02d0mr5809271wrw.243.1661774873476; Mon, 29 Aug 2022 05:07:53 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:3900:658b:bed0:4260:4c25? (p200300cbc7073900658bbed042604c25.dip0.t-ipconnect.de. [2003:cb:c707:3900:658b:bed0:4260:4c25]) by smtp.gmail.com with ESMTPSA id f17-20020adfdb51000000b002252cb35184sm6771976wrj.25.2022.08.29.05.07.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Aug 2022 05:07:53 -0700 (PDT) Message-ID: <10a9d33a-58a3-10b3-690b-53100d4e5440@redhat.com> Date: Mon, 29 Aug 2022 14:07:52 +0200 MIME-Version: 1.0 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: John Hubbard , 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> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220827083607.2345453-2-jhubbard@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 27.08.22 10:36, John Hubbard wrote: > 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(). Specifically, pin_user_page() has a void > return type. > > 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(). > > Signed-off-by: John Hubbard > --- > include/linux/mm.h | 1 + > mm/gup.c | 33 +++++++++++++++++++++++++++++++++ > 2 files changed, 34 insertions(+) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 982f2607180b..85a105157334 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1869,6 +1869,7 @@ long pin_user_pages_remote(struct mm_struct *mm, > long get_user_pages(unsigned long start, unsigned long nr_pages, > unsigned int gup_flags, struct page **pages, > struct vm_area_struct **vmas); > +void pin_user_page(struct page *page); > long pin_user_pages(unsigned long start, unsigned long nr_pages, > unsigned int gup_flags, struct page **pages, > struct vm_area_struct **vmas); > diff --git a/mm/gup.c b/mm/gup.c > index 5abdaf487460..245ccb41ed8c 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -3213,6 +3213,39 @@ long pin_user_pages(unsigned long start, unsigned long nr_pages, > } > EXPORT_SYMBOL(pin_user_pages); > > +/** > + * 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. > + * > + * 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. I assume the intend is to use pin_user_page() only to duplicate pins, right? -- Thanks, David / dhildenb