From nobody Mon Jul 13 19:40:52 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 4gzXq90GhHz6lhPS for ; Mon, 13 Jul 2026 19:40:53 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gzXq85rFCz3VRn for ; Mon, 13 Jul 2026 19:40:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783971652; 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=1ad6yCHTjz4JAyVcaKQ/K2oo0anU1yc69It3nrPKtYk=; b=mP86Tc/X//T/Iscglc57IvtmSU4HXcOQfvzYaq9R+oQ2D/NiT7CwcVwbIMFSBnILuA15/d tbfnm98+XfZn6T/LwILoRYbaTkiqo+D2ZUTl43Zo1dgytt7OWVrGLtSLEXNLrN4Fwsfmba OGUsRmnyRpmeMEfslD3AysR5tNHrf11IDSKxPSDJj5+GvIj29VZ43FVi9rC0h3zzgSayS5 kvFR/63nZgy4a/BTf8l+sHtLpHEzESNEZkmKl1HaIEOqMeUM5EbXlSgo0YtggA9NReucJT i7dqXKwtXx1Kyhf95EaS7wZ0+r8Oise4W5h2Q49VX8OZ4yOc2IfXi8e2d1xrbg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783971652; a=rsa-sha256; cv=none; b=BsIjSz5mBqEMTapLGoxgduCjB5oigZ7AMpqmV1vARXKLF5dpcH3HA2X5ictv92qGFR/Do7 e94PZr6Ft7KuCvE+M8o945oTpKcBaTYkBa5dXp6cGfIeULg/vWT9AkS2Qon+U4b9s4abfZ uB0xTHqnQ7OUIK3qsNH9QfUYU6wLl5wNzsK3AX4HNPmiZGrXeWrmFVLmdMOvNt0kcRt6Ff vfnpQfDATHusLhzGGyIFakkCTkB82BucnrPNwiGD++g1AW8JnVKGc4ALKLVbqv8N6zIGnQ qvw3yx0XNqb4h0Sk5HF/Leo8oyV8ICWUHcTCGzY6pBmFkleykGwhEBvpEnOUEw== 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=1783971652; 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=1ad6yCHTjz4JAyVcaKQ/K2oo0anU1yc69It3nrPKtYk=; b=BIPNhh3l5he2QuKJBD6TiudiD/WreMmO7MLH8X3MdFAeOWsGp/2iSxb5gXttDY3fUiR4kd mXgfaRsQiHsvAvUmZzKzFUBCLBxnZ946aOz+SZu/u4G2bnuZIpLNPx79TBfRX3CpW+pSSF uKJ60QL0Imv2tBJERPlqYmLWcib5WMtqCFlv+T3oCdFghUhvj3YPOWm+MkV6gQQisWn+3h /6djGYrZJx2YpFxVFf8e3C2o9GhgJLepjfV71hfZ3WuNXLfdMw6hEoiUeEN/DQfbaVCy7s ZPVePPvLP1urKXVEH0XpZxvXtybqNoYYQmP9tk4xrQ7pkNTU3qiqJzWCsxgfpg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gzXq84T9hz1B3L for ; Mon, 13 Jul 2026 19:40:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33ae4 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 13 Jul 2026 19:40:52 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 185039d27252 - main - g_eli: disambiguate CPU-bound worker creation 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 185039d27252ae4ce7d6e3d68ba74907091cd565 Auto-Submitted: auto-generated Date: Mon, 13 Jul 2026 19:40:52 +0000 Message-Id: <6a553f44.33ae4.5f4d2431@gitrepo.freebsd.org> The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=185039d27252ae4ce7d6e3d68ba74907091cd565 commit 185039d27252ae4ce7d6e3d68ba74907091cd565 Author: Mitchell Horne AuthorDate: 2026-07-13 19:15:49 +0000 Commit: Mitchell Horne CommitDate: 2026-07-13 19:40:43 +0000 g_eli: disambiguate CPU-bound worker creation This makes an effort to clarify and correct the intent of the code, which is to either: 1. Create one software crypto worker thread for each CPU, to be pinned later 2. Create the number of threads requested by the kern.geom.eli.threads tunable This is as described in geli(8). If a CPU were somehow* absent, it should be skipped, but not in the second case when creating a set number of threads. To achieve this cleanly and correctly: - split worker creation logic into a helper function - keep the loops separate - debug message for absent CPUs is dropped - add a short explanatory comment - style, rename local var to 'nthreads' *Practically, it is impossible today to get a bootable system with a sparsely populated CPU map. Thus these concerns are hypothetical and this change should have no functional effect. Finally, while here, guard the sc->sc_workers list insertion with the appropriate mutex. The code is safe from races today, but this gives a better guarantee. Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58214 --- sys/geom/eli/g_eli.c | 114 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 42 deletions(-) diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c index d302d84fc415..6b763496baf5 100644 --- a/sys/geom/eli/g_eli.c +++ b/sys/geom/eli/g_eli.c @@ -990,17 +990,63 @@ g_eli_free_data(struct bio *bp) bp->bio_driver2 = NULL; } +static int +g_eli_create_worker(struct g_eli_softc *sc, struct gctl_req *req, + struct g_provider *bpp, u_int idx) +{ + struct g_eli_worker *wr; + int error; + + wr = malloc(sizeof(*wr), M_ELI, M_WAITOK | M_ZERO); + wr->w_softc = sc; + wr->w_number = idx; + wr->w_active = TRUE; + + error = g_eli_newsession(wr); + if (error != 0) { + free(wr, M_ELI); + if (req != NULL) { + gctl_error(req, "Cannot set up crypto session " + "for %s (error=%d).", bpp->name, error); + } else { + G_ELI_DEBUG(1, "Cannot set up crypto session " + "for %s (error=%d).", bpp->name, error); + } + return (error); + } + + error = kproc_create(g_eli_worker, wr, &wr->w_proc, 0, 0, + "g_eli[%u] %s", idx, bpp->name); + if (error != 0) { + g_eli_freesession(wr); + free(wr, M_ELI); + if (req != NULL) { + gctl_error(req, "Cannot create kernel thread " + "for %s (error=%d).", bpp->name, error); + } else { + G_ELI_DEBUG(1, "Cannot create kernel thread " + "for %s (error=%d).", bpp->name, error); + } + return (error); + } + + mtx_lock(&sc->sc_queue_mtx); + LIST_INSERT_HEAD(&sc->sc_workers, wr, w_next); + mtx_unlock(&sc->sc_queue_mtx); + + return (0); +} + struct g_geom * g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, const struct g_eli_metadata *md, const u_char *mkey, int nkey) { struct g_eli_softc *sc; - struct g_eli_worker *wr; struct g_geom *gp; struct g_provider *pp; struct g_consumer *cp; struct g_geom_alias *gap; - u_int i, threads; + u_int i, nthreads; int dcw, error; G_ELI_DEBUG(1, "Creating device %s%s.", bpp->name, G_ELI_SUFFIX); @@ -1080,49 +1126,33 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp, LIST_INIT(&sc->sc_workers); - threads = g_eli_threads; - if (threads == 0) - threads = mp_ncpus; - sc->sc_cpubind = (mp_ncpus > 1 && threads == mp_ncpus); - for (i = 0; i < threads; i++) { - if (CPU_ABSENT(i)) { - G_ELI_DEBUG(1, "%s: CPU %u disabled, skipping.", - bpp->name, i); - continue; - } - wr = malloc(sizeof(*wr), M_ELI, M_WAITOK | M_ZERO); - wr->w_softc = sc; - wr->w_number = i; - wr->w_active = TRUE; + /* + * Create a pool of worker kthreads according to one of two schemes: + * + * 1. CPU-bound: one thread per entry in the CPU map, which + * may be sparsely populated. + * + * 2. kern.geom.eli.threads: A linear pool of threads according to + * the user-tuned value. This may be greater-than or less-than + * mp_ncpus. + */ + nthreads = g_eli_threads; + if (nthreads == 0) + nthreads = mp_ncpus; + sc->sc_cpubind = mp_ncpus > 1 && nthreads == mp_ncpus; - error = g_eli_newsession(wr); - if (error != 0) { - free(wr, M_ELI); - if (req != NULL) { - gctl_error(req, "Cannot set up crypto session " - "for %s (error=%d).", bpp->name, error); - } else { - G_ELI_DEBUG(1, "Cannot set up crypto session " - "for %s (error=%d).", bpp->name, error); - } - goto failed; + if (sc->sc_cpubind) { + CPU_FOREACH(i) { + error = g_eli_create_worker(sc, req, bpp, i); + if (error != 0) + goto failed; } - - error = kproc_create(g_eli_worker, wr, &wr->w_proc, 0, 0, - "g_eli[%u] %s", i, bpp->name); - if (error != 0) { - g_eli_freesession(wr); - free(wr, M_ELI); - if (req != NULL) { - gctl_error(req, "Cannot create kernel thread " - "for %s (error=%d).", bpp->name, error); - } else { - G_ELI_DEBUG(1, "Cannot create kernel thread " - "for %s (error=%d).", bpp->name, error); - } - goto failed; + } else { + for (i = 0; i < nthreads; i++) { + error = g_eli_create_worker(sc, req, bpp, i); + if (error != 0) + goto failed; } - LIST_INSERT_HEAD(&sc->sc_workers, wr, w_next); } /*