Skip to content

Commit 62135bf

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: uaccess: use input constraints for ptr of __put_user()
Putting ptr in the inputs as opposed to output may seem incorrect but this is done for a few reasons: - Not having it in the output permits the use of asm goto in a subsequent patch. There are bugs in gcc [1] which would otherwise prevent it. - Since the output memory is userspace there isn't any real benefit from telling the compiler about the memory clobber. - x86, arm and powerpc all use this technique. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921 # 1 Signed-off-by: Jisheng Zhang <[email protected]> [Cyril Bur: Rewritten commit message] Signed-off-by: Cyril Bur <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 19500c6 commit 62135bf

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

arch/riscv/include/asm/uaccess.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ do { \
219219
__typeof__(*(ptr)) __x = x; \
220220
__asm__ __volatile__ ( \
221221
"1:\n" \
222-
" " insn " %z2, %1\n" \
222+
" " insn " %z1, %2\n" \
223223
"2:\n" \
224224
_ASM_EXTABLE_UACCESS_ERR(1b, 2b, %0) \
225-
: "+r" (err), "=m" (*(ptr)) \
226-
: "rJ" (__x)); \
225+
: "+r" (err) \
226+
: "rJ" (__x), "m"(*(ptr))); \
227227
} while (0)
228228

229229
#ifdef CONFIG_64BIT
@@ -236,16 +236,16 @@ do { \
236236
u64 __x = (__typeof__((x)-(x)))(x); \
237237
__asm__ __volatile__ ( \
238238
"1:\n" \
239-
" sw %z3, %1\n" \
239+
" sw %z1, %3\n" \
240240
"2:\n" \
241-
" sw %z4, %2\n" \
241+
" sw %z2, %4\n" \
242242
"3:\n" \
243243
_ASM_EXTABLE_UACCESS_ERR(1b, 3b, %0) \
244244
_ASM_EXTABLE_UACCESS_ERR(2b, 3b, %0) \
245-
: "+r" (err), \
246-
"=m" (__ptr[__LSW]), \
247-
"=m" (__ptr[__MSW]) \
248-
: "rJ" (__x), "rJ" (__x >> 32)); \
245+
: "+r" (err) \
246+
: "rJ" (__x), "rJ" (__x >> 32), \
247+
"m" (__ptr[__LSW]), \
248+
"m" (__ptr[__MSW])); \
249249
} while (0)
250250
#endif /* CONFIG_64BIT */
251251

0 commit comments

Comments
 (0)