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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87229C4321E for ; Wed, 30 Nov 2022 22:08:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B899A6B008A; Wed, 30 Nov 2022 17:08:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B108E6B008C; Wed, 30 Nov 2022 17:08:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ECE26B0092; Wed, 30 Nov 2022 17:08:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 779406B008A for ; Wed, 30 Nov 2022 17:08:15 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4D63C411BC for ; Wed, 30 Nov 2022 22:08:15 +0000 (UTC) X-FDA: 80191497750.01.5F673D7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id F39E340004 for ; Wed, 30 Nov 2022 22:08:14 +0000 (UTC) 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=Bf9QgNgl8uu84zUZAyTetZnjlw3v/IdWDtDQm/ZO4Nw=; b=qWaBxKInFy2BBK0lobKCcVwpzx F8KWylsxU0loegts+qKNXRjtnAu2jP7Nq///h84MtAOGqmU4IKzRVF+kUq/mW9ysHDT5soCIggufZ nyR6XlxKnnOKLbjP/NASbm7jwUiiJB9kzNaMa9e9O/1/L8Q/nMeQrS5s0WoosjIUBUQbJiDEwfo+9 z2/4sve9GVWIB3yBkwj8SAbdfULtJSzat9twZa82REpw1Pw4VgaEl3/7I9KruP/m4JFqRTdOFaLvm opVp6T94gWOdDQuIwtom/BwaJ9ofW/bm0hbaQt8BZhbzvatjtefQZ8PstHfRTTZ5LswKgUTdrCRkk 2+xGkxsg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0VFM-00FLUz-O0; Wed, 30 Nov 2022 22:08:04 +0000 From: "Matthew Wilcox (Oracle)" To: Jesper Dangaard Brouer , Ilias Apalodimas Cc: "Matthew Wilcox (Oracle)" , netdev@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/24] netmem: Add utility functions Date: Wed, 30 Nov 2022 22:07:41 +0000 Message-Id: <20221130220803.3657490-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20221130220803.3657490-1-willy@infradead.org> References: <20221130220803.3657490-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qWaBxKIn; spf=none (imf07.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669846095; a=rsa-sha256; cv=none; b=4f+93Cy20r3xAGok8nqDrIR822EBKWAqf7QjaK6KdzIzMvuEdLHQfaLJG8OQz/PQK+Mrl9 DUN/zJGGn3knU7CU5Iql7iG2qIJr4RZfdtvQskn7lB7jMU3yGHf0A/JjzvVZZpOjSZ7zQV N6/dLoQT/uG1er3RkbXRAA//KYj14gw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669846095; 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=Bf9QgNgl8uu84zUZAyTetZnjlw3v/IdWDtDQm/ZO4Nw=; b=LJk+1d7JBe3vUNjCQNpyAFJrvJKzz6q71gseknezZMuwYPgAST8zdgG0H6XcqZ11fLLioT EtPFXgX87vU7RiivsGFSpFpAUYzdpTkg4yhVerOwBZgkCdUHDt/E/6b9v0KiVMCwKsUFL5 qOdAsDa7ZSsS4BTnRQGrW5uyIUzdvVU= Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qWaBxKIn; spf=none (imf07.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Stat-Signature: 5bopwmbe31499e5gca4t4zpj7ergamjy X-Rspamd-Queue-Id: F39E340004 X-Rspam-User: X-HE-Tag: 1669846094-815439 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: netmem_page() is defined this way to preserve constness. page_netmem() doesn't call compound_head() because netmem users always use the head page; it does include a debugging assert to check that it's true. Signed-off-by: Matthew Wilcox (Oracle) --- include/net/page_pool.h | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/net/page_pool.h b/include/net/page_pool.h index af6ff8c302a0..0ce20b95290b 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -91,6 +91,48 @@ NETMEM_MATCH(_refcount, _refcount); #undef NETMEM_MATCH static_assert(sizeof(struct netmem) <= sizeof(struct page)); +#define netmem_page(nmem) (_Generic((*nmem), \ + const struct netmem: (const struct page *)nmem, \ + struct netmem: (struct page *)nmem)) + +static inline struct netmem *page_netmem(struct page *page) +{ + VM_BUG_ON_PAGE(PageTail(page), page); + return (struct netmem *)page; +} + +static inline unsigned long netmem_pfn(const struct netmem *nmem) +{ + return page_to_pfn(netmem_page(nmem)); +} + +static inline unsigned long netmem_nid(const struct netmem *nmem) +{ + return page_to_nid(netmem_page(nmem)); +} + +static inline struct netmem *virt_to_netmem(const void *x) +{ + return page_netmem(virt_to_head_page(x)); +} + +static inline int netmem_ref_count(const struct netmem *nmem) +{ + return page_ref_count(netmem_page(nmem)); +} + +static inline void netmem_put(struct netmem *nmem) +{ + struct folio *folio = (struct folio *)nmem; + + return folio_put(folio); +} + +static inline bool netmem_is_pfmemalloc(const struct netmem *nmem) +{ + return nmem->pp_magic & BIT(1); +} + /* * Fast allocation side cache array/stack * -- 2.35.1