From patchwork Mon Jul 10 22:32:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 118133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp118240vqm; Mon, 10 Jul 2023 15:50:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlElQ+qZ69uUYW3hX3/AqJ3Gy1zBlGkBe0DF4sbHxJZKMShgByPdE7Fy9Erdp80hz565ChDT X-Received: by 2002:a17:906:7a5a:b0:993:d589:8b75 with SMTP id i26-20020a1709067a5a00b00993d5898b75mr14377039ejo.2.1689029457123; Mon, 10 Jul 2023 15:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689029457; cv=none; d=google.com; s=arc-20160816; b=MlLunvcOCijbf7BYFc5vRgWyrZ86MYPDay1vlmDvdpqJ5vwbmoi4zHvLRSrGZcZk0r nv+oiMk4nozgsGSsjNT0fvKOtpQXck0mPmPAUywcEAIFZfGx3ZqtNBs5qHu7cIO48/zL 5nOn5axn414zSl5bO6Z62SVu+I2jtKBkHvZsCLOMnZecnkMoMPPFQDoqTNUAudUQlbIZ xISH0sl/xTybwfXgy0+40AtICRrHXrOXjKy11DsOg/QCuMjIhTIFLePSE6PDz3wlAOVM exHkTxFBt0Ocy2FwyPQa993MgHeCyfOrOqSrw7FYeo+tIVvlJw1JrPlS8K4WDQ2SARkt NDwQ== 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=ZtAFtzT26HwoXDlgQMNRwGQzav+ArXt3GcR/tyBO9gA=; fh=55VxVtf/wwatkgb/EP05SgBT89BC1zibP0SY8oI5qug=; b=alb0VR/KmT4yBas6pLbBXrVDPkzxPE0rJGsc2TGRNTOtdaCM5qm3jJTbF1YH5rzIVD Gz+JbLvPdGUn7XRE8UXdmE8EzNwUGELWv3yC9ys6YUihDD9rm3rSzY1IERURdcwFh2UD fdqdMKxn+R5dnxVrAvSIZGWNxk51VfADPVZClxiudIZqxv4izuwp1gZThgtHH+nA7mB1 XI6CpAYfjge1QufsqWPSZP5NJLH4kfnpObAkPtRVk8DdGom4AMO+1MG8CYg0kh2Z2FgA rI4M+7pk1fbdLB/0KLo2527/ecREFJf+Lu7xRVEXILxeEzBsvN6djVC34ezbCyUtUiW0 QM2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=HkBlwseb; 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 v6-20020a170906564600b009929280d0dfsi632219ejr.434.2023.07.10.15.50.33; Mon, 10 Jul 2023 15:50:57 -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=HkBlwseb; 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 S230406AbjGJWeG (ORCPT + 99 others); Mon, 10 Jul 2023 18:34:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjGJWeA (ORCPT ); Mon, 10 Jul 2023 18:34:00 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97746E55 for ; Mon, 10 Jul 2023 15:33:53 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-57059e6f9c7so73873987b3.0 for ; Mon, 10 Jul 2023 15:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689028432; x=1691620432; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZtAFtzT26HwoXDlgQMNRwGQzav+ArXt3GcR/tyBO9gA=; b=HkBlwsebRlph1pf39ww19ir3TXRKAaMo7qsHRnHvMwd7eaBtsd+aEsyn2PFrjYVPN/ Q1m2zbfqNxMH7b2QmwqEmx7Hw8+0VDdPsjPbv5ClyeuSbRANbqwhxJwBlxKfNPSzGspo 7yQorKtO9RR3lY8Caocl1cEReHVAh3gKZjRNe8K/5mwfYof1P1cHyHw8LwIbAtpadOQi xt/cqEvGCmmTBBOu377T/OItahks2lVVcdnKMKB3565gPdYG/TvH20z3G9f0jRiObQC7 /Ikbp8b7IOidW9ZdGHVTIfQ7XQf/3jcuOVmetsVhHpuKf5wo9wt+kW67ruZRHH/8+c9U xfJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689028432; x=1691620432; 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=ZtAFtzT26HwoXDlgQMNRwGQzav+ArXt3GcR/tyBO9gA=; b=D56Xum9Fe7I35d1nknbKkP2EmR3UgB3h82bbHJblU/zjOJxdwUL5WpMKn3iASlq4ZX nv3E+chyWlvE8VMNKEI6n+QtEyTzBsSWBUPg2SHMRYLrIrwxpcQfUzCXmiPI9sr7hfn6 2OeANfo1wYiT/XSOhGcRUfd+zBPXsqucadVddXnfZqF4+LBhxnhUcasLbom2JKJTGsAc F9WFYkI9dFivz3qCJTDnDb53a980LADCvNdpdfexkfJe2DaFva+WrLzJ0Ryi4XVCEPSd 9jO7fTVIy59gq3am4krgTPFaHgG0Zl11kW5kWWGp4VUQ86Jj3epjBr1tjeS7dnQVsSBT WFRA== X-Gm-Message-State: ABy/qLa4wHonWGXvMhEszmdR2+89flQ7Dt7oRsy9j3+FQgI/78GNTcpb +JnKiG6cQ4tptrf0UyGKsRsGxmlAr2itaVjX1zo7yIjRfJF2ovzMK1x2sb1iHOOfju7B7f9WaY2 Hfyb3qVWcW/yq6HjT1w/OaaGu69f9iXiKthVYjivMhzx+7qOqjJQsuTtf8gk6c3kARlaX8VIu79 g30G/lE3g= X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:4c0f:bfb6:9942:8c53]) (user=almasrymina job=sendgmr) by 2002:a81:7e0c:0:b0:56c:e9fe:3cb4 with SMTP id o12-20020a817e0c000000b0056ce9fe3cb4mr204351ywn.1.1689028432231; Mon, 10 Jul 2023 15:33:52 -0700 (PDT) Date: Mon, 10 Jul 2023 15:32:54 -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-4-almasrymina@google.com> Subject: [RFC PATCH 03/10] dma-buf: add support for NET_TX pages 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_NONE, 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: 1771075751922743446 X-GMAIL-MSGID: 1771075751922743446 Used the paged attachment mappings support to create NET_TX pages. NET_TX pages can be used in the networking transmit path: 1. Create an iov_iter & bio_vec entries to represent this dmabuf. 2. Initialize the bio_vec with the backing dmabuf pages. Signed-off-by: Mina Almasry --- drivers/dma-buf/dma-buf.c | 47 ++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 7 ++++++ include/uapi/linux/dma-buf.h | 1 + 3 files changed, 55 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index acb86bf406f4..3ca71297b9b4 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1683,6 +1683,7 @@ static void dma_buf_pages_destroy(struct percpu_ref *ref) } const struct dma_buf_pages_type_ops net_rx_ops; +const struct dma_buf_pages_type_ops net_tx_ops; static long dma_buf_create_pages(struct file *file, struct dma_buf_create_pages_info *create_info) @@ -1799,6 +1800,9 @@ static long dma_buf_create_pages(struct file *file, case DMA_BUF_PAGES_NET_RX: priv->type_ops = &net_rx_ops; break; + case DMA_BUF_PAGES_NET_TX: + priv->type_ops = &net_tx_ops; + break; default: err = -EINVAL; goto out_put_new_file; @@ -2140,3 +2144,46 @@ struct page *dma_buf_pages_net_rx_alloc(struct dma_buf_pages *priv) percpu_ref_get(&priv->pgmap.ref); return pg; } + +/******************************** + * dma_buf_pages_net_tx * + ********************************/ + +static void dma_buf_pages_net_tx_release(struct dma_buf_pages *priv, + struct file *file) +{ + int i; + for (i = 0; i < priv->num_pages; i++) + put_page(&priv->pages[i]); +} + +static int dma_buf_pages_net_tx_init(struct dma_buf_pages *priv, + struct file *file) +{ + int i; + priv->net_tx.tx_bv = kvmalloc_array(priv->num_pages, + sizeof(struct bio_vec), GFP_KERNEL); + if (!priv->net_tx.tx_bv) + return -ENOMEM; + + for (i = 0; i < priv->num_pages; i++) { + priv->net_tx.tx_bv[i].bv_page = &priv->pages[i]; + priv->net_tx.tx_bv[i].bv_offset = 0; + priv->net_tx.tx_bv[i].bv_len = PAGE_SIZE; + } + percpu_ref_get_many(&priv->pgmap.ref, priv->num_pages); + iov_iter_bvec(&priv->net_tx.iter, WRITE, priv->net_tx.tx_bv, + priv->num_pages, priv->dmabuf->size); + return 0; +} + +static void dma_buf_pages_net_tx_free(struct dma_buf_pages *priv) +{ + kvfree(priv->net_tx.tx_bv); +} + +const struct dma_buf_pages_type_ops net_tx_ops = { + .dma_buf_pages_init = dma_buf_pages_net_tx_init, + .dma_buf_pages_release = dma_buf_pages_net_tx_release, + .dma_buf_pages_destroy = dma_buf_pages_net_tx_free, +}; diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index e8e66d6407d0..93228a2fec47 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -555,6 +556,11 @@ struct dma_buf_pages_type_ops { struct page *page); }; +struct dma_buf_pages_net_tx { + struct iov_iter iter; + struct bio_vec *tx_bv; +}; + struct dma_buf_pages_net_rx { struct gen_pool *page_pool; struct xarray bound_rxq_list; @@ -579,6 +585,7 @@ struct dma_buf_pages { union { struct dma_buf_pages_net_rx net_rx; + struct dma_buf_pages_net_tx net_tx; }; }; diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h index b392cef9d3c6..546f211a7556 100644 --- a/include/uapi/linux/dma-buf.h +++ b/include/uapi/linux/dma-buf.h @@ -187,6 +187,7 @@ struct dma_buf_create_pages_info { }; #define DMA_BUF_PAGES_NET_RX (1 << 0) +#define DMA_BUF_PAGES_NET_TX (2 << 0) #define DMA_BUF_CREATE_PAGES _IOW(DMA_BUF_BASE, 4, struct dma_buf_create_pages_info)