* [PATCH 1/3] KVM: PPC: Add generic single register ioctls
2012-01-06 3:59 [PATCH 0/3] GET/SET_ONE_REG and HIOR patches v2 Alexander Graf
@ 2012-01-06 3:59 ` Alexander Graf
2012-01-06 3:49 ` Alexander Graf
2012-01-06 3:59 ` [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting Alexander Graf
2012-01-06 3:59 ` [PATCH 3/3] KVM: PPC: Move kvm_vcpu_ioctl_[gs]et_one_reg down to platform-specific code Alexander Graf
2 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2012-01-06 3:59 UTC (permalink / raw)
To: kvm-ppc; +Cc: kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood
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@suse.de>
---
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;
+ }
+ break;
+ }
+
+ case KVM_SET_ONE_REG:
+ {
+ struct kvm_one_reg reg;
+ r = -EFAULT;
+ if (copy_from_user(®, argp, sizeof(reg)))
+ goto out;
+ r = kvm_vcpu_ioctl_set_one_reg(vcpu, ®);
+ break;
+ }
+
#ifdef CONFIG_KVM_E500
case KVM_DIRTY_TLB: {
struct kvm_dirty_tlb dirty;
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 8d40db7..31fce98 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -557,6 +557,7 @@ struct kvm_ppc_pvinfo {
#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */
#define KVM_CAP_PPC_PAPR 68
#define KVM_CAP_SW_TLB 69
+#define KVM_CAP_ONE_REG 70
#define KVM_CAP_S390_GMAP 71
#define KVM_CAP_TSC_DEADLINE_TIMER 72
@@ -653,6 +654,37 @@ struct kvm_dirty_tlb {
__u32 num_dirty;
};
+/* Available with KVM_CAP_ONE_REG */
+
+#define KVM_REG_ARCH_MASK 0xff00000000000000ULL
+#define KVM_REG_GENERIC 0x0000000000000000ULL
+
+/*
+ * Architecture specific registers are to be defined in arch headers and
+ * ORed with the arch identifier.
+ */
+#define KVM_REG_PPC 0x1000000000000000ULL
+#define KVM_REG_X86 0x2000000000000000ULL
+#define KVM_REG_IA64 0x3000000000000000ULL
+#define KVM_REG_ARM 0x4000000000000000ULL
+#define KVM_REG_S390 0x5000000000000000ULL
+
+#define KVM_REG_SIZE_SHIFT 52
+#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
+#define KVM_REG_SIZE_U8 0x0000000000000000ULL
+#define KVM_REG_SIZE_U16 0x0010000000000000ULL
+#define KVM_REG_SIZE_U32 0x0020000000000000ULL
+#define KVM_REG_SIZE_U64 0x0030000000000000ULL
+#define KVM_REG_SIZE_U128 0x0040000000000000ULL
+#define KVM_REG_SIZE_U256 0x0050000000000000ULL
+#define KVM_REG_SIZE_U512 0x0060000000000000ULL
+#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
+
+struct kvm_one_reg {
+ __u64 id;
+ __u64 addr;
+};
+
/*
* ioctls for VM fds
*/
@@ -781,6 +813,9 @@ struct kvm_dirty_tlb {
#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)
/* Available with KVM_CAP_SW_TLB */
#define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb)
+/* Available with KVM_CAP_ONE_REG */
+#define KVM_GET_ONE_REG _IOWR(KVMIO, 0xab, struct kvm_one_reg)
+#define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
--
1.6.0.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 1/3] KVM: PPC: Add generic single register ioctls
2012-01-06 3:59 ` [PATCH 1/3] KVM: PPC: Add generic single register ioctls Alexander Graf
@ 2012-01-06 3:49 ` Alexander Graf
2012-01-06 4:15 ` [PATCH] " Alexander Graf
0 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2012-01-06 3:49 UTC (permalink / raw)
To: Alexander Graf; +Cc: kvm-ppc, kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood
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@suse.de>
>
> ---
>
> 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
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-06 3:49 ` Alexander Graf
@ 2012-01-06 4:15 ` Alexander Graf
2012-01-06 19:32 ` Scott Wood
0 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2012-01-06 4:15 UTC (permalink / raw)
To: kvm-ppc; +Cc: kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood
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@suse.de>
---
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
v2 -> v3:
- make GET_ONE_REG ioctl write-only
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..8bdd75b 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,20 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
break;
}
+ case KVM_SET_ONE_REG:
+ case KVM_GET_ONE_REG:
+ {
+ struct kvm_one_reg reg;
+ r = -EFAULT;
+ if (copy_from_user(®, argp, sizeof(reg)))
+ goto out;
+ if (ioctl == KVM_SET_ONE_REG)
+ r = kvm_vcpu_ioctl_set_one_reg(vcpu, ®);
+ else
+ r = kvm_vcpu_ioctl_get_one_reg(vcpu, ®);
+ break;
+ }
+
#ifdef CONFIG_KVM_E500
case KVM_DIRTY_TLB: {
struct kvm_dirty_tlb dirty;
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 8d40db7..4b63ec1 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -557,6 +557,7 @@ struct kvm_ppc_pvinfo {
#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */
#define KVM_CAP_PPC_PAPR 68
#define KVM_CAP_SW_TLB 69
+#define KVM_CAP_ONE_REG 70
#define KVM_CAP_S390_GMAP 71
#define KVM_CAP_TSC_DEADLINE_TIMER 72
@@ -653,6 +654,37 @@ struct kvm_dirty_tlb {
__u32 num_dirty;
};
+/* Available with KVM_CAP_ONE_REG */
+
+#define KVM_REG_ARCH_MASK 0xff00000000000000ULL
+#define KVM_REG_GENERIC 0x0000000000000000ULL
+
+/*
+ * Architecture specific registers are to be defined in arch headers and
+ * ORed with the arch identifier.
+ */
+#define KVM_REG_PPC 0x1000000000000000ULL
+#define KVM_REG_X86 0x2000000000000000ULL
+#define KVM_REG_IA64 0x3000000000000000ULL
+#define KVM_REG_ARM 0x4000000000000000ULL
+#define KVM_REG_S390 0x5000000000000000ULL
+
+#define KVM_REG_SIZE_SHIFT 52
+#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
+#define KVM_REG_SIZE_U8 0x0000000000000000ULL
+#define KVM_REG_SIZE_U16 0x0010000000000000ULL
+#define KVM_REG_SIZE_U32 0x0020000000000000ULL
+#define KVM_REG_SIZE_U64 0x0030000000000000ULL
+#define KVM_REG_SIZE_U128 0x0040000000000000ULL
+#define KVM_REG_SIZE_U256 0x0050000000000000ULL
+#define KVM_REG_SIZE_U512 0x0060000000000000ULL
+#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
+
+struct kvm_one_reg {
+ __u64 id;
+ __u64 addr;
+};
+
/*
* ioctls for VM fds
*/
@@ -781,6 +813,9 @@ struct kvm_dirty_tlb {
#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)
/* Available with KVM_CAP_SW_TLB */
#define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb)
+/* Available with KVM_CAP_ONE_REG */
+#define KVM_GET_ONE_REG _IOW(KVMIO, 0xab, struct kvm_one_reg)
+#define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-06 4:15 ` [PATCH] " Alexander Graf
@ 2012-01-06 19:32 ` Scott Wood
2012-01-07 0:52 ` Alexander Graf
0 siblings, 1 reply; 16+ messages in thread
From: Scott Wood @ 2012-01-06 19:32 UTC (permalink / raw)
To: Alexander Graf; +Cc: kvm-ppc, kvm list, Avi Kivity, Marcelo Tosatti
On 01/05/2012 10:15 PM, 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.
The comment about padding is no longer relevant.
> +/*
> + * Architecture specific registers are to be defined in arch headers and
> + * ORed with the arch identifier.
> + */
> +#define KVM_REG_PPC 0x1000000000000000ULL
> +#define KVM_REG_X86 0x2000000000000000ULL
> +#define KVM_REG_IA64 0x3000000000000000ULL
> +#define KVM_REG_ARM 0x4000000000000000ULL
> +#define KVM_REG_S390 0x5000000000000000ULL
> +
> +#define KVM_REG_SIZE_SHIFT 52
> +#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
> +#define KVM_REG_SIZE_U8 0x0000000000000000ULL
> +#define KVM_REG_SIZE_U16 0x0010000000000000ULL
> +#define KVM_REG_SIZE_U32 0x0020000000000000ULL
> +#define KVM_REG_SIZE_U64 0x0030000000000000ULL
> +#define KVM_REG_SIZE_U128 0x0040000000000000ULL
> +#define KVM_REG_SIZE_U256 0x0050000000000000ULL
> +#define KVM_REG_SIZE_U512 0x0060000000000000ULL
> +#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
Why not just encode directly as number of bytes?
-Scott
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-06 19:32 ` Scott Wood
@ 2012-01-07 0:52 ` Alexander Graf
2012-01-09 19:07 ` Scott Wood
0 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2012-01-07 0:52 UTC (permalink / raw)
To: Scott Wood
Cc: <kvm-ppc@vger.kernel.org>, kvm list, Avi Kivity,
Marcelo Tosatti
On 06.01.2012, at 20:32, Scott Wood <scottwood@freescale.com> wrote:
> On 01/05/2012 10:15 PM, 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.
>
> The comment about padding is no longer relevant.
>
>> +/*
>> + * Architecture specific registers are to be defined in arch headers and
>> + * ORed with the arch identifier.
>> + */
>> +#define KVM_REG_PPC 0x1000000000000000ULL
>> +#define KVM_REG_X86 0x2000000000000000ULL
>> +#define KVM_REG_IA64 0x3000000000000000ULL
>> +#define KVM_REG_ARM 0x4000000000000000ULL
>> +#define KVM_REG_S390 0x5000000000000000ULL
>> +
>> +#define KVM_REG_SIZE_SHIFT 52
>> +#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
>> +#define KVM_REG_SIZE_U8 0x0000000000000000ULL
>> +#define KVM_REG_SIZE_U16 0x0010000000000000ULL
>> +#define KVM_REG_SIZE_U32 0x0020000000000000ULL
>> +#define KVM_REG_SIZE_U64 0x0030000000000000ULL
>> +#define KVM_REG_SIZE_U128 0x0040000000000000ULL
>> +#define KVM_REG_SIZE_U256 0x0050000000000000ULL
>> +#define KVM_REG_SIZE_U512 0x0060000000000000ULL
>> +#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
>
> Why not just encode directly as number of bytes?
Because this is 1 << n bytes :)
Alex
>
> -Scott
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-07 0:52 ` Alexander Graf
@ 2012-01-09 19:07 ` Scott Wood
2012-01-09 20:11 ` Alexander Graf
0 siblings, 1 reply; 16+ messages in thread
From: Scott Wood @ 2012-01-09 19:07 UTC (permalink / raw)
To: Alexander Graf
Cc: <kvm-ppc@vger.kernel.org>, kvm list, Avi Kivity,
Marcelo Tosatti
On 01/06/2012 06:52 PM, Alexander Graf wrote:
>
>
> On 06.01.2012, at 20:32, Scott Wood <scottwood@freescale.com> wrote:
>
>> On 01/05/2012 10:15 PM, Alexander Graf wrote:
>>
>>> +/*
>>> + * Architecture specific registers are to be defined in arch headers and
>>> + * ORed with the arch identifier.
>>> + */
>>> +#define KVM_REG_PPC 0x1000000000000000ULL
>>> +#define KVM_REG_X86 0x2000000000000000ULL
>>> +#define KVM_REG_IA64 0x3000000000000000ULL
>>> +#define KVM_REG_ARM 0x4000000000000000ULL
>>> +#define KVM_REG_S390 0x5000000000000000ULL
>>> +
>>> +#define KVM_REG_SIZE_SHIFT 52
>>> +#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
>>> +#define KVM_REG_SIZE_U8 0x0000000000000000ULL
>>> +#define KVM_REG_SIZE_U16 0x0010000000000000ULL
>>> +#define KVM_REG_SIZE_U32 0x0020000000000000ULL
>>> +#define KVM_REG_SIZE_U64 0x0030000000000000ULL
>>> +#define KVM_REG_SIZE_U128 0x0040000000000000ULL
>>> +#define KVM_REG_SIZE_U256 0x0050000000000000ULL
>>> +#define KVM_REG_SIZE_U512 0x0060000000000000ULL
>>> +#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
>>
>> Why not just encode directly as number of bytes?
>
> Because this is 1 << n bytes :)
Some registers may not be a power-of-2 number of bytes (e.g. x86 segment
descriptors), and we've got plenty of space to spare in the id.
It's probably not worth another respin, though -- we can just document
right/left justification in the event that we have such a register.
-Scott
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-09 19:07 ` Scott Wood
@ 2012-01-09 20:11 ` Alexander Graf
2012-01-09 20:12 ` Scott Wood
0 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2012-01-09 20:11 UTC (permalink / raw)
To: Scott Wood
Cc: <kvm-ppc@vger.kernel.org>, kvm list, Avi Kivity,
Marcelo Tosatti
Am 09.01.2012 um 20:07 schrieb Scott Wood <scottwood@freescale.com>:
> On 01/06/2012 06:52 PM, Alexander Graf wrote:
>>
>>
>> On 06.01.2012, at 20:32, Scott Wood <scottwood@freescale.com> wrote:
>>
>>> On 01/05/2012 10:15 PM, Alexander Graf wrote:
>>>
>>>> +/*
>>>> + * Architecture specific registers are to be defined in arch headers and
>>>> + * ORed with the arch identifier.
>>>> + */
>>>> +#define KVM_REG_PPC 0x1000000000000000ULL
>>>> +#define KVM_REG_X86 0x2000000000000000ULL
>>>> +#define KVM_REG_IA64 0x3000000000000000ULL
>>>> +#define KVM_REG_ARM 0x4000000000000000ULL
>>>> +#define KVM_REG_S390 0x5000000000000000ULL
>>>> +
>>>> +#define KVM_REG_SIZE_SHIFT 52
>>>> +#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
>>>> +#define KVM_REG_SIZE_U8 0x0000000000000000ULL
>>>> +#define KVM_REG_SIZE_U16 0x0010000000000000ULL
>>>> +#define KVM_REG_SIZE_U32 0x0020000000000000ULL
>>>> +#define KVM_REG_SIZE_U64 0x0030000000000000ULL
>>>> +#define KVM_REG_SIZE_U128 0x0040000000000000ULL
>>>> +#define KVM_REG_SIZE_U256 0x0050000000000000ULL
>>>> +#define KVM_REG_SIZE_U512 0x0060000000000000ULL
>>>> +#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
>>>
>>> Why not just encode directly as number of bytes?
>>
>> Because this is 1 << n bytes :)
>
> Some registers may not be a power-of-2 number of bytes (e.g. x86 segment
> descriptors), and we've got plenty of space to spare in the id.
If they're not a power of 2, we can still bmp it to the next power of 2 size, no?
Alex
>
> It's probably not worth another respin, though -- we can just document
> right/left justification in the event that we have such a register.
>
> -Scott
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-09 20:11 ` Alexander Graf
@ 2012-01-09 20:12 ` Scott Wood
2012-01-09 20:14 ` Alexander Graf
0 siblings, 1 reply; 16+ messages in thread
From: Scott Wood @ 2012-01-09 20:12 UTC (permalink / raw)
To: Alexander Graf
Cc: <kvm-ppc@vger.kernel.org>, kvm list, Avi Kivity,
Marcelo Tosatti
On 01/09/2012 02:11 PM, Alexander Graf wrote:
>
>
> Am 09.01.2012 um 20:07 schrieb Scott Wood <scottwood@freescale.com>:
>
>> On 01/06/2012 06:52 PM, Alexander Graf wrote:
>>>
>>>
>>> On 06.01.2012, at 20:32, Scott Wood <scottwood@freescale.com> wrote:
>>>
>>>> On 01/05/2012 10:15 PM, Alexander Graf wrote:
>>>>
>>>>> +/*
>>>>> + * Architecture specific registers are to be defined in arch headers and
>>>>> + * ORed with the arch identifier.
>>>>> + */
>>>>> +#define KVM_REG_PPC 0x1000000000000000ULL
>>>>> +#define KVM_REG_X86 0x2000000000000000ULL
>>>>> +#define KVM_REG_IA64 0x3000000000000000ULL
>>>>> +#define KVM_REG_ARM 0x4000000000000000ULL
>>>>> +#define KVM_REG_S390 0x5000000000000000ULL
>>>>> +
>>>>> +#define KVM_REG_SIZE_SHIFT 52
>>>>> +#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
>>>>> +#define KVM_REG_SIZE_U8 0x0000000000000000ULL
>>>>> +#define KVM_REG_SIZE_U16 0x0010000000000000ULL
>>>>> +#define KVM_REG_SIZE_U32 0x0020000000000000ULL
>>>>> +#define KVM_REG_SIZE_U64 0x0030000000000000ULL
>>>>> +#define KVM_REG_SIZE_U128 0x0040000000000000ULL
>>>>> +#define KVM_REG_SIZE_U256 0x0050000000000000ULL
>>>>> +#define KVM_REG_SIZE_U512 0x0060000000000000ULL
>>>>> +#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
>>>>
>>>> Why not just encode directly as number of bytes?
>>>
>>> Because this is 1 << n bytes :)
>>
>> Some registers may not be a power-of-2 number of bytes (e.g. x86 segment
>> descriptors), and we've got plenty of space to spare in the id.
>
> If they're not a power of 2, we can still bmp it to the next power of 2 size, no?
Yes, that's what I meant by it not being a huge deal and documenting
whether the padding is on the right or the left. Just seems a little
more awkward than necessary, given that we have room to encode it as a
plain linear size.
-Scott
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] KVM: PPC: Add generic single register ioctls
2012-01-09 20:12 ` Scott Wood
@ 2012-01-09 20:14 ` Alexander Graf
0 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2012-01-09 20:14 UTC (permalink / raw)
To: Scott Wood
Cc: <kvm-ppc@vger.kernel.org>, kvm list, Avi Kivity,
Marcelo Tosatti
Am 09.01.2012 um 21:12 schrieb Scott Wood <scottwood@freescale.com>:
> On 01/09/2012 02:11 PM, Alexander Graf wrote:
>>
>>
>> Am 09.01.2012 um 20:07 schrieb Scott Wood <scottwood@freescale.com>:
>>
>>> On 01/06/2012 06:52 PM, Alexander Graf wrote:
>>>>
>>>>
>>>> On 06.01.2012, at 20:32, Scott Wood <scottwood@freescale.com> wrote:
>>>>
>>>>> On 01/05/2012 10:15 PM, Alexander Graf wrote:
>>>>>
>>>>>> +/*
>>>>>> + * Architecture specific registers are to be defined in arch headers and
>>>>>> + * ORed with the arch identifier.
>>>>>> + */
>>>>>> +#define KVM_REG_PPC 0x1000000000000000ULL
>>>>>> +#define KVM_REG_X86 0x2000000000000000ULL
>>>>>> +#define KVM_REG_IA64 0x3000000000000000ULL
>>>>>> +#define KVM_REG_ARM 0x4000000000000000ULL
>>>>>> +#define KVM_REG_S390 0x5000000000000000ULL
>>>>>> +
>>>>>> +#define KVM_REG_SIZE_SHIFT 52
>>>>>> +#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U8 0x0000000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U16 0x0010000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U32 0x0020000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U64 0x0030000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U128 0x0040000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U256 0x0050000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U512 0x0060000000000000ULL
>>>>>> +#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
>>>>>
>>>>> Why not just encode directly as number of bytes?
>>>>
>>>> Because this is 1 << n bytes :)
>>>
>>> Some registers may not be a power-of-2 number of bytes (e.g. x86 segment
>>> descriptors), and we've got plenty of space to spare in the id.
>>
>> If they're not a power of 2, we can still bmp it to the next power of 2 size, no?
>
> Yes, that's what I meant by it not being a huge deal and documenting
> whether the padding is on the right or the left. Just seems a little
> more awkward than necessary, given that we have room to encode it as a
> plain linear size.
Well I thought it makes things easier, since variable types are usually in a power of 2 :). But I'm certainly not attached to it.
Alex
>
> -Scott
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting
2012-01-06 3:59 [PATCH 0/3] GET/SET_ONE_REG and HIOR patches v2 Alexander Graf
2012-01-06 3:59 ` [PATCH 1/3] KVM: PPC: Add generic single register ioctls Alexander Graf
@ 2012-01-06 3:59 ` Alexander Graf
2012-01-06 18:42 ` Scott Wood
2012-04-01 19:51 ` Andreas Schwab
2012-01-06 3:59 ` [PATCH 3/3] KVM: PPC: Move kvm_vcpu_ioctl_[gs]et_one_reg down to platform-specific code Alexander Graf
2 siblings, 2 replies; 16+ messages in thread
From: Alexander Graf @ 2012-01-06 3:59 UTC (permalink / raw)
To: kvm-ppc; +Cc: kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood
Until now, we always set HIOR based on the PVR, but this is just wrong.
Instead, we should be setting HIOR explicitly, so user space can decide
what the initial HIOR value is - just like on real hardware.
We keep the old PVR based way around for backwards compatibility, but
once user space uses the SET_ONE_REG based method, we drop the PVR logic.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
v1 -> v2:
- rename KVM_ONE_REG to KVM_REG
- add size information to HIOR
- change HIOR number to 1, indicating that numbers are consecutive
---
Documentation/virtual/kvm/api.txt | 1 +
arch/powerpc/include/asm/kvm.h | 2 ++
arch/powerpc/include/asm/kvm_book3s.h | 2 ++
arch/powerpc/kvm/book3s_pr.c | 6 ++++--
arch/powerpc/kvm/powerpc.c | 13 +++++++++++++
include/linux/kvm.h | 1 +
6 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 8494214..d73b8ea 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1546,6 +1546,7 @@ registers, find a list below:
Arch | Register | Width (bits)
| |
+ PPC | KVM_REG_PPC_HIOR | 64
4.66 KVM_GET_ONE_REG
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 25964ee..7e9e24d 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -327,4 +327,6 @@ struct kvm_book3e_206_tlb_params {
__u32 reserved[8];
};
+#define KVM_REG_PPC_HIOR KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x1
+
#endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index 3c3edee..aa795cc 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -90,6 +90,8 @@ struct kvmppc_vcpu_book3s {
#endif
int context_id[SID_CONTEXTS];
+ bool hior_explicit; /* HIOR is set by ioctl, not PVR */
+
struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE];
struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG];
struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE];
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index c193625..00efda6 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -157,14 +157,16 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
#ifdef CONFIG_PPC_BOOK3S_64
if ((pvr >= 0x330000) && (pvr < 0x70330000)) {
kvmppc_mmu_book3s_64_init(vcpu);
- to_book3s(vcpu)->hior = 0xfff00000;
+ if (!to_book3s(vcpu)->hior_explicit)
+ to_book3s(vcpu)->hior = 0xfff00000;
to_book3s(vcpu)->msr_mask = 0xffffffffffffffffULL;
vcpu->arch.cpu_type = KVM_CPU_3S_64;
} else
#endif
{
kvmppc_mmu_book3s_32_init(vcpu);
- to_book3s(vcpu)->hior = 0;
+ if (!to_book3s(vcpu)->hior_explicit)
+ to_book3s(vcpu)->hior = 0;
to_book3s(vcpu)->msr_mask = 0xffffffffULL;
vcpu->arch.cpu_type = KVM_CPU_3S_32;
}
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 9c598b6..4223c6f 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -209,6 +209,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_PPC_BOOKE_SREGS:
#else
case KVM_CAP_PPC_SEGSTATE:
+ case KVM_CAP_PPC_HIOR:
case KVM_CAP_PPC_PAPR:
#endif
case KVM_CAP_PPC_UNSET_IRQ:
@@ -649,6 +650,11 @@ static int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,
int r = -EINVAL;
switch (reg->id) {
+#ifdef CONFIG_PPC_BOOK3S
+ case KVM_REG_PPC_HIOR:
+ r = put_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
+ break;
+#endif
default:
break;
}
@@ -662,6 +668,13 @@ static int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
int r = -EINVAL;
switch (reg->id) {
+#ifdef CONFIG_PPC_BOOK3S
+ case KVM_ONE_REG_PPC_HIOR:
+ r = get_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
+ if (!r)
+ to_book3s(vcpu)->hior_explicit = true;
+ break;
+#endif
default:
break;
}
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 31fce98..125f1bc 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -555,6 +555,7 @@ struct kvm_ppc_pvinfo {
#define KVM_CAP_PPC_SMT 64
#define KVM_CAP_PPC_RMA 65
#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */
+#define KVM_CAP_PPC_HIOR 67
#define KVM_CAP_PPC_PAPR 68
#define KVM_CAP_SW_TLB 69
#define KVM_CAP_ONE_REG 70
--
1.6.0.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting
2012-01-06 3:59 ` [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting Alexander Graf
@ 2012-01-06 18:42 ` Scott Wood
2012-04-01 19:51 ` Andreas Schwab
1 sibling, 0 replies; 16+ messages in thread
From: Scott Wood @ 2012-01-06 18:42 UTC (permalink / raw)
To: Alexander Graf; +Cc: kvm-ppc, kvm list, Avi Kivity, Marcelo Tosatti
On 01/05/2012 09:59 PM, Alexander Graf wrote:
> diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
> index 25964ee..7e9e24d 100644
> --- a/arch/powerpc/include/asm/kvm.h
> +++ b/arch/powerpc/include/asm/kvm.h
> @@ -327,4 +327,6 @@ struct kvm_book3e_206_tlb_params {
> __u32 reserved[8];
> };
>
> +#define KVM_REG_PPC_HIOR KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x1
Parentheses around macro definition
-Scott
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting
2012-01-06 3:59 ` [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting Alexander Graf
2012-01-06 18:42 ` Scott Wood
@ 2012-04-01 19:51 ` Andreas Schwab
2012-04-16 16:54 ` Alexander Graf
1 sibling, 1 reply; 16+ messages in thread
From: Andreas Schwab @ 2012-04-01 19:51 UTC (permalink / raw)
To: Alexander Graf; +Cc: kvm-ppc, kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood
Alexander Graf <agraf@suse.de> writes:
> @@ -662,6 +668,13 @@ static int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
> int r = -EINVAL;
>
> switch (reg->id) {
> +#ifdef CONFIG_PPC_BOOK3S
> + case KVM_ONE_REG_PPC_HIOR:
> + r = get_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
That doesn't build on ppc32, get_user cannot handle 64 bit values. You
need to use __get_user64 instead.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting
2012-04-01 19:51 ` Andreas Schwab
@ 2012-04-16 16:54 ` Alexander Graf
2012-04-16 21:42 ` Paul Mackerras
0 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2012-04-16 16:54 UTC (permalink / raw)
To: Andreas Schwab; +Cc: kvm-ppc, kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood
On 01.04.2012, at 21:51, Andreas Schwab wrote:
> Alexander Graf <agraf@suse.de> writes:
>
>> @@ -662,6 +668,13 @@ static int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>> int r = -EINVAL;
>>
>> switch (reg->id) {
>> +#ifdef CONFIG_PPC_BOOK3S
>> + case KVM_ONE_REG_PPC_HIOR:
>> + r = get_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
>
> That doesn't build on ppc32, get_user cannot handle 64 bit values. You
> need to use __get_user64 instead.
Yeah :(. I already have this patch in my tree to fix that:
commit 3c82a50bb07455b2f0663ebc12fffdb647f737d2
Author: Alexander Graf <agraf@suse.de>
Date: Tue Mar 13 19:59:39 2012 +0100
KVM: PPC: Book3S: Compile fix for ppc32 in HIOR
On PPC32 we can not use get_user/put_user for 64bit wide variables, as there
is no single instruction that could load or store variables that big.
So instead, we have to use copy_from/to_user which works everywhere.
Signed-off-by: Alexander Graf <agraf@suse.de>
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 1717ac8..e2be5ad 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -881,8 +881,8 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
switch (reg->id) {
case KVM_REG_PPC_HIOR:
- r = put_user(to_book3s(vcpu)->hior,
- (u64 __user *)(long)reg->addr);
+ r = copy_to_user((u64 __user *)(long)reg->addr,
+ &to_book3s(vcpu)->hior, sizeof(u64));
break;
default:
break;
@@ -897,8 +897,8 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
switch (reg->id) {
case KVM_REG_PPC_HIOR:
- r = get_user(to_book3s(vcpu)->hior,
- (u64 __user *)(long)reg->addr);
+ r = copy_from_user(&to_book3s(vcpu)->hior,
+ (u64 __user *)(long)reg->addr, sizeof(u64));
if (!r)
to_book3s(vcpu)->hior_explicit = true;
break;
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting
2012-04-16 16:54 ` Alexander Graf
@ 2012-04-16 21:42 ` Paul Mackerras
0 siblings, 0 replies; 16+ messages in thread
From: Paul Mackerras @ 2012-04-16 21:42 UTC (permalink / raw)
To: Alexander Graf
Cc: Andreas Schwab, kvm-ppc, kvm list, Avi Kivity, Marcelo Tosatti,
Scott Wood
On Mon, Apr 16, 2012 at 06:54:50PM +0200, Alexander Graf wrote:
>
> Yeah :(. I already have this patch in my tree to fix that:
...
> case KVM_REG_PPC_HIOR:
> - r = put_user(to_book3s(vcpu)->hior,
> - (u64 __user *)(long)reg->addr);
> + r = copy_to_user((u64 __user *)(long)reg->addr,
> + &to_book3s(vcpu)->hior, sizeof(u64));
I folded this in with your other patch that touches these lines and
sent it to Avi, and it is in Linus' tree as b8e6f8ae51.
Paul.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 3/3] KVM: PPC: Move kvm_vcpu_ioctl_[gs]et_one_reg down to platform-specific code
2012-01-06 3:59 [PATCH 0/3] GET/SET_ONE_REG and HIOR patches v2 Alexander Graf
2012-01-06 3:59 ` [PATCH 1/3] KVM: PPC: Add generic single register ioctls Alexander Graf
2012-01-06 3:59 ` [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting Alexander Graf
@ 2012-01-06 3:59 ` Alexander Graf
2 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2012-01-06 3:59 UTC (permalink / raw)
To: kvm-ppc; +Cc: kvm list, Avi Kivity, Marcelo Tosatti, Scott Wood, Paul Mackerras
From: Paul Mackerras <paulus@samba.org>
This moves the get/set_one_reg implementation down from powerpc.c into
booke.c, book3s_pr.c and book3s_hv.c. This avoids #ifdefs in C code,
but more importantly, it fixes a bug on Book3s HV where we were
accessing beyond the end of the kvm_vcpu struct (via the to_book3s()
macro) and corrupting memory, causing random crashes and file corruption.
On Book3s HV we only accept setting the HIOR to zero, since the guest
runs in supervisor mode and its vectors are never offset from zero.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
[agraf update to apply on top of changed ONE_REG patches]
---
arch/powerpc/include/asm/kvm_ppc.h | 3 ++
arch/powerpc/kvm/book3s_hv.c | 36 ++++++++++++++++++++++++++++++++++
arch/powerpc/kvm/book3s_pr.c | 32 ++++++++++++++++++++++++++++++
arch/powerpc/kvm/booke.c | 10 +++++++++
arch/powerpc/kvm/powerpc.c | 38 ------------------------------------
5 files changed, 81 insertions(+), 38 deletions(-)
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index fb70414..a61b5b5 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -176,6 +176,9 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
+int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
+
void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
#ifdef CONFIG_KVM_BOOK3S_64_HV
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index fdc804c..3580db8 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -398,6 +398,42 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
return 0;
}
+int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+{
+ int r = -EINVAL;
+
+ switch (reg->id) {
+ case KVM_REG_PPC_HIOR:
+ r = put_user(0, (u64 __user *)reg->addr);
+ break;
+ default:
+ break;
+ }
+
+ return r;
+}
+
+int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+{
+ int r = -EINVAL;
+
+ switch (reg->id) {
+ case KVM_REG_PPC_HIOR:
+ {
+ u64 hior;
+ /* Only allow this to be set to zero */
+ r = get_user(hior, (u64 __user *)reg->addr);
+ if (!r && (hior != 0))
+ r = -EINVAL;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return r;
+}
+
int kvmppc_core_check_processor_compat(void)
{
if (cpu_has_feature(CPU_FTR_HVMODE))
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 00efda6..ee222ec 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -874,6 +874,38 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
return 0;
}
+int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+{
+ int r = -EINVAL;
+
+ switch (reg->id) {
+ case KVM_REG_PPC_HIOR:
+ r = put_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
+ break;
+ default:
+ break;
+ }
+
+ return r;
+}
+
+int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+{
+ int r = -EINVAL;
+
+ switch (reg->id) {
+ case KVM_REG_PPC_HIOR:
+ r = get_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
+ if (!r)
+ to_book3s(vcpu)->hior_explicit = true;
+ break;
+ default:
+ break;
+ }
+
+ return r;
+}
+
int kvmppc_core_check_processor_compat(void)
{
return 0;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 9e41f45..ee9e1ee 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -887,6 +887,16 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
return kvmppc_core_set_sregs(vcpu, sregs);
}
+int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+{
+ return -EINVAL;
+}
+
+int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+{
+ return -EINVAL;
+}
+
int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
{
return -ENOTSUPP;
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 4223c6f..64c738d 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -644,44 +644,6 @@ 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) {
-#ifdef CONFIG_PPC_BOOK3S
- case KVM_REG_PPC_HIOR:
- r = put_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
- break;
-#endif
- 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) {
-#ifdef CONFIG_PPC_BOOK3S
- case KVM_ONE_REG_PPC_HIOR:
- r = get_user(to_book3s(vcpu)->hior, (u64 __user *)reg->addr);
- if (!r)
- to_book3s(vcpu)->hior_explicit = true;
- break;
-#endif
- default:
- break;
- }
-
- return r;
-}
-
int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
struct kvm_mp_state *mp_state)
{
--
1.6.0.2
^ permalink raw reply related [flat|nested] 16+ messages in thread