From patchwork Mon Nov 13 13:00:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 164463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1182606vqg; Mon, 13 Nov 2023 05:01:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHs4cw0kndUVeVbpQ5YaK244AzsMqnIp0SOTWg5JnJ1KcTkxK0Ww+Xxl0sz5GBCHYHEUyMt X-Received: by 2002:a9d:7e91:0:b0:6bf:1e78:cc52 with SMTP id m17-20020a9d7e91000000b006bf1e78cc52mr7843506otp.25.1699880496641; Mon, 13 Nov 2023 05:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699880496; cv=none; d=google.com; s=arc-20160816; b=BqQRwXTtlXCDloAC4D/E2Jd79pNeMtEGIGi6GgcHOaGg3hvPkn9alLJR/+75lnpMQm D2SjPpWj+RXqeUdPHEAhDewm4wSD9kweiYMXuUnR9+q3lWWz6E364pVVK/1fwOb3E2QA eAUb0kt9eLW3A9emuak+iaz66R4ZfeQJ5jgxwTqogwhEe4i/iAbZ3Yr+66wHFWN/t/Ly 92WZqWST0MMb87sr/Vr3Eak2XnHwe/ddlkWE5rFUhi0SDXS7rRQJWiGl7ySqgPQxmsKn FHb3+pyVpJquHdblDgV2ihWeA28JvMP4zH3MKfyOfhyZcnxhen+WwZm2HbMuBLaKhRBh YoCA== 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; bh=y58kFmZpX3EILqiR8ZBPIVJUozNKi9peP7z59HEirw4=; fh=cURveIlAsDWLrnfJFZhNYW9+lOK4hKD2b5uY2n7BOnU=; b=W/dFS2iHXQwNUSdzVRKB6QO0TiPTCxshwgtmuQlXsKHoBg2XxY+7RRBzwN/+bK9r3n vkpYTaADsWVlHz7A9VCMRKYNsCj79Bx+bUngg+0dsRCnNoLYMAxTwLKC0C9Erv0LZEo0 17GcrQe0q20TU/rUtRzEDmHNEip58bsSs48rgv6nOJVd1mbvIncpQrUIlB7RInU/714J rmGpCGNIBlndl4R2u/yH41KwTKCfHOzkeB/3tZ7LPiQhoCoZWRY5h1hs9Q8xECIB64R/ HzZwWlv1jc/sHz/RwzaivN8ktJeF5uIjOsoaSpT0CpZsXZjcSHNnq9pmO8/JEUTkxrMr faiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id d17-20020a056830045100b006ce2a47bc3asi1779100otc.351.2023.11.13.05.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B8DCF805743D; Mon, 13 Nov 2023 05:01:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231200AbjKMNAs (ORCPT + 29 others); Mon, 13 Nov 2023 08:00:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjKMNAl (ORCPT ); Mon, 13 Nov 2023 08:00:41 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 917E419B5; Mon, 13 Nov 2023 05:00:33 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STTzv4QsTzWhJn; Mon, 13 Nov 2023 21:00:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 13 Nov 2023 21:00:31 +0800 From: Yunsheng Lin To: , , CC: , , Mina Almasry , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet Subject: [PATCH RFC 1/8] net: page_pool: factor out releasing DMA from releasing the page Date: Mon, 13 Nov 2023 21:00:33 +0800 Message-ID: <20231113130041.58124-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231113130041.58124-1-linyunsheng@huawei.com> References: <20231113130041.58124-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 13 Nov 2023 05:01:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782453891541625107 X-GMAIL-MSGID: 1782453891541625107 From: Jakub Kicinski Releasing the DMA mapping will be useful for other types of pages, so factor it out. Make sure compiler inlines it, to avoid any regressions. Signed-off-by: Jakub Kicinski Signed-off-by: Mina Almasry --- net/core/page_pool.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 5e409b98aba0..578b6f2eeb46 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -514,21 +514,16 @@ static s32 page_pool_inflight(struct page_pool *pool) return inflight; } -/* Disconnects a page (from a page_pool). API users can have a need - * to disconnect a page (from a page_pool), to allow it to be used as - * a regular page (that will eventually be returned to the normal - * page-allocator via put_page). - */ -static void page_pool_return_page(struct page_pool *pool, struct page *page) +static __always_inline +void __page_pool_release_page_dma(struct page_pool *pool, struct page *page) { dma_addr_t dma; - int count; if (!(pool->p.flags & PP_FLAG_DMA_MAP)) /* Always account for inflight pages, even if we didn't * map them */ - goto skip_dma_unmap; + return; dma = page_pool_get_dma_addr(page); @@ -537,7 +532,19 @@ static void page_pool_return_page(struct page_pool *pool, struct page *page) PAGE_SIZE << pool->p.order, pool->p.dma_dir, DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING); page_pool_set_dma_addr(page, 0); -skip_dma_unmap: +} + +/* Disconnects a page (from a page_pool). API users can have a need + * to disconnect a page (from a page_pool), to allow it to be used as + * a regular page (that will eventually be returned to the normal + * page-allocator via put_page). + */ +void page_pool_return_page(struct page_pool *pool, struct page *page) +{ + int count; + + __page_pool_release_page_dma(pool, page); + page_pool_clear_pp_info(page); /* This may be the last page returned, releasing the pool, so From patchwork Mon Nov 13 13:00:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 164459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1182332vqg; Mon, 13 Nov 2023 05:01:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGL27yh58FFPTITYYoGQno94z6U7dsuTvZG+jOveaGHO5yF1J9JvlZ8U+o/KsctrO0hvMYo X-Received: by 2002:a05:6a20:e118:b0:180:e8b5:f19e with SMTP id kr24-20020a056a20e11800b00180e8b5f19emr4570340pzb.27.1699880477022; Mon, 13 Nov 2023 05:01:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699880477; cv=none; d=google.com; s=arc-20160816; b=s3j+y46n9DrClhCQR0UQUZmcX7tdswiY9rT+79ko85KJx3Yg2/k+9GxcyWlLgBdj/7 hhxkS/BAbIw+byVb6GC4gBEGC/nH8GGAg9B7C46dHjvAlNyDQLqZbaenHl6ruS2u5yKC 0+4vzYVX5Dj3UwNB1HcucitxX4Uyu2bWZNNU3O70trYFcgBrCVJbo5DAuMAwgzWVFrSF XsXJaOBBd2bbUcY8a8mfrrXqhmHJKNHoA16Slo4Ypsop3nH02YxB2i9RJ4me9zyrdtC7 /bNy/EUXW6AzYnGcNKK3+7XkApZ1ObTmQdRh/WAzNIu5y8CIxESj3Y0GmeePlXBVs//z Fyeg== 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; bh=lfb+SSpXqOk+yOXUmg+JtR0108/favXGBi32ZG3YzWc=; fh=4GWX8OAuAX3umXfqEfwAdW/IAhM83i2jhVS2JD+7U3E=; b=FAfD0FFHsXkILOSeJktWPydUiMGMMqC06lXrUFP4JrLbZOdl1NqqB3t7vc4zYqnLAE abB4zynml7eDKrha0qg1hwSzmXu0ZhFMKRT4U9CGbYJxLPFP/ziFygXlBXOYc7F8uZUO XTKs0qT2oETy9vxyYDqj+xQQVNeQj5yaePLn4dhEI4fRgdqmPO3rDhOhCzQqRSdBgfQq 3HwOr0w3OJ7CpNJdHdrhI3HSr4Wurs5aVPwEgii7MAWQpoz5asY3UFGnq3k+Qq20K54u tINDCvzBATvjSOfdKTBIM68jXnYeEOaSuNcQfq367kgt4kzfROa0NkeC1yt1OCZJa8dv Yf5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q18-20020a170902dad200b001cc41a2b752si5765223plx.206.2023.11.13.05.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:01:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4B16E8057426; Mon, 13 Nov 2023 05:01:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbjKMNAw (ORCPT + 29 others); Mon, 13 Nov 2023 08:00:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjKMNAn (ORCPT ); Mon, 13 Nov 2023 08:00:43 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC0E2171A; Mon, 13 Nov 2023 05:00:35 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STV026PRSzvQQN; Mon, 13 Nov 2023 21:00:18 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 13 Nov 2023 21:00:33 +0800 From: Yunsheng Lin To: , , CC: , , Mina Almasry , Yunsheng Lin , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet Subject: [PATCH RFC 2/8] net: page_pool: create hooks for custom page providers Date: Mon, 13 Nov 2023 21:00:34 +0800 Message-ID: <20231113130041.58124-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231113130041.58124-1-linyunsheng@huawei.com> References: <20231113130041.58124-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 13 Nov 2023 05:01:10 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782453870987639815 X-GMAIL-MSGID: 1782453870987639815 From: Jakub Kicinski The page providers which try to reuse the same pages will need to hold onto the ref, even if page gets released from the pool - as in releasing the page from the pp just transfers the "ownership" reference from pp to the provider, and provider will wait for other references to be gone before feeding this page back into the pool. Signed-off-by: Jakub Kicinski Signed-off-by: Mina Almasry Signed-off-by: Yunsheng Lin --- include/net/page_pool/types.h | 19 ++++++++ net/core/page_pool.c | 81 +++++++++++++++++++++++++++++------ 2 files changed, 87 insertions(+), 13 deletions(-) diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 6fc5134095ed..5e4fcd45ba50 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -60,6 +60,8 @@ struct page_pool_params { int nid; struct device *dev; struct napi_struct *napi; + u8 memory_provider; + void *mp_priv; enum dma_data_direction dma_dir; unsigned int max_len; unsigned int offset; @@ -118,6 +120,20 @@ struct page_pool_stats { }; #endif +struct mem_provider; + +enum pp_memory_provider_type { + __PP_MP_NONE, /* Use system allocator directly */ +}; + +struct pp_memory_provider_ops { + int (*init)(struct page_pool *pool); + void (*destroy)(struct page_pool *pool); + struct page *(*alloc_pages)(struct page_pool *pool, gfp_t gfp); + void (*release_page)(struct page_pool *pool, struct page *page); + void (*free_pages)(struct page_pool *pool, struct page *page); +}; + struct page_pool { struct page_pool_params p; @@ -165,6 +181,9 @@ struct page_pool { */ struct ptr_ring ring; + const struct pp_memory_provider_ops *mp_ops; + void *mp_priv; + #ifdef CONFIG_PAGE_POOL_STATS /* recycle stats are per-cpu to avoid locking */ struct page_pool_recycle_stats __percpu *recycle_stats; diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 578b6f2eeb46..6c502bea842b 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -23,6 +23,8 @@ #include +static DEFINE_STATIC_KEY_FALSE(page_pool_mem_providers); + #define DEFER_TIME (msecs_to_jiffies(1000)) #define DEFER_WARN_INTERVAL (60 * HZ) @@ -172,6 +174,7 @@ static int page_pool_init(struct page_pool *pool, const struct page_pool_params *params) { unsigned int ring_qsize = 1024; /* Default */ + int err; memcpy(&pool->p, params, sizeof(pool->p)); @@ -225,10 +228,34 @@ static int page_pool_init(struct page_pool *pool, /* Driver calling page_pool_create() also call page_pool_destroy() */ refcount_set(&pool->user_cnt, 1); + switch (pool->p.memory_provider) { + case __PP_MP_NONE: + break; + default: + err = -EINVAL; + goto free_ptr_ring; + } + + pool->mp_priv = pool->p.mp_priv; + if (pool->mp_ops) { + err = pool->mp_ops->init(pool); + if (err) { + pr_warn("%s() mem-provider init failed %d\n", + __func__, err); + goto free_ptr_ring; + } + + static_branch_inc(&page_pool_mem_providers); + } + if (pool->p.flags & PP_FLAG_DMA_MAP) get_device(pool->p.dev); return 0; + +free_ptr_ring: + ptr_ring_cleanup(&pool->ring, NULL); + return err; } /** @@ -257,18 +284,13 @@ EXPORT_SYMBOL(page_pool_create); static void page_pool_return_page(struct page_pool *pool, struct page *page); -noinline -static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) +static bool page_pool_page_in_pref_node(struct page_pool *pool, struct page *page) { - struct ptr_ring *r = &pool->ring; - struct page *page; int pref_nid; /* preferred NUMA node */ - /* Quicker fallback, avoid locks when ring is empty */ - if (__ptr_ring_empty(r)) { - alloc_stat_inc(pool, empty); - return NULL; - } + /* Always assume page is in pref node for mem providers */ + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) + return true; /* Softirq guarantee CPU and thus NUMA node is stable. This, * assumes CPU refilling driver RX-ring will also run RX-NAPI. @@ -280,13 +302,31 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) pref_nid = numa_mem_id(); /* will be zero like page_to_nid() */ #endif + if (page_to_nid(page) == pref_nid) + return true; + + return false; +} + +noinline +static struct page *page_pool_refill_alloc_cache(struct page_pool *pool) +{ + struct ptr_ring *r = &pool->ring; + struct page *page; + + /* Quicker fallback, avoid locks when ring is empty */ + if (__ptr_ring_empty(r)) { + alloc_stat_inc(pool, empty); + return NULL; + } + /* Refill alloc array, but only if NUMA match */ do { page = __ptr_ring_consume(r); if (unlikely(!page)) break; - if (likely(page_to_nid(page) == pref_nid)) { + if (likely(page_pool_page_in_pref_node(pool, page))) { pool->alloc.cache[pool->alloc.count++] = page; } else { /* NUMA mismatch; @@ -490,7 +530,10 @@ struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp) return page; /* Slow-path: cache empty, do real allocation */ - page = __page_pool_alloc_pages_slow(pool, gfp); + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) + page = pool->mp_ops->alloc_pages(pool, gfp); + else + page = __page_pool_alloc_pages_slow(pool, gfp); return page; } EXPORT_SYMBOL(page_pool_alloc_pages); @@ -543,7 +586,10 @@ void page_pool_return_page(struct page_pool *pool, struct page *page) { int count; - __page_pool_release_page_dma(pool, page); + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) + pool->mp_ops->release_page(pool, page); + else + __page_pool_release_page_dma(pool, page); page_pool_clear_pp_info(page); @@ -553,7 +599,11 @@ void page_pool_return_page(struct page_pool *pool, struct page *page) count = atomic_inc_return_relaxed(&pool->pages_state_release_cnt); trace_page_pool_state_release(pool, page, count); - put_page(page); + if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_ops) + pool->mp_ops->free_pages(pool, page); + else + put_page(page); + /* An optimization would be to call __free_pages(page, pool->p.order) * knowing page is not part of page-cache (thus avoiding a * __page_cache_release() call). @@ -821,6 +871,11 @@ static void __page_pool_destroy(struct page_pool *pool) if (pool->disconnect) pool->disconnect(pool); + if (pool->mp_ops) { + pool->mp_ops->destroy(pool); + static_branch_dec(&page_pool_mem_providers); + } + ptr_ring_cleanup(&pool->ring, NULL); if (pool->p.flags & PP_FLAG_DMA_MAP) From patchwork Mon Nov 13 13:00:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 164461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1182568vqg; Mon, 13 Nov 2023 05:01:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6sY/roDcnie40Bu7XiKMHQVxAf1ihXH0vglVWjiuvTqQU7kRCFAK2ibiTBnDgf3IaFU7/ X-Received: by 2002:a05:6808:23d0:b0:3b2:f5be:4fd5 with SMTP id bq16-20020a05680823d000b003b2f5be4fd5mr7534994oib.14.1699880493645; Mon, 13 Nov 2023 05:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699880493; cv=none; d=google.com; s=arc-20160816; b=cXHokJ/zTqYBdT7rzdarjGHN2mZBohq0xs2PejY3tyvJOhx8yfz5t+X6jHEzfkZLye FSnCrPJZn/U6Vin+B0JcoCh6zq0J53Bu+C2t5sShledMxpO6UhRW3SviSiOgmzE30o/+ 9+MNpRu5jSgxYAF7Mf2WeaoDPKRq7/l1fLFQm4GqHgZysd1/CadK1AGvjV9kQeoqVm8f MYeFrAEJssU9JePUpCO+3plXIrDP2uq3UYoMHV7TaYz0AlEwXdBST4ay5Q895ei294xI TfNOOA94h0ECG/7dYomNCJFvclWOTvY4omVcbaTjdFbrxCaZkhBbWmtby8BDSFUjNPQ/ GKww== 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; bh=s3ToAF9lPk5lV5aeLAhUsNkuFJwiyqjfy4ZK1ZXiH0w=; fh=rpgd+rBTFhv/UVUrKvI/g1qH621dbxAWhcUv71ig/BU=; b=N3iAIfPdhqfrFzKa2P4spxry65d/IG3Y/vYleFCiHZcFNUaOtQAvBKegZpzDcCHMAv wOfXboJr35vAwNKXXYbjI9rOMUWdwPa1ukIM0Ml86f9I0AmCZOlgtZyVU+7KABiXt06i 3AbbrSzRmsk64MKJ8XV7zictqxHXWN7F8vzf8d2uqCodf643/ahJySk91mUc0S9YwQVm s8sKfL/pAGusSLrJbLYZH9jVk1X/ZF4o0HA0HbzyH2GvVjXE8nmq1730437lwRTzRKwz kpyMDUDUGRIxPckk9Lsi7ttvYaLYgzyWS0Msr6XZSEWC0uC8s6VYYeNUDMyOaPrNI16a VOZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u192-20020a6379c9000000b005b3e61af56esi5432741pgc.121.2023.11.13.05.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:01:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3A9158056982; Mon, 13 Nov 2023 05:01:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbjKMNBA (ORCPT + 29 others); Mon, 13 Nov 2023 08:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbjKMNAn (ORCPT ); Mon, 13 Nov 2023 08:00:43 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DC701984; Mon, 13 Nov 2023 05:00:38 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STTwZ5Mryz1P8HW; Mon, 13 Nov 2023 20:57:18 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 13 Nov 2023 21:00:35 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin Subject: [PATCH RFC 4/8] skbuff: explicitize the semantics of skb_frag_fill_page_desc() Date: Mon, 13 Nov 2023 21:00:36 +0800 Message-ID: <20231113130041.58124-5-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231113130041.58124-1-linyunsheng@huawei.com> References: <20231113130041.58124-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 13 Nov 2023 05:01:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782453888435751010 X-GMAIL-MSGID: 1782453888435751010 As we have ensured that the page and the offset to the page for the skb frag is passed togetherly in one function call, see [1], make it explicit that skb_frag_fill_page_desc() expect a base page or head page for a compound page, so that we can avoid the compound_head() in the net stack. Log a warning if the caller passes a tail page of compoud page and adjust 'page' to point to it's head page and 'offset' to point to start of it's head page. The warning can be removed if we have ensured all the caller is passing non tail page to skb_frag_fill_page_desc() in the future. 1. https://lore.kernel.org/all/20230511011213.59091-2-linyunsheng@huawei.com/ Signed-off-by: Yunsheng Lin --- include/linux/skbuff.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 27998f73183e..3e2f806c8ed8 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2423,6 +2423,14 @@ static inline void skb_frag_fill_page_desc(skb_frag_t *frag, struct page *page, int off, int size) { + /* expect head page for compound page */ + if (WARN_ON_ONCE(PageTail(page))) { + struct page *head = compound_head(page); + + off += (page_to_pfn(page) - page_to_pfn(head)) * PAGE_SIZE; + page = head; + } + frag->bv_page = page; frag->bv_offset = off; skb_frag_size_set(frag, size); From patchwork Mon Nov 13 13:00:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 164464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1182798vqg; Mon, 13 Nov 2023 05:01:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcDmJT2txZmM4zY6diMDEA62ZBytzUePK90ivBmFh7X+ApNch+/gmfemuhFFra+hhaINR0 X-Received: by 2002:a17:903:248:b0:1cc:78a5:50a2 with SMTP id j8-20020a170903024800b001cc78a550a2mr9249122plh.39.1699880507723; Mon, 13 Nov 2023 05:01:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699880507; cv=none; d=google.com; s=arc-20160816; b=qMdDqSk8mJiRprV7nCRv7ZUOSJdQJosHBfL5AWy5vapzJbNwnaMGFOvW2MlogfVMfx ndwEejFrLBNE8JxiVK81cTOKG1BKpIK5mJpE3fVPFtoPUxsqOCaFXb8aqLGxYM8QHmzy KCfskxZFHnrOJQ8DWK+DzFPeftaDnUAGYQsGZdMaiqinzMyW6HNZuCKjFTUhymj1h1P+ uB/ZfWHOLq3nYpb+u/KZrnCW+L8v/nZoq83WN+7oijUBmDwXnAJyd4RsRhuYzlZuTjrB NbHuyXSfKBor0wMtb0Rgbfv3CLqCvhrrT0oKhT8WYWYmNlkNw7secM1nXYe0lIkoukuq qW5w== 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; bh=0veeVgGcPKI6vl8TxRqQ/3Hmtiyt8E5Ws6REHZvgTlc=; fh=D6xVSegNul4KrUJ9ERmiGKlse4yUgZ/4HEoMM009vXk=; b=TIqjB/CKCI+1fT7Gfgow75tfWvvu/pr/SBeXvoSPfJ8gU0W/qXgc7FurAgncqm+qo6 rjpTCbkr1IRr9+k1SSeatJZgRVGZ6886A+urDwP0/mqUvlYSKoZ/O54nImhgUpESPq50 P/QWnmUfQWaegGl/btkvRkGm0dSbHLZQjVn96QIqiJnCSk8IgURbY3SMoTsDMV70JlTD MLzZ5+UDfLcKPBr+53YOrjecHRkVIJzd6Hrrq02C2cteVcIbXTQ1ZFsD+X6OkA0MC2Vg V/onKQgktqcr8D0voETNywGGuWjd/rOY5nDYiGOGIYkN1Q1FUmaRfV6FR5ToAVAtH/FV tvkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id lk8-20020a17090308c800b001cc6529c7besi6097388plb.88.2023.11.13.05.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:01:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 01C3B8057429; Mon, 13 Nov 2023 05:01:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbjKMNAz (ORCPT + 29 others); Mon, 13 Nov 2023 08:00:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbjKMNAn (ORCPT ); Mon, 13 Nov 2023 08:00:43 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3726519A7; Mon, 13 Nov 2023 05:00:39 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STTvY6l89zPnY6; Mon, 13 Nov 2023 20:56:25 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 13 Nov 2023 21:00:37 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Eric Dumazet Subject: [PATCH RFC 5/8] skbuff: remove compound_head() related function calling Date: Mon, 13 Nov 2023 21:00:37 +0800 Message-ID: <20231113130041.58124-6-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231113130041.58124-1-linyunsheng@huawei.com> References: <20231113130041.58124-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 13 Nov 2023 05:01:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782453903022975916 X-GMAIL-MSGID: 1782453903022975916 As we have ensured that the page for the skb frag is always a base page or head page for a compound page, we can remove some compound_head() related function. Signed-off-by: Yunsheng Lin --- include/linux/skbuff.h | 8 +++++--- net/core/skbuff.c | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 3e2f806c8ed8..1889b0968be0 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2473,13 +2473,15 @@ static inline void skb_len_add(struct sk_buff *skb, int delta) static inline void __skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size) { - __skb_fill_page_desc_noacc(skb_shinfo(skb), i, page, off, size); + skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; + + skb_frag_fill_page_desc(frag, page, off, size); /* Propagate page pfmemalloc to the skb if we can. The problem is * that not all callers have unique ownership of the page but rely * on page_is_pfmemalloc doing the right thing(tm). */ - page = compound_head(page); + page = frag->bv_page; if (page_is_pfmemalloc(page)) skb->pfmemalloc = true; } @@ -3429,7 +3431,7 @@ static inline struct page *skb_frag_page(const skb_frag_t *frag) */ static inline void __skb_frag_ref(skb_frag_t *frag) { - get_page(skb_frag_page(frag)); + page_ref_inc(skb_frag_page(frag)); } /** diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b157efea5dea..ada3da4fe221 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -896,8 +896,6 @@ bool napi_pp_put_page(struct page *page, bool napi_safe) bool allow_direct = false; struct page_pool *pp; - page = compound_head(page); - /* page->pp_magic is OR'ed with PP_SIGNATURE after the allocation * in order to preserve any existing bits, such as bit 0 for the * head page of compound page and bit 1 for pfmemalloc page, so @@ -939,7 +937,7 @@ static bool skb_pp_recycle(struct sk_buff *skb, void *data, bool napi_safe) { if (!IS_ENABLED(CONFIG_PAGE_POOL) || !skb->pp_recycle) return false; - return napi_pp_put_page(virt_to_page(data), napi_safe); + return napi_pp_put_page(virt_to_head_page(data), napi_safe); } static void skb_kfree_head(void *head, unsigned int end_offset) From patchwork Mon Nov 13 13:00:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 164467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1182911vqg; Mon, 13 Nov 2023 05:01:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSSkhNPfzqil++lxsLkI0kCHLNZpaWR5JSKsH//D2WgIsPkOJEsyYzaZB9GWyC4ffR3XIX X-Received: by 2002:a17:902:f80e:b0:1cc:501b:1d13 with SMTP id ix14-20020a170902f80e00b001cc501b1d13mr4010621plb.40.1699880512585; Mon, 13 Nov 2023 05:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699880512; cv=none; d=google.com; s=arc-20160816; b=IIeMYX3B0uen5yf+9NCReejgoJ6N7E6W0FZpxUgAFrEIpp6MOCh7Q90ghDSN+YJzLM RSZjM2H7aI9TDyfRvNJevAbhw6msgtjoEod5MSHUHXTfL2oicqLojE2XWjCrr9C29N7V 1kky/5HZBNgXYeC0pCA83rKqDexkxv+IreY7QDewyOLW6wypP2DUGJHXai5GntSsBlSL 9tX04oyFbpu9GCntcqEg/oZaIh/tWUXuqGsYZi5bXjP8/9DbmnwP/XsRwT2t7ZgLHRGi Dxzb2ivncy0s8YO/shaH9kxpXSQBsmTtob37thF7l/5N6vLrK2COJoADLEoHFiQTFixy bpxw== 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; bh=1eyr2HPD23KD1LLUrHugt9+M3HlPepGULzVHZPxVl9M=; fh=X0kT1+hjUyC3dXa4KDNLFXU6BTNiUKwzU7Q+P/tRGs4=; b=ztrqqJpR98UVYu/cItcaMWwSDOkJaEJWjYT8bjLPbn703/I94BwuopQia68TVNbFu+ Gld1Mbh+W5fkQkpneNu6z+rk6ZzrHxYjzlOWcRfp2wGg9Ooi7iHq4507FvZIbDhWUoFS wtw2GNhWcwzXxoCrrF1lQezKcAPN/sJFxPoQDx0vCA9bsCad/Ljz/GYL63GOQT2cYk9e Fydh2dmZxpG7YlIuMEsscDhj/m27ONGqmraYxL1SZEsQaPbIv/plxkXfDr0Mw5eaBGgE uIjzXmDFeUe45/eWxyFX++uM5l/Nl6bv0XpSZGdHbqmJJgqnPhrTjh7rONa96fnx0L0H G6eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b8-20020a170902e94800b001c432da203asi5905927pll.270.2023.11.13.05.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:01:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BCD6B8098B0E; Mon, 13 Nov 2023 05:01:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231396AbjKMNBM (ORCPT + 29 others); Mon, 13 Nov 2023 08:01:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231191AbjKMNAs (ORCPT ); Mon, 13 Nov 2023 08:00:48 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C624C172D; Mon, 13 Nov 2023 05:00:44 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STTvD12YMzMmpm; Mon, 13 Nov 2023 20:56:08 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 13 Nov 2023 21:00:41 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Yisen Zhuang , Salil Mehta , Eric Dumazet Subject: [PATCH RFC 7/8] net: hns3: temp hack for hns3 to use dmabuf memory provider Date: Mon, 13 Nov 2023 21:00:39 +0800 Message-ID: <20231113130041.58124-8-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231113130041.58124-1-linyunsheng@huawei.com> References: <20231113130041.58124-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 13 Nov 2023 05:01:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782453908380579649 X-GMAIL-MSGID: 1782453908380579649 Signed-off-by: Yunsheng Lin --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 06117502001f..43454aa6a279 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -3371,6 +3371,8 @@ static int hns3_alloc_buffer(struct hns3_enet_ring *ring, struct page *p; if (ring->page_pool) { + struct page_pool_iov *ppiov; + p = page_pool_dev_alloc_frag(ring->page_pool, &cb->page_offset, hns3_buf_size(ring)); @@ -3378,7 +3380,8 @@ static int hns3_alloc_buffer(struct hns3_enet_ring *ring, return -ENOMEM; cb->priv = p; - cb->buf = page_address(p); + ppiov = cb->priv; + cb->buf = page_address(ppiov->page); cb->dma = page_pool_get_dma_addr(p); cb->type = DESC_TYPE_PP_FRAG; cb->reuse_flag = 0; @@ -4940,7 +4943,7 @@ static void hns3_put_ring_config(struct hns3_nic_priv *priv) static void hns3_alloc_page_pool(struct hns3_enet_ring *ring) { struct page_pool_params pp_params = { - .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .flags = 0,//PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, .order = hns3_page_order(ring), .pool_size = ring->desc_num * hns3_buf_size(ring) / (PAGE_SIZE << hns3_page_order(ring)), @@ -4949,6 +4952,8 @@ static void hns3_alloc_page_pool(struct hns3_enet_ring *ring) .dma_dir = DMA_FROM_DEVICE, .offset = 0, .max_len = PAGE_SIZE << hns3_page_order(ring), + .memory_provider = PP_MP_DMABUF_DEVMEM, + .mp_priv = &dmabuf_devmem_ops, }; ring->page_pool = page_pool_create(&pp_params); From patchwork Mon Nov 13 13:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 164468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1183128vqg; Mon, 13 Nov 2023 05:02:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcE0WO5ChfszArZ0gP7Sjs5UDyo4svtw7gSZ9Rm2XQxUTKmXLwqAkPDeHPtFTQUfRCd55y X-Received: by 2002:a05:6a20:7f99:b0:184:26d8:db7e with SMTP id d25-20020a056a207f9900b0018426d8db7emr10682281pzj.14.1699880531290; Mon, 13 Nov 2023 05:02:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699880531; cv=none; d=google.com; s=arc-20160816; b=LvwrPavSPYWEiVcDHh8oViFF8yvx4/6FOZtXBogFcXdw++pEY3Rp6WWwxmSvGIIUo8 1zUyaLmT+PCYx/EvvFFwquZRyTj0BYLHlncjGuJMdt1P9idaU2h6cH3hJexpZeUsqZVK +c4qo3p0FvdasZomJ2TVDMdnn0WWJhinJFCUxhrYp3NIZHxnahFUVH+0RDVCXrIDi9O1 pVR/P+eP2SNW4nvS+eRdaQHtOWC+oq989vyiPZGbTg67vF55S7Bix4h55RM6kctRIua0 D/pPnEMSYncV3SIJnXFrEbcczo27eXNNXA8/WLNjuqRsmWsfItaPfwJydtJgWYlOmbHK 8/nQ== 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; bh=yprYwkuv2QMnHlT2eUBfdWw1OEs3H1kZidn2ZZzPvm8=; fh=D6xVSegNul4KrUJ9ERmiGKlse4yUgZ/4HEoMM009vXk=; b=SN3sN1I3s2MAGcXmKviPrSDUJCdUuimu09kR8UfNO1BjCk6m/bp3t0XGsRLxcCxVOL WbM6LYdM0w7Hjb1w4OH+zdwYP0mrHJQYnz//NZBSBDAmji+oxliQjHwDy309zCmsvR+5 GmQ4I+9nvnEPxsAPnpBVpVcFuqtNT/B3k3RBXO5E7lFXec4CqY0HM3E4e7MzihfVL8jx 3VQLI8EUXOLTwi97i7jUwljDVhYCZPOwxsuZUNPRjVsJvuItIak38IeFfHIHP1Y3cD7F BULJdUaEEN/YyaHO5vwdLOYHnBoCfRSTAGa01usiVsqgmhan+nv6ubyc+PIhHX1+VCrL Fzaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s12-20020a056a00194c00b006bddac4b018si5775586pfk.107.2023.11.13.05.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:02:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CA412802FB90; Mon, 13 Nov 2023 05:01:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231232AbjKMNBZ (ORCPT + 29 others); Mon, 13 Nov 2023 08:01:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbjKMNAz (ORCPT ); Mon, 13 Nov 2023 08:00:55 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC7FF1727; Mon, 13 Nov 2023 05:00:51 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4STV0G0LFJzWhLY; Mon, 13 Nov 2023 21:00:30 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 13 Nov 2023 21:00:50 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Eric Dumazet Subject: [PATCH RFC 8/8] net: temp hack for dmabuf page in __skb_datagram_iter() Date: Mon, 13 Nov 2023 21:00:40 +0800 Message-ID: <20231113130041.58124-9-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231113130041.58124-1-linyunsheng@huawei.com> References: <20231113130041.58124-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 13 Nov 2023 05:01:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782453927874241496 X-GMAIL-MSGID: 1782453927874241496 Signed-off-by: Yunsheng Lin --- net/core/datagram.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/core/datagram.c b/net/core/datagram.c index 103d46fa0eeb..5556782ac658 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -436,7 +436,15 @@ static int __skb_datagram_iter(const struct sk_buff *skb, int offset, end = start + skb_frag_size(frag); if ((copy = end - offset) > 0) { struct page *page = skb_frag_page(frag); - u8 *vaddr = kmap(page); + u8 *vaddr; + + if ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) { + struct page_pool_iov *ppiov = (struct page_pool_iov *)page; + + page = ppiov->page; + } + + vaddr = kmap(page); if (copy > len) copy = len;