[PATCH v3 1/4] kvm: decode the argument for KVM_SET_USER_MEMORY_REGION ioctl command
Masatake YAMATO
yamato at redhat.com
Mon Dec 4 11:28:32 UTC 2017
On Mon, 4 Dec 2017 14:23:14 +0300, "Dmitry V. Levin" <ldv at altlinux.org> wrote:
> On Mon, Dec 04, 2017 at 08:04:49PM +0900, Masatake YAMATO wrote:
>> * configure.ac (AC_CHECK_TYPES): Add struct kvm_userspace_memory_region.
>> * xlat/kvm_mem_flags.in: New file.
>> * kvm.c: Include print_fields.h and xlat/kvm_mem_flags.h.
>> (kvm_ioctl_set_user_memory_region): New function.
>> (kvm_ioctl) <KVM_SET_USER_MEMORY_REGION>: Use it.
>>
>> 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.
>>
>> Change in v3:
>> * Verify the availability struct kvm_userspace_memory_region.
>> Suggested by ldv.
>>
>> Signed-off-by: Masatake YAMATO <yamato at redhat.com>
>> ---
>> configure.ac | 2 ++
>> kvm.c | 27 +++++++++++++++++++++++++++
>> xlat/kvm_mem_flags.in | 2 ++
>> 3 files changed, 31 insertions(+)
>> create mode 100644 xlat/kvm_mem_flags.in
>>
>> diff --git a/configure.ac b/configure.ac
>> index fa451d84..dad995c4 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -541,6 +541,8 @@ AC_CHECK_TYPES([struct statfs64], [
>>
>> AC_CHECK_TYPES([struct blk_user_trace_setup],,, [#include <linux/blktrace_api.h>])
>>
>> +AC_CHECK_TYPES([struct kvm_userspace_memory_region],,, [#include <linux/kvm.h>])
>> +
>> AC_CHECK_HEADERS([linux/btrfs.h], [
>> AC_CHECK_MEMBERS(m4_normalize([
>> struct btrfs_ioctl_feature_flags.compat_flags,
>> diff --git a/kvm.c b/kvm.c
>> index 9e4f9978..8f68aef5 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,12 +43,38 @@ 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)
>> +{
>> +#ifdef HAVE_STRUCT_KVM_USERSPACE_MEMORY_REGION
>> + 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;
>> +#else
>> + return RVAL_DECODED;
>> +#endif
>> +}
>> +
>> int
>> kvm_ioctl(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t arg)
>> {
>> switch (code) {
>> case KVM_CREATE_VCPU:
>> return kvm_ioctl_create_vcpu(tcp, arg);
>> + case KVM_SET_USER_MEMORY_REGION:
>> + return kvm_ioctl_set_user_memory_region(tcp, arg);
>
> If HAVE_STRUCT_KVM_USERSPACE_MEMORY_REGION is not set, then
> KVM_SET_USER_MEMORY_REGION is not available, too,
> and it's use also has to be guarded, e.g.
>
> # ifdef HAVE_STRUCT_KVM_USERSPACE_MEMORY_REGION
> case KVM_SET_USER_MEMORY_REGION:
> return kvm_ioctl_set_user_memory_region(tcp, arg);
> # endif
>
> This allows to move the whole definition
> of kvm_ioctl_set_user_memory_region inside
> HAVE_STRUCT_KVM_USERSPACE_MEMORY_REGION guard, too.
Oh, I see. This will be applicatable the rest ioctl
commands I decoded in the patch set.
O.k. I will make v4 patch set.
Masatake YAMATO
>
> --
> ldv
More information about the Strace-devel
mailing list