sh: uaccess: Require offsettable operands for 64-bit user access
PATCH 1/1 sh: uaccess: Require offsettable operands for 64-bit user access
The 64-bit __get_user_u64()/__put_user_u64() paths address the memory operand as %T2 (base+4). This base+4 requires an offsettable address, but "m" also allows the indexed mode @(R0,Rn) (e.g. for a variable- indexed array element), which has no displacement field for the +4. Depending on optimization this build fails with "invalid 'asm'" or an ICE in GCC's change_address_1.
Require an offsettable memory operand, allowing GCC to reload an unsuitable indexed address into an appropriate form.
---
The patch was verified on the J2 core on the Mimas v2 board. And booted on the Dreamcast SH4. checkpatch doesn't like the missing whitespaces around : I preferred not to touch the other unrelated lines, so I kept the local style.
The original GCC ICE, without this patch can be seen here:
https://lore.kernel.org/linux-sh/[email protected]/
arch/sh/include/asm/uaccess_32.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/sh/include/asm/uaccess_32.h +4 -4
@@ -92,7 +92,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#else #define __get_user_u64 (x, addr, err) \ ({ \
@@ -116,7 +116,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#endif #define __put_user_size (x,ptr,size,retval) \
@@ -196,7 +196,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #else #define __put_user_u64(val,addr,retval) \
@@ -218,7 +218,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #endif
Signature · 1 line
2.43.0
Hi Florian,
Quoted 56 lines · Florian Fuchs
The 64-bit __get_user_u64()/__put_user_u64() paths address the memory operand as %T2 (base+4). This base+4 requires an offsettable address, but "m" also allows the indexed mode @(R0,Rn) (e.g. for a variable- indexed array element), which has no displacement field for the +4. Depending on optimization this build fails with "invalid 'asm'" or an ICE in GCC's
change_address_1.Require an offsettable memory operand, allowing GCC to reload an unsuitable indexed address into an appropriate form.
Fixes 2d2b308a8b7d ("sh: Implement __get_user_u64() required for 64-bit get_user()")Signed-off-by Florian Fuchs <[email protected]>---
The patch was verified on the J2 core on the Mimas v2 board. And booted on the Dreamcast SH4. checkpatch doesn't like the missing whitespaces around : I preferred not to touch the other unrelated lines, so I kept the local style.The original GCC ICE, without this patch can be seen here:
https://lore.kernel.org/linux-sh/[email protected]/arch/sh/include/asm/uaccess_32.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/sh/include/asm/uaccess_32.h +3
-3@@ -92,7 +92,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#else #define __get_user_u64 (x, addr, err) \ ({ \@@ -116,7 +116,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#endif #define __put_user_size (x,ptr,size,retval) \@@ -196,7 +196,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #else #define __put_user_u64(val,addr,retval) \
arch/sh/include/asm/uaccess_32.h __asm__ __volatile__( \ · line 224
Quoted 8 lines
arch/sh/include/asm/uaccess_32.h +1
-1@@ -218,7 +218,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #endif
Nice catch, thanks a lot for fixing this!
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 12 lines · On Thu, 16 Jul 2026 19:05:03 +0200 John Paul Adrian Glaubitz…
Hi Florian,
Quoted 9 lines · Florian Fuchs
The 64-bit __get_user_u64()/__put_user_u64() paths address the memory operand as %T2 (base+4). This base+4 requires an offsettable address, but "m" also allows the indexed mode @(R0,Rn) (e.g. for a variable- indexed array element), which has no displacement field for the +4. Depending on optimization this build fails with "invalid 'asm'" or an ICE in GCC's
change_address_1.Require an offsettable memory operand, allowing GCC to reload an unsuitable indexed address into an appropriate form.
An alternative would be to pass 'addr' and 'addr + 4' separately so that the C compilation adds in the offset.
With a bit more effort the define wouldn't need repeating for LE and BE.
There is a bug in the __put_user_u64 code - it is missing the exception table entry for the second word.
(It is present in __get_user_u64, but a separate label would be better.)
I also wonder whether there should be non-mmu copies?
David
Hi Florian,
Quoted 56 lines · Florian Fuchs
The 64-bit __get_user_u64()/__put_user_u64() paths address the memory operand as %T2 (base+4). This base+4 requires an offsettable address, but "m" also allows the indexed mode @(R0,Rn) (e.g. for a variable- indexed array element), which has no displacement field for the +4. Depending on optimization this build fails with "invalid 'asm'" or an ICE in GCC's
change_address_1.Require an offsettable memory operand, allowing GCC to reload an unsuitable indexed address into an appropriate form.
Fixes 2d2b308a8b7d ("sh: Implement __get_user_u64() required for 64-bit get_user()")Signed-off-by Florian Fuchs <[email protected]>---
The patch was verified on the J2 core on the Mimas v2 board. And booted on the Dreamcast SH4. checkpatch doesn't like the missing whitespaces around : I preferred not to touch the other unrelated lines, so I kept the local style.The original GCC ICE, without this patch can be seen here:
https://lore.kernel.org/linux-sh/[email protected]/arch/sh/include/asm/uaccess_32.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/sh/include/asm/uaccess_32.h +3
-3@@ -92,7 +92,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#else #define __get_user_u64 (x, addr, err) \ ({ \@@ -116,7 +116,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#endif #define __put_user_size (x,ptr,size,retval) \@@ -196,7 +196,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #else #define __put_user_u64(val,addr,retval) \
arch/sh/include/asm/uaccess_32.h __asm__ __volatile__( \ · line 224
Quoted 8 lines
arch/sh/include/asm/uaccess_32.h +1
-1@@ -218,7 +218,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #endif
I have now also tested the patch and I can confirm that it unbreaks the J2 kernel build for me and GCC no longer fails with an internal compiler error.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 56 lines · Florian Fuchs
The 64-bit __get_user_u64()/__put_user_u64() paths address the memory operand as %T2 (base+4). This base+4 requires an offsettable address, but "m" also allows the indexed mode @(R0,Rn) (e.g. for a variable- indexed array element), which has no displacement field for the +4. Depending on optimization this build fails with "invalid 'asm'" or an ICE in GCC's
change_address_1.Require an offsettable memory operand, allowing GCC to reload an unsuitable indexed address into an appropriate form.
Fixes 2d2b308a8b7d ("sh: Implement __get_user_u64() required for 64-bit get_user()")Signed-off-by Florian Fuchs <[email protected]>---
The patch was verified on the J2 core on the Mimas v2 board. And booted on the Dreamcast SH4. checkpatch doesn't like the missing whitespaces around : I preferred not to touch the other unrelated lines, so I kept the local style.The original GCC ICE, without this patch can be seen here:
https://lore.kernel.org/linux-sh/[email protected]/arch/sh/include/asm/uaccess_32.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/sh/include/asm/uaccess_32.h +3
-3@@ -92,7 +92,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#else #define __get_user_u64 (x, addr, err) \ ({ \@@ -116,7 +116,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#endif #define __put_user_size (x,ptr,size,retval) \@@ -196,7 +196,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #else #define __put_user_u64(val,addr,retval) \
arch/sh/include/asm/uaccess_32.h __asm__ __volatile__( \ · line 224
Quoted 8 lines
arch/sh/include/asm/uaccess_32.h +1
-1@@ -218,7 +218,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #endif
Merged into for-next for v7.4.
Thanks,
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913