From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com,
mizhang@google.com
Subject: Re: [PATCH v3 8/8] KVM: selftests: Add XCR0 Test
Date: Thu, 23 Mar 2023 14:46:57 -0700 [thread overview]
Message-ID: <ZBzI0eTlpJR9A1Xp@google.com> (raw)
In-Reply-To: <20230224223607.1580880-9-aaronlewis@google.com>
On Fri, Feb 24, 2023, Aaron Lewis wrote:
> diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
> index ebe83cfe521c..380daa82b023 100644
> --- a/tools/testing/selftests/kvm/include/x86_64/processor.h
> +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
> @@ -667,6 +667,15 @@ static inline bool this_pmu_has(struct kvm_x86_pmu_feature feature)
> !this_cpu_has(feature.anti_feature);
> }
>
> +static __always_inline uint64_t this_cpu_supported_xcr0(void)
> +{
> + uint32_t a, b, c, d;
> +
> + cpuid(0xd, &a, &b, &c, &d);
> +
> + return a | ((uint64_t)d << 32);
This can be done via X86_PROPERTY. It's not that much prettier, but it at least
avoids open coding things.
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index fa49d51753e5..2bb0ec8dddf3 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -228,8 +228,11 @@ struct kvm_x86_cpu_property {
#define X86_PROPERTY_PMU_NR_GP_COUNTERS KVM_X86_CPU_PROPERTY(0xa, 0, EAX, 8, 15)
#define X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH KVM_X86_CPU_PROPERTY(0xa, 0, EAX, 24, 31)
+#define X86_PROPERTY_SUPPORTED_XCR0_LO KVM_X86_CPU_PROPERTY(0xd, 0, EAX, 0, 31)
#define X86_PROPERTY_XSTATE_MAX_SIZE_XCR0 KVM_X86_CPU_PROPERTY(0xd, 0, EBX, 0, 31)
#define X86_PROPERTY_XSTATE_MAX_SIZE KVM_X86_CPU_PROPERTY(0xd, 0, ECX, 0, 31)
+#define X86_PROPERTY_SUPPORTED_XCR0_HI KVM_X86_CPU_PROPERTY(0xd, 0, EDX, 0, 31)
+
#define X86_PROPERTY_XSTATE_TILE_SIZE KVM_X86_CPU_PROPERTY(0xd, 18, EAX, 0, 31)
#define X86_PROPERTY_XSTATE_TILE_OFFSET KVM_X86_CPU_PROPERTY(0xd, 18, EBX, 0, 31)
#define X86_PROPERTY_AMX_TOTAL_TILE_BYTES KVM_X86_CPU_PROPERTY(0x1d, 1, EAX, 0, 15)
@@ -669,11 +672,11 @@ static inline bool this_pmu_has(struct kvm_x86_pmu_feature feature)
static __always_inline uint64_t this_cpu_supported_xcr0(void)
{
- uint32_t a, b, c, d;
+ if (!this_cpu_has_p(X86_PROPERTY_SUPPORTED_XCR0_LO))
+ return 0;
- cpuid(0xd, &a, &b, &c, &d);
-
- return a | ((uint64_t)d << 32);
+ return this_cpu_property(X86_PROPERTY_SUPPORTED_XCR0_LO) |
+ ((uint64_t)this_cpu_property(X86_PROPERTY_SUPPORTED_XCR0_HI) << 32);
}
typedef u32 __attribute__((vector_size(16))) sse128_t;
> +/* Architectural check. */
If you're going to bother with a comment, might as well actually explain the
architectural rule.
/*
* Assert that architectural dependency rules are satisfied, e.g. that AVX is
* supported if and only if SSE is supported.
*/
> +#define ASSERT_XFEATURE_DEPENDENCIES(supported_xcr0, xfeatures, dependencies) \
> +do { \
> + uint64_t __supported = (supported_xcr0) & ((xfeatures) | (dependencies)); \
> + \
> + GUEST_ASSERT_3((__supported & (xfeatures)) != (xfeatures) || \
> + __supported == ((xfeatures) | (dependencies)), \
> + __supported, (xfeatures), (dependencies)); \
> +} while (0)
> +
> +/*
> + * KVM's own software-defined rules. While not architectural it really
> + * ought to be true.
This should call out what KVM's "rule" is. But it's not really a rule, it's more
of a contract with userspace.
/*
* Assert that KVM reports a sane, usable as-is XCR0. Architecturally, a CPU
* isn't strictly required to _support_ all XFeatures related to a feature, but
* at the same time XSETBV will #GP if bundled XFeatures aren't enabled and
* disabled coherently. E.g. a CPU can technically enumerate supported for
* XTILE_CFG but not XTILE_DATA, but attempt to enable XTILE_CFG without also
* enabling XTILE_DATA will #GP.
*/
> + /* Tell stdout not to buffer its content */
> + setbuf(stdout, NULL);
This copy pasta is no longer necessary, see kvm_selftest_init().
next prev parent reply other threads:[~2023-03-23 21:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 22:35 [PATCH v3 0/8] Clean up the supported xfeatures Aaron Lewis
2023-02-24 22:36 ` [PATCH v3 1/8] KVM: x86: Add kvm_permitted_xcr0() Aaron Lewis
2023-03-03 21:13 ` Mingwei Zhang
2023-02-24 22:36 ` [PATCH v3 2/8] KVM: x86: Clear all supported MPX xfeatures if they are not all set Aaron Lewis
2023-03-03 21:23 ` Mingwei Zhang
2023-03-03 22:23 ` Aaron Lewis
2023-03-07 16:32 ` Mingwei Zhang
2023-03-23 20:29 ` Sean Christopherson
2023-03-23 21:10 ` Mingwei Zhang
2023-03-23 21:16 ` Mingwei Zhang
2023-03-23 21:30 ` Sean Christopherson
2023-03-23 21:29 ` Sean Christopherson
2023-02-24 22:36 ` [PATCH v3 3/8] KVM: x86: Clear all supported AVX-512 " Aaron Lewis
2023-02-24 22:36 ` [PATCH v3 4/8] KVM: x86: Clear AVX-512 xfeatures if SSE or AVX is clear Aaron Lewis
2023-02-24 22:36 ` [PATCH v3 5/8] KVM: x86: Clear all supported AMX xfeatures if they are not all set Aaron Lewis
2023-03-03 21:12 ` Mingwei Zhang
2023-02-24 22:36 ` [PATCH v3 6/8] KVM: selftests: Hoist XGETBV and XSETBV to make them more accessible Aaron Lewis
2023-03-03 21:24 ` Mingwei Zhang
2023-02-24 22:36 ` [PATCH v3 7/8] KVM: selftests: Add XFEATURE masks to common code Aaron Lewis
2023-03-03 21:16 ` Mingwei Zhang
2023-03-03 22:25 ` Aaron Lewis
2023-03-07 16:33 ` Mingwei Zhang
2023-02-24 22:36 ` [PATCH v3 8/8] KVM: selftests: Add XCR0 Test Aaron Lewis
2023-03-02 20:34 ` Mingwei Zhang
2023-03-02 22:50 ` Aaron Lewis
2023-03-03 21:11 ` Mingwei Zhang
2023-03-23 21:46 ` Sean Christopherson [this message]
2023-03-20 15:45 ` [PATCH v3 0/8] Clean up the supported xfeatures Mingwei Zhang
2023-03-23 21:47 ` 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=ZBzI0eTlpJR9A1Xp@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=mizhang@google.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).