[PATCH RFC v2] riscv: Use 64-bit variable for output in __get_user_asm

Paul Walmsley pjw at kernel.org
Wed Jan 14 17:02:46 PST 2026


Hi Nathan,

On Tue, 13 Jan 2026, Nathan Chancellor wrote:

> After commit f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for
> get_user()"), which was the first commit that started using asm goto
> with outputs on RISC-V, builds of clang built with assertions enabled
> start crashing in certain files that use get_user() with:
> 
>   clang: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:12743: Register FollowCopyChain(MachineRegisterInfo &, Register): Assertion `MI->getOpcode() == TargetOpcode::COPY && "start of copy chain MUST be COPY"' failed.
> 
> Internally, LLVM generates an addiw instruction when the output of the
> inline asm (which may be any scalar type) needs to be sign extended for
> ABI reasons, such as a later function call, so that basic block does not
> have to do it.
> 
> Use a temporary 64-bit variable as the output of the inline assembly in
> __get_user_asm() and explicitly cast it to truncate it if necessary,
> avoiding the addiw that triggers the assertion.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/2092
> Signed-off-by: Nathan Chancellor <nathan at kernel.org>
> ---
> Changes in v2:
> - Rebase on 6.19-rc5
> - Send to updated addresses
> - Link to v1: https://lore.kernel.org/r/20250811-riscv-wa-llvm-asm-goto-outputs-assertion-failure-v1-1-7bb8c9cbb92b@kernel.org
> ---
> I did this unconditionally but I did not do much investigation into how
> the code generation changes, as I never have good luck with figuring out
> what is real vs. noise. If this is a worry, I can just duplicate this
> under a CONFIG_CC_IS_CLANG block. Alternatively, we could mark
> CONFIG_CC_HAS_ASM_GOTO_OUTPUT as broken with clang when targeting
> RISC-V.

I'm assuming this would be a temporary patch, and that we might be able to 
remove it at some point (years, I guess?)

Might be worth adding a comment in the code to explain why a temporary 
variable is needed.


thanks for the patch,

- Paul



More information about the linux-riscv mailing list