mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-08 02:49:48 +00:00
Reduce system call overhead time (round trip time for invoking a non-existent system call) by 25%. With the removal of set_fs() [1] lazy control register handling was removed in order to keep kernel entry and exit simple. However this made system calls slower. With the conversion to generic entry [2] and numerous follow up changes which simplified the entry code significantly, adding support for lazy asce handling doesn't add much complexity to the entry code anymore. In particular this means: - On kernel entry the primary asce is not modified and contains the user asce - Kernel accesses which require secondary-space mode (for example futex operations) are surrounded by enable_sacf_uaccess() and disable_sacf_uaccess() calls. enable_sacf_uaccess() sets the primary asce to kernel asce so that the sacf instruction can be used to switch to secondary-space mode. The primary asce is changed back to user asce with disable_sacf_uaccess(). The state of the control register which contains the primary asce is reflected with a new TIF_ASCE_PRIMARY bit. This is required on context switch so that the correct asce is restored for the scheduled in process. In result address spaces are now setup like this: CPU running in | %cr1 ASCE | %cr7 ASCE | %cr13 ASCE -----------------------------|-----------|-----------|----------- user space | user | user | kernel kernel (no sacf) | user | user | kernel kernel (during sacf uaccess) | kernel | user | kernel kernel (kvm guest execution) | guest | user | kernel In result cr1 control register content is not changed except for: - futex system calls - legacy s390 PCI system calls - the kvm specific cmpxchg_user_key() uaccess helper This leads to faster system call execution. [1]87d5986345("s390/mm: remove set_fs / rework address space handling") [2]56e62a7370("s390: convert to generic entry") Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
148 lines
3.6 KiB
C
148 lines
3.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Standard user space access functions based on mvcp/mvcs and doing
|
|
* interesting things in the secondary space mode.
|
|
*
|
|
* Copyright IBM Corp. 2006,2014
|
|
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
|
|
* Gerald Schaefer (gerald.schaefer@de.ibm.com)
|
|
*/
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <linux/export.h>
|
|
#include <linux/mm.h>
|
|
#include <asm/asm-extable.h>
|
|
#include <asm/ctlreg.h>
|
|
|
|
#ifdef CONFIG_DEBUG_ENTRY
|
|
void debug_user_asce(int exit)
|
|
{
|
|
struct lowcore *lc = get_lowcore();
|
|
struct ctlreg cr1, cr7;
|
|
|
|
local_ctl_store(1, &cr1);
|
|
local_ctl_store(7, &cr7);
|
|
if (cr1.val == lc->user_asce.val && cr7.val == lc->user_asce.val)
|
|
return;
|
|
panic("incorrect ASCE on kernel %s\n"
|
|
"cr1: %016lx cr7: %016lx\n"
|
|
"kernel: %016lx user: %016lx\n",
|
|
exit ? "exit" : "entry", cr1.val, cr7.val,
|
|
lc->kernel_asce.val, lc->user_asce.val);
|
|
}
|
|
#endif /*CONFIG_DEBUG_ENTRY */
|
|
|
|
union oac {
|
|
unsigned int val;
|
|
struct {
|
|
struct {
|
|
unsigned short key : 4;
|
|
unsigned short : 4;
|
|
unsigned short as : 2;
|
|
unsigned short : 4;
|
|
unsigned short k : 1;
|
|
unsigned short a : 1;
|
|
} oac1;
|
|
struct {
|
|
unsigned short key : 4;
|
|
unsigned short : 4;
|
|
unsigned short as : 2;
|
|
unsigned short : 4;
|
|
unsigned short k : 1;
|
|
unsigned short a : 1;
|
|
} oac2;
|
|
};
|
|
};
|
|
|
|
static uaccess_kmsan_or_inline __must_check unsigned long
|
|
raw_copy_from_user_key(void *to, const void __user *from, unsigned long size, unsigned long key)
|
|
{
|
|
unsigned long osize;
|
|
union oac spec = {
|
|
.oac2.key = key,
|
|
.oac2.as = PSW_BITS_AS_SECONDARY,
|
|
.oac2.k = 1,
|
|
.oac2.a = 1,
|
|
};
|
|
int cc;
|
|
|
|
while (1) {
|
|
osize = size;
|
|
asm_inline volatile(
|
|
" lr %%r0,%[spec]\n"
|
|
"0: mvcos %[to],%[from],%[size]\n"
|
|
"1: nopr %%r7\n"
|
|
CC_IPM(cc)
|
|
EX_TABLE_UA_MVCOS_FROM(0b, 0b)
|
|
EX_TABLE_UA_MVCOS_FROM(1b, 0b)
|
|
: CC_OUT(cc, cc), [size] "+d" (size), [to] "=Q" (*(char *)to)
|
|
: [spec] "d" (spec.val), [from] "Q" (*(const char __user *)from)
|
|
: CC_CLOBBER_LIST("memory", "0"));
|
|
if (CC_TRANSFORM(cc) == 0)
|
|
return osize - size;
|
|
size -= 4096;
|
|
to += 4096;
|
|
from += 4096;
|
|
}
|
|
}
|
|
|
|
unsigned long _copy_from_user_key(void *to, const void __user *from,
|
|
unsigned long n, unsigned long key)
|
|
{
|
|
unsigned long res = n;
|
|
|
|
might_fault();
|
|
if (!should_fail_usercopy()) {
|
|
instrument_copy_from_user_before(to, from, n);
|
|
res = raw_copy_from_user_key(to, from, n, key);
|
|
instrument_copy_from_user_after(to, from, n, res);
|
|
}
|
|
if (unlikely(res))
|
|
memset(to + (n - res), 0, res);
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(_copy_from_user_key);
|
|
|
|
static uaccess_kmsan_or_inline __must_check unsigned long
|
|
raw_copy_to_user_key(void __user *to, const void *from, unsigned long size, unsigned long key)
|
|
{
|
|
unsigned long osize;
|
|
union oac spec = {
|
|
.oac1.key = key,
|
|
.oac1.as = PSW_BITS_AS_SECONDARY,
|
|
.oac1.k = 1,
|
|
.oac1.a = 1,
|
|
};
|
|
int cc;
|
|
|
|
while (1) {
|
|
osize = size;
|
|
asm_inline volatile(
|
|
" lr %%r0,%[spec]\n"
|
|
"0: mvcos %[to],%[from],%[size]\n"
|
|
"1: nopr %%r7\n"
|
|
CC_IPM(cc)
|
|
EX_TABLE_UA_MVCOS_TO(0b, 0b)
|
|
EX_TABLE_UA_MVCOS_TO(1b, 0b)
|
|
: CC_OUT(cc, cc), [size] "+d" (size), [to] "=Q" (*(char __user *)to)
|
|
: [spec] "d" (spec.val), [from] "Q" (*(const char *)from)
|
|
: CC_CLOBBER_LIST("memory", "0"));
|
|
if (CC_TRANSFORM(cc) == 0)
|
|
return osize - size;
|
|
size -= 4096;
|
|
to += 4096;
|
|
from += 4096;
|
|
}
|
|
}
|
|
|
|
unsigned long _copy_to_user_key(void __user *to, const void *from,
|
|
unsigned long n, unsigned long key)
|
|
{
|
|
might_fault();
|
|
if (should_fail_usercopy())
|
|
return n;
|
|
instrument_copy_to_user(to, from, n);
|
|
return raw_copy_to_user_key(to, from, n, key);
|
|
}
|
|
EXPORT_SYMBOL(_copy_to_user_key);
|