2022-02-28 11:37:52 +01:00
// SPDX-License-Identifier: GPL-2.0
2022-05-01 21:26:06 +02:00
# include <linux/bitfield.h>
2022-02-28 11:37:52 +01:00
# include <linux/extable.h>
2022-05-01 21:26:06 +02:00
# include <linux/string.h>
s390/extable: add dedicated uaccess handler
This is more or less a combination of commit 2e77a62cb3a6 ("arm64:
extable: add a dedicated uaccess handler") and commit 4b5305decc84
("x86/extable: Extend extable functionality").
To describe the problem that needs to solved let's cite the full arm64
commit message:
------
For inline assembly, we place exception fixups out-of-line in the
`.fixup` section such that these are out of the way of the fast path.
This has a few drawbacks:
* Since the fixup code is anonymous, backtraces will symbolize fixups
as offsets from the nearest prior symbol, currently
`__entry_tramp_text_end`. This is confusing, and painful to debug
without access to the relevant vmlinux.
* Since the exception handler adjusts the PC to execute the fixup, and
the fixup uses a direct branch back into the function it fixes,
backtraces of fixups miss the original function. This is confusing,
and violates requirements for RELIABLE_STACKTRACE (and therefore
LIVEPATCH).
* Inline assembly and associated fixups are generated from templates,
and we have many copies of logically identical fixups which only
differ in which specific registers are written to and which address
is branched to at the end of the fixup. This is potentially wasteful
of I-cache resources, and makes it hard to add additional logic to
fixups without significant bloat.
This patch address all three concerns for inline uaccess fixups by
adding a dedicated exception handler which updates registers in
exception context and subsequent returns back into the function which
faulted, removing the need for fixups specialized to each faulting
instruction.
Other than backtracing, there should be no functional change as a result
of this patch.
------
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2022-02-28 15:02:46 +01:00
# include <linux/errno.h>
2022-02-28 14:52:42 +01:00
# include <linux/panic.h>
# include <asm/asm-extable.h>
2022-02-28 11:37:52 +01:00
# include <asm/extable.h>
const struct exception_table_entry * s390_search_extables ( unsigned long addr )
{
const struct exception_table_entry * fixup ;
size_t num ;
fixup = search_exception_tables ( addr ) ;
if ( fixup )
return fixup ;
num = __stop_amode31_ex_table - __start_amode31_ex_table ;
return search_extable ( __start_amode31_ex_table , num , addr ) ;
}
2022-02-28 14:29:25 +01:00
2022-02-28 14:52:42 +01:00
static bool ex_handler_fixup ( const struct exception_table_entry * ex , struct pt_regs * regs )
{
regs - > psw . addr = extable_fixup ( ex ) ;
return true ;
}
2022-05-01 21:26:06 +02:00
static bool ex_handler_ua_store ( const struct exception_table_entry * ex , struct pt_regs * regs )
s390/extable: add dedicated uaccess handler
This is more or less a combination of commit 2e77a62cb3a6 ("arm64:
extable: add a dedicated uaccess handler") and commit 4b5305decc84
("x86/extable: Extend extable functionality").
To describe the problem that needs to solved let's cite the full arm64
commit message:
------
For inline assembly, we place exception fixups out-of-line in the
`.fixup` section such that these are out of the way of the fast path.
This has a few drawbacks:
* Since the fixup code is anonymous, backtraces will symbolize fixups
as offsets from the nearest prior symbol, currently
`__entry_tramp_text_end`. This is confusing, and painful to debug
without access to the relevant vmlinux.
* Since the exception handler adjusts the PC to execute the fixup, and
the fixup uses a direct branch back into the function it fixes,
backtraces of fixups miss the original function. This is confusing,
and violates requirements for RELIABLE_STACKTRACE (and therefore
LIVEPATCH).
* Inline assembly and associated fixups are generated from templates,
and we have many copies of logically identical fixups which only
differ in which specific registers are written to and which address
is branched to at the end of the fixup. This is potentially wasteful
of I-cache resources, and makes it hard to add additional logic to
fixups without significant bloat.
This patch address all three concerns for inline uaccess fixups by
adding a dedicated exception handler which updates registers in
exception context and subsequent returns back into the function which
faulted, removing the need for fixups specialized to each faulting
instruction.
Other than backtracing, there should be no functional change as a result
of this patch.
------
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2022-02-28 15:02:46 +01:00
{
2022-05-01 21:26:06 +02:00
unsigned int reg_err = FIELD_GET ( EX_DATA_REG_ERR , ex - > data ) ;
regs - > gprs [ reg_err ] = - EFAULT ;
regs - > psw . addr = extable_fixup ( ex ) ;
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 ;
}
2022-11-02 15:18:45 +01:00
static bool ex_handler_ua_load_reg ( const struct exception_table_entry * ex ,
bool pair , struct pt_regs * regs )
2022-05-01 21:26:06 +02:00
{
unsigned int reg_zero = FIELD_GET ( EX_DATA_REG_ADDR , ex - > data ) ;
unsigned int reg_err = FIELD_GET ( EX_DATA_REG_ERR , ex - > data ) ;
regs - > gprs [ reg_err ] = - EFAULT ;
regs - > gprs [ reg_zero ] = 0 ;
2022-11-02 15:18:45 +01:00
if ( pair )
regs - > gprs [ reg_zero + 1 ] = 0 ;
s390/extable: add dedicated uaccess handler
This is more or less a combination of commit 2e77a62cb3a6 ("arm64:
extable: add a dedicated uaccess handler") and commit 4b5305decc84
("x86/extable: Extend extable functionality").
To describe the problem that needs to solved let's cite the full arm64
commit message:
------
For inline assembly, we place exception fixups out-of-line in the
`.fixup` section such that these are out of the way of the fast path.
This has a few drawbacks:
* Since the fixup code is anonymous, backtraces will symbolize fixups
as offsets from the nearest prior symbol, currently
`__entry_tramp_text_end`. This is confusing, and painful to debug
without access to the relevant vmlinux.
* Since the exception handler adjusts the PC to execute the fixup, and
the fixup uses a direct branch back into the function it fixes,
backtraces of fixups miss the original function. This is confusing,
and violates requirements for RELIABLE_STACKTRACE (and therefore
LIVEPATCH).
* Inline assembly and associated fixups are generated from templates,
and we have many copies of logically identical fixups which only
differ in which specific registers are written to and which address
is branched to at the end of the fixup. This is potentially wasteful
of I-cache resources, and makes it hard to add additional logic to
fixups without significant bloat.
This patch address all three concerns for inline uaccess fixups by
adding a dedicated exception handler which updates registers in
exception context and subsequent returns back into the function which
faulted, removing the need for fixups specialized to each faulting
instruction.
Other than backtracing, there should be no functional change as a result
of this patch.
------
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2022-02-28 15:02:46 +01:00
regs - > psw . addr = extable_fixup ( ex ) ;
return true ;
}
2022-02-28 14:29:25 +01:00
bool fixup_exception ( struct pt_regs * regs )
{
const struct exception_table_entry * ex ;
ex = s390_search_extables ( instruction_pointer ( regs ) ) ;
if ( ! ex )
return false ;
2022-02-28 14:52:42 +01:00
switch ( ex - > type ) {
case EX_TYPE_FIXUP :
return ex_handler_fixup ( ex , regs ) ;
case EX_TYPE_BPF :
return ex_handler_bpf ( ex , regs ) ;
2022-05-01 21:26:06 +02:00
case EX_TYPE_UA_STORE :
return ex_handler_ua_store ( ex , regs ) ;
case EX_TYPE_UA_LOAD_MEM :
return ex_handler_ua_load_mem ( ex , regs ) ;
case EX_TYPE_UA_LOAD_REG :
2022-11-02 15:18:45 +01:00
return ex_handler_ua_load_reg ( ex , false , regs ) ;
case EX_TYPE_UA_LOAD_REGPAIR :
return ex_handler_ua_load_reg ( ex , true , regs ) ;
2022-02-28 14:52:42 +01:00
}
panic ( " invalid exception table entry " ) ;
2022-02-28 14:29:25 +01:00
}