From: sashiko-bot@kernel.org
To: "Charlie Jenkins" <thecharlesjenkins@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 16/17] riscv: kexec: Use generated instruction headers for kexec relocations
Date: Wed, 08 Jul 2026 04:01:03 +0000 [thread overview]
Message-ID: <20260708040104.97AE71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-riscv_insn_table-v3-16-3f8e5f75ba97@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unaligned memory accesses during instruction patching in kexec could cause hardware traps on RISC-V.
--
--- Patch [16]: [PATCH v3 16/17] riscv: kexec: Use generated instruction headers for kexec relocations ---
commit 8214fe744bbe604843e11511b3e732e4ee739dad
Author: Charlie Jenkins <thecharlesjenkins@gmail.com>
riscv: kexec: Use generated instruction headers for kexec relocations
This commit migrates the kexec relocation code to use the generated
instruction headers instead of the hand-written instruction composition
functions.
> diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
> index 54e2d9552e930..cad40e4afd867 100644
> --- a/arch/riscv/kernel/machine_kexec_file.c
> +++ b/arch/riscv/kernel/machine_kexec_file.c
[ ... ]
> @@ -197,12 +171,14 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
>
> switch (r_type) {
> case R_RISCV_BRANCH:
> - *(u32 *)loc = CLEAN_IMM(BTYPE, *(u32 *)loc) |
> - ENCODE_BTYPE_IMM(val - addr);
> + /*
> + * For simplicity, use beq as represenative of all
> + * branches (they all have the same imm encoding)
> + */
> + riscv_insn_beq_insert_imm((u32 *)loc, val - addr);
[Severity: High]
This is a pre-existing issue, but does casting loc to a u32 pointer here
trigger unaligned memory access traps on strict-alignment hardware?
If the purgatory ELF contains 32-bit instructions aligned on a 2-byte
boundary, which happens frequently due to the RISC-V Compressed extension,
passing this pointer to a function that performs a direct 32-bit
read-modify-write operation could cause a kernel panic during kexec.
> break;
> case R_RISCV_JAL:
> - *(u32 *)loc = CLEAN_IMM(JTYPE, *(u32 *)loc) |
> - ENCODE_JTYPE_IMM(val - addr);
> + riscv_insn_jal_insert_imm((u32 *)loc, val - addr);
[Severity: High]
This is also a pre-existing issue, but could this direct u32 pointer cast
cause similar unaligned memory access traps if the location is 2-byte
aligned?
> break;
[ ... ]
> case R_RISCV_PCREL_HI20:
> case R_RISCV_CALL_PLT:
> case R_RISCV_CALL:
> - *(u64 *)loc = CLEAN_IMM(UITYPE, *(u64 *)loc) |
> - ENCODE_UJTYPE_IMM(val - addr);
> + riscv_insn_auipc_insert_imm((u32 *)loc, RISCV_CONST_HIGH_PART(val - addr));
> + riscv_insn_jalr_insert_imm((u32 *)loc + 1,
> + RISCV_CONST_LOW_PART(val - addr));
> break;
[Severity: High]
This is a pre-existing issue, but would accessing loc and loc + 1 as u32
pointers lead to unaligned access faults in arch_kexec_apply_relocations_add
if the base instruction is misaligned?
The kernel module loader avoids this problem by correctly using 16-bit access
pairs, such as riscv_insn_rmw, for instruction patching.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-riscv_insn_table-v3-0-3f8e5f75ba97@gmail.com?part=16
next prev parent reply other threads:[~2026-07-08 4:01 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 3:34 [PATCH v3 00/17] riscv: Generate riscv instruction functions Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 01/17] riscv: Introduce instruction table generation Charlie Jenkins
2026-07-08 3:50 ` sashiko-bot
2026-07-09 6:23 ` Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 02/17] riscv: alternatives: Use generated instruction headers for patching code Charlie Jenkins
2026-07-08 3:45 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 03/17] riscv: kgdb: Use generated instruction headers Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 04/17] riscv: Add kprobes instruction simulation KUnit Charlie Jenkins
2026-07-08 3:51 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 05/17] riscv: kprobes: Use generated instruction headers Charlie Jenkins
2026-07-08 3:52 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 06/17] riscv: cfi: " Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 07/17] riscv: Maintain epc on misaligned emulation error Charlie Jenkins
2026-07-08 3:55 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 08/17] riscv: Use generated instruction headers for misaligned loads/stores Charlie Jenkins
2026-07-08 3:49 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 09/17] riscv: kvm: Use generated instruction headers for csr code Charlie Jenkins
2026-07-08 3:48 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 10/17] KVM: device: Add test device Charlie Jenkins
2026-07-08 3:48 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 11/17] KVM: riscv: selftests: Add mmio test Charlie Jenkins
2026-07-08 3:59 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 12/17] riscv: kvm: Use generated instruction headers for mmio emulation Charlie Jenkins
2026-07-08 4:01 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 13/17] riscv: kvm: Add emulated test csr Charlie Jenkins
2026-07-08 4:00 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 14/17] KVM: riscv: selftests: Add csr emulation test Charlie Jenkins
2026-07-08 3:58 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 15/17] riscv: kvm: Use generated instruction headers for csr emulation Charlie Jenkins
2026-07-08 4:04 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 16/17] riscv: kexec: Use generated instruction headers for kexec relocations Charlie Jenkins
2026-07-08 4:01 ` sashiko-bot [this message]
2026-07-08 3:34 ` [PATCH v3 17/17] riscv: Remove unused instruction headers Charlie Jenkins
2026-07-08 4:09 ` sashiko-bot
2026-07-09 6:26 ` [syzbot ci] Re: riscv: Generate riscv instruction functions syzbot ci
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=20260708040104.97AE71F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=thecharlesjenkins@gmail.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