Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2786452pxm; Mon, 28 Feb 2022 06:09:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkjbRG5ayR20CMFknleY7qLZ7oJwyb/kGRikFipXTOQtHIYkZTfTk4MtreLOFV1uw5OuYE X-Received: by 2002:a17:906:7d98:b0:6bb:b32b:d3bc with SMTP id v24-20020a1709067d9800b006bbb32bd3bcmr14815185ejo.126.1646057361416; Mon, 28 Feb 2022 06:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646057361; cv=none; d=google.com; s=arc-20160816; b=ewpEJ7tBGDfrxZrnTliPIK1AtRJ8lgeLsg/nACztyEZKwhlNZXeHai6/6caQ8ZC/yR oONpcFZFNzi1vA1Vxs/MPpJG1TsjPyxXs0eh7eXhLcoQhIlQB2wEeK76qV3eGtcCImjQ kE5fUQnxppZuvluaeSZGejInibGo+cGVXMFdd5nYzt0DKZCJMVhh7OO0No1/NEIIlDSH QEMPmKuGj3a1o0vOBUapr8SmAwGnCn9TOaVBUh67zIeCqAwZ9ub+m1rWaAClbTKL2gPZ 9knuKT1Yx/XXFcG9B245/jfsD81iN3j6qpjMKB6tUM+qmeNSzknypZ6GnsAbkAwYVJj1 aSWw== 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=TgHmDz0GNu5q6ZWTFzBjKZo8h99OvSwyTIwCakMfNVM=; b=HWnhROSfnhGB+ZfSvfpq2OlHHL1/7r9NEUhNbOyMZQ+/XsHaVrVTJEtFM6hShv7X3C uF97e/o9mKarkDMt8ZFwz9lA3DMMoWnji08s3s9xLRk8D+wohzKgJ1RbX8St8cU0Xudn UlOJ+1w9ONbliqNuKuhzFOWk5GlfqhRZc+5hTg46QGOXQbMgOR0QWRr1FL2LdPyZj06O uMc63Ov7asfToEgcdt2sU0Fu5hQXSra9TFJNwYu7xaH6o8Lq/Qq8qQC/o9oUAKNaOvBn P2ayn7znBNZVf18XXPusC0tcZ5HQGnvhTKtx3/hNeWgkDW8soqTSzopRVYMoZeMqoe1y qzWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S0Xzhn+O; 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=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 y22-20020a056402359600b00413c9ab28e8si1199615edc.411.2022.02.28.06.08.58; Mon, 28 Feb 2022 06:09:21 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=S0Xzhn+O; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231967AbiB1N2C (ORCPT + 99 others); Mon, 28 Feb 2022 08:28:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbiB1N2A (ORCPT ); Mon, 28 Feb 2022 08:28:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8F37D2D1D3 for ; Mon, 28 Feb 2022 05:27:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646054840; 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=TgHmDz0GNu5q6ZWTFzBjKZo8h99OvSwyTIwCakMfNVM=; b=S0Xzhn+OggOfA2chvChpwZRLe2xLny5D5NWNsNIFfryMLs+sHDQITmoJxMAco8HcC7wE+D PqSc7LVXsjrR9MeypReTJcbyU0GgD00UMFGDsR/8LHdoYJExUjaossq4Siyxf2d/GG1RZ1 Y/gt1v/jgKhF0kGIdWIcydjwthjoxzI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-acqTj7hwMAuvgJYE9ePVBg-1; Mon, 28 Feb 2022 08:27:19 -0500 X-MC-Unique: acqTj7hwMAuvgJYE9ePVBg-1 Received: by mail-wr1-f72.google.com with SMTP id c5-20020adffb05000000b001edbbefe96dso2077419wrr.8 for ; Mon, 28 Feb 2022 05:27:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=TgHmDz0GNu5q6ZWTFzBjKZo8h99OvSwyTIwCakMfNVM=; b=djv9eryD8eWS/IuDT5/3JZMlRS9TZNMeiM3VsFyzB+9djt5tOSvx6pytC6hQoZFcbY 7JZmccprAOEBr70NyZ1K+uFIuLISZkwNLT4HEYe+58cEsULH9jFcBhs99OfFtk/NkKvh DxpJO/fVkDrR4f6KftIyCDzu9IZ/G56dHFMVh5di02bDKbGn8dSGYzYWV6uLmKA5oaze XIRAX0duUXYxp5dwHMAuww6N1mNIcStWjVNj3cYPNJCsOABIwDby65qHj8wikXryXLPT xZnNHJVPkjHe8Jgi0cRz348Ww3gKPU8NIq6Cd2F+EXTmi+s1DZFxlumoaZmooR/sVyYk Kybw== X-Gm-Message-State: AOAM532Fecn5IbU1OIBxfXAqrqgufVIphp9HAwHk6T9JEmwPawYnme5D QdqnK7Qt4TJfYhe72vUI4QBG7jFDnPmVqMaqkQM4sTzbEbIrWhKJjxKLAKgIEa0UPQPFOHpyCUE kkBxY35iPfYBIHMxaq2N3J/SH X-Received: by 2002:a05:6000:1e17:b0:1ef:d2b0:5624 with SMTP id bj23-20020a0560001e1700b001efd2b05624mr3754146wrb.598.1646054838218; Mon, 28 Feb 2022 05:27:18 -0800 (PST) X-Received: by 2002:a05:6000:1e17:b0:1ef:d2b0:5624 with SMTP id bj23-20020a0560001e1700b001efd2b05624mr3754116wrb.598.1646054837932; Mon, 28 Feb 2022 05:27:17 -0800 (PST) Received: from ?IPV6:2003:cb:c702:9700:f1d:e242:33b4:67f? (p200300cbc70297000f1de24233b4067f.dip0.t-ipconnect.de. [2003:cb:c702:9700:f1d:e242:33b4:67f]) by smtp.gmail.com with ESMTPSA id y7-20020adff147000000b001dbd1b9812fsm15058303wro.45.2022.02.28.05.27.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 05:27:17 -0800 (PST) Message-ID: <6ba088ae-4f84-6cd9-cbcc-bbc6b9547f04@redhat.com> Date: Mon, 28 Feb 2022 14:27:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [RFC PATCH 1/7] mm/gup: introduce pin_user_page() Content-Language: en-US To: John Hubbard , Jens Axboe , Jan Kara , Christoph Hellwig , Dave Chinner , "Darrick J . Wong" , Theodore Ts'o , Alexander Viro , Miklos Szeredi , Andrew Morton , Chaitanya Kulkarni Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, LKML References: <20220225085025.3052894-1-jhubbard@nvidia.com> <20220225085025.3052894-2-jhubbard@nvidia.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220225085025.3052894-2-jhubbard@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 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,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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-kernel@vger.kernel.org On 25.02.22 09:50, 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 is 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 | 34 ++++++++++++++++++++++++++++++++++ > 2 files changed, 35 insertions(+) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 929488a47181..bb51f5487aef 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1914,6 +1914,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 5c3f6ede17eb..44446241c3a9 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -3034,6 +3034,40 @@ 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. > + * > + * Similar to get_user_pages(), in that the page's refcount is elevated using > + * FOLL_PIN rules. > + * > + * IMPORTANT: That means that 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); > + > + /* > + * Similar to try_grab_page(): be sure to *also* > + * increment the normal page refcount field at least once, > + * so that the page really is pinned. > + */ > + if (folio_test_large(folio)) { > + folio_ref_add(folio, 1); > + atomic_add(1, folio_pincount_ptr(folio)); > + } else { > + folio_ref_add(folio, GUP_PIN_COUNTING_BIAS); > + } > + > + node_stat_mod_folio(folio, NR_FOLL_PIN_ACQUIRED, 1); > +} > +EXPORT_SYMBOL(pin_user_page); > + > /* > * pin_user_pages_unlocked() is the FOLL_PIN variant of > * get_user_pages_unlocked(). Behavior is the same, except that this one sets I assume that function will only get called on a page that has been obtained by a previous pin_user_pages_fast(), correct? -- Thanks, David / dhildenb