s390/uaccess: Replace EX_TABLE_UA_LOAD_MEM exception handling

Remove EX_TABLE_UA_LOAD_MEM exception handling and replace it with
EX_TABLE_UA_FAULT. Open code the return code check, and also open code
setting of the destination to zero in case of an error. In almost all cases
the compiler is able to optimize the open coded checks away, since all
users of get_users() must check the return code, and are not supposed to
use the result in case of an error.

In addition this allows to change the get_user() inline assembly so that
the "Q" constraint can be used for the destination, instead of only an "a"
constraint. This generates slightly better code.

Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
This commit is contained in:
Heiko Carstens 2025-01-13 13:37:04 +01:00 committed by Alexander Gordeev
parent 67e959af25
commit dc7ff4b8cb
3 changed files with 8 additions and 24 deletions

View File

@ -10,7 +10,6 @@
#define EX_TYPE_FIXUP 1
#define EX_TYPE_BPF 2
#define EX_TYPE_UA_FAULT 3
#define EX_TYPE_UA_LOAD_MEM 4
#define EX_TYPE_UA_LOAD_REG 5
#define EX_TYPE_UA_LOAD_REGPAIR 6
#define EX_TYPE_ZEROPAD 7
@ -73,9 +72,6 @@
#define EX_TABLE_UA_FAULT(_fault, _target, _regerr) \
__EX_TABLE(__ex_table, _fault, _target, EX_TYPE_UA_FAULT, _regerr, _regerr, 0)
#define EX_TABLE_UA_LOAD_MEM(_fault, _target, _regerr, _regmem, _len) \
__EX_TABLE(__ex_table, _fault, _target, EX_TYPE_UA_LOAD_MEM, _regerr, _regmem, _len)
#define EX_TABLE_UA_LOAD_REG(_fault, _target, _regerr, _regzero) \
__EX_TABLE(__ex_table, _fault, _target, EX_TYPE_UA_LOAD_REG, _regerr, _regzero, 0)

View File

@ -184,16 +184,18 @@ __get_user_##type##_noinstr(unsigned type *to, \
\
asm volatile( \
" lr %%r0,%[spec]\n" \
"0: mvcos 0(%[to]),%[from],%[size]\n" \
"0: mvcos %[to],%[from],%[size]\n" \
"1: lhi %[rc],0\n" \
"2:\n" \
EX_TABLE_UA_LOAD_MEM(0b, 2b, %[rc], %[to], %[ksize]) \
EX_TABLE_UA_LOAD_MEM(1b, 2b, %[rc], %[to], %[ksize]) \
: [rc] "=d" (rc), "=Q" (*to) \
EX_TABLE_UA_FAULT(0b, 2b, %[rc]) \
EX_TABLE_UA_FAULT(1b, 2b, %[rc]) \
: [rc] "=d" (rc), [to] "=Q" (*to) \
: [size] "d" (size), [from] "Q" (*from), \
[spec] "d" (__oac_spec.val), [to] "a" (to), \
[ksize] "K" (size) \
[spec] "d" (__oac_spec.val) \
: "cc", "0"); \
if (likely(!rc)) \
return 0; \
*to = 0; \
return rc; \
} \
\

View File

@ -36,18 +36,6 @@ static bool ex_handler_ua_fault(const struct exception_table_entry *ex, struct p
return true;
}
static bool ex_handler_ua_load_mem(const struct exception_table_entry *ex, struct pt_regs *regs)
{
unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
size_t len = FIELD_GET(EX_DATA_LEN, ex->data);
regs->gprs[reg_err] = -EFAULT;
memset((void *)regs->gprs[reg_addr], 0, len);
regs->psw.addr = extable_fixup(ex);
return true;
}
static bool ex_handler_ua_load_reg(const struct exception_table_entry *ex,
bool pair, struct pt_regs *regs)
{
@ -99,8 +87,6 @@ bool fixup_exception(struct pt_regs *regs)
return ex_handler_bpf(ex, regs);
case EX_TYPE_UA_FAULT:
return ex_handler_ua_fault(ex, regs);
case EX_TYPE_UA_LOAD_MEM:
return ex_handler_ua_load_mem(ex, regs);
case EX_TYPE_UA_LOAD_REG:
return ex_handler_ua_load_reg(ex, false, regs);
case EX_TYPE_UA_LOAD_REGPAIR: