From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, linux-kselftest@vger.kernel.org
Cc: Shuah Khan <shuah@kernel.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Andrew Jones <drjones@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] selftests/kvm: add test for KVM_GET_MSR_FEATURE_INDEX_LIST
Date: Wed, 17 Mar 2021 12:25:52 +0100 [thread overview]
Message-ID: <61d11f32-a2da-b593-1c62-bbadc6408215@redhat.com> (raw)
In-Reply-To: <ac3ba1c0-450e-4e24-c2a2-39d037358758@redhat.com>
On 17/03/2021 11:49, Paolo Bonzini wrote:
> On 17/03/21 08:45, Emanuele Giuseppe Esposito wrote:
>> + struct kvm_msr_list features_list;
>> buffer.header.nmsrs = 1;
>> buffer.entry.index = msr_index;
>> + features_list.nmsrs = 1;
>> +
>> kvm_fd = open(KVM_DEV_PATH, O_RDONLY);
>> if (kvm_fd < 0)
>> exit(KSFT_SKIP);
>> + r = ioctl(kvm_fd, KVM_GET_MSR_FEATURE_INDEX_LIST, &features_list);
>> + TEST_ASSERT(r < 0 && r != -E2BIG, "KVM_GET_MSR_FEATURE_INDEX_LIST
>> IOCTL failed,\n"
>> + " rc: %i errno: %i", r, errno);
>
> Careful: because this has nsmrs == 1, you are overwriting an u32 of the
> stack after struct kvm_msr_list. You need to use your own struct
> similar to what is done with "buffer.header" and "buffer.entry".
>
>> r = ioctl(kvm_fd, KVM_GET_MSRS, &buffer.header);
>> TEST_ASSERT(r == 1, "KVM_GET_MSRS IOCTL failed,\n"
>> " rc: %i errno: %i", r, errno);
>>
>
> More in general, this is not a test, but rather a library function used
> to read a single MSR.
>
> If you would like to add a test for KVM_GET_MSR_FEATURE_INDEX_LIST that
> would be very welcome. That would be a new executable. Looking at the
> logic for the ioctl, the main purpose of the test should be:
>
> - check that if features_list.nmsrs is too small it will set the nmsrs
> field and return -E2BIG.
>
> - check that all MSRs returned by KVM_GET_MSR_FEATURE_INDEX_LIST can be
> accessed with KVM_GET_MSRS
>
> So something like this:
>
> set nmsrs to 0 and try the ioctl
> check that it returns -E2BIG and has changed nmsrs
> if nmsrs != 1 {
> set nmsrs to 1 and try the ioctl again
> check that it returns -E2BIG
> }
> malloc a buffer with room for struct kvm_msr_list and nmsrs indices
> set nmsrs in the malloc-ed buffer and try the ioctl again
> for each index
> invoke kvm_get_feature_msr to read it
>
> (The test should also be skipped if KVM does not expose the
> KVM_CAP_GET_MSR_FEATURES capability).
Thank you for the feedback, the title is indeed a little bit misleading.
My idea in this patch was to just add an additional check to all usages
of KVM_GET_MSRS, since KVM_GET_MSR_FEATURE_INDEX_LIST is used only to
probe host capabilities and processor features.
But you are right, a separate test would be better.
Thank you,
Emanuele
next prev parent reply other threads:[~2021-03-17 11:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 7:45 Emanuele Giuseppe Esposito
2021-03-17 10:49 ` Paolo Bonzini
2021-03-17 11:25 ` Emanuele Giuseppe Esposito [this message]
2021-03-17 12:07 ` Andrew Jones
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=61d11f32-a2da-b593-1c62-bbadc6408215@redhat.com \
--to=eesposit@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
--cc=vkuznets@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®