aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/powerpc/include/pkeys.h
diff options
context:
space:
mode:
authorSandipan Das <sandipan@linux.ibm.com>2020-07-27 09:30:36 +0530
committerMichael Ellerman <mpe@ellerman.id.au>2020-07-29 21:02:10 +1000
commit264d7fccc4711328a19f07e6bd57aee4c68803aa (patch)
tree073d8e445862db4d4e910151ee6d47af135d86e9 /tools/testing/selftests/powerpc/include/pkeys.h
parentselftests/powerpc: Move pkey helpers to headers (diff)
downloadlinux-dev-264d7fccc4711328a19f07e6bd57aee4c68803aa.tar.xz
linux-dev-264d7fccc4711328a19f07e6bd57aee4c68803aa.zip
selftests/powerpc: Add pkey helpers for rights
This adds some new pkey-related helper to print access rights of a pkey in the "rwx" format and to generate different valid combinations of pkey rights starting from a given combination. Signed-off-by: Sandipan Das <sandipan@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/6cc1c7d1f686618668a3e090f1d0c2a4cd9dea3f.1595821792.git.sandipan@linux.ibm.com
Diffstat (limited to 'tools/testing/selftests/powerpc/include/pkeys.h')
-rw-r--r--tools/testing/selftests/powerpc/include/pkeys.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/testing/selftests/powerpc/include/pkeys.h b/tools/testing/selftests/powerpc/include/pkeys.h
index 9b53a97e664e..6ba95039a034 100644
--- a/tools/testing/selftests/powerpc/include/pkeys.h
+++ b/tools/testing/selftests/powerpc/include/pkeys.h
@@ -105,4 +105,32 @@ int siginfo_pkey(siginfo_t *si)
#endif
}
+#define pkey_rights(r) ({ \
+ static char buf[4] = "rwx"; \
+ unsigned int amr_bits; \
+ if ((r) & PKEY_DISABLE_EXECUTE) \
+ buf[2] = '-'; \
+ amr_bits = (r) & PKEY_BITS_MASK; \
+ if (amr_bits & PKEY_DISABLE_WRITE) \
+ buf[1] = '-'; \
+ if (amr_bits & PKEY_DISABLE_ACCESS & ~PKEY_DISABLE_WRITE) \
+ buf[0] = '-'; \
+ buf; \
+})
+
+unsigned long next_pkey_rights(unsigned long rights)
+{
+ if (rights == PKEY_DISABLE_ACCESS)
+ return PKEY_DISABLE_EXECUTE;
+ else if (rights == (PKEY_DISABLE_ACCESS | PKEY_DISABLE_EXECUTE))
+ return 0;
+
+ if ((rights & PKEY_BITS_MASK) == 0)
+ rights |= PKEY_DISABLE_WRITE;
+ else if ((rights & PKEY_BITS_MASK) == PKEY_DISABLE_WRITE)
+ rights |= PKEY_DISABLE_ACCESS;
+
+ return rights;
+}
+
#endif /* _SELFTESTS_POWERPC_PKEYS_H */