@@ -756,6 +756,26 @@ The *KVMI_EVENT_TRAP* event will be sent with the effective injected expection.
* -KVM_EBUSY - another *KVMI_VCPU_INJECT_EXCEPTION*-*KVMI_EVENT_TRAP* pair
is in progress
+16. KVMI_VM_GET_MAX_GFN
+-----------------------
+
+:Architecture: all
+:Versions: >= 1
+:Parameters: none
+:Returns:
+
+::
+
+ struct kvmi_error_code;
+ struct kvmi_vm_get_max_gfn_reply {
+ __u64 gfn;
+ };
+
+Provides the maximum GFN allocated to the VM by walking through all
+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.
+
Events
======
@@ -34,6 +34,8 @@ enum {
KVMI_VCPU_CONTROL_CR = 15,
KVMI_VCPU_INJECT_EXCEPTION = 16,
+ KVMI_VM_GET_MAX_GFN = 17,
+
KVMI_NUM_MESSAGES
};
@@ -140,6 +142,10 @@ struct kvmi_vcpu_control_events {
__u32 padding2;
};
+struct kvmi_vm_get_max_gfn_reply {
+ __u64 gfn;
+};
+
struct kvmi_event {
__u16 size;
__u16 vcpu;
@@ -1232,6 +1232,17 @@ static void test_cmd_vcpu_inject_exception(struct kvm_vm *vm)
disable_vcpu_event(vm, KVMI_EVENT_BREAKPOINT);
}
+static void test_cmd_vm_get_max_gfn(void)
+{
+ struct kvmi_vm_get_max_gfn_reply rpl;
+ struct kvmi_msg_hdr req;
+
+ test_vm_command(KVMI_VM_GET_MAX_GFN, &req, sizeof(req),
+ &rpl, sizeof(rpl));
+
+ DEBUG("max_gfn: 0x%llx\n", rpl.gfn);
+}
+
static void test_introspection(struct kvm_vm *vm)
{
srandom(time(0));
@@ -1256,6 +1267,7 @@ static void test_introspection(struct kvm_vm *vm)
test_event_breakpoint(vm);
test_cmd_vcpu_control_cr(vm);
test_cmd_vcpu_inject_exception(vm);
+ test_cmd_vm_get_max_gfn();
unhook_introspection(vm);
}
@@ -26,6 +26,7 @@ static const char *const msg_IDs[] = {
[KVMI_VM_CHECK_EVENT] = "KVMI_VM_CHECK_EVENT",
[KVMI_VM_CONTROL_EVENTS] = "KVMI_VM_CONTROL_EVENTS",
[KVMI_VM_GET_INFO] = "KVMI_VM_GET_INFO",
+ [KVMI_VM_GET_MAX_GFN] = "KVMI_VM_GET_MAX_GFN",
[KVMI_VM_READ_PHYSICAL] = "KVMI_VM_READ_PHYSICAL",
[KVMI_VM_WRITE_PHYSICAL] = "KVMI_VM_WRITE_PHYSICAL",
[KVMI_VCPU_CONTROL_CR] = "KVMI_VCPU_CONTROL_CR",
@@ -348,6 +349,18 @@ static int handle_pause_vcpu(struct kvm_introspection *kvmi,
return kvmi_msg_vm_reply(kvmi, msg, err, NULL, 0);
}
+static int handle_vm_get_max_gfn(struct kvm_introspection *kvmi,
+ const struct kvmi_msg_hdr *msg,
+ const void *req)
+{
+ struct kvmi_vm_get_max_gfn_reply rpl;
+
+ memset(&rpl, 0, sizeof(rpl));
+ rpl.gfn = kvm_get_max_gfn(kvmi->kvm);
+
+ return kvmi_msg_vm_reply(kvmi, msg, 0, &rpl, sizeof(rpl));
+}
+
/*
* These commands are executed by the receiving thread/worker.
*/
@@ -358,6 +371,7 @@ static int(*const msg_vm[])(struct kvm_introspection *,
[KVMI_VM_CHECK_EVENT] = handle_check_event,
[KVMI_VM_CONTROL_EVENTS] = handle_vm_control_events,
[KVMI_VM_GET_INFO] = handle_get_info,
+ [KVMI_VM_GET_MAX_GFN] = handle_vm_get_max_gfn,
[KVMI_VM_READ_PHYSICAL] = handle_read_physical,
[KVMI_VM_WRITE_PHYSICAL] = handle_write_physical,
[KVMI_VCPU_PAUSE] = handle_pause_vcpu,