Skip to content

Commit dd4516a

Browse files
committed
selftests: kvm: move vm_xsave_req_perm call to amx_test
There is no need for tests other than amx_test to enable dynamic xsave states. Remove the call to vm_xsave_req_perm from generic code, and move it inside the test. While at it, allow customizing the bit that is requested, so that future tests can use it differently. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 05a9e06 commit dd4516a

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

tools/testing/selftests/kvm/include/kvm_util_base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
345345
* guest_code - The vCPU's entry point
346346
*/
347347
void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code);
348-
void vm_xsave_req_perm(void);
349348

350349
bool vm_is_unrestricted_guest(struct kvm_vm *vm);
351350

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
458458
struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void);
459459
void vcpu_set_hv_cpuid(struct kvm_vm *vm, uint32_t vcpuid);
460460
struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vm *vm, uint32_t vcpuid);
461+
void vm_xsave_req_perm(int bit);
461462

462463
enum x86_page_size {
463464
X86_PAGE_SIZE_4K = 0,

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
393393
struct kvm_vm *vm;
394394
int i;
395395

396-
#ifdef __x86_64__
397-
/*
398-
* Permission needs to be requested before KVM_SET_CPUID2.
399-
*/
400-
vm_xsave_req_perm();
401-
#endif
402-
403396
/* Force slot0 memory size not small than DEFAULT_GUEST_PHY_PAGES */
404397
if (slot0_mem_pages < DEFAULT_GUEST_PHY_PAGES)
405398
slot0_mem_pages = DEFAULT_GUEST_PHY_PAGES;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,16 +665,16 @@ static bool is_xfd_supported(void)
665665
return !!(eax & CPUID_XFD_BIT);
666666
}
667667

668-
void vm_xsave_req_perm(void)
668+
void vm_xsave_req_perm(int bit)
669669
{
670-
unsigned long bitmask;
670+
u64 bitmask;
671671
long rc;
672672

673673
if (!is_xfd_supported())
674-
return;
674+
exit(KSFT_SKIP);
675+
676+
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit);
675677

676-
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM,
677-
XSTATE_XTILE_DATA_BIT);
678678
/*
679679
* The older kernel version(<5.15) can't support
680680
* ARCH_REQ_XCOMP_GUEST_PERM and directly return.
@@ -684,7 +684,7 @@ void vm_xsave_req_perm(void)
684684

685685
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask);
686686
TEST_ASSERT(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
687-
TEST_ASSERT(bitmask & XFEATURE_XTILE_MASK,
687+
TEST_ASSERT(bitmask & (1ULL << bit),
688688
"prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
689689
bitmask);
690690
}

tools/testing/selftests/kvm/x86_64/amx_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ int main(int argc, char *argv[])
329329
u32 amx_offset;
330330
int stage, ret;
331331

332+
vm_xsave_req_perm(XSTATE_XTILE_DATA_BIT);
333+
332334
/* Create VM */
333335
vm = vm_create_default(VCPU_ID, 0, guest_code);
334336

0 commit comments

Comments
 (0)