KVM: PPC: Add support for explicit HIOR setting
authorAlexander Graf <agraf@suse.de>
Wed, 14 Sep 2011 19:45:23 +0000 (21:45 +0200)
committerAvi Kivity <avi@redhat.com>
Mon, 5 Mar 2012 12:52:41 +0000 (14:52 +0200)
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>
Signed-off-by: Avi Kivity <avi@redhat.com>
Documentation/virtual/kvm/api.txt
arch/powerpc/include/asm/kvm.h
arch/powerpc/include/asm/kvm_book3s.h
arch/powerpc/kvm/book3s_pr.c
arch/powerpc/kvm/powerpc.c
include/linux/kvm.h

index e0c75dcb2ca369a63f695b5a0743c2acf9cc6f8a..59a38264a0edab5da7942e6aa6b6297c7efbb891 100644 (file)
@@ -1610,6 +1610,7 @@ registers, find a list below:
 
   Arch  |       Register        | Width (bits)
         |                       |
+  PPC   | KVM_REG_PPC_HIOR      | 64
 
 4.69 KVM_GET_ONE_REG
 
index 663c57f8716514f87514d02991ce33d64e2fd718..f41adcda1468dc6f3ad90644681877c5c2ea973d 100644 (file)
@@ -331,4 +331,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 */
index 3c3edee672aa27d4a022acf6fd1a4e3014261509..aa795ccef2942feb73f8cf7e85bda5f7b1f47ad1 100644 (file)
@@ -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];
index c193625d5289d2d154a28064a4bcc02021a47a0a..00efda6dc0e2b72ac98f43728a2f21a9d917e5b1 100644 (file)
@@ -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;
        }
index 089c61bf0e168aba72cb06db775e9d36d4c683a6..59852091b38961529d5eb57b24890fe36205e1d9 100644 (file)
@@ -212,6 +212,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:
@@ -652,6 +653,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;
        }
@@ -665,6 +671,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;
        }
index 4f7a9fb8ab06b53428240ee93ace8ebf5ced4f77..acbe42939089224d06b0307f7a7c41d6bd9d1ada 100644 (file)
@@ -580,6 +580,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