In title: I'd say s/addresses/bounds/
On 09/01/2024 13:04, Chaitanya S Prakash wrote:
From: Amit Daniel Kachhap amit.kachhap@arm.com
Morello uses a compressed capability format which makes it difficult to represent bounds with arbitrary precision. As the corresponding address range of a given memory mapping may not be exactly representable as valid capability bounds, a test to verify that the PCuABI kernel is able to mmap/munmap those addresses has been added.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@arm.com Signed-off-by: Chaitanya S Prakash ChaitanyaS.Prakash@arm.com
tools/testing/selftests/arm64/morello/mmap.c | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/tools/testing/selftests/arm64/morello/mmap.c b/tools/testing/selftests/arm64/morello/mmap.c index cb40bb88b1dd..50e1c8313ecd 100644 --- a/tools/testing/selftests/arm64/morello/mmap.c +++ b/tools/testing/selftests/arm64/morello/mmap.c @@ -552,6 +552,43 @@ TEST(test_brk_check) EXPECT_EQ(retval, -ENOSYS); } +/* test to verify the Cheri unrepresentable address/length */
"CHERI" (all capitals).
+TEST(test_cheri_unrepresentability) +{
- void *ptr1, *ptr2;
- int retval;
- int prot = PROT_READ | PROT_WRITE;
- int flags = MAP_PRIVATE | MAP_ANONYMOUS;
- size_t len;
- unsigned long inc_page = 0;
- /* Use pageshift 16 for 64K pages so as to use as mmap fixed address */
- unsigned long pageshift = 16;
- /* Generate an unrepresentable length/address */
- do {
len = (1 << (pageshift + inc_page++)) + 1;
I suppose pageshift could be directly incremented.
len = __builtin_align_up(len, pagesize);
That seems to be exactly equivalent to adding pagesize to len, instead of adding 1 above.
- } while (len == cheri_representable_length(len));
- /* Create a memory mapping with reserved memory at the end */
- ptr1 = mmap(0, len, prot, flags, -1, 0);
We should at least check the bounds of ptr1. Its length should be cheri_representable_length(len)), and its base aligned according to the alignment mask. Same idea for the second test.
Kevin
- ASSERT_FALSE(IS_ERR_VALUE(ptr1));
- EXPECT_EQ(0, probe_mem_range(ptr1, len, PROBE_MODE_TOUCH | PROBE_MODE_VERIFY));
- /* Create a memory mapping with reserved memory at the front */
- ptr2 = mmap((void *)(uintcap_t)len, len, prot, flags, -1, 0);
- ASSERT_FALSE(IS_ERR_VALUE(ptr2));
- ASSERT_EQ(len, cheri_address_get(ptr2));
- EXPECT_EQ(0, probe_mem_range(ptr2, len, PROBE_MODE_TOUCH | PROBE_MODE_VERIFY));
- retval = munmap(ptr1, len);
- ASSERT_EQ(retval, 0);
- retval = munmap(ptr2, len);
- ASSERT_EQ(retval, 0);
+}
int main(__unused int argc, __unused char **argv, __unused char **envp, struct morello_auxv *auxv) { pagesize = get_pagesize(auxv); @@ -565,5 +602,6 @@ int main(__unused int argc, __unused char **argv, __unused char **envp, struct m test_mremap_bounds_check(); test_permissions(); test_brk_check();
- test_cheri_unrepresentability(); return 0;
}