From nobody Thu Oct 23 14:07:03 2025 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4csnsc4khbz6DZpn for ; Thu, 23 Oct 2025 14:07:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4csnsc1Wtmz3Nvv; Thu, 23 Oct 2025 14:07:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 59NE73uZ022480; Thu, 23 Oct 2025 17:07:06 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 59NE73uZ022480 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 59NE7376022479; Thu, 23 Oct 2025 17:07:03 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 23 Oct 2025 17:07:03 +0300 From: Konstantin Belousov To: Kyle Evans Cc: FreeBSD CURRENT , wulf@freebsd.org Subject: Re: evdev-induced panic (devfs / destroy_dev race?) Message-ID: References: List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4csnsc1Wtmz3Nvv On Thu, Oct 23, 2025 at 07:41:48AM -0500, Kyle Evans wrote: > Hi, > > Not sure if anyone else has noticed this, but I seem to have scared up an evdev panic: > > Fatal trap 9: general protection fault while in kernel mode > cpuid = 1; apic id = 01 > instruction pointer = 0x20:0xffffffff80b98b5b > stack pointer = 0x28:0xfffffe01a62b4b60 > frame pointer = 0x28:0xfffffe01a62b4c00 > code segment = base 0x0, limit 0xfffff, type 0x1b > = DPL 0, pres 1, long 1, def32 0, gran 1 > processor eflags = interrupt enabled, resume, IOPL = 0 > current process = 7339 (moused) > rdi: fffff80001b55128 rsi: 0000000000000001 rdx: 0000000000000000 > rcx: fffffe0186e5b570 r8: fffff80353686cd0 r9: fffffe01a62b5000 > rax: fffff800027d7780 rbx: fffff80001b55128 rbp: fffffe01a62b4c00 > r10: 0000000000002af8 r11: 000000000000298c r12: fffff80353686780 > r13: deadc0dedeadc0c0 r14: 0000000000000001 r15: 0000000000000000 > trap number = 9 > panic: general protection fault > cpuid = 1 > time = 1761098215 > KDB: stack backtrace: > db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe01a62b48e0 > vpanic() at vpanic+0x136/frame 0xfffffe01a62b4a10 > panic() at panic+0x43/frame 0xfffffe01a62b4a70 > trap_fatal() at trap_fatal+0x68/frame 0xfffffe01a62b4a90 > calltrap() at calltrap+0x8/frame 0xfffffe01a62b4a90 > --- trap 0x9, rip = 0xffffffff80b98b5b, rsp = 0xfffffe01a62b4b60, rbp = 0xfffffe01a62b4c00 --- > _sx_xlock_hard() at _sx_xlock_hard+0x18b/frame 0xfffffe01a62b4c00 > _sx_xlock() at _sx_xlock+0xac/frame 0xfffffe01a62b4c40 > evdev_dtor() at evdev_dtor+0x5c/frame 0xfffffe01a62b4c70 > devfs_destroy_cdevpriv() at devfs_destroy_cdevpriv+0xab/frame 0xfffffe01a62b4c90 > devfs_close_f() at devfs_close_f+0x63/frame 0xfffffe01a62b4cc0 > _fdrop() at _fdrop+0x1a/frame 0xfffffe01a62b4ce0 > closef() at closef+0x1e3/frame 0xfffffe01a62b4d70 > closefp_impl() at closefp_impl+0x71/frame 0xfffffe01a62b4db0 > closefp_hl() at closefp_hl+0x70/frame 0xfffffe01a62b4e00 > amd64_syscall() at amd64_syscall+0x169/frame 0xfffffe01a62b4f30 > fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe01a62b4f30 > --- syscall (6, FreeBSD ELF64, close), rip = 0x2b5f166d5eaa, rsp = 0x2b5f133b49c8, rbp = 0x2b5f133b4ab0 --- > KDB: enter: panic > > This was seemingly the result of removing my mouse's USB dongle. Presumably detach revoked the client and > woke it up, which then triggered the above close() from moused to race with destroy_dev() for invoking the > cdevpriv dtor. Do you have core dump? > > I spent a few minutes thinking about it and didn't really come to a good idea of what the fix might be, > though I suspect there's nothing evdev can really do about it at the moment and we might need to somehow > coordinate this in destroy_dev(). destroy_dev() already does the following; - clears si_devsw so no new thread could enter devfs cdev methods - drain until all threads in cdev methods return from them - destruct cdevprivs At this point no new cdevpriv structures should be created because no new threads are allowed into cdev methods. I would say that there is something else causing the problem, not a lack of coordination with destroy_dev().