From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96A81ECAAD4 for ; Mon, 29 Aug 2022 12:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbiH2Mh5 (ORCPT ); Mon, 29 Aug 2022 08:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbiH2Mhm (ORCPT ); Mon, 29 Aug 2022 08:37:42 -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 958F4A6C2A for ; Mon, 29 Aug 2022 05:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661775678; 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=Liz7p0niJwOoZkvl8/emaYNL/c7bdcbi/8w0BtbSHeaIHxjytHp7fXIRjE61UTrzOLUrqI RByS5Zqam9P3x+go+U+NV2qAdK2t53xW8agZhZktY8j1saUSC1m46b7eJA9WCiIMxa7mpI Wo+fVf4rTzWPxZgbpx/8Z2j+fbmX9pw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-357-DQoaDj-WNGOFVTa8YobbaQ-1; Mon, 29 Aug 2022 08:07:55 -0400 X-MC-Unique: DQoaDj-WNGOFVTa8YobbaQ-1 Received: by mail-wm1-f72.google.com with SMTP id a17-20020a05600c349100b003a545125f6eso8372598wmq.4 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=aSgL6ds/vZumJ+4jYWwSgsWz9gRMCPUObmnApLVZk37bStIQW3u3MYKNDTqgsHYbYF CDwDk9CoiACmFItJ1KLjbYbzmrhD2m1hf2dyIoeu2St22kgXygcuF+ZSdUP/CeIZuzm/ wqQWQIsGzrpumKc1RDcRK53AaJWLFUoYIRzLBxRbbGjNnYcpUAHz6kX68UQBwiYRjq8v gCYx/p7b1MLTw1r46uBoAxDQXpogNb1Mobn5WvmbhpSlZ1TYn9yp4c6QQxAOlFBPOuXb RWMdIcNjW8EY9ehDHuf7Nmoc6eZS04/rOoKIrX6vUJq8XmiGr2JtJyonoT6lgast63mO mNqA== X-Gm-Message-State: ACgBeo2mbms1BclVaxFqjAsB3SinMVY85PzkddI2vo+F6oJ3FPUB/qg5 xzPwAqoy/hYYFzfvFwj2jCvJv5z2hS2/eDAZCDbWrsUIOWSuuMeXWW/JwtWjOorZ6/dPWnPT7G3 fEtM5OdpwP+dJW0/hmOLna/0= X-Received: by 2002:a5d:68c9:0:b0:225:330b:2d0 with SMTP id p9-20020a5d68c9000000b00225330b02d0mr5809298wrw.243.1661774873806; Mon, 29 Aug 2022 05:07:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR40B6aIc3Kd7HqO+pm6F4fpndLD4ybKX0vv6qIxnrSvSPYic+blNQ9JwBkZ3/6303cVEkP7JA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-block@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