All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] PPC: Support -M pseries for PR KVM
@ 2011-08-09 16:39 Alexander Graf
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 1/3] KVM: update kernel headers Alexander Graf
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexander Graf @ 2011-08-09 16:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: paulus, david

We have support for -M pseries with TCG for a while now, but are missing
integration with KVM. While the KVM HV target which is predestined for -M
pseries is slightly more tricky to integrate and needs to evolve a bit still,
we can easily support it with PR KVM.

So this patch set adds support for running -M pseries with KVM that has the
patch set applied I just submitted to the kvm list.


Alex

Alexander Graf (3):
  KVM: update kernel headers
  PPC: Enable to use PAPR with PR style KVM
  PPC: SPAPR: Use KVM function for time info

 hw/spapr.c                       |   22 ++++++++++++---
 linux-headers/asm-powerpc/kvm.h  |   23 ++++++++++++++++
 linux-headers/asm-x86/kvm_para.h |   14 ++++++++++
 linux-headers/linux/kvm.h        |   25 ++++++++++++-----
 linux-headers/linux/kvm_para.h   |    1 +
 target-ppc/kvm.c                 |   53 ++++++++++++++++++++++++++++++++++++++
 target-ppc/kvm_ppc.h             |    5 +++
 7 files changed, 130 insertions(+), 13 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 1/3] KVM: update kernel headers
  2011-08-09 16:39 [Qemu-devel] [PATCH 0/3] PPC: Support -M pseries for PR KVM Alexander Graf
@ 2011-08-09 16:39 ` Alexander Graf
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 2/3] PPC: Enable to use PAPR with PR style KVM Alexander Graf
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info Alexander Graf
  2 siblings, 0 replies; 7+ messages in thread
From: Alexander Graf @ 2011-08-09 16:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: paulus, david

This patch updates the kvm kernel headers to the latest version.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 linux-headers/asm-powerpc/kvm.h  |   23 +++++++++++++++++++++++
 linux-headers/asm-x86/kvm_para.h |   14 ++++++++++++++
 linux-headers/linux/kvm.h        |   25 +++++++++++++++++--------
 linux-headers/linux/kvm_para.h   |    1 +
 4 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/linux-headers/asm-powerpc/kvm.h b/linux-headers/asm-powerpc/kvm.h
index 777d307..579e219 100644
--- a/linux-headers/asm-powerpc/kvm.h
+++ b/linux-headers/asm-powerpc/kvm.h
@@ -22,6 +22,10 @@
 
 #include <linux/types.h>
 
+/* Select powerpc specific features in <linux/kvm.h> */
+#define __KVM_HAVE_SPAPR_TCE
+#define __KVM_HAVE_PPC_SMT
+
 struct kvm_regs {
 	__u64 pc;
 	__u64 cr;
@@ -145,6 +149,12 @@ struct kvm_regs {
 #define KVM_SREGS_E_UPDATE_DBSR		(1 << 3)
 
 /*
+ * Book3S special bits to indicate contents in the struct by maintaining
+ * backwards compatibility with older structs. If adding a new field,
+ * please make sure to add a flag for that new field */
+#define KVM_SREGS_S_HIOR		(1 << 0)
+
+/*
  * In KVM_SET_SREGS, reserved/pad fields must be left untouched from a
  * previous KVM_GET_REGS.
  *
@@ -169,6 +179,8 @@ struct kvm_sregs {
 				__u64 ibat[8];
 				__u64 dbat[8];
 			} ppc32;
+			__u64 flags; /* KVM_SREGS_S_ */
+			__u64 hior;
 		} s;
 		struct {
 			union {
@@ -272,4 +284,15 @@ struct kvm_guest_debug_arch {
 #define KVM_INTERRUPT_UNSET	-2U
 #define KVM_INTERRUPT_SET_LEVEL	-3U
 
+/* for KVM_CAP_SPAPR_TCE */
+struct kvm_create_spapr_tce {
+	__u64 liobn;
+	__u32 window_size;
+};
+
+/* for KVM_ALLOCATE_RMA */
+struct kvm_allocate_rma {
+	__u64 rma_size;
+};
+
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/linux-headers/asm-x86/kvm_para.h b/linux-headers/asm-x86/kvm_para.h
index 834d71e..f2ac46a 100644
--- a/linux-headers/asm-x86/kvm_para.h
+++ b/linux-headers/asm-x86/kvm_para.h
@@ -21,6 +21,7 @@
  */
 #define KVM_FEATURE_CLOCKSOURCE2        3
 #define KVM_FEATURE_ASYNC_PF		4
+#define KVM_FEATURE_STEAL_TIME		5
 
 /* The last 8 bits are used to indicate how to interpret the flags field
  * in pvclock structure. If no bits are set, all flags are ignored.
@@ -30,10 +31,23 @@
 #define MSR_KVM_WALL_CLOCK  0x11
 #define MSR_KVM_SYSTEM_TIME 0x12
 
+#define KVM_MSR_ENABLED 1
 /* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */
 #define MSR_KVM_WALL_CLOCK_NEW  0x4b564d00
 #define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
 #define MSR_KVM_ASYNC_PF_EN 0x4b564d02
+#define MSR_KVM_STEAL_TIME  0x4b564d03
+
+struct kvm_steal_time {
+	__u64 steal;
+	__u32 version;
+	__u32 flags;
+	__u32 pad[12];
+};
+
+#define KVM_STEAL_ALIGNMENT_BITS 5
+#define KVM_STEAL_VALID_BITS ((-1ULL << (KVM_STEAL_ALIGNMENT_BITS + 1)))
+#define KVM_STEAL_RESERVED_MASK (((1 << KVM_STEAL_ALIGNMENT_BITS) - 1 ) << 1)
 
 #define KVM_MAX_MMU_OP_BATCH           32
 
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index fc63b73..2062375 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -161,6 +161,7 @@ struct kvm_pit_config {
 #define KVM_EXIT_NMI              16
 #define KVM_EXIT_INTERNAL_ERROR   17
 #define KVM_EXIT_OSI              18
+#define KVM_EXIT_PAPR_HCALL	  19
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 #define KVM_INTERNAL_ERROR_EMULATION 1
@@ -264,6 +265,11 @@ struct kvm_run {
 		struct {
 			__u64 gprs[32];
 		} osi;
+		struct {
+			__u64 nr;
+			__u64 ret;
+			__u64 args[9];
+		} papr_hcall;
 		/* Fix the size of the union. */
 		char padding[256];
 	};
@@ -457,7 +463,7 @@ struct kvm_ppc_pvinfo {
 #define KVM_CAP_VAPIC 6
 #define KVM_CAP_EXT_CPUID 7
 #define KVM_CAP_CLOCKSOURCE 8
-#define KVM_CAP_NR_VCPUS 9       /* returns max vcpus per vm */
+#define KVM_CAP_NR_VCPUS 9       /* returns recommended max vcpus per vm */
 #define KVM_CAP_NR_MEMSLOTS 10   /* returns max memory slots per vm */
 #define KVM_CAP_PIT 11
 #define KVM_CAP_NOP_IO_DELAY 12
@@ -544,6 +550,12 @@ struct kvm_ppc_pvinfo {
 #define KVM_CAP_TSC_CONTROL 60
 #define KVM_CAP_GET_TSC_KHZ 61
 #define KVM_CAP_PPC_BOOKE_SREGS 62
+#define KVM_CAP_SPAPR_TCE 63
+#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
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -746,6 +758,9 @@ struct kvm_clock_data {
 /* Available with KVM_CAP_XCRS */
 #define KVM_GET_XCRS		  _IOR(KVMIO,  0xa6, struct kvm_xcrs)
 #define KVM_SET_XCRS		  _IOW(KVMIO,  0xa7, struct kvm_xcrs)
+#define KVM_CREATE_SPAPR_TCE	  _IOW(KVMIO,  0xa8, struct kvm_create_spapr_tce)
+/* Available with KVM_CAP_RMA */
+#define KVM_ALLOCATE_RMA	  _IOR(KVMIO,  0xa9, struct kvm_allocate_rma)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
 
@@ -773,20 +788,14 @@ struct kvm_assigned_pci_dev {
 
 struct kvm_assigned_irq {
 	__u32 assigned_dev_id;
-	__u32 host_irq;
+	__u32 host_irq; /* ignored (legacy field) */
 	__u32 guest_irq;
 	__u32 flags;
 	union {
-		struct {
-			__u32 addr_lo;
-			__u32 addr_hi;
-			__u32 data;
-		} guest_msi;
 		__u32 reserved[12];
 	};
 };
 
-
 struct kvm_assigned_msix_nr {
 	__u32 assigned_dev_id;
 	__u16 entry_nr;
diff --git a/linux-headers/linux/kvm_para.h b/linux-headers/linux/kvm_para.h
index 7bdcf93..b315e27 100644
--- a/linux-headers/linux/kvm_para.h
+++ b/linux-headers/linux/kvm_para.h
@@ -26,3 +26,4 @@
 #include <asm/kvm_para.h>
 
 #endif /* __LINUX_KVM_PARA_H */
+
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/3] PPC: Enable to use PAPR with PR style KVM
  2011-08-09 16:39 [Qemu-devel] [PATCH 0/3] PPC: Support -M pseries for PR KVM Alexander Graf
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 1/3] KVM: update kernel headers Alexander Graf
@ 2011-08-09 16:39 ` Alexander Graf
  2011-08-10  3:34   ` David Gibson
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info Alexander Graf
  2 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2011-08-09 16:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: paulus, david

When running PR style KVM, we need to tell the kernel that we want
to run in PAPR mode now. This means that we need to pass some more
register information down and enable papr mode. We also need to align
the HTAB to htab_size boundary.

Using this patch, -M pseries works with kvm even on non-hv kvm
implementations, as long as the preceding kernel patches are in.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/spapr.c           |   14 ++++++++++++-
 target-ppc/kvm.c     |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 target-ppc/kvm_ppc.h |    5 ++++
 3 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/hw/spapr.c b/hw/spapr.c
index 07b2165..d56697a 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -38,6 +38,9 @@
 #include "hw/spapr_vio.h"
 #include "hw/xics.h"
 
+#include "kvm.h"
+#include "kvm_ppc.h"
+
 #include <libfdt.h>
 
 #define KERNEL_LOAD_ADDR        0x00000000
@@ -336,12 +339,21 @@ static void ppc_spapr_init(ram_addr_t ram_size,
      * later we should probably make it scale to the size of guest
      * RAM */
     spapr->htab_size = 1ULL << (pteg_shift + 7);
-    spapr->htab = qemu_malloc(spapr->htab_size);
+    spapr->htab = qemu_memalign(spapr->htab_size, spapr->htab_size);
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         env->external_htab = spapr->htab;
         env->htab_base = -1;
         env->htab_mask = spapr->htab_size - 1;
+
+        /* Tell KVM that we're in PAPR mode */
+        env->spr[SPR_SDR1] = (unsigned long)spapr->htab |
+                             ((pteg_shift + 7) - 18);
+        env->spr[SPR_HIOR] = 0;
+
+        if (kvm_enabled()) {
+            kvmppc_set_papr(env);
+        }
     }
 
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "spapr-rtas.bin");
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 219e7a7..02f958f 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -29,6 +29,10 @@
 #include "cpu.h"
 #include "device_tree.h"
 
+#include "hw/sysbus.h"
+#include "hw/spapr.h"
+#include "hw/spapr_vio.h"
+
 //#define DEBUG_KVM
 
 #ifdef DEBUG_KVM
@@ -455,6 +459,14 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
         dprintf("handle halt\n");
         ret = kvmppc_handle_halt(env);
         break;
+#if defined(CONFIG_FDT) && defined(TARGET_PPC64)
+    case KVM_EXIT_PAPR_HCALL:
+        dprintf("handle PAPR hypercall\n");
+        run->papr_hcall.ret = spapr_hypercall(env, run->papr_hcall.nr,
+                                              run->papr_hcall.args);
+        ret = 1;
+        break;
+#endif
     default:
         fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
         ret = -1;
@@ -606,6 +618,47 @@ int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len)
     return 0;
 }
 
+void kvmppc_set_papr(CPUState *env)
+{
+    struct kvm_enable_cap cap;
+    struct kvm_sregs sregs;
+    int ret;
+
+    memset(&cap, 0, sizeof(cap));
+    cap.cap = KVM_CAP_PPC_PAPR;
+    ret = kvm_vcpu_ioctl(env, KVM_ENABLE_CAP, &cap);
+
+    if (ret) {
+        goto fail;
+    }
+
+    /*
+     * XXX We set HIOR here. It really should be a qdev property of
+     *     the CPU node, but we don't have CPUs converted to qdev yet.
+     *
+     *     Once we have qdev CPUs, move HIOR to a qdev property and
+     *     remove this chunk.
+     */
+    memset(&sregs, 0, sizeof(sregs));
+    ret = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs);
+    if (ret) {
+        goto fail;
+    }
+
+    sregs.u.s.flags |= KVM_SREGS_S_HIOR;
+    sregs.u.s.hior = env->spr[SPR_HIOR];
+    sregs.u.s.sdr1 = env->spr[SPR_SDR1];
+    ret = kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs);
+    if (ret) {
+        goto fail;
+    }
+
+    return;
+
+fail:
+    cpu_abort(env, "This KVM version does not support PAPR\n");
+}
+
 bool kvm_arch_stop_on_emulation_error(CPUState *env)
 {
     return true;
diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h
index 76f98d9..809b8b4 100644
--- a/target-ppc/kvm_ppc.h
+++ b/target-ppc/kvm_ppc.h
@@ -17,6 +17,7 @@ uint32_t kvmppc_get_tbfreq(void);
 uint64_t kvmppc_get_clockfreq(void);
 int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len);
 int kvmppc_set_interrupt(CPUState *env, int irq, int level);
+void kvmppc_set_papr(CPUState *env);
 
 #else
 
@@ -40,6 +41,10 @@ static inline int kvmppc_set_interrupt(CPUState *env, int irq, int level)
     return -1;
 }
 
+static void kvmppc_set_papr(CPUState *env)
+{
+}
+
 #endif
 
 #ifndef CONFIG_KVM
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info
  2011-08-09 16:39 [Qemu-devel] [PATCH 0/3] PPC: Support -M pseries for PR KVM Alexander Graf
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 1/3] KVM: update kernel headers Alexander Graf
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 2/3] PPC: Enable to use PAPR with PR style KVM Alexander Graf
@ 2011-08-09 16:39 ` Alexander Graf
  2011-08-10  3:35   ` David Gibson
  2 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2011-08-09 16:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: paulus, david

One of the things we can't fake on PPC is the timer speed. So
we need to extract the frequency information from the host and
put it back into the guest device tree.

Luckily, we already have functions for that from the non-pseries
targets, so all we need to do is to connect the dots and the guest
suddenly gets to know its real timer speeds.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/spapr.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/spapr.c b/hw/spapr.c
index d56697a..a73f38a 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -140,6 +140,8 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
         char *nodename;
         uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40),
                            0xffffffff, 0xffffffff};
+        uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TIMEBASE_FREQ;
+        uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000;
 
         if (asprintf(&nodename, "%s@%x", modelname, index) < 0) {
             fprintf(stderr, "Allocation failure\n");
@@ -158,10 +160,8 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
                                 env->dcache_line_size)));
         _FDT((fdt_property_cell(fdt, "icache-block-size",
                                 env->icache_line_size)));
-        _FDT((fdt_property_cell(fdt, "timebase-frequency", TIMEBASE_FREQ)));
-        /* Hardcode CPU frequency for now.  It's kind of arbitrary on
-         * full emu, for kvm we should copy it from the host */
-        _FDT((fdt_property_cell(fdt, "clock-frequency", 1000000000)));
+        _FDT((fdt_property_cell(fdt, "timebase-frequency", tbfreq)));
+        _FDT((fdt_property_cell(fdt, "clock-frequency", cpufreq)));
         _FDT((fdt_property_cell(fdt, "ibm,slb-size", env->slb_nr)));
         _FDT((fdt_property(fdt, "ibm,pft-size",
                            pft_size_prop, sizeof(pft_size_prop))));
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 2/3] PPC: Enable to use PAPR with PR style KVM
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 2/3] PPC: Enable to use PAPR with PR style KVM Alexander Graf
@ 2011-08-10  3:34   ` David Gibson
  0 siblings, 0 replies; 7+ messages in thread
From: David Gibson @ 2011-08-10  3:34 UTC (permalink / raw)
  To: Alexander Graf; +Cc: paulus, qemu-devel

On Tue, Aug 09, 2011 at 06:39:29PM +0200, Alexander Graf wrote:
> When running PR style KVM, we need to tell the kernel that we want
> to run in PAPR mode now. This means that we need to pass some more
> register information down and enable papr mode. We also need to align
> the HTAB to htab_size boundary.
> 
> Using this patch, -M pseries works with kvm even on non-hv kvm
> implementations, as long as the preceding kernel patches are in.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  hw/spapr.c           |   14 ++++++++++++-
>  target-ppc/kvm.c     |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  target-ppc/kvm_ppc.h |    5 ++++
>  3 files changed, 71 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/spapr.c b/hw/spapr.c
> index 07b2165..d56697a 100644
> --- a/hw/spapr.c
> +++ b/hw/spapr.c
> @@ -38,6 +38,9 @@
>  #include "hw/spapr_vio.h"
>  #include "hw/xics.h"
>  
> +#include "kvm.h"
> +#include "kvm_ppc.h"
> +
>  #include <libfdt.h>
>  
>  #define KERNEL_LOAD_ADDR        0x00000000
> @@ -336,12 +339,21 @@ static void ppc_spapr_init(ram_addr_t ram_size,
>       * later we should probably make it scale to the size of guest
>       * RAM */
>      spapr->htab_size = 1ULL << (pteg_shift + 7);
> -    spapr->htab = qemu_malloc(spapr->htab_size);
> +    spapr->htab = qemu_memalign(spapr->htab_size, spapr->htab_size);
>  
>      for (env = first_cpu; env != NULL; env = env->next_cpu) {
>          env->external_htab = spapr->htab;
>          env->htab_base = -1;
>          env->htab_mask = spapr->htab_size - 1;
> +
> +        /* Tell KVM that we're in PAPR mode */
> +        env->spr[SPR_SDR1] = (unsigned long)spapr->htab |
> +                             ((pteg_shift + 7) - 18);
> +        env->spr[SPR_HIOR] = 0;
> +
> +        if (kvm_enabled()) {
> +            kvmppc_set_papr(env);
> +        }
>      }
>  
>      filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "spapr-rtas.bin");
> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
> index 219e7a7..02f958f 100644
> --- a/target-ppc/kvm.c
> +++ b/target-ppc/kvm.c
> @@ -29,6 +29,10 @@
>  #include "cpu.h"
>  #include "device_tree.h"
>  
> +#include "hw/sysbus.h"
> +#include "hw/spapr.h"
> +#include "hw/spapr_vio.h"
> +
>  //#define DEBUG_KVM
>  
>  #ifdef DEBUG_KVM
> @@ -455,6 +459,14 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
>          dprintf("handle halt\n");
>          ret = kvmppc_handle_halt(env);
>          break;
> +#if defined(CONFIG_FDT) && defined(TARGET_PPC64)

We should hack up configure to give us a CONFIG_PSERIES variable,
instead of duplicating this horrid logic in multiple places
(especially since it will later become CONFIG_FDT && TARGET_PPC64 &&
CONFIG_IOMMU.

> +    case KVM_EXIT_PAPR_HCALL:
> +        dprintf("handle PAPR hypercall\n");
> +        run->papr_hcall.ret = spapr_hypercall(env, run->papr_hcall.nr,
> +                                              run->papr_hcall.args);
> +        ret = 1;
> +        break;
> +#endif
>      default:
>          fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
>          ret = -1;
> @@ -606,6 +618,47 @@ int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len)
>      return 0;
>  }
>  
> +void kvmppc_set_papr(CPUState *env)
> +{
> +    struct kvm_enable_cap cap;
> +    struct kvm_sregs sregs;
> +    int ret;
> +
> +    memset(&cap, 0, sizeof(cap));
> +    cap.cap = KVM_CAP_PPC_PAPR;
> +    ret = kvm_vcpu_ioctl(env, KVM_ENABLE_CAP, &cap);
> +
> +    if (ret) {
> +        goto fail;
> +    }
> +
> +    /*
> +     * XXX We set HIOR here. It really should be a qdev property of
> +     *     the CPU node, but we don't have CPUs converted to qdev yet.
> +     *
> +     *     Once we have qdev CPUs, move HIOR to a qdev property and
> +     *     remove this chunk.
> +     */
> +    memset(&sregs, 0, sizeof(sregs));
> +    ret = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs);
> +    if (ret) {
> +        goto fail;
> +    }
> +
> +    sregs.u.s.flags |= KVM_SREGS_S_HIOR;
> +    sregs.u.s.hior = env->spr[SPR_HIOR];
> +    sregs.u.s.sdr1 = env->spr[SPR_SDR1];
> +    ret = kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs);
> +    if (ret) {
> +        goto fail;
> +    }
> +
> +    return;
> +
> +fail:
> +    cpu_abort(env, "This KVM version does not support PAPR\n");
> +}
> +
>  bool kvm_arch_stop_on_emulation_error(CPUState *env)
>  {
>      return true;
> diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h
> index 76f98d9..809b8b4 100644
> --- a/target-ppc/kvm_ppc.h
> +++ b/target-ppc/kvm_ppc.h
> @@ -17,6 +17,7 @@ uint32_t kvmppc_get_tbfreq(void);
>  uint64_t kvmppc_get_clockfreq(void);
>  int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len);
>  int kvmppc_set_interrupt(CPUState *env, int irq, int level);
> +void kvmppc_set_papr(CPUState *env);
>  
>  #else
>  
> @@ -40,6 +41,10 @@ static inline int kvmppc_set_interrupt(CPUState *env, int irq, int level)
>      return -1;
>  }
>  
> +static void kvmppc_set_papr(CPUState *env)
> +{

Shouldn't this have a cpu_error or assert or something, since it
should never be called if !kvm_enabled().

> +}
> +
>  #endif
>  
>  #ifndef CONFIG_KVM

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info
  2011-08-09 16:39 ` [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info Alexander Graf
@ 2011-08-10  3:35   ` David Gibson
  2011-08-10  7:50     ` Alexander Graf
  0 siblings, 1 reply; 7+ messages in thread
From: David Gibson @ 2011-08-10  3:35 UTC (permalink / raw)
  To: Alexander Graf; +Cc: paulus, qemu-devel

On Tue, Aug 09, 2011 at 06:39:30PM +0200, Alexander Graf wrote:
> One of the things we can't fake on PPC is the timer speed. So
> we need to extract the frequency information from the host and
> put it back into the guest device tree.
> 
> Luckily, we already have functions for that from the non-pseries
> targets, so all we need to do is to connect the dots and the guest
> suddenly gets to know its real timer speeds.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  hw/spapr.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/spapr.c b/hw/spapr.c
> index d56697a..a73f38a 100644
> --- a/hw/spapr.c
> +++ b/hw/spapr.c
> @@ -140,6 +140,8 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
>          char *nodename;
>          uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40),
>                             0xffffffff, 0xffffffff};
> +        uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TIMEBASE_FREQ;
> +        uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000;

Um.. I see the kvmppc_get_tbfreq() function but not the
kvmppc_get_clockfreq() function in my tree (pulled from upstream this
morning).  Is that something new in your ppc patch queue?

>          if (asprintf(&nodename, "%s@%x", modelname, index) < 0) {
>              fprintf(stderr, "Allocation failure\n");
> @@ -158,10 +160,8 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
>                                  env->dcache_line_size)));
>          _FDT((fdt_property_cell(fdt, "icache-block-size",
>                                  env->icache_line_size)));
> -        _FDT((fdt_property_cell(fdt, "timebase-frequency", TIMEBASE_FREQ)));
> -        /* Hardcode CPU frequency for now.  It's kind of arbitrary on
> -         * full emu, for kvm we should copy it from the host */
> -        _FDT((fdt_property_cell(fdt, "clock-frequency", 1000000000)));
> +        _FDT((fdt_property_cell(fdt, "timebase-frequency", tbfreq)));
> +        _FDT((fdt_property_cell(fdt, "clock-frequency", cpufreq)));
>          _FDT((fdt_property_cell(fdt, "ibm,slb-size", env->slb_nr)));
>          _FDT((fdt_property(fdt, "ibm,pft-size",
>                             pft_size_prop, sizeof(pft_size_prop))));

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info
  2011-08-10  3:35   ` David Gibson
@ 2011-08-10  7:50     ` Alexander Graf
  0 siblings, 0 replies; 7+ messages in thread
From: Alexander Graf @ 2011-08-10  7:50 UTC (permalink / raw)
  To: David Gibson; +Cc: paulus, qemu-devel


Am 10.08.2011 um 05:35 schrieb David Gibson <david@gibson.dropbear.id.au>:

> On Tue, Aug 09, 2011 at 06:39:30PM +0200, Alexander Graf wrote:
>> One of the things we can't fake on PPC is the timer speed. So
>> we need to extract the frequency information from the host and
>> put it back into the guest device tree.
>> 
>> Luckily, we already have functions for that from the non-pseries
>> targets, so all we need to do is to connect the dots and the guest
>> suddenly gets to know its real timer speeds.
>> 
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> ---
>> hw/spapr.c |    8 ++++----
>> 1 files changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/hw/spapr.c b/hw/spapr.c
>> index d56697a..a73f38a 100644
>> --- a/hw/spapr.c
>> +++ b/hw/spapr.c
>> @@ -140,6 +140,8 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
>>         char *nodename;
>>         uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40),
>>                            0xffffffff, 0xffffffff};
>> +        uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TIMEBASE_FREQ;
>> +        uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000;
> 
> Um.. I see the kvmppc_get_tbfreq() function but not the
> kvmppc_get_clockfreq() function in my tree (pulled from upstream this
> morning).  Is that something new in your ppc patch queue?

Yes, it's part of the SMP patch set for e500 :)

Alex

> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-10  7:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-09 16:39 [Qemu-devel] [PATCH 0/3] PPC: Support -M pseries for PR KVM Alexander Graf
2011-08-09 16:39 ` [Qemu-devel] [PATCH 1/3] KVM: update kernel headers Alexander Graf
2011-08-09 16:39 ` [Qemu-devel] [PATCH 2/3] PPC: Enable to use PAPR with PR style KVM Alexander Graf
2011-08-10  3:34   ` David Gibson
2011-08-09 16:39 ` [Qemu-devel] [PATCH 3/3] PPC: SPAPR: Use KVM function for time info Alexander Graf
2011-08-10  3:35   ` David Gibson
2011-08-10  7:50     ` Alexander Graf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.