Re: [PATCH 3/3] KVM: Add KVM_VCPU_GET_REG_LIST/KVM_CAP_REG_LIST.

2012-10-11 Thread Rusty Russell
Marcelo Tosatti mtosa...@redhat.com writes:
 On Wed, Sep 05, 2012 at 05:28:46PM +0930, Rusty Russell wrote:
...
 +struct kvm_reg_list {
 +__u64 n; /* number of registers in reg[] */
 +__u64 reg[0];
 +};

 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 = argp;
 +struct kvm_reg_list reg_list;
 +unsigned n;
 +
 +if (copy_from_user(reg_list, user_list, sizeof reg_list))
 +return -EFAULT;
 +n = reg_list.n;
 +reg_list.n = kvm_arch_num_regs(vcpu);

 The code does not actually support more than 2^32 registers, does it?
 Why __u64 n ?

Well, the interface is simpler, and the alignment issues vanish.

kvm_arch_num_regs could return a 64-bit number in future if we want to
get completely insane :)

Cheers,
Rusty.
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] KVM: Add KVM_VCPU_GET_REG_LIST/KVM_CAP_REG_LIST.

2012-10-10 Thread Marcelo Tosatti
On Wed, Sep 05, 2012 at 05:28:46PM +0930, Rusty Russell wrote:
 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 rusty.russ...@linaro.org
 ---
  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.)
  
  
 +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:
 +  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];
 +};

 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 = argp;
 + struct kvm_reg_list reg_list;
 + unsigned n;
 +
 + if (copy_from_user(reg_list, user_list, sizeof reg_list))
 + return -EFAULT;
 + n = reg_list.n;
 + reg_list.n = kvm_arch_num_regs(vcpu);

The code does not actually support more than 2^32 registers, does it?
Why __u64 n ?


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] KVM: Add KVM_VCPU_GET_REG_LIST/KVM_CAP_REG_LIST.

2012-09-19 Thread Alexander Graf

On 05.09.2012, at 09:58, Rusty Russell wrote:

 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 rusty.russ...@linaro.org

Acked-by: Alexander Graf ag...@suse.de


Alex

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] KVM: Add KVM_VCPU_GET_REG_LIST/KVM_CAP_REG_LIST.

2012-09-05 Thread Rusty Russell
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 rusty.russ...@linaro.org
---
 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.)
 
 
+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:
+  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/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
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -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)
 
 #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];
 };
 
+/* 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 *vcpu);
 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 *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 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 = argp;
+   struct kvm_reg_list reg_list;
+   unsigned n;
+
+   if (copy_from_user(reg_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, reg_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);
@@ -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:
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html