On Fri, Nov 18, 2022 at 11:03:06AM -0500, Dave Voutila wrote:
> That fixes booting and the Surface Keyboard is usable, but I'm getting
> spurious faults coming from retpoline out of filt_wseventdetach if I
> detach and reattach the Surface Keyboard multiple times while running
> Xorg.
> 
> It's not consistent, but I've been able to trigger it 3 times now. 2 via
> physical detach/reattach of the Surface Keyboard and another by just
> running `sysctl machdep.forceukdb=1` which apparently detaches/attaches
> behind the scenes.

It seems that the detaching can leave behind dangling wsevent knotes.
They should be ferreted out before the device disappears.

Does the following patch help?

klist_invalidate() can block, so I put it before ev->q is freed and
set NULL. This tries to avoid causing new races with wsevent_init().

The detach logic is tangled and particularly so with ws devices,
so I am uncertain if tweaking just wsevent_fini() is enough.

Index: dev/wscons/wsevent.c
===================================================================
RCS file: src/sys/dev/wscons/wsevent.c,v
retrieving revision 1.26
diff -u -p -r1.26 wsevent.c
--- dev/wscons/wsevent.c        2 Jul 2022 08:50:42 -0000       1.26
+++ dev/wscons/wsevent.c        19 Nov 2022 15:05:26 -0000
@@ -131,6 +131,9 @@ wsevent_fini(struct wseventvar *ev)
 #endif
                return;
        }
+
+       klist_invalidate(&ev->sel.si_note);
+
        free(ev->q, M_DEVBUF, WSEVENT_QSIZE * sizeof(struct wscons_event));
        ev->q = NULL;
 

Reply via email to