git: d02c54533aa4 - stable/15 - kqueue: add some kn_knlist assertions around knlist_(add|remove)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 13 Apr 2026 04:01:52 UTC
The branch stable/15 has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=d02c54533aa49980ad3e8b984d9af4ec835d9adc
commit d02c54533aa49980ad3e8b984d9af4ec835d9adc
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-04-01 22:30:48 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-04-13 03:12:29 +0000
kqueue: add some kn_knlist assertions around knlist_(add|remove)
We currently assert that kn_status is accurate, but there's more room
for error. Neither of these are very likely, but currently we'd blow up
in SLIST*() macros instead of providing more obvious diagnostics. It's
perhaps only worth testing these because knlist_remove() requires
getting logic across both f_attach() and f_detach() correct.
Reviewed by: kib, markj
(cherry picked from commit 306c9049c642da6a59a5dc088589605a9aa38b87)
---
sys/kern/kern_event.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 2d7df3da58bb..915d34ac1695 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -2619,6 +2619,8 @@ knlist_add(struct knlist *knl, struct knote *kn, int islocked)
KASSERT(kn_in_flux(kn), ("knote %p not in flux", kn));
KASSERT((kn->kn_status & KN_DETACHED) != 0,
("knote %p was not detached", kn));
+ KASSERT(kn->kn_knlist == NULL,
+ ("knote %p was already on knlist %p", kn, kn->kn_knlist));
if (!islocked)
knl->kl_lock(knl->kl_lockarg);
SLIST_INSERT_HEAD(&knl->kl_list, kn, kn_selnext);
@@ -2641,6 +2643,8 @@ knlist_remove_kq(struct knlist *knl, struct knote *kn, int knlislocked,
KASSERT(kqislocked || kn_in_flux(kn), ("knote %p not in flux", kn));
KASSERT((kn->kn_status & KN_DETACHED) == 0,
("knote %p was already detached", kn));
+ KASSERT(kn->kn_knlist == knl,
+ ("knote %p was not on knlist %p", kn, knl));
if (!knlislocked)
knl->kl_lock(knl->kl_lockarg);
SLIST_REMOVE(&knl->kl_list, kn, knote, kn_selnext);