From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (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 4B8B0606A323 for ; Wed, 2 Dec 2026 07:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=FnLskkh9 Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A4F24402D9; Wed, 2 Dec 2026 08:09:47 +0100 (CET) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTPS id 2AE11402D5 for ; Wed, 2 Dec 2026 08:09:45 +0100 (CET) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2f04244c3d0so97240845ad.3 for ; Tue, 01 Dec 2026 23:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796195384; x=1796800184; darn=dpdk.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=UuvUh8sjh4UdqYIxSAcbxtVieR4hS/OwGEySLvw+f6o=; b=FnLskkh9fooRwZlVcDI9UAFDD7k5xcqPpcRHEuBnmGZ7Mi2dtyRM1+bHAKEa5Jj/Gm 5iq8cGKs4SsYbxpoiLyPc0uyMRkoHFroPPpMw6HFmcbft8MklHqkfPsocvgK9dsy6Mw/ 3zsehM3lWEHswPBGNUCKipOTsJ/mBHV8ph+wZl8MTuC4xPPJCqqBRr/E+C+ZhLP8thjy NTEInc0j+ddEafON279hlSBC/Q4HfZhNIL/KQBuPrkOdW2nqbH1i8HAvKsYKafAv8X8f bPQC2r6ImDzkByjoyFVwc58pPPZx96SarIY+LfB1clSVjSXllX+q9in5PZnwQMKfLBAz bgdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796195384; x=1796800184; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UuvUh8sjh4UdqYIxSAcbxtVieR4hS/OwGEySLvw+f6o=; b=faPqkX3MpwiIaMaStFPbAv+7E473whlK6osum/d3H3UU3WyJHS/wDuqF/Ni5f+qbyS wVsPcme1Ex+uRAyU54UrfOUhvYa0/7Dx3CxXoX5F7MU7qOnxGltZ/6b3D5DorOL/V7Z6 KIZWOkJ0LS9SzxsncFPZWYsA/zRPilQk7Er38hx9LCI3jiC4PVTR7XSpSsANFUDAHb9M lJAyFh6Ppkm9O/RMIiuH5sSoRWEQEjMa24g3vNFBBr9WqXBCVK+esuhzX2/N6uP4ecI4 cN9SeOwwXzecZjMmmeNd964LX9Zt0Qtln0+MzNtU1//QFTDvlY86n3i+g4/7vOl0+hdj BlTw== X-Gm-Message-State: APuU4Z9jOrQurftHlg0nPgbUTt8NRPbO9tPBzhOegALzhc3C/Q35QAkL DAt/z0uXYG2Mi7Hwfo5bgprYm1Fuyw/pvneOogURY7gPEf47T1X5XvOJ+NUKVtHyXcE= X-Gm-Gg: AZFdTZeXanGU25+/MU+6a87CRMpM+CfEh//XkdCpfJGcc5s9e/NO3JS2t7etvGu7+Ab 5+K81PyJx2qxIqyvPHtByVkAq66AgxS/K9pc2EPggQXAMg6OMRriudh6UttR97MzRwawYnfnjlG wE8K1QCaMXWaOJlk2b+APPQgxjddGiW+dU0DB3XqePRS6bSs+x8I37qXH0Q31axHz4nsvw3MA9s p3fhnk2IVNdoWMe3JKEly0ehbdlZ0k7q5Yowg69yjnZWwHnUA6xMltCkmOn46Lf5g+H8CziUqXM JSOYXPQtRZI+XyfvmvWWGyV0XVxWpyp2mP3kwu8MCi/AA42Rpt1wSACGC3C7vokn8mdo5xNMcMw U6H0Mksmx5fJpl+PojSCBaKRHC5qHPWQieSf696xwhf+wqaT1B91orzFZMZYi+aasY/EJajgeuB jlY+q8ZJmnOM0+YvFvThLDIOD7p4VKCUeiM02GD3lNRrrLo+f1wt962EkqInBDamdEacFIjSAL7 tJOoERvq6lR5DnVJcHdSyWBrBreEyZtpevyx1RKWG63TOaClzc8OnU72WxIyGv6vfZ8EW8YLkLR hd4nOx6YIDNZ9WBERlm3XqO3pbRl+64VfQ+0tOAWKJR6xzju6zhe8qAp8MxrzsMRwj4lCQ== X-Received: by 2002:a17:903:b0e:b0:2eb:3599:aa2a with SMTP id d9443c01a7336-2f03f18520amr451141105ad.56.1796195384012; Tue, 01 Dec 2026 23:09:44 -0800 (PST) Received: from phoenix.local (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f0dc13fsm195659245ad.29.2026.12.01.23.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 23:09:43 -0800 (PST) Date: Tue, 1 Dec 2026 23:09:42 -0800 From: Stephen Hemminger To: Scott Mitchell Cc: dev@dpdk.org, Thomas Monjalon , David Marchand Subject: Re: [PATCH v7 0/4] net/af_packet: correctness, performance, cksum Message-ID: <20261201230942.2e0f97ca@phoenix.local> In-Reply-To: <20261201222405.88922-1-scott.k.mitch1@gmail.com> References: <20260206011141.2377-1-scott.k.mitch1@gmail.com> <20261201222405.88922-1-scott.k.mitch1@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Tue, 1 Dec 2026 14:24:01 -0800 Scott Mitchell wrote: > Fixes and improvements for the af_packet PMD. Each patch adds tests to > app/test/test_pmd_af_packet.c. > > 1/4 fixes tp_status memory ordering and frame addressing. > 2/4 bulk-frees TX mbufs. > 3/4 adds a txpollnotrdy devarg so TX does not block in poll(). > 4/4 adds software TX checksum offload, shared with the tap driver. > > Depends-on: patch- ("test/cksum: fix EtherType of IPv6 TCP packet") The long form AI review from Fable agrees with what I was going to say about this series. There are sublties here because of differences in atomics load/store vs fences and what C11 std is. Review: [PATCH v7 0/4] net/af_packet fixes and tx features Applied to main (ddb3b0c, 27.03-rc0). Each commit builds with -Dwerror=true. Tests not run. Series ------ The two real fixes in 1/4 are small (about 15 and 20 lines of driver code) but arrive with 370 lines of test, new devarg validation and unrelated cleanup, all under one Fixes tag and Cc: stable. That is not backportable as is. Suggested split: 1 fix tp_status memory ordering (Fixes, stable) 2 fix frame address with unused block tail (Fixes, stable) 3 test: frame layout (stable optional) 4 validate ring devargs (not stable) 5 tx cleanup: overhead macro, bulk free, unlikely 6 tx: non-blocking when ring is full 7 net: add rte_net_ip_udptcp_cksum_mbuf() + test_cksum 8 net/tap: use it 9 net/af_packet: tx checksum offload + test 1/4 subject says "thread safety". Nothing here is about threads in the application; it is ordering against the kernel side of the ring. Patch 1/4 --------- Warning: ordering primitive tpacket_read_status() is a plain load followed by rte_atomic_thread_fence(acquire); tpacket_write_status() is a fence(release) followed by a plain store. The C11 model only gives a fence meaning relative to atomic operations, so this relies on what the compiler happens to emit. It does emit a barrier on arm64, so the generated code is right, but there is no reason not to use the defined form. What others do with the same ring: libpcap pcap-linux.c __atomic_load_n(&h.h2->tp_status, __ATOMIC_ACQUIRE) __atomic_store_n(&pkt->tp_status, TP_STATUS_KERNEL, __ATOMIC_RELEASE) kernel net/packet/af_packet.c __packet_set_status: WRITE_ONCE(); smp_wmb() __packet_get_status: smp_rmb(); READ_ONCE() tpacket_rcv: smp_mb() between frame fill and status kernel selftest psock_tpacket.c plain store then __sync_synchronize() In DPDK, net/memif does load-acquire/store-release on the shared ring indexes and virtio does load-acquire on the weak-barrier path. Match libpcap and memif: static inline uint32_t tpacket_read_status(struct tpacket2_hdr *ppd) { return rte_atomic_load_explicit( (RTE_ATOMIC(uint32_t) *)&ppd->tp_status, rte_memory_order_acquire); } static inline void tpacket_write_status(struct tpacket2_hdr *ppd, uint32_t status) { rte_atomic_store_explicit( (RTE_ATOMIC(uint32_t) *)&ppd->tp_status, status, rte_memory_order_release); } tp_status is at offset 0 of a frame and frames are TPACKET_ALIGNMENT aligned, so the unaligned_uint32_t casts are not needed. Warning: remove the new PMD_LOG(WARNING) block rte_eth_from_packet() is the probe path. A bad devarg is an error to return from probe, not something to warn about and carry on. As written, the three "must be" cases log a WARNING and then fail at setsockopt(PACKET_RX_RING) anyway, since they are exactly what packet_set_ring() rejects with EINVAL. Reject at probe, next to the existing framesize > blocksize test, so nothing later can see an invalid ring geometry: if (blocksize % pagesize != 0 || framesize % TPACKET_ALIGNMENT != 0 || framecount % frames_per_block != 0) { PMD_LOG(ERR, "%s: invalid AF_PACKET MMAP parameters", name); return -1; } Two of the sub-conditions in the patch cannot be true and go away: frames_per_block == 0 framesize > blocksize already returned -1 above frames_per_block > UINT_MAX / blockcount blockcount = framecount / frames_per_block, so the product is <= framecount The two "hint" warnings (blocksize not a multiple of framesize, blocksize not a power of two) are valid configurations. The first is the layout the address fix in this patch exists to support. Drop both. Info: num_rx_bytes/num_tx_bytes narrowed from unsigned long to uint32_t with no explanation. The queue counters are unsigned long. Drop this hunk, along with the int -> uint16_t and while -> do/while changes; none belong in a stable fix. Patch 2/4 --------- Error: tx can stall permanently when the ring is full if (unlikely(num_tx > 0 && sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, ... sendto() is what makes the kernel walk SEND_REQUEST frames. Frames stay in SEND_REQUEST when tpacket_snd() bails out early: -ENETDOWN when the interface is down, or sock_alloc_send_skb() failing with MSG_DONTWAIT. The existing comment under this sendto() describes that case. Once every slot is SEND_REQUEST the next burst breaks at i == 0, num_tx is 0, and sendto() is never called again. Nothing else will move those frames, so the queue is dead even after the link comes back. Before this patch every tx_burst kicked the kernel and the ring drained. The test added in 3/4 builds exactly this state (link down, ring full, second burst returns 0) and then destroys the port. Bring the link up and burst again there and it will show the stall. Fix: keep the kick unconditional. if (unlikely(sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0) == -1 && errno != ENOBUFS && errno != EAGAIN)) { Info: commit message says "RX/TX bulk free"; only tx is changed. The tp_len/tp_snaplen move is undone by 4/4. Patch 3/4 --------- Warning: wrong fix for a blocking tx_burst tx_burst is not supposed to sleep. poll(-1) in the tx path is the bug; a devarg that lets the user opt out of it makes af_packet behave differently from every other ethdev and leaves the bad default. Remove the poll() and return short when the ring is full, which is the normal ethdev backpressure contract. No devarg, no doc change, and the test becomes "tx never blocks". If blocking has to stay for compatibility, the default should be non-blocking and the name should say what it does (tx_poll=1). Warning: "bool sw_cksum" is added to struct pkt_tx_queue here but belongs to 4/4. Info: the pfd setup is now conditional on txpollnotrdy; it saves nothing measurable and pfd.revents = 0 after memset() is redundant. The doc example command line gains txpollnotrdy=0, i.e. the example no longer shows defaults. Patch 4/4 --------- Error: shared/indirect mbuf with L4 header not in first segment The length check was relaxed from the old tap test (data_len >= l2 + l3 + l4 header) to data_len >= l2 + l3 so the direct case can linearize. The copy path still needs the old condition: seg = rte_pktmbuf_copy(mbuf, mbuf->pool, 0, hdrlens); ... rte_pktmbuf_adj(mbuf, hdrlens); rte_pktmbuf_chain(seg, mbuf); rte_pktmbuf_adj() returns NULL and does nothing when hdrlens > data_len. The result is seg (hdrlens bytes) chained in front of the untrimmed original: the headers go out twice and pkt_len is hdrlens too long. test_cksum_offload_cases() covers split headers only for the direct path. if (!RTE_MBUF_DIRECT(mbuf) || rte_mbuf_refcnt_read(mbuf) > 1) { struct rte_mbuf *seg; if (unlikely(rte_pktmbuf_data_len(mbuf) < hdrlens)) return NULL; seg = rte_pktmbuf_copy(mbuf, mbuf->pool, 0, hdrlens); if (seg == NULL) return NULL; rte_pktmbuf_adj(mbuf, hdrlens); if (rte_pktmbuf_chain(seg, mbuf) != 0) { rte_pktmbuf_prepend(mbuf, hdrlens); rte_pktmbuf_free(seg); return NULL; } mbuf = seg; } Warning: refcnt > 1 on a direct mbuf In that case rte_pktmbuf_adj() and rte_pktmbuf_chain() rewrite data_off, data_len and pkt_len of an rte_mbuf another holder still references. The other holder now sees a packet with its headers cut off. This was already true in tap, but it is now a public lib/net function documented as safe for shared mbufs. The test only covers the indirect (clone) case, where the metadata is private. Either return NULL for refcnt > 1 (as rte_vlan_insert() does) or copy the whole packet. Warning: af_packet does not need to touch the mbuf The driver copies every packet into the ring frame. Compute the checksums there, after the copy and before the status write. The frame is contiguous and private, so there is no allocation, no linearize, no shared/indirect special case and no bufs[i] rewrite: static inline bool af_packet_tx_cksum(uint8_t *frame, const struct rte_mbuf *m) { uint64_t l4 = m->ol_flags & RTE_MBUF_F_TX_L4_MASK; uint32_t off = m->l2_len + m->l3_len; void *l3 = frame + m->l2_len; unaligned_uint16_t *ck; struct rte_udp_hdr *udp = (void *)(frame + off); struct rte_tcp_hdr *tcp = (void *)(frame + off); if (l4 == RTE_MBUF_F_TX_UDP_CKSUM) ck = &udp->dgram_cksum; else if (l4 == RTE_MBUF_F_TX_TCP_CKSUM) ck = &tcp->cksum; else if (l4 == RTE_MBUF_F_TX_L4_NO_CKSUM) ck = NULL; else return false; /* caller checks off + L4 header <= pkt_len */ if (m->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) { struct rte_ipv4_hdr *ip = l3; ip->hdr_checksum = 0; ip->hdr_checksum = rte_ipv4_cksum(ip); } if (ck != NULL) { *ck = 0; *ck = (m->ol_flags & RTE_MBUF_F_TX_IPV4) ? rte_ipv4_udptcp_cksum(l3, frame + off) : rte_ipv6_udptcp_cksum(l3, frame + off); } return true; } That leaves rte_net_ip_udptcp_cksum_mbuf() with tap as its only user, which weakens the case for a new lib/net API. If it stays, it goes in its own patch with the test_cksum changes, and the tap conversion in another.