From owner-svn-src-user@freebsd.org Mon Jan 15 00:57:56 2018 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 64656E6EFB4 for ; Mon, 15 Jan 2018 00:57:56 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3EDEC764D9; Mon, 15 Jan 2018 00:57:56 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6533415C3; Mon, 15 Jan 2018 00:57:55 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0F0vtg8047210; Mon, 15 Jan 2018 00:57:55 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0F0vtB5047209; Mon, 15 Jan 2018 00:57:55 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201801150057.w0F0vtB5047209@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Mon, 15 Jan 2018 00:57:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r327986 - user/markj/netdump/sys/dev/virtio/network X-SVN-Group: user X-SVN-Commit-Author: markj X-SVN-Commit-Paths: user/markj/netdump/sys/dev/virtio/network X-SVN-Commit-Revision: 327986 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jan 2018 00:57:56 -0000 Author: markj Date: Mon Jan 15 00:57:55 2018 New Revision: 327986 URL: https://svnweb.freebsd.org/changeset/base/327986 Log: Add netdump support to vtnet(4). Tested with bhyve. Modified: user/markj/netdump/sys/dev/virtio/network/if_vtnet.c Modified: user/markj/netdump/sys/dev/virtio/network/if_vtnet.c ============================================================================== --- user/markj/netdump/sys/dev/virtio/network/if_vtnet.c Mon Jan 15 00:57:09 2018 (r327985) +++ user/markj/netdump/sys/dev/virtio/network/if_vtnet.c Mon Jan 15 00:57:55 2018 (r327986) @@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -143,7 +144,7 @@ static struct mbuf * struct virtio_net_hdr *); static int vtnet_txq_enqueue_buf(struct vtnet_txq *, struct mbuf **, struct vtnet_tx_header *); -static int vtnet_txq_encap(struct vtnet_txq *, struct mbuf **); +static int vtnet_txq_encap(struct vtnet_txq *, struct mbuf **, int); #ifdef VTNET_LEGACY_TX static void vtnet_start_locked(struct vtnet_txq *, struct ifnet *); static void vtnet_start(struct ifnet *); @@ -231,6 +232,8 @@ static void vtnet_disable_interrupts(struct vtnet_soft static int vtnet_tunable_int(struct vtnet_softc *, const char *, int); +NETDUMP_DEFINE(vtnet); + /* Tunables. */ static SYSCTL_NODE(_hw, OID_AUTO, vtnet, CTLFLAG_RD, 0, "VNET driver parameters"); static int vtnet_csum_disable = 0; @@ -1027,6 +1030,8 @@ vtnet_setup_interface(struct vtnet_softc *sc) vtnet_set_rx_process_limit(sc); vtnet_set_tx_intr_threshold(sc); + NETDUMP_SET(ifp, vtnet); + return (0); } @@ -1779,6 +1784,7 @@ vtnet_rxq_eof(struct vtnet_rxq *rxq) m = virtqueue_dequeue(vq, &len); if (m == NULL) break; + deq++; if (len < sc->vtnet_hdr_size + ETHER_HDR_LEN) { @@ -1806,6 +1812,7 @@ vtnet_rxq_eof(struct vtnet_rxq *rxq) vtnet_rxq_discard_buf(rxq, m); if (nbufs > 1) vtnet_rxq_discard_merged_bufs(rxq, nbufs); + printf("vtnet_rxq_replace_buf failed!\n"); continue; } @@ -2177,7 +2184,7 @@ fail: } static int -vtnet_txq_encap(struct vtnet_txq *txq, struct mbuf **m_head) +vtnet_txq_encap(struct vtnet_txq *txq, struct mbuf **m_head, int flags) { struct vtnet_tx_header *txhdr; struct virtio_net_hdr *hdr; @@ -2187,7 +2194,7 @@ vtnet_txq_encap(struct vtnet_txq *txq, struct mbuf **m m = *m_head; M_ASSERTPKTHDR(m); - txhdr = uma_zalloc(vtnet_tx_header_zone, M_NOWAIT | M_ZERO); + txhdr = uma_zalloc(vtnet_tx_header_zone, flags | M_ZERO); if (txhdr == NULL) { m_freem(m); *m_head = NULL; @@ -2261,7 +2268,7 @@ again: if (m0 == NULL) break; - if (vtnet_txq_encap(txq, &m0) != 0) { + if (vtnet_txq_encap(txq, &m0, M_NOWAIT) != 0) { if (m0 != NULL) IFQ_DRV_PREPEND(&ifp->if_snd, m0); break; @@ -2338,7 +2345,7 @@ again: break; } - if (vtnet_txq_encap(txq, &m) != 0) { + if (vtnet_txq_encap(txq, &m, M_NOWAIT) != 0) { if (m != NULL) drbr_putback(ifp, br, m); else @@ -3977,3 +3984,82 @@ vtnet_tunable_int(struct vtnet_softc *sc, const char * return (def); } + +#ifdef NETDUMP +static void +vtnet_netdump_init(struct ifnet *ifp, int *nmbufp, int *nclustp) +{ + struct vtnet_softc *sc; + + sc = ifp->if_softc; + + /* + * Allocate enough packet buffers to fill an entire queue. This ought + * to be enough provided that we don't have many queues. + */ + *nmbufp += virtqueue_size(sc->vtnet_rxqs[0].vtnrx_vq); + *nclustp += virtqueue_size(sc->vtnet_rxqs[0].vtnrx_vq); + + /* + * We need to allocate from this zone in the transmit path, so ensure + * that we have at least one item per header available. + * XXX add a separate zone like we do for mbufs? otherwise we may alloc + * buckets + */ + uma_zone_reserve_kva(vtnet_tx_header_zone, NETDUMP_MAX_IN_FLIGHT * 2); +} + +static void +vtnet_netdump_event(struct ifnet *ifp, enum netdump_ev event) +{ + struct vtnet_softc *sc; + + sc = ifp->if_softc; + + switch (event) { + case NETDUMP_START: + sc->vtnet_rx_clsize = MCLBYTES; + break; + default: + break; + } +} + +static int +vtnet_netdump_transmit(struct ifnet *ifp, struct mbuf *m) +{ + struct vtnet_softc *sc; + struct vtnet_txq *txq; + int error; + + sc = ifp->if_softc; + + if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != + IFF_DRV_RUNNING) + return (EBUSY); + + txq = &sc->vtnet_txqs[0]; + error = vtnet_txq_encap(txq, &m, M_NOWAIT | M_USE_RESERVE); + if (error == 0) + error = vtnet_txq_notify(txq); + return (error); +} + +static int +vtnet_netdump_poll(struct ifnet *ifp, int count) +{ + struct vtnet_softc *sc; + int i; + + sc = ifp->if_softc; + + if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != + IFF_DRV_RUNNING) + return (EBUSY); + + (void)vtnet_txq_eof(&sc->vtnet_txqs[0]); + for (i = 0; i < sc->vtnet_max_vq_pairs; i++) + (void)vtnet_rxq_eof(&sc->vtnet_rxqs[i]); + return (0); +} +#endif /* NETDUMP */