From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53D9F1E5B9F; Sat, 12 Sep 2026 07:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789199651; cv=none; b=LLkmm9AwXPH5ZCT3TvyoH2aojGZJ9Uk8g+RVYUwuGj0T1ILiFgiSS5brwQkiPqpIYdk7Q1e8n0y8BLBZ2WJkTgDEt7d83llRd1pEvlURtzql9p5j2Xd0Uzl4/oxu2DSHXAJ3rZIJC/yqDkuHf+9JJAhSk97zaFDU/1wtrhi4q1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789199651; c=relaxed/simple; bh=K9eaFrHq0sW+Ft/YFiCsnJkW4MvTTQiJQ2Sk37blQXs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k5vilI/5uYE1wZoUmZ0rfONxSJuUKrKFQE6AFT4lya1dWdAh0cmOAMKQ+NmDZjoGMBvLbpCcBFwIkoKI8fAgtN+ICj5e4lCWcF2ol8IcGJZCR3F8sY2LO5FL3M1Zoy10nTc70J7IDWDpYGn/fTJy+7wtF8G/JkNXvIbOGv0+oYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DW2WbEeX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DW2WbEeX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C8211F000FF; Sat, 12 Sep 2026 07:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789199650; bh=8FAvVKYOSf2K+AoVdmVP+jrOhgg0USeZt8m5DfbcgUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DW2WbEeXh+4IVQNKxo+1UPVZUVfrbwpbONzZPeGegyvUBlYeEBpbr1ich01Yebc+t RXtIz7dGqt6Ir7Z0oRuL9/C//zNtXZh0c1yiQ9hgiobFvsY3mbD2wg+JlNY8Y2bhBZ 1e+hZ89SBxFwLiTyRspPpsccj7cby+rtoR5bscTE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, James Clark , Leo Yan , Namhyung Kim , Sasha Levin Subject: [PATCH 7.2 0627/1815] perf cs-etm: Flush thread stacks after decoder reset Date: Sat, 12 Sep 2026 08:39:37 +0200 Message-ID: <20260912065703.598174078@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leo Yan [ Upstream commit ea5075e3776846d4941dddf1549426ebd3feb81f ] Perf resets the CoreSight decoder when moving to a new AUX trace buffer, this causes trace discontinunity globally. For callchain synthesis, keeping thread-stack state after decoder reset can leave stale call/return history attached to threads that are decoded later, producing incorrect synthesized callchains. Flush all host thread stacks after a decoder reset. When virtualization is present, flush the guest thread stacks as well. Reviewed-by: James Clark Signed-off-by: Leo Yan Signed-off-by: Namhyung Kim Stable-dep-of: ec99be8a31db ("perf cs-etm: Avoid truncating AUX buffer sizes to int") Signed-off-by: Sasha Levin --- tools/perf/util/cs-etm.c | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 95530e10e010c..54b82cf6442a7 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2089,6 +2089,45 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq, return 0; } + +static int cs_etm__flush_stack_cb(struct thread *thread, + void *data __maybe_unused) +{ + thread_stack__flush(thread); + return 0; +} + +static void cs_etm__flush_machine_stack(struct cs_etm_queue *etmq, pid_t pid) +{ + struct machine *machine; + + machine = machines__find(&etmq->etm->session->machines, pid); + if (machine) + machine__for_each_thread(machine, cs_etm__flush_stack_cb, NULL); +} + +static void cs_etm__flush_all_stack(struct cs_etm_queue *etmq) +{ + enum cs_etm_pid_fmt pid_fmt = cs_etm__get_pid_fmt(etmq); + + if (!etmq->etm->synth_opts.last_branch) + return; + + switch (pid_fmt) { + case CS_ETM_PIDFMT_CTXTID2: + /* Clear the guest stack if virtualization is supported */ + cs_etm__flush_machine_stack(etmq, DEFAULT_GUEST_KERNEL_ID); + fallthrough; + case CS_ETM_PIDFMT_CTXTID: + cs_etm__flush_machine_stack(etmq, HOST_KERNEL_ID); + break; + case CS_ETM_PIDFMT_NONE: + default: + break; + + } +} + /* * cs_etm__get_data_block: Fetch a block from the auxtrace_buffer queue * if need be. @@ -2111,6 +2150,12 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) ret = cs_etm_decoder__reset(etmq->decoder); if (ret) return ret; + + /* + * Since the decoder is reset, this causes a global trace + * discontinuity. Flush all thread stacks. + */ + cs_etm__flush_all_stack(etmq); } return etmq->buf_len; -- 2.53.0