From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793349349; b=t4EYE23fKgkR4LXp4CARAYzqrcl1inDgORSp3+DwvgZQNuJtOBxJPNe+RVbdDmZiS+tm 6xp7X60Od2QUNQYGCWz0LzG8qW78WFvXi77nH+Yiddwyn6cw916ChlOHrLV6XTDHEtJs+ r6FLURo69gPdeLMg0OuvlgdqVRN0m6fj/zhcj0dWkAUr9V+NNTQ9kDdNmiPgMkBgt+xfv 1iZeDuidRlC5OsxSMuYFMuLucbcd+Y2ton1R45kijyWoKtkYt0Ac1VITSpOGoB4nYc7I1 Ru+aR8NaQVpM+27ZAJQiv4uzj911FyzVeEmt/mtdvrv9fLx64cbjvVVqLP/unnuO4uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793349349; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=F0zE/6OtBk5Lv6PuQXE1z46Ii6lr5+GgEZoby1iAKkE=; b=PMoUHEuN60adiVIkDLHaYmqL1UJTFDWGJA4nxI8bKetb9n3yDdeyPA5G2BW4xKmXGXjF pb/kJEE4gobm5oPLteQl9zJvn9FgkYvxnd9/wVzaOwNljIXxlHZ+OucN+uRmWEicMku57 jpLuaMoWm9cGnbcflewQnswajLpXEIZoPFY/0gKCHQC7TrDge2dcEh0kxl8FdDSp591sR CfoZTGHiDtz3e59wbywiCAoaBmgkPTS6RzUSZ1Sbt7IRHVIZx1RQbLAgIQQHBjBEAT4vJ pJ1XVh0ekc3mf7TOU8w47wsf/4NpmwzBRlGKoRSFznoUkZ9oaA9DZD1ckwAZ4P8+VIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ek+dUlQH; arc=none smtp.remote-ip=74.125.82.69 Received: from mail-dl1-f69.google.com (mail-dl1-f69.google.com [74.125.82.69]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7030060A261A for ; Fri, 30 Oct 2026 08:35:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7030060A261A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ek+dUlQH Received: by mail-dl1-f69.google.com with SMTP id a92af1059eb24-1aa0fb7f157so876598c88.0 for ; Fri, 30 Oct 2026 01:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793349344; x=1793954144; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=F0zE/6OtBk5Lv6PuQXE1z46Ii6lr5+GgEZoby1iAKkE=; b=ek+dUlQHB83eBDtH+ieQMbvMLppVX0fHaHuX9mL0dnqTY73uM9uQ+YwHHEGJUEiNVy gFmFwxlkVH0BPr2X3Z++j1DaxMFiwmZofQHEGXQmnAolviKCRTuhNUy5sNeUtTND/Nu2 dgS+NC+V0UBaTv6UfAF8AgYptcznpgM2+ESHHxF76iTIi02Kyb9eXkoZsXOaELvZvW/v 1aTX3rmi6UdssW9zShCKm9lVTavxPbQf5S0vIpYXSY5J0kEudQCD5oLvPhsTrzvMDjNP 3VlnmVQZT0qSvC8KxSLIVeLui2fJVOhp7LWOuyriKjQz9WAkCmH/A3iTa/rYnUk4ejdm UGDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793349344; x=1793954144; h=content-type: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:content-type; bh=F0zE/6OtBk5Lv6PuQXE1z46Ii6lr5+GgEZoby1iAKkE=; b=0y34WdrrTBGMVDu3/pX7yvZWY8x+UYZYMZU0spsUgf7fCdXykcbfaZRNYG+6npcDn0 UTJHekYIGbYnpLBVnf0IiPKgSxpGYuyDJRjiD6CskE5PV1BdMBmqnMwbwSckA2ArgfYA m7EOISk9k/tOjUTJ+ih1dACF+xQMDhuYOR2N3/nFD/bvwfvvFxTTXMd2mQPS5hwAQJdY WLioG7FSeY10pWuACCruPOJGYBP7vFvxVP30DC/5w8pg/lRrEs1XfWkvuS0GQ4W1zzn4 pVHJMnEmDmrCGjJtZWzccSc6TzgQyucj4OU+6JEaHrCrOXdyda/9kAWwoIOkCnOYwt9w i64g== X-Gm-Message-State: AFq9FYJmArIMRI71c8so3t4odIMDV0KIQVHl+tUtEEiNThpInt5mp892 o+idz5HSma0jrfOoYKHPL8kYgtgzPRwaHueyYu84lUEiTui6aMrmbL8wIGwvektIWzWeV2E4k+f oUA1W3OC/61V3AFFPtyLpriXhy7tw+0ZJRs+pGDwXOtbKm4R037919HHuVrqdtJ4+n/fimGHLB8 hDUn1zPCG+wqjkvCb2P+79N45c8m6jfd4TxhfBaZZJswqKdxcGu5hictLcIYloyv4= X-Received: from dlbec15.prod.google.com ([2002:a05:7022:d8f:b0:19f:9e93:9354]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7023:904:b0:168:3243:c907 with SMTP id a92af1059eb24-1ad85de518fmr460495c88.24.1793349343177; Fri, 30 Oct 2026 01:35:43 -0700 (PDT) Date: Fri, 30 Oct 2026 08:35:37 +0000 In-Reply-To: <20261030083539.777877-1-almasrymina@google.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261030083539.777877-1-almasrymina@google.com> X-Mailer: git-send-email 2.56.0.385.gac671c819a-goog Message-ID: <20261030083539.777877-4-almasrymina@google.com> Subject: [PATCH net v5 3/4] netdevsim: support devmem RX and TX bindings From: Mina Almasry To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, Paolo Abeni , Stanislav Fomichev , Mina Almasry , Kaiyuan Zhang , Jakub Kicinski , Bobby Eshleman , Pavel Begunkov , David Wei , Taehee Yoo Cc: "David S. Miller" , Eric Dumazet , Simon Horman , Shuah Khan , Sumit Semwal , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Philipp Stanner , Andrew Lunn , Stanislav Fomichev , Jesper Dangaard Brouer , Ilias Apalodimas , Daniel Borkmann , Nikolay Aleksandrov , Tariq Toukan , Kaifeng Wang , Dragos Tatulea Content-Type: text/plain; charset="UTF-8" Set a 64-bit DMA mask and UINT_MAX max segment size on nsim_bus_dev in nsim_bus_probe() when direct DMA mapping is supported, enable NETMEM_TX_DMA on the netdevsim net_device, and configure page_pool instances with PP_FLAG_ALLOW_UNREADABLE_NETMEM and queue_idx, plus PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV when a DMA mask and PP_DMA_INDEX_BITS are available, so devmem bind-rx and bind-tx netlink operations can be tested against netdevsim in software selftests. The pp_hold debugfs file allocates pages from the queue 0 page pool, so refuse it when that pool is absent or backed by a memory provider, and take the netdev instance lock there so a concurrent bind-rx cannot swap the pool in between. Since netdevsim forwards TX skbs in software without a DMA engine, drop unreadable or net_iov skbs in nsim_start_xmit(). Cc: Tariq Toukan Cc: Kaifeng Wang Signed-off-by: Mina Almasry Reviewed-by: Dragos Tatulea Acked-by: Stanislav Fomichev --- v5: - Configure the DMA mask and dma_parms in nsim_bus_probe() gated on dma_pci_p2pdma_supported(), and require PP_DMA_INDEX_BITS before setting PP_FLAG_DMA_MAP so page_pool_scrub() can unmap inflight pages on 32-bit builds (Sashiko). - Check for NULL ns->rq in nsim_pp_hold_write() and drop unreadable or net_iov skbs at the start of nsim_start_xmit() (Sashiko). v3: - Only request page pool DMA mapping when CONFIG_HAS_DMA is set (Sashiko). - Refuse pp_hold on a page pool backed by a memory provider, under the netdev instance lock (Sashiko). - Drop unreadable skbs in the software PSP path when it would have to checksum the payload (Sashiko). --- drivers/net/netdevsim/bus.c | 9 +++++++++ drivers/net/netdevsim/netdev.c | 33 +++++++++++++++++++++++++------ drivers/net/netdevsim/netdevsim.h | 1 + 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index b792ee10b1c1a..5f8f0c2f76939 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -416,6 +417,14 @@ static int nsim_bus_probe(struct device *dev) { struct nsim_bus_dev *nsim_bus_dev = to_nsim_bus_dev(dev); + if (dma_pci_p2pdma_supported(dev) && + !dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64))) { + dev->dma_parms = &nsim_bus_dev->dma_parms; + dma_set_max_seg_size(dev, UINT_MAX); + } else { + dev->dma_mask = NULL; + } + return nsim_drv_probe(nsim_bus_dev); } diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index eebc02ccc4a92..0372a9bd63bbb 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -133,6 +133,10 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev) int dr; rcu_read_lock(); + if (!skb_frags_readable(skb) || + (skb_shinfo(skb)->nr_frags && + skb_frag_is_net_iov(&skb_shinfo(skb)->frags[0]))) + goto out_drop_any; if (!nsim_ipsec_tx(ns, skb)) goto out_drop_any; @@ -422,19 +426,27 @@ static int nsim_poll(struct napi_struct *napi, int budget) return done; } -static int nsim_create_page_pool(struct page_pool **p, struct napi_struct *napi) +static int nsim_create_page_pool(struct net_device *dev, struct page_pool **p, + struct napi_struct *napi, int idx) { + struct netdevsim *ns = netdev_priv(dev); struct page_pool_params params = { .order = 0, .pool_size = NSIM_RING_SIZE, + .flags = PP_FLAG_ALLOW_UNREADABLE_NETMEM, + .max_len = PAGE_SIZE, .nid = NUMA_NO_NODE, - .dev = &napi->dev->dev, + .dev = &ns->nsim_bus_dev->dev, .napi = napi, .dma_dir = DMA_BIDIRECTIONAL, - .netdev = napi->dev, + .netdev = dev, + .queue_idx = idx, }; struct page_pool *pool; + if (ns->nsim_bus_dev->dev.dma_mask && PP_DMA_INDEX_BITS) + params.flags |= PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV; + pool = page_pool_create(¶ms); if (IS_ERR(pool)) return PTR_ERR(pool); @@ -458,7 +470,7 @@ static int nsim_init_napi(struct netdevsim *ns) for (i = 0; i < dev->num_rx_queues; i++) { rq = ns->rq[i]; - err = nsim_create_page_pool(&rq->page_pool, &rq->napi); + err = nsim_create_page_pool(dev, &rq->page_pool, &rq->napi, i); if (err) goto err_pp_destroy; } @@ -770,14 +782,16 @@ nsim_queue_mem_alloc(struct net_device *dev, if (ns->rq_reset_mode == 1) { if (!netif_running(ns->netdev)) return -ENETDOWN; - return nsim_create_page_pool(&qmem->pp, &ns->rq[idx]->napi); + return nsim_create_page_pool(dev, &qmem->pp, + &ns->rq[idx]->napi, idx); } qmem->rq = nsim_queue_alloc(); if (!qmem->rq) return -ENOMEM; - err = nsim_create_page_pool(&qmem->rq->page_pool, &qmem->rq->napi); + err = nsim_create_page_pool(dev, &qmem->rq->page_pool, &qmem->rq->napi, + idx); if (err) goto err_free; @@ -937,12 +951,16 @@ nsim_pp_hold_write(struct file *file, const char __user *data, return ret; rtnl_lock(); + netdev_lock(ns->netdev); ret = count; if (val == !!ns->page) goto exit; if (!netif_running(ns->netdev) && val) { ret = -ENETDOWN; + } else if (val && (!ns->rq || + page_pool_is_unreadable(ns->rq[0]->page_pool))) { + ret = -EOPNOTSUPP; } else if (val) { ns->page = page_pool_dev_alloc_pages(ns->rq[0]->page_pool); if (!ns->page) @@ -954,6 +972,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data, } exit: + netdev_unlock(ns->netdev); rtnl_unlock(); return ret; } @@ -1059,6 +1078,8 @@ static int nsim_init_netdevsim(struct netdevsim *ns) ns->netdev->netdev_ops = &nsim_netdev_ops; ns->netdev->stat_ops = &nsim_stat_ops; ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops; + if (ns->nsim_bus_dev->dev.dma_mask) + ns->netdev->netmem_tx = NETMEM_TX_DMA; netdev_lockdep_set_classes(ns->netdev); err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index fd5599cd3bb9f..2aa7ea924396e 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -476,6 +476,7 @@ int nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, #define NSIM_BUS_DEV_MAX_VFS 4 struct nsim_bus_dev { struct device dev; + struct device_dma_parameters dma_parms; struct list_head list; unsigned int port_count; unsigned int num_queues; /* Number of queues for each port on this bus */ -- 2.56.0.385.gac671c819a-goog