From nobody Mon Sep 14 20:17:25 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hkGfM0gpzz6rg8R for ; Mon, 14 Sep 2026 20:17:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hkGfL6hdgz4g7P for ; Mon, 14 Sep 2026 20:17:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789417050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FM219TZ5JGNJBBA23W6rWwbU86jmG7dnbiwnqrz0MLk=; b=OmK8BPogWK6WGX4+3Og+WZM2vHttUSunbfbzQNqMTnkBrtmkoSydwDeEiTnXWBcv2zmJm1 eQxRTp6CJI+Hej8V+CyeBgWsz9oszfTe8RM5Tim4oBqgTUTIfWU4paINvreeLGIu86PgIe HUeoFsCumOiiNduqN5iH+zw14k+o/WbdwA8vsIHGoT/DmcRuQnXO19fVTayeLWSNlrBE6w xdLbO7FSuFvWumcnN6cRx5MdTAERFMC/DUeo2DMpqY7C7FNxHYJvmRZ2d2dQ7n3/XA9f3U ZOny6Jj43a1VEvYkS4mbuXZtGLeCM5Ky7LOE0zPkSg3LSHCmKalto2Gt6L5WdQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789417050; b=Jx8kx1c38Y+3YgHOZCI8xfIX1a7kVGNyA+9BmbNV6Jh6TCbdTuV6FFbBtv6ItX2DZ2WhuH CzaaXEHgMM4mBybt/pdtCQkHTI1+6m4WmsIk0s64ndVgEKWC8Zmrg88lzEusADlC7ETWxS isJ4x3XOYLQktDgcCTcYJYhtm7z15PE6C4P/AIg+iXxQEDLhu13wPk5r8Idc1OgwXOZfHT yLiAkcPLDuZB+cw2w9XWwIpmwR0KeGzflKnuLaX0xh/EguS3or0leK5HOxMWGuTvwYSk7U EXdvZpUpru8nsc0kWEaDYxh2ymndE4/qtrVhhZ3TVal/dQBSgGcbH9s1pNbE/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789417050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FM219TZ5JGNJBBA23W6rWwbU86jmG7dnbiwnqrz0MLk=; b=jnMmkHAYda5X27odwoUcbopwXmHo7Jfa+J2OdZkGRLKRXF5s/BFgc2EPtnNcxEcEvdzAMH YYaaTqCgXK567UDjpGT51f3SutFubt/SsHXK8OZZqgYoBpaTcUgIri5TlG2EfojOfMATMJ 6zX8Uam9EYTKsmn5bh6+aHDrk+5CSPo9gehOQjQyshqxeNVdT5klJnsYCdLWEWJoxSQWie 8oXngFjnXxzGnhvvfnl9NG/OOFfwg1JSDiQy4Abqj62z8xa1VD5xb1aDefoLfhr0TUGkWA eYbB73Cr7A35dPi14WkaGGmxn+KrG4xLSamjiLpRgZ/xXYDLd2ucFqHed4EcKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hkGfL5lmNzSXf for ; Mon, 14 Sep 2026 20:17:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 27355 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 14 Sep 2026 20:17:25 +0000 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?= From: Michael Tuexen Subject: git: c1fa70c6e9f6 - main - vtnet: offer VIRTIO_NET_F_GUEST_CSUM List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c1fa70c6e9f652e79ef3ffaf366949744f11ce5c Auto-Submitted: auto-generated Date: Mon, 14 Sep 2026 20:17:25 +0000 Message-Id: <6aa85655.27355.48e74491@gitrepo.freebsd.org> The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=c1fa70c6e9f652e79ef3ffaf366949744f11ce5c commit c1fa70c6e9f652e79ef3ffaf366949744f11ce5c Author: Timo Völker AuthorDate: 2026-09-14 20:09:35 +0000 Commit: Michael Tuexen CommitDate: 2026-09-14 20:16:25 +0000 vtnet: offer VIRTIO_NET_F_GUEST_CSUM Always offer the VIRTIO_NET_F_GUEST_CSUM feature to the host, and not only if RXCSUM is enabled on vtnet. Instead of using RXCSUM to control whether this feature will be negotiated with the host, just use it to control whether the VIRTIO_NET_HDR_F_DATA_VALID flag on an incoming packet is processed (i.e., translated to the corresponding mbuf flag only if RXCSUM is enabled on the vtnet interface). This has two benefits: 1. Enabling/disabling RXCSUM on vtnet does not require feature renegotiation. 2. The host is always allowed to send locally generated TCP or UDP packets to the guest without computing a full checksum (by setting the VIRTIO_NET_HDR_F_NEEDS_CSUM flag) and not only if the guest has enabled RXCSUM on vtnet. Since locally generated packets do not require a checksum, this saves otherwise unnecessarily wasted computing power. If a user of a FreeBSD guest really does not want to negotiate the VIRTIO_NET_F_GUEST_CSUM feature with the host, it still can disable the loader tunable hw.vtnet.csum_disable. Reviewed by: kfv, tuexen MFC after: 1 week MFC to: stable/15 Differential Revision: https://reviews.freebsd.org/D59052 --- sys/dev/virtio/network/if_vtnet.c | 87 ++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c index 53f5bba146fc..15dd50e7df77 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -1456,11 +1456,12 @@ static int vtnet_ioctl_ifcap(struct vtnet_softc *sc, struct ifreq *ifr) { if_t ifp; - int mask, reinit, update; + int mask; + bool reinit, update; ifp = sc->vtnet_ifp; mask = (ifr->ifr_reqcap & if_getcapabilities(ifp)) ^ if_getcapenable(ifp); - reinit = update = 0; + reinit = update = false; VTNET_CORE_LOCK_ASSERT(sc); @@ -1500,52 +1501,44 @@ vtnet_ioctl_ifcap(struct vtnet_softc *sc, struct ifreq *ifr) if_togglehwassist(ifp, CSUM_IP6_TSO); } } - - if (mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_LRO)) { - /* - * These Rx features require the negotiated features to - * be updated. Avoid a full reinit if possible. - */ - if (sc->vtnet_features & VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) - update = 1; - else - reinit = 1; - - /* BMV: Avoid needless renegotiation for just software LRO. */ - if ((mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_LRO)) == - IFCAP_LRO && vtnet_software_lro(sc)) - reinit = update = 0; - /* - * VirtIO does not distinguish between receive checksum offload - * for IPv4 and IPv6 packets, so treat them as a pair. - */ - if (mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6)) { - if_togglecapenable(ifp, IFCAP_RXCSUM); - if_togglecapenable(ifp, IFCAP_RXCSUM_IPV6); + /* + * VirtIO does not distinguish between receive checksum offload + * for IPv4 and IPv6 packets, so treat them as a pair. + */ + if (mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6)) { + if (if_getcapenable(ifp) & IFCAP_RXCSUM && + if_getcapenable(ifp) & IFCAP_LRO) { + /* Disable lro, because rxcsum will be disabled. */ + if_setcapenablebit(ifp, 0, IFCAP_LRO); + /* Changing hardware LRO requires an update. */ + update = !vtnet_software_lro(sc); + mask &= ~IFCAP_LRO; } - if (mask & IFCAP_LRO) + if_togglecapenable(ifp, IFCAP_RXCSUM); + if_togglecapenable(ifp, IFCAP_RXCSUM_IPV6); + } + if (mask & IFCAP_LRO) { + if (if_getcapenable(ifp) & (IFCAP_RXCSUM | IFCAP_LRO)) { if_togglecapenable(ifp, IFCAP_LRO); - /* Both SW and HW TCP LRO require receive checksum offload. */ - if ((if_getcapenable(ifp) & - (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6)) == 0) - if_setcapenablebit(ifp, 0, IFCAP_LRO); + /* Changing hardware LRO requires an update. */ + update = !vtnet_software_lro(sc); + } } - if (mask & IFCAP_VLAN_HWFILTER) { - /* These Rx features require renegotiation. */ - reinit = 1; + /* This Rx feature requires renegotiation. */ + reinit = true; if (mask & IFCAP_VLAN_HWFILTER) if_togglecapenable(ifp, IFCAP_VLAN_HWFILTER); } - if (mask & IFCAP_VLAN_HWTSO) if_togglecapenable(ifp, IFCAP_VLAN_HWTSO); if (mask & IFCAP_VLAN_HWTAGGING) if_togglecapenable(ifp, IFCAP_VLAN_HWTAGGING); if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { - if (reinit) { + if (reinit || (update && (sc->vtnet_features & + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) == 0)) { if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); vtnet_init_locked(sc, 0); } else if (update) @@ -2084,8 +2077,20 @@ vtnet_rxq_input(struct vtnet_rxq *rxq, struct mbuf *m, M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); } - if (hdr->flags & - (VIRTIO_NET_HDR_F_NEEDS_CSUM | VIRTIO_NET_HDR_F_DATA_VALID)) { + /* + * Check if VirtIO header flags are set that need to be translated to + * mbuf flags. + * + * Translate VIRTIO_NET_HDR_F_DATA_VALID flag only if IFCAP_RXCSUM is + * enabled. If it is disabled, meaning the user does not want to use the + * result of a previous validation, this flag is ignored. + * + * Note that IFCAP_RXCSUM and IFCAP_RXCSUM_IPV6 are treated as pair: + * Either both are enabled, or neither of them is. + */ + if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) || + ((hdr->flags & VIRTIO_NET_HDR_F_DATA_VALID) && + (if_getcapenable(ifp) & IFCAP_RXCSUM))) { #if defined(INET) || defined(INET6) int ret; @@ -3318,9 +3323,6 @@ vtnet_virtio_reinit(struct vtnet_softc *sc) * via if_capenable and if_hwassist. */ - if ((if_getcapenable(ifp) & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6)) == 0) - features &= ~(VIRTIO_NET_F_GUEST_CSUM | VTNET_LRO_FEATURES); - if ((if_getcapenable(ifp) & IFCAP_LRO) == 0) features &= ~VTNET_LRO_FEATURES; @@ -3465,13 +3467,6 @@ vtnet_update_rx_offloads(struct vtnet_softc *sc) VTNET_CORE_LOCK_ASSERT(sc); - if (if_getcapabilities(ifp) & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6)) { - if (if_getcapenable(ifp) & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6)) - features |= VIRTIO_NET_F_GUEST_CSUM; - else - features &= ~VIRTIO_NET_F_GUEST_CSUM; - } - if (if_getcapabilities(ifp) & IFCAP_LRO && !vtnet_software_lro(sc)) { if (if_getcapenable(ifp) & IFCAP_LRO) features |= VTNET_LRO_FEATURES;