lkml.org 
[lkml]   [2018]   [Jan]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v10 21/24] selftests/vm: sub-page allocator
    Date
    introduce a new allocator that allocates 4k hardware-pages to back
    64k linux-page. This allocator is only applicable on powerpc.

    Signed-off-by: Ram Pai <linuxram@us.ibm.com>
    ---
    tools/testing/selftests/vm/protection_keys.c | 30 ++++++++++++++++++++++++++
    1 files changed, 30 insertions(+), 0 deletions(-)

    diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c
    index 5783587..ae71dad 100644
    --- a/tools/testing/selftests/vm/protection_keys.c
    +++ b/tools/testing/selftests/vm/protection_keys.c
    @@ -766,6 +766,35 @@ void free_pkey_malloc(void *ptr)
    return ptr;
    }

    +void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
    +{
    +#ifdef __powerpc64__
    + void *ptr;
    + int ret;
    +
    + dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__,
    + size, prot, pkey);
    + pkey_assert(pkey < NR_PKEYS);
    + ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
    + pkey_assert(ptr != (void *)-1);
    +
    + ret = syscall(__NR_subpage_prot, ptr, size, NULL);
    + if (ret) {
    + perror("subpage_perm");
    + return PTR_ERR_ENOTSUP;
    + }
    +
    + ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey);
    + pkey_assert(!ret);
    + record_pkey_malloc(ptr, size);
    +
    + dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr);
    + return ptr;
    +#else /* __powerpc64__ */
    + return PTR_ERR_ENOTSUP;
    +#endif /* __powerpc64__ */
    +}
    +
    void *malloc_pkey_anon_huge(long size, int prot, u16 pkey)
    {
    int ret;
    @@ -888,6 +917,7 @@ void setup_hugetlbfs(void)
    void *(*pkey_malloc[])(long size, int prot, u16 pkey) = {

    malloc_pkey_with_mprotect,
    + malloc_pkey_with_mprotect_subpage,
    malloc_pkey_anon_huge,
    malloc_pkey_hugetlb
    /* can not do direct with the pkey_mprotect() API:
    --
    1.7.1
    \
     
     \ /
      Last update: 2018-01-22 19:55    [W:7.584 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site