From patchwork Mon Jul 10 22:33:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 118127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp114192vqm; Mon, 10 Jul 2023 15:39:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEavLqIxQF8064cOM/2RJwUGJJuraN5zvUHvmyK0/Ilf5OuWHMiGO5WsqOytSZiODQbsXC X-Received: by 2002:a17:906:4f97:b0:96f:1f79:c0a6 with SMTP id o23-20020a1709064f9700b0096f1f79c0a6mr13123932eju.70.1689028792834; Mon, 10 Jul 2023 15:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689028792; cv=none; d=google.com; s=arc-20160816; b=JOBjWBpmPlsegTL0LfPwpa3v0SHWqILYJvAYvV7FR5ELeRSaqsnZEYfnSmwsit/O2j 4PKfilS236+VAbXDu+gHnXyKLjZn15fhyYFQHBvM1ZLs4WnziKO6qPQ7X4VXWdA2gwr/ f8RmOmfKNY9qai54d6D0uTsSnDUyN/haU2BYVxjt2BhOImJjoA9MiM6WsP73xuQ0awh7 DGBsWq+AckRxMsKgpyDgYnvEJLpHO6Fj9xfkGo6OatSpA578AeRVJjw7gNgJ5xGao1YM BP+7E0ZzUO5Y42oBbHe4OL9hsaDUkRHKjQzO4cmTvYA/hB9qRcBQHExGgxsaa6QqU4GV hCdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=UnMZL8UhzWb/0aBP8bCpuACSexb4BfJiKzPPZTajpks=; fh=55VxVtf/wwatkgb/EP05SgBT89BC1zibP0SY8oI5qug=; b=Iv6JqIoqV8DF+4pHBf13c+0H5GLqMCQ62GS2sLN0kmwOPMbuW0skUnRON0wtjbq/5A LKSnQfiyFuA5XsAflujSmgGLnCqoQjYH+sJAm3Xw4yFbcAjxHGdMetdf/ns+5HIifdRX XtJvsPbd9RWaRNS8SI1ie0McBasVJI8S7NvI0iQQnclo1S8LKZO2N+8/EM7a6SAzT3I5 uwWJjGV3CQcpaUT9yNRTfXgdHCFVhk1+foUQQ5qbZEXAt0LIs/7ZYSh98wC+tW+R3f+Y 8Ro1DHSzUpyaJGVT/UbmFed+d5WX+zXMTZAN32yo/qf0HbF8n6SDwQvhNtgdF41kTi1p bIOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="ZycEIM/t"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p19-20020a170906b21300b0098e417a0c3bsi651533ejz.109.2023.07.10.15.39.28; Mon, 10 Jul 2023 15:39:52 -0700 (PDT) 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=@google.com header.s=20221208 header.b="ZycEIM/t"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231195AbjGJWff (ORCPT + 99 others); Mon, 10 Jul 2023 18:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbjGJWfb (ORCPT ); Mon, 10 Jul 2023 18:35:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FE761707 for ; Mon, 10 Jul 2023 15:34:54 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c0f35579901so5919511276.0 for ; Mon, 10 Jul 2023 15:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689028459; x=1691620459; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UnMZL8UhzWb/0aBP8bCpuACSexb4BfJiKzPPZTajpks=; b=ZycEIM/tzN0od6DMdpG2ZBlkJqdG/YaEAiXfT+38tW9bimX5mFjLfnmha8sMd1FwJJ P1YTcXkuScRdFZ+6Nke3Sdy4NjMA2W+JEp3F6Wzh3QRgc3G5LGn1Zu1iHZ4RyIqBjoHq k9jtQN4DN+tPVpc1G/NOC+sNs6OMyg6jWMhgxeuaJcoDHd6HbM1Xh1fktrKhCJh7t8TZ 2mOqQGiKrSnTwbDIJsz/RpKI8MeOMnJHXoAtfD0XSqgWhXjbLkfzJLjhD09BOkgZES0H docmIVXKHe4UX6CgXt/bh6mysKACg9wyOus054kiN2CxJmmkeSAQzjRyHNih7/Suny73 Z7kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689028459; x=1691620459; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UnMZL8UhzWb/0aBP8bCpuACSexb4BfJiKzPPZTajpks=; b=ACKhdyLRgmh0fbCHDMWtO8fLmhtC9dptejyxnCz2WDH9LgmIRBbxgDu1ucMA7soNp9 I30vh07oYqUGf3IAZt3K7W8D+8njITQf742vpUtOYfebojWo8sWhpMoBFwtEoEYb8zUo OhyjpGUTA0CKvinKWoXp+bgpwLGbiscpWuFlA2Akbv6vysC05PK3CV/O/CnFeaBodBmX TLq94efFazL0G12/FDSmXSqeas3SIeJkFy+2GFjoN/Dab2qEq/zQKe6e49PLluiCHj3X 6inp/+FTen5+A4urQWLXWrikomhmeVnZLXzOfvxNclG8P9mDoHXGmLFeWn1mmQ/MB8jN 0JMA== X-Gm-Message-State: ABy/qLbvTrabec6BwvJ3yJBZIPDuz5x1YjLd6sB37l7f+Z1o2w/Tx+Y7 y73/24JVrAO5AcXecjpXN7TI8yexc4+XSO/WxEgnLt3b3K1T2Fo4B3NDqM2nYdoSzuSHyNula8i BHWn+9T2aDT9MsSp8N9UgaJbtBaQTBxYzyVnkEI2fvIfV2CN60DUHJEsv1NjYj0HpAQ0+S64svY HrioiLjKA= X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:4c0f:bfb6:9942:8c53]) (user=almasrymina job=sendgmr) by 2002:a25:11c6:0:b0:c85:934:7ad2 with SMTP id 189-20020a2511c6000000b00c8509347ad2mr21545ybr.8.1689028458996; Mon, 10 Jul 2023 15:34:18 -0700 (PDT) Date: Mon, 10 Jul 2023 15:33:00 -0700 In-Reply-To: <20230710223304.1174642-1-almasrymina@google.com> Mime-Version: 1.0 References: <20230710223304.1174642-1-almasrymina@google.com> X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog Message-ID: <20230710223304.1174642-10-almasrymina@google.com> Subject: [RFC PATCH 09/10] memory-provider: updates core provider API for devmem TCP From: Mina Almasry To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, netdev@vger.kernel.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , Sumit Semwal , " =?utf-8?q?Christian_K=C3=B6nig?= " , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , Ilias Apalodimas , Arnd Bergmann , David Ahern , Willem de Bruijn , Shuah Khan , jgg@ziepe.ca X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771075055289682833 X-GMAIL-MSGID: 1771075055289682833 Implement a few updates to Jakub's RFC memory provider API to make it suitable for device memory TCP: 1. Currently for devmem TCP the driver's netdev_rx_queue holds a reference to the dma_buf_pages struct and needs to pass that to the page_pool's memory provider somehow. For PoC purposes, create a pp->mp_priv field that is set by the driver. Likely needs a better API (likely dependant on the general memory provider API). 2. The current memory_provider API gives the memory_provider the option to override put_page(), but tries page_pool_clear_pp_info() after the memory provider has released the page. IMO if the page freeing is delegated to the provider then the page_pool should not modify the page after release_page() has been called. Signed-off-by: Mina Almasry --- include/net/page_pool.h | 1 + net/core/page_pool.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/net/page_pool.h b/include/net/page_pool.h index 364fe6924258..7b6668479baf 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -78,6 +78,7 @@ struct page_pool_params { struct device *dev; /* device, for DMA pre-mapping purposes */ struct napi_struct *napi; /* Sole consumer of pages, otherwise NULL */ u8 memory_provider; /* haaacks! should be user-facing */ + void *mp_priv; /* argument to pass to the memory provider */ enum dma_data_direction dma_dir; /* DMA mapping direction */ unsigned int max_len; /* max DMA sync memory size */ unsigned int offset; /* DMA addr offset */ diff --git a/net/core/page_pool.c b/net/core/page_pool.c index d50f6728e4f6..df3f431fcff3 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -241,6 +241,7 @@ static int page_pool_init(struct page_pool *pool, goto free_ptr_ring; } + pool->mp_priv = pool->p.mp_priv; if (pool->mp_ops) { err = pool->mp_ops->init(pool); if (err) { @@ -564,16 +565,16 @@ void page_pool_return_page(struct page_pool *pool, struct page *page) else __page_pool_release_page_dma(pool, page); - page_pool_clear_pp_info(page); - /* This may be the last page returned, releasing the pool, so * it is not safe to reference pool afterwards. */ count = atomic_inc_return_relaxed(&pool->pages_state_release_cnt); trace_page_pool_state_release(pool, page, count); - if (put) + if (put) { + page_pool_clear_pp_info(page); 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).