All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Ben Gardon <bgardon@google.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
	David Matlack <dmatlack@google.com>,
	Jim Mattson <jmattson@google.com>,
	David Dunn <daviddunn@google.com>,
	Jing Zhang <jingzhangos@google.com>,
	Junaid Shahid <junaids@google.com>
Subject: Re: [PATCH v5 06/10] KVM: selftests: Add NX huge pages test
Date: Wed, 13 Apr 2022 22:35:36 +0000	[thread overview]
Message-ID: <YldQOJjqLJxRz6Ea@google.com> (raw)
In-Reply-To: <20220413175944.71705-7-bgardon@google.com>

On Wed, Apr 13, 2022, Ben Gardon wrote:
> There's currently no test coverage of NX hugepages in KVM selftests, so
> add a basic test to ensure that the feature works as intended.

...

> diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
> new file mode 100644
> index 000000000000..7f80e48781fd
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
> @@ -0,0 +1,166 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * tools/testing/selftests/kvm/nx_huge_page_test.c
> + *
> + * Usage: to be run via nx_huge_page_test.sh, which does the necessary
> + * environment setup and teardown

It would be really nice if this test could either (a) do something useful without
having to manually set /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages,
or (b) refuse to run unless it's (likely) been invoked by the script.  E.g. maybe
add a magic token that must be passed in?  That way just running the bare test
will provide a helpful skip message, but someone that wants to fiddle with it can
still run it manually.

> +int main(int argc, char **argv)
> +{
> +	struct kvm_vm *vm;
> +	struct timespec ts;
> +	void *hva;

This needs to check if the workaround is actually enabled via module param.  Not
as big a deal if there's a magic number, but it's also not too hard to query a
module param.  Or at least, it shouldn't be, I'm fairly certain that's one of the
things I want to address in the selftests overhaul.

Aha! Actually, IIUC, the patch that validates the per-VM override adds full support
for the module param being turned off.

So, how about pull in the tweaks to the expected number to this patch, and then
the per-VM override test just makes disable_nx a logical OR of the module param
beyond off or the test using the per-VM override.

> diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> new file mode 100755
> index 000000000000..19fc95723fcb
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.sh
> @@ -0,0 +1,25 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0-only */
> +
> +# tools/testing/selftests/kvm/nx_huge_page_test.sh
> +# Copyright (C) 2022, Google LLC.

This should either check for root or use sudo.

> +NX_HUGE_PAGES=$(cat /sys/module/kvm/parameters/nx_huge_pages)
> +NX_HUGE_PAGES_RECOVERY_RATIO=$(cat /sys/module/kvm/parameters/nx_huge_pages_recovery_ratio)
> +NX_HUGE_PAGES_RECOVERY_PERIOD=$(cat /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms)
> +HUGE_PAGES=$(cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages)
> +
> +echo 1 > /sys/module/kvm/parameters/nx_huge_pages
> +echo 1 > /sys/module/kvm/parameters/nx_huge_pages_recovery_ratio
> +echo 100 > /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms
> +echo 200 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
> +
> +./nx_huge_pages_test

I would much prefer this find its path and use that to reference the test, e.g. this
fails if invoking the script from anything but the x86_64 subdirectory.  I'd provide
a snippet of how to do that, but my scripting skills are garbage :-)

> +RET=$?
> +
> +echo $NX_HUGE_PAGES > /sys/module/kvm/parameters/nx_huge_pages
> +echo $NX_HUGE_PAGES_RECOVERY_RATIO > /sys/module/kvm/parameters/nx_huge_pages_recovery_ratio
> +echo $NX_HUGE_PAGES_RECOVERY_PERIOD > /sys/module/kvm/parameters/nx_huge_pages_recovery_period_ms
> +echo $HUGE_PAGES > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
> +
> +exit $RET
> -- 
> 2.35.1.1178.g4f1659d476-goog
> 

  reply	other threads:[~2022-04-13 22:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13 17:59 [PATCH v5 00/10] KVM: x86: Add a cap to disable NX hugepages on a VM Ben Gardon
2022-04-13 17:59 ` [PATCH v5 01/10] KVM: selftests: Remove dynamic memory allocation for stats header Ben Gardon
2022-04-13 17:59 ` [PATCH v5 02/10] KVM: selftests: Read binary stats header in lib Ben Gardon
2022-04-13 17:59 ` [PATCH v5 03/10] KVM: selftests: Read binary stats desc " Ben Gardon
2022-04-13 17:59 ` [PATCH v5 04/10] KVM: selftests: Clean up coding style in binary stats test Ben Gardon
2022-04-13 17:59 ` [PATCH v5 05/10] KVM: selftests: Read binary stat data in lib Ben Gardon
2022-04-13 17:59 ` [PATCH v5 06/10] KVM: selftests: Add NX huge pages test Ben Gardon
2022-04-13 22:35   ` Sean Christopherson [this message]
2022-04-14 20:59     ` Ben Gardon
2022-04-14 21:36       ` Sean Christopherson
2022-04-13 17:59 ` [PATCH v5 07/10] KVM: x86: Fix errant brace in KVM capability handling Ben Gardon
2022-04-13 17:59 ` [PATCH v5 08/10] KVM: x86/MMU: Allow NX huge pages to be disabled on a per-vm basis Ben Gardon
2022-04-13 23:03   ` Sean Christopherson
2022-04-13 17:59 ` [PATCH v5 09/10] KVM: selftests: Factor out calculation of pages needed for a VM Ben Gardon
2022-04-13 17:59 ` [PATCH v5 10/10] KVM: selftests: Test disabling NX hugepages on " Ben Gardon
2022-04-13 22:48   ` Sean Christopherson
2022-04-14 21:14     ` Ben Gardon
2022-04-14 22:29       ` Sean Christopherson
2022-04-13 21:21 ` [PATCH v5 00/10] KVM: x86: Add a cap to disable " David Matlack

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=YldQOJjqLJxRz6Ea@google.com \
    --to=seanjc@google.com \
    --cc=bgardon@google.com \
    --cc=daviddunn@google.com \
    --cc=dmatlack@google.com \
    --cc=jingzhangos@google.com \
    --cc=jmattson@google.com \
    --cc=junaids@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.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.