diff mbox series

[v5] selftests/vm: Only run 128TBswitch with 5-level paging

Message ID 20220701104934.413146-1-adam@wowsignal.io (mailing list archive)
State New
Headers show
Series [v5] selftests/vm: Only run 128TBswitch with 5-level paging | expand

Commit Message

Adam Sindelar July 1, 2022, 10:49 a.m. UTC
The test va_128TBswitch.c expects to be able to pass mmap an address hint
and length that cross the address 1<<47. On x86_64, this is not possible
without 5-level page tables, so the test fails.

The test is already only run on 64-bit powerpc and x86_64 archs, but this
patch adds an additional check on x86_64 that skips the test if PG_TABLE_LEVELS
< 5.  There is precedent for checking /proc/config.gz in selftests, e.g. in
selftests/firmware.

Running the tests produces the desired output:

sudo make -C tools/testing/selftests TARGETS=vm run_tests
---------------------------
running ./va_128TBswitch.sh
---------------------------
./va_128TBswitch.sh: PG_TABLE_LEVELS=4, must be >= 5 to run this test
[SKIP]
-------------------------------

Signed-off-by: Adam Sindelar <adam@wowsignal.io>
---
V4 -> V5: Renamed "die" to "fail" (missed the review comment, sorry!)
V3 -> V4: Restrict the check to x86_64
V2 -> V3: Clean up the commit message
V1 -> V2: Variables local, fixed Makefile typo, comment on gzip usage

 tools/testing/selftests/vm/Makefile          |  1 +
 tools/testing/selftests/vm/run_vmtests.sh    |  2 +-
 tools/testing/selftests/vm/va_128TBswitch.sh | 54 ++++++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/vm/va_128TBswitch.sh

Comments

Adam Sindelar July 1, 2022, 10:50 a.m. UTC | #1
On Fri, Jul 01, 2022 at 12:49:34PM +0200, Adam Sindelar wrote:
> The test va_128TBswitch.c expects to be able to pass mmap an address hint
> and length that cross the address 1<<47. On x86_64, this is not possible
> without 5-level page tables, so the test fails.
> 
> The test is already only run on 64-bit powerpc and x86_64 archs, but this
> patch adds an additional check on x86_64 that skips the test if PG_TABLE_LEVELS
> < 5.  There is precedent for checking /proc/config.gz in selftests, e.g. in
> selftests/firmware.
> 
> Running the tests produces the desired output:
> 
> sudo make -C tools/testing/selftests TARGETS=vm run_tests
> ---------------------------
> running ./va_128TBswitch.sh
> ---------------------------
> ./va_128TBswitch.sh: PG_TABLE_LEVELS=4, must be >= 5 to run this test
> [SKIP]
> -------------------------------
> 
> Signed-off-by: Adam Sindelar <adam@wowsignal.io>
> ---
> V4 -> V5: Renamed "die" to "fail" (missed the review comment, sorry!)
> V3 -> V4: Restrict the check to x86_64
> V2 -> V3: Clean up the commit message
> V1 -> V2: Variables local, fixed Makefile typo, comment on gzip usage
> 
>  tools/testing/selftests/vm/Makefile          |  1 +
>  tools/testing/selftests/vm/run_vmtests.sh    |  2 +-
>  tools/testing/selftests/vm/va_128TBswitch.sh | 54 ++++++++++++++++++++
>  3 files changed, 56 insertions(+), 1 deletion(-)
>  create mode 100755 tools/testing/selftests/vm/va_128TBswitch.sh
> 
> diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
> index 44f25acfbeca..6a34209379a4 100644
> --- a/tools/testing/selftests/vm/Makefile
> +++ b/tools/testing/selftests/vm/Makefile
> @@ -93,6 +93,7 @@ TEST_PROGS := run_vmtests.sh
>  
>  TEST_FILES := test_vmalloc.sh
>  TEST_FILES += test_hmm.sh
> +TEST_FILES += va_128TBswitch.sh
>  
>  KSFT_KHDR_INSTALL := 1
>  include ../lib.mk
> diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh
> index 41fce8bea929..27c01c35c7a9 100755
> --- a/tools/testing/selftests/vm/run_vmtests.sh
> +++ b/tools/testing/selftests/vm/run_vmtests.sh
> @@ -151,7 +151,7 @@ if [ $VADDR64 -ne 0 ]; then
>  	run_test ./virtual_address_range
>  
>  	# virtual address 128TB switch test
> -	run_test ./va_128TBswitch
> +	run_test ./va_128TBswitch.sh
>  fi # VADDR64
>  
>  # vmalloc stability smoke test
> diff --git a/tools/testing/selftests/vm/va_128TBswitch.sh b/tools/testing/selftests/vm/va_128TBswitch.sh
> new file mode 100755
> index 000000000000..334d12715ac3
> --- /dev/null
> +++ b/tools/testing/selftests/vm/va_128TBswitch.sh
> @@ -0,0 +1,54 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Copyright (C) 2022 Adam Sindelar (Meta) <adam@wowsignal.io>
> +#
> +# This is a test for mmap behavior with 5-level paging. This script wraps the
> +# real test to check that the kernel is configured to support at least 5
> +# pagetable levels.
> +
> +# 1 means the test failed
> +exitcode=1
> +
> +# Kselftest framework requirement - SKIP code is 4.
> +ksft_skip=4
> +
> +fail()
> +{
> +    echo "$1"
> +    exit $exitcode
> +}
> +
> +check_supported_x86_64()
> +{
> +    local config="/proc/config.gz"
> +    [[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
> +    [[ -f "${config}" ]] || fail "Cannot find kernel config in /proc or /boot"
> +
> +    # gzip -dcfq automatically handles both compressed and plaintext input.
> +    # See man 1 gzip under '-f'.
> +    local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2)
> +
> +    if [[ "${pg_table_levels}" -lt 5 ]]; then
> +        echo "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
> +        exit $ksft_skip
> +    fi
> +}
> +
> +check_test_requirements()
> +{
> +    # The test supports x86_64 and powerpc64. We currently have no useful
> +    # eligibility check for powerpc64, and the test itself will reject other
> +    # architectures.
> +    case `uname -m` in
> +        "x86_64")
> +            check_supported_x86_64
> +        ;;
> +        *)
> +            return 0
> +        ;;
> +    esac
> +}
> +
> +check_test_requirements
> +./va_128TBswitch
> -- 
> 2.35.1
> 

Apologies for sending such a minor revision, but I'd realized I missed
an earlier review comment and wanted to address it.

-Adam
David Vernet July 1, 2022, 2:21 p.m. UTC | #2
On Fri, Jul 01, 2022 at 12:49:34PM +0200, Adam Sindelar wrote:

Hi Adam,

> The test va_128TBswitch.c expects to be able to pass mmap an address hint
> and length that cross the address 1<<47. On x86_64, this is not possible
> without 5-level page tables, so the test fails.
> 
> The test is already only run on 64-bit powerpc and x86_64 archs, but this
> patch adds an additional check on x86_64 that skips the test if PG_TABLE_LEVELS

It looks like checkpatch.pl is complaining about this line being too long:

WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#11:
patch adds an additional check on x86_64 that skips the test if PG_TABLE_LEVELS

> < 5.  There is precedent for checking /proc/config.gz in selftests, e.g. in
> selftests/firmware.
> 
> Running the tests produces the desired output:
> 
> sudo make -C tools/testing/selftests TARGETS=vm run_tests
> ---------------------------
> running ./va_128TBswitch.sh
> ---------------------------
> ./va_128TBswitch.sh: PG_TABLE_LEVELS=4, must be >= 5 to run this test
> [SKIP]
> -------------------------------
> 
> Signed-off-by: Adam Sindelar <adam@wowsignal.io>
> ---
> V4 -> V5: Renamed "die" to "fail" (missed the review comment, sorry!)
> V3 -> V4: Restrict the check to x86_64
> V2 -> V3: Clean up the commit message
> V1 -> V2: Variables local, fixed Makefile typo, comment on gzip usage
> 
>  tools/testing/selftests/vm/Makefile          |  1 +
>  tools/testing/selftests/vm/run_vmtests.sh    |  2 +-
>  tools/testing/selftests/vm/va_128TBswitch.sh | 54 ++++++++++++++++++++
>  3 files changed, 56 insertions(+), 1 deletion(-)
>  create mode 100755 tools/testing/selftests/vm/va_128TBswitch.sh

[...]

> diff --git a/tools/testing/selftests/vm/va_128TBswitch.sh b/tools/testing/selftests/vm/va_128TBswitch.sh
> new file mode 100755
> index 000000000000..334d12715ac3
> --- /dev/null
> +++ b/tools/testing/selftests/vm/va_128TBswitch.sh
> @@ -0,0 +1,54 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Copyright (C) 2022 Adam Sindelar (Meta) <adam@wowsignal.io>
> +#
> +# This is a test for mmap behavior with 5-level paging. This script wraps the
> +# real test to check that the kernel is configured to support at least 5
> +# pagetable levels.
> +
> +# 1 means the test failed
> +exitcode=1
> +
> +# Kselftest framework requirement - SKIP code is 4.
> +ksft_skip=4
> +
> +fail()
> +{
> +    echo "$1"
> +    exit $exitcode
> +}

My apologies for missing this in earlier reviews, but this file should be
updated to use 8-character wide tabs instead of spaces. Please see [0] for
details.

[0] https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation

> +
> +check_supported_x86_64()
> +{
> +    local config="/proc/config.gz"
> +    [[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
> +    [[ -f "${config}" ]] || fail "Cannot find kernel config in /proc or /boot"
> +
> +    # gzip -dcfq automatically handles both compressed and plaintext input.
> +    # See man 1 gzip under '-f'.
> +    local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2)
> +
> +    if [[ "${pg_table_levels}" -lt 5 ]]; then
> +        echo "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
> +        exit $ksft_skip
> +    fi
> +}
> +
> +check_test_requirements()
> +{
> +    # The test supports x86_64 and powerpc64. We currently have no useful
> +    # eligibility check for powerpc64, and the test itself will reject other
> +    # architectures.
> +    case `uname -m` in
> +        "x86_64")
> +            check_supported_x86_64
> +        ;;
> +        *)
> +            return 0
> +        ;;
> +    esac
> +}
> +
> +check_test_requirements
> +./va_128TBswitch
> -- 
> 2.35.1
>
Adam Sindelar July 1, 2022, 4:32 p.m. UTC | #3
On Fri, Jul 01, 2022 at 07:21:13AM -0700, David Vernet wrote:
> On Fri, Jul 01, 2022 at 12:49:34PM +0200, Adam Sindelar wrote:
> 
> Hi Adam,
> 
> > The test va_128TBswitch.c expects to be able to pass mmap an address hint
> > and length that cross the address 1<<47. On x86_64, this is not possible
> > without 5-level page tables, so the test fails.
> > 
> > The test is already only run on 64-bit powerpc and x86_64 archs, but this
> > patch adds an additional check on x86_64 that skips the test if PG_TABLE_LEVELS
> 
> It looks like checkpatch.pl is complaining about this line being too long:
> 
> WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line)
> #11:
> patch adds an additional check on x86_64 that skips the test if PG_TABLE_LEVELS
> 

Fixed in v6, sorry.

> > < 5.  There is precedent for checking /proc/config.gz in selftests, e.g. in
> > selftests/firmware.
> > 
> > Running the tests produces the desired output:
> > 
> > sudo make -C tools/testing/selftests TARGETS=vm run_tests
> > ---------------------------
> > running ./va_128TBswitch.sh
> > ---------------------------
> > ./va_128TBswitch.sh: PG_TABLE_LEVELS=4, must be >= 5 to run this test
> > [SKIP]
> > -------------------------------
> > 
> > Signed-off-by: Adam Sindelar <adam@wowsignal.io>
> > ---
> > V4 -> V5: Renamed "die" to "fail" (missed the review comment, sorry!)
> > V3 -> V4: Restrict the check to x86_64
> > V2 -> V3: Clean up the commit message
> > V1 -> V2: Variables local, fixed Makefile typo, comment on gzip usage
> > 
> >  tools/testing/selftests/vm/Makefile          |  1 +
> >  tools/testing/selftests/vm/run_vmtests.sh    |  2 +-
> >  tools/testing/selftests/vm/va_128TBswitch.sh | 54 ++++++++++++++++++++
> >  3 files changed, 56 insertions(+), 1 deletion(-)
> >  create mode 100755 tools/testing/selftests/vm/va_128TBswitch.sh
> 
> [...]
> 
> > diff --git a/tools/testing/selftests/vm/va_128TBswitch.sh b/tools/testing/selftests/vm/va_128TBswitch.sh
> > new file mode 100755
> > index 000000000000..334d12715ac3
> > --- /dev/null
> > +++ b/tools/testing/selftests/vm/va_128TBswitch.sh
> > @@ -0,0 +1,54 @@
> > +#!/bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# Copyright (C) 2022 Adam Sindelar (Meta) <adam@wowsignal.io>
> > +#
> > +# This is a test for mmap behavior with 5-level paging. This script wraps the
> > +# real test to check that the kernel is configured to support at least 5
> > +# pagetable levels.
> > +
> > +# 1 means the test failed
> > +exitcode=1
> > +
> > +# Kselftest framework requirement - SKIP code is 4.
> > +ksft_skip=4
> > +
> > +fail()
> > +{
> > +    echo "$1"
> > +    exit $exitcode
> > +}
> 
> My apologies for missing this in earlier reviews, but this file should be
> updated to use 8-character wide tabs instead of spaces. Please see [0] for
> details.
> 
> [0] https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation
> 

Ah, sorry, I thought that only applied to C code, but now I see
shellscripts are formatted the same way. I'll fix my editor config.

> > +
> > +check_supported_x86_64()
> > +{
> > +    local config="/proc/config.gz"
> > +    [[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
> > +    [[ -f "${config}" ]] || fail "Cannot find kernel config in /proc or /boot"
> > +
> > +    # gzip -dcfq automatically handles both compressed and plaintext input.
> > +    # See man 1 gzip under '-f'.
> > +    local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2)
> > +
> > +    if [[ "${pg_table_levels}" -lt 5 ]]; then
> > +        echo "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
> > +        exit $ksft_skip
> > +    fi
> > +}
> > +
> > +check_test_requirements()
> > +{
> > +    # The test supports x86_64 and powerpc64. We currently have no useful
> > +    # eligibility check for powerpc64, and the test itself will reject other
> > +    # architectures.
> > +    case `uname -m` in
> > +        "x86_64")
> > +            check_supported_x86_64
> > +        ;;
> > +        *)
> > +            return 0
> > +        ;;
> > +    esac
> > +}
> > +
> > +check_test_requirements
> > +./va_128TBswitch
> > -- 
> > 2.35.1
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index 44f25acfbeca..6a34209379a4 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -93,6 +93,7 @@  TEST_PROGS := run_vmtests.sh
 
 TEST_FILES := test_vmalloc.sh
 TEST_FILES += test_hmm.sh
+TEST_FILES += va_128TBswitch.sh
 
 KSFT_KHDR_INSTALL := 1
 include ../lib.mk
diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh
index 41fce8bea929..27c01c35c7a9 100755
--- a/tools/testing/selftests/vm/run_vmtests.sh
+++ b/tools/testing/selftests/vm/run_vmtests.sh
@@ -151,7 +151,7 @@  if [ $VADDR64 -ne 0 ]; then
 	run_test ./virtual_address_range
 
 	# virtual address 128TB switch test
-	run_test ./va_128TBswitch
+	run_test ./va_128TBswitch.sh
 fi # VADDR64
 
 # vmalloc stability smoke test
diff --git a/tools/testing/selftests/vm/va_128TBswitch.sh b/tools/testing/selftests/vm/va_128TBswitch.sh
new file mode 100755
index 000000000000..334d12715ac3
--- /dev/null
+++ b/tools/testing/selftests/vm/va_128TBswitch.sh
@@ -0,0 +1,54 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2022 Adam Sindelar (Meta) <adam@wowsignal.io>
+#
+# This is a test for mmap behavior with 5-level paging. This script wraps the
+# real test to check that the kernel is configured to support at least 5
+# pagetable levels.
+
+# 1 means the test failed
+exitcode=1
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+fail()
+{
+    echo "$1"
+    exit $exitcode
+}
+
+check_supported_x86_64()
+{
+    local config="/proc/config.gz"
+    [[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
+    [[ -f "${config}" ]] || fail "Cannot find kernel config in /proc or /boot"
+
+    # gzip -dcfq automatically handles both compressed and plaintext input.
+    # See man 1 gzip under '-f'.
+    local pg_table_levels=$(gzip -dcfq "${config}" | grep PGTABLE_LEVELS | cut -d'=' -f 2)
+
+    if [[ "${pg_table_levels}" -lt 5 ]]; then
+        echo "$0: PGTABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
+        exit $ksft_skip
+    fi
+}
+
+check_test_requirements()
+{
+    # The test supports x86_64 and powerpc64. We currently have no useful
+    # eligibility check for powerpc64, and the test itself will reject other
+    # architectures.
+    case `uname -m` in
+        "x86_64")
+            check_supported_x86_64
+        ;;
+        *)
+            return 0
+        ;;
+    esac
+}
+
+check_test_requirements
+./va_128TBswitch