diff options
author | Zbigniew Bodek <zbb@FreeBSD.org> | 2017-05-30 11:55:02 +0000 |
---|---|---|
committer | Zbigniew Bodek <zbb@FreeBSD.org> | 2017-05-30 11:55:02 +0000 |
commit | e67c655431b463c93cb8194a118f8a7cd9dc7dff (patch) | |
tree | f9883573f630a6b86f99c64767372f4d2ba623ca /sys/dev/ena/ena.c | |
parent | 1e9fb89962095a532753fb194811c323d6ea147b (diff) | |
download | src-e67c655431b463c93cb8194a118f8a7cd9dc7dff.tar.gz src-e67c655431b463c93cb8194a118f8a7cd9dc7dff.zip |
Add locks before each ena_up and ena_down
Lock only ena_up and ena_down calls in ioctl handler, instead of whole
ioctl. Locking ioctl with sx lock that is sleepable, is not allowed in
some cases, e.g. when multicast options are being changed.
Additional locking was added in deatch function to prevent race condition
with ioctl function.
Submitted by: Michal Krawczyk <mk@semihalf.com>
Obtained from: Semihalf
Sponsored by: Amazon.com Inc.
Differential revision: https://reviews.freebsd.org/D10924
Notes
Notes:
svn path=/head/; revision=319198
Diffstat (limited to 'sys/dev/ena/ena.c')
-rw-r--r-- | sys/dev/ena/ena.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c index 0bc0aa7208fe..7a9e0350afc8 100644 --- a/sys/dev/ena/ena.c +++ b/sys/dev/ena/ena.c @@ -2285,16 +2285,16 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) /* * Acquiring lock to prevent from running up and down routines parallel. */ - sx_xlock(&adapter->ioctl_sx); - rc = 0; switch (command) { case SIOCSIFMTU: + sx_xlock(&adapter->ioctl_sx); ena_down(adapter); ena_change_mtu(ifp, ifr->ifr_mtu); rc = ena_up(adapter); + sx_unlock(&adapter->ioctl_sx); break; case SIOCSIFFLAGS: @@ -2306,11 +2306,16 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) "ioctl promisc/allmulti\n"); } } else { + sx_xlock(&adapter->ioctl_sx); rc = ena_up(adapter); + sx_unlock(&adapter->ioctl_sx); } } else { - if (ifp->if_drv_flags & IFF_DRV_RUNNING) + if (ifp->if_drv_flags & IFF_DRV_RUNNING) { + sx_xlock(&adapter->ioctl_sx); ena_down(adapter); + sx_unlock(&adapter->ioctl_sx); + } } break; @@ -2333,8 +2338,10 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) } if (reinit && (ifp->if_drv_flags & IFF_DRV_RUNNING)) { + sx_xlock(&adapter->ioctl_sx); ena_down(adapter); rc = ena_up(adapter); + sx_unlock(&adapter->ioctl_sx); } } @@ -2344,8 +2351,6 @@ ena_ioctl(if_t ifp, u_long command, caddr_t data) break; } - sx_unlock(&adapter->ioctl_sx); - return (rc); } @@ -3666,7 +3671,9 @@ ena_detach(device_t pdev) taskqueue_drain(adapter->reset_tq, &adapter->reset_task); taskqueue_free(adapter->reset_tq); + sx_xlock(&adapter->ioctl_sx); ena_down(adapter); + sx_unlock(&adapter->ioctl_sx); if (adapter->ifp != NULL) { ether_ifdetach(adapter->ifp); |