Module Name: src Committed By: jdolecek Date: Wed Mar 18 19:23:13 UTC 2020
Modified Files: src/sys/arch/xen/include: xennet_checksum.h src/sys/arch/xen/xen: if_xennet_xenbus.c xennet_checksum.c xennetback_xenbus.c Log Message: use NET[RT]XF_data_validated flag to mark when Tx packet has valid checksum; this is used to skip software checksum validation on xennet Rx side when configured for Rx offloading in Dom0 assume that checksum is valid when the Tx mbuf has no offload flags - in that case either it's local packet where checksum has just been computed in software, or forwarded external packet already verified when received on Dom0 practical offshot of this is that DomU doesn't re-verify checksum of packets forwarded from external hosts, e.g. via bridge(4) To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/xen/include/xennet_checksum.h cvs rdiff -u -r1.90 -r1.91 src/sys/arch/xen/xen/if_xennet_xenbus.c cvs rdiff -u -r1.6 -r1.7 src/sys/arch/xen/xen/xennet_checksum.c cvs rdiff -u -r1.79 -r1.80 src/sys/arch/xen/xen/xennetback_xenbus.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/xen/include/xennet_checksum.h diff -u src/sys/arch/xen/include/xennet_checksum.h:1.2 src/sys/arch/xen/include/xennet_checksum.h:1.3 --- src/sys/arch/xen/include/xennet_checksum.h:1.2 Mon Mar 16 20:51:36 2020 +++ src/sys/arch/xen/include/xennet_checksum.h Wed Mar 18 19:23:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xennet_checksum.h,v 1.2 2020/03/16 20:51:36 jdolecek Exp $ */ +/* $NetBSD: xennet_checksum.h,v 1.3 2020/03/18 19:23:12 jdolecek Exp $ */ /*- * Copyright (c)2006 YAMAMOTO Takashi, @@ -32,6 +32,6 @@ struct ifnet; struct mbuf; -int xennet_checksum_fill(struct ifnet *, struct mbuf *); +int xennet_checksum_fill(struct ifnet *, struct mbuf *, bool); #endif /* !_XEN_XENNET_CHECKSUM_H_ */ Index: src/sys/arch/xen/xen/if_xennet_xenbus.c diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.90 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.91 --- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.90 Mon Mar 16 20:51:36 2020 +++ src/sys/arch/xen/xen/if_xennet_xenbus.c Wed Mar 18 19:23:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: if_xennet_xenbus.c,v 1.90 2020/03/16 20:51:36 jdolecek Exp $ */ +/* $NetBSD: if_xennet_xenbus.c,v 1.91 2020/03/18 19:23:13 jdolecek Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -84,7 +84,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.90 2020/03/16 20:51:36 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.91 2020/03/18 19:23:13 jdolecek Exp $"); #include "opt_xen.h" #include "opt_nfs_boot.h" @@ -1120,8 +1120,9 @@ again: m->m_ext.ext_paddr = pa; m->m_flags |= M_EXT_RW; /* we own the buffer */ } - if ((rx->flags & NETRXF_csum_blank) != 0) { - xennet_checksum_fill(ifp, m); + if ((rx->flags & (NETRXF_csum_blank|NETRXF_data_validated))) { + xennet_checksum_fill(ifp, m, + ((rx->flags & NETRXF_data_validated) != 0)); } /* free req may overwrite *rx, better doing it late */ xennet_rx_free_req(req); @@ -1231,7 +1232,7 @@ xennet_softstart(void *arg) (M_CSUM_TCPv4 | M_CSUM_UDPv4)) != 0) { txflags = NETTXF_csum_blank; } else { - txflags = 0; + txflags = NETTXF_data_validated; } if (m->m_pkthdr.len != m->m_len || Index: src/sys/arch/xen/xen/xennet_checksum.c diff -u src/sys/arch/xen/xen/xennet_checksum.c:1.6 src/sys/arch/xen/xen/xennet_checksum.c:1.7 --- src/sys/arch/xen/xen/xennet_checksum.c:1.6 Mon Mar 16 20:51:36 2020 +++ src/sys/arch/xen/xen/xennet_checksum.c Wed Mar 18 19:23:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xennet_checksum.c,v 1.6 2020/03/16 20:51:36 jdolecek Exp $ */ +/* $NetBSD: xennet_checksum.c,v 1.7 2020/03/18 19:23:13 jdolecek Exp $ */ /*- * Copyright (c)2006 YAMAMOTO Takashi, @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.6 2020/03/16 20:51:36 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.7 2020/03/18 19:23:13 jdolecek Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -46,6 +46,17 @@ __KERNEL_RCSID(0, "$NetBSD: xennet_check #include <xen/xennet_checksum.h> +static struct evcnt xn_cksum_defer = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "xennet", "csum blank"); +static struct evcnt xn_cksum_undefer = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "xennet", "csum undeferred"); +static struct evcnt xn_cksum_valid = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "xennet", "csum data valid"); + +EVCNT_ATTACH_STATIC(xn_cksum_defer); +EVCNT_ATTACH_STATIC(xn_cksum_undefer); +EVCNT_ATTACH_STATIC(xn_cksum_valid); + /* ratecheck(9) for checksum validation failures */ static const struct timeval xn_cksum_errintvl = { 600, 0 }; /* 10 min, each */ @@ -66,7 +77,7 @@ m_extract(struct mbuf *m, int off, int l * for hw offload to do it */ int -xennet_checksum_fill(struct ifnet *ifp, struct mbuf *m) +xennet_checksum_fill(struct ifnet *ifp, struct mbuf *m, bool data_validated) { const struct ether_header *eh; struct ip *iph; @@ -94,8 +105,9 @@ xennet_checksum_fill(struct ifnet *ifp, } else { static struct timeval lasttime; if (ratecheck(&lasttime, &xn_cksum_errintvl)) - printf("%s: unknown etype %#x passed no checksum\n", - ifp->if_xname, ntohs(etype)); + printf("%s: unknown etype %#x passed%s\n", + ifp->if_xname, ntohs(etype), + data_validated ? "" : " no checksum"); return EINVAL; } @@ -127,21 +139,35 @@ xennet_checksum_fill(struct ifnet *ifp, { static struct timeval lasttime; if (ratecheck(&lasttime, &xn_cksum_errintvl)) - printf("%s: unknown proto %d passed no checksum\n", - ifp->if_xname, nxt); + printf("%s: unknown proto %d passed%s\n", + ifp->if_xname, nxt, + data_validated ? "" : " no checksum"); error = EINVAL; goto out; } } - /* - * Only compute the checksum if impossible to defer. - */ - sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_csum_flags_rx; - - if (sw_csum & (M_CSUM_UDPv4|M_CSUM_TCPv4)) { - in_undefer_cksum(m, ehlen, - sw_csum & (M_CSUM_UDPv4|M_CSUM_TCPv4)); + if (!data_validated) { + /* + * Only compute the checksum if impossible to defer. + */ + sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_csum_flags_rx; + + if (sw_csum & (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4)) { + in_undefer_cksum(m, ehlen, + sw_csum & (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4)); + } + + if (m->m_pkthdr.csum_flags != 0) { + xn_cksum_defer.ev_count++; +#ifdef M_CSUM_BLANK + m->m_pkthdr.csum_flags |= M_CSUM_BLANK; +#endif + } else { + xn_cksum_undefer.ev_count++; + } + } else { + xn_cksum_valid.ev_count++; } out: Index: src/sys/arch/xen/xen/xennetback_xenbus.c diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.79 src/sys/arch/xen/xen/xennetback_xenbus.c:1.80 --- src/sys/arch/xen/xen/xennetback_xenbus.c:1.79 Tue Mar 17 05:04:10 2020 +++ src/sys/arch/xen/xen/xennetback_xenbus.c Wed Mar 18 19:23:13 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xennetback_xenbus.c,v 1.79 2020/03/17 05:04:10 kre Exp $ */ +/* $NetBSD: xennetback_xenbus.c,v 1.80 2020/03/18 19:23:13 jdolecek Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.79 2020/03/17 05:04:10 kre Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.80 2020/03/18 19:23:13 jdolecek Exp $"); #include "opt_xen.h" @@ -881,8 +881,9 @@ xennetback_evthandler(void *arg) xennetback_tx_response(xneti, txreq.id, NETIF_RSP_OKAY); - if ((txreq.flags & NETTXF_csum_blank) != 0) { - xennet_checksum_fill(ifp, m); + if ((txreq.flags & (NETTXF_csum_blank|NETTXF_data_validated))) { + xennet_checksum_fill(ifp, m, + ((txreq.flags & NETTXF_data_validated) != 0)); } m_set_rcvif(m, ifp); @@ -1051,7 +1052,7 @@ xennetback_ifsoftstart_transfer(void *ar (M_CSUM_TCPv4 | M_CSUM_UDPv4)) != 0) { rxresp->flags = NETRXF_csum_blank; } else { - rxresp->flags = 0; + rxresp->flags = NETRXF_data_validated; } /* * transfers the page containing the packet to the @@ -1360,7 +1361,7 @@ xennetback_ifsoftstart_copy(void *arg) (M_CSUM_TCPv4 | M_CSUM_UDPv4)) != 0) { rxresp->flags = NETRXF_csum_blank; } else { - rxresp->flags = 0; + rxresp->flags = NETRXF_data_validated; } mbufs_sent[i] = m;