All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
	kvm list <kvm@vger.kernel.org>
Subject: Re: [PATCH] KVM: selftests: Skip tests that require EPT when it is not available
Date: Mon, 26 Sep 2022 15:18:22 -0700	[thread overview]
Message-ID: <CALzav=d-4a8yPxPUuHNh1884Z4Pe_0ewMwnunGK_jAAvr9L-vw@mail.gmail.com> (raw)
In-Reply-To: <YzIdfkovobW3w/zk@google.com>

On Mon, Sep 26, 2022 at 2:45 PM Sean Christopherson <seanjc@google.com> wrote:
>
> On Mon, Sep 26, 2022, David Matlack wrote:
> > +bool kvm_vm_has_ept(struct kvm_vm *vm)
> > +{
> > +     struct kvm_vcpu *vcpu;
> > +     uint64_t ctrl;
> > +
> > +     vcpu = list_first_entry(&vm->vcpus, struct kvm_vcpu, list);
> > +     TEST_ASSERT(vcpu, "Cannot determine EPT support without vCPUs.\n");
>
> KVM_GET_MSRS is supported on /dev/kvm for feature MSRs, and is available for
> selftests via kvm_get_feature_msr().

Ack.

>
> > +
> > +     ctrl = vcpu_get_msr(vcpu, MSR_IA32_VMX_TRUE_PROCBASED_CTLS) >> 32;
> > +     if (!(ctrl & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS))
> > +             return false;
> > +
> > +     ctrl = vcpu_get_msr(vcpu, MSR_IA32_VMX_PROCBASED_CTLS2) >> 32;
> > +     return ctrl & SECONDARY_EXEC_ENABLE_EPT;
> > +}
> > +
> >  void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm,
> >                 uint32_t eptp_memslot)
> >  {
> > +     TEST_REQUIRE(kvm_vm_has_ept(vm));
>
> I would much rather this be an assert, i.e. force the test to do TEST_REQUIRE(),
> even if that means duplicate code.  One of the roles of TEST_REQUIRE() is to
> document test requirements.

This gets difficult when you consider dirty_log_perf_test. Users can
use dirty_log_perf_test in nested mode by passing "-n". But
dirty_log_perf_test is an architecture-neutral test, so adding
TEST_REQUIRE() there would require an ifdef, and then gets even more
complicated if we add support for AMD or nested on non-x86
architectures.

One option is to put the TEST_REQUIRE() in the x86-specific
perf_test_setup_ept(), but that is only one level above
prepare_eptp(), so not exactly any better at documenting the
requirement.

Another option is to do nothing and let the test fail if running on
hosts without EPT. I don't like this solution though, because that
means developers and automation would need custom logic to skip
running dirty_log_perf_test with -n depending on the state of the
host. (For context: I typically run all selftests and kvm-unit-tests
against kvm with ept=Y and ept=N.)

At least for vmx_dirty_log_test, the TEST_REQUIRE() could be put in main().

  reply	other threads:[~2022-09-26 22:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 17:14 [PATCH] KVM: selftests: Skip tests that require EPT when it is not available David Matlack
2022-09-26 21:45 ` Sean Christopherson
2022-09-26 22:18   ` David Matlack [this message]
2022-09-26 22:28     ` Sean Christopherson
2022-09-26 22:40       ` David Matlack
2022-09-26 23:57         ` Sean Christopherson
2022-09-27 11:58 ` Paolo Bonzini
2022-09-27 16:54   ` 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='CALzav=d-4a8yPxPUuHNh1884Z4Pe_0ewMwnunGK_jAAvr9L-vw@mail.gmail.com' \
    --to=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@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: 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.