linux-loongson/arch/s390/include/asm/skey.h
Heiko Carstens ee417a84d0 s390/skey: Provide infrastructure for executing with non-default access key
The current assumption is that kernel code is always executed with access
key zero, which means that storage key protection does not apply.

However this assumption is not correct: cmpxchg_user_key() may be executed
with a non-zero key; if then the storage key of the page which belongs to
the cmpxchg_user_key() code contains a key with fetch-protection enabled
the result is a protection exception.

For several performance optimizations storage keys are not initialized on
system boot. To keep these optimizations add infrastructure which allows to
define code ranges within functions which are executed with a non-default
key. When such code is executed such functions must explicitly call
skey_regions_initialize().

This will initialize all storage keys belonging to such code ranges in a
way that no protection exceptions happen when the code is executed with a
non-default access key.

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2025-06-29 13:12:02 +02:00

33 lines
725 B
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_SKEY_H
#define __ASM_SKEY_H
#include <asm/rwonce.h>
struct skey_region {
unsigned long start;
unsigned long end;
};
#define SKEY_REGION(_start, _end) \
stringify_in_c(.section .skey_region,"a";) \
stringify_in_c(.balign 8;) \
stringify_in_c(.quad (_start);) \
stringify_in_c(.quad (_end);) \
stringify_in_c(.previous)
extern int skey_regions_initialized;
extern struct skey_region __skey_region_start[];
extern struct skey_region __skey_region_end[];
void __skey_regions_initialize(void);
static inline void skey_regions_initialize(void)
{
if (READ_ONCE(skey_regions_initialized))
return;
__skey_regions_initialize();
}
#endif /* __ASM_SKEY_H */