Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ
@ 2026-08-07  0:59 Xixin Liu
  2026-08-08  0:45 ` Paul Walmsley
  2026-08-11  3:51 ` [PATCH v2 0/1] " Xixin Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Xixin Liu @ 2026-08-07  0:59 UTC (permalink / raw)
  To: linux-riscv
  Cc: atish.patra, anup, will, mark.rutland, pjw, palmer, aou, alex,
	linux-arm-kernel, linux-perf-users, linux-kernel, liuxixin

The overflow IRQ handler dereferences cpu_hw_evt before the null check.
Move the check first. Defensive only; the cookie is valid on the normal
path today.

Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
 drivers/perf/riscv_pmu_sbi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index dfc886dee5ad..f0dd9d2645b4 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -1050,11 +1050,13 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)
 	u64 overflowed_ctrs = 0;
 	struct cpu_hw_events *cpu_hw_evt = dev;
 	u64 start_clock = sched_clock();
-	struct riscv_pmu_snapshot_data *sdata = cpu_hw_evt->snapshot_addr;
+	struct riscv_pmu_snapshot_data *sdata;
 
 	if (WARN_ON_ONCE(!cpu_hw_evt))
 		return IRQ_NONE;
 
+	sdata = cpu_hw_evt->snapshot_addr;
+
 	/* Firmware counter don't support overflow yet */
 	fidx = find_first_bit(cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS);
 	if (fidx == RISCV_MAX_COUNTERS) {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ
  2026-08-07  0:59 [PATCH] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ Xixin Liu
@ 2026-08-08  0:45 ` Paul Walmsley
  2026-08-11  3:51 ` [PATCH v2 0/1] " Xixin Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Walmsley @ 2026-08-08  0:45 UTC (permalink / raw)
  To: Xixin Liu
  Cc: linux-riscv, atish.patra, anup, will, mark.rutland, pjw, palmer,
	aou, alex, linux-arm-kernel, linux-perf-users, linux-kernel

Hi,

On Fri, 7 Aug 2026, Xixin Liu wrote:

> The overflow IRQ handler dereferences cpu_hw_evt before the null check.
> Move the check first. Defensive only; the cookie is valid on the normal
> path today.
> 
> Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>

Could you please add a Fixes: tag?  Also, if it was written with LLM 
assistance, please add the appropriate Assisted-by: tag.

thanks 


- Paul


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 0/1] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ
  2026-08-07  0:59 [PATCH] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ Xixin Liu
  2026-08-08  0:45 ` Paul Walmsley
@ 2026-08-11  3:51 ` Xixin Liu
  2026-08-11  3:51   ` [PATCH v2 1/1] " Xixin Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Xixin Liu @ 2026-08-11  3:51 UTC (permalink / raw)
  To: linux-riscv
  Cc: atish.patra, anup, will, mark.rutland, pjw, palmer, aou, alex,
	linux-arm-kernel, linux-perf-users, linux-kernel, liuxixin

Hi,

Thanks for the review, Paul.

v2 adds Fixes for the snapshot commit that introduced the early load,
and Assisted-by for DeepSeek v3 help. Code change is unchanged from v1.

Thanks,
Xixin Liu

---

Xixin Liu (1):
  perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ

 drivers/perf/riscv_pmu_sbi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/1] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ
  2026-08-11  3:51 ` [PATCH v2 0/1] " Xixin Liu
@ 2026-08-11  3:51   ` Xixin Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Xixin Liu @ 2026-08-11  3:51 UTC (permalink / raw)
  To: linux-riscv
  Cc: atish.patra, anup, will, mark.rutland, pjw, palmer, aou, alex,
	linux-arm-kernel, linux-perf-users, linux-kernel, liuxixin

The overflow IRQ handler dereferences cpu_hw_evt before the null check.
Move the check first. Defensive only; the cookie is valid on the normal
path today.

Fixes: a8625217a054 ("drivers/perf: riscv: Implement SBI PMU snapshot function")
Assisted-by: DeepSeek:deepseek-v3
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
 drivers/perf/riscv_pmu_sbi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index dfc886dee5ad..f0dd9d2645b4 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -1050,11 +1050,13 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)
 	u64 overflowed_ctrs = 0;
 	struct cpu_hw_events *cpu_hw_evt = dev;
 	u64 start_clock = sched_clock();
-	struct riscv_pmu_snapshot_data *sdata = cpu_hw_evt->snapshot_addr;
+	struct riscv_pmu_snapshot_data *sdata;
 
 	if (WARN_ON_ONCE(!cpu_hw_evt))
 		return IRQ_NONE;
 
+	sdata = cpu_hw_evt->snapshot_addr;
+
 	/* Firmware counter don't support overflow yet */
 	fidx = find_first_bit(cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS);
 	if (fidx == RISCV_MAX_COUNTERS) {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-11  6:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07  0:59 [PATCH] perf: RISC-V: check cpu_hw_evt before dereference in overflow IRQ Xixin Liu
2026-08-08  0:45 ` Paul Walmsley
2026-08-11  3:51 ` [PATCH v2 0/1] " Xixin Liu
2026-08-11  3:51   ` [PATCH v2 1/1] " Xixin Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox