[PATCH 5/8] kvm: decode the argument for KVM_SET_USER_MEMORY_REGION ioctl command

Masatake YAMATO yamato at redhat.com
Fri Dec 1 05:45:55 UTC 2017


* xlat/kvm_mem_flags.in: New file.
* kvm.c (kvm_ioctl): Handle KVM_SET_USER_MEMORY_REGION.
(kvm_ioctl_set_user_memory_region): New function.
(top-level): Include print_fields.h and xlat/kvm_mem_flags.h.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 kvm.c                 | 22 ++++++++++++++++++++++
 xlat/kvm_mem_flags.in |  2 ++
 2 files changed, 24 insertions(+)
 create mode 100644 xlat/kvm_mem_flags.in

diff --git a/kvm.c b/kvm.c
index 1b21dab5..43746fef 100644
--- a/kvm.c
+++ b/kvm.c
@@ -32,6 +32,7 @@
 
 #ifdef HAVE_LINUX_KVM_H
 #include <linux/kvm.h>
+#include "print_fields.h"
 
 static int
 kvm_ioctl_create_vm(struct tcb *const tcp, const kernel_ulong_t arg)
@@ -52,6 +53,25 @@ kvm_ioctl_create_vcpu(struct tcb *const tcp, const kernel_ulong_t arg)
 	return RVAL_IOCTL_DECODED | RVAL_FD;
 }
 
+#include "xlat/kvm_mem_flags.h"
+static int
+kvm_ioctl_set_user_memory_region(struct tcb *const tcp, const kernel_ulong_t arg)
+{
+	struct kvm_userspace_memory_region u_memory_region;
+
+	if (umove(tcp, arg, &u_memory_region) < 0)
+		return RVAL_DECODED;
+
+	PRINT_FIELD_U(", {", u_memory_region, slot);
+	PRINT_FIELD_FLAGS(", ", u_memory_region, flags, kvm_mem_flags,
+			  "KVM_MEM_???");
+	PRINT_FIELD_X(", ", u_memory_region, guest_phys_addr);
+	PRINT_FIELD_U(", ", u_memory_region, memory_size);
+	PRINT_FIELD_X(", ", u_memory_region, userspace_addr);
+
+	return RVAL_IOCTL_DECODED;
+}
+
 int
 kvm_ioctl(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t arg)
 {
@@ -60,6 +80,8 @@ kvm_ioctl(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t a
 		return kvm_ioctl_create_vcpu(tcp, arg);
 	case KVM_CREATE_VM:
 		return kvm_ioctl_create_vm(tcp, arg);
+	case KVM_SET_USER_MEMORY_REGION:
+		return kvm_ioctl_set_user_memory_region(tcp, arg);
 
 	/* Commands not taking any arguments. */
 	case KVM_RUN:
diff --git a/xlat/kvm_mem_flags.in b/xlat/kvm_mem_flags.in
new file mode 100644
index 00000000..82b93ba7
--- /dev/null
+++ b/xlat/kvm_mem_flags.in
@@ -0,0 +1,2 @@
+KVM_MEM_LOG_DIRTY_PAGES	(1 << 0)
+KVM_MEM_READONLY	(1 << 1)
-- 
2.13.6





More information about the Strace-devel mailing list