Commit 4dbdd947 authored by Sandipan Das's avatar Sandipan Das Committed by Linus Torvalds

selftests: vm: pkeys: Use sane types for pkey register

The size of the pkey register can vary across architectures.  This
converts the data type of all its references to u64 in preparation for
multi-arch support.

To keep the definition of the u64 type consistent and remove format
specifier related warnings, __SANE_USERSPACE_TYPES__ is defined as
suggested by Michael Ellerman.
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: "Desnes A. Nunes do Rosario" <desnesn@linux.vnet.ibm.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Ram Pai <linuxram@us.ibm.com>
Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
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/d3e271798455d940e395e56e1ff1e82a31bcb7aa.1585646528.git.sandipan@linux.ibm.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a09160e6
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include <sys/mman.h> #include <sys/mman.h>
/* Define some kernel-like types */ /* Define some kernel-like types */
#define u8 uint8_t #define u8 __u8
#define u16 uint16_t #define u16 __u16
#define u32 uint32_t #define u32 __u32
#define u64 uint64_t #define u64 __u64
#define PTR_ERR_ENOTSUP ((void *)-ENOTSUP) #define PTR_ERR_ENOTSUP ((void *)-ENOTSUP)
...@@ -80,13 +80,14 @@ extern void abort_hooks(void); ...@@ -80,13 +80,14 @@ extern void abort_hooks(void);
#error Architecture not supported #error Architecture not supported
#endif /* arch */ #endif /* arch */
extern unsigned int shadow_pkey_reg; extern u64 shadow_pkey_reg;
static inline unsigned int _read_pkey_reg(int line) static inline u64 _read_pkey_reg(int line)
{ {
unsigned int pkey_reg = __read_pkey_reg(); u64 pkey_reg = __read_pkey_reg();
dprintf4("read_pkey_reg(line=%d) pkey_reg: %x shadow: %x\n", dprintf4("read_pkey_reg(line=%d) pkey_reg: %016llx"
" shadow: %016llx\n",
line, pkey_reg, shadow_pkey_reg); line, pkey_reg, shadow_pkey_reg);
assert(pkey_reg == shadow_pkey_reg); assert(pkey_reg == shadow_pkey_reg);
...@@ -95,15 +96,15 @@ static inline unsigned int _read_pkey_reg(int line) ...@@ -95,15 +96,15 @@ static inline unsigned int _read_pkey_reg(int line)
#define read_pkey_reg() _read_pkey_reg(__LINE__) #define read_pkey_reg() _read_pkey_reg(__LINE__)
static inline void write_pkey_reg(unsigned int pkey_reg) static inline void write_pkey_reg(u64 pkey_reg)
{ {
dprintf4("%s() changing %08x to %08x\n", __func__, dprintf4("%s() changing %016llx to %016llx\n", __func__,
__read_pkey_reg(), pkey_reg); __read_pkey_reg(), pkey_reg);
/* will do the shadow check for us: */ /* will do the shadow check for us: */
read_pkey_reg(); read_pkey_reg();
__write_pkey_reg(pkey_reg); __write_pkey_reg(pkey_reg);
shadow_pkey_reg = pkey_reg; shadow_pkey_reg = pkey_reg;
dprintf4("%s(%08x) pkey_reg: %08x\n", __func__, dprintf4("%s(%016llx) pkey_reg: %016llx\n", __func__,
pkey_reg, __read_pkey_reg()); pkey_reg, __read_pkey_reg());
} }
...@@ -113,7 +114,7 @@ static inline void write_pkey_reg(unsigned int pkey_reg) ...@@ -113,7 +114,7 @@ static inline void write_pkey_reg(unsigned int pkey_reg)
*/ */
static inline void __pkey_access_allow(int pkey, int do_allow) static inline void __pkey_access_allow(int pkey, int do_allow)
{ {
unsigned int pkey_reg = read_pkey_reg(); u64 pkey_reg = read_pkey_reg();
int bit = pkey * 2; int bit = pkey * 2;
if (do_allow) if (do_allow)
...@@ -121,13 +122,13 @@ static inline void __pkey_access_allow(int pkey, int do_allow) ...@@ -121,13 +122,13 @@ static inline void __pkey_access_allow(int pkey, int do_allow)
else else
pkey_reg |= (1<<bit); pkey_reg |= (1<<bit);
dprintf4("pkey_reg now: %08x\n", read_pkey_reg()); dprintf4("pkey_reg now: %016llx\n", read_pkey_reg());
write_pkey_reg(pkey_reg); write_pkey_reg(pkey_reg);
} }
static inline void __pkey_write_allow(int pkey, int do_allow_write) static inline void __pkey_write_allow(int pkey, int do_allow_write)
{ {
long pkey_reg = read_pkey_reg(); u64 pkey_reg = read_pkey_reg();
int bit = pkey * 2 + 1; int bit = pkey * 2 + 1;
if (do_allow_write) if (do_allow_write)
...@@ -136,7 +137,7 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write) ...@@ -136,7 +137,7 @@ static inline void __pkey_write_allow(int pkey, int do_allow_write)
pkey_reg |= (1<<bit); pkey_reg |= (1<<bit);
write_pkey_reg(pkey_reg); write_pkey_reg(pkey_reg);
dprintf4("pkey_reg now: %08x\n", read_pkey_reg()); dprintf4("pkey_reg now: %016llx\n", read_pkey_reg());
} }
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
......
...@@ -53,11 +53,11 @@ static inline void __page_o_noops(void) ...@@ -53,11 +53,11 @@ static inline void __page_o_noops(void)
asm(".rept 512 ; nopl 0x7eeeeeee(%eax) ; .endr"); asm(".rept 512 ; nopl 0x7eeeeeee(%eax) ; .endr");
} }
static inline unsigned int __read_pkey_reg(void) static inline u64 __read_pkey_reg(void)
{ {
unsigned int eax, edx; unsigned int eax, edx;
unsigned int ecx = 0; unsigned int ecx = 0;
unsigned int pkey_reg; unsigned pkey_reg;
asm volatile(".byte 0x0f,0x01,0xee\n\t" asm volatile(".byte 0x0f,0x01,0xee\n\t"
: "=a" (eax), "=d" (edx) : "=a" (eax), "=d" (edx)
...@@ -66,13 +66,13 @@ static inline unsigned int __read_pkey_reg(void) ...@@ -66,13 +66,13 @@ static inline unsigned int __read_pkey_reg(void)
return pkey_reg; return pkey_reg;
} }
static inline void __write_pkey_reg(unsigned int pkey_reg) static inline void __write_pkey_reg(u64 pkey_reg)
{ {
unsigned int eax = pkey_reg; unsigned int eax = pkey_reg;
unsigned int ecx = 0; unsigned int ecx = 0;
unsigned int edx = 0; unsigned int edx = 0;
dprintf4("%s() changing %08x to %08x\n", __func__, dprintf4("%s() changing %016llx to %016llx\n", __func__,
__read_pkey_reg(), pkey_reg); __read_pkey_reg(), pkey_reg);
asm volatile(".byte 0x0f,0x01,0xef\n\t" asm volatile(".byte 0x0f,0x01,0xef\n\t"
: : "a" (eax), "c" (ecx), "d" (edx)); : : "a" (eax), "c" (ecx), "d" (edx));
......
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