git: 6f8b356c0b17 - stable/13 - LinuxKPI: Convert lkpi-shrinker lock to sx.

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Wed, 01 Jun 2022 21:51:46 UTC
The branch stable/13 has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=6f8b356c0b178897658f6714e5c6c6592fc6a116

commit 6f8b356c0b178897658f6714e5c6c6592fc6a116
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2022-05-17 12:10:20 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-06-01 21:50:13 +0000

    LinuxKPI: Convert lkpi-shrinker lock to sx.
    
    This fixes "might_sleep() with the following non-sleepable locks held:
    exclusive sleep mutex lkpi-shrinker" warnings.
    
    MFC after:      1 week
    Reviewed by:    hselasky, manu
    Differential Revision:  https://reviews.freebsd.org/D35047
    
    (cherry picked from commit 29d5f0c148059806d8f0d9e55acdd072994fa450)
---
 sys/compat/linuxkpi/common/src/linux_shrinker.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_shrinker.c b/sys/compat/linuxkpi/common/src/linux_shrinker.c
index b66316c22013..b48e491a4e2f 100644
--- a/sys/compat/linuxkpi/common/src/linux_shrinker.c
+++ b/sys/compat/linuxkpi/common/src/linux_shrinker.c
@@ -34,13 +34,13 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/queue.h>
 #include <sys/eventhandler.h>
-#include <sys/mutex.h>
+#include <sys/sx.h>
 
 #include <linux/compat.h>
 #include <linux/shrinker.h>
 
 TAILQ_HEAD(, shrinker) lkpi_shrinkers = TAILQ_HEAD_INITIALIZER(lkpi_shrinkers);
-static struct mtx mtx_shrinker;
+static struct sx sx_shrinker;
 
 int
 linuxkpi_register_shrinker(struct shrinker *s)
@@ -49,9 +49,9 @@ linuxkpi_register_shrinker(struct shrinker *s)
 	KASSERT(s != NULL, ("NULL shrinker"));
 	KASSERT(s->count_objects != NULL, ("NULL shrinker"));
 	KASSERT(s->scan_objects != NULL, ("NULL shrinker"));
-	mtx_lock(&mtx_shrinker);
+	sx_xlock(&sx_shrinker);
 	TAILQ_INSERT_TAIL(&lkpi_shrinkers, s, next);
-	mtx_unlock(&mtx_shrinker);
+	sx_xunlock(&sx_shrinker);
 	return (0);
 }
 
@@ -59,9 +59,9 @@ void
 linuxkpi_unregister_shrinker(struct shrinker *s)
 {
 
-	mtx_lock(&mtx_shrinker);
+	sx_xlock(&sx_shrinker);
 	TAILQ_REMOVE(&lkpi_shrinkers, s, next);
-	mtx_unlock(&mtx_shrinker);
+	sx_xunlock(&sx_shrinker);
 }
 
 #define	SHRINKER_BATCH	512
@@ -94,12 +94,11 @@ linuxkpi_vm_lowmem(void *arg __unused)
 {
 	struct shrinker *s;
 
-	linux_set_current(curthread);
-	mtx_lock(&mtx_shrinker);
+	sx_xlock(&sx_shrinker);
 	TAILQ_FOREACH(s, &lkpi_shrinkers, next) {
 		shrinker_shrink(s);
 	}
-	mtx_unlock(&mtx_shrinker);
+	sx_xunlock(&sx_shrinker);
 }
 
 static eventhandler_tag lowmem_tag;
@@ -108,7 +107,7 @@ static void
 linuxkpi_sysinit_shrinker(void *arg __unused)
 {
 
-	mtx_init(&mtx_shrinker, "lkpi-shrinker", NULL, MTX_DEF);
+	sx_init(&sx_shrinker, "lkpi-shrinker");
 	lowmem_tag = EVENTHANDLER_REGISTER(vm_lowmem, linuxkpi_vm_lowmem,
 	    NULL, EVENTHANDLER_PRI_FIRST);
 }
@@ -117,7 +116,7 @@ static void
 linuxkpi_sysuninit_shrinker(void *arg __unused)
 {
 
-	mtx_destroy(&mtx_shrinker);
+	sx_destroy(&sx_shrinker);
 	EVENTHANDLER_DEREGISTER(vm_lowmem, lowmem_tag);
 }