From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com
Subject: Re: [RFC PATCH v2 3/3] selftests: kvm/x86: Test the flags in MSR filtering / exiting
Date: Thu, 21 Jul 2022 16:21:29 +0000 [thread overview]
Message-ID: <Ytl9CaEZUKMug5oD@google.com> (raw)
In-Reply-To: <CAAAPnDEKS5hrunMg8Q5Gvt=bU81zZD6fMWsfqRJu029JXpvv1w@mail.gmail.com>
On Thu, Jul 21, 2022, Aaron Lewis wrote:
> > > --- a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c
> > > +++ b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c
> > > @@ -734,6 +734,99 @@ static void test_msr_permission_bitmap(void)
> > > kvm_vm_free(vm);
> > > }
> > >
> > > +static void test_results(int rc, const char *scmd, bool expected_success)
> >
> > Rather than pass in "success expected", pass in the actual value and the valid
> > mask. Then you can spit out the problematic value in the assert and be kind to
> > future debuggers.
> >
> > And similarly, make the __vm_ioctl() call here instead of in the "caller" and name
> > this __test_ioctl() (rename as necessary, see below) to show it's relationship with
> > the macro.
>
> The other comments look good. I'll update.
>
> This one is a bit tricky though. I did originally have __vm_ioctl()
> in test_results() (or whatever name it will end up with), but the
> static assert in kvm_do_ioctl() gave me problems. Unless I make
> test_results() a macro, I have to force cmd to a uint64_t or something
> other than a literal, then I get this:
>
> include/kvm_util_base.h:190:39: error: expression in static assertion
> is not constant
> 190 | static_assert(!_IOC_SIZE(cmd) || sizeof(*arg) ==
> _IOC_SIZE(cmd), ""); \
> | ^
> include/kvm_util_base.h:213:9: note: in expansion of macro ‘kvm_do_ioctl’
> 213 | kvm_do_ioctl((vm)->fd, cmd, arg); \
>
> That's not the only problem. In order to pass 'arg' in I would have
> to pass it as a void *, making sizeof(*arg) wrong.
>
> Being that the ioctl call was the first thing I did in that function I
> opted to make it a part of test_ioctl() rather than making
> test_results() a macro.
>
> If only C had templates :)
Eh, what C++ can do with templates, C can usually do with macros :-)
Sans backslashes, I think this can simply be:
#define test_user_exit_msr_ioctl(vm, cmd, arg, val, valid_mask)
({
int r = __vm_ioctl(vm, cmd, arg);
if (val & valid_mask)
TEST_ASSERT(!r, KVM_IOCTL_ERROR(cmd, r));
else
TEST_ASSERT(r == -1 && errno == EINVAL,
"Wanted EINVAL with val = 0x%llx, got rc: %i errno: %i (%s)",
val, r, errno, strerror(errno))
})
It doesn't print "val" when success is expected, but I'm ok with that. Though I
suspect that adding a common macro to print additional info on an unexpected
ioctl() result would be useful for other tests.
prev parent reply other threads:[~2022-07-21 16:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 23:49 [RFC PATCH v2 0/3] MSR filtering / exiting flag cleanup Aaron Lewis
2022-07-19 23:49 ` [RFC PATCH v2 1/3] KVM: x86: Protect the unused bits in the MSR filtering / exiting flags Aaron Lewis
2022-07-20 23:31 ` Sean Christopherson
2022-07-22 15:35 ` Aaron Lewis
2022-07-19 23:49 ` [PATCH v2 2/3] KVM: x86: Add a VALID_MASK for the flags in kvm_msr_filter_range Aaron Lewis
2022-07-19 23:49 ` [RFC PATCH v2 3/3] selftests: kvm/x86: Test the flags in MSR filtering / exiting Aaron Lewis
2022-07-20 23:23 ` Sean Christopherson
2022-07-21 2:28 ` Aaron Lewis
2022-07-21 16:21 ` Sean Christopherson [this message]
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=Ytl9CaEZUKMug5oD@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@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.