[PATCH 6/8] kvm: decode the argument for KVM_{SET, GET}_REGS ioctl command

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


* kvm.c (kvm_ioctl): Handle KVM_SET_REGS and KVM_GET_REGES.
(kvm_ioctl_decode_regs): New function.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 kvm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/kvm.c b/kvm.c
index 43746fef..69a8c97a 100644
--- a/kvm.c
+++ b/kvm.c
@@ -72,6 +72,55 @@ kvm_ioctl_set_user_memory_region(struct tcb *const tcp, const kernel_ulong_t arg
 	return RVAL_IOCTL_DECODED;
 }
 
+static int
+kvm_ioctl_decode_regs(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t arg)
+{
+#ifdef X86_64
+	struct kvm_regs regs;
+
+	if (code == KVM_GET_REGS && entering(tcp))
+		return 0;
+
+	if (umove(tcp, arg, &regs) < 0)
+		return RVAL_DECODED;
+
+	PRINT_FIELD_X(", {", regs, rax);
+	if (abbrev(tcp))
+		tprints(", ...");
+	else {
+		PRINT_FIELD_X(", ",  regs, rbx);
+		PRINT_FIELD_X(", ",  regs, rcx);
+		PRINT_FIELD_X(", ",  regs, rdx);
+		PRINT_FIELD_X(", ",  regs, rsi);
+		PRINT_FIELD_X(", ",  regs, rdi);
+	}
+	PRINT_FIELD_X(", ",  regs, rsp);
+	PRINT_FIELD_X(", ",  regs, rbp);
+	if (abbrev(tcp))
+		tprints(", ...");
+	else {
+		PRINT_FIELD_X(", ",  regs, r8);
+		PRINT_FIELD_X(", ",  regs, r9);
+		PRINT_FIELD_X(", ",  regs, r10);
+		PRINT_FIELD_X(", ",  regs, r11);
+		PRINT_FIELD_X(", ",  regs, r12);
+		PRINT_FIELD_X(", ",  regs, r13);
+		PRINT_FIELD_X(", ",  regs, r14);
+		PRINT_FIELD_X(", ",  regs, r15);
+	}
+	PRINT_FIELD_X(", ",  regs, rip);
+
+	/* TODO: we can decode this more */
+	PRINT_FIELD_X(", ",  regs, rflags);
+
+	tprints("}");
+
+	return RVAL_IOCTL_DECODED;
+#else
+	return RVAL_DECODED;
+#endif
+}
+
 int
 kvm_ioctl(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t arg)
 {
@@ -82,6 +131,9 @@ kvm_ioctl(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t a
 		return kvm_ioctl_create_vm(tcp, arg);
 	case KVM_SET_USER_MEMORY_REGION:
 		return kvm_ioctl_set_user_memory_region(tcp, arg);
+	case KVM_SET_REGS:
+	case KVM_GET_REGS:
+		return kvm_ioctl_decode_regs(tcp, code, arg);
 
 	/* Commands not taking any arguments. */
 	case KVM_RUN:
-- 
2.13.6





More information about the Strace-devel mailing list