On Tue, Aug 28, 2012 at 4:47 PM, Rusty Russell <rusty.russell@xxxxxxxxxx> wrote: > This is a generic interface to find out what you can use > KVM_GET_ONE_REG/KVM_SET_ONE_REG on. Arhs 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 <rusty.russell@xxxxxxxxxx> > > diff --git a/include/linux/kvm.h b/include/linux/kvm.h > index 209b432..b607f60 100644 > --- a/include/linux/kvm.h > +++ b/include/linux/kvm.h > @@ -906,7 +906,7 @@ struct kvm_s390_ucas_mapping { > #define KVM_KVMCLOCK_CTRL _IO(KVMIO, 0xad) > #define KVM_ARM_VCPU_INIT _IOW(KVMIO, 0xae, struct kvm_vcpu_init) > #define KVM_VCPU_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0xaf, struct kvm_msr_list) > +#define KVM_VCPU_GET_REG_LIST _IOWR(KVMIO, 0xb0, struct kvm_reg_list) > > #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) > #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) > @@ -958,4 +958,9 @@ struct kvm_assigned_msix_entry { > __u16 padding[3]; > }; > > +/* 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 f3d43c3..daa3838 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -572,7 +572,10 @@ int kvm_arch_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); > #define KVM_REG_LEN(index) \ > (1U << (((index) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) > #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 *indices); > +#endif > void kvm_free_physmem(struct kvm *kvm); > > void *kvm_kvzalloc(unsigned long size); > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index ad67cf4..b220c74 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1949,6 +1949,23 @@ out_free2: > break; > } > #endif > +#ifdef KVM_HAVE_REG_LIST > + case KVM_VCPU_GET_REG_LIST: { > + struct kvm_reg_list __user *user_list = argp; > + struct kvm_reg_list reg_list; > + unsigned n; > + > + if (copy_from_user(®_list, user_list, sizeof reg_list)) > + return -EFAULT; > + n = reg_list.n; > + reg_list.n = 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 > > default: > r = kvm_arch_vcpu_ioctl(filp, ioctl, arg); looks fine, but don't you need to update the API documentation? -Christoffer -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html