From nobody Mon Sep 14 20:17:25 2026 X-Original-To: dev-commits-src-all@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 4hkGfM0pvcz6rg8V 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 4hkGfM05WKz4ftj for ; Mon, 14 Sep 2026 20:17:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789417051; 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=HSNq1g676prUQJYyrP6Kqb5d2UI3GdTH7fd5L5ERp0kUcIKXVozFReUVB+c4jpeT6I4xvE uhETrDTOPEVg5HmOU09BXzYwJ/3WB5kQYkWeuM9eTijGWIgVNlAMELkxYxlnEWj5qc2ZGN wjaWSoRxmB7IoyXiHTSxXNNRA+jt/MeFbpDLVMuBfwfXwwTBxqnfFKUnS9YQU+2OFjuvar RRP5s0Gm9CpexkuzUyPlf0mcMin2J1vcAs3dQNgFLpABr4STpzxBnbOtlQqId8VYKvmko+ Gcarraa9skH9QXgBXbWhKoL9o5hEYHoSBQQ17SGLKkWaWB2Z2nKpP9c1CenPQQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789417051; b=fkvR/5y5aBlkLDUDDckYo4o10j2fXeK5CjO1H2aH+HXFkTrCt1EMhVn9rd9sYM5fSQIZsj 2gvRJBiC9WPgzZ8tmjSzQpvSWgJq7Uvo0zVV9MUjz7lNO8iO+/i7Ejfr7IVrwCINxgpk28 mW0BG+AmigWYoDAMkO7KFFB3oJ5+DcgckT1Z9u57sFiLtcsE1e1I9RgUsvxgDNMBPkdkwd lCOrY2EYXaZQTSvPD61prd02g2l/XBjoLsPYxLv2vS3ZDtdGrYBPFQsgOAQtRj9wLfEFDZ ZEa4S5WYSZWS60rXehAPZnqBPCkQSs6ImiR2a4qIPYlrUfFhShIytSeQ4f2w0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789417051; 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=Uqlf3O/Hv90gN8ye5cLenLBNGUolGjXyfD6rtscJj5B/PTURSv8nt3NTvhXp9vqRAPFldB baUts1RhNHyjP2K4Ik1Nc03JrSd1BuKbUIVomq5RxKEYyFxq1kXpjGHlwRT4NmU2wP7wAR 30o/EhtvkNKIhQwXTXR0UMloHuQa7Eps1pQLrBNT6JOu0c8jeG95oMQ8seYnIk2A315TnL z/ePs3rw4m0d8rY+ns6ldS7Y1OSnQTPTEgERvLL26AF4ZIhlb1LLSL3qSTvvqvmT00DiqG eQBKKacvu5fHs+4lL7kp+qPcHR2kHSElaNw60A1MpV/QpP/9L3x8ADzak11H/Q== 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 4hkGfL5nBRzSXh 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 all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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;