[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/3] xen/riscv: fix switch_stack_and_jump() for range beyond 1M
- To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Tue, 2 Jun 2026 17:21:52 +0200
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:In-Reply-To:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
- Cc: Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
- Delivery-date: Tue, 02 Jun 2026 15:21:59 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 6/2/26 1:21 PM, Andrew Cooper wrote:
On 25/05/2026 2:20 pm, Oleksii Kurochko wrote:
The `j` instruction (JAL x0) used in switch_stack_and_jump() is a
J-type instruction with only a ±1MB range, and that this can
be exceeded in some configurations, causing a linker error:
relocation truncated to fit: R_RISCV_JAL against `<symbol>'
Replace `j` with `jr` (JALR x0) via an explicit register, which has
unlimited range.
Found in a downstream branch when UBSAN instrumentation was enabled.
Note that the `tail` instruction looks more natural here, but `jr` is
chosen instead to avoid depending on how the assembler expands `tail`
and which scratch register it uses (`t1` in GAS), which would need to
be listed in the clobber section of `asm volatile`.
Fixes: e66003e7be199 ("xen/riscv: introduce setup_initial_pages")
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
Reviewed-by: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
---
Changes in v2:
- Update the commit message and subject
---
xen/arch/riscv/include/asm/current.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/xen/arch/riscv/include/asm/current.h
b/xen/arch/riscv/include/asm/current.h
index 5fbee8182caa..cc004670d18c 100644
--- a/xen/arch/riscv/include/asm/current.h
+++ b/xen/arch/riscv/include/asm/current.h
@@ -51,11 +51,11 @@ DECLARE_PER_CPU(struct vcpu *, curr_vcpu);
#define vcpu_guest_cpu_user_regs(vcpu) \
(&(vcpu)->arch.cpu_info->guest_cpu_user_regs)
-#define switch_stack_and_jump(stack, fn) do { \
- asm volatile ( \
- "mv sp, %0\n" \
- "j " #fn :: "r" (stack), "X" (fn) : "memory" ); \
- unreachable(); \
+#define switch_stack_and_jump(stack, fn) do { \
+ asm volatile ( \
+ "mv sp, %0\n" \
+ "jr %1" :: "r" (stack), "r" (fn) : "memory" ); \
+ unreachable(); \
} while ( false )
Just as a note, with this simplified again, the \'s can avoid moving, at
which point the diff becomes a single line.
Can be fixed on commit.
I would be happy with that.
Thanks.
~ Oleksii
|