From: sashiko-bot@kernel.org
To: "Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v10 2/9] riscv: add support for SBI Supervisor Software Events extension
Date: Fri, 11 Sep 2026 12:34:47 +0000 [thread overview]
Message-ID: <20260911123448.12E501F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260911121456.33223-3-zhangzhanpeng.jasper@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Physical address truncation on RV32 with 64-bit physical addresses during SBI_SSE_EVENT_ATTR_READ/WRITE.
--
commit 009ca408c0e515d2b163c5c6737a07a0e84156e8
Author: Clément Léger <cleger@rivosinc.com>
riscv: add support for SBI Supervisor Software Events extension
This commit adds support for the SBI Supervisor Software Events (SSE)
extension, allowing firmware to notify supervisor software of independent
events. It provisions per-event stacks, saves and restores interrupted
contexts, and handles nested exceptions safely.
> diff --git a/arch/riscv/kernel/sbi_sse.c b/arch/riscv/kernel/sbi_sse.c
> new file mode 100644
> --- /dev/null
> +++ b/arch/riscv/kernel/sbi_sse.c
[ ... ]
> +void noinstr do_sse(struct sse_event_arch_data *arch_evt,
> + struct pt_regs *regs, unsigned long hstatus)
> +{
> + struct riscv_sse_interrupted_context context = { regs, hstatus };
> + struct riscv_sse_interrupted_context *previous;
> + struct sbiret sret;
> +
> + nmi_enter();
> + instrumentation_begin();
> +
> + /* Retrieve missing GPRs from SBI */
> + sret = sbi_ecall(SBI_EXT_SSE, SBI_SSE_EVENT_ATTR_READ, arch_evt->evt_id,
> + SBI_SSE_ATTR_INTERRUPTED_A6,
> + (SBI_SSE_ATTR_INTERRUPTED_A7 -
> + SBI_SSE_ATTR_INTERRUPTED_A6) + 1,
> + (unsigned long)arch_evt->interrupted_phys, 0, 0);
[Severity: High]
Does casting arch_evt->interrupted_phys to unsigned long truncate the
physical address on RV32 systems?
When CONFIG_PHYS_ADDR_T_64BIT is enabled on RV32, virt_to_phys() returns a
64-bit physical address. By casting to unsigned long for the phys_lo
argument and hardcoding 0 for the phys_hi argument, if the physical memory
resides above the 4GB boundary, the firmware receives a truncated 32-bit
address. Could this result in the firmware reading from unintended memory?
> + if (sret.error) {
> + pr_warn("Failed to read interrupted registers for event %x: %ld\n",
> + arch_evt->evt_id, sret.error);
[ ... ]
> + if (memcmp(®s->a6, arch_evt->interrupted,
> + sizeof(*arch_evt->interrupted))) {
> + memcpy(arch_evt->interrupted, ®s->a6,
> + sizeof(*arch_evt->interrupted));
> + sret = sbi_ecall(SBI_EXT_SSE, SBI_SSE_EVENT_ATTR_WRITE,
> + arch_evt->evt_id, SBI_SSE_ATTR_INTERRUPTED_A6,
> + (SBI_SSE_ATTR_INTERRUPTED_A7 -
> + SBI_SSE_ATTR_INTERRUPTED_A6) + 1,
> + (unsigned long)arch_evt->interrupted_phys, 0, 0);
[Severity: High]
Similarly, could this truncation cause memory corruption here?
If the firmware writes back the state using a truncated 32-bit physical
address, it may corrupt unintended memory regions if the original address
was above 4GB.
> + /*
> + * If writeback fails, COMPLETE resumes with firmware's original
> + * a6/a7 rather than treating the shared buffer as committed.
> + */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260911121456.33223-1-zhangzhanpeng.jasper@bytedance.com?part=2
next prev parent reply other threads:[~2026-09-11 12:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 12:14 [PATCH v10 0/9] riscv: add SBI Supervisor Software Events support Zhanpeng Zhang
2026-09-11 12:14 ` [PATCH v10 1/9] riscv: add SBI SSE extension definitions Zhanpeng Zhang
2026-09-11 12:20 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 2/9] riscv: add support for SBI Supervisor Software Events extension Zhanpeng Zhang
2026-09-11 12:34 ` sashiko-bot [this message]
2026-09-11 12:14 ` [PATCH v10 3/9] riscv: sse: mask events during shutdown and kexec Zhanpeng Zhang
2026-09-11 12:30 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 4/9] drivers: firmware: add riscv SSE support Zhanpeng Zhang
2026-09-11 12:35 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 5/9] riscv: mm: avoid enabling interrupts for nofault page faults Zhanpeng Zhang
2026-09-11 12:28 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 6/9] perf: RISC-V: support callchains with SSE delivery Zhanpeng Zhang
2026-09-11 12:35 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 7/9] perf: RISC-V: add support for SSE event Zhanpeng Zhang
2026-09-11 12:37 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 8/9] selftests/riscv: add SSE test module Zhanpeng Zhang
2026-09-11 12:40 ` sashiko-bot
2026-09-11 12:14 ` [PATCH v10 9/9] selftests/riscv: add perf user-stack SSE copy regression test Zhanpeng Zhang
2026-09-11 12:33 ` sashiko-bot
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=20260911123448.12E501F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhangzhanpeng.jasper@bytedance.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;
as well as URLs for NNTP newsgroup(s).