From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 3E6C43AE706 for ; Sun, 9 Aug 2026 07:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786259734; cv=none; b=loReOLbSYLsAbOxmAeoPRLHucmPyF3tdpxJDbwj1+8xLF8qdPqQIhqE3OdAWHHgb5YMrHu+EhpUz9wkNAUMoruHoLCXYltX6IwAztg/jX3/RurhMIMye+k8ywSjDkfwNGdStPcXL819bsdvLkVJADY7pi9gt7KnNAmEa6VILUYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786259734; c=relaxed/simple; bh=WqXvWR2hCxFvOgd+6gdprd/n6snSgyVLotq2AlUBaqE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AikwgAcb3sGoWujY1N2KVr5B0dZJg8Tm/nVEPsXf3TLi9MZFl690tZHJ9ya9jPSP2xi+PlEV1+UdzcycpfefoDY2AFL4el7Bq3ANmUzQR6jxgx+hoV8fWsZMOt40dpSXGuGzBbXOVX+ZPaJrOhu36BmPXjvpetEtzy6j5XZGUYw= 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=PIO30/1F; arc=none smtp.client-ip=209.85.214.199 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="PIO30/1F" Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2cca5e0a0c9so20697785ad.1 for ; Sun, 09 Aug 2026 00:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786259731; x=1786864531; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fGltuG+0CYnELP248yw/EDAEAytweOI4Owg75trfZt0=; b=PIO30/1FKFlokpDXke58LSvXU6Dq5q99fBGf/V2F6X0TFOBnmBwYFMecEfpXMGVJu7 haBq3/3TqZHEcryQXpY0IikuAbIDhRzMqbJ1hRUSBKY5dFjQQmQIh2wEK696b2LMz1eQ qLoV7mEgJCSnZQpN8vL8smU0cHl8A14ydJCmbUqNpVMKBu/dSZ2nBtYpe/n4th5SNMln e+caEObgFsS6nB3Kza4hyXjdBCBXSlqHZJZ4E2rFZgejLOgXD5wIngpQMG18q0E5+kE7 fDEdLPU2WSevrdapKmDkKvcTltR7Qy39itZWfIzXbsXUDjgi2Cz96YI2LlPRCNkMQyFA EE+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786259731; x=1786864531; h=content-type: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:content-type; bh=fGltuG+0CYnELP248yw/EDAEAytweOI4Owg75trfZt0=; b=CG9EbyNfp1qvgDdoHXaNeKdV+dk+fQ3SXz47KUr2T545W33f8zzHzMTqyiz7789qow DX/zEmjX0QhBH+Kvdp/z7UxMcN1TOhHQ8bY4DIzTIMF6aClLofT6YWAP25c/hOsNsRAu Oo1aRsmToypxu9+9j5lPuvDXLXRbtmkFX9iU36RFDz7dju09Ads/BukXT5cOf91h1jSa N6D/yW7w7F+OKUrLteEAFohXn6QZ3HK8BJIo8/0BW+l2lvHZ+gF2EUCzbOocy9i8AN/b vdyTGsD/g9daLzJE/2rV00N5quqo7kW02JlE1S3quB+SHEMdslZPQ6OvFC2lTNgqgAg7 VMhg== X-Forwarded-Encrypted: i=1; AHgh+RojbrfkILI6ediZSnC2SAn6MfKF0E4+KVOT2j7EhbDEfjTMvIUdt0kbhwHIY6TkD8viq4rA91HzSUTjPoI=@vger.kernel.org X-Gm-Message-State: AOJu0YxluS92irCDEfgrodepblqBSc3MJe8Hn8q8H55IMsCrC6ifmQLH LjuX73Kfc3FPHaW76lPc3RBR7ajpuKKWUns/KTACwGNgs/fS9w9KEo7aDfGGU8U27o0m/JKR6e5 jD54BMrClvQ== X-Received: from dlbdm7.prod.google.com ([2002:a05:7022:6b87:b0:141:c12:d053]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:730e:b0:3c3:791e:5e0c with SMTP id adf61e73a8af0-3cbce8e5348mr13746989637.19.1786259731293; Sun, 09 Aug 2026 00:15:31 -0700 (PDT) Date: Sun, 9 Aug 2026 00:14:54 -0700 In-Reply-To: <20260809071455.1221514-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: <20260624051535.3584977-1-irogers@google.com> <20260809071455.1221514-1-irogers@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260809071455.1221514-16-irogers@google.com> Subject: [PATCH v3 15/15] 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. Fixes: 340b47f510bb ("perf top: Implement multithreading for perf_event__synthesize_threads") 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 3583a60cc487..0c150193cca8 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1175,7 +1175,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.679.g6767b8d81c-goog