git: 306c9049c642 - main - kqueue: add some kn_knlist assertions around knlist_(add|remove)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 01 Apr 2026 22:33:32 UTC
The branch main has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=306c9049c642da6a59a5dc088589605a9aa38b87
commit 306c9049c642da6a59a5dc088589605a9aa38b87
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-04-01 22:30:48 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-04-01 22:30:48 +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
Differential Revision: https://reviews.freebsd.org/D56211
---
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 485123989319..deb23ae96f9a 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -2617,6 +2617,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);
@@ -2639,6 +2641,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);