From nobody Thu Sep 03 16:36:42 2026 X-Original-To: dev-commits-src-branches@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 4hbQGf70sDz6q2cb for ; Thu, 03 Sep 2026 16:36:42 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hbQGf3dT8z3FHb for ; Thu, 03 Sep 2026 16:36:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788453402; 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=VApGogTbfcdnDvUGWb3nU9Gj8WvjXfH9LboU+54n0aQ=; b=XBaXc4W25dwKhKOMh2+T4/uHbeCoB3+IyDmPBX7/8mznrnfWKX4SR1eh6iauQF+lv6KZTW JZ2X6mCA0hcteXE65QiW5dYRE1agSlDEM3D7qTAA0ydlsTmWBckDdjRY48palyMfEEKX0s R160+rfcSEF+6A/gI1UT42mECDVAu+VDI9FcdvpgRok/sYiSz0rcOL8DkdVZkraAYyr2gw cIB1uGJGENH/8FJIX8x2rOCkgpAbe8vhT/DfGryWOzMZXJA61aVBgGCt1IsDpYesIVLQWf GWovg8TKXaTk2QKcMdqRH1X5m8TAddP0E+i6cGmF/+8oI4j8ixgEcj/RmVRR3A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788453402; a=rsa-sha256; cv=none; b=LRIE3tJ+t4Stx7bmEZ/I/Hj2ZXT9FXt175dp7skm6DfUUzeamHzBIi7B3O2FBFzYjjlxQs MzoiELvJ7pTim8oXrlQyhNVdfZx+PbJeTzU7/FrBYhyLlouv9KTvaayngJuk/Fhh75yOcf Znvcbd7Yht42iGwkl0dBchykZwkFtw3Owi2r566tpEBtJg1FINAxsOuvBNb8MriD/ok3MH hiYZ9SLXAtrmJGtlLBuCiWq882l1p6dv7sexmH4OyTiZelzkuTnsd6C2+Azy8OhKMdJojV KknRxl1V99AcDPhMDNByPw66z+dqe72wFxZ24rkuoh8ZRkoDKTIOqx11lkM0eg== 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=1788453402; 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=VApGogTbfcdnDvUGWb3nU9Gj8WvjXfH9LboU+54n0aQ=; b=szUoKmAFVGlm88nUxuJeM8TiwL4U6r2bJRD6psAR2IAcuOhd0RfW0eYsme5OFinkuNLoNr r+w9ibJQi14+wnhKcqcAkyEjtwOg3VxcrVQCNFNa4Wznkv99AJzjQko3aZPW5Kg+ZmXydh hCM2uRTyxePt+RpA857BXaYlHLVs/w44IBw0Btv0M9nLKwiGkC9pZxZV3GCM48DbCfodVn grOPW+zv/7itcW8ChmhtwDkXdDQlVPMnJu14cUl1T7UAnBVdgkCdACZ9RQOWLxjQ5hM1Q9 9t+EoDHg8QGRiSt0p/aCPm5R0GqrdowgM6MgpiJF/fFLEjBVg1QMCpANvTJ7IA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hbQGf1JRkz5xK for ; Thu, 03 Sep 2026 16:36:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 38dd3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 03 Sep 2026 16:36:42 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 261d58969487 - stable/15 - g_eli: disambiguate CPU-bound worker creation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/15 X-Git-Reftype: branch X-Git-Commit: 261d589694875521d241b73d23c376e786d735e3 Auto-Submitted: auto-generated Date: Thu, 03 Sep 2026 16:36:42 +0000 Message-Id: <6a99a21a.38dd3.56e1ca33@gitrepo.freebsd.org> The branch stable/15 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=261d589694875521d241b73d23c376e786d735e3 commit 261d589694875521d241b73d23c376e786d735e3 Author: Mitchell Horne AuthorDate: 2026-07-13 19:15:49 +0000 Commit: Mitchell Horne CommitDate: 2026-09-03 16:32:36 +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 (cherry picked from commit 185039d27252ae4ce7d6e3d68ba74907091cd565) --- 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 bc321a0561c8..597464fd2ce4 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); } /*