From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6957606A31A for ; Wed, 2 Dec 2026 06:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=3iAOJtvi; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=iHiubFGs Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 86F8E80BD4; Wed, 2 Dec 2026 06:57:52 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 0Sx0jedqDMO1; Wed, 2 Dec 2026 06:57:51 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 5DBF380EFD Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796194671; b=JQiIACP5m8kbFH9kfYLzdKsanfdTKsHACyTVyZazgC9nmA/qemCrOa6Yqsecw6Adx6Ds 1Lp9xvXxGb3HHAPbogGPizyQ02U8O8explq2YqIZp6N7r1/R8xhojS6V5F5ZIDu53IQ0j thd79/kZyg79Ualq+Ucd/qq+hKSE14vWYGj3pAEGhnuZNWiieciarPRpmecwDYY+EWXh4 nLy40qXhL682I4GAJ3HASs44n0FFoS+KQKFGryOiGeWda9hG2IjFdIgCQZtnfVSy1cqVg k6AkJxChBHr3xBsYXC3vocR1htxaWNGtt2JSpf5s0i0xS5YP48zVmh9cjEqNIBNuXWg== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796194671; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type: X-BeenThere:X-Mailman-Version:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:Errors-To; bh=BT1UygfA1mphRIeQvIQ+68KfG97nqT84V8ik/cfS9WY=; b=X7BY7hamHvLMmIRbRVQRBwG+Zee8xExUZ+GOIKLVdxMVPn+R3/2rnGVYROF4dpULF9PU Ie2pyepCb4IloIgF0XFgOtu29vmFGEXx87Uv0nDo5UiZ8Oc0B6mk/rSM2/ybk5LDcR7WB F+BvN6z0P3Rx7IazVFs3SBUzGa0C3TfyyD5xXTNSaoph8UuDxT/AG567N84+K4yLiu8XL r0QzRFvM8WHuEoKmyuiqqOt2c1FYw+qNux2PhePY+nzsFJumCq6wj7dojx8shK+UxU46K 0W3+MBGjqy+Ps79OTNUpIZLIn8jQQlHLKb5EblnP6JDVjX+o3hdfiyyvG2a00QdZ2Jg== ARC-Authentication-Results: i=1; smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1796194671; bh=BT1UygfA1mphRIeQvIQ+68KfG97nqT84V8ik/cfS9WY=; h=Date:In-Reply-To:References:Subject:From:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=3iAOJtvioT8fw5/qJKz7SExRXkKmVTK02+O+dt2Pj+eCjkZjuuYVNmfn8Cgb/QsJr 5xDO2wmbLdhIxt9I7oN3HtGWdrGGXl6rVKmS5AE9JUfRWJQHF74ukHkbniKXJyVUGo sxR1iPe/jSPkD4Db7whYse9YHPgH5JuFMz2D2urrmpU+qGj/8aToRRAcNwUglB4eUR TMdxbUKuv3EA7it8LfscJCxthIepq8qXB13r9EmGMzaBokTt5uXb/KG9DO9O6Xcw01 C65hj3nno1hh+p1VUBZPM01i39oJ8IqV5W7RMf0nXEY0Bja/rshyHR3VSvwASkcbRz BGwOyaiu7WL/w== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp1.osuosl.org (Postfix) with ESMTP id 5DBF380EFD; Wed, 2 Dec 2026 06:57:51 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists1.osuosl.org (Postfix) with ESMTP id D59742FF for ; Wed, 2 Dec 2026 06:57:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id C6ED84038B for ; Wed, 2 Dec 2026 06:57:47 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id IdoDeoLoxLPx for ; Wed, 2 Dec 2026 06:57:46 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp2.osuosl.org A9B0240179 Authentication-Results: smtp2.osuosl.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::648" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2607:f8b0:4864:20::648; helo=mail-pl1-x648.google.com; envelope-from=3z8epawykd4gw6zua6s00sxq.o0yuz5qx-8u3qp-xmzxu454.04604x.03s@flex--kuniyu.bounces.google.com; receiver= Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=iHiubFGs Received: from mail-pl1-x648.google.com (mail-pl1-x648.google.com [IPv6:2607:f8b0:4864:20::648]) by smtp2.osuosl.org (Postfix) with ESMTPS id A9B0240179 for ; Wed, 2 Dec 2026 06:57:44 +0000 (UTC) Received: by mail-pl1-x648.google.com with SMTP id d9443c01a7336-2f033dc37cfso119971155ad.0 for ; Tue, 01 Dec 2026 22:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796194664; x=1796799464; darn=lists.osuosl.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=BT1UygfA1mphRIeQvIQ+68KfG97nqT84V8ik/cfS9WY=; b=iHiubFGs8Q7Cd6qkT8F8q35W/Qj1JeJcRpcGt2fDQx+grRiO8FfTxGtT/zDfHmE7z9 xDDGvUxUQg+njGJJ7EjcJ46BGO1V40eyOL7bvxDPrIfYFmv/6Py8LhrtVEzFJ6c2q8b1 6ID76zfjLCvc89UsiYOSeOfKMJr6R3Kc8amWeXG+J3SIzP7zWUW7Bybg1UqtzQtoUfvJ PJSzZT4KsCzaO16dWXPkhn6EA6IQA+0am1S1+oREs5zjcyaOJMo2k03QJDEcOIoQQASC cvmFFGYjEX7npyTuWcqlys2prEzPZNID9aGbhFn8eBow0b/oEmzF0nd6lFMkOw69S46Z EVnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796194664; x=1796799464; 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=BT1UygfA1mphRIeQvIQ+68KfG97nqT84V8ik/cfS9WY=; b=jiySFrF21rpnN4JqJv06DAQ8iLELijYG0ych8tf2VAxTYsFruMjNofwXkpX0Dsh/IG zjgLJgrQI1NN3GmyhUcMZ2MJMqS4U7cRgoAQbDfcEPhHOKO/MaavnY4w1xMCwQevDnTC avPJNLW32Fgm8lwGQXapg/0aq5fMm4lfSLpr0w0JBAs5t9RGW7lQCDQwlTHb0u41tIvg TJjvhfNR7Vb8cGhYHVG4F32M5Z5QSckpBoAV4/GfZR5+gilTEnVwJIsdIfIRKUYPtQG9 6EpyyCR68umYVmf0PV9NBeeqn4MyNlsttL8ZelkH08RBDh3f4MAePp/ta8bf5YBIRaBA BdOg== X-Forwarded-Encrypted: i=1; AL+hErGRGtIA7p0aZf+KJ7rF+zDr/8azeCEq/ZQhEsKojLhxnPtpxCbXuzrWb4lk1+49o/KQ662Off8h8VKU5rmAw/M=@lists.osuosl.org X-Gm-Message-State: APuU4Z8MZMi1NYISi9GOpkbSZlZhNQbI1k+7KM2x1AQi3452FOgt7Qwn WB5w0tMm56VUDvGtUkhN8ekYnKc54YteAeX/c2yI0k236mgVbIcr6g+j0DtFddfsQNtEz0Ouo64 Q4eHLpg== X-Received: from pltj5.prod.google.com ([2002:a17:902:76c5:b0:2f0:6732:5e47]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ec8b:b0:2f0:20cc:32fd with SMTP id d9443c01a7336-2f03f17e8acmr356177605ad.51.1796194663664; Tue, 01 Dec 2026 22:57:43 -0800 (PST) Date: Wed, 2 Dec 2026 15:57:23 +0900 In-Reply-To: <20261202065737.207610-1-kuniyu@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261202065737.207610-1-kuniyu@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202065737.207610-6-kuniyu@google.com> Subject: [PATCH v1 iwl-next 5/5] idpf: Unmap Rx payload pages under DMA-FQ IOMMU. From: Kuniyuki Iwashima To: Alexander Lobakin , Tony Nguyen , Przemek Kitszel Cc: Kuniyuki Iwashima , Kuniyuki Iwashima , intel-wired-lan@lists.osuosl.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 In splitq mode under an IOMMU DMA-FQ domain, page_pool keeps every Rx payload page DMA-mapped until it is released back to the pool. When running tcp_stream with 100000 flows, # tcp_stream -6 --suicide-length=2000 --min-rto=5 --num-threads=256 \ --test-length=30 --num-flows=100000 --num-ports=20 -B 65536 on the server side, Rx payload pages pinned in socket queues saturate the 32-bit IOVA window, causing every subsequent DMA mapping (including Tx in idpf_tx_splitq_frame()) to contend on alloc_iova(), and perf shows heavy contention with 13.8M dropped packets: 21.62% switchto-defaul [kernel.kallsyms] [k] queued_spin_lock_slowpath | ---queued_spin_lock_slowpath _raw_spin_lock_irqsave alloc_iova alloc_iova_fast iommu_dma_alloc_iova __iommu_dma_map __iommu_dma_map_phys iommu_dma_map_phys dma_map_phys idpf_tx_splitq_frame dev_hard_start_xmit sch_direct_xmit __qdisc_run # ethtool -S eth1 | grep -E 'ingress_drop3|rx-hsplit' rx-hsplit: 92006 rx-hsplit_hbo: 393 ingress_drop3.packets: 488310980 # before neper ingress_drop3.bytes: 1989178010650 rx-hsplit: 27779097 rx-hsplit_hbo: 611 ingress_drop3.packets: 502138587 # after neper ingress_drop3.bytes: 2046991419840 # dmesg ... [ 1291.279869] idpf 0000:01:00.0: Using 56-bit DMA addresses On the client side, we can see many retransmissions, and the throughput is 161 Gbps w/ 200G NIC. remote_throughput=161031856462 TcpInSegs 19235891 0.0 TcpOutSegs 225122216 0.0 TcpRetransSegs 20767366 0.0 Even with iommu.forcedac=1, IOVA nodes continue accumulating across the IOMMU rbtree because iova_depot_work_func() drains only one magazine (127 PFNs) every 100 ms, which still leads to alloc_iova() soft lockup under heavy churn. Let's opt out of page_pool DMA mapping when XDP is disabled under IOMMU_DOMAIN_DMA_FQ. Each page tracks active descriptor counts so sub-page fragment sharing and skb truesize remain unchanged while each page is unmapped once all of its descriptors complete. With coherent header split and Rx DMA unmap enabled, we no longer see huge drops on the server side (84K), # ethtool -S eth1 | grep -E 'ingress_drop3|rx-hsplit' rx-hsplit: 29763692 rx-hsplit_hbo: 1782 ingress_drop3.packets: 488226531 # before neper ingress_drop3.bytes: 1988824925613 rx-hsplit: 58004576 rx-hsplit_hbo: 2073 ingress_drop3.packets: 488310980 # after neper ingress_drop3.bytes: 1989178010650 and the throughput recovers to 178 Gbps and retransmissions are reduced by 19x on the client side: remote_throughput=178451793325 TcpInSegs 14033635 0.0 TcpOutSegs 178978164 0.0 TcpRetransSegs 1067657 0.0 Signed-off-by: Kuniyuki Iwashima --- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 247 +++++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 8 +- 2 files changed, 243 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c index 78558c16412f..561e1c19df00 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c @@ -11,6 +11,35 @@ #include "xsk.h" #define IDPF_RX_HDR_BUF_SIZE ALIGN(LIBETH_MAX_HEAD, LIBETH_RX_BUF_STRIDE) +#define IDPF_RX_DMA_INVALID_ID U16_MAX + +/** + * struct idpf_rx_dma_entry - DMA mapping slot for an Rx payload page + * @dma: base DMA address of the mapped page + * @refs: number of active HW descriptors referencing this mapping + * @next_free: index of the next free entry, or %IDPF_RX_DMA_INVALID_ID + */ +struct idpf_rx_dma_entry { + dma_addr_t dma; + u16 refs; + u16 next_free; +}; + +/** + * struct idpf_rx_dma_ring - Per-bufq DMA mapping tracker for Rx payload pages + * @cur_page: most recently mapped netmem page for sub-page frag sharing + * @page_ids: per-buf_id mapping slot index, or %IDPF_RX_DMA_INVALID_ID + * @cur_id: entry index corresponding to @cur_page, or %IDPF_RX_DMA_INVALID_ID + * @free_head: head of the free entry list, or %IDPF_RX_DMA_INVALID_ID + * @entries: flexible array of DMA mapping slots indexed by page ID + */ +struct idpf_rx_dma_ring { + netmem_ref cur_page; + u16 *page_ids; + u16 cur_id; + u16 free_head; + struct idpf_rx_dma_entry entries[]; +}; #define idpf_tx_buf_next(buf) (*(u32 *)&(buf)->priv) LIBETH_SQE_CHECK_PRIV(u32); @@ -394,6 +423,60 @@ static void idpf_rx_hdr_buf_rel_all(struct idpf_buf_queue *bufq) bufq->hdr_pp = NULL; } +/** + * idpf_rx_buf_sync_unmap - Sync Rx payload buffer and unmap page when unused + * @bufq: buffer queue owning the descriptor + * @buf_id: buffer index in @bufq + * @len: received payload length to sync for CPU, or 0 to skip sync + * + * Syncs CPU access if @len > 0, drops the HW descriptor refcount, and + * unmaps the page while resetting @cur_id/@cur_page when refs reaches 0. + * Must be called from the owning NAPI poll or control path. + */ +static void idpf_rx_buf_sync_unmap(struct idpf_buf_queue *bufq, u32 buf_id, + u32 len) +{ + struct idpf_rx_dma_entry *entry; + struct idpf_rx_dma_ring *ring; + struct page_pool *pp; + u16 id; + + if (likely(!idpf_queue_has(DMA_UNMAP, bufq))) + return; + + ring = bufq->buf_dma; + id = ring->page_ids[buf_id]; + if (unlikely(id == IDPF_RX_DMA_INVALID_ID)) + return; + + ring->page_ids[buf_id] = IDPF_RX_DMA_INVALID_ID; + entry = &ring->entries[id]; + pp = bufq->pp; + + if (likely(len)) { + const struct libeth_fqe *rx_buf = &bufq->buf[buf_id]; + + dma_sync_single_range_for_cpu(pp->p.dev, entry->dma, + rx_buf->offset + pp->p.offset, + len, pp->p.dma_dir); + } + + if (--entry->refs) + return; + + dma_unmap_page_attrs(pp->p.dev, entry->dma, PAGE_SIZE << pp->p.order, + pp->p.dma_dir, + DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING); + + if (ring->cur_id == id) { + ring->cur_id = IDPF_RX_DMA_INVALID_ID; + ring->cur_page = 0; + } + + entry->next_free = ring->free_head; + ring->free_head = id; +} + /** * idpf_rx_buf_rel_bufq - Free all Rx buffer resources for a buffer queue * @bufq: queue to be cleaned @@ -418,13 +501,20 @@ static void idpf_rx_buf_rel_bufq(struct idpf_buf_queue *bufq) } /* Free all the bufs allocated and given to hw on Rx queue */ - for (u32 i = 0; i < bufq->desc_count; i++) - idpf_rx_page_rel(&bufq->buf[i]); + for (u32 i = 0; i < bufq->desc_count; i++) { + if (bufq->buf[i].netmem) { + idpf_rx_buf_sync_unmap(bufq, i, 0); + idpf_rx_page_rel(&bufq->buf[i]); + } + } if (idpf_queue_has(HSPLIT_EN, bufq)) idpf_rx_hdr_buf_rel_all(bufq); libeth_rx_fq_destroy(&fq); + kvfree(bufq->buf_dma); + bufq->buf_dma = NULL; + idpf_queue_clear(DMA_UNMAP, bufq); bufq->buf = NULL; bufq->pp = NULL; } @@ -624,6 +714,110 @@ static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id) refillq->next_to_use = nta; } +/** + * idpf_rx_buf_dma_map - DMA-map or reuse mapping for an Rx payload buffer + * @bufq: buffer queue to map for + * @rx_buf: Rx buffer descriptor containing the allocated netmem + * @buf_id: buffer index in @bufq + * + * Reuses the @cur_id DMA mapping for consecutive frags on the same page, + * or maps a new page from the free list. Caller must run in the owning + * NAPI poll or control context. + * + * Return: base DMA address of the mapped page, or %DMA_MAPPING_ERROR. + */ +static dma_addr_t idpf_rx_buf_dma_map(struct idpf_buf_queue *bufq, + const struct libeth_fqe *rx_buf, + u32 buf_id) +{ + struct idpf_rx_dma_ring *ring = bufq->buf_dma; + struct page_pool *pp = bufq->pp; + struct idpf_rx_dma_entry *entry; + dma_addr_t dma; + u16 id; + + if (ring->cur_id != IDPF_RX_DMA_INVALID_ID && + ring->cur_page == rx_buf->netmem) { + id = ring->cur_id; + ring->entries[id].refs++; + ring->page_ids[buf_id] = id; + + return ring->entries[id].dma; + } + + id = ring->free_head; + if (WARN_ON_ONCE(id == IDPF_RX_DMA_INVALID_ID)) + return DMA_MAPPING_ERROR; + + dma = dma_map_page_attrs(pp->p.dev, netmem_to_page(rx_buf->netmem), 0, + PAGE_SIZE << pp->p.order, pp->p.dma_dir, + DMA_ATTR_SKIP_CPU_SYNC | + DMA_ATTR_WEAK_ORDERING); + if (unlikely(dma_mapping_error(pp->p.dev, dma))) + return DMA_MAPPING_ERROR; + + entry = &ring->entries[id]; + ring->free_head = entry->next_free; + entry->dma = dma; + entry->refs = 1; + + ring->cur_id = id; + ring->cur_page = rx_buf->netmem; + ring->page_ids[buf_id] = id; + + return dma; +} + +/** + * idpf_rx_buf_alloc - Allocate and DMA-map an Rx payload buffer + * @bufq: buffer queue to allocate from + * @buf_id: buffer index + * @gfp: allocation flags (GFP_KERNEL for initial fill, GFP_ATOMIC from NAPI) + * + * Return: DMA address for HW, or %DMA_MAPPING_ERROR on allocation failure. + */ +static dma_addr_t idpf_rx_buf_alloc(struct idpf_buf_queue *bufq, u32 buf_id, + gfp_t gfp) +{ + struct page_pool *pp = bufq->pp; + struct libeth_fqe *rx_buf; + dma_addr_t dma; + u32 truesize; + + if (likely(!idpf_queue_has(DMA_UNMAP, bufq))) { + struct libeth_fq_fp fq = { + .pp = pp, + .fqes = bufq->buf, + .truesize = bufq->truesize, + .count = bufq->desc_count, + }; + + return __libeth_rx_alloc(&fq, buf_id, gfp); + } + + truesize = bufq->truesize; + rx_buf = &bufq->buf[buf_id]; + rx_buf->netmem = page_pool_alloc_netmem(pp, &rx_buf->offset, + &truesize, gfp | __GFP_NOWARN); + if (unlikely(!rx_buf->netmem)) + return DMA_MAPPING_ERROR; + + rx_buf->truesize = truesize; + dma = idpf_rx_buf_dma_map(bufq, rx_buf, buf_id); + if (unlikely(dma == DMA_MAPPING_ERROR)) { + libeth_rx_recycle_slow(rx_buf->netmem); + rx_buf->netmem = 0; + return DMA_MAPPING_ERROR; + } + + dma_sync_single_range_for_device(pp->p.dev, dma, + rx_buf->offset + pp->p.offset, + truesize - pp->p.offset, + pp->p.dma_dir); + + return dma + rx_buf->offset + pp->p.offset; +} + /** * idpf_rx_update_bufq_desc - Update buffer queue descriptor * @bufq: Pointer to the buffer queue @@ -637,15 +831,10 @@ static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id, struct virtchnl2_splitq_rx_buf_desc *buf_desc, gfp_t gfp) { - struct libeth_fq_fp fq = { - .pp = bufq->pp, - .fqes = bufq->buf, - .truesize = bufq->truesize, - .count = bufq->desc_count, - }; + struct libeth_fq_fp fq; dma_addr_t addr; - addr = __libeth_rx_alloc(&fq, buf_id, gfp); + addr = idpf_rx_buf_alloc(bufq, buf_id, gfp); if (addr == DMA_MAPPING_ERROR) return -ENOMEM; @@ -665,9 +854,11 @@ static int idpf_rx_update_bufq_desc(struct idpf_buf_queue *bufq, u32 buf_id, fq.pp = bufq->hdr_pp; fq.fqes = bufq->hdr_buf; fq.truesize = bufq->hdr_truesize; + fq.count = bufq->desc_count; addr = __libeth_rx_alloc(&fq, buf_id, gfp); if (addr == DMA_MAPPING_ERROR) { + idpf_rx_buf_sync_unmap(bufq, buf_id, 0); idpf_rx_page_rel(&bufq->buf[buf_id]); return -ENOMEM; } @@ -811,24 +1002,56 @@ static int idpf_rx_buf_alloc_all(struct idpf_buf_queue *rxbufq) static int idpf_rx_bufs_init(struct idpf_buf_queue *bufq, enum libeth_fqe_type type) { + struct idpf_vport *vport = bufq->q_vector->vport; struct libeth_fq fq = { .truesize = bufq->truesize, .count = bufq->desc_count, .type = type, .buf_len = IDPF_RX_MAX_BUF_SZ, .hsplit = idpf_queue_has(HSPLIT_EN, bufq), - .xdp = idpf_xdp_enabled(bufq->q_vector->vport), + .xdp = idpf_xdp_enabled(vport), .nid = idpf_q_vector_to_mem(bufq->q_vector), }; + struct iommu_domain *domain; int ret; if (idpf_queue_has(XSK, bufq)) return idpf_xskfq_init(bufq); + domain = iommu_get_domain_for_dev(&vport->adapter->pdev->dev); + fq.no_dma_map = !fq.xdp && domain && domain->type == IOMMU_DOMAIN_DMA_FQ; + ret = libeth_rx_fq_create(&fq, &bufq->q_vector->napi); if (ret) return ret; + if (fq.no_dma_map) { + struct idpf_rx_dma_ring *ring; + size_t size; + + size = size_add(struct_size(ring, entries, bufq->desc_count), + array_size(sizeof(*ring->page_ids), + bufq->desc_count)); + ring = kvzalloc_node(size, GFP_KERNEL, fq.nid); + if (!ring) { + libeth_rx_fq_destroy(&fq); + return -ENOMEM; + } + + ring->page_ids = (u16 *)&ring->entries[bufq->desc_count]; + ring->cur_id = IDPF_RX_DMA_INVALID_ID; + ring->free_head = 0; + for (u32 i = 0; i < bufq->desc_count; i++) { + ring->entries[i].next_free = i + 1; + ring->page_ids[i] = IDPF_RX_DMA_INVALID_ID; + } + ring->entries[bufq->desc_count - 1].next_free = + IDPF_RX_DMA_INVALID_ID; + + bufq->buf_dma = ring; + idpf_queue_set(DMA_UNMAP, bufq); + } + bufq->pp = fq.pp; bufq->buf = fq.fqes; bufq->truesize = fq.truesize; @@ -3858,7 +4081,8 @@ idpf_rx_splitq_clean_skb(struct idpf_rx_queue *rxq, * This function provides a "bounce buffer" approach to Rx interrupt * processing. The advantage to this is that on systems that have * expensive overhead for IOMMU access this provides a means of avoiding - * it by maintaining the mapping of the page to the system. + * it by maintaining the mapping of the page to the system, unless + * DMA_UNMAP is set under DMA-FQ IOMMU. * * Return: amount of work completed */ @@ -3926,6 +4150,7 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget) buf_id = le16_to_cpu(rx_desc->buf_id); rx_buf = &rx_bufq->buf[buf_id]; + idpf_rx_buf_sync_unmap(rx_bufq, buf_id, pkt_len); if (!coherent_hdr && !rx_bufq->hdr_pp) goto payload; diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h index 0df23e01be53..c5a29638891e 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h @@ -289,6 +289,7 @@ struct idpf_ptype_state { * @__IDPF_Q_RSC_EN: enable Receive Side Coalescing on Rx (splitq) * @__IDPF_Q_HSPLIT_EN: enable header split on Rx (splitq) * @__IDPF_Q_HSPLIT_COHERENT: use coherent DMA buffer for Rx header split + * @__IDPF_Q_DMA_UNMAP: unmap Rx payload pages per packet under DMA-FQ IOMMU * @__IDPF_Q_PTP: indicates whether the Rx timestamping is enabled for the * queue * @__IDPF_Q_NOIRQ: queue is polling-driven and has no interrupt @@ -305,6 +306,7 @@ enum idpf_queue_flags_t { __IDPF_Q_RSC_EN, __IDPF_Q_HSPLIT_EN, __IDPF_Q_HSPLIT_COHERENT, + __IDPF_Q_DMA_UNMAP, __IDPF_Q_PTP, __IDPF_Q_NOIRQ, __IDPF_Q_XDP, @@ -726,6 +728,8 @@ libeth_cacheline_set_assert(struct idpf_tx_queue, 64, offsetofend(struct idpf_tx_queue, tstamp_task), 32); +struct idpf_rx_dma_ring; + /** * struct idpf_buf_queue - software structure representing a buffer queue * @split_buf: buffer descriptor array @@ -747,6 +751,7 @@ libeth_cacheline_set_assert(struct idpf_tx_queue, 64, * @pending: number of buffers to refill (Xsk) * @hdr_truesize: truesize for buffer headers * @truesize: truesize for data buffers + * @buf_dma: DMA mapping tracker for payload pages when driver unmaps * @q_id: Queue id * @size: Length of descriptor ring in bytes * @dma: Physical address of ring @@ -794,6 +799,7 @@ struct idpf_buf_queue { u32 pending; u32 hdr_truesize; u32 truesize; + struct idpf_rx_dma_ring *buf_dma; __cacheline_group_end_aligned(read_write); __cacheline_group_begin_aligned(cold); @@ -808,7 +814,7 @@ struct idpf_buf_queue { u16 rx_buf_size; __cacheline_group_end_aligned(cold); }; -libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 24, 32); +libeth_cacheline_set_assert(struct idpf_buf_queue, 64, 32, 32); /** * struct idpf_compl_queue - software structure representing a completion queue -- 2.56.1.911.g883d8bcb20-goog