Commit 5461c662 authored by Ram Pai's avatar Ram Pai Committed by Linus Torvalds

selftests/vm/pkeys: move generic definitions to header file

Moved all the generic definition and helper functions to the
header file.
Signed-off-by: default avatarRam Pai <linuxram@us.ibm.com>
Signed-off-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
Signed-off-by: default avatarSandipan Das <sandipan@linux.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarDave Hansen <dave.hansen@intel.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Suchanek <msuchanek@suse.de>
Cc: Shuah Khan <shuah@kernel.org>
Link: http://lkml.kernel.org/r/57177f99e92a51295956715d5f2d5688a4d13927.1585646528.git.sandipan@linux.ibm.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c4273c7f
...@@ -13,6 +13,14 @@ ...@@ -13,6 +13,14 @@
#include <ucontext.h> #include <ucontext.h>
#include <sys/mman.h> #include <sys/mman.h>
/* Define some kernel-like types */
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define u64 uint64_t
#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)
#define NR_PKEYS 16 #define NR_PKEYS 16
#define PKEY_BITS_PER_PKEY 2 #define PKEY_BITS_PER_PKEY 2
...@@ -53,6 +61,18 @@ static inline void sigsafe_printf(const char *format, ...) ...@@ -53,6 +61,18 @@ static inline void sigsafe_printf(const char *format, ...)
#define dprintf3(args...) dprintf_level(3, args) #define dprintf3(args...) dprintf_level(3, args)
#define dprintf4(args...) dprintf_level(4, args) #define dprintf4(args...) dprintf_level(4, args)
extern void abort_hooks(void);
#define pkey_assert(condition) do { \
if (!(condition)) { \
dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \
__FILE__, __LINE__, \
test_nr, iteration_nr); \
dprintf0("errno at assert: %d", errno); \
abort_hooks(); \
exit(__LINE__); \
} \
} while (0)
extern unsigned int shadow_pkey_reg; extern unsigned int shadow_pkey_reg;
static inline unsigned int __read_pkey_reg(void) static inline unsigned int __read_pkey_reg(void)
{ {
...@@ -137,11 +157,6 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write) ...@@ -137,11 +157,6 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write)
dprintf4("pkey_reg now: %08x\n", read_pkey_reg()); dprintf4("pkey_reg now: %08x\n", read_pkey_reg());
} }
#define PROT_PKEY0 0x10 /* protection key value (bit 0) */
#define PROT_PKEY1 0x20 /* protection key value (bit 1) */
#define PROT_PKEY2 0x40 /* protection key value (bit 2) */
#define PROT_PKEY3 0x80 /* protection key value (bit 3) */
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
#define MB (1<<20) #define MB (1<<20)
...@@ -219,4 +234,14 @@ int pkey_reg_xstate_offset(void) ...@@ -219,4 +234,14 @@ int pkey_reg_xstate_offset(void)
return xstate_offset; return xstate_offset;
} }
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1))
#define ALIGN_DOWN(x, align_to) ((x) & ~((align_to)-1))
#define ALIGN_PTR_UP(p, ptr_align_to) \
((typeof(p))ALIGN_UP((unsigned long)(p), ptr_align_to))
#define ALIGN_PTR_DOWN(p, ptr_align_to) \
((typeof(p))ALIGN_DOWN((unsigned long)(p), ptr_align_to))
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
#endif /* _PKEYS_HELPER_H */ #endif /* _PKEYS_HELPER_H */
...@@ -51,31 +51,10 @@ int test_nr; ...@@ -51,31 +51,10 @@ int test_nr;
unsigned int shadow_pkey_reg; unsigned int shadow_pkey_reg;
#define HPAGE_SIZE (1UL<<21) #define HPAGE_SIZE (1UL<<21)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define ALIGN_UP(x, align_to) (((x) + ((align_to)-1)) & ~((align_to)-1))
#define ALIGN_DOWN(x, align_to) ((x) & ~((align_to)-1))
#define ALIGN_PTR_UP(p, ptr_align_to) ((typeof(p))ALIGN_UP((unsigned long)(p), ptr_align_to))
#define ALIGN_PTR_DOWN(p, ptr_align_to) ((typeof(p))ALIGN_DOWN((unsigned long)(p), ptr_align_to))
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)
int dprint_in_signal; int dprint_in_signal;
char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE];
extern void abort_hooks(void);
#define pkey_assert(condition) do { \
if (!(condition)) { \
dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \
__FILE__, __LINE__, \
test_nr, iteration_nr); \
dprintf0("errno at assert: %d", errno); \
abort_hooks(); \
exit(__LINE__); \
} \
} while (0)
void cat_into_file(char *str, char *file) void cat_into_file(char *str, char *file)
{ {
int fd = open(file, O_RDWR); int fd = open(file, O_RDWR);
...@@ -186,12 +165,6 @@ void lots_o_noops_around_write(int *write_to_me) ...@@ -186,12 +165,6 @@ void lots_o_noops_around_write(int *write_to_me)
dprintf3("%s() done\n", __func__); dprintf3("%s() done\n", __func__);
} }
/* Define some kernel-like types */
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define u64 uint64_t
#ifdef __i386__ #ifdef __i386__
#ifndef SYS_mprotect_key #ifndef SYS_mprotect_key
......
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