public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Thomas Richter <tmricht@linux.ibm.com>,
	Jan Polensky <japo@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Sasha Levin <sashal@kernel.org>,
	agordeev@linux.ibm.com, liubo03@inspur.com, peterz@infradead.org,
	kan.liang@linux.intel.com
Subject: [PATCH AUTOSEL 6.19-5.10] s390/perf: Disable register readout on sampling events
Date: Wed, 11 Feb 2026 07:30:11 -0500	[thread overview]
Message-ID: <20260211123112.1330287-1-sashal@kernel.org> (raw)

From: Thomas Richter <tmricht@linux.ibm.com>

[ Upstream commit b2c04fc1239062b39ddfdd8731ee1a10810dfb74 ]

Running commands
 # ./perf record  -IR0,R1 -a sleep 1
extracts and displays register value of general purpose register r1 and r0.
However the value displayed of any register is random and does not
reflect the register value recorded at the time of the sample interrupt.

The sampling device driver on s390 creates a very large buffer
for the hardware to store the samples. Only when that large buffer
gets full an interrupt is generated and many hundreds of sample
entries are processed and copied to the kernel ring buffer and
eventually get copied to the perf tool. It is during the copy
to the kernel ring buffer that each sample is processed (on s390)
and at that time the register values are extracted.
This is not the original goal, the register values should be read
when the samples are created not when the samples are copied to the
kernel ring buffer.

Prevent this event from being installed in the first place and
return -EOPNOTSUPP. This is already the case for PERF_SAMPLE_REGS_USER.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Detailed Analysis

### 1. Commit Message Analysis

The commit message is clear and detailed. It describes a concrete,
reproducible problem: running `perf record -IR0,R1 -a sleep 1` on s390
produces **random, meaningless register values** that do not reflect the
actual register state at the time of sampling. The root cause is well-
explained — the s390 hardware sampling facility buffers hundreds of
samples, and registers are only read during batch processing (when the
buffer fills), not when each sample is actually taken.

The commit was authored by **Thomas Richter** (the s390 perf/cpumf
maintainer), reviewed by **Jan Polensky**, and signed off by **Heiko
Carstens** (s390 subsystem maintainer). This is authoritative review
from the exact right people.

### 2. Code Change Analysis

The change is a **single line modification** in `is_callchain_event()`:

```839:845:arch/s390/kernel/perf_cpum_sf.c
static bool is_callchain_event(struct perf_event *event)
{
        u64 sample_type = event->attr.sample_type;

        return sample_type & (PERF_SAMPLE_CALLCHAIN |
PERF_SAMPLE_REGS_USER |
                              PERF_SAMPLE_STACK_USER);
}
```

The fix adds `PERF_SAMPLE_REGS_INTR` to the bitmask, so the function
also detects interrupt-time register requests. The caller
`cpumsf_pmu_event_init()` returns `-EOPNOTSUPP` when
`is_callchain_event()` returns true:

```851:854:arch/s390/kernel/perf_cpum_sf.c
        /* No support for taken branch sampling */
        /* No support for callchain, stacks and registers */
        if (has_branch_stack(event) || is_callchain_event(event))
                return -EOPNOTSUPP;
```

### 3. Historical Context

- **`PERF_SAMPLE_REGS_INTR`** was introduced in kernel 3.19 (commit
  `60e2364e60e86`, September 2014).
- **`is_callchain_event()`** was introduced in kernel 5.9 (commit
  `5aa98879efe77`, June 2020). That commit already blocked
  `PERF_SAMPLE_REGS_USER` and `PERF_SAMPLE_STACK_USER` for the exact
  same reason: register/stack values collected at interrupt-processing
  time don't match the actual sample context. But it missed
  `PERF_SAMPLE_REGS_INTR`.
- The bug has existed since 2020, affecting all kernels from 5.9 onward.

### 4. Bug Mechanism

Looking at `arch/s390/kernel/perf_regs.c`, the `perf_reg_value()`
function reads from `regs->gprs[idx]` — the current pt_regs. For regular
PMU interrupts, these registers correspond to the interrupted context.
But for s390's hardware sampling PMU (cpum_sf), the "interrupt" fires
when a large hardware buffer fills up, and hundreds of samples are
processed in batch. By that time, the pt_regs reflect the interrupt-
handler context, **not** the context when each individual sample was
taken. The result is that users see random register values that are
misleading.

### 5. Applicability to Stable Trees

I verified that the affected `is_callchain_event()` function exists
**identically** (without `PERF_SAMPLE_REGS_INTR`) in all active stable
trees:
- **6.18.y**: Bug present, same code
- **6.12.y**: Bug present, same code
- **6.6.y**: Bug present, same code
- **6.1.y**: Bug present, same code
- **5.15.y**: Bug present, same code
- **5.10.y**: Bug present, same code

`PERF_SAMPLE_REGS_INTR` is available in all these trees (added in 3.19).
The patch will apply cleanly with trivial line-offset fuzz.

### 6. Risk Assessment

- **Risk**: Essentially zero. The change adds one flag to an existing
  bitmask check that already blocks three other sample types for the
  same reason.
- **Worst case**: Users who previously requested `-I` (interrupt
  registers) with s390 hardware sampling now get `-EOPNOTSUPP` instead
  of silently receiving garbage data. This is strictly an improvement.
- **No dependencies**: The patch is completely self-contained.
- **No new features**: This restricts behavior, preventing a broken code
  path from being used.

### 7. Classification

This is a **data correctness bug fix**. While it doesn't cause a crash
or security vulnerability, it produces **silently incorrect output**
that could lead users to make wrong conclusions during performance
analysis. The commit message from the original 2020 fix
(`5aa98879efe77`) even calls out that "invalid data is picked, because
the context of the collected information does not match the context when
the sample was taken" — the exact same bug, just for a different sample
type that was overlooked.

### 8. Conclusion

This commit meets all stable kernel criteria:
- **Obviously correct**: One flag added to existing bitmask, same
  pattern as existing blocked types
- **Fixes a real bug**: Silently returns random/meaningless register
  values to users
- **Small and contained**: 1 file, 1 line, 1 flag addition
- **No new features**: Restricts an existing broken capability
- **Applies cleanly**: Identical code in all stable trees
- **Properly reviewed**: By s390 maintainers
- **Zero regression risk**: Only changes behavior from "return garbage"
  to "return EOPNOTSUPP"

**YES**

 arch/s390/kernel/perf_cpum_sf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c
index 459af23a47a5e..e8bd19ac82c7d 100644
--- a/arch/s390/kernel/perf_cpum_sf.c
+++ b/arch/s390/kernel/perf_cpum_sf.c
@@ -841,7 +841,7 @@ static bool is_callchain_event(struct perf_event *event)
 	u64 sample_type = event->attr.sample_type;
 
 	return sample_type & (PERF_SAMPLE_CALLCHAIN | PERF_SAMPLE_REGS_USER |
-			      PERF_SAMPLE_STACK_USER);
+			      PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_STACK_USER);
 }
 
 static int cpumsf_pmu_event_init(struct perf_event *event)
-- 
2.51.0


             reply	other threads:[~2026-02-11 12:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-11 12:30 Sasha Levin [this message]
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] arm64: Add support for TSV110 Spectre-BHB mitigation Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] xenbus: Use .freeze/.thaw to handle xenbus devices Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] s390/purgatory: Add -Wno-default-const-init-unsafe to KBUILD_CFLAGS Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] s390/boot: " Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.1] perf/arm-cmn: Support CMN-600AE Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] ntfs: ->d_compare() must not block Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] ACPI: x86: s2idle: Invoke Microsoft _DSM Function 9 (Turn On Display) Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] block: decouple secure erase size limit from discard size limit Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] sparc: don't reference obsolete termio struct for TC* constants Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] EFI/CPER: don't go past the ARM processor CPER record buffer Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19] ACPI: scan: Use async schedule function in acpi_scan_clear_dep_fn() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.6] cpufreq: dt-platdev: Block the driver from probing on more QC platforms Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] EFI/CPER: don't dump the entire memory region Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] ACPI: battery: fix incorrect charging status when current is zero Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] rust: cpufreq: always inline functions using build_assert with arguments Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] blk-mq-sched: unify elevators checking for async requests Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] x86/xen/pvh: Enable PAE mode for 32-bit guest only when CONFIG_X86_PAE is set Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] APEI/GHES: ARM processor Error: don't go past allocated memory Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] md raid: fix hang when stopping arrays with metadata through dm-raid Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] tools/power cpupower: Reset errno before strtoull() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] sparc: Synchronize user stack on fork and clone Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] blk-mq-debugfs: add missing debugfs_mutex in blk_mq_debugfs_register_hctxs() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] rnbd-srv: Zero the rsp buffer before using it Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] alpha: fix user-space corruption during memory compaction Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] ACPICA: Abort AML bytecode execution when executing AML_FATAL_OP Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19] arm64: mte: Set TCMA1 whenever MTE is present in the kernel Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] tools/cpupower: Fix inverted APERF capability check Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.15] ACPI: processor: Fix NULL-pointer dereference in acpi_processor_errata_piix4() Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] ACPI: resource: Add JWIPC JVC9100 to irq1_level_low_skip_override[] Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.6] perf/cxlpmu: Replace IRQF_ONESHOT with IRQF_NO_THREAD Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.6] md-cluster: fix NULL pointer dereference in process_metadata_update Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-5.10] APEI/GHES: ensure that won't go past CPER allocated record Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.12] powercap: intel_rapl: Add PL4 support for Ice Lake Sasha Levin
2026-02-11 12:30 ` [PATCH AUTOSEL 6.19-6.18] io_uring/timeout: annotate data race in io_flush_timeouts() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260211123112.1330287-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=japo@linux.ibm.com \
    --cc=kan.liang@linux.intel.com \
    --cc=liubo03@inspur.com \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tmricht@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox