All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
To: Adam Sindelar <adam@wowsignal.io>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Adam Sindelar <adam@wowsignal.io>,
	Adam Sindelar <ats@fb.com>, David Vernet <void@manifault.com>,
	kernel-team@fb.com
Subject: Re: [PATCH v3] selftests/vm: Only run 128TBswitch with 5-level paging
Date: Tue, 28 Jun 2022 20:49:42 +0530	[thread overview]
Message-ID: <874k04hl2p.fsf@linux.ibm.com> (raw)
In-Reply-To: <20220627163912.5581-1-adam@wowsignal.io>

Adam Sindelar <adam@wowsignal.io> writes:

> The test va_128TBswitch.c expects to be able to pass mmap an address hint
> and length that cross the address 1<<47. 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 archs, but this
> patch adds an additional check 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>
> ---
> 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 | 39 ++++++++++++++++++++
>  3 files changed, 41 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 c45e535ff4b8..7860d0969888 100644
> --- a/tools/testing/selftests/vm/Makefile
> +++ b/tools/testing/selftests/vm/Makefile
> @@ -91,6 +91,7 @@ endif
>  TEST_PROGS := run_vmtests.sh
>  
>  TEST_FILES := test_vmalloc.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 a2302b5faaf2..edda7350ccca 100755
> --- a/tools/testing/selftests/vm/run_vmtests.sh
> +++ b/tools/testing/selftests/vm/run_vmtests.sh
> @@ -149,7 +149,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..767a6465b5d2
> --- /dev/null
> +++ b/tools/testing/selftests/vm/va_128TBswitch.sh
> @@ -0,0 +1,39 @@
> +#!/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
> +
> +die()
> +{
> +    echo "$1"
> +    exit $exitcode
> +}
> +
> +check_test_requirements()
> +{
> +    local config="/proc/config.gz"
> +    [[ -f "${config}" ]] || config="/boot/config-$(uname -r)"
> +    [[ -f "${config}" ]] || die "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: PG_TABLE_LEVELS=${pg_table_levels}, must be >= 5 to run this test"
> +        exit $ksft_skip
> +    fi
> +}

This prevent the test from running on powerpc architecture.

$bash -x  ./va_128TBswitch.sh  
+ exitcode=1
+ ksft_skip=4
+ check_test_requirements
+ local config=/proc/config.gz
+ [[ -f /proc/config.gz ]]
+ [[ -f /proc/config.gz ]]
++ gzip -dcfq /proc/config.gz
++ grep PGTABLE_LEVELS
++ cut -d= -f 2
+ local pg_table_levels=4
+ [[ 4 -lt 5 ]]
+ echo './va_128TBswitch.sh: PG_TABLE_LEVELS=4, must be >= 5 to run this test'
./va_128TBswitch.sh: PG_TABLE_LEVELS=4, must be >= 5 to run this test
+ exit 4

Without the patch

:src/linux/tools/testing/selftests/vm$ ./va_128TBswitch
mmap(ADDR_SWITCH_HINT - PAGE_SIZE, PAGE_SIZE): 0x7fffffff0000 - OK
mmap(ADDR_SWITCH_HINT - PAGE_SIZE, (2 * PAGE_SIZE)): 0x763910f30000 - OK
mmap(ADDR_SWITCH_HINT, PAGE_SIZE): 0x763910f40000 - OK
mmap(ADDR_SWITCH_HINT, 2 * PAGE_SIZE, MAP_FIXED): 0x800000000000 - OK
mmap(NULL): 0x763910f20000 - OK
mmap(LOW_ADDR): 0x40000000 - OK
mmap(HIGH_ADDR): 0x1000000000000 - OK
mmap(HIGH_ADDR) again: 0xff63910fc0000 - OK
mmap(HIGH_ADDR, MAP_FIXED): 0x1000000000000 - OK
mmap(-1): 0xff63910fa0000 - OK
mmap(-1) again: 0xff63910f80000 - OK
mmap(ADDR_SWITCH_HINT - PAGE_SIZE, PAGE_SIZE): 0x7fffffff0000 - OK
mmap(ADDR_SWITCH_HINT - PAGE_SIZE, 2 * PAGE_SIZE): 0x763910f20000 - OK
mmap(ADDR_SWITCH_HINT - PAGE_SIZE/2 , 2 * PAGE_SIZE): 0x763910f00000 - OK
mmap(ADDR_SWITCH_HINT, PAGE_SIZE): 0x763910ef0000 - OK
mmap(ADDR_SWITCH_HINT, 2 * PAGE_SIZE, MAP_FIXED): 0x800000000000 - OK
> +
> +check_test_requirements
> +./va_128TBswitch
> -- 
> 2.35.1


  reply	other threads:[~2022-06-28 15:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 16:39 [PATCH v3] selftests/vm: Only run 128TBswitch with 5-level paging Adam Sindelar
2022-06-28 15:19 ` Aneesh Kumar K.V [this message]
2022-06-28 15:24   ` Adam Sindelar

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=874k04hl2p.fsf@linux.ibm.com \
    --to=aneesh.kumar@linux.ibm.com \
    --cc=adam@wowsignal.io \
    --cc=akpm@linux-foundation.org \
    --cc=ats@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-mm@kvack.org \
    --cc=void@manifault.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: link
Be 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.