2022-11-28 23:16:24

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH v2 0/4] KVM: selftests: AMX test fix and cleanups

Fix a bug in the AMX test introduced by moving to kvm_cpu_has() for
X86_FEATURE_XFD, and clean up the related code. The fix and cleanups
all revolve around ARCH_REQ_XCOMP_GUEST_PERM impacting the output of
KVM_GET_SUPPORTED_CPUID, and thus causing problems for selftest's
caching of KVM's supported CPUID.

Lei Wang, I adjusted your Author and SOB tags to drop the comma, which I
think? violates that "use your real name" rule, and use formatting from
patches you've sent in the past[*]. Let me know if that's ok (or not).

[*] https://lore.kernel.org/all/[email protected]

Lei Wang (1):
KVM: selftests: Move XFD CPUID checking out of
__vm_xsave_require_permission()

Sean Christopherson (3):
KVM: selftests: Move __vm_xsave_require_permission() below CPUID
helpers
KVM: selftests: Disallow "get supported CPUID" before
REQ_XCOMP_GUEST_PERM
KVM: selftests: Do kvm_cpu_has() checks before creating VM+vCPU

.../selftests/kvm/lib/x86_64/processor.c | 84 ++++++++++---------
tools/testing/selftests/kvm/x86_64/amx_test.c | 11 ++-
2 files changed, 52 insertions(+), 43 deletions(-)


base-commit: 519c2002cd92bdc37c8412ca22cb9c7e7bc48c48
--
2.38.1.584.g0f3c55d4c2-goog


2022-11-28 23:37:39

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH v2 2/4] KVM: selftests: Move __vm_xsave_require_permission() below CPUID helpers

Move __vm_xsave_require_permission() below the CPUID helpers so that a
future change can reference the cached result of KVM_GET_SUPPORTED_CPUID
while keeping the definition of the variable close to its intended user,
kvm_get_supported_cpuid().

No functional change intended.

Signed-off-by: Sean Christopherson <[email protected]>
---
.../selftests/kvm/lib/x86_64/processor.c | 64 +++++++++----------
1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index aac7b32a794b..23067465c035 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -552,38 +552,6 @@ static void vcpu_setup(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
vcpu_sregs_set(vcpu, &sregs);
}

-void __vm_xsave_require_permission(int bit, const char *name)
-{
- int kvm_fd;
- u64 bitmask;
- long rc;
- struct kvm_device_attr attr = {
- .group = 0,
- .attr = KVM_X86_XCOMP_GUEST_SUPP,
- .addr = (unsigned long) &bitmask
- };
-
- kvm_fd = open_kvm_dev_path_or_exit();
- rc = __kvm_ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);
- close(kvm_fd);
-
- if (rc == -1 && (errno == ENXIO || errno == EINVAL))
- __TEST_REQUIRE(0, "KVM_X86_XCOMP_GUEST_SUPP not supported");
-
- TEST_ASSERT(rc == 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) error: %ld", rc);
-
- __TEST_REQUIRE(bitmask & (1ULL << bit),
- "Required XSAVE feature '%s' not supported", name);
-
- TEST_REQUIRE(!syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit));
-
- rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
- TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
- TEST_ASSERT(bitmask & (1ULL << bit),
- "prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
- bitmask);
-}
-
void kvm_arch_vm_post_create(struct kvm_vm *vm)
{
vm_create_irqchip(vm);
@@ -705,6 +673,38 @@ uint64_t kvm_get_feature_msr(uint64_t msr_index)
return buffer.entry.data;
}

+void __vm_xsave_require_permission(int bit, const char *name)
+{
+ int kvm_fd;
+ u64 bitmask;
+ long rc;
+ struct kvm_device_attr attr = {
+ .group = 0,
+ .attr = KVM_X86_XCOMP_GUEST_SUPP,
+ .addr = (unsigned long) &bitmask
+ };
+
+ kvm_fd = open_kvm_dev_path_or_exit();
+ rc = __kvm_ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);
+ close(kvm_fd);
+
+ if (rc == -1 && (errno == ENXIO || errno == EINVAL))
+ __TEST_REQUIRE(0, "KVM_X86_XCOMP_GUEST_SUPP not supported");
+
+ TEST_ASSERT(rc == 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) error: %ld", rc);
+
+ __TEST_REQUIRE(bitmask & (1ULL << bit),
+ "Required XSAVE feature '%s' not supported", name);
+
+ TEST_REQUIRE(!syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit));
+
+ rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
+ TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
+ TEST_ASSERT(bitmask & (1ULL << bit),
+ "prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
+ bitmask);
+}
+
void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid)
{
TEST_ASSERT(cpuid != vcpu->cpuid, "@cpuid can't be the vCPU's CPUID");
--
2.38.1.584.g0f3c55d4c2-goog

2022-11-29 02:21:44

by Wang, Lei

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] KVM: selftests: AMX test fix and cleanups


On 11/29/2022 6:57 AM, Sean Christopherson wrote:
> Fix a bug in the AMX test introduced by moving to kvm_cpu_has() for
> X86_FEATURE_XFD, and clean up the related code. The fix and cleanups
> all revolve around ARCH_REQ_XCOMP_GUEST_PERM impacting the output of
> KVM_GET_SUPPORTED_CPUID, and thus causing problems for selftest's
> caching of KVM's supported CPUID.
>
> Lei Wang, I adjusted your Author and SOB tags to drop the comma, which I
> think? violates that "use your real name" rule, and use formatting from
> patches you've sent in the past[*]. Let me know if that's ok (or not).

That's OK, thanks!

> [*] https://lore.kernel.org/all/[email protected]
>
> Lei Wang (1):
> KVM: selftests: Move XFD CPUID checking out of
> __vm_xsave_require_permission()
>
> Sean Christopherson (3):
> KVM: selftests: Move __vm_xsave_require_permission() below CPUID
> helpers
> KVM: selftests: Disallow "get supported CPUID" before
> REQ_XCOMP_GUEST_PERM
> KVM: selftests: Do kvm_cpu_has() checks before creating VM+vCPU
>
> .../selftests/kvm/lib/x86_64/processor.c | 84 ++++++++++---------
> tools/testing/selftests/kvm/x86_64/amx_test.c | 11 ++-
> 2 files changed, 52 insertions(+), 43 deletions(-)
>
>
> base-commit: 519c2002cd92bdc37c8412ca22cb9c7e7bc48c48