提交 7390fb33 编写于 作者: P Paolo Bonzini 提交者: Lin Wang

selftests: kvm: move vm_xsave_req_perm call to amx_test

mainline inclusion
from mainline-v5.17-rc1
commit dd4516ae
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5RQLJ
CVE: NA

Intel-SIG: commit dd4516ae 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: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NLin Wang <lin.x.wang@intel.com>
上级 f57bbcb3
...@@ -256,7 +256,6 @@ struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages, ...@@ -256,7 +256,6 @@ struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages,
* guest_code - The vCPU's entry point * guest_code - The vCPU's entry point
*/ */
void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code); void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code);
void vm_xsave_req_perm(void);
bool vm_is_unrestricted_guest(struct kvm_vm *vm); bool vm_is_unrestricted_guest(struct kvm_vm *vm);
......
...@@ -391,6 +391,8 @@ bool set_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 *ent); ...@@ -391,6 +391,8 @@ bool set_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 *ent);
uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t a3); uint64_t a3);
void vm_xsave_req_perm(int bit);
/* /*
* Basic CPU control in CR0 * Basic CPU control in CR0
*/ */
......
...@@ -595,16 +595,16 @@ static bool is_xfd_supported(void) ...@@ -595,16 +595,16 @@ static bool is_xfd_supported(void)
return !!(eax & CPUID_XFD_BIT); return !!(eax & CPUID_XFD_BIT);
} }
void vm_xsave_req_perm(void) void vm_xsave_req_perm(int bit)
{ {
unsigned long bitmask; u64 bitmask;
long rc; long rc;
if (!is_xfd_supported()) if (!is_xfd_supported())
return; exit(KSFT_SKIP);
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit);
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM,
XSTATE_XTILE_DATA_BIT);
/* /*
* The older kernel version(<5.15) can't support * The older kernel version(<5.15) can't support
* ARCH_REQ_XCOMP_GUEST_PERM and directly return. * ARCH_REQ_XCOMP_GUEST_PERM and directly return.
...@@ -614,7 +614,7 @@ void vm_xsave_req_perm(void) ...@@ -614,7 +614,7 @@ void vm_xsave_req_perm(void)
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask); 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(rc == 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", rc);
TEST_ASSERT(bitmask & XFEATURE_XTILE_MASK, TEST_ASSERT(bitmask & (1ULL << bit),
"prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx", "prctl(ARCH_REQ_XCOMP_GUEST_PERM) failure bitmask=0x%lx",
bitmask); bitmask);
} }
...@@ -627,11 +627,6 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) ...@@ -627,11 +627,6 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
stack_vaddr = vm_vaddr_alloc(vm, DEFAULT_STACK_PGS * getpagesize(), stack_vaddr = vm_vaddr_alloc(vm, DEFAULT_STACK_PGS * getpagesize(),
DEFAULT_GUEST_STACK_VADDR_MIN, 0, 0); DEFAULT_GUEST_STACK_VADDR_MIN, 0, 0);
/*
* Permission needs to be requested before KVM_SET_CPUID2.
*/
vm_xsave_req_perm();
/* Create VCPU */ /* Create VCPU */
vm_vcpu_add(vm, vcpuid); vm_vcpu_add(vm, vcpuid);
vcpu_setup(vm, vcpuid, 0, 0); vcpu_setup(vm, vcpuid, 0, 0);
......
...@@ -342,6 +342,8 @@ int main(int argc, char *argv[]) ...@@ -342,6 +342,8 @@ int main(int argc, char *argv[])
u32 amx_offset; u32 amx_offset;
int stage, ret; int stage, ret;
vm_xsave_req_perm(XSTATE_XTILE_DATA_BIT);
/* Create VM */ /* Create VM */
vm = vm_create_default(VCPU_ID, 0, guest_code); vm = vm_create_default(VCPU_ID, 0, guest_code);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册