Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056701; b=CQL0Pr/Dpo3PJijTBnS8DDQN7NAsL9khOwWHqu25om1B55ysh68p5uo8guQnxdKyP44C sfXfuq3ovLeE1ZWTAhnZXccrLbcRI8XeUmh2OFSnZaBQRXWoFI178HVtrMtmutORMmiPV KbGLtzQPKmdO/Xro+sTPEqHjGc8Wp9tsceIywzrWQp4YnR/T9disRqdVVCIjsAjX7P8Tl oBygSCZUQQL7/YQUWOqcNB3KlzZa9mVl7BesG95l5YFHwUcVlJt3/iSU7JMhecLT5zxvn IQZ6MiZ2QSeVyVkGIYK9BBn2aNyyU/XyJVKkqtAgyexg90O5T4JlDNzqUhZ5ET0pEIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056701; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=AGnh/rsMHqpHPo/JeV0jy7cKbJuO7qn8U02oBBwYTj8=; b=aqV5SmLnazUEbQkoxPCFw+PCeDOBigro21AY3djUfnYUQe4itYg19xPClvSwHCvNnQ7N lXkmxfOQA/BknnYonXYfNiWzYI2Oo+ZDP6QeKKmIZ1F6Sc4RKVw2aq2qPau6s/PlTlIY5 RbaPW+sXJIVzkVlQOQWa6a+wiVDfDOw4X1/EM2hOazgZOBZ3TU0u5FKiGq5bW8H7HS1fx B2jYA25O8VJbF5ikxiibXSjn9lTyxCq4XydjAskLG7xnOaO+2qxZLNd9G0MoHlUUxHb7W 1i10/FQILV5wU9hkGHHsGpiFj7u6P6vfJH9JuRoOJXFwnoTwhqNcdsYy5/abCZy2RSg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Twybuq3h; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3F31606A31C for ; Mon, 30 Nov 2026 16:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Twybuq3h Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDEBD1F00897; Mon, 30 Nov 2026 16:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796056701; bh=AGnh/rsMHqpHPo/JeV0jy7cKbJuO7qn8U02oBBwYTj8=; h=From:To:Cc:Subject:Date; b=Twybuq3h9fRV/AvIdmnZfilwSaD2RVcr78zDXcUAsmj1EkuT+mnG4cAh7iacJKdjM zV9wbiLomDrCgm0BomxNQaBuxtSRxvAznMhl1YG++0GNJjtpBs6iaISvxgtt/cWggh RT9t3aKHWFQeKE6s0nUzv+2ZLGENZm33AJZT2jX5aTVTen2fqLtiAt+bWI3z1avTjv CpWNcn7UzvR3LyURnNf5IZhiwbxuDnaSXFNStoxIQ1he5LWOPIh7vTHN3dlH4XCtQH SZeDjMtvpSL2OdnPixyzlxLd5yIZa+bSAlejtrTJEnpa8i7001c0NGuYywTIp7NDOJ cARdSHK/iaReg== From: Trond Myklebust To: dwarves@vger.kernel.org Cc: Arnaldo Carvalho de Melo , Alan Maguire , Ihor Solodrai Subject: [PATCH dwarves] dwarf_loader: Don't crash when a worker thread can't be created Date: Mon, 30 Nov 2026 11:36:19 -0500 Message-ID: <20261130163619.3004516-1-trondmy@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: dwarves@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Trond Myklebust dwarf_cus__process_cus() stores the return value of pthread_create() in dcus->error, which the workers that are already running read. If the creation of a worker fails with EAGAIN, dwarf_cus__nextcu() returns 11 to a running worker, dwarf_loader__decode_next_cu() only treats negative values as errors, and the worker dereferences a NULL dcu. If the first pthread_create() fails, pahole exits with status 0 without encoding anything. Kernel builds hit this intermittently, since pahole gets the make job count as -j and many pahole processes run at once during module BTF generation: ./scripts/gen-btf.sh: line 70: ... Segmentation fault (core dumped) ${PAHOLE} -J ... The job queue doesn't depend on the number of workers, so carry on with the workers that did start, and do the work in the calling thread if none did. Also stop storing a positive ENOMEM in dcus->error, and treat any value other than 0 and 1 from dwarf_cus__nextcu() as an error. Fixes: 4c916259c3e7 ("dwarf_loader: Multithreading with a job/worker model") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Trond Myklebust --- dwarf_loader.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 10ab37a9bc2f..dd9c2f0eb146 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -5217,8 +5217,8 @@ static int dwarf_cus__nextcu(struct dwarf_cus *dcus, struct dwarf_cu **dcu, if (ret == 0 && *cu_die != NULL) { *dcu = dwarf_cus__create_cu(dcus, *cu_die, *pointer_size); if (*dcu == NULL) { - dcus->error = ENOMEM; - ret = -1; + dcus->error = -ENOMEM; + ret = -ENOMEM; goto out_unlock; } // Do it here to keep all CUs in cus->cus in the same @@ -5241,10 +5241,10 @@ static struct cu *dwarf_loader__decode_next_cu(struct dwarf_cus *dcus) err = dwarf_cus__nextcu(dcus, &dcu, &die_mem, &cu_die, &pointer_size, &offset_size); - if (err < 0) - goto out_error; - else if (err == 1) /* no more CUs */ + if (err == 1) /* no more CUs */ return NULL; + else if (err) + goto out_error; err = die__process_and_recode(cu_die, dcu->cu, dcus->conf); if (err) @@ -5370,17 +5370,29 @@ static int dwarf_cus__process_cus(struct dwarf_cus *dcus) list_add(&job->node, &cus_processing_queue.jobs); } + /* Workers that are already running read dcus->error, so don't store + * pthread_create() errors there. The queue doesn't depend on the + * number of workers: carry on with the ones that did start, or do + * the work in this thread if none did. + */ for (i = 0; i < nr_workers; ++i) { - dcus->error = pthread_create(&workers[i], NULL, - dwarf_loader__worker_thread, - dcus); - if (dcus->error) - goto out_join; + int err = pthread_create(&workers[i], NULL, + dwarf_loader__worker_thread, dcus); + + if (err) { + fprintf(stderr, "pahole: started %d of %d DWARF loader threads: %s\n", + i, nr_workers, strerror(err)); + break; + } } - dcus->error = 0; + if (i == 0) { + void *res = dwarf_loader__worker_thread(dcus); + + if (res != NULL) + dcus->error = (long)res; + } -out_join: while (--i >= 0) { void *res; int err = pthread_join(workers[i], &res); -- 2.56.1