• Vitaliy Makkoveev [2023-10-05 00:02]:
On 5 Oct 2023, at 00:56, Kirill Miazine <k...@krot.org> wrote:
new diff doesn't prevent hang in test scenario either.
Which one?
I meant to say new diffS, as I had applied both... what I have now is this:
===================================================================
RCS file: /cvs/src/sys/net/if_wg.c,v
retrieving revision 1.31
diff -u -p -r1.31 if_wg.c
--- net/if_wg.c 26 Sep 2023 15:16:44 -0000 1.31
+++ net/if_wg.c 4 Oct 2023 22:05:05 -0000
@@ -507,13 +507,8 @@ wg_peer_destroy(struct wg_peer *peer)
noise_remote_clear(&peer->p_remote);
- NET_LOCK();
- while (!ifq_empty(&sc->sc_if.if_snd)) {
- NET_UNLOCK();
+ while (!ifq_empty(&sc->sc_if.if_snd))
tsleep_nsec(sc, PWAIT, "wg_ifq", 1000);
- NET_LOCK();
- }
- NET_UNLOCK();
taskq_barrier(wg_crypt_taskq);
taskq_barrier(net_tq(sc->sc_if.if_index));
@@ -2580,6 +2575,7 @@ wg_down(struct wg_softc *sc)
wg_unbind(sc);
rw_exit_read(&sc->sc_lock);
NET_LOCK();
+ ifq_purge(&sc->sc_if.if_snd);
}
int
Index: net/ifq.c
===================================================================
RCS file: /cvs/src/sys/net/ifq.c,v
retrieving revision 1.50
diff -u -p -r1.50 ifq.c
--- net/ifq.c 30 Jul 2023 05:39:52 -0000 1.50
+++ net/ifq.c 4 Oct 2023 22:05:05 -0000
@@ -529,6 +529,14 @@ ifq_hdatalen(struct ifqueue *ifq)
return (len);
}
+void
+ifq_set_maxlen(struct ifqueue *ifq, unsigned int maxlen)
+{
+ mtx_enter(&ifq->ifq_mtx);
+ ifq->ifq_maxlen = maxlen;
+ mtx_leave(&ifq->ifq_mtx);
+}
+
unsigned int
ifq_purge(struct ifqueue *ifq)
{
Index: net/ifq.h
===================================================================
RCS file: /cvs/src/sys/net/ifq.h,v
retrieving revision 1.38
diff -u -p -r1.38 ifq.h
--- net/ifq.h 30 Jul 2023 05:39:52 -0000 1.38
+++ net/ifq.h 4 Oct 2023 22:05:05 -0000
@@ -435,6 +435,7 @@ void ifq_deq_commit(struct ifqueue *,
void ifq_deq_rollback(struct ifqueue *, struct mbuf *);
struct mbuf *ifq_dequeue(struct ifqueue *);
int ifq_hdatalen(struct ifqueue *);
+void ifq_set_maxlen(struct ifqueue *, unsigned int);
void ifq_mfreem(struct ifqueue *, struct mbuf *);
void ifq_mfreeml(struct ifqueue *, struct mbuf_list *);
unsigned int ifq_purge(struct ifqueue *);
@@ -448,9 +449,8 @@ int ifq_deq_sleep(struct ifqueue *, st
const char *, volatile unsigned int *,
volatile unsigned int *);
-#define ifq_len(_ifq) ((_ifq)->ifq_len)
-#define ifq_empty(_ifq) (ifq_len(_ifq) == 0)
-#define ifq_set_maxlen(_ifq, _l) ((_ifq)->ifq_maxlen = (_l))
+#define ifq_len(_ifq) READ_ONCE((_ifq)->ifq_len)
+#define ifq_empty(_ifq) (ifq_len(_ifq) == 0)
static inline int
ifq_is_priq(struct ifqueue *ifq)
@@ -490,8 +490,8 @@ int ifiq_input(struct ifiqueue *, stru
int ifiq_enqueue(struct ifiqueue *, struct mbuf *);
void ifiq_add_data(struct ifiqueue *, struct if_data *);
-#define ifiq_len(_ifiq) ml_len(&(_ifiq)->ifiq_ml)
-#define ifiq_empty(_ifiq) ml_empty(&(_ifiq)->ifiq_ml)
+#define ifiq_len(_ifiq) READ_ONCE(ml_len(&(_ifiq)->ifiq_ml))
+#define ifiq_empty(_ifiq) (ifiq_len(_ifiq) == 0)
#endif /* _KERNEL */