summaryrefslogtreecommitdiff
path: root/sys/netinet/in.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2024-01-06 10:58:46 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2024-01-06 10:58:46 +0000
commit3a62aa44389f62e3c1882453a2f52127e16354a5 (patch)
treef6f16cebadab2c8a66c88faafc89268f41b466ee /sys/netinet/in.c
parent0e15f6ca0303b5954586a8f02c9027f370722254 (diff)
Take net lock before kernel lock.
Doing KERNEL_LOCK() just before NET_LOCK() does not make sense. Net lock is a rwlock that releases kernel lock during sleep. To avoid an unnecessary release and take kernel lock cycle, move KERNEL_LOCK() after NET_LOCK(). There is no lock order reversal deadlock issue. Both locks are used in any order thoughout the kernel. As NET_LOCK() releases the kernel lock when it cannot take the lock immediately and has to sleep, we always end in the order kernel lock before net lock after sleeping. OK sashan@
Diffstat (limited to 'sys/netinet/in.c')
-rw-r--r--sys/netinet/in.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index d2207b3e124..7cf2cc6392c 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.c,v 1.185 2023/06/28 11:49:49 kn Exp $ */
+/* $OpenBSD: in.c,v 1.186 2024/01/06 10:58:45 bluhm Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
@@ -260,8 +260,8 @@ in_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged)
return (error);
}
- KERNEL_LOCK();
NET_LOCK();
+ KERNEL_LOCK();
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
if (ifa->ifa_addr->sa_family != AF_INET)
@@ -331,8 +331,8 @@ in_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged)
break;
}
err:
- NET_UNLOCK();
KERNEL_UNLOCK();
+ NET_UNLOCK();
return (error);
}
@@ -353,8 +353,8 @@ in_ioctl_set_ifaddr(u_long cmd, caddr_t data, struct ifnet *ifp)
if (error)
return (error);
- KERNEL_LOCK();
NET_LOCK();
+ KERNEL_LOCK();
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
if (ifa->ifa_addr->sa_family != AF_INET)
@@ -387,8 +387,8 @@ in_ioctl_set_ifaddr(u_long cmd, caddr_t data, struct ifnet *ifp)
if (!error)
if_addrhooks_run(ifp);
- NET_UNLOCK();
KERNEL_UNLOCK();
+ NET_UNLOCK();
return error;
}
@@ -409,8 +409,8 @@ in_ioctl_change_ifaddr(u_long cmd, caddr_t data, struct ifnet *ifp)
return (error);
}
- KERNEL_LOCK();
NET_LOCK();
+ KERNEL_LOCK();
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
if (ifa->ifa_addr->sa_family != AF_INET)
@@ -527,8 +527,8 @@ in_ioctl_change_ifaddr(u_long cmd, caddr_t data, struct ifnet *ifp)
panic("%s: invalid ioctl %lu", __func__, cmd);
}
- NET_UNLOCK();
KERNEL_UNLOCK();
+ NET_UNLOCK();
return (error);
}