From owner-dev-commits-src-branches@freebsd.org Mon Mar 15 05:16:42 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B9C9756FCE5; Mon, 15 Mar 2021 05:16:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DzPmB4wNRz3q8B; Mon, 15 Mar 2021 05:16:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9B1312D82; Mon, 15 Mar 2021 05:16:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 12F5Ggo2074773; Mon, 15 Mar 2021 05:16:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12F5GgBw074772; Mon, 15 Mar 2021 05:16:42 GMT (envelope-from git) Date: Mon, 15 Mar 2021 05:16:42 GMT Message-Id: <202103150516.12F5GgBw074772@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Wei Hu Subject: git: 70f7b2475333 - stable/12 - Hyper-V: hn: Relinquish cpu in HN_LOCK to avoid deadlock MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: whu X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 70f7b24753336efeb3cf6e73040780b2e4d28d8a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2021 05:16:42 -0000 The branch stable/12 has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=70f7b24753336efeb3cf6e73040780b2e4d28d8a commit 70f7b24753336efeb3cf6e73040780b2e4d28d8a Author: Wei Hu AuthorDate: 2020-10-15 11:44:28 +0000 Commit: Wei Hu 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 #include #include +#include #include #include +#include #include #include #include @@ -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)