svn commit: r366721 - head/sys/dev/hyperv/netvsc

Wei Hu whu at FreeBSD.org
Thu Oct 15 11:44:28 UTC 2020


Author: whu
Date: Thu Oct 15 11:44:28 2020
New Revision: 366721
URL: https://svnweb.freebsd.org/changeset/base/366721

Log:
  Hyper-V: hn: Relinquish cpu in HN_LOCK to avoid deadlock
  
  The try lock loop in HN_LOCK put the thread spinning on cpu if the lock
  is not available. It is possible to cause deadlock if the thread holding
  the lock is sleeping. Relinquish the cpu to work around this problem even
  it doesn't completely solve the issue. The priority inversion could cause
  the livelock no matter how less likely it could happen. A more complete
  solution may be needed in the future.
  
  Reported by:	Microsoft, Netapp
  MFC after:	2 weeks
  Sponsored by:	Microsoft

Modified:
  head/sys/dev/hyperv/netvsc/if_hn.c

Modified: head/sys/dev/hyperv/netvsc/if_hn.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/if_hn.c	Thu Oct 15 05:57:20 2020	(r366720)
+++ head/sys/dev/hyperv/netvsc/if_hn.c	Thu Oct 15 11:44:28 2020	(r366721)
@@ -71,8 +71,10 @@ __FBSDID("$FreeBSD$");
 #include <sys/module.h>
 #include <sys/queue.h>
 #include <sys/lock.h>
+#include <sys/proc.h>
 #include <sys/rmlock.h>
 #include <sys/sbuf.h>
+#include <sys/sched.h>
 #include <sys/smp.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
@@ -165,8 +167,11 @@ __FBSDID("$FreeBSD$");
 #define HN_LOCK_ASSERT(sc)		sx_assert(&(sc)->hn_lock, SA_XLOCKED)
 #define HN_LOCK(sc)					\
 do {							\
-	while (sx_try_xlock(&(sc)->hn_lock) == 0)	\
+	while (sx_try_xlock(&(sc)->hn_lock) == 0) {	\
+		/* Relinquish cpu to avoid deadlock */	\
+		sched_relinquish(curthread);		\
 		DELAY(1000);				\
+	}						\
 } while (0)
 #define HN_UNLOCK(sc)			sx_xunlock(&(sc)->hn_lock)
 


More information about the svn-src-head mailing list