Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Apr 2026 09:46:16 +0000
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Cc:        Timo =?utf-8?Q?V=C3=B6lker?= <timo.voelker@fh-muenster.de>
Subject:   git: 1bfd392b9e4d - main - vtnet: remove loader tunable fixup_needs_csum
Message-ID:  <69eddee8.39be1.56e9b6db@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=1bfd392b9e4dcddef3d80efaa517fafa648cd0b1

commit 1bfd392b9e4dcddef3d80efaa517fafa648cd0b1
Author:     Timo Völker <timo.voelker@fh-muenster.de>
AuthorDate: 2026-04-26 09:42:38 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2026-04-26 09:42:38 +0000

    vtnet: remove loader tunable fixup_needs_csum
    
    Removes the deprecated loader tunable fixup_needs_csum. Removes also
    the sysctl counter rx_csum_bad_offset that is no longer in use.
    
    Reviewed by:            tuexen
    Event:                  Wiesbaden Hackathon 2026
    Differential Revision:  https://reviews.freebsd.org/D55588
---
 share/man/man4/vtnet.4            | 24 +-----------
 sys/arm/allwinner/if_awg.c        | 14 +++----
 sys/dev/virtio/network/if_vtnet.c | 78 ++++++---------------------------------
 3 files changed, 21 insertions(+), 95 deletions(-)

diff --git a/share/man/man4/vtnet.4 b/share/man/man4/vtnet.4
index 926f504d8070..fad0257a2b10 100644
--- a/share/man/man4/vtnet.4
+++ b/share/man/man4/vtnet.4
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 19, 2025
+.Dd April 26, 2026
 .Dt VTNET 4
 .Os
 .Sh NAME
@@ -87,19 +87,6 @@ UDP.
 This also implies that TCP segmentation offloading and large receive offload
 are disabled.
 The default value is 0.
-.It Va hw.vtnet.fixup_needs_csum
-.It Va hw.vtnet. Ns Ar X Ns Va .fixup_needs_csum
-This tunable enforces the calculation of a valid TCP or UDP checksum for
-packets received with 
-.Dv VIRTIO_NET_HDR_F_NEEDS_CSUM
-being set in the
-.Va flags
-field of the structure
-.Vt struct virtio_net_hdr .
-It also marks the checksum as being correct in the mbuf packet header.
-The default value is 0.
-This tunable is deprecated and will be removed in
-.Fx 16 .
 .It Va hw.vtnet.tso_disable
 .It Va hw.vtnet. Ns Ar X Ns Va .tso_disable
 This tunable disables TCP segmentation offloading.
@@ -174,9 +161,8 @@ offloading was received and this request failed.
 The different reasons for the failure are counted by
 .Va dev.vtnet. Ns Ar X Ns Va .rx_csum_inaccessible_ipproto ,
 .Va dev.vtnet. Ns Ar X Ns Va .rx_csum_bad_ipproto ,
-.Va dev.vtnet. Ns Ar X Ns Va .rx_csum_bad_ethtype ,
 and
-.Va dev.vtnet. Ns Ar X Ns Va .rx_csum_bad_offset .
+.Va dev.vtnet. Ns Ar X Ns Va .rx_csum_bad_ethtype .
 .It Va dev.vtnet. Ns Ar X Ns Va .rxq Ns Ar Y Ns Va .csum
 The number of times receive checksum offloading for UDP or TCP was performed.
 .It Va dev.vtnet. Ns Ar X Ns Va .rxq Ns Ar Y Ns Va .ierrors
@@ -239,12 +225,6 @@ over all receive queues of the interface.
 .It Va dev.vtnet. Ns Ar X Ns Va .rx_csum_inaccessible_ipproto
 The number of times a packet with a request for receive or transmit checksum
 offloading was received where the IP protocol was not accessible.
-.It Va dev.vtnet. Ns Ar X Ns Va .rx_csum_bad_offset
-The number of times fixing the checksum required by
-.Va hw.vtnet.fixup_needs_csum
-or
-.Va hw.vtnet. Ns Ar X Ns Va .fixup_needs_csum
-was attempted for a packet where the csum is not located in the first mbuf.
 .It Va dev.vtnet. Ns Ar X Ns Va .rx_csum_bad_ipproto
 The number of times a packet with a request for receive or transmit checksum
 offloading was received where the IP protocol was neither TCP nor UDP.
diff --git a/sys/arm/allwinner/if_awg.c b/sys/arm/allwinner/if_awg.c
index c66aab9422b8..d5a6fdb96192 100644
--- a/sys/arm/allwinner/if_awg.c
+++ b/sys/arm/allwinner/if_awg.c
@@ -651,13 +651,13 @@ awg_encap(struct awg_softc *sc, struct mbuf **mp)
 
 	flags = TX_FIR_DESC;
 	status = 0;
-	if ((m->m_pkthdr.csum_flags & CSUM_IP) != 0) {
-		if ((m->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP)) != 0)
-			csum_flags = TX_CHECKSUM_CTL_FULL;
-		else
-			csum_flags = TX_CHECKSUM_CTL_IP;
-		flags |= (csum_flags << TX_CHECKSUM_CTL_SHIFT);
-	}
+	if ((m->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP)) != 0)
+		csum_flags = TX_CHECKSUM_CTL_FULL;
+	else if ((m->m_pkthdr.csum_flags & CSUM_IP) != 0)
+		csum_flags = TX_CHECKSUM_CTL_IP;
+	else
+		csum_flags = 0;
+	flags |= (csum_flags << TX_CHECKSUM_CTL_SHIFT);
 
 	for (i = 0; i < nsegs; i++) {
 		sc->tx.segs++;
diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index da89dea03f87..ef01833b9e03 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -135,7 +135,7 @@ static int	vtnet_rxq_replace_buf(struct vtnet_rxq *, struct mbuf *, int);
 static int	vtnet_rxq_enqueue_buf(struct vtnet_rxq *, struct mbuf *);
 static int	vtnet_rxq_new_buf(struct vtnet_rxq *);
 #if defined(INET) || defined(INET6)
-static int	vtnet_rxq_csum_needs_csum(struct vtnet_rxq *, struct mbuf *,
+static void	vtnet_rxq_csum_needs_csum(struct vtnet_rxq *, struct mbuf *,
 		     bool, int, struct virtio_net_hdr *);
 static void	vtnet_rxq_csum_data_valid(struct vtnet_rxq *, struct mbuf *,
 		    int);
@@ -273,11 +273,6 @@ static int vtnet_csum_disable = 0;
 SYSCTL_INT(_hw_vtnet, OID_AUTO, csum_disable, CTLFLAG_RDTUN,
     &vtnet_csum_disable, 0, "Disables receive and send checksum offload");
 
-static int vtnet_fixup_needs_csum = 0;
-SYSCTL_INT(_hw_vtnet, OID_AUTO, fixup_needs_csum, CTLFLAG_RDTUN,
-    &vtnet_fixup_needs_csum, 0,
-    "Calculate valid checksum for NEEDS_CSUM packets");
-
 static int vtnet_tso_disable = 0;
 SYSCTL_INT(_hw_vtnet, OID_AUTO, tso_disable, CTLFLAG_RDTUN,
     &vtnet_tso_disable, 0, "Disables TSO");
@@ -1158,10 +1153,6 @@ vtnet_setup_interface(struct vtnet_softc *sc)
 		if_setcapabilitiesbit(ifp, IFCAP_RXCSUM, 0);
 		if_setcapabilitiesbit(ifp, IFCAP_RXCSUM_IPV6, 0);
 
-		if (vtnet_tunable_int(sc, "fixup_needs_csum",
-		    vtnet_fixup_needs_csum) != 0)
-			sc->vtnet_flags |= VTNET_FLAG_FIXUP_NEEDS_CSUM;
-
 		/* Support either "hardware" or software LRO. */
 		if_setcapabilitiesbit(ifp, IFCAP_LRO, 0);
 	}
@@ -1784,12 +1775,10 @@ vtnet_rxq_new_buf(struct vtnet_rxq *rxq)
 }
 
 #if defined(INET) || defined(INET6)
-static int
+static void
 vtnet_rxq_csum_needs_csum(struct vtnet_rxq *rxq, struct mbuf *m, bool isipv6,
     int protocol, struct virtio_net_hdr *hdr)
 {
-	struct vtnet_softc *sc;
-
 	/*
 	 * The packet is likely from another VM on the same host or from the
 	 * host that itself performed checksum offloading so Tx/Rx is basically
@@ -1800,57 +1789,18 @@ vtnet_rxq_csum_needs_csum(struct vtnet_rxq *rxq, struct mbuf *m, bool isipv6,
 	    ("%s: unsupported IP protocol %d", __func__, protocol));
 
 	/*
-	 * If the user don't want us to fix it up here by computing the
-	 * checksum, just forward the order to compute the checksum by setting
+	 * Just forward the order to compute the checksum by setting
 	 * the corresponding mbuf flag (e.g., CSUM_TCP).
 	 */
-	sc = rxq->vtnrx_sc;
-	if ((sc->vtnet_flags & VTNET_FLAG_FIXUP_NEEDS_CSUM) == 0) {
-		switch (protocol) {
-		case IPPROTO_TCP:
-			m->m_pkthdr.csum_flags |=
-			    (isipv6 ? CSUM_TCP_IPV6 : CSUM_TCP);
-			break;
-		case IPPROTO_UDP:
-			m->m_pkthdr.csum_flags |=
-			    (isipv6 ? CSUM_UDP_IPV6 : CSUM_UDP);
-			break;
-		}
-		m->m_pkthdr.csum_data = hdr->csum_offset;
-		return (0);
-	}
-
-	/*
-	 * Compute the checksum in the driver so the packet will contain a
-	 * valid checksum. The checksum is at csum_offset from csum_start.
-	 */
-	int csum_off, csum_end;
-	uint16_t csum;
-
-	csum_off = hdr->csum_start + hdr->csum_offset;
-	csum_end = csum_off + sizeof(uint16_t);
-
-	/* Assume checksum will be in the first mbuf. */
-	if (m->m_len < csum_end || m->m_pkthdr.len < csum_end) {
-		sc->vtnet_stats.rx_csum_bad_offset++;
-		return (1);
+	switch (protocol) {
+	case IPPROTO_TCP:
+		m->m_pkthdr.csum_flags |= (isipv6 ? CSUM_TCP_IPV6 : CSUM_TCP);
+		break;
+	case IPPROTO_UDP:
+		m->m_pkthdr.csum_flags |= (isipv6 ? CSUM_UDP_IPV6 : CSUM_UDP);
+		break;
 	}
-
-	/*
-	 * Like in_delayed_cksum()/in6_delayed_cksum(), compute the
-	 * checksum and write it at the specified offset. We could
-	 * try to verify the packet: csum_start should probably
-	 * correspond to the start of the TCP/UDP header.
-	 *
-	 * BMV: Need to properly handle UDP with zero checksum. Is
-	 * the IPv4 header checksum implicitly validated?
-	 */
-	csum = in_cksum_skip(m, m->m_pkthdr.len, hdr->csum_start);
-	*(uint16_t *)(mtodo(m, csum_off)) = csum;
-	m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
-	m->m_pkthdr.csum_data = 0xFFFF;
-
-	return (0);
+	m->m_pkthdr.csum_data = hdr->csum_offset;
 }
 
 static void
@@ -1934,8 +1884,7 @@ vtnet_rxq_csum(struct vtnet_rxq *rxq, struct mbuf *m,
 	}
 
 	if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM)
-		return (vtnet_rxq_csum_needs_csum(rxq, m, isipv6, protocol,
-		    hdr));
+		vtnet_rxq_csum_needs_csum(rxq, m, isipv6, protocol, hdr);
 	else /* VIRTIO_NET_HDR_F_DATA_VALID */
 		vtnet_rxq_csum_data_valid(rxq, m, protocol);
 
@@ -4354,9 +4303,6 @@ vtnet_setup_stat_sysctl(struct sysctl_ctx_list *ctx,
 	SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, "rx_csum_bad_ipproto",
 	    CTLFLAG_RD | CTLFLAG_STATS, &stats->rx_csum_bad_ipproto,
 	    "Received checksum offloaded buffer with incorrect IP protocol");
-	SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, "rx_csum_bad_offset",
-	    CTLFLAG_RD | CTLFLAG_STATS, &stats->rx_csum_bad_offset,
-	    "Received checksum offloaded buffer with incorrect offset");
 	SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, "rx_csum_inaccessible_ipproto",
 	    CTLFLAG_RD | CTLFLAG_STATS, &stats->rx_csum_inaccessible_ipproto,
 	    "Received checksum offloaded buffer with inaccessible IP protocol");


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69eddee8.39be1.56e9b6db>