Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3048100rwb; Fri, 20 Jan 2023 10:28:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXt0GD21f2TWUB1iDv5vhOkJqVOH9tJhdUWwrujvqTDlyTbdmK2QNQwY2RHx16Cvfr1nMR/a X-Received: by 2002:a62:3181:0:b0:58d:90aa:6039 with SMTP id x123-20020a623181000000b0058d90aa6039mr13748497pfx.32.1674239309739; Fri, 20 Jan 2023 10:28:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674239309; cv=none; d=google.com; s=arc-20160816; b=XLQumCO7q8PM1lvGTsxKgWSVV7tcpuhIUbdn8A1eUZ3pvJBjbr1u8FtlJE8cxnqaIA +tEa5M8VN2E7iD1C9+O2IWPPz9CyDYo2jLLTWmpb3L5c/mVr0u7sw6ArSHj4DRDkcVRF vkFfR9ISvAamihgz/+VRNeCp8eOm/UzAZQI3rRvU/URWkvcmhR/3rx25hTc2kd8VThW+ wqoe5uulxxS3/dMIxNNLYhK75O6uAjjvUUU0YJhu1UuAl+0PTcWlwFNVblx5ghdpi1Lu hcNilXPbJCajl4v7bkk/8tl1UWUszd0TvFBlfnBPaluYcdw+oVnC7gO39mXsEBmwlEJT Bl6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CYkyXriQe+db2xB55AZm41G9E0QZGdRv8ItoT4z1ez8=; b=ulzbuJrVV2qA7Tc5T2GSeyWzuHIt4SfkJsTF7eeFkqiiligEhwtw3rungfz+fnFIEZ WQ+h+RTBprjZ6937DPlViojIiXU/e6F7QXJAuTZBcf+iWRXH+2XbatgJt/jgTFb2vWwl aIZTDtMPql+TsNGe+Nn7wbW8fYKnnFOHYdPzuMXE/H4xP/pwUlA8wCdp8oDE1icPdg0Z e25512fdqt1RjkrqW6uGq3SWN0Cj9YFpw1Nus4MSSgBXKhLhEmE2RGAxKYnl+VZI7t0/ JK711+h4iHQ7/SFvYxE7YVdIGWVKoY3POPQAqe9FxUC26zMIZCpntdWIxLzumyp2uADL Dk6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U4FysDuP; 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 c15-20020a056a00248f00b005726e8b1cedsi19482105pfv.345.2023.01.20.10.28.23; Fri, 20 Jan 2023 10:28:29 -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=U4FysDuP; 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 S230211AbjATR5m (ORCPT + 50 others); Fri, 20 Jan 2023 12:57:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbjATR5k (ORCPT ); Fri, 20 Jan 2023 12:57:40 -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 ESMTPS id D458C46091 for ; Fri, 20 Jan 2023 09:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674237375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CYkyXriQe+db2xB55AZm41G9E0QZGdRv8ItoT4z1ez8=; b=U4FysDuPRIwf4vXTToFrnIYAasHiGSmvyB4DbHtnutn0ayA8/zz4JbEBP/cPA59vYIJnjs HpJS2aHbDY+q8Y5/Tcu5zD218UhMEX35iJf234mnvzJtqaqxlEAS/fZXHQfSmbEprVK2LB u6s0S18Ds9qrQjifD9kF5ED1gFowDg8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-569-rOeDDMKeNQmo4B5_T1HLmg-1; Fri, 20 Jan 2023 12:56:09 -0500 X-MC-Unique: rOeDDMKeNQmo4B5_T1HLmg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04CEB185A794; Fri, 20 Jan 2023 17:56:09 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C3A5492C3C; Fri, 20 Jan 2023 17:56:07 +0000 (UTC) From: David Howells To: Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jens Axboe , Jan Kara , Jeff Layton , Logan Gunthorpe , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , linux-mm@kvack.org Subject: [PATCH v7 3/8] mm: Provide a helper to drop a pin/ref on a page Date: Fri, 20 Jan 2023 17:55:51 +0000 Message-Id: <20230120175556.3556978-4-dhowells@redhat.com> In-Reply-To: <20230120175556.3556978-1-dhowells@redhat.com> References: <20230120175556.3556978-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Provide a helper in the get_user_pages code to drop a pin or a ref on a page based on being given FOLL_GET or FOLL_PIN in its flags argument or do nothing if neither is set. Signed-off-by: David Howells cc: Al Viro cc: Christoph Hellwig cc: Matthew Wilcox cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- include/linux/mm.h | 3 +++ mm/gup.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index f3f196e4d66d..f1cf8f4eb946 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1367,6 +1367,9 @@ static inline bool is_cow_mapping(vm_flags_t flags) #define SECTION_IN_PAGE_FLAGS #endif +void folio_put_unpin(struct folio *folio, unsigned int flags); +void page_put_unpin(struct page *page, unsigned int flags); + /* * The identification function is mainly used by the buddy allocator for * determining if two pages could be buddies. We are not really identifying diff --git a/mm/gup.c b/mm/gup.c index f45a3a5be53a..3ee4b4c7e0cb 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -191,6 +191,28 @@ static void gup_put_folio(struct folio *folio, int refs, unsigned int flags) folio_put_refs(folio, refs); } +/** + * folio_put_unpin - Unpin/put a folio as appropriate + * @folio: The folio to release + * @flags: gup flags indicating the mode of release (FOLL_*) + * + * Release a folio according to the flags. If FOLL_GET is set, the folio has a + * ref dropped; if FOLL_PIN is set, it is unpinned; otherwise it is left + * unaltered. + */ +void folio_put_unpin(struct folio *folio, unsigned int flags) +{ + if (flags & (FOLL_GET | FOLL_PIN)) + gup_put_folio(folio, 1, flags); +} +EXPORT_SYMBOL_GPL(folio_put_unpin); + +void page_put_unpin(struct page *page, unsigned int flags) +{ + folio_put_unpin(page_folio(page), flags); +} +EXPORT_SYMBOL_GPL(page_put_unpin); + /** * try_grab_page() - elevate a page's refcount by a flag-dependent amount * @page: pointer to page to be grabbed