Date: Mon, 15 Mar 2021 05:16:42 GMT From: Wei Hu <whu@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 70f7b2475333 - stable/12 - Hyper-V: hn: Relinquish cpu in HN_LOCK to avoid deadlock Message-ID: <202103150516.12F5GgBw074772@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=70f7b24753336efeb3cf6e73040780b2e4d28d8a commit 70f7b24753336efeb3cf6e73040780b2e4d28d8a Author: Wei Hu <whu@FreeBSD.org> AuthorDate: 2020-10-15 11:44:28 +0000 Commit: Wei Hu <whu@FreeBSD.org> CommitDate: 2021-03-15 05:15:21 +0000 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 (cherry picked from commit b3460f44524b145c6c8a760ebe65052560a810bf) --- sys/dev/hyperv/netvsc/if_hn.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/dev/hyperv/netvsc/if_hn.c b/sys/dev/hyperv/netvsc/if_hn.c index e9d1b9439671..1945732590cc 100644 --- a/sys/dev/hyperv/netvsc/if_hn.c +++ b/sys/dev/hyperv/netvsc/if_hn.c @@ -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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103150516.12F5GgBw074772>