git: d82a9494e798 - stable/15 - u2f(4): Use taskqueue to start USB transfers from kqueue context
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 27 Sep 2025 10:26:52 UTC
The branch stable/15 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=d82a9494e7985dd9e3e8b5d31f9488e60972b865 commit d82a9494e7985dd9e3e8b5d31f9488e60972b865 Author: Vladimir Kondratyev <wulf@FreeBSD.org> AuthorDate: 2025-09-25 07:54:19 +0000 Commit: Vladimir Kondratyev <wulf@FreeBSD.org> CommitDate: 2025-09-27 10:25:05 +0000 u2f(4): Use taskqueue to start USB transfers from kqueue context to avoid recursion on u2f mutex and taking of hidbus sleepable lock. Tested by: emaste PR: 289494 MFC after: 2 days (cherry picked from commit 186e433300fed9093dd9716baa20e838eb3b51b6) --- sys/dev/hid/u2f.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/dev/hid/u2f.c b/sys/dev/hid/u2f.c index ac2eba7a499d..39610845c5fb 100644 --- a/sys/dev/hid/u2f.c +++ b/sys/dev/hid/u2f.c @@ -47,6 +47,7 @@ #include <sys/selinfo.h> #include <sys/sysctl.h> #include <sys/systm.h> +#include <sys/taskqueue.h> #include <sys/uio.h> #include <dev/evdev/input.h> @@ -78,6 +79,7 @@ struct u2f_softc { struct cdev *dev; struct mtx sc_mtx; /* hidbus private mutex */ + struct task sc_kqtask; /* kqueue task */ void *sc_rdesc; hid_size_t sc_rdesc_size; hid_size_t sc_isize; @@ -121,6 +123,7 @@ static device_probe_t u2f_probe; static device_attach_t u2f_attach; static device_detach_t u2f_detach; +static void u2f_kqtask(void *context, int pending); static int u2f_kqread(struct knote *, long); static void u2f_kqdetach(struct knote *); static void u2f_notify(struct u2f_softc *); @@ -174,6 +177,7 @@ u2f_attach(device_t dev) mtx_init(&sc->sc_mtx, "u2f lock", NULL, MTX_DEF); knlist_init_mtx(&sc->sc_rsel.si_note, &sc->sc_mtx); + TASK_INIT(&sc->sc_kqtask, 0, u2f_kqtask, sc); make_dev_args_init(&mda); mda.mda_flags = MAKEDEV_WAITOK; @@ -217,6 +221,7 @@ u2f_detach(device_t dev) destroy_dev(sc->dev); } + taskqueue_drain(taskqueue_thread, &sc->sc_kqtask); hid_intr_stop(sc->sc_dev); knlist_clear(&sc->sc_rsel.si_note, 0); @@ -519,6 +524,14 @@ u2f_kqfilter(struct cdev *dev, struct knote *kn) return (0); } +static void +u2f_kqtask(void *context, int pending) +{ + struct u2f_softc *sc = context; + + hid_intr_start(sc->sc_dev); +} + static int u2f_kqread(struct knote *kn, long hint) { @@ -533,7 +546,7 @@ u2f_kqread(struct knote *kn, long hint) } else { ret = sc->sc_state.data ? 1 : 0; if (!sc->sc_state.data) - hid_intr_start(sc->sc_dev); + taskqueue_enqueue(taskqueue_thread, &sc->sc_kqtask); } return (ret);