gve_xmit_ifp() runs without gve_iface_lock: it tests IFF_DRV_RUNNING
and then enqueues xmit_task on tx->xmit_tq or transmits directly
under the ring lock. Meanwhile, gve_down() clears IFF_DRV_RUNNING
and proceeds to quiesce and free the ring taskqueues. A caller that
tested IFF_DRV_RUNNING just before gve_down() cleared it can still
enqueue xmit_task on a taskqueue that is being quiesced or freed, or
transmit directly while the queues are torn down.
Test IFF_DRV_RUNNING inside a NET_EPOCH section in gve_xmit_ifp(),
keep the section active until gve_xmit_ifp() returns, and call
NET_EPOCH_WAIT() in gve_down() right after clearing IFF_DRV_RUNNING
so all in-flight transmit callers finish before ring taskqueues are
quiesced and freed.
The net epoch is used over a local lock or driver-private epoch for
performance and precedent: it avoids taking a lock on every transmit,
reuses the net epoch the stack normally enters before if_transmit
(entered explicitly since some callers such as lagg(4) do not), and
follows the same flag-clear plus NET_EPOCH_WAIT() pattern used by
wg(4), mlx5, and if_vlan(4).
Also free the packet when the interface is not running. if_transmit
owns the mbuf on every return, but gve_xmit_ifp() returned ENODEV
without freeing it.
In A/B testing on arm64 (c4a-standard-8, FreeBSD 14.5), the nested
NET_EPOCH section added a minor cost on single-thread 64-byte UDP
transmit (~24-30 ns/pkt, ~3.4-4.1% at ~1.45 Mpps), with no
noticeable effect on multi-stream UDP or TCP throughput and CPU.
Fixes: 54dfc97b0bd9 ("Add gve, the driver for Google Virtual NIC (gVNIC)")
Reviewed-by: Jasper Tran O'Leary <jtranoleary@google.com>
Signed-off-by: Tim Hostetler <thostet@google.com>