lkml.org 
[lkml]   [2023]   [Aug]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 7/7] selftest/mm: ksm_functional_tests: Add PROT_NONE test
On Thu, Aug 03, 2023 at 04:32:08PM +0200, David Hildenbrand wrote:
> Let's test whether merging and unmerging in PROT_NONE areas works as
> expected.
>
> Pass a page protection to mmap_and_merge_range(), which will trigger
> an mprotect() after writing to the pages, but before enabling merging.
>
> Make sure that unsharing works as expected, by performing a ptrace write
> (using /proc/self/mem) and by setting MADV_UNMERGEABLE.
>
> Note that this implicitly tests that ptrace writes in an inaccessible
> (PROT_NONE) mapping work as expected.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>

[...]

> +static void test_prot_none(void)
> +{
> + const unsigned int size = 2 * MiB;
> + char *map;
> + int i;
> +
> + ksft_print_msg("[RUN] %s\n", __func__);
> +
> + map = mmap_and_merge_range(0x11, size, PROT_NONE, false);
> + if (map == MAP_FAILED)
> + goto unmap;
> +
> + /* Store a unique value in each page on one half using ptrace */
> + for (i = 0; i < size / 2; i += pagesize) {
> + lseek(mem_fd, (uintptr_t) map + i, SEEK_SET);
> + if (write(mem_fd, &i, sizeof(size)) != sizeof(size)) {

sizeof(i)? May not matter a huge lot, though..

> + ksft_test_result_fail("ptrace write failed\n");
> + goto unmap;
> + }
> + }

Acked-by: Peter Xu <peterx@redhat.com>

--
Peter Xu

\
 
 \ /
  Last update: 2023-08-03 21:09    [W:0.043 / U:1.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site