Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v14 02/10] riscv: add support for SBI Supervisor Software Events extension
Date: Wed, 02 Dec 2026 07:21:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-245057@kernel.org> (raw)
In-Reply-To: <20261202070003.42491-14-zhangzhanpeng.jasper@bytedance.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] riscv: sbi_sse: field-spanning memcpy() on regs->a6 in do_sse()
--

commit cbcd8754d3b4e96f78b91cc198faaeb7455da29b
Author: Clément Léger <cleger@rivosinc.com>

riscv: add support for SBI Supervisor Software Events extension

This commit adds architectural support for the RISC-V SBI Supervisor
Software Events (SSE) extension, including dedicated per-event stacks,
low-level entry and exit assembly, and event lifecycle helpers.

Link: https://lore.kernel.org/r/as79MHtNYd-VbUug@hu-himchau-blr.qualcomm.com/
Link: https://lore.kernel.org/r/69a099c3-082e-43b8-82f5-122d32df5eff@linux.dev/
Link: https://sashiko.dev/#/patchset/20261119120824.13969-13-zhangzhanpeng.jasper%40bytedance.com?part=2

> diff --git a/arch/riscv/kernel/sbi_sse.c b/arch/riscv/kernel/sbi_sse.c
> new file mode 100644
> index 0000000000000..59e47a39589d0
> --- /dev/null
> +++ b/arch/riscv/kernel/sbi_sse.c
> @@ -0,0 +1,252 @@

[ ... ]

> +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;
> +	irqentry_state_t state;
> +	struct sbiret sret;
> +
> +	state = irqentry_nmi_enter(regs);
> +	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);
> +	if (sret.error) {
> +		pr_warn("Failed to read interrupted registers for event %x: %ld\n",
> +			arch_evt->evt_id, sret.error);
> +		/* Let the client quiesce its source without using incomplete regs. */
> +		sse_handle_event(arch_evt, NULL);
> +		goto out;
> +	}
> +
> +	memcpy(&regs->a6, arch_evt->interrupted,
> +	       sizeof(*arch_evt->interrupted));
> +
> +	/* Make the interrupted frame visible while clients handle this event. */
> +	previous = this_cpu_read(riscv_sse_interrupted_context);
> +	this_cpu_write(riscv_sse_interrupted_context, &context);
> +	sse_handle_event(arch_evt, regs);
> +	this_cpu_write(riscv_sse_interrupted_context, previous);
> +
> +	if (memcmp(&regs->a6, arch_evt->interrupted,
> +		   sizeof(*arch_evt->interrupted))) {
> +		memcpy(arch_evt->interrupted, &regs->a6,
> +		       sizeof(*arch_evt->interrupted));

[Severity: High]
Does copying sizeof(*arch_evt->interrupted) bytes to and from &regs->a6
trip CONFIG_FORTIFY_SOURCE?

In struct pt_regs, a6 and a7 are separate unsigned long fields, so the
member size of &regs->a6 is sizeof(unsigned long) while
sizeof(*arch_evt->interrupted) is 2 * sizeof(unsigned long).  With
CONFIG_FORTIFY_SOURCE=y, fortify_memcpy_chk() flags this at compile time
with __write_overflow_field() (and __read_overflow2_field() under W=1),
breaking builds with CONFIG_WERROR=y, and triggers a fortify WARN_ONCE()
at runtime inside the NMI-like SSE handler.  Assigning and comparing
regs->a6 and regs->a7 directly avoids the field-spanning memcpy() and
memcmp() calls.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202070003.42491-12-zhangzhanpeng.jasper@bytedance.com?part=2

  reply	other threads:[~2026-12-02  7:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:00 [PATCH v14 00/10] riscv: add SBI Supervisor Software Events support Zhanpeng Zhang
2026-12-02  7:00 ` [PATCH v14 01/10] riscv: add SBI SSE extension definitions Zhanpeng Zhang
2026-12-02  7:00 ` [PATCH v14 02/10] riscv: add support for SBI Supervisor Software Events extension Zhanpeng Zhang
2026-12-02  7:21   ` sashiko-bot [this message]
2026-12-02  7:00 ` [PATCH v14 03/10] riscv: sse: mask events during shutdown and kexec Zhanpeng Zhang
2026-12-02  7:29   ` sashiko-bot
2026-12-02  7:00 ` [PATCH v14 04/10] drivers: firmware: add riscv SSE support Zhanpeng Zhang
2026-12-02  7:25   ` sashiko-bot
2026-12-02  7:00 ` [PATCH v14 05/10] riscv: mm: avoid enabling interrupts for nofault page faults Zhanpeng Zhang
2026-12-02  7:00 ` [PATCH v14 06/10] perf: RISC-V: support callchains with SSE delivery Zhanpeng Zhang
2026-12-02  7:00 ` [PATCH v14 07/10] perf: RISC-V: add support for SSE event Zhanpeng Zhang
2026-12-02  7:33   ` sashiko-bot
2026-12-02  7:00 ` [PATCH v14 08/10] MAINTAINERS: add RISC-V SSE maintainers and file coverage Zhanpeng Zhang
2026-12-02  7:00 ` [PATCH v14 09/10] selftests/riscv: add SSE test module Zhanpeng Zhang
2026-12-02  7:26   ` sashiko-bot
2026-12-02  7:00 ` [PATCH v14 10/10] selftests/riscv: add perf user-stack SSE copy regression test Zhanpeng Zhang
2026-12-02  7:24   ` 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=sashiko-outbox-245057@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