On 06.01.2012, at 04:59, Alexander Graf wrote: > Right now we transfer a static struct every time we want to get or set > registers. Unfortunately, over time we realize that there are more of > these than we thought of before and the extensibility and flexibility of > transferring a full struct every time is limited. > > So this is a new approach to the problem. With these new ioctls, we can > get and set a single register that is identified by an ID. This allows for > very precise and limited transmittal of data. When we later realize that > it's a better idea to shove over multiple registers at once, we can reuse > most of the infrastructure and simply implement a GET_MANY_REGS / SET_MANY_REGS > interface. > > The only downpoint I see to this one is that it needs to pad to 1024 bits > (hardware is already on 512 bit registers, so I wanted to leave some room) > which is slightly too much for transmitting only 64 bits. But if that's all > the tradeoff we have to do for getting an extensible interface, I'd say go > for it nevertheless. > > Signed-off-by: Alexander Graf <agraf@xxxxxxx> > > --- > > v1 -> v2: > > - rename KVM_ONE_REG to KVM_REG > - change semantics to include size in constant > and a user pointer to write/read to/from > - update documentation respectively > --- > Documentation/virtual/kvm/api.txt | 40 +++++++++++++++++++++++++++++ > arch/powerpc/kvm/powerpc.c | 51 +++++++++++++++++++++++++++++++++++++ > include/linux/kvm.h | 35 +++++++++++++++++++++++++ > 3 files changed, 126 insertions(+), 0 deletions(-) > > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt > index a4d7b4d..8494214 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -1523,6 +1523,46 @@ following algorithm: > Some guests configure the LINT1 NMI input to cause a panic, aiding in > debugging. > > +4.65 KVM_SET_ONE_REG > + > +Capability: KVM_CAP_ONE_REG > +Architectures: all > +Type: vcpu ioctl > +Parameters: struct kvm_one_reg (in) > +Returns: 0 on success, negative value on failure > + > +struct kvm_one_reg { > + __u64 id; > + __u64 addr; > +}; > + > +Using this ioctl, a single vcpu register can be set to a specific value > +defined by user space with the passed in struct kvm_one_reg, where id > +refers to the register identifier as described below and addr is a pointer > +to a variable with the respective size. There can be architecture agnostic > +and architecture specific registers. Each have their own range of operation > +and their own constants and width. To keep track of the implemented > +registers, find a list below: > + > + Arch | Register | Width (bits) > + | | > + > +4.66 KVM_GET_ONE_REG > + > +Capability: KVM_CAP_ONE_REG > +Architectures: all > +Type: vcpu ioctl > +Parameters: struct kvm_one_reg (in and out) > +Returns: 0 on success, negative value on failure > + > +This ioctl allows to receive the value of a single register implemented > +in a vcpu. The register to read is indicated by the "id" field of the > +kvm_one_reg struct passed in. On success, the register value can be found > +at the memory location pointed to by "addr". > + > +The list of registers accessible using this interface is identical to the > +list in 4.64. > + > 5. The kvm_run structure > > Application code obtains a pointer to the kvm_run structure by > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index 76993eb..9c598b6 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -214,6 +214,7 @@ int kvm_dev_ioctl_check_extension(long ext) > case KVM_CAP_PPC_UNSET_IRQ: > case KVM_CAP_PPC_IRQ_LEVEL: > case KVM_CAP_ENABLE_CAP: > + case KVM_CAP_ONE_REG: > r = 1; > break; > #ifndef CONFIG_KVM_BOOK3S_64_HV > @@ -642,6 +643,32 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, > return r; > } > > +static int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, > + struct kvm_one_reg *reg) > +{ > + int r = -EINVAL; > + > + switch (reg->id) { > + default: > + break; > + } > + > + return r; > +} > + > +static int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, > + struct kvm_one_reg *reg) > +{ > + int r = -EINVAL; > + > + switch (reg->id) { > + default: > + break; > + } > + > + return r; > +} > + > int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, > struct kvm_mp_state *mp_state) > { > @@ -681,6 +708,30 @@ long kvm_arch_vcpu_ioctl(struct file *filp, > break; > } > > + case KVM_GET_ONE_REG: > + { > + struct kvm_one_reg reg; > + r = -EFAULT; > + if (copy_from_user(®, argp, sizeof(reg))) > + goto out; > + r = kvm_vcpu_ioctl_get_one_reg(vcpu, ®); > + if (copy_to_user(argp, ®, sizeof(reg))) { > + r = -EFAULT; > + goto out; > + } This is useless now - we already do the write to the user defined address. No need to write back the address and id fields :). Will send out v3 soon. Alex -- 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