@@ -777,6 +777,37 @@ memory slots allocated by KVM, considering all address spaces indicated
by KVM_ADDRESS_SPACE_NUM. Stricly speaking, the returned value refers
to the first inaccessible GFN, next to the maximum accessible GFN.
+17. KVMI_VCPU_GET_XSAVE
+-----------------------
+
+:Architecture: x86
+:Versions: >= 1
+:Parameters:
+
+::
+
+ struct kvmi_vcpu_hdr;
+
+:Returns:
+
+::
+
+ struct kvmi_error_code;
+ struct kvmi_vcpu_get_xsave_reply {
+ __u32 region[0];
+ };
+
+Returns a buffer containing the XSAVE area. Currently, the size of
+``kvm_xsave`` is used, but it could change. The userspace should get
+the buffer size from the message size (kvmi_msg_hdr.size).
+
+:Errors:
+
+* -KVM_EINVAL - the selected vCPU is invalid
+* -KVM_EINVAL - the padding is not zero
+* -KVM_EAGAIN - the selected vCPU can't be introspected yet
+* -KVM_ENOMEM - there is not enough memory to allocate the reply
+
Events
======
@@ -97,4 +97,8 @@ struct kvmi_vcpu_inject_exception {
__u64 address;
};
+struct kvmi_vcpu_get_xsave_reply {
+ __u32 region[0];
+};
+
#endif /* _UAPI_ASM_X86_KVMI_H */
@@ -701,3 +701,24 @@ void kvmi_xsetbv_event(struct kvm_vcpu *vcpu)
kvmi_put(vcpu->kvm);
}
+
+int kvmi_arch_cmd_vcpu_get_xsave(struct kvm_vcpu *vcpu,
+ struct kvmi_vcpu_get_xsave_reply **dest,
+ size_t *dest_size)
+{
+ struct kvmi_vcpu_get_xsave_reply *rpl = NULL;
+ size_t rpl_size = sizeof(*rpl) + sizeof(struct kvm_xsave);
+ struct kvm_xsave *area;
+
+ rpl = kvmi_msg_alloc_check(rpl_size);
+ if (!rpl)
+ return -KVM_ENOMEM;
+
+ area = (struct kvm_xsave *) rpl->region;
+ kvm_vcpu_ioctl_x86_get_xsave(vcpu, area);
+
+ *dest = rpl;
+ *dest_size = rpl_size;
+
+ return 0;
+}
@@ -36,6 +36,8 @@ enum {
KVMI_VM_GET_MAX_GFN = 17,
+ KVMI_VCPU_GET_XSAVE = 18,
+
KVMI_NUM_MESSAGES
};
@@ -1325,6 +1325,26 @@ static void test_event_xsetbv(struct kvm_vm *vm)
disable_vcpu_event(vm, event_id);
}
+static void test_cmd_vcpu_get_xsave(struct kvm_vm *vm)
+{
+ struct kvm_cpuid_entry2 *entry;
+ struct {
+ struct kvmi_msg_hdr hdr;
+ struct kvmi_vcpu_hdr vcpu_hdr;
+ } req = {};
+ struct kvm_xsave rpl;
+
+ entry = kvm_get_supported_cpuid_entry(1);
+ if (!(entry->ecx & X86_FEATURE_XSAVE)) {
+ DEBUG("XSAVE is not supported, ecx 0x%x, skipping xsave test\n",
+ entry->ecx);
+ return;
+ }
+
+ test_vcpu0_command(vm, KVMI_VCPU_GET_XSAVE, &req.hdr, sizeof(req),
+ &rpl, sizeof(rpl));
+}
+
static void test_introspection(struct kvm_vm *vm)
{
srandom(time(0));
@@ -1351,6 +1371,7 @@ static void test_introspection(struct kvm_vm *vm)
test_cmd_vcpu_inject_exception(vm);
test_cmd_vm_get_max_gfn();
test_event_xsetbv(vm);
+ test_cmd_vcpu_get_xsave(vm);
unhook_introspection(vm);
}
@@ -103,5 +103,8 @@ int kvmi_arch_cmd_vcpu_inject_exception(struct kvm_vcpu *vcpu, u8 vector,
u32 error_code, u64 address);
void kvmi_arch_trap_event(struct kvm_vcpu *vcpu);
void kvmi_arch_inject_exception(struct kvm_vcpu *vcpu);
+int kvmi_arch_cmd_vcpu_get_xsave(struct kvm_vcpu *vcpu,
+ struct kvmi_vcpu_get_xsave_reply **dest,
+ size_t *dest_size);
#endif
@@ -34,6 +34,7 @@ static const char *const msg_IDs[] = {
[KVMI_VCPU_GET_CPUID] = "KVMI_VCPU_GET_CPUID",
[KVMI_VCPU_GET_INFO] = "KVMI_VCPU_GET_INFO",
[KVMI_VCPU_GET_REGISTERS] = "KVMI_VCPU_GET_REGISTERS",
+ [KVMI_VCPU_GET_XSAVE] = "KVMI_VCPU_GET_XSAVE",
[KVMI_VCPU_INJECT_EXCEPTION] = "KVMI_VCPU_INJECT_EXCEPTION",
[KVMI_VCPU_PAUSE] = "KVMI_VCPU_PAUSE",
[KVMI_VCPU_SET_REGISTERS] = "KVMI_VCPU_SET_REGISTERS",
@@ -560,6 +561,21 @@ static int handle_vcpu_inject_exception(const struct kvmi_vcpu_cmd_job *job,
return kvmi_msg_vcpu_reply(job, msg, ec, NULL, 0);
}
+static int handle_vcpu_get_xsave(const struct kvmi_vcpu_cmd_job *job,
+ const struct kvmi_msg_hdr *msg,
+ const void *req)
+{
+ struct kvmi_vcpu_get_xsave_reply *rpl = NULL;
+ size_t rpl_size = 0;
+ int err, ec;
+
+ ec = kvmi_arch_cmd_vcpu_get_xsave(job->vcpu, &rpl, &rpl_size);
+
+ err = kvmi_msg_vcpu_reply(job, msg, ec, rpl, rpl_size);
+ kvmi_msg_free(rpl);
+ return err;
+}
+
/*
* These commands are executed from the vCPU thread. The receiving thread
* passes the messages using a newly allocated 'struct kvmi_vcpu_cmd_job'
@@ -574,6 +590,7 @@ static int(*const msg_vcpu[])(const struct kvmi_vcpu_cmd_job *,
[KVMI_VCPU_GET_CPUID] = handle_get_cpuid,
[KVMI_VCPU_GET_INFO] = handle_get_vcpu_info,
[KVMI_VCPU_GET_REGISTERS] = handle_get_registers,
+ [KVMI_VCPU_GET_XSAVE] = handle_vcpu_get_xsave,
[KVMI_VCPU_INJECT_EXCEPTION] = handle_vcpu_inject_exception,
[KVMI_VCPU_SET_REGISTERS] = handle_set_registers,
};