Commit 012a224e authored by Nico Boehr's avatar Nico Boehr Committed by Heiko Carstens

s390/uaccess: introduce bit field for OAC specifier

Previously, we've used  magic values to specify the OAC
(operand-access control) for mvcos.

Instead we introduce a bit field for it.

When using a bit field, we cannot use an immediate value with K
constraint anymore, since GCC older than 10 doesn't recognize
the bit field union as a compile time constant.
To make things work with older compilers,
load the OAC value through a register.

Bloat-o-meter reports a slight increase in kernel size with this change:
Total: Before=15692135, After=15693015, chg +0.01%
Signed-off-by: default avatarNico Boehr <nrb@linux.ibm.com>
Co-developed-by: default avatarJanis Schoetterl-Glausch <scgl@linux.ibm.com>
Signed-off-by: default avatarJanis Schoetterl-Glausch <scgl@linux.ibm.com>
Link: https://lore.kernel.org/r/20220111100003.743116-1-scgl@linux.ibm.com
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
parent 745f5d20
...@@ -49,51 +49,85 @@ int __get_user_bad(void) __attribute__((noreturn)); ...@@ -49,51 +49,85 @@ int __get_user_bad(void) __attribute__((noreturn));
#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
#define __put_get_user_asm(to, from, size, insn) \ union oac {
({ \ unsigned int val;
int __rc; \ struct {
\ struct {
asm volatile( \ unsigned short key : 4;
insn " 0,%[spec]\n" \ unsigned short : 4;
"0: mvcos %[_to],%[_from],%[_size]\n" \ unsigned short as : 2;
"1: xr %[rc],%[rc]\n" \ unsigned short : 4;
"2:\n" \ unsigned short k : 1;
".pushsection .fixup, \"ax\"\n" \ unsigned short a : 1;
"3: lhi %[rc],%[retval]\n" \ } oac1;
" jg 2b\n" \ struct {
".popsection\n" \ unsigned short key : 4;
EX_TABLE(0b,3b) EX_TABLE(1b,3b) \ unsigned short : 4;
: [rc] "=&d" (__rc), [_to] "+Q" (*(to)) \ unsigned short as : 2;
: [_size] "d" (size), [_from] "Q" (*(from)), \ unsigned short : 4;
[retval] "K" (-EFAULT), [spec] "K" (0x81UL) \ unsigned short k : 1;
: "cc", "0"); \ unsigned short a : 1;
__rc; \ } oac2;
};
};
#define __put_get_user_asm(to, from, size, oac_spec) \
({ \
int __rc; \
\
asm volatile( \
" lr 0,%[spec]\n" \
"0: mvcos %[_to],%[_from],%[_size]\n" \
"1: xr %[rc],%[rc]\n" \
"2:\n" \
".pushsection .fixup, \"ax\"\n" \
"3: lhi %[rc],%[retval]\n" \
" jg 2b\n" \
".popsection\n" \
EX_TABLE(0b,3b) EX_TABLE(1b,3b) \
: [rc] "=&d" (__rc), [_to] "+Q" (*(to)) \
: [_size] "d" (size), [_from] "Q" (*(from)), \
[retval] "K" (-EFAULT), [spec] "d" (oac_spec.val) \
: "cc", "0"); \
__rc; \
}) })
#define __put_user_asm(to, from, size) \
__put_get_user_asm(to, from, size, ((union oac) { \
.oac1.as = PSW_BITS_AS_SECONDARY, \
.oac1.a = 1 \
}))
#define __get_user_asm(to, from, size) \
__put_get_user_asm(to, from, size, ((union oac) { \
.oac2.as = PSW_BITS_AS_SECONDARY, \
.oac2.a = 1 \
})) \
static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size)
{ {
int rc; int rc;
switch (size) { switch (size) {
case 1: case 1:
rc = __put_get_user_asm((unsigned char __user *)ptr, rc = __put_user_asm((unsigned char __user *)ptr,
(unsigned char *)x, (unsigned char *)x,
size, "llilh"); size);
break; break;
case 2: case 2:
rc = __put_get_user_asm((unsigned short __user *)ptr, rc = __put_user_asm((unsigned short __user *)ptr,
(unsigned short *)x, (unsigned short *)x,
size, "llilh"); size);
break; break;
case 4: case 4:
rc = __put_get_user_asm((unsigned int __user *)ptr, rc = __put_user_asm((unsigned int __user *)ptr,
(unsigned int *)x, (unsigned int *)x,
size, "llilh"); size);
break; break;
case 8: case 8:
rc = __put_get_user_asm((unsigned long __user *)ptr, rc = __put_user_asm((unsigned long __user *)ptr,
(unsigned long *)x, (unsigned long *)x,
size, "llilh"); size);
break; break;
default: default:
__put_user_bad(); __put_user_bad();
...@@ -108,24 +142,24 @@ static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsign ...@@ -108,24 +142,24 @@ static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsign
switch (size) { switch (size) {
case 1: case 1:
rc = __put_get_user_asm((unsigned char *)x, rc = __get_user_asm((unsigned char *)x,
(unsigned char __user *)ptr, (unsigned char __user *)ptr,
size, "lghi"); size);
break; break;
case 2: case 2:
rc = __put_get_user_asm((unsigned short *)x, rc = __get_user_asm((unsigned short *)x,
(unsigned short __user *)ptr, (unsigned short __user *)ptr,
size, "lghi"); size);
break; break;
case 4: case 4:
rc = __put_get_user_asm((unsigned int *)x, rc = __get_user_asm((unsigned int *)x,
(unsigned int __user *)ptr, (unsigned int __user *)ptr,
size, "lghi"); size);
break; break;
case 8: case 8:
rc = __put_get_user_asm((unsigned long *)x, rc = __get_user_asm((unsigned long *)x,
(unsigned long __user *)ptr, (unsigned long __user *)ptr,
size, "lghi"); size);
break; break;
default: default:
__get_user_bad(); __get_user_bad();
......
...@@ -62,10 +62,14 @@ static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr ...@@ -62,10 +62,14 @@ static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr
unsigned long size) unsigned long size)
{ {
unsigned long tmp1, tmp2; unsigned long tmp1, tmp2;
union oac spec = {
.oac2.as = PSW_BITS_AS_SECONDARY,
.oac2.a = 1,
};
tmp1 = -4096UL; tmp1 = -4096UL;
asm volatile( asm volatile(
" lghi 0,%[spec]\n" " lr 0,%[spec]\n"
"0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n" "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
"6: jz 4f\n" "6: jz 4f\n"
"1: algr %0,%3\n" "1: algr %0,%3\n"
...@@ -84,7 +88,7 @@ static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr ...@@ -84,7 +88,7 @@ static inline unsigned long copy_from_user_mvcos(void *x, const void __user *ptr
"5:\n" "5:\n"
EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b) EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
: "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
: [spec] "K" (0x81UL) : [spec] "d" (spec.val)
: "cc", "memory", "0"); : "cc", "memory", "0");
return size; return size;
} }
...@@ -135,10 +139,14 @@ static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x, ...@@ -135,10 +139,14 @@ static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x,
unsigned long size) unsigned long size)
{ {
unsigned long tmp1, tmp2; unsigned long tmp1, tmp2;
union oac spec = {
.oac1.as = PSW_BITS_AS_SECONDARY,
.oac1.a = 1,
};
tmp1 = -4096UL; tmp1 = -4096UL;
asm volatile( asm volatile(
" llilh 0,%[spec]\n" " lr 0,%[spec]\n"
"0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n" "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
"6: jz 4f\n" "6: jz 4f\n"
"1: algr %0,%3\n" "1: algr %0,%3\n"
...@@ -157,7 +165,7 @@ static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x, ...@@ -157,7 +165,7 @@ static inline unsigned long copy_to_user_mvcos(void __user *ptr, const void *x,
"5:\n" "5:\n"
EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b) EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
: "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2) : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
: [spec] "K" (0x81UL) : [spec] "d" (spec.val)
: "cc", "memory", "0"); : "cc", "memory", "0");
return size; return size;
} }
...@@ -207,10 +215,14 @@ EXPORT_SYMBOL(raw_copy_to_user); ...@@ -207,10 +215,14 @@ EXPORT_SYMBOL(raw_copy_to_user);
static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size) static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size)
{ {
unsigned long tmp1, tmp2; unsigned long tmp1, tmp2;
union oac spec = {
.oac1.as = PSW_BITS_AS_SECONDARY,
.oac1.a = 1,
};
tmp1 = -4096UL; tmp1 = -4096UL;
asm volatile( asm volatile(
" llilh 0,%[spec]\n" " lr 0,%[spec]\n"
"0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n" "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
" jz 4f\n" " jz 4f\n"
"1: algr %0,%2\n" "1: algr %0,%2\n"
...@@ -228,7 +240,7 @@ static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size ...@@ -228,7 +240,7 @@ static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size
"5:\n" "5:\n"
EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(0b,2b) EX_TABLE(3b,5b)
: "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2) : "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
: "a" (empty_zero_page), [spec] "K" (0x81UL) : "a" (empty_zero_page), [spec] "d" (spec.val)
: "cc", "memory", "0"); : "cc", "memory", "0");
return size; return size;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment