From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796196118; b=wIWZkwY2Ja7KNcFkN8bNRddKNBCmi6TgEohngCKbsOEoERq9jaYv4WsB7jGsgCNHKMzc KurDVmHd6LqXwE4t1u76uWlub7JgE2fC979Lq4PJKhpj/3sfupg5XSrE+Q/Ke5X+z04mO foEgUDdzlo2VIkk4Zr8jZRke9hwT0wSaLoJKWIOEPMPbrkeAHb1zFpPeybDahoCRcVGOW 10ra+y3phlRfUfAQO9E7y1iygnPzsIsDqvG93dDk0C5RkvPTR36IkhptYFy6E1vHtXpRJ vPfBlcp/WfPB9Sglyx147vclRve5r8upyoUQSVvZ2DqJyhatnqqp5NHCFYzFT97/A/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196118; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=21bx26yWs66NU2id26w2nwdU9CTdw3AU8Aimdiviw0c=; b=1hmnEslD7D7XawRmRDfzWnJ505YW1DCoiW5KtLLuglvUggVLcXGYTndqxJF2H5dETtyk M3xMrBEG9gkvS55eW+F/mJv8AfWX+6gzhHzKYF7yFr8EBXza8P/AFGMeKReeRsv8fnVvv vf7daSNvwyPEG6fQzn+Qaa7/eMRn9/3bXcNuy4Xq6mTxj4Kn4DhgVLWn3TCdVXOZz3x0X Rm6LlJXoOmarysWg0IN7H0bg3v2QbG25RJQVwI4WB4txah4O8rwS/1Onw7sPaCQGEJwRB 27lLdhvrt9qFJQTutRx01Q60ihafzK0LsSWCMqJI/+54Unm53w94n809goR1ABPut2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hD2jPgf+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A80C5606A329 for ; Wed, 2 Dec 2026 07:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hD2jPgf+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2131C1F00896; Wed, 2 Dec 2026 07:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796196118; bh=21bx26yWs66NU2id26w2nwdU9CTdw3AU8Aimdiviw0c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hD2jPgf+a1wBQBMA0ghY0o9i4H9S+/5CGFAARlDMnflbm6yz/R4h4bzBH4Xa2KJ0/ zOhzFKLZLeP5OFj6vLL7GExcylQBYJG/MAG4oIyPVhVawzB3I/2KDeBiZtAHDxW9bq UFt1jWBAHTMZZpSEVt1jjFPLvN7fGZT6wiIyf9obCpMON/2eR6eVvdCdHz5aXJqdIR 46D1uWc4K2ltAXtnJW1OdZRxDFWMlpdn5xP01O9iRu8XxKIHHtnVku/QAMnI206qQw WDSyvAh9DaOkh14cRP8HfSH/Jeo5xvPdXxh9sXCnOwoFq2FVRH65b1VITLSzMAv6fh LqOJ5nF1DzWew== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 02/10] riscv: add support for SBI Supervisor Software Events extension Reply-To: sashiko-reviews@lists.linux.dev To: "Zhanpeng Zhang" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261202070003.42491-14-zhangzhanpeng.jasper@bytedance.com> References: <20261202070003.42491-12-zhangzhanpeng.jasper@bytedance.com> <20261202070003.42491-14-zhangzhanpeng.jasper@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 07:21:57 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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=C3=A9ment L=C3=A9ger 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.co= m/ 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=3D2 > 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 =3D { regs, hstatus }; > + struct riscv_sse_interrupted_context *previous; > + irqentry_state_t state; > + struct sbiret sret; > + > + state =3D irqentry_nmi_enter(regs); > + instrumentation_begin(); > + > + /* Retrieve missing GPRs from SBI */ > + sret =3D 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(®s->a6, arch_evt->interrupted, > + sizeof(*arch_evt->interrupted)); > + > + /* Make the interrupted frame visible while clients handle this event. = */ > + previous =3D 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(®s->a6, arch_evt->interrupted, > + sizeof(*arch_evt->interrupted))) { > + memcpy(arch_evt->interrupted, ®s->a6, > + sizeof(*arch_evt->interrupted)); [Severity: High] Does copying sizeof(*arch_evt->interrupted) bytes to and from ®s->a6 trip CONFIG_FORTIFY_SOURCE? In struct pt_regs, a6 and a7 are separate unsigned long fields, so the member size of ®s->a6 is sizeof(unsigned long) while sizeof(*arch_evt->interrupted) is 2 * sizeof(unsigned long). With CONFIG_FORTIFY_SOURCE=3Dy, fortify_memcpy_chk() flags this at compile time with __write_overflow_field() (and __read_overflow2_field() under W=3D1), breaking builds with CONFIG_WERROR=3Dy, 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202070003.4249= 1-12-zhangzhanpeng.jasper@bytedance.com?part=3D2