From: Peter Collingbourne <pcc@google.com> To: Catalin Marinas <catalin.marinas@arm.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Dave Martin <Dave.Martin@arm.com>, Will Deacon <will@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Andrea Arcangeli <aarcange@redhat.com> Cc: Peter Collingbourne <pcc@google.com>, Alistair Delva <adelva@google.com>, Lokesh Gidra <lokeshgidra@google.com>, William McVicker <willmcvicker@google.com>, Evgenii Stepanov <eugenis@google.com>, Mitch Phillips <mitchp@google.com>, Linux ARM <linux-arm-kernel@lists.infradead.org>, linux-mm@kvack.org, Andrey Konovalov <andreyknvl@gmail.com>, stable@vger.kernel.org Subject: [PATCH v3 2/2] selftest: use mmap instead of posix_memalign to allocate memory Date: Fri, 2 Jul 2021 15:57:05 -0700 [thread overview] Message-ID: <20210702225705.2477947-3-pcc@google.com> (raw) In-Reply-To: <20210702225705.2477947-1-pcc@google.com> This test passes pointers obtained from anon_allocate_area to the userfaultfd and mremap APIs. This causes a problem if the system allocator returns tagged pointers because with the tagged address ABI the kernel rejects tagged addresses passed to these APIs, which would end up causing the test to fail. To make this test compatible with such system allocators, stop using the system allocator to allocate memory in anon_allocate_area, and instead just use mmap. Co-developed-by: Lokesh Gidra <lokeshgidra@google.com> Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> Signed-off-by: Peter Collingbourne <pcc@google.com> Fixes: c47174fc362a ("userfaultfd: selftest") Cc: <stable@vger.kernel.org> # 5.4 Link: https://linux-review.googlesource.com/id/Icac91064fcd923f77a83e8e133f8631c5b8fc241 --- tools/testing/selftests/vm/userfaultfd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index f5ab5e0312e7..d0f802053dfd 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -197,8 +197,10 @@ static int anon_release_pages(char *rel_area) static void anon_allocate_area(void **alloc_area) { - if (posix_memalign(alloc_area, page_size, nr_pages * page_size)) { - fprintf(stderr, "out of memory\n"); + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*alloc_area == MAP_FAILED) { + fprintf(stderr, "anon memory mmap failed\n"); *alloc_area = NULL; } } -- 2.32.0.93.g670b81a890-goog
WARNING: multiple messages have this Message-ID (diff)
From: Peter Collingbourne <pcc@google.com> To: Catalin Marinas <catalin.marinas@arm.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Dave Martin <Dave.Martin@arm.com>, Will Deacon <will@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Andrea Arcangeli <aarcange@redhat.com> Cc: Peter Collingbourne <pcc@google.com>, Alistair Delva <adelva@google.com>, Lokesh Gidra <lokeshgidra@google.com>, William McVicker <willmcvicker@google.com>, Evgenii Stepanov <eugenis@google.com>, Mitch Phillips <mitchp@google.com>, Linux ARM <linux-arm-kernel@lists.infradead.org>, linux-mm@kvack.org, Andrey Konovalov <andreyknvl@gmail.com>, stable@vger.kernel.org Subject: [PATCH v3 2/2] selftest: use mmap instead of posix_memalign to allocate memory Date: Fri, 2 Jul 2021 15:57:05 -0700 [thread overview] Message-ID: <20210702225705.2477947-3-pcc@google.com> (raw) In-Reply-To: <20210702225705.2477947-1-pcc@google.com> This test passes pointers obtained from anon_allocate_area to the userfaultfd and mremap APIs. This causes a problem if the system allocator returns tagged pointers because with the tagged address ABI the kernel rejects tagged addresses passed to these APIs, which would end up causing the test to fail. To make this test compatible with such system allocators, stop using the system allocator to allocate memory in anon_allocate_area, and instead just use mmap. Co-developed-by: Lokesh Gidra <lokeshgidra@google.com> Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> Signed-off-by: Peter Collingbourne <pcc@google.com> Fixes: c47174fc362a ("userfaultfd: selftest") Cc: <stable@vger.kernel.org> # 5.4 Link: https://linux-review.googlesource.com/id/Icac91064fcd923f77a83e8e133f8631c5b8fc241 --- tools/testing/selftests/vm/userfaultfd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index f5ab5e0312e7..d0f802053dfd 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -197,8 +197,10 @@ static int anon_release_pages(char *rel_area) static void anon_allocate_area(void **alloc_area) { - if (posix_memalign(alloc_area, page_size, nr_pages * page_size)) { - fprintf(stderr, "out of memory\n"); + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*alloc_area == MAP_FAILED) { + fprintf(stderr, "anon memory mmap failed\n"); *alloc_area = NULL; } } -- 2.32.0.93.g670b81a890-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-07-02 22:57 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-02 22:57 [PATCH v3 0/2] userfaultfd: do not untag user pointers Peter Collingbourne 2021-07-02 22:57 ` Peter Collingbourne 2021-07-02 22:57 ` [PATCH v3 1/2] " Peter Collingbourne 2021-07-02 22:57 ` Peter Collingbourne 2021-07-02 22:57 ` Peter Collingbourne 2021-07-03 2:46 ` kernel test robot 2021-07-03 2:46 ` kernel test robot 2021-07-03 3:06 ` kernel test robot 2021-07-03 3:06 ` kernel test robot 2021-07-03 5:02 ` kernel test robot 2021-07-03 5:02 ` kernel test robot 2021-07-03 9:05 ` kernel test robot 2021-07-03 9:05 ` kernel test robot 2021-07-04 15:39 ` Andrey Konovalov 2021-07-04 15:39 ` Andrey Konovalov 2021-07-04 15:39 ` Andrey Konovalov 2021-07-02 22:57 ` Peter Collingbourne [this message] 2021-07-02 22:57 ` [PATCH v3 2/2] selftest: use mmap instead of posix_memalign to allocate memory Peter Collingbourne 2021-07-02 22:57 ` Peter Collingbourne
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210702225705.2477947-3-pcc@google.com \ --to=pcc@google.com \ --cc=Dave.Martin@arm.com \ --cc=aarcange@redhat.com \ --cc=adelva@google.com \ --cc=akpm@linux-foundation.org \ --cc=andreyknvl@gmail.com \ --cc=catalin.marinas@arm.com \ --cc=eugenis@google.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-mm@kvack.org \ --cc=lokeshgidra@google.com \ --cc=mitchp@google.com \ --cc=stable@vger.kernel.org \ --cc=vincenzo.frascino@arm.com \ --cc=will@kernel.org \ --cc=willmcvicker@google.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.