From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com,
like.xu.linux@gmail.com
Subject: Re: [PATCH v3 5/5] KVM: selftests: Test the PMU event "Instructions retired"
Date: Fri, 7 Apr 2023 13:17:29 -0700 [thread overview]
Message-ID: <ZDB6WWhpl6b4/2M9@google.com> (raw)
In-Reply-To: <20230307141400.1486314-6-aaronlewis@google.com>
On Tue, Mar 07, 2023, Aaron Lewis wrote:
> @@ -71,6 +86,16 @@ static const uint64_t event_list[] = {
> AMD_ZEN_BR_RETIRED,
> };
>
> +struct perf_results {
> + union {
> + uint64_t raw;
> + struct {
> + uint64_t br_count:32;
> + uint64_t ir_count:32;
> + };
> + };
> +};
> +
> /*
> * If we encounter a #GP during the guest PMU sanity check, then the guest
> * PMU is not functional. Inform the hypervisor via GUEST_SYNC(0).
> @@ -102,13 +127,20 @@ static void check_msr(uint32_t msr, uint64_t bits_to_flip)
>
> static uint64_t test_guest(uint32_t msr_base)
> {
> + struct perf_results r;
> uint64_t br0, br1;
> + uint64_t ir0, ir1;
>
> br0 = rdmsr(msr_base + 0);
> + ir0 = rdmsr(msr_base + 1);
> __asm__ __volatile__("loop ." : "+c"((int){NUM_BRANCHES}));
> br1 = rdmsr(msr_base + 0);
> + ir1 = rdmsr(msr_base + 1);
>
> - return br1 - br0;
> + r.br_count = br1 - br0;
> + r.ir_count = ir1 - ir0;
The struct+union is problematic on 2+ fronts. I don't like that it truncates
a 64-bit MSR value into a 32-bit field. And this test now ends up with two
structs (perf_results and perf_counter) that serve the same purpose, but count
different events, and without any indiciation in the name _what_ event(s) the
struct tracks.
The existing "struct perf_count" has the same truncation problem. It _shouldn't_
cause problems, but unless I'm missing something, it means that, very theoretically,
the test could have false passes, e.g. if KVM manages to corrupt the upper 32 bits.
There's really no reason to limit ourselves to 64 bits of data, as the selftests
framework provides helpers to copy arbitrary structs to/from the guest. If we
throw all of the counts into a single struct, then we solve the naming issue and
can provide a helper to do the copies to/from the guest.
I have all of this typed up and it appears to work. I'll post a new version of
just the selftests patches.
next prev parent reply other threads:[~2023-04-07 20:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 14:13 [PATCH v3 0/5] Fix "Instructions Retired" from incorrectly counting Aaron Lewis
2023-03-07 14:13 ` [PATCH v3 1/5] KVM: x86/pmu: Prevent the PMU from counting disallowed events Aaron Lewis
2023-03-07 15:19 ` Like Xu
2023-03-07 15:52 ` Aaron Lewis
2023-03-07 16:01 ` Sean Christopherson
2023-03-08 2:45 ` Like Xu
2023-03-08 19:46 ` Sean Christopherson
2023-03-07 14:13 ` [PATCH v3 2/5] KVM: selftests: Add a common helper to the guest Aaron Lewis
2023-04-07 18:43 ` Sean Christopherson
2023-03-07 14:13 ` [PATCH v3 3/5] KVM: selftests: Add helpers for PMC asserts Aaron Lewis
2023-04-07 18:47 ` Sean Christopherson
2023-03-07 14:13 ` [PATCH v3 4/5] KVM: selftests: Fixup test asserts Aaron Lewis
2023-04-07 18:53 ` Sean Christopherson
2023-03-07 14:14 ` [PATCH v3 5/5] KVM: selftests: Test the PMU event "Instructions retired" Aaron Lewis
2023-04-07 20:17 ` Sean Christopherson [this message]
2023-04-07 9:06 ` [PATCH v3 0/5] Fix "Instructions Retired" from incorrectly counting Like Xu
2023-04-07 21:30 ` Sean Christopherson
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=ZDB6WWhpl6b4/2M9@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).