Re: [PATCH V2] selftest/vm: Add test case for mmap across 128TB boundary.

From: Kirill A. Shutemov
Date: Thu Nov 23 2017 - 05:14:30 EST


On Thu, Nov 23, 2017 at 08:33:13AM +0530, Aneesh Kumar K.V wrote:
> From: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
>
> This patch add a self-test that covers a few corner cases of the interface.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx>
> ---
>
> Changes from V1:
> * Add the test to run_vmtests script
>
> tools/testing/selftests/vm/Makefile | 1 +
> tools/testing/selftests/vm/run_vmtests | 11 ++
> tools/testing/selftests/vm/va_128TBswitch.c | 297 ++++++++++++++++++++++++++++
> 3 files changed, 309 insertions(+)
> create mode 100644 tools/testing/selftests/vm/va_128TBswitch.c

Patch with my selftest is already in -tip tree. I think this selftest
should replace it, not add another one.

> diff --git a/tools/testing/selftests/vm/va_128TBswitch.c b/tools/testing/selftests/vm/va_128TBswitch.c
> new file mode 100644
> index 000000000000..2fdb84ab94b1
> --- /dev/null
> +++ b/tools/testing/selftests/vm/va_128TBswitch.c
> @@ -0,0 +1,297 @@
> +/*
> + *
> + * Authors: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> + * Authors: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2.1 of the GNU Lesser General Public License
> + * as published by the Free Software Foundation.

LGPL? Why?

> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + */
> +
> +static int run_test(struct testcase *test, int count)
> +{
> + void *p;
> + int i, ret = 0;
> +
> + for (i = 0; i < count; i++) {
> + struct testcase *t = test + i;
> +
> + p = mmap(t->addr, t->size, PROT_READ | PROT_WRITE, t->flags, -1, 0);
> +
> + printf("%s: %p - ", t->msg, p);
> +
> + if (p == MAP_FAILED) {
> + printf("FAILED\n");
> + ret = 1;
> + continue;
> + }
> +
> + if (t->low_addr_required && p >= (void *)(1UL << 47)) {
> + printf("FAILED\n");
> + ret = 1;
> + } else {
> + /*
> + * Do a dereference of the address returned so that we catch
> + * bugs in page fault handling
> + */
> + *(int *)p = 10;

If we are going to touch memory, maybe not just first page, but whole
range? memset()?

> + printf("OK\n");
> + }
> + if (!t->keep_mapped)
> + munmap(p, t->size);
> + }
> +
> + return ret;
> +}

--
Kirill A. Shutemov