Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci vioif(4): access to txq_active and rxq_active wi...
details: https://anonhg.NetBSD.org/src/rev/e3b870ac1db1
branches: trunk
changeset: 373953:e3b870ac1db1
user: yamaguchi <yamaguchi%NetBSD.org@localhost>
date: Thu Mar 23 01:26:29 2023 +0000
description:
vioif(4): access to txq_active and rxq_active with lock held
diffstat:
sys/dev/pci/if_vioif.c | 66 +++++++++++++++++++++++++++----------------------
1 files changed, 36 insertions(+), 30 deletions(-)
diffs (128 lines):
diff -r 5b4114fba8e3 -r e3b870ac1db1 sys/dev/pci/if_vioif.c
--- a/sys/dev/pci/if_vioif.c Thu Mar 23 01:23:18 2023 +0000
+++ b/sys/dev/pci/if_vioif.c Thu Mar 23 01:26:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_vioif.c,v 1.83 2023/03/23 01:23:18 yamaguchi Exp $ */
+/* $NetBSD: if_vioif.c,v 1.84 2023/03/23 01:26:29 yamaguchi Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.83 2023/03/23 01:23:18 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.84 2023/03/23 01:26:29 yamaguchi Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -1662,6 +1662,7 @@
struct vioif_softc *sc = device_private(virtio_child(vsc));
bool more;
+ KASSERT(mutex_owned(rxq->rxq_lock));
KASSERT(!rxq->rxq_stopping);
more = vioif_rx_deq_locked(sc, vsc, rxq, limit);
@@ -1674,7 +1675,8 @@
vioif_rx_sched_handle(sc, rxq);
return;
}
- atomic_store_relaxed(&rxq->rxq_active, false);
+
+ rxq->rxq_active = false;
}
static int
@@ -1686,22 +1688,23 @@
struct vioif_softc *sc = device_private(virtio_child(vsc));
u_int limit;
- limit = sc->sc_rx_intr_process_limit;
-
- if (atomic_load_relaxed(&rxq->rxq_active) == true)
- return 1;
mutex_enter(rxq->rxq_lock);
- if (!rxq->rxq_stopping) {
- rxq->rxq_workqueue = sc->sc_txrx_workqueue_sysctl;
-
- virtio_stop_vq_intr(vsc, vq);
- atomic_store_relaxed(&rxq->rxq_active, true);
-
- vioif_rx_handle_locked(rxq, limit);
- }
-
+ /* rx handler is already running in softint/workqueue */
+ if (rxq->rxq_active)
+ goto done;
+
+ if (rxq->rxq_stopping)
+ goto done;
+
+ rxq->rxq_active = true;
+
+ limit = sc->sc_rx_intr_process_limit;
+ virtio_stop_vq_intr(vsc, vq);
+ vioif_rx_handle_locked(rxq, limit);
+
+done:
mutex_exit(rxq->rxq_lock);
return 1;
}
@@ -1773,6 +1776,7 @@
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
bool more;
+ KASSERT(mutex_owned(txq->txq_lock));
KASSERT(!txq->txq_stopping);
more = vioif_tx_deq_locked(sc, vsc, txq, limit);
@@ -1790,7 +1794,8 @@
return;
}
- atomic_store_relaxed(&txq->txq_active, false);
+ txq->txq_active = false;
+
/* for ALTQ */
if (txq == &sc->sc_txq[0]) {
if_schedule_deferred_start(ifp);
@@ -1811,22 +1816,23 @@
limit = sc->sc_tx_intr_process_limit;
- if (atomic_load_relaxed(&txq->txq_active) == true)
- return 1;
-
mutex_enter(txq->txq_lock);
- if (!txq->txq_stopping) {
- txq->txq_workqueue = sc->sc_txrx_workqueue_sysctl;
-
- virtio_stop_vq_intr(vsc, vq);
- atomic_store_relaxed(&txq->txq_active, true);
-
- vioif_tx_handle_locked(txq, limit);
- }
-
+ /* tx handler is already running in softint/workqueue */
+ if (txq->txq_active)
+ goto done;
+
+ if (txq->txq_stopping)
+ goto done;
+
+ txq->txq_active = true;
+
+ virtio_stop_vq_intr(vsc, vq);
+ txq->txq_workqueue = sc->sc_txrx_workqueue_sysctl;
+ vioif_tx_handle_locked(txq, limit);
+
+done:
mutex_exit(txq->txq_lock);
-
return 1;
}
Home |
Main Index |
Thread Index |
Old Index