diff options
| author | Vladimir Kondratyev <wulf@FreeBSD.org> | 2025-09-25 07:54:19 +0000 |
|---|---|---|
| committer | Vladimir Kondratyev <wulf@FreeBSD.org> | 2025-09-25 07:54:19 +0000 |
| commit | 186e433300fed9093dd9716baa20e838eb3b51b6 (patch) | |
| tree | f280f4df9b5f58c59c2e2719b801ef6c314faf57 | |
| parent | 56e01d0d7e0f7c2129c05467ca99d5f5538f52bc (diff) | |
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
| -rw-r--r-- | sys/dev/hid/u2f.c | 15 |
1 files changed, 14 insertions, 1 deletions
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); |
