Skip to content

Commit 2ceade1

Browse files
committed
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]> Link: https://lore.kernel.org/r/[email protected]
1 parent 18eee7b commit 2ceade1

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

tools/testing/selftests/kvm/lib/x86_64/processor.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -552,38 +552,6 @@ static void vcpu_setup(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
552552
vcpu_sregs_set(vcpu, &sregs);
553553
}
554554

555-
void __vm_xsave_require_permission(int bit, const char *name)
556-
{
557-
int kvm_fd;
558-
u64 bitmask;
559-
long rc;
560-
struct kvm_device_attr attr = {
561-
.group = 0,
562-
.attr = KVM_X86_XCOMP_GUEST_SUPP,
563-
.addr = (unsigned long) &bitmask
564-
};
565-
566-
kvm_fd = open_kvm_dev_path_or_exit();
567-
rc = __kvm_ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);
568-
close(kvm_fd);
569-
570-
if (rc == -1 && (errno == ENXIO || errno == EINVAL))
571-
__TEST_REQUIRE(0, "KVM_X86_XCOMP_GUEST_SUPP not supported");
572-
573-
TEST_ASSERT(rc == 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) error: %ld", rc);
574-
575-
__TEST_REQUIRE(bitmask & (1ULL << bit),
576-
"Required XSAVE feature '%s' not supported", name);
577-
578-
TEST_REQUIRE(!syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit));
579-
580-
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
581-
TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
582-
TEST_ASSERT(bitmask & (1ULL << bit),
583-
"prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
584-
bitmask);
585-
}
586-
587555
void kvm_arch_vm_post_create(struct kvm_vm *vm)
588556
{
589557
vm_create_irqchip(vm);
@@ -705,6 +673,38 @@ uint64_t kvm_get_feature_msr(uint64_t msr_index)
705673
return buffer.entry.data;
706674
}
707675

676+
void __vm_xsave_require_permission(int bit, const char *name)
677+
{
678+
int kvm_fd;
679+
u64 bitmask;
680+
long rc;
681+
struct kvm_device_attr attr = {
682+
.group = 0,
683+
.attr = KVM_X86_XCOMP_GUEST_SUPP,
684+
.addr = (unsigned long) &bitmask
685+
};
686+
687+
kvm_fd = open_kvm_dev_path_or_exit();
688+
rc = __kvm_ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);
689+
close(kvm_fd);
690+
691+
if (rc == -1 && (errno == ENXIO || errno == EINVAL))
692+
__TEST_REQUIRE(0, "KVM_X86_XCOMP_GUEST_SUPP not supported");
693+
694+
TEST_ASSERT(rc == 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) error: %ld", rc);
695+
696+
__TEST_REQUIRE(bitmask & (1ULL << bit),
697+
"Required XSAVE feature '%s' not supported", name);
698+
699+
TEST_REQUIRE(!syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit));
700+
701+
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
702+
TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
703+
TEST_ASSERT(bitmask & (1ULL << bit),
704+
"prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
705+
bitmask);
706+
}
707+
708708
void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid)
709709
{
710710
TEST_ASSERT(cpuid != vcpu->cpuid, "@cpuid can't be the vCPU's CPUID");

0 commit comments

Comments
 (0)