git: fa1a4ff944f4 - stable/12 - netmap: vtnet: stop krings during interface reset
Vincenzo Maffione
vmaffione at FreeBSD.org
Sun Jan 17 13:40:07 UTC 2021
The branch stable/12 has been updated by vmaffione:
URL: https://cgit.FreeBSD.org/src/commit/?id=fa1a4ff944f4b3e841df0cdd67c6373a589ffdd5
commit fa1a4ff944f4b3e841df0cdd67c6373a589ffdd5
Author: Vincenzo Maffione <vmaffione at FreeBSD.org>
AuthorDate: 2021-01-09 22:34:10 +0000
Commit: Vincenzo Maffione <vmaffione at FreeBSD.org>
CommitDate: 2021-01-17 13:38:09 +0000
netmap: vtnet: stop krings during interface reset
Similarly to what done for iflib in 1d238b07d5d4d9660ae0e,
this patch prevents access to the krings during the interface
reset triggered by netmap_register().
MFC after: 1 week
(cherry picked from commit 9ac59d42c0b4b6cd9c36a5dace7f49753c2e175a)
netmap: vtnet: enable/disable krings on any interface reinit
See 3d65fd97e85ab807f3b for a detailed explanation.
PR: 252453
MFC after: 1 week
(cherry picked from commit bb714db6d39583a9fbf5d11849c5e2365e7c0d80)
netmap: vtnet: fix RX initialization after netmap_reset()
At device reset, we must not publish those netmap receive buffers
that are owned by userspace (nm_kr_rxspace).
MFC after: 1 week
(cherry picked from commit 3005e10ddbfbec3ecf46a080607bb0d85986eee5)
---
sys/dev/netmap/if_vtnet_netmap.h | 21 +++++++++++++--------
sys/dev/netmap/netmap.c | 4 ++++
sys/dev/virtio/network/if_vtnet.c | 10 ++++++++++
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/sys/dev/netmap/if_vtnet_netmap.h b/sys/dev/netmap/if_vtnet_netmap.h
index 0f686ed60788..cd652938bca5 100644
--- a/sys/dev/netmap/if_vtnet_netmap.h
+++ b/sys/dev/netmap/if_vtnet_netmap.h
@@ -50,7 +50,7 @@ vtnet_netmap_reg(struct netmap_adapter *na, int state)
: VTNET_INIT_NETMAP_EXIT);
VTNET_CORE_UNLOCK(sc);
- return 0;
+ return (0);
}
@@ -213,20 +213,25 @@ vtnet_netmap_rxq_populate(struct vtnet_rxq *rxq)
struct netmap_kring *kring;
struct netmap_slot *slot;
int error;
+ int num;
slot = netmap_reset(na, NR_RX, rxq->vtnrx_id, 0);
if (slot == NULL)
return -1;
kring = na->rx_rings[rxq->vtnrx_id];
- /* Expose all the RX netmap buffers we can. In case of no indirect
+ /*
+ * Expose all the RX netmap buffers we can. In case of no indirect
* buffers, the number of netmap slots in the RX ring matches the
* maximum number of 2-elements sglist that the RX virtqueue can
- * accommodate. We need to start from kring->nr_hwcur, which is 0
- * on netmap register and may be different from 0 if a virtio
- * re-init happens while the device is in use by netmap. */
- rxq->vtnrx_nm_refill = kring->nr_hwcur;
- error = vtnet_netmap_kring_refill(kring, na->num_rx_desc - 1);
+ * accommodate. We need to start from kring->nr_hwtail, which is 0
+ * on the first netmap register and may be different from 0 if a
+ * virtio re-init (caused by a netma register or i.e., ifconfig)
+ * happens while the device is in use by netmap.
+ */
+ rxq->vtnrx_nm_refill = kring->nr_hwtail;
+ num = na->num_rx_desc - 1 - nm_kr_rxspace(kring);
+ error = vtnet_netmap_kring_refill(kring, num);
virtqueue_notify(rxq->vtnrx_vq);
return error;
@@ -256,7 +261,7 @@ vtnet_netmap_rxsync(struct netmap_kring *kring, int flags)
* First part: import newly received packets.
* Only accept our own buffers (matching the token). We should only get
* matching buffers. The hwtail should never overrun hwcur, because
- * we publish only N-1 receive buffers (and non N).
+ * we publish only N-1 receive buffers (and not N).
* In any case we must not leave this routine with the interrupts
* disabled, pending packets in the VQ and hwtail == (hwcur - 1),
* otherwise the pending packets could stall.
diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c
index 075c27b7a597..f75567565bf1 100644
--- a/sys/dev/netmap/netmap.c
+++ b/sys/dev/netmap/netmap.c
@@ -616,6 +616,10 @@ netmap_set_all_rings(struct netmap_adapter *na, int stopped)
if (!nm_netmap_on(na))
return;
+ if (netmap_verbose) {
+ nm_prinf("%s: %sable all rings", na->name,
+ (stopped ? "dis" : "en"));
+ }
for_rx_tx(t) {
for (i = 0; i < netmap_real_rings(na, t); i++) {
netmap_set_ring(na, i, t, stopped);
diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index ff0a07672f49..6018fe56e360 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -2833,6 +2833,11 @@ vtnet_stop(struct vtnet_softc *sc)
/* Only advisory. */
vtnet_disable_interrupts(sc);
+#ifdef DEV_NETMAP
+ /* Stop any pending txsync/rxsync and disable them. */
+ netmap_disable_all_rings(ifp);
+#endif /* DEV_NETMAP */
+
/*
* Stop the host adapter. This resets it to the pre-initialized
* state. It will not generate any interrupts until after it is
@@ -3098,6 +3103,11 @@ vtnet_init_locked(struct vtnet_softc *sc, int init_mode)
vtnet_update_link_status(sc);
callout_reset(&sc->vtnet_tick_ch, hz, vtnet_tick, sc);
+#ifdef DEV_NETMAP
+ /* Re-enable txsync/rxsync. */
+ netmap_enable_all_rings(ifp);
+#endif /* DEV_NETMAP */
+
return;
fail:
More information about the dev-commits-src-all
mailing list