From nobody Wed Apr 01 22:33:28 2026 X-Original-To: dev-commits-src-main@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 4fmKWs19gtz6YfPk for ; Wed, 01 Apr 2026 22:33:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fmKWs0HMXz3wpT for ; Wed, 01 Apr 2026 22:33:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1775082809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lL7ema5ldZgLy9AAZS62VL/eFCGeaJhA+CajftLogqE=; b=ab8/SePXlTXlDqY9JEjhcEJLTCkxBJJ+OxqVXZiY7FNZdzdzKbMyneOyBPKBFJLkVD5qci Ggsx2nRXkbF8xs5Ac4ex9mpojP04qFRMWdCjYoHaNw+bqTpOT8Pn29WigGV7iq/tB0Ai85 fiSgiVtkTI2bFspgl3CmfyW+XgJpJSqx/PP4VSQv5p1gP2qQF1kZ6G56obY/sisKtz/KrL 06xL2A0lsVGT3JqtNdnn+hUbe6wDLzv1Ui8qv/XPYgLBDvPkts7hFBUaSnne/wdTRMrgjd vUo+qB0bq18CAT68xm/b3gFKL6vx3TcFBV1kn0lOPjYg4oM70ViPXtI54aQvPQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1775082809; a=rsa-sha256; cv=none; b=iEJEb77LOtxvnhfDt5rORGz214ICImWQJUKd1ZmCKCRoW2NkVsqYzTr+KWny/ICNgr+YwL YToB7+oJKHZ4FKZSZ/DI7GM6pp1ePednA9UISRm1Jd5mFLLwHSoWC2oJwTISofs+vNVSRF gOYa02wGnoIN3CStWBXqJsklAUoohh/7AyDWKzTvdBRETUVzLC9pFxJXiLL5wHIWTu9Wy0 Gq2GOWOq8yQuZWvDKhp4zRkSWACxcadJpuiEdyH0q5CG1cN2bQCxNxneB5lRvd9JBXeGzr UqcQvpG/oFy8Ay0oi/32hR3d4hXCU4kdiogihcrp9wLGqFT/qBPXsspeqEymSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1775082809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lL7ema5ldZgLy9AAZS62VL/eFCGeaJhA+CajftLogqE=; b=ncS0eSwOq+i8z2jvDPzB6fGtbp2XFra6baUM7ci6H704QelZXo9JAH6H9DngQLlyB/HvB5 UumqoAMXhINOC9v3Ga7YBbu/qZfMNnZVWwLgcQVmr/9t7GPheDw9/Y/r5ogDmKzTXok+Us TTCFBT5dCwA3+yIREoKpiRo/XaVGF9OKPVOTmEOYFOzFRIxyBhs/PcTDaYFcJJpAT3U2jq p3ce2gW5A5mS/lP7JSuJFIr/ZHuwmHNxaN6+AQL6/6E8cvWxhzp0eMd/MUsBayv7QJuVUE BJzmm9bDlb+2uzvmAGwywvqNOiRTMM9WCav9+m3pEc9tQ64825y/rV5LWvx6mg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fmKWr70cVzbps for ; Wed, 01 Apr 2026 22:33:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 452a7 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 01 Apr 2026 22:33:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 0b4f0e0515d0 - main - kqueue: compare against the size in kqueue_expand List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0b4f0e0515d0c7ec855cd654ae5dc562f4931cae Auto-Submitted: auto-generated Date: Wed, 01 Apr 2026 22:33:28 +0000 Message-Id: <69cd9d38.452a7.4d5842ab@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=0b4f0e0515d0c7ec855cd654ae5dc562f4931cae commit 0b4f0e0515d0c7ec855cd654ae5dc562f4931cae Author: Kyle Evans AuthorDate: 2026-04-01 22:30:48 +0000 Commit: Kyle Evans CommitDate: 2026-04-01 22:30:48 +0000 kqueue: compare against the size in kqueue_expand This is a cosmetic change, rather than a functional one: comparing the knlistsize against the fd requires a little bit of mental gymnastics to confirm that this is fine and not doing unnecessary work in some cases. Notably, one must consider that kq_knlistsize only grows in KQEXTENT chunks, which means that concurrent threads trying to grow the kqueue to consecutive fds will usually not result in the list being replaced twice. One can also more clearly rule out classes of arithmetic problems in the final `else` branch. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D56209 --- sys/kern/kern_event.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index f984161bfcd6..2cdc37b710e6 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -2013,10 +2013,11 @@ kqueue_expand(struct kqueue *kq, const struct filterops *fops, uintptr_t ident, to_free = NULL; if (fops->f_isfd) { fd = ident; - if (kq->kq_knlistsize <= fd) { - size = kq->kq_knlistsize; - while (size <= fd) + size = atomic_load_int(&kq->kq_knlistsize); + if (size <= fd) { + do { size += KQEXTENT; + } while (size <= fd); list = malloc(size * sizeof(*list), M_KQUEUE, mflag); if (list == NULL) return ENOMEM; @@ -2024,7 +2025,7 @@ kqueue_expand(struct kqueue *kq, const struct filterops *fops, uintptr_t ident, if ((kq->kq_state & KQ_CLOSING) != 0) { to_free = list; error = EBADF; - } else if (kq->kq_knlistsize > fd) { + } else if (kq->kq_knlistsize >= size) { to_free = list; } else { if (kq->kq_knlist != NULL) { @@ -2039,6 +2040,7 @@ kqueue_expand(struct kqueue *kq, const struct filterops *fops, uintptr_t ident, kq->kq_knlistsize = size; kq->kq_knlist = list; } + MPASS(error != 0 || kq->kq_knlistsize > fd); KQ_UNLOCK(kq); } } else {