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

Masatake YAMATO yamato at redhat.com
Fri Dec 1 19:05:29 UTC 2017


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

Change in v2:
* Use umove_or_printaddr instead of umove because umove_or_printaddr
  performs verbose(tcp) check and prints the zero address nicely.
  Suggested by ldv.

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

diff --git a/kvm.c b/kvm.c
index f725f9df..19779c84 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_vcpu(struct tcb *const tcp, const kernel_ulong_t arg)
@@ -42,6 +43,26 @@ 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;
+
+	tprints(", ");
+	if (umove_or_printaddr(tcp, arg, &u_memory_region))
+		return RVAL_IOCTL_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)
 {
@@ -50,6 +71,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 RVAL_DECODED | RVAL_FD;
+	case KVM_SET_USER_MEMORY_REGION:
+		return kvm_ioctl_set_user_memory_region(tcp, arg);
 	case KVM_RUN:
 	case KVM_GET_VCPU_MMAP_SIZE:
 	case KVM_GET_API_VERSION:
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