coresight: cpu-debug: PC sampling via PMPCSR (FEAT_PCSRv8p2)?
Hi,
Cortex-A55 (Amlogic S905X3) reports EDDEVID.PCSample = 0, so coresight-cpu-debug cannot use it. The PC is available through PMPCSR in the external PMU frame (debug frame + 0x20000, PMDEVID.PCSample = 1). A lab module reading PMPCSR caught the PC of a CPU stuck on a PCIe bus access with IRQs off; on this GICv2 SoC the stop IPI never reaches it.
Two observations:
- A panic notifier samples too late: the other CPUs are stopped by then, and on this SoC reading the PMU frame of a stopped CPU raises a synchronous external abort. Sampling on entry to smp_send_stop() works.
- Marvell has an out-of-tree patch, "coresight: cpu-debug: Add support to dump PMPCSR" (2023, carried in linux-yocto); I could not find it on the lists.
Is PMPCSR support in coresight-cpu-debug planned or welcome? And how should such a PMU frame be described in DT: arm,coresight-cpu-debug or a new compatible?
Thanks,
Igor
Hi Igor
Quoted 17 lines · Igor Velkov
Hi,
Cortex-A55 (Amlogic S905X3) reports EDDEVID.PCSample = 0, so coresight-cpu-debug cannot use it. The PC is available through PMPCSR in the external PMU frame (debug frame +
0x20000, PMDEVID.PCSample = 1). A lab module reading PMPCSR caught the PC of a CPU stuck on a PCIe bus access with IRQs off; on this GICv2 SoC the stop IPI never reaches it.Two observations:
- A panic notifier samples too late: the other CPUs are stopped by then, and on this SoC reading the PMU frame of a stopped CPU raises a synchronous external abort. Sampling on entry tosmp_send_stop()works.
- Marvell has an out-of-tree patch, "coresight: cpu-debug: Add support to dump PMPCSR" (2023, carried in linux-yocto); I could not find it on the lists.
Quoted 1 line
Is PMPCSR support in coresight-cpu-debug planned or welcome? And how
Patches are definitely welcome, as such I don't know of anyone working on it from within Arm. So, please go ahead and post it.
Quoted 2 lines
should such a PMU frame be described in DT: arm,coresight-cpu-debug or a new compatible?
If the support can be detected using the "standard" cpu-debug frame, via the DEVID registers, I don't think we need a new compatible.
But we can debate on it with the patch review.
Cheers
Suzuki
Quoted 3 lines
Thanks,
Igor
Hi,
Quoted 8 lines · Igor Velkov
Hi,
Cortex-A55 (Amlogic S905X3) reports EDDEVID.PCSample = 0, so coresight-cpu-debug cannot use it. The PC is available through PMPCSR in the external PMU frame (debug frame +
0x20000, PMDEVID.PCSample = 1). A lab module reading PMPCSR caught the PC of a CPU stuck on a PCIe bus access with IRQs off; on this GICv2 SoC the stop IPI never reaches it.
Quoted 5 lines
Two observations:
- A panic notifier samples too late: the other CPUs are stopped by then, and on this SoC reading the PMU frame of a stopped CPU raises a synchronous external abort. Sampling on entry tosmp_send_stop()works.
Arm ARM, section I5.3.48 PMPCSR mentions "PMPCSR is in the Core power domain". The challenge is ensuring that the target core remains powered _throughout_ the access; checking its power state beforehand still leaves a race.
For example, with CPUidle enabled, a CPU can be powered off any time so it still race even move sampling in smp_send_stop().
This seems to be the main challenge. I'll check a bit if any guidance for safely accessing PMPCSR.
Quoted 7 lines
- Marvell has an out-of-tree patch, "coresight: cpu-debug: Add support to dump PMPCSR" (2023, carried in linux-yocto); I could not find it on the lists.
Is PMPCSR support in coresight-cpu-debug planned or welcome? And how should such a PMU frame be described in DT: arm,coresight-cpu-debug or a new compatible?
Would it make sense to describe external PMU frames in the PMU node and have cpu-debug reference its phandle? As Suzuki mentioned, this can be reviewed on patch.
Thanks,
Leo
Quoted 2 lines · Leo Yan
For example, with CPUidle enabled, a CPU can be powered off any time so it still race even move sampling in
smp_send_stop().
I tested this on S905X3 (Cortex-A55, PMPCSR) and RK3399 (Cortex-A53 + A72, EDPCSR, idle states with core powerdown).
Sampling only the CPUs still online after the stop request avoids the
race: a CPU that did not stop within the timeout did not take the stop IPI, so it is not in a powerdown state; it spins with IRQs off or is stuck on the bus. On RK3399 the CPUs found powered down in idle all stopped.
EDPRSR still has to be checked, and PU alone is not enough:
- A55 after CPU_OFF on the crash path: PU=0; reading PMPCSR aborts.
- A72 after CPU_OFF: PU=1, R=1 (the same in idle); reading EDPCSR aborts.
- S905X3: once every other core is off, even EDPRSR reads do not return. With a stuck core still on, reading it from the panic CPU worked on both SoCs, across clusters on RK3399.
The cpu-debug panic notifier reads every possible CPU after COREPURQ; on RK3399 on the crash path without pseudo-NMI it hit an SError on the first CPU that was off.
So I would send:
1. cpu-debug notifier: online CPUs other than the panic CPU, read only with PU=1, R=0 and DLK=0, no COREPURQ;
2. PMPCSR when EDDEVID.PCSample is 0 and PMDEVID.PCSample is not.
Panic notifiers run after the stop only with crash_kexec_post_notifiers; with a crash kernel loaded and without it, they do not run at all. Is that acceptable, or would you rather see a hook in the crash stop path?
Thanks,
Igor
Quoted 3 lines · Igor Velkov
The cpu-debug panic notifier reads every possible CPU after COREPURQ; on RK3399 on the crash path without pseudo-NMI it hit an SError on the first CPU that was off.
Seems the SoC does not honor COREPURQ. The current driver relies on an accessible debug interface; these platform limitations are already documented in [1].
Quoted 3 lines
So I would send:
1. cpu-debug notifier: online CPUs other than the panic CPU, read only with PU=1, R=0 and DLK=0, no COREPURQ;
Sampling only CPUs still online after the stop request may help, but the online mask does not guarantee register accessibility. A late stop acknowledgement can race with that check, and an offline CPU may still be running (or stuck) in firmware - the driver is also helpful for CPU stuck not in kernel.
We also need to consider FEAT_DoPD: EDPRCR and EDPRSR move from debug power domain into the Core power domain, and COREPURQ is absent. We then need another mechanism before accessing PCSR register.
I would check a bit if any suggestions for safely access registers. Otherwise, we may need to explore kernel states as you suggested (not only cpu online but also idle states).
Quoted 1 line
2. PMPCSR when EDDEVID.PCSample is 0 and PMDEVID.PCSample is not.
This is fine for me.
Quoted 3 lines
Panic notifiers run after the stop only with
crash_kexec_post_notifiers; with a crash kernel loaded and without it, they do not run at all. Is that acceptable, or would you rather see a hook in the crash stop path?
I agree that the notifier need improvement.
Could we explore a hook in the CPU hard lockup detector? Seems this module is more relevant to hard lockup rather than panic.
Thanks,
Leo
[1] Documentation/trace/coresight/coresight-cpu-debug.rst
Quoted 2 lines · Leo Yan
Could we explore a hook in the CPU hard lockup detector? Seems this module is more relevant to hard lockup rather than panic.
Yes, that fits better. The hard lockup detector reports a CPU that missed its watchdog hrtimer interrupts, so it runs with IRQs masked and is not in an idle powerdown. The backtrace request then names the CPUs that did not answer ("these CPUS still haven't responded"). I would sample PCSR only for those, from a hook at that point, and leave the panic notifier alone. Does that sound right?
Thanks,
Igor
Quoted 10 lines · Igor Velkov
Quoted 2 lines · Leo Yan
Could we explore a hook in the CPU hard lockup detector? Seems this module is more relevant to hard lockup rather than panic.
Yes, that fits better. The hard lockup detector reports a CPU that missed its watchdog hrtimer interrupts, so it runs with IRQs masked and is not in an idle powerdown. The backtrace request then names the CPUs that did not answer ("these CPUS still haven't responded"). I would sample PCSR only for those, from a hook at that point, and leave the panic notifier alone. Does that sound right?
Yes, sampling CPUs that do not respond to the backtrace request sounds reasonable.
The hard lockup detector can also call panic(), so we should avoid a second dump from the panic notifier. After hook with hard-lockup diagnosis, then makes sense to remove that panic notifier.
For CPU power state, could we take a cautious approach in the driver?
1) If idle_cpu(cpu) == 0, sample the CPU directly.
2) If idle_cpu(cpu) == 1, follow the existing flow to request power-up before sampling.
3) Consider adding a module parameter, such as skip_idle, for hardware that doesn't support or honour EDPRCR_COREPURQ. This would allow the driver to sample only active CPUs.
Thanks,
Leo
Quoted 3 lines · Leo Yan
1) If
idle_cpu(cpu)== 0, sample the CPU directly.
2) Ifidle_cpu(cpu)== 1, follow the existing flow to request power-up before sampling.
I tried step 2 on RK3399 (Cortex-A53 + A72, cpuidle with core powerdown), following debug_read_regs() on a running system:
- Idle A53 (EDPRSR.PU = 0): the EDOSLAR write raises an SError on the reading CPU. COREPURQ brings the core up only for a moment; with COREPURQ | CORENPDRQ it is off again within 10 ms, and the write still faults.
- Idle A72 (PU = 1, R = 1): the same SError on the EDOSLAR write.
- Busy CPUs (idle_cpu() == 0) on both clusters: no errors, full PC.
So on this SoC only step 1 is safe.
Thanks,
Igor
Quoted 8 lines · Igor Velkov
Quoted 3 lines · Leo Yan
1) If
idle_cpu(cpu)== 0, sample the CPU directly.
2) Ifidle_cpu(cpu)== 1, follow the existing flow to request power-up before sampling.I tried step 2 on RK3399 (Cortex-A53 + A72, cpuidle with core powerdown), following
debug_read_regs()on a running system:
Quoted 8 lines
- Idle A53 (EDPRSR.PU = 0): the EDOSLAR write raises an SError on the reading CPU. COREPURQ brings the core up only for a moment; with COREPURQ | CORENPDRQ it is off again within 10 ms, and the write still faults.
- Idle A72 (PU = 1, R = 1): the same SError on the EDOSLAR write.
- Busy CPUs (idle_cpu()== 0) on both clusters: no errors, full PC.So on this SoC only step 1 is safe.
This is why I suggested 3) in my previous reply. Seems you should skip sample idle CPUs if COREPURQ/CORENPDRQ are not properly integrated in the SoC.
Thanks,
Leo