Tests which currently use the vDSO find it using getauxval(). However, in
purecap, the pointer to the vDSO in the auxiliary vector is a capability and
therefore cannot be returned as an unsigned long. Replace getauxval() with
getauxptr() when building for purecap to solve this issue.
This patch replicates changes made to the Morello kernel vDSO selftests to
enable testing in purecap. See Morello/Linux/Kernel: ("Add support for purecap
vDSO testing").
Signed-off-by: Aditya Deshpande <aditya.deshpande(a)arm.com>
---
include/parse_vdso.h | 20 ++++++++++++++++++++
libs/libltpvdso/vdso_helpers.c | 4 ++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/include/parse_vdso.h b/include/parse_vdso.h
index 5212fc659..643c773da 100644
--- a/include/parse_vdso.h
+++ b/include/parse_vdso.h
@@ -9,6 +9,10 @@
#include <stdint.h>
+#ifdef HAVE_GETAUXVAL
+# include <sys/auxv.h>
+#endif /* HAVE_GETAUXVAL */
+
/*
* To use this vDSO parser, first call one of the vdso_init_* functions.
* If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR
@@ -38,4 +42,20 @@ extern void *vdso_sym(const char *version, const char *name);
typedef int (*gettime_t)(clockid_t clk_id, void *ts);
void find_clock_gettime_vdso(gettime_t *ptr_vdso_gettime,
gettime_t *ptr_vdso_gettime64);
+
+/*
+ * Under PCuABI, pointers in the auxiliary vector can no longer be represented
+ * as unsigned long as they are now capabilities. Get the capability to the
+ * vDSO using getauxptr() instead, which returns a a capability instead of
+ * unsigned long.
+ */
+static inline uintptr_t get_sysinfo_ehdr()
+{
+#ifdef __CHERI_PURE_CAPABILITY__
+ return (uintptr_t)getauxptr(AT_SYSINFO_EHDR);
+#else
+ return getauxval(AT_SYSINFO_EHDR);
+#endif
+}
+
#endif /* PARSE_VDSO_H__ */
diff --git a/libs/libltpvdso/vdso_helpers.c b/libs/libltpvdso/vdso_helpers.c
index 208c12f65..cb5e01687 100644
--- a/libs/libltpvdso/vdso_helpers.c
+++ b/libs/libltpvdso/vdso_helpers.c
@@ -14,7 +14,7 @@
# include <sys/auxv.h>
#endif /* HAVE_GETAUXVAL */
-static unsigned long sysinfo_ehdr;
+static uintptr_t sysinfo_ehdr;
static void vdso_init(void)
{
@@ -22,7 +22,7 @@ static void vdso_init(void)
if (sysinfo_ehdr)
return;
- sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
+ sysinfo_ehdr = get_sysinfo_ehdr();
if (!sysinfo_ehdr) {
tst_res(TINFO, "Couldn't find AT_SYSINFO_EHDR");
return;
--
2.25.1
Tests which currently use the vDSO find it using getauxval(). However, in
purecap, the pointer to the vDSO in the auxiliary vector is a capability and
therefore cannot be returned as an unsigned long. Replace getauxval() with
getauxptr() when building for purecap to solve this issue.
This patch replicates changes made to the Morello kernel vDSO selftests to
enable testing in purecap. See Morello/Linux/Kernel: ad001738e9c8
("Add support for purecap vDSO testing").
Signed-off-by: Aditya Deshpande <aditya.deshpande(a)arm.com>
---
include/parse_vdso.h | 28 ++++++++++++++++++++++++++++
libs/libltpvdso/vdso_helpers.c | 4 ++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/include/parse_vdso.h b/include/parse_vdso.h
index 5212fc659..43c865cc1 100644
--- a/include/parse_vdso.h
+++ b/include/parse_vdso.h
@@ -9,6 +9,10 @@
#include <stdint.h>
+#ifdef HAVE_GETAUXVAL
+# include <sys/auxv.h>
+#endif /* HAVE_GETAUXVAL */
+
/*
* To use this vDSO parser, first call one of the vdso_init_* functions.
* If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR
@@ -38,4 +42,28 @@ extern void *vdso_sym(const char *version, const char *name);
typedef int (*gettime_t)(clockid_t clk_id, void *ts);
void find_clock_gettime_vdso(gettime_t *ptr_vdso_gettime,
gettime_t *ptr_vdso_gettime64);
+
+/*
+ * Define uintptr_t as a capability in purecap.
+ * When not in purecap, uintptr_t will default to unsigned long.
+ */
+#ifdef __CHERI_PURE_CAPABILITY__
+typedef __uintcap_t uintptr_t;
+#endif
+
+/*
+ * Under PCuABI, pointers in the auxiliary vector can no longer be represented
+ * as unsigned long as they are now capabilities. Get the capability to the
+ * vDSO using getauxptr() instead, which returns a a capability instead of
+ * unsigned long.
+ */
+static inline uintptr_t get_sysinfo_ehdr()
+{
+#ifdef __CHERI_PURE_CAPABILITY__
+ return getauxptr(AT_SYSINFO_EHDR);
+#else
+ return (uintptr_t)getauxval(AT_SYSINFO_EHDR);
+#endif
+}
+
#endif /* PARSE_VDSO_H__ */
diff --git a/libs/libltpvdso/vdso_helpers.c b/libs/libltpvdso/vdso_helpers.c
index 208c12f65..cb5e01687 100644
--- a/libs/libltpvdso/vdso_helpers.c
+++ b/libs/libltpvdso/vdso_helpers.c
@@ -14,7 +14,7 @@
# include <sys/auxv.h>
#endif /* HAVE_GETAUXVAL */
-static unsigned long sysinfo_ehdr;
+static uintptr_t sysinfo_ehdr;
static void vdso_init(void)
{
@@ -22,7 +22,7 @@ static void vdso_init(void)
if (sysinfo_ehdr)
return;
- sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
+ sysinfo_ehdr = get_sysinfo_ehdr();
if (!sysinfo_ehdr) {
tst_res(TINFO, "Couldn't find AT_SYSINFO_EHDR");
return;
--
2.25.1
Looks like we're almost there with the bpf syscall patches on the
linux-morello list[1][2]. So seems like a good time to update the
accompanying LTP tests.
Some of the bpf tests require either CAP_SYS_ADMIN or CAP_BPF, or
enabling unprivileged bpf with:
echo "0" > /proc/sys/kernel/unprivileged_bpf_disabled
Thanks,
Zach
Review branch: https://git.morello-project.org/zdleaf/morello-linux-test-project/-/tree/mo…
Kernel changes: https://git.morello-project.org/zdleaf/linux/-/tree/morello/bpf_v5
[1] https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[2] famous last words
Zachary Leaf (3):
bpf: align tests with PCuABI/uAPI
bpf: add bpf_check_attr test
runtest: add bpf to extended PCuABI syscall list
include/lapi/bpf.h | 354 +++++++++++++-----
runtest/morello_transitional_extended | 13 +
.../kernel/syscalls/bpf/bpf_check_attr.c | 62 +++
testcases/kernel/syscalls/bpf/bpf_common.c | 10 +-
testcases/kernel/syscalls/bpf/bpf_map01.c | 12 +-
testcases/kernel/syscalls/bpf/bpf_prog03.c | 4 +-
6 files changed, 352 insertions(+), 103 deletions(-)
create mode 100644 testcases/kernel/syscalls/bpf/bpf_check_attr.c
--
2.34.1