From patchwork Fri Mar 1 21:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13579161 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BEC0C5475B for ; Fri, 1 Mar 2024 21:47:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B69F86B0098; Fri, 1 Mar 2024 16:47:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B19E56B009B; Fri, 1 Mar 2024 16:47:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A30006B009C; Fri, 1 Mar 2024 16:47:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 908986B0098 for ; Fri, 1 Mar 2024 16:47:16 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 62E671205E5 for ; Fri, 1 Mar 2024 21:47:16 +0000 (UTC) X-FDA: 81849806472.10.C8810C5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id E8E27C000C for ; Fri, 1 Mar 2024 21:47:14 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gEKfwRsD; dmarc=none; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709329635; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m55YQGBGw9qVxoXEA/93FX4UlDUH9XWWX9notPlTSC8=; b=uQmXO8giiZo/WziiHsGM2ApRmuxAYGob1TX/iSa6C9srzZ26knW0IDgLc/Ikx3Q+WzEVyM ej8wQpmMGA3biZRrYUsxyiGO8XFVGivJi1PEVtNDJe2bTxA0+bJZ5iInodD4Ohf6AAIrq0 1fYBRbYka1fFm8mCr/QQLMtyBbI1Ac0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gEKfwRsD; dmarc=none; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709329635; a=rsa-sha256; cv=none; b=1RCJeYrX/6vIJk7oBW/MX3E2I/Jn4IawvQfTaH/VVVQDDoCJPWw1EuVcBoVHUYvRJLbDsr Se+OYyy+CxyN7fz0gQblqxpGQK/CQ/swQec772bDKfXsWzHrgsa3jRtUS5yLYKoSACeLCD RVKq2cvOU4CKVVnZeMdgkzLX0knrPak= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=m55YQGBGw9qVxoXEA/93FX4UlDUH9XWWX9notPlTSC8=; b=gEKfwRsDt5A11MFHZYQ9jnXYbz srP/61zMNtPq+C7wvY6T8/OulnjowP3il+775wbFWXeXls612mjoGruI9aYIjVZXoZjXux17ZVBEB 7YRhpZdcInzgYHzRIAU0DUJP4BDynKqzlF9k7kWuLhioM2RJ21vJIrnZg9tfYSC3Hsn4YoV0nvZ0B Fvg6oYQwTZF4iXfpbyCYt/lmgIQgBHnV/jKdV7NQ4ZRRuqXfPu/Z9wrerKv7ZrViEkNBpu7L65sdL qE0353tz5VE2BsJDS5iNvfhb13adZ7SSF9FFhqnUHIwpA3dXLxGR1kL/ufANEfvLGET6RSOgzpw3l 0bTcHzbg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgAin-0000000ByEj-2hEW; Fri, 01 Mar 2024 21:47:13 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Oscar Salvador Subject: [PATCH 2/5] hugetlb: Add hugetlb_pfn_folio Date: Fri, 1 Mar 2024 21:47:07 +0000 Message-ID: <20240301214712.2853147-3-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240301214712.2853147-1-willy@infradead.org> References: <20240301214712.2853147-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E8E27C000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fsf9erf7yd91gnggndgwkzfxqirctk56 X-HE-Tag: 1709329634-976420 X-HE-Meta: U2FsdGVkX1/9nbWQlLxZvuLOAPlzQ4o3GnWidif2C8xSRgj700DyhkBVKufuWOUfPqaAagXq4zbiflLMsU397ryGKno4E0imL/G03fsGrSoCWd/5iZO3xvd7vVWRs50w7pWXaKkfZwYEy4ca1k6FYo4BC6PR6gXmkf/rZ7HkYsF5NnIsCRX7pTWWaagtvQqicjtvgdspC3N3FLy0d4ObGU1CK1+NHbhRpVrBZIWm4uQJ5d8291N5jFEAUWoIsmKhbTGcNM/fRD449tFh8x5+9SoTjLoIKXkd0b4o0LNVTywxffgt1eUfgGzusKEyh42bTs/IAV2A5MJsK+UjlJlR2f9OhRXgeMMemjlKkJwI4JQn5Lq4xK3DZaa75lG5XDu5ODgfvUG8FicrXbMdD8AXo1tEo4EVHajqrrR1f139BAgptLGDyicYNgZ0QZDvsD6QuOKhzmdznF5BAowwLmnPmb6whoSsQ4dTE4u/rKQrEN5CnvDGAzkEccxSGt7iyUmWfdetfhi4+ueQ5/w54+pCw9GwzW/CYk38nBuOiRr4VB2bSCpmw+WhGb51VIsr/jP8KYpc8/4vVoa661FMcmSCgs5LHoigad0GDnGMoLsSyj71q7zBBi34+v9HGhStwdZ1PEBy8DWkQ+uNQeBsel9o9ALDkAqujRxkvzeDZiL1oYVngGJcvZikKYVMYtN5HdfnlydxeaMmS0MxF3GnAuApqRlhI6lUFMFM897ji8We4WsuFnmcNjg7pRiAg+xxT8ysQgzqmrGkrpp8qcBO5CKSPfa2zuYIoVm3XAZ+3j9+fhYkVriOpJmuJYQTk82QMyeYFKfrAqp12Bn7/AHAvMZmRPi3EWfGaI4KqW9WowPvBWIfcB04hLI6dDU8PNx9MfRgGeYYeDIr2WEdgsokzao1FrQf3k6xSCcH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Returns the hugetlb folio containing this PFN or NULL if the PFN is not within a hugetlb folio. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Oscar Salvador --- include/linux/hugetlb.h | 1 + mm/hugetlb.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 77b30a8c6076..c1d23ab53752 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -163,6 +163,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long freed); bool isolate_hugetlb(struct folio *folio, struct list_head *list); +struct folio *hugetlb_pfn_folio(unsigned long pfn); int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags, bool *migratable_cleared); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 963c25963b5e..0895debc36f3 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -124,6 +124,33 @@ bool folio_test_hugetlb(const struct folio *folio) } EXPORT_SYMBOL_GPL(folio_test_hugetlb); +/** + * hugetlb_pfn_folio - Convert a pfn to a hugetlb folio. + * @pfn: The Page Frame Number. + * + * If this function returns NULL, the pfn definitely wasn't part of + * a hugetlb folio. If a folio pointer is returned, this pfn was + * part of that hugetlb folio at some point. If the caller holds + * the @hugetlb_lock, hugetlb folios may not be returned to the page + * allocator, so the folio will still be valid (it may or may not + * be free). + * + * Return: NULL if the pfn is not part of a hugetlb folio. + */ +struct folio *hugetlb_pfn_folio(unsigned long pfn) +{ + struct page *page = pfn_to_page(pfn); + struct folio *folio; + + if (!PageCompound(page)) + return NULL; + folio = page_folio(page); + if (folio->large_id != &hugetlb_lock) + return NULL; + + return folio; +} + static inline bool subpool_is_free(struct hugepage_subpool *spool) { if (spool->count)