Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Avoid callout_halt under lock.



details:   https://anonhg.NetBSD.org/src/rev/7c3bbdbb4d2e
branches:  trunk
changeset: 937521:7c3bbdbb4d2e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Aug 20 21:35:44 2020 +0000

description:
Avoid callout_halt under lock.

- We could pass the lock in, except we hold another lock too.

- We could halt before taking the other lock, but it's not safe to
  sleep after getting the session pointer before taking its lock.

- We could halt before getting the session pointer, but then there's
  no point in doing it under the lock.

So just halt a little earlier instead.

diffstat:

 sys/net/if_wg.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r 13b3e644f11d -r 7c3bbdbb4d2e sys/net/if_wg.c
--- a/sys/net/if_wg.c   Thu Aug 20 21:35:33 2020 +0000
+++ b/sys/net/if_wg.c   Thu Aug 20 21:35:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wg.c,v 1.17 2020/08/20 21:35:33 riastradh Exp $     */
+/*     $NetBSD: if_wg.c,v 1.18 2020/08/20 21:35:44 riastradh Exp $     */
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.17 2020/08/20 21:35:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.18 2020/08/20 21:35:44 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1829,13 +1829,14 @@
        wg_clear_states(wgs);
        WG_TRACE("WGS_STATE_ESTABLISHED");
 
+       wg_stop_handshake_timeout_timer(wgp);
+
        mutex_enter(wgp->wgp_lock);
        wg_swap_sessions(wgp);
        wgs_prev = wgp->wgp_session_unstable;
        mutex_enter(wgs_prev->wgs_lock);
 
        getnanotime(&wgp->wgp_last_handshake_time);
-       wg_stop_handshake_timeout_timer(wgp);
        wgp->wgp_handshake_start_time = 0;
        wgp->wgp_last_sent_mac1_valid = false;
        wgp->wgp_last_sent_cookie_valid = false;



Home | Main Index | Thread Index | Old Index