From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (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 E49B31F3BA2 for ; Tue, 18 Aug 2026 00:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787013067; cv=none; b=OfXwM0Cgirvyb8plmq/XdQjPQLRp2SQ1kiaHrEFJvsHlOuyJ9ZP+3Cq8eSgbM7rPl91R7CX8aTxOXFvu0HszrpbQlBsZHgA0T4rnd3q/XlEPvLZKrPGsQmTlbJ3LDqosgaqTUNSkaxDKAaQlXxJqi1wlU4USCarwEueTg7pKL1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787013067; c=relaxed/simple; bh=Xvd1UL8Vgn5rYH7mFCDcMHXnFC3yh+9nr4WA6d6jVf0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tkaoUbhqMPvG2X5hyxPEGVjY5/y5nCdCOAxj7MN89QMvyot7P2ThKLNTG8YgzgZkZpXxl3YiCxkDf6SzAM+eFJOSUpPuwdMim5Gr1ezAhPAqHKS7pbvLcO/RRgenWtrN0wB5aB5ZqqlDM8Gucn7VQf1yTe5+HyHLiaiRm6THJTk= 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=BuC7h3g0; arc=none smtp.client-ip=209.85.215.197 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="BuC7h3g0" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cb7d6ba548eso5110524a12.1 for ; Mon, 17 Aug 2026 17:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787013065; x=1787617865; 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=eBkWEsGiIHckhP28r73Q4W8h3Fk9SPGkVFAPKyhiLAg=; b=BuC7h3g0iEjTdFx37EQ+qsaxca+sC7ZX2HLwsMk4pLwKaGex4lnoHZfSFojmpZsU5h 73hlqPrx3hlto4+msLmdD+U1d6vFWG0YnM02gcR5ZNBX1lQb/ZYNwItM3a8Y9D5wwPXp Nk5eD6U2qjZ3ukm20aBEfHhLjFh0D2FvmpcTo6VrS+TtFcbWiNRBcDJkZPwXhbob2fTC UHg8s5KSjwRq7MK8FG4dsj8mjCBMdIIvxxTMT2SZx1GEGUgJVjZ0LWvCaGS4tfoRfrtl BeLb+sSxfmQdLypPWfttinf4kfVQSeJFmZPXPb0Wliw4eE5+n6qU37+0AuEmMAdD4fGv 7fzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787013065; x=1787617865; 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=eBkWEsGiIHckhP28r73Q4W8h3Fk9SPGkVFAPKyhiLAg=; b=e+mxmehhwVb3x3O1MQ79iqb5lS+9ioBeSMlQD5DZHVoCrHF+fpVdfshexsjeNEMWEY RRRYpDecd5JB6V6zECE31wj4bBc4xW9wfuE0SEH1iGbfhMiu+YNM0UXohE0x+fBkTex6 ELTW8TyhLJ8o6aC5x9KGbMrncJu5qEV3R97BrgLAzxLvpHf12e8XsNy2F1kpwAx50owG wDmIXbKulW33c7uK9hvfX4/0H+lB6y1vqfs1FfYtia2Cw+tU3oYiEDtQ2KnlNDk7/D8S 8ZiVWLWy4DEf4O86yriz4mCUDwvJMRcOI9kCxOJ1CcjYOZGOARfJP4jZoTnZ2050O4vu 6Xzg== X-Forwarded-Encrypted: i=1; AHgh+RrnCnePP82LB9b5dF93QMK0TtMkMJnRdggMWBnjWTEdyQb4LkpZz6ANp2TFUjgUnRwYpsEARUiX4ITNgPw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2/Jrp7cFTSDo6HKMOvQH/U+OC5TYsK4XLdnsfp74LLgEceLFX EMQV4cjdAGI6aBpN/mnkwRyfmDBZMSixkN4YTaEX4UmEnzOBsPnVxJcvyHW3rbImQIDyFAAha1N rg6YAb7C1rw== X-Received: from dlec4-n2.prod.google.com ([2002:a05:701b:4284:20b0:141:5319:4d04]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3a48:b0:3c3:b57b:6291 with SMTP id adf61e73a8af0-3ccdac00616mr5132127637.18.1787013065039; Mon, 17 Aug 2026 17:31:05 -0700 (PDT) Date: Mon, 17 Aug 2026 17:31:01 -0700 In-Reply-To: <20260817230431.424646-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: <20260817230431.424646-1-irogers@google.com> X-Mailer: git-send-email 2.55.0.699.gb54405d56f-goog Message-ID: <20260818003101.520874-1-irogers@google.com> Subject: [PATCH v5] perf record: Fix unhandled POLLHUP on non_perf_event descriptors From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: abyssmystery@gmail.com, adrian.hunter@intel.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org Content-Type: text/plain; charset="UTF-8" When processing POLLHUP or POLLERR for an event in fdarray__filter, the function's prior iterations incorrectly mutated non_perf_event control descriptors by zeroing their events when a POLLHUP occurred. This caused premature termination due to index mismatches or hangs since the core evlist logic was prevented from safely finalizing the poll array setup via evlist__ctlfd_process(). Revert the logic in fdarray__filter to cleanly bypass all nonfilterable events as introduced by fb4751e79c45. Instead, fix the underlying logic within record__update_evlist_pollfd_from_thread() in builtin-record.c to sustainably reflect teardown statuses (-1) originating from evlist__finalize_ctlfd(). This correctly mirrors the finalized state to the thread's poll structure avoiding both invalid -EINVAL index crashes and POLLHUP spin loops. Included is a unit test to enforce that fdarray_flag__nonfilterable items are accurately completely circumvented during revents filtering loops. Fixes: fb4751e79c45 ("perf record: Fix teardown hang on system-wide multi-threaded sessions") Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 10 ++++++++++ tools/perf/tests/fdarray.c | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index a57987851cf0..d7c083803029 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1169,6 +1169,16 @@ static int record__update_evlist_pollfd_from_thread(struct record *rec, int e_pos = rec->index_map[i].evlist_pollfd_index; int t_pos = rec->index_map[i].thread_pollfd_index; + if (e_entries[e_pos].fd == -1 || e_entries[e_pos].events == 0) { + /* + * e_entries might have been finalized by evlist__finalize_ctlfd(). + * We must propagate it to t_entries to avoid index mismatches + * and to prevent a poll storm on the next iteration. + */ + t_entries[t_pos].fd = -1; + t_entries[t_pos].events = 0; + } + if (e_entries[e_pos].fd != t_entries[t_pos].fd || e_entries[e_pos].events != t_entries[t_pos].events) { pr_err("Thread and evlist pollfd index mismatch\n"); diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c index 40983c3574b1..2d3db7b754a1 100644 --- a/tools/perf/tests/fdarray.c +++ b/tools/perf/tests/fdarray.c @@ -80,6 +80,30 @@ static int test__fdarray__filter(struct test_suite *test __maybe_unused, int sub goto out_delete; } + fdarray__init_revents(fda, POLLHUP); + fda->priv[2].flags = fdarray_flag__nonfilterable; + + pr_debug("\nfiltering all but fda->entries[2] (nonfilterable):"); + fdarray__fprintf_prefix(fda, "before", stderr); + nr_fds = fdarray__filter(fda, POLLHUP, NULL, NULL); + fdarray__fprintf_prefix(fda, " after", stderr); + + if (nr_fds != 0) { + pr_debug("\nfdarray__filter()=%d != 0, should be 0\n", + nr_fds); + goto out_delete; + } + if (fda->entries[2].fd == -1) { + pr_debug("\nfdarray__filter() illegally modified nonfilterable fd!"); + goto out_delete; + } + if (fda->entries[2].revents != POLLHUP) { + pr_debug("\nfdarray__filter() illegally modified nonfilterable revents!"); + goto out_delete; + } + + fda->priv[2].flags = 0; /* reset flags */ + pr_debug("\n"); err = 0; -- 2.55.0.699.gb54405d56f-goog