From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A177532B123 for ; Wed, 24 Jun 2026 05:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782278180; cv=none; b=qJ65Isqp6aZgRPTohgR69kiTEdCrLIaFrrzs33BPQllgUzJSB/a/9QXV2ByaA/+IYVq2ZfoVH9LAkNGg0uj6+R4Q5Kiuq0Cg68mMGhBNL6P3n6wNGscnYl1jmEQT/jSZBbpMKzCJpKVL96UBmsndqom1pxkX+VcgU3cWziUn0MI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782278180; c=relaxed/simple; bh=ntfUbjerjoiwZYnmLDvdmJfc3i00I0KJggwMyX+cjvU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YCieWsye7n9jowln696s42y09FSA6Xpy7SaclyBLT2NQUKJmuaDl6zsmD5oh4y5CJFNFv7G+TVyMFPOuEu8YHbCZKvsB4obciPN+y1JHRSwigoMLBccr04td2kpFUegCPZbff1i9Ir+jt8WJiLpvijNlufaRoA0DmJvAmdjulkk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PUJxLl3a; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PUJxLl3a" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1383723dfddso1390412c88.0 for ; Tue, 23 Jun 2026 22:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782278179; x=1782882979; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TOvgfK/YXBnBbR1lk38E5LQPe20hVZUh4Fxj/vXJics=; b=PUJxLl3aw1KMHRhcDey/7E/64p5A08ScFDA0cmUOJLqzGOwaBSbMxql8GI1e9t1+3N j+Pesm2EZAbrQgdorlyXxURxh/Z+Pl9Pz10Z8TWL6NOwy0bKIAtwfwxLs5X+39GCMs3z VxyOftgdUgjyP/tcJsFNtPYf7TH9F8+5ymIjG8qV3tmtuskr2MlMPnTsaojpZQ0bwJVf rc9dDp1fzN9fVWokzRrYUwOgyonvczJQU4nIYf7AWrBy2TktCOwPSMpg9YZjnxVBIPIc g8EIs+hwNna18r0z5oC52uf4szv2lT9Yj7AY3wRxtAlVsENbpKRfMXe2SJYayTF0fJbt IUxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782278179; x=1782882979; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TOvgfK/YXBnBbR1lk38E5LQPe20hVZUh4Fxj/vXJics=; b=QfIShaeG5YP6kknSDjO2N3fIDCiCnYwlzm6XOb85NJV3iTucNuepjm6+F7NUkvUvlv vM44CtXkpd0QEK8rmNrZ+AyryZKDx6HcUqKkaxS96qBF6lnYd096vMEg/A18/FWWozHK xF1lHuaJzqxrOihfRu6/MhS3QIRedY71atszxEhMiBidBXfErHOjVT1XBw59T+9JmF4v mDe4cyxjhSM4zaRbe/vss2xkzH2l/pMb+G8B2oYJuO8+YR4BiOm+/NijuaTjmnJwkfNA owN5s5Dk2N/Vi8iWOfHXYZDKFg9WVxnea2ccEJfuRp1pwmDmcMCiW+iCwEEfwkxxri9C ob3A== X-Forwarded-Encrypted: i=1; AFNElJ+mgV+fPeJzzToU1HR/c9oVdi/r+DyfWXVRvZKjlYYxucBLBh2uq4vWr0IRciQ6wXxWa2VyjN11unclq5Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxeILoFlrwAGk1O1NarQTrCanwrdDDI7vbWDouWwQpHu2cbaGVC rFhnKKqbBcqyBFZAByqU+D1ItcokBV8Ch43Xap8Zj1ZK37UVLkQ/Z0PywBi/O97FRrRgcqDDRL/ dwJ04Lk7b0Q== X-Received: from dlbtd2.prod.google.com ([2002:a05:7022:1a82:b0:138:17ae:de57]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ef12:b0:137:fad9:3a30 with SMTP id a92af1059eb24-139d0c89276mr1391954c88.19.1782278178417; Tue, 23 Jun 2026 22:16:18 -0700 (PDT) Date: Tue, 23 Jun 2026 22:15:34 -0700 In-Reply-To: <20260624051535.3584977-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260623053515.2677888-1-irogers@google.com> <20260624051535.3584977-1-irogers@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260624051535.3584977-18-irogers@google.com> Subject: [PATCH v2 16/16] perf synthetic-events: Fix divide by zero in perf_event__synthesize_threads From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, alice.mei.rogers@gmail.com, dapeng1.mi@linux.intel.com, james.clark@linaro.org, leo.yan@linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" If scandir() finds no matching tasks in /proc, n is 0. If thread_nr is > 1, we bypass the single-thread fast path and then clamp thread_nr to n, making it 0. This results in a divide by zero when calculating num_per_thread. Handle n <= 1 early to use the single-thread fast path and prevent the crash. Signed-off-by: Ian Rogers --- tools/perf/util/synthetic-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index 35de41ad14d3..19c1f3eaf58d 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1058,7 +1058,7 @@ int perf_event__synthesize_threads(const struct perf_tool *tool, else thread_nr = nr_threads_synthesize; - if (thread_nr <= 1) { + if (thread_nr <= 1 || n <= 1) { err = __perf_event__synthesize_threads(tool, process, machine, needs_mmap, mmap_data, -- 2.55.0.rc0.799.gd6f94ed593-goog