From: Rusty Russell Subject: =?UTF-8?q?=5BPATCH=203/3=5D=20KVM=3A=20Add=20KVM=5FVCPU=5FGET=5FREG=5FLIST/KVM=5FCAP=5FREG=5FLIST=2E?= Date: Wed, 5 Sep 2012 17:28:46 +0930 Message-ID: <1346831926-31820-4-git-send-email-rusty.russell@linaro.org> References: <1346831926-31820-1-git-send-email-rusty.russell@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Avi Kivity , Christoffer Dall , Alexander Graf , Peter Maydell , Rusty Russell To: kvm@vger.kernel.org Return-path: Received: from ozlabs.org ([203.10.76.45]:40553 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757396Ab2IEIVz (ORCPT ); Wed, 5 Sep 2012 04:21:55 -0400 In-Reply-To: <1346831926-31820-1-git-send-email-rusty.russell@linaro.org> Sender: kvm-owner@vger.kernel.org List-ID: This is a generic interface to find out what you can use KVM_GET_ONE_REG/KVM_SET_ONE_REG on. Archs need to define KVM_HAVE_REG_LIST and then kvm_arch_num_regs() and kvm_arch_copy_reg_indices() functions. It's inspired by KVM_GET_MSR_INDEX_LIST, except it's a per-vcpu ioctl, and uses 64-bit indices. Signed-off-by: Rusty Russell --- Documentation/virtual/kvm/api.txt | 20 ++++++++++++++++++++ include/linux/kvm.h | 12 ++++++++++++ include/linux/kvm_host.h | 5 ++++- virt/kvm/kvm_main.c | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/= kvm/api.txt index b91bfd4..f30c3d0 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1985,6 +1985,26 @@ the virtualized real-mode area (VRMA) facility, = the kernel will re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.) =20 =20 +4.76 KVM_VCPU_GET_REG_LIST + +Capability: KVM_CAP_REG_LIST +Architectures: all +Type: vcpu ioctl +Parameters: struct kvm_reg_list (in/out) +Returns: 0 on success; -1 on error +Errors: + =C2=A0E2BIG: =C2=A0=C2=A0=C2=A0=C2=A0the reg index list is too big to= fit in the array specified by + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0the user (the number required will be written into n). + +struct kvm_reg_list { + __u64 n; /* number of registers in reg[] */ + __u64 reg[0]; +}; + +This ioctl returns the guest registers that are supported for the +KVM_GET_ONE_REG/KVM_SET_ONE_REG calls. + + 5. The kvm_run structure ------------------------ =20 diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 8c3760e..e839889 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -625,6 +625,7 @@ struct kvm_ppc_smmu_info { #ifdef __KVM_HAVE_READONLY_MEM #define KVM_CAP_READONLY_MEM 81 #endif +#define KVM_CAP_REG_LIST 82 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 @@ -913,6 +914,7 @@ struct kvm_s390_ucas_mapping { #define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg) /* VM is being stopped by host */ #define KVM_KVMCLOCK_CTRL _IO(KVMIO, 0xad) +#define KVM_VCPU_GET_REG_LIST _IOWR(KVMIO, 0xb0, struct kvm_reg_list= ) =20 #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) @@ -964,4 +971,9 @@ struct kvm_assigned_msix_entry { __u16 padding[3]; }; =20 +/* For KVM_VCPU_GET_REG_LIST. */ +struct kvm_reg_list { + __u64 n; /* number of regs */ + __u64 reg[0]; +}; #endif /* __LINUX_KVM_H */ diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2277ff8..d9ee33f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -587,7 +587,10 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcp= u); int kvm_arch_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *= reg); int kvm_arch_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *= reg); #endif - +#ifdef KVM_HAVE_REG_LIST +unsigned long kvm_arch_num_regs(struct kvm_vcpu *vcpu); +int kvm_arch_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indic= es); +#endif void kvm_free_physmem(struct kvm *kvm); =20 void *kvm_kvzalloc(unsigned long size); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 169a001..453fe93 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2082,6 +2082,23 @@ out_free2: break; } #endif +#ifdef KVM_HAVE_REG_LIST + case KVM_VCPU_GET_REG_LIST: { + struct kvm_reg_list __user *user_list =3D argp; + struct kvm_reg_list reg_list; + unsigned n; + + if (copy_from_user(®_list, user_list, sizeof reg_list)) + return -EFAULT; + n =3D reg_list.n; + reg_list.n =3D kvm_arch_num_regs(vcpu); + if (copy_to_user(user_list, ®_list, sizeof reg_list)) + return -EFAULT; + if (n < reg_list.n) + return -E2BIG; + return kvm_arch_copy_reg_indices(vcpu, user_list->reg); + } +#endif =20 default: r =3D kvm_arch_vcpu_ioctl(filp, ioctl, arg); @@ -2397,6 +2414,9 @@ static long kvm_dev_ioctl_check_extension_generic= (long arg) #ifdef KVM_HAVE_ONE_REG case KVM_CAP_ONE_REG: #endif +#ifdef KVM_HAVE_REG_LIST + case KVM_CAP_REG_LIST: +#endif return 1; #ifdef KVM_CAP_IRQ_ROUTING case KVM_CAP_IRQ_ROUTING: --=20 1.7.9.5