Rather than using KVM_VCPU_GET_MSR_INDEX_LIST (a poor clone of x86's KVM_GET_MSR_INDEX_LIST), we create a more genericly named ONE_REG discovery mechanism. Which looks like KVM_GET_MSR_INDEX_LIST, except: 1) It's a VCPU ioctl, not a KVM ioctl. 2) The array entries are 64 bits, since they're ONE_REG identifiers. Signed-off-by: Rusty Russell <rusty.russell@xxxxxxxxxx> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index b09438b..e63dbe8 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -457,8 +457,7 @@ Parameters: struct kvm_msrs (in/out) Returns: 0 on success, -1 on error Reads model-specific registers from the vcpu. Supported msr indices can -be obtained using KVM_GET_MSR_INDEX_LIST (x86) or KVM_VCPU_GET_MSR_INDEX_LIST -(arm). +be obtained using KVM_GET_MSR_INDEX_LIST. struct kvm_msrs { __u32 nmsrs; /* number of msrs in entries */ @@ -2007,52 +2006,6 @@ the virtualized real-mode area (VRMA) facility, the kernel will re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.) -4.76 KVM_VCPU_GET_MSR_INDEX_LIST - -Capability: basic -Architectures: arm -Type: vcpu ioctl -Parameters: struct kvm_msr_list (in/out) -Returns: 0 on success; -1 on error -Errors: - E2BIG: the msr index list is too big to fit in the array specified by - the user. - -struct kvm_msr_list { - __u32 nmsrs; /* number of msrs in entries */ - __u32 indices[0]; -}; - -This ioctl returns the guest special registers that are supported, and -is only valid after KVM_ARM_VCPU_INIT has been performed to initialize -the vcpu type and features. It is otherwise the equivalent of the -x86-specific KVM_GET_MSR_INDEX_LIST, for arm's coprocessor registers -and other non-register state. - -The numbering for the indices for coprocesors is simple: the upper 16 -bits are the coprocessor number. If it's > 15, it's something else, -for future expansion. - -Bit 15 indicates a 64-bit register. For 64 bit registers the bottom 4 -bits are CRm, the next 4 are opc1 (just like the MCRR/MRCC instruction -encoding). For 32 bit registers, the bottom 4 bits are CRm, the next -3 are opc2, the next 4 CRn, and the next 3 opc1 (the same order as the -MRC/MCR instruction encoding, but not the same bit positions). - -64-bit coprocessor register: - ...|19 18 17 16|15|14 13 12 11 10 9 8| 7 6 5 4 |3 2 1 0| - ...0 0 | cp num | 1| 0 0 0 0 0 0 0| opc1 | CRm | - -32-bit coprocessor register: - ...|19 18 17 16|15|14|13 12 11|10 9 8 7 |6 5 4 |3 2 1 0| - ...0 0 | cp num | 0| 0| opc1 | CRn | opc2 | CRm | - -Non-coprocessor register: - - | 32 31 30 29 28 27 26 25 24 23 22 21 20|19 18 17 16 15 ... - | < some non-zero value > | ... - - 4.77 KVM_ARM_VCPU_INIT Capability: basic @@ -2072,6 +2025,25 @@ return ENOEXEC for that vcpu. Note that because some registers reflect machine topology, all vcpus should be created before this ioctl is invoked. +4.78 KVM_GET_REG_LIST + +Capability: basic +Architectures: arm +Type: vcpu ioctl +Parameters: struct kvm_reg_list (in/out) +Returns: 0 on success; -1 on error +Errors: + E2BIG: the reg index list is too big to fit in the array specified by + the 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 ------------------------ diff --git a/arch/arm/include/asm/kvm.h b/arch/arm/include/asm/kvm.h index d2a65e4..2a9ae6e 100644 --- a/arch/arm/include/asm/kvm.h +++ b/arch/arm/include/asm/kvm.h @@ -85,10 +85,10 @@ struct kvm_sync_regs { struct kvm_arch_memory_slot { }; -/* for KVM_VCPU_GET_MSR_INDEX_LIST */ -struct kvm_msr_list { - __u64 nmsrs; /* number of msrs in entries */ - __u64 indices[0]; +/* For KVM_VCPU_GET_REG_LIST. */ +struct kvm_reg_list { + __u64 n; /* number of regs */ + __u64 reg[0]; }; /* If you need to interpret the index values, here is the key: */ diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 896e13f..78af73d 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -191,6 +192,9 @@ int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); +unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu); +int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); + /* We do not have shadow page tables, hence the empty hooks */ static inline int kvm_age_hva(struct kvm *kvm, unsigned long hva) { diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 271ea92..d456f7e1 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -779,20 +779,20 @@ long kvm_arch_vcpu_ioctl(struct file *filp, else return kvm_arm_get_reg(vcpu, ®); } - case KVM_VCPU_GET_MSR_INDEX_LIST: { - struct kvm_msr_list __user *user_msr_list = argp; - struct kvm_msr_list msr_list; + case KVM_GET_REG_LIST: { + struct kvm_reg_list __user *user_list = argp; + struct kvm_reg_list reg_list; unsigned n; - if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list)) + if (copy_from_user(®_list, user_list, sizeof reg_list)) return -EFAULT; - n = msr_list.nmsrs; - msr_list.nmsrs = kvm_arm_num_guest_msrs(vcpu); - if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list)) + n = reg_list.n; + reg_list.n = kvm_arm_num_regs(vcpu); + if (copy_to_user(user_list, ®_list, sizeof reg_list)) return -EFAULT; - if (n < msr_list.nmsrs) + if (n < reg_list.n) return -E2BIG; - return kvm_arm_copy_msrindices(vcpu, user_msr_list->indices); + return kvm_arm_copy_reg_indices(vcpu, user_list->reg); } #ifdef CONFIG_KVM_ARM_VGIC case KVM_IRQ_LINE: { diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index 5a0a7e0..4743707 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -878,21 +878,21 @@ static int walk_msrs(struct kvm_vcpu *vcpu, u64 __user *uind) } /** - * kvm_arm_num_guest_msrs - how many registers do we present via KVM_GET_MSR + * kvm_arm_num_regs - how many registers do we present via KVM_GET_ONE_REG * * This is for special registers, particularly cp15. */ -unsigned long kvm_arm_num_guest_msrs(struct kvm_vcpu *vcpu) +unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu) { return ARRAY_SIZE(invariant_cp15) + walk_msrs(vcpu, (u64 __user *)NULL); } /** - * kvm_arm_copy_msrindices - copy a series of coprocessor registers. + * kvm_arm_copy_reg_indices - copy a series of coprocessor registers. * * This is for special registers, particularly cp15. */ -int kvm_arm_copy_msrindices(struct kvm_vcpu *vcpu, u64 __user *uindices) +int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) { unsigned int i; int err; diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 29de90e..4dda11e 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -908,7 +908,7 @@ struct kvm_s390_ucas_mapping { /* VM is being stopped by host */ #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_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) _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm