Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting

2012-04-16 Thread Paul Mackerras
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.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting

2012-04-16 Thread Alexander Graf

On 01.04.2012, at 21:51, Andreas Schwab wrote:

> Alexander Graf  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 
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 

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;--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting

2012-04-01 Thread Andreas Schwab
Alexander Graf  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, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting

2012-01-06 Thread Scott Wood
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

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


[PATCH 2/3] KVM: PPC: Add support for explicit HIOR setting

2012-01-05 Thread Alexander Graf
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 

---

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 >= 0x33) && (pvr < 0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
-   to_book3s(vcpu)->hior = 0xfff0;
+   if (!to_book3s(vcpu)->hior_explicit)
+   to_book3s(vcpu)->hior = 0xfff0;
to_book3s(vcpu)->msr_mask = 0xULL;
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 = 0xULL;
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_RMA65
 #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

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a m