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

Dmitry V. Levin ldv at altlinux.org
Fri Dec 1 07:17:55 UTC 2017


On Fri, Dec 01, 2017 at 02:45:56PM +0900, Masatake YAMATO wrote:
> * 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

Wouldn't this work on X32 as well?
Let's avoid such ifdefs in the new code.

What I suggest is adding a check, e.g.
AC_CHECK_TYPES([struct kvm_regs],,, [#include <linux/kvm.h>])
to configure.ac and using #ifdef HAVE_STRUCT_KVM_REGS here instead.

> +	struct kvm_regs regs;
> +
> +	if (code == KVM_GET_REGS && entering(tcp))
> +		return 0;
> +
> +	if (umove(tcp, arg, &regs) < 0)
> +		return RVAL_DECODED;

Let's use umove_or_printaddr the same way and for the same reason as
in the previous patch.

> +	PRINT_FIELD_X(", {", regs, rax);

As struct kvm_regs is inherently arch-specific, let's introduce an
arch-specific function, e.g.

static void
arch_print_kvm_regs(struct tcb *const tcp,
		    const kernel_ulong_t addr,
		    const struct kvm_regs *const regs);

linux/*/arch_kvm.c would provide arch-specific decoders,
linux/arch_kvm.c would provide a stub arch_print_kvm_regs that just prints
the address, and this file just includes "arch_kvm.c".


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20171201/0445b7c7/attachment.bin>


More information about the Strace-devel mailing list