Skip to contentSkip to conversation

spapr: Enable ibm, client-architecture-support

PATCH Superseded Alexey Kardashevskiy 3 participants 29 messages May 15, 2014 – May 21, 2014

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover spapr: Enable ibm, client-architecture-support

This enables a ibm,client-architecture-support RTAS call.

This allows older distros (such as SLES11 or RHEL6) to work on modern POWERPC hardware (such as POWER8) in "architected" mode.

The previous try was "RFC", so this is "v1".

The very first patch here is for the reference, it is already on its way to upstream.

Please comment. Thanks!

Alexey Kardashevskiy (9):
kvm: add set_one_reg/get_one_reg helpers
target-ppc: Add "compat" CPU option
spapr: Move server# property out of skeleton fdt
target-ppc: Implement "compat" CPU option
target-ppc: Define Processor Compatibility Masks
spapr: Add ibm,client-architecture-support call
spapr: Limit threads per core according to current compatibility mode
spapr: Implement processor compatibility in
ibm,client-architecture-support
KVM: PPC: Enable compatibility mode

 hw/ppc/spapr.c              | 149 +++++++++++++++++++++++++++++++++++++++-----
 hw/ppc/spapr_hcall.c        | 108 ++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h      |   9 ++-
 include/sysemu/kvm.h        |  21 +++++++
 kvm-all.c                   |  18 ++++++
 target-ppc/cpu-models.h     |  17 +++++
 target-ppc/cpu-qom.h        |   5 ++
 target-ppc/cpu.h            |   3 +
 target-ppc/kvm.c            |   5 ++
 target-ppc/kvm_ppc.h        |   6 ++
 target-ppc/translate_init.c | 113 +++++++++++++++++++++++++++++++++
 trace-events                |   9 +++
 12 files changed, 446 insertions(+), 17 deletions(-)
Signature · 1 line
1.9.rc0
#1 lore raw

PATCH 1/9 kvm: add set_one_reg/get_one_reg helpers

This adds QEMU wrappers for KVM_SET_ONE_REG/KVM_GET_ONE_REG ioctls.

---
Changes:
v3:
* changed comments

v2:
* added Doc Comments
* removed error_print

---
 include/sysemu/kvm.h | 21 +++++++++++++++++++++
 kvm-all.c            | 18 ++++++++++++++++++
 2 files changed, 39 insertions(+)
include/sysemu/kvm.h +21 -0
index 63e241a..b1566a4 100644
@@ -383,4 +383,25 @@ void kvm_init_irq_routing(KVMState *s);
  *          > 0: irq chip was created
  */
 int kvm_arch_irqchip_create(KVMState *s);
+
+/**
+ * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
+ * @id: The register ID
+ * @addr: The pointer to a value must point to a variable of the correct
+ * type/size for the register being accessed.
+ *
+ * Returns: 0 on success, or a negative errno on failure.
+ */
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr);
+
+/**
+ * kvm_get_one_reg - get a register value from KVM via KVM_GET_ONE_REG ioctl
+ * @id: The register ID
+ * @addr: The pointer to a value must point to a variable of the correct
+ * type/size for the register being accessed.
+ *
+ * Returns: 0 on success, or a negative errno on failure.
+ */
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr);
+
 #endif
kvm-all.c +18 -0
index 5cb7f26..ebb1afa 100644
@@ -2114,3 +2114,21 @@ int kvm_create_device(KVMState *s, uint64_t type, bool test)
 
     return test ? 0 : create_dev.fd;
 }
+
+int kvm_set_one_reg(CPUState *cs, uint64_t id, void *addr)
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+}
+
+int kvm_get_one_reg(CPUState *cs, uint64_t id, void *addr)
+{
+    struct kvm_one_reg reg = {
+        .id = id,
+        .addr = (uintptr_t)addr,
+    };
+    return kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+}
Signature · 1 line
1.9.rc0
#2 lore raw

PATCH 2/9 target-ppc: Add "compat" CPU option

In reply to Alexey Kardashevskiy

PowerISA defines a compatibility mode for server POWERPC CPUs which is supported by the PCR special register. To support this feature, SPAPR defines a set of virtual PVRs, once per PowerISA spec version.

This introduces a "compat" CPU option which defines maximal compatibility mode enabled. The supported modes are power6/power7/power8.

This does not change the existing behaviour, new property will be used by next patches.

---
 target-ppc/cpu-models.h     | 11 +++++++
 target-ppc/cpu-qom.h        |  2 ++
 target-ppc/translate_init.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+)
target-ppc/cpu-models.h +11 -0
index 9a003b4..33d2c51 100644
@@ -595,6 +595,17 @@ enum {
     CPU_POWERPC_PA6T               = 0x00900000,
 };
 
+/* Logical PVR definitions for sPAPR */
+enum {
+    /* Logical CPUs */
+    CPU_POWERPC_LOGICAL_2_04       = 0x0F000001,
+    CPU_POWERPC_LOGICAL_2_05       = 0x0F000002,
+    CPU_POWERPC_LOGICAL_2_06       = 0x0F000003,
+    CPU_POWERPC_LOGICAL_2_06_PLUS  = 0x0F100003,
+    CPU_POWERPC_LOGICAL_2_07       = 0x0F000004,
+    CPU_POWERPC_LOGICAL_2_08       = 0x0F000005,
+};
+
 /* System version register (used on MPC 8xxx)                                */
 enum {
     POWERPC_SVR_NONE               = 0x00000000,
target-ppc/cpu-qom.h +2 -0
index 47dc8e6..2a8515b 100644
@@ -82,6 +82,7 @@ typedef struct PowerPCCPUClass {
  * PowerPCCPU:
  * @env: #CPUPPCState
  * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
+ * @max_compat: Maximal supported logical PVR from the command line
  *
  * A PowerPC CPU.
  */
@@ -92,6 +93,7 @@ struct PowerPCCPU {
 
     CPUPPCState env;
     int cpu_dt_id;
+    uint32_t max_compat;
 };
 
 static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/translate_init.c +75 -0

105 lines not on this page · raw message

Signature · 1 line
1.9.rc0
#3 lore raw

PATCH 3/9 spapr: Move server# property out of skeleton fdt

In reply to Alexey Kardashevskiy

The upcoming support of the "ibm,client-architecture-support" reconfiguration method will be able to reduce the number of threads per core so the server# and gserver# device tree properties are not parts of the FDT skeleton anymore.

---
 hw/ppc/spapr.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
hw/ppc/spapr.c +22 -15
index 166c1c6..0f8bd95 100644
@@ -219,6 +219,9 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
                                     cpu_to_be32(0x0),
                                     cpu_to_be32(cpu->numa_node),
                                     cpu_to_be32(index)};
+        uint32_t servers_prop[smp_threads];
+        uint32_t gservers_prop[smp_threads * 2];
+        int i;
 
         if ((index % smt) != 0) {
             continue;
@@ -245,6 +248,24 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
         if (ret < 0) {
             return ret;
         }
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smp_threads; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;
+        }
+        ret = fdt_setprop(fdt, offset, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop));
+        if (ret < 0) {
+            return ret;
+        }
+        ret = fdt_setprop(fdt, offset, "ibm,ppc-interrupt-gserver#s",
+                          gservers_prop, sizeof(gservers_prop));
+        if (ret < 0) {
+            return ret;
+        }
     }
     return ret;
 }
@@ -311,7 +332,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
     char qemu_hypertas_prop[] = "hcall-memop1";
     uint32_t refpoints[] = {cpu_to_be32(0x4), cpu_to_be32(0x4)};
     uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(smp_cpus)};
-    int i, smt = kvmppc_smt_threads();
+    int smt = kvmppc_smt_threads();
     unsigned char vec5[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x80};
     QemuOpts *opts = qemu_opts_find(qemu_find_opts("smp-opts"), NULL);
     unsigned sockets = opts ? qemu_opt_get_number(opts, "sockets", 0) : 0;
@@ -378,8 +399,6 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
         DeviceClass *dc = DEVICE_GET_CLASS(cs);
         PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs);
         int index = ppc_get_vcpu_dt_id(cpu);
-        uint32_t servers_prop[smp_threads];
-        uint32_t gservers_prop[smp_threads * 2];
         char *nodename;
         uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40),
                            0xffffffff, 0xffffffff};
@@ -428,18 +447,6 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
         _FDT((fdt_property_string(fdt, "status", "okay")));
         _FDT((fdt_property(fdt, "64-bit", NULL, 0)));
 
-        /* Build interrupt servers and gservers properties */
-        for (i = 0; i < smp_threads; i++) {
-            servers_prop[i] = cpu_to_be32(index + i);
-            /* Hack, direct the group queues back to cpu 0 */
-            gservers_prop[i*2] = cpu_to_be32(index + i);
-            gservers_prop[i*2 + 1] = 0;
-        }
-        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
-                           servers_prop, sizeof(servers_prop))));
-        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
-                           gservers_prop, sizeof(gservers_prop))));
-
         if (env->spr_cb[SPR_PURR].oea_read) {
             _FDT((fdt_property(fdt, "ibm,purr", NULL, 0)));
         }
Signature · 1 line
1.9.rc0
#4 lore raw

PATCH 4/9 target-ppc: Implement "compat" CPU option

In reply to Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
 hw/ppc/spapr.c              | 15 ++++++++++++++-
 target-ppc/cpu-models.h     |  6 ++++++
 target-ppc/cpu-qom.h        |  2 ++
 target-ppc/cpu.h            |  3 +++
 target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
 5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +14 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
 
     CPU_FOREACH(cpu) {
         DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
         uint32_t associativity[] = {cpu_to_be32(0x5),
                                     cpu_to_be32(0x0),
                                     cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
             return ret;
         }
 
+        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version, sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
         /* Build interrupt servers and gservers properties */
         for (i = 0; i < smp_threads; i++) {
             servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
             kvmppc_set_papr(cpu);
         }
 
+        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
         xics_cpu_setup(spapr->icp, cpu);
 
         qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +6 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
     POWERPC_SVR_8641D              = 0x80900121,
 };
 
+/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
 #endif
target-ppc/cpu-qom.h +2 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
  * @env: #CPUPPCState
  * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
  * @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode
  *
  * A PowerPC CPU.
  */
@@ -94,6 +95,7 @@ struct PowerPCCPU {
     CPUPPCState env;
     int cpu_dt_id;
     uint32_t max_compat;
+    uint32_t cpu_version;
 };
 
 static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +3 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong value);
 
 void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
 
+void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
 /* Time-base and decrementer management */
 #ifndef NO_CPU_IO_DEFS
 uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
 #define SPR_LPCR              (0x13E)
 #define SPR_BOOKE_DVC2        (0x13F)
 #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
 #define SPR_BOOKE_TCR         (0x154)
 #define SPR_BOOKE_TLB0PS      (0x158)
 #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +35 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
     /* Can't find information on what this should be on reset.  This
      * value is the one used by 74xx processors. */
     vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
 }
 
 POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
     }
 }
 
+void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    default:
+        env->spr[SPR_PCR] = 0;
+        break;
+    }
+}
+
 static gint ppc_cpu_compare_class_pvr(gconstpointer a, gconstpointer b)
 {
     ObjectClass *oc = (ObjectClass *)a;
Signature · 1 line
1.9.rc0
#5 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 146 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
  hw/ppc/spapr.c              | 15 ++++++++++++++-
  target-ppc/cpu-models.h     |  6 ++++++
  target-ppc/cpu-qom.h        |  2 ++
  target-ppc/cpu.h            |  3 +++
  target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
  5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +14 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
 
      CPU_FOREACH(cpu) {
          DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
          uint32_t associativity[] = {cpu_to_be32(0x5),
                                      cpu_to_be32(0x0),
                                      cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
              return ret;
          }
 
+        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version, sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
          /* Build interrupt servers and gservers properties */
          for (i = 0; i < smp_threads; i++) {
              servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
              kvmppc_set_papr(cpu);
          }
 
+        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
          xics_cpu_setup(spapr->icp, cpu);
 
          qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +6 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
      POWERPC_SVR_8641D              = 0x80900121,
  };
 
+/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
  #endif
target-ppc/cpu-qom.h +2 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
   * @env: #CPUPPCState
   * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
   * @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode
   *
   * A PowerPC CPU.
   */
@@ -94,6 +95,7 @@ struct PowerPCCPU {
      CPUPPCState env;
      int cpu_dt_id;
      uint32_t max_compat;
+    uint32_t cpu_version;
  };
 
  static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +3 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong value);
 
  void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
 
+void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
  /* Time-base and decrementer management */
  #ifndef NO_CPU_IO_DEFS
  uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
  #define SPR_LPCR              (0x13E)
  #define SPR_BOOKE_DVC2        (0x13F)
  #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
  #define SPR_BOOKE_TCR         (0x154)
  #define SPR_BOOKE_TLB0PS      (0x158)
  #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +19 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
      /* Can't find information on what this should be on reset.  This
       * value is the one used by 74xx processors. */
      vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
  }
 
  POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
      }
  }
 
+void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

#define   PCR_VEC_DIS   (1ul << (63-0)) /* Vec. disable (bit NA since POWER8) */
#define   PCR_VSX_DIS   (1ul << (63-1)) /* VSX disable (bit NA since POWER8) */
#define   PCR_TM_DIS    (1ul << (63-2)) /* Trans. memory disable (POWER8) */

In fact, we probably want those bits always set when compat < power8.

Alex

#6 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 156 lines · Alexander Graf
Quoted 141 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
  hw/ppc/spapr.c              | 15 ++++++++++++++-
  target-ppc/cpu-models.h     |  6 ++++++
  target-ppc/cpu-qom.h        |  2 ++
  target-ppc/cpu.h            |  3 +++
  target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
  5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
        CPU_FOREACH(cpu) {
          DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
          uint32_t associativity[] = {cpu_to_be32(0x5),
                                      cpu_to_be32(0x0),
                                      cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
              return ret;
          }
  +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
          /* Build interrupt servers and gservers properties */
          for (i = 0; i < smp_threads; i++) {
              servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
              kvmppc_set_papr(cpu);
          }
  +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
          xics_cpu_setup(spapr->icp, cpu);
            qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
      POWERPC_SVR_8641D              = 0x80900121,
  };
  +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
  #endif
target-ppc/cpu-qom.h +2 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
   * @env: #CPUPPCState
   * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
   * @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode
   *
   * A PowerPC CPU.
   */
@@ -94,6 +95,7 @@ struct PowerPCCPU {
      CPUPPCState env;
      int cpu_dt_id;
      uint32_t max_compat;
+    uint32_t cpu_version;
  };
    static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +2 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong
 value);
    void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
  +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
  /* Time-base and decrementer management */
  #ifndef NO_CPU_IO_DEFS
  uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
  #define SPR_LPCR              (0x13E)
  #define SPR_BOOKE_DVC2        (0x13F)
  #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
  #define SPR_BOOKE_TCR         (0x154)
  #define SPR_BOOKE_TLB0PS      (0x158)
  #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +18 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
      /* Can't find information on what this should be on reset.  This
       * value is the one used by 74xx processors. */
      vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
  }
    POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev,
 Error **errp)
      }
  }
  +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

Quoted 5 lines

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable (POWER8) */

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Why? VSX is present on power7. VEC is defined in 2.06 too.

Signature · 1 line
Alexey
#7 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 160 lines · Alexey Kardashevskiy
Quoted 154 lines · Alexander Graf
Quoted 141 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
   hw/ppc/spapr.c              | 15 ++++++++++++++-
   target-ppc/cpu-models.h     |  6 ++++++
   target-ppc/cpu-qom.h        |  2 ++
   target-ppc/cpu.h            |  3 +++
   target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
   5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
         CPU_FOREACH(cpu) {
           DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
           uint32_t associativity[] = {cpu_to_be32(0x5),
                                       cpu_to_be32(0x0),
                                       cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
               return ret;
           }
   +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
           /* Build interrupt servers and gservers properties */
           for (i = 0; i < smp_threads; i++) {
               servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
               kvmppc_set_papr(cpu);
           }
   +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
           xics_cpu_setup(spapr->icp, cpu);
             qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
       POWERPC_SVR_8641D              = 0x80900121,
   };
   +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
   #endif
target-ppc/cpu-qom.h +2 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
    * @env: #CPUPPCState
    * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
    * @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode
    *
    * A PowerPC CPU.
    */
@@ -94,6 +95,7 @@ struct PowerPCCPU {
       CPUPPCState env;
       int cpu_dt_id;
       uint32_t max_compat;
+    uint32_t cpu_version;
   };
     static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +2 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong
 value);
     void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
   +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
   /* Time-base and decrementer management */
   #ifndef NO_CPU_IO_DEFS
   uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
   #define SPR_LPCR              (0x13E)
   #define SPR_BOOKE_DVC2        (0x13F)
   #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
   #define SPR_BOOKE_TCR         (0x154)
   #define SPR_BOOKE_TLB0PS      (0x158)
   #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +18 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
       /* Can't find information on what this should be on reset.  This
        * value is the one used by 74xx processors. */
       vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
   }
     POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev,
 Error **errp)
       }
   }
   +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

Quoted 5 lines

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable (POWER8) */

Quoted 4 lines

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Why? VSX is present on power7. VEC is defined in 2.06 too.

True. So how does pre-p8 treat those p8 and above bits?

Alex

#8 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 165 lines · Alexander Graf
Quoted 163 lines · Alexey Kardashevskiy
Quoted 162 lines · Alexander Graf
Quoted 143 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
   hw/ppc/spapr.c              | 15 ++++++++++++++-
   target-ppc/cpu-models.h     |  6 ++++++
   target-ppc/cpu-qom.h        |  2 ++
   target-ppc/cpu.h            |  3 +++
   target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
   5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
         CPU_FOREACH(cpu) {
           DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
           uint32_t associativity[] = {cpu_to_be32(0x5),
                                       cpu_to_be32(0x0),
                                       cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
               return ret;
           }
   +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
           /* Build interrupt servers and gservers properties */
           for (i = 0; i < smp_threads; i++) {
               servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs
 *args)
               kvmppc_set_papr(cpu);
           }
   +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
           xics_cpu_setup(spapr->icp, cpu);
             qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
       POWERPC_SVR_8641D              = 0x80900121,
   };
   +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
   #endif
target-ppc/cpu-qom.h +0 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
    * @env: #CPUPPCState
    * @cpu_dt_id: CPU index used in the device tree. KVM uses this

index too
* @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode

    *
    * A PowerPC CPU.
    */
target-ppc/cpu-qom.h +1 -0
@@ -94,6 +95,7 @@ struct PowerPCCPU {
       CPUPPCState env;
       int cpu_dt_id;
       uint32_t max_compat;
+    uint32_t cpu_version;
   };
     static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +2 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong
 value);
     void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
   +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
   /* Time-base and decrementer management */
   #ifndef NO_CPU_IO_DEFS
   uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
   #define SPR_LPCR              (0x13E)
   #define SPR_BOOKE_DVC2        (0x13F)
   #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
   #define SPR_BOOKE_TCR         (0x154)
   #define SPR_BOOKE_TLB0PS      (0x158)
   #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +18 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
       /* Can't find information on what this should be on reset.  This
        * value is the one used by 74xx processors. */
       vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
   }
     POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev,
 Error **errp)
       }
   }
   +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable
(POWER8) */

Quoted 6 lines
Quoted 4 lines

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Why? VSX is present on power7. VEC is defined in 2.06 too.

True. So how does pre-p8 treat those p8 and above bits?

PowerISA 2.07 says if 2.06 mode is selected, the TM bit does not matter anymore - TM will be disabled because 2.06 does not define it at all. The same is true for VSX and 2.05 mode. So just setting a mode must be ok.

Signature · 1 line
Alexey
#9 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 165 lines · Alexey Kardashevskiy
Quoted 164 lines · Alexander Graf
Quoted 163 lines · Alexey Kardashevskiy
Quoted 162 lines · Alexander Graf
Quoted 143 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
    hw/ppc/spapr.c              | 15 ++++++++++++++-
    target-ppc/cpu-models.h     |  6 ++++++
    target-ppc/cpu-qom.h        |  2 ++
    target-ppc/cpu.h            |  3 +++
    target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
    5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
          CPU_FOREACH(cpu) {
            DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
            uint32_t associativity[] = {cpu_to_be32(0x5),
                                        cpu_to_be32(0x0),
                                        cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
                return ret;
            }
    +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
            /* Build interrupt servers and gservers properties */
            for (i = 0; i < smp_threads; i++) {
                servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs
 *args)
                kvmppc_set_papr(cpu);
            }
    +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
            xics_cpu_setup(spapr->icp, cpu);
              qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
        POWERPC_SVR_8641D              = 0x80900121,
    };
    +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
    #endif
target-ppc/cpu-qom.h +0 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
     * @env: #CPUPPCState
     * @cpu_dt_id: CPU index used in the device tree. KVM uses this

index too
* @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode

     *
     * A PowerPC CPU.
     */
target-ppc/cpu-qom.h +1 -0
@@ -94,6 +95,7 @@ struct PowerPCCPU {
        CPUPPCState env;
        int cpu_dt_id;
        uint32_t max_compat;
+    uint32_t cpu_version;
    };
      static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +2 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong
 value);
      void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
    +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
    /* Time-base and decrementer management */
    #ifndef NO_CPU_IO_DEFS
    uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
    #define SPR_LPCR              (0x13E)
    #define SPR_BOOKE_DVC2        (0x13F)
    #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
    #define SPR_BOOKE_TCR         (0x154)
    #define SPR_BOOKE_TLB0PS      (0x158)
    #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +18 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
        /* Can't find information on what this should be on reset.  This
         * value is the one used by 74xx processors. */
        vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
    }
      POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev,
 Error **errp)
        }
    }
    +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable
(POWER8) */

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Why? VSX is present on power7. VEC is defined in 2.06 too.

True. So how does pre-p8 treat those p8 and above bits?

PowerISA 2.07 says if 2.06 mode is selected, the TM bit does not matter anymore - TM will be disabled because 2.06 does not define it at all. The same is true for VSX and 2.05 mode. So just setting a mode must be ok.

And for POWER8-on-POWER9 (or whatever it will be called) we can just set PCR to the respective feature disable bits. I think that should work.

Alex

#10 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 170 lines · Alexander Graf
Quoted 168 lines · Alexey Kardashevskiy
Quoted 167 lines · Alexander Graf
Quoted 166 lines · Alexey Kardashevskiy
Quoted 156 lines · Alexander Graf
Quoted 143 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
    hw/ppc/spapr.c              | 15 ++++++++++++++-
    target-ppc/cpu-models.h     |  6 ++++++
    target-ppc/cpu-qom.h        |  2 ++
    target-ppc/cpu.h            |  3 +++
    target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
    5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
          CPU_FOREACH(cpu) {
            DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
            uint32_t associativity[] = {cpu_to_be32(0x5),
                                        cpu_to_be32(0x0),
                                        cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
                return ret;
            }
    +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
            /* Build interrupt servers and gservers properties */
            for (i = 0; i < smp_threads; i++) {
                servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs
 *args)
                kvmppc_set_papr(cpu);
            }
    +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
            xics_cpu_setup(spapr->icp, cpu);
              qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
        POWERPC_SVR_8641D              = 0x80900121,
    };
    +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
    #endif
target-ppc/cpu-qom.h +0 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
     * @env: #CPUPPCState
     * @cpu_dt_id: CPU index used in the device tree. KVM uses this

index too
* @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode

     *
     * A PowerPC CPU.
     */
target-ppc/cpu-qom.h +1 -0
@@ -94,6 +95,7 @@ struct PowerPCCPU {
        CPUPPCState env;
        int cpu_dt_id;
        uint32_t max_compat;
+    uint32_t cpu_version;
    };
      static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +2 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong
 value);
      void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
    +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
    /* Time-base and decrementer management */
    #ifndef NO_CPU_IO_DEFS
    uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
    #define SPR_LPCR              (0x13E)
    #define SPR_BOOKE_DVC2        (0x13F)
    #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
    #define SPR_BOOKE_TCR         (0x154)
    #define SPR_BOOKE_TLB0PS      (0x158)
    #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +18 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
        /* Can't find information on what this should be on reset.  This
         * value is the one used by 74xx processors. */
        vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
    }
      POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev,
 Error **errp)
        }
    }
    +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

Quoted 6 lines

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable
(POWER8) */

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Why? VSX is present on power7. VEC is defined in 2.06 too.

True. So how does pre-p8 treat those p8 and above bits?

PowerISA 2.07 says if 2.06 mode is selected, the TM bit does not matter anymore - TM will be disabled because 2.06 does not define it at all. The same is true for VSX and 2.05 mode. So just setting a mode must be ok.

And for POWER8-on-POWER9 (or whatever it will be called) we can just set PCR to the respective feature disable bits. I think that should work.

I lost you here. I suspect it will also have "2.07" compatibility mode and we will use that instead of disabling feature one by one.

Signature · 1 line
Alexey
#11 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 171 lines · Alexey Kardashevskiy
Quoted 170 lines · Alexander Graf
Quoted 169 lines · Alexey Kardashevskiy
Quoted 168 lines · Alexander Graf
Quoted 167 lines · Alexey Kardashevskiy
Quoted 156 lines · Alexander Graf
Quoted 143 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
     hw/ppc/spapr.c              | 15 ++++++++++++++-
     target-ppc/cpu-models.h     |  6 ++++++
     target-ppc/cpu-qom.h        |  2 ++
     target-ppc/cpu.h            |  3 +++
     target-ppc/translate_init.c | 35 +++++++++++++++++++++++++++++++++++
     5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
           CPU_FOREACH(cpu) {
             DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
             uint32_t associativity[] = {cpu_to_be32(0x5),
                                         cpu_to_be32(0x0),
                                         cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
                 return ret;
             }
     +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
             /* Build interrupt servers and gservers properties */
             for (i = 0; i < smp_threads; i++) {
                 servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs
 *args)
                 kvmppc_set_papr(cpu);
             }
     +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
             xics_cpu_setup(spapr->icp, cpu);
               qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
         POWERPC_SVR_8641D              = 0x80900121,
     };
     +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
     #endif
target-ppc/cpu-qom.h +0 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
      * @env: #CPUPPCState
      * @cpu_dt_id: CPU index used in the device tree. KVM uses this

index too
* @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode

      *
      * A PowerPC CPU.
      */
target-ppc/cpu-qom.h +1 -0
@@ -94,6 +95,7 @@ struct PowerPCCPU {
         CPUPPCState env;
         int cpu_dt_id;
         uint32_t max_compat;
+    uint32_t cpu_version;
     };
       static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +2 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env, target_ulong
 value);
       void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
     +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
+
     /* Time-base and decrementer management */
     #ifndef NO_CPU_IO_DEFS
     uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
     #define SPR_LPCR              (0x13E)
     #define SPR_BOOKE_DVC2        (0x13F)
     #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
     #define SPR_BOOKE_TCR         (0x154)
     #define SPR_BOOKE_TLB0PS      (0x158)
     #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +18 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
         /* Can't find information on what this should be on reset.  This
          * value is the one used by 74xx processors. */
         vscr_init(env, 0x00010000);
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
     }
       POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState *dev,
 Error **errp)
         }
     }
     +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState *dev, · line 8911

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

Quoted 6 lines

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable
(POWER8) */

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Why? VSX is present on power7. VEC is defined in 2.06 too.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

True. So how does pre-p8 treat those p8 and above bits?

PowerISA 2.07 says if 2.06 mode is selected, the TM bit does not matter anymore - TM will be disabled because 2.06 does not define it at all. The same is true for VSX and 2.05 mode. So just setting a mode must be ok.

And for POWER8-on-POWER9 (or whatever it will be called) we can just set PCR to the respective feature disable bits. I think that should work.

I lost you here. I suspect it will also have "2.07" compatibility mode and we will use that instead of disabling feature one by one.

Considering that the architects added by-feature bits, I would assume they won't introduce a 2.07 bit but rather make every new feature disableable one by one. But maybe I'm wrong - the point is that either way will work and is future proof ;).

Alex

#12 lore raw

Re: [Qemu-devel] [PATCH 4/9] target-ppc: Implement "compat" CPU option

Quoted 183 lines · Alexander Graf
Quoted 181 lines · Alexey Kardashevskiy
Quoted 180 lines · Alexander Graf
Quoted 179 lines · Alexey Kardashevskiy
Quoted 170 lines · Alexander Graf
Quoted 169 lines · Alexey Kardashevskiy
Quoted 168 lines · Alexander Graf
Quoted 149 lines · Alexey Kardashevskiy

This adds basic support for the "compat" CPU option. By specifying the compat property, the user can manually switch guest CPU mode from "raw" to "architected".

Since the actual compatibility mode is not implemented yet, this does not change the existing behavior.

---
     hw/ppc/spapr.c              | 15 ++++++++++++++-
     target-ppc/cpu-models.h     |  6 ++++++
     target-ppc/cpu-qom.h        |  2 ++
     target-ppc/cpu.h            |  3 +++
     target-ppc/translate_init.c | 35
+++++++++++++++++++++++++++++++++++
     5 files changed, 60 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +12 -1
index 0f8bd95..61d0675 100644
@@ -212,7 +212,8 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
           CPU_FOREACH(cpu) {
             DeviceClass *dc = DEVICE_GET_CLASS(cpu);
-        int index = ppc_get_vcpu_dt_id(POWERPC_CPU(cpu));
+        PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+        int index = ppc_get_vcpu_dt_id(pcpu);
             uint32_t associativity[] = {cpu_to_be32(0x5),
                                         cpu_to_be32(0x0),
                                         cpu_to_be32(0x0),
@@ -249,6 +250,14 @@ static int spapr_fixup_cpu_dt(void *fdt,
 sPAPREnvironment *spapr)
                 return ret;
             }
     +        if (pcpu->cpu_version) {
+            ret = fdt_setprop(fdt, offset, "cpu-version",
+                              &pcpu->cpu_version,
 sizeof(pcpu->cpu_version));
+            if (ret < 0) {
+                return ret;
+            }
+        }
+
             /* Build interrupt servers and gservers properties */
             for (i = 0; i < smp_threads; i++) {
                 servers_prop[i] = cpu_to_be32(index + i);
@@ -1278,6 +1287,10 @@ static void ppc_spapr_init(QEMUMachineInitArgs
 *args)
                 kvmppc_set_papr(cpu);
             }
     +        if (cpu->max_compat) {
+            ppc_set_compat(cpu, cpu->max_compat);
+        }
+
             xics_cpu_setup(spapr->icp, cpu);
               qemu_register_reset(spapr_cpu_reset, cpu);
target-ppc/cpu-models.h +5 -0
index 33d2c51..45c0028 100644
@@ -753,4 +753,10 @@ enum {
         POWERPC_SVR_8641D              = 0x80900121,
     };
     +/* Processor Compatibility mask (PCR) */
+enum {
+    POWERPC_ISA_COMPAT_2_05 = 0x02,
+    POWERPC_ISA_COMPAT_2_06 = 0x04,
+};
+
     #endif
target-ppc/cpu-qom.h +0 -0
index 2a8515b..dfd1419 100644
@@ -83,6 +83,7 @@ typedef struct PowerPCCPUClass {
      * @env: #CPUPPCState
      * @cpu_dt_id: CPU index used in the device tree. KVM uses this

index too
* @max_compat: Maximal supported logical PVR from the command
line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode

      *
      * A PowerPC CPU.
      */
target-ppc/cpu-qom.h +1 -0
@@ -94,6 +95,7 @@ struct PowerPCCPU {
         CPUPPCState env;
         int cpu_dt_id;
         uint32_t max_compat;
+    uint32_t cpu_version;
     };
       static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/cpu.h +0 -0
index d498340..f61675a 100644
@@ -1123,6 +1123,8 @@ void ppc_store_msr (CPUPPCState *env,

target_ulong

value);
       void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
     +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
target-ppc/cpu.h +2 -0
+
     /* Time-base and decrementer management */
     #ifndef NO_CPU_IO_DEFS
     uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
@@ -1338,6 +1340,7 @@ static inline int cpu_mmu_index (CPUPPCState
 *env)
     #define SPR_LPCR              (0x13E)
     #define SPR_BOOKE_DVC2        (0x13F)
     #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
     #define SPR_BOOKE_TCR         (0x154)
     #define SPR_BOOKE_TLB0PS      (0x158)
     #define SPR_BOOKE_TLB1PS      (0x159)
target-ppc/translate_init.c +0 -0
index 6f61b34..c4bd5de 100644
@@ -7803,6 +7803,15 @@ static void init_proc_POWER7 (CPUPPCState *env)
         /* Can't find information on what this should be on

reset. This
* value is the one used by 74xx processors. */
vscr_init(env, 0x00010000);

target-ppc/translate_init.c +18 -0
+
+    /*
+     * Register PCR to report POWERPC_EXCP_PRIV_REG instead of
+     * POWERPC_EXCP_INVAL_SPR.
+     */
+    spr_register(env, SPR_PCR, "PCR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 0x00000000);
     }
       POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
@@ -8880,6 +8889,32 @@ static void ppc_cpu_unrealizefn(DeviceState
 *dev,
 Error **errp)
         }
     }
     +void ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    CPUPPCState *env = &cpu->env;
+
+    cpu->cpu_version = cpu_version;
+
+    /*
+     * Calculate PCR value from virtual PVR.
+     * TODO: support actual compatibility in TCG.
+     */

target-ppc/translate_init.c static void ppc_cpu_unrealizefn(DeviceState · line 8912

Quoted 10 lines
target-ppc/translate_init.c +10 -0
+    switch (cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_05;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06_PLUS:
+        env->spr[SPR_PCR] = POWERPC_ISA_COMPAT_2_06;
+        break;

Don't we have to disable all those fancy p8 features too?

#define PCR_VEC_DIS (1ul << (63-0)) /* Vec. disable (bit NA since
POWER8) */
#define PCR_VSX_DIS (1ul << (63-1)) /* VSX disable (bit NA since
POWER8) */
#define PCR_TM_DIS (1ul << (63-2)) /* Trans. memory disable
(POWER8) */

Quoted 5 lines
Quoted 4 lines

Yep, makes sense to set "TM" for POWER < 8 and VSX+VEC for POWER < 7.

Quoted 1 line

In fact, we probably want those bits always set when compat < power8.

Why? VSX is present on power7. VEC is defined in 2.06 too.

True. So how does pre-p8 treat those p8 and above bits?

PowerISA 2.07 says if 2.06 mode is selected, the TM bit does not matter anymore - TM will be disabled because 2.06 does not define it at all. The same is true for VSX and 2.05 mode. So just setting a mode must be ok.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

And for POWER8-on-POWER9 (or whatever it will be called) we can just set PCR to the respective feature disable bits. I think that should work.

I lost you here. I suspect it will also have "2.07" compatibility mode and we will use that instead of disabling feature one by one.

Considering that the architects added by-feature bits, I would assume they won't introduce a 2.07 bit but rather make every new feature disableable one by one.

2.05 defines PCR_VEC_DIS already and since then 2 specs were released so it is unlikely to happen :)

Quoted 2 lines

But maybe I'm wrong - the point is that either way will work and is future proof ;).

Signature · 1 line
Alexey
#13 lore raw

PATCH 5/9 target-ppc: Define Processor Compatibility Masks

In reply to Alexey Kardashevskiy

This introduces PCR mask for supported compatibility modes. This will be used later by the ibm,client-architecture-support call.

---
 target-ppc/cpu-qom.h        | 1 +
 target-ppc/translate_init.c | 3 +++
 2 files changed, 4 insertions(+)
target-ppc/cpu-qom.h +1 -0
index dfd1419..093f09a 100644
@@ -57,6 +57,7 @@ typedef struct PowerPCCPUClass {
 
     uint32_t pvr;
     uint32_t pvr_mask;
+    uint64_t pcr_mask;
     uint32_t svr;
     uint64_t insns_flags;
     uint64_t insns_flags2;
target-ppc/translate_init.c +3 -0
index c4bd5de..1b72485 100644
@@ -7824,6 +7824,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
     dc->props = powerpc_servercpu_properties;
     pcc->pvr = CPU_POWERPC_POWER7_BASE;
     pcc->pvr_mask = CPU_POWERPC_POWER7_MASK;
+    pcc->pcr_mask = POWERPC_ISA_COMPAT_2_05 | POWERPC_ISA_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER7;
     pcc->check_pow = check_pow_nocheck;
     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
@@ -7883,6 +7884,7 @@ POWERPC_FAMILY(POWER7P)(ObjectClass *oc, void *data)
     dc->props = powerpc_servercpu_properties;
     pcc->pvr = CPU_POWERPC_POWER7P_BASE;
     pcc->pvr_mask = CPU_POWERPC_POWER7P_MASK;
+    pcc->pcr_mask = POWERPC_ISA_COMPAT_2_05 | POWERPC_ISA_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER7;
     pcc->check_pow = check_pow_nocheck;
     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
@@ -7954,6 +7956,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
     dc->props = powerpc_servercpu_properties;
     pcc->pvr = CPU_POWERPC_POWER8_BASE;
     pcc->pvr_mask = CPU_POWERPC_POWER8_MASK;
+    pcc->pcr_mask = POWERPC_ISA_COMPAT_2_05 | POWERPC_ISA_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER8;
     pcc->check_pow = check_pow_nocheck;
     pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |
Signature · 1 line
1.9.rc0
#14 lore raw

PATCH 6/9 spapr: Add ibm, client-architecture-support call

In reply to Alexey Kardashevskiy

The PAPR+ specification defines a ibm,client-architecture-support (CAS) RTAS call which purpose is to provide a negotiation mechanism for the guest and the hypervisor to work out the best compatibility parameters. During the negotiation process, the guest provides an array of various options and capabilities which it supports, the hypervisor adjusts the device tree and (optionally) reboots the guest.

At the moment the Linux guest calls CAS method at early boot so SLOF gets called. SLOF allocates a memory buffer for the device tree changes and calls a custom KVMPPC_H_CAS hypercall. QEMU parses the options, composes a diff for the device tree, copies it to the buffer provided by SLOF and returns to SLOF. SLOF updates the device tree and returns control to the guest kernel. Only then the Linux guest parses the device tree so it is possible to avoid unnecessary reboot in most cases.

The device tree diff is a header with the update format version (defined as 0 in this patch) followed by a device tree with the properties which require update.

If QEMU detects during the option list parsing that it has to reboot the guest, it silently does so as the guest expects reboot to happen as pHyp firmware does it almost all the time.

This defines custom KVMPPC_H_CAS hypercall. The current SLOF already has support for it.

This implements stub which returns empty tree to the guest.

---
 hw/ppc/spapr.c         | 26 ++++++++++++++++++++++++++
 hw/ppc/spapr_hcall.c   | 21 +++++++++++++++++++++
 include/hw/ppc/spapr.h |  9 ++++++++-
 trace-events           |  4 ++++
 4 files changed, 59 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +26 -0
index 61d0675..cf53a7a 100644
@@ -53,6 +53,7 @@
 #include "hw/usb.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "trace.h"
 
 #include <libfdt.h>
 
@@ -562,6 +563,31 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
     return fdt;
 }
 
+int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)
+{
+    void *fdt;
+    sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+
+    size -= sizeof(hdr);
+
+    fdt = g_malloc0(size);
+    _FDT((fdt_create(fdt, size)));
+
+    _FDT((fdt_finish(fdt)));
+
+    if (fdt_totalsize(fdt) + sizeof(hdr) > size) {
+        trace_spapr_cas_failed(size);
+        return -1;
+    }
+
+    cpu_physical_memory_write(addr, &hdr, sizeof(hdr));
+    cpu_physical_memory_write(addr + sizeof(hdr), fdt, fdt_totalsize(fdt));
+    trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr));
+    g_free(fdt);
+
+    return 0;
+}
+
 static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt)
 {
     uint32_t associativity[] = {cpu_to_be32(0x4), cpu_to_be32(0x0),
hw/ppc/spapr_hcall.c +21 -0
index 0bae053..2f6aa5c 100644
@@ -752,6 +752,24 @@ out:
     return ret;
 }
 
+static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
+                                                  sPAPREnvironment *spapr,
+                                                  target_ulong opcode,
+                                                  target_ulong *args)
+{
+    target_ulong list = args[0];
+
+    if (!list) {
+        return H_SUCCESS;
+    }
+
+    if (spapr_h_cas_compose_response(args[1], args[2])) {
+        qemu_system_reset_request();
+    }
+
+    return H_SUCCESS;
+}
+
 static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1];
 static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCALL_BASE + 1];
 
@@ -831,6 +849,9 @@ static void hypercall_register_types(void)
     spapr_register_hypercall(KVMPPC_H_RTAS, h_rtas);
 
     spapr_register_hypercall(H_SET_MODE, h_set_mode);
+
+    /* ibm,client-architecture-support support */
+    spapr_register_hypercall(KVMPPC_H_CAS, h_client_architecture_support);
 }
 
 type_init(hypercall_register_types)
include/hw/ppc/spapr.h +8 -1
index 5fdac1e..dd6d97a 100644
@@ -302,10 +302,16 @@ typedef struct sPAPREnvironment {
 #define KVMPPC_HCALL_BASE       0xf000
 #define KVMPPC_H_RTAS           (KVMPPC_HCALL_BASE + 0x0)
 #define KVMPPC_H_LOGICAL_MEMOP  (KVMPPC_HCALL_BASE + 0x1)
-#define KVMPPC_HCALL_MAX        KVMPPC_H_LOGICAL_MEMOP
+/* Client Architecture support */
+#define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
+#define KVMPPC_HCALL_MAX        KVMPPC_H_CAS
 
 extern sPAPREnvironment *spapr;
 
+typedef struct sPAPRDeviceTreeUpdateHeader {
+    uint32_t version_id;
+} sPAPRDeviceTreeUpdateHeader;
+
 /*#define DEBUG_SPAPR_HCALLS*/
 
 #ifdef DEBUG_SPAPR_HCALLS
@@ -401,6 +407,7 @@ struct sPAPRTCETable {
 
 void spapr_events_init(sPAPREnvironment *spapr);
 void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
+int spapr_h_cas_compose_response(target_ulong addr, target_ulong size);
 sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
                                    size_t window_size);
 MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet);
trace-events +4 -0
index af4449d..03565dc 100644
@@ -1179,6 +1179,10 @@ xics_ics_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_
 xics_ics_reject(int nr, int srcno) "reject irq %#x [src %d]"
 xics_ics_eoi(int nr) "ics_eoi: irq %#x"
 
+# hw/ppc/spapr.c
+spapr_cas_failed(unsigned long n) "DT diff buffer is too small: %ld bytes"
+spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes"
+
 # hw/ppc/spapr_iommu.c
 spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
 spapr_iommu_get(uint64_t liobn, uint64_t ioba, uint64_t ret, uint64_t tce) "liobn=%"PRIx64" ioba=0x%"PRIx64" ret=%"PRId64" tce=0x%"PRIx64
Signature · 1 line
1.9.rc0
#15 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH 6/9] spapr: Add ibm, client-architecture-support call

Quoted 15 lines · Alexey Kardashevskiy

The PAPR+ specification defines a ibm,client-architecture-support (CAS) RTAS call which purpose is to provide a negotiation mechanism for the guest and the hypervisor to work out the best compatibility parameters. During the negotiation process, the guest provides an array of various options and capabilities which it supports, the hypervisor adjusts the device tree and (optionally) reboots the guest.

At the moment the Linux guest calls CAS method at early boot so SLOF gets called. SLOF allocates a memory buffer for the device tree changes and calls a custom KVMPPC_H_CAS hypercall. QEMU parses the options, composes a diff for the device tree, copies it to the buffer provided by SLOF and returns to SLOF. SLOF updates the device tree and returns control to the guest kernel. Only then the Linux guest parses the device tree so it is possible to avoid unnecessary reboot in most cases.

Quoted 2 lines

The device tree diff is a header with the update format version (defined as 0 in this patch)

That is 1 in the code.

hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 570

Quoted 9 lines
hw/ppc/spapr.c +5 -0
@@ -562,6 +563,31 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
     return fdt;
 }
 
+int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)
+{
+    void *fdt;
+    sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+

Regards
Nikunj

#16 lore raw

PATCH 7/9 spapr: Limit threads per core according to current compatibility mode

In reply to Alexey Kardashevskiy

This puts a limit to the number of threads per core based on the current compatibility mode. Although PowerISA specs do not specify the maximum threads per core number, the linux guest still expects that PowerISA2.05-compatible CPU supports only 2 threads per core as this is what POWER6 (2.05 compliant CPU) implements, same is true for POWER7 (2.06, 4 threads) and POWER8 (2.07, 8 threads).

---
 hw/ppc/spapr.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +28 -3
index cf53a7a..a2c9106 100644
@@ -34,6 +34,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
+#include "cpu-models.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
@@ -203,6 +204,29 @@ static XICSState *xics_system_init(int nr_servers, int nr_irqs)
     return icp;
 }
 
+static int spapr_get_compat_smp_threads(PowerPCCPU *cpu)
+{
+    int ret = -1;
+
+    switch (cpu->cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        ret = 2;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:
+        ret = 4;
+        break;
+    case CPU_POWERPC_LOGICAL_2_07:
+        ret = 8;
+        break;
+    default:
+        ret = smp_threads;
+        break;
+    }
+    ret = MIN(ret, smp_threads);
+
+    return ret;
+}
+
 static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
 {
     int ret = 0, offset;
@@ -221,8 +245,9 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
                                     cpu_to_be32(0x0),
                                     cpu_to_be32(cpu->numa_node),
                                     cpu_to_be32(index)};
-        uint32_t servers_prop[smp_threads];
-        uint32_t gservers_prop[smp_threads * 2];
+        int smpt = spapr_get_compat_smp_threads(pcpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
         int i;
 
         if ((index % smt) != 0) {
@@ -260,7 +285,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr)
         }
 
         /* Build interrupt servers and gservers properties */
-        for (i = 0; i < smp_threads; i++) {
+        for (i = 0; i < smpt; i++) {
             servers_prop[i] = cpu_to_be32(index + i);
             /* Hack, direct the group queues back to cpu 0 */
             gservers_prop[i*2] = cpu_to_be32(index + i);
Signature · 1 line
1.9.rc0
#17 lore raw

Re: [Qemu-devel] [PATCH 7/9] spapr: Limit threads per core according to current compatibility mode

Quoted 37 lines · Alexey Kardashevskiy

This puts a limit to the number of threads per core based on the current compatibility mode. Although PowerISA specs do not specify the maximum threads per core number, the linux guest still expects that PowerISA2.05-compatible CPU supports only 2 threads per core as this is what POWER6 (2.05 compliant CPU) implements, same is true for POWER7 (2.06, 4 threads) and POWER8 (2.07, 8 threads).

---
  hw/ppc/spapr.c | 31 ++++++++++++++++++++++++++++---
  1 file changed, 28 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +10 -0
index cf53a7a..a2c9106 100644
@@ -34,6 +34,7 @@
  #include "sysemu/kvm.h"
  #include "kvm_ppc.h"
  #include "mmu-hash64.h"
+#include "cpu-models.h"
 
  #include "hw/boards.h"
  #include "hw/ppc/ppc.h"
@@ -203,6 +204,29 @@ static XICSState *xics_system_init(int nr_servers, int nr_irqs)
      return icp;
  }
 
+static int spapr_get_compat_smp_threads(PowerPCCPU *cpu)
+{
+    int ret = -1;
+
+    switch (cpu->cpu_version) {
+    case CPU_POWERPC_LOGICAL_2_05:
+        ret = 2;
+        break;
+    case CPU_POWERPC_LOGICAL_2_06:

hw/ppc/spapr.c static XICSState *xics_system_init(int nr_servers, int nr_irqs) · line 225

Quoted 10 lines
hw/ppc/spapr.c +10 -0
+        ret = 4;
+        break;
+    case CPU_POWERPC_LOGICAL_2_07:
+        ret = 8;
+        break;
+    default:
+        ret = smp_threads;
+        break;
+    }
+    ret = MIN(ret, smp_threads);

Just call this in the function where you set the compat property and error out if threads > supported_threads. We always default to 1 thread anyway, so the only thing that could get us a broken configuration is the user.

Alex

#18 lore raw

PATCH 8/9 spapr: Implement processor compatibility in ibm, client-architecture-support

In reply to Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

Quoted 1 line

From the hardware prospective, it is supported by the Processor

Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
 hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
 hw/ppc/spapr_hcall.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 trace-events         |  5 ++++
 3 files changed, 128 insertions(+)
hw/ppc/spapr.c +40 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
 #include "cpu-models.h"
+#include "qom/cpu.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)
 {
     void *fdt;
     sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
 
     size -= sizeof(hdr);
 
     fdt = g_malloc0(size);
     _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));
 
     _FDT((fdt_finish(fdt)));
 
hw/ppc/spapr_hcall.c +83 -0

101 lines not on this page · raw message

trace-events +5 -0
index 03565dc..c2db909 100644
@@ -1182,6 +1182,11 @@ xics_ics_eoi(int nr) "ics_eoi: irq %#x"
 # hw/ppc/spapr.c
 spapr_cas_failed(unsigned long n) "DT diff buffer is too small: %ld bytes"
 spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes"
+spapr_cas_add_subnode(const char *s) "%s"
+
+# hw/ppc/spapr_hcall.c
+spapr_cas_pvr_try(uint32_t pvr) "%x"
+spapr_cas_pvr(uint32_t cur_pvr, bool cpu_match, uint32_t new_pvr, uint64_t pcr) "current=%x, cpu_match=%u, new=%x, compat flags=%"PRIx64
 
 # hw/ppc/spapr_iommu.c
 spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
Signature · 1 line
1.9.rc0
#19 lore raw

Re: [Qemu-devel] [PATCH 8/9] spapr: Implement processor compatibility in ibm, client-architecture-support

Quoted 75 lines · Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

From the hardware prospective, it is supported by the Processor
Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
  hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
  hw/ppc/spapr_hcall.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  trace-events         |  5 ++++
  3 files changed, 128 insertions(+)
hw/ppc/spapr.c +30 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
  #include "kvm_ppc.h"
  #include "mmu-hash64.h"
  #include "cpu-models.h"
+#include "qom/cpu.h"
 
  #include "hw/boards.h"
  #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)
  {
      void *fdt;
      sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
 
      size -= sizeof(hdr);
 
      fdt = g_malloc0(size);
      _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;

hw/ppc/spapr.c int spapr_h_cas_compose_response(target_ulong addr, target_ulong size) · line 639

Quoted 10 lines
hw/ppc/spapr.c +10 -0
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));

Why is this so much code? Can we only replace full nodes? Then please extract the original CPU node creation into a function and just call it from the original generation and from here.

If we can also replace single properties I'd say we only need to override cpu-version.

Quoted 36 lines
hw/ppc/spapr.c +0 -0
      _FDT((fdt_finish(fdt)));
 
hw/ppc/spapr_hcall.c +12 -0
index 2f6aa5c..cb815c3 100644
@@ -3,6 +3,9 @@
  #include "helper_regs.h"
  #include "hw/ppc/spapr.h"
  #include "mmu-hash64.h"
+#include "cpu-models.h"
+#include "trace.h"
+#include "kvm_ppc.h"
 
  struct SPRSyncState {
      CPUState *cs;
@@ -752,12 +755,92 @@ out:
      return ret;
  }
 
+#define get_compat_level(cpuver) ( \
+    ((cpuver) == CPU_POWERPC_LOGICAL_2_05) ? 2050 : \
+    ((cpuver) == CPU_POWERPC_LOGICAL_2_06) ? 2060 : \
+    ((cpuver) == CPU_POWERPC_LOGICAL_2_06_PLUS) ? 2061 : \
+    ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0)
+
  static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
                                                    sPAPREnvironment *spapr,
                                                    target_ulong opcode,
                                                    target_ulong *args)
  {
      target_ulong list = args[0];
+    PowerPCCPUClass *pcc_ = POWERPC_CPU_GET_CLASS(cpu_);
+    CPUState *cs;
+    CPUState *cs_ = CPU(cpu_);

hw/ppc/spapr_hcall.c out: · line 782

Quoted 10 lines
hw/ppc/spapr_hcall.c +10 -0
+    bool cpu_match = false;
+    unsigned old_cpu_version = cpu_->cpu_version;
+    unsigned compat_lvl = 0, cpu_version = 0;
+    unsigned max_lvl = get_compat_level(cpu_->max_compat);
+
+    /* Parse PVR list */
+    for ( ; ; ) {
+        uint32_t pvr, pvr_mask;
+
+        pvr_mask = ldl_phys(cs_->as, list);

We access memory that the guest thinks gets accessed by real mode, so we need to mask it again. Just use the rtas helpers.

Quoted 45 lines
hw/ppc/spapr_hcall.c +45 -0
+        list += 4;
+        pvr = ldl_phys(cs_->as, list);
+        list += 4;
+
+        trace_spapr_cas_pvr_try(pvr);
+        if (!max_lvl &&
+            ((cpu_->env.spr[SPR_PVR] & pvr_mask) == (pvr & pvr_mask))) {
+            cpu_match = true;
+            cpu_version = 0;
+        } else if (pvr == cpu_->cpu_version) {
+            cpu_match = true;
+            cpu_version = cpu_->cpu_version;
+        } else if (!cpu_match) {
+            /* If it is a logical PVR, try to determine the highest level */
+            unsigned lvl = get_compat_level(pvr);
+            if (lvl) {
+                bool is205 = (pcc_->pcr_mask & POWERPC_ISA_COMPAT_2_05) &&
+                     (lvl == get_compat_level(CPU_POWERPC_LOGICAL_2_05));
+                bool is206 = (pcc_->pcr_mask & POWERPC_ISA_COMPAT_2_06) &&
+                    ((lvl == get_compat_level(CPU_POWERPC_LOGICAL_2_06)) ||
+                    (lvl == get_compat_level(CPU_POWERPC_LOGICAL_2_06_PLUS)));
+
+                if (is205 || is206) {
+                    if (!max_lvl) {
+                        /* User did not set the level, choose the highest */
+                        if (compat_lvl <= lvl) {
+                            compat_lvl = lvl;
+                            cpu_version = pvr;
+                        }
+                    } else if (max_lvl >= lvl) {
+                        /* User chose the level, don't set higher than this */
+                        compat_lvl = lvl;
+                        cpu_version = pvr;
+                    }
+                }
+            }
+        }
+        /* Terminator record */
+        if (~pvr_mask & pvr) {
+            break;
+        }
+    }
+
+    /* For the future use: here @list points to the first capability */
+

hw/ppc/spapr_hcall.c out: · line 837

Quoted 10 lines
hw/ppc/spapr_hcall.c +10 -0
+    /* Parsing finished */
+    trace_spapr_cas_pvr(cpu_->cpu_version, cpu_match,
+                        cpu_version, pcc_->pcr_mask);
+
+    /* Update CPUs */
+    if (old_cpu_version != cpu_version) {
+        CPU_FOREACH(cs) {
+            PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+            ppc_set_compat(cpu, cpu_version);

Better make this a run_on call to ensure the vcpus get their new compat properties set.

Alex

Quoted 25 lines
hw/ppc/spapr_hcall.c +6 -0
+        }
+    }
+
+    if (!cpu_version) {
+        return H_SUCCESS;
+    }
 
      if (!list) {
          return H_SUCCESS;
trace-events +5 -0
index 03565dc..c2db909 100644
@@ -1182,6 +1182,11 @@ xics_ics_eoi(int nr) "ics_eoi: irq %#x"
  # hw/ppc/spapr.c
  spapr_cas_failed(unsigned long n) "DT diff buffer is too small: %ld bytes"
  spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes"
+spapr_cas_add_subnode(const char *s) "%s"
+
+# hw/ppc/spapr_hcall.c
+spapr_cas_pvr_try(uint32_t pvr) "%x"
+spapr_cas_pvr(uint32_t cur_pvr, bool cpu_match, uint32_t new_pvr, uint64_t pcr) "current=%x, cpu_match=%u, new=%x, compat flags=%"PRIx64
 
  # hw/ppc/spapr_iommu.c
  spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
#20 lore raw

Re: [Qemu-devel] [PATCH 8/9] spapr: Implement processor compatibility in ibm, client-architecture-support

Quoted 80 lines · Alexander Graf
Quoted 78 lines · Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

From the hardware prospective, it is supported by the Processor
Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
  hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
  hw/ppc/spapr_hcall.c | 83
++++++++++++++++++++++++++++++++++++++++++++++++++++
  trace-events         |  5 ++++
  3 files changed, 128 insertions(+)
hw/ppc/spapr.c +34 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
  #include "kvm_ppc.h"
  #include "mmu-hash64.h"
  #include "cpu-models.h"
+#include "qom/cpu.h"
    #include "hw/boards.h"
  #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr,
 target_ulong size)
  {
      void *fdt;
      sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
        size -= sizeof(hdr);
        fdt = g_malloc0(size);
      _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
Quoted 8 lines

hw/ppc/spapr.c int spapr_h_cas_compose_response(target_ulong addr, target_ulong size) · line 639

Quoted 6 lines
hw/ppc/spapr.c +6 -0
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));

Why is this so much code? Can we only replace full nodes?

It is a diff tree, in only has properties to change.

Quoted 6 lines

Then please
extract the original CPU node creation into a function and just call it from the original generation and from here.

If we can also replace single properties I'd say we only need to override cpu-version.

Mmm. The user could run qemu with threads=8 on POWER8 with SLES11 which must not see 8 threads but it can update itself and reboot with the kernel which is aware of POWER8. You are saying we do not want to support that?

Signature · 1 line
Alexey
#21 lore raw

Re: [Qemu-devel] [PATCH 8/9] spapr: Implement processor compatibility in ibm, client-architecture-support

Quoted 87 lines · Alexey Kardashevskiy
Quoted 78 lines · Alexander Graf
Quoted 77 lines · Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

From the hardware prospective, it is supported by the Processor
Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
   hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
   hw/ppc/spapr_hcall.c | 83
++++++++++++++++++++++++++++++++++++++++++++++++++++
   trace-events         |  5 ++++
   3 files changed, 128 insertions(+)
hw/ppc/spapr.c +33 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
   #include "kvm_ppc.h"
   #include "mmu-hash64.h"
   #include "cpu-models.h"
+#include "qom/cpu.h"
     #include "hw/boards.h"
   #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr,
 target_ulong size)
   {
       void *fdt;
       sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
         size -= sizeof(hdr);
         fdt = g_malloc0(size);
       _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
Quoted 8 lines

hw/ppc/spapr.c int spapr_h_cas_compose_response(target_ulong addr, target_ulong size) · line 639

Quoted 7 lines
hw/ppc/spapr.c +7 -0
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));

Why is this so much code? Can we only replace full nodes?

Quoted 1 line

It is a diff tree, in only has properties to change.

So why do we change so much then? :)

Quoted 11 lines
Quoted 7 lines

Then please
extract the original CPU node creation into a function and just call it from the original generation and from here.

If we can also replace single properties I'd say we only need to override cpu-version.

Mmm. The user could run qemu with threads=8 on POWER8 with SLES11 which must not see 8 threads but it can update itself and reboot with the kernel which is aware of POWER8. You are saying we do not want to support that?

First off, I think that practically speaking people will want to use 2-thread granularity on POWER8 because that gives them the best load exploitation on the system.

So if we just disable CPU nodes that would not be visible usually (there was a disabled flag in cpu nodes, right?) for threads that are incompatible with a new CAS mode, we can then remove the disabled flag when the guest accepts more threads again.

That means we could expose 8 threads (POWER8), guest only supports 2 threads (POWER6), so we waste 6 threads. But the remaining 2 will be fast ;). We basically degrade the system to SMT2 mode.

What does pHyp do here?

Alex

#22 lore raw

Re: [Qemu-devel] [PATCH 8/9] spapr: Implement processor compatibility in ibm, client-architecture-support

Quoted 89 lines · Alexander Graf
Quoted 87 lines · Alexey Kardashevskiy
Quoted 86 lines · Alexander Graf
Quoted 74 lines · Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

From the hardware prospective, it is supported by the Processor
Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
   hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
   hw/ppc/spapr_hcall.c | 83
++++++++++++++++++++++++++++++++++++++++++++++++++++
   trace-events         |  5 ++++
   3 files changed, 128 insertions(+)
hw/ppc/spapr.c +30 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
   #include "kvm_ppc.h"
   #include "mmu-hash64.h"
   #include "cpu-models.h"
+#include "qom/cpu.h"
     #include "hw/boards.h"
   #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr,
 target_ulong size)
   {
       void *fdt;
       sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
         size -= sizeof(hdr);
         fdt = g_malloc0(size);
       _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;

hw/ppc/spapr.c int spapr_h_cas_compose_response(target_ulong addr, · line 638

Quoted 10 lines
hw/ppc/spapr.c +10 -0
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));

Why is this so much code? Can we only replace full nodes?

Quoted 3 lines
Quoted 1 line

It is a diff tree, in only has properties to change.

So why do we change so much then? :)

3 (three) properties are "much" now? :)

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Then please
extract the original CPU node creation into a function and just call it from the original generation and from here.

If we can also replace single properties I'd say we only need to override cpu-version.

Quoted 7 lines
Quoted 3 lines

Mmm. The user could run qemu with threads=8 on POWER8 with SLES11 which must not see 8 threads but it can update itself and reboot with the kernel which is aware of POWER8. You are saying we do not want to support that?

First off, I think that practically speaking people will want to use 2-thread granularity on POWER8 because that gives them the best load exploitation on the system.

Practically speaking, people will want to use kernels which can work on POWER8 in raw mode, no? Here we are trying to fix older guests.

Quoted 8 lines

So if we just disable CPU nodes that would not be visible usually (there was a disabled flag in cpu nodes, right?) for threads that are incompatible with a new CAS mode, we can then remove the disabled flag when the guest accepts more threads again.

That means we could expose 8 threads (POWER8), guest only supports 2 threads (POWER6), so we waste 6 threads. But the remaining 2 will be fast ;). We basically degrade the system to SMT2 mode.

We do not want to show more threads (i.e. bigger ibm,ppc-interrupt-server#s properties) if we do not support more threads as we do not really know what guest kernel (including AIX) or some ppc64_cpu/drmgr/whatever tool will do if they find more.

Quoted 1 line

What does pHyp do here?

I wish it was easy to verify :)

I fail to see what exactly your objections are all about, I definitely miss something big here. Is it a minor code duplication or some dangerous bug? If it is just a code duplication, I could do something about it.

Signature · 1 line
Alexey
#23 lore raw

Re: [Qemu-devel] [PATCH 8/9] spapr: Implement processor compatibility in ibm, client-architecture-support

Quoted 108 lines · Alexey Kardashevskiy
Quoted 89 lines · Alexander Graf
Quoted 87 lines · Alexey Kardashevskiy
Quoted 86 lines · Alexander Graf
Quoted 74 lines · Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

From the hardware prospective, it is supported by the Processor
Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
   hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
   hw/ppc/spapr_hcall.c | 83
++++++++++++++++++++++++++++++++++++++++++++++++++++
   trace-events         |  5 ++++
   3 files changed, 128 insertions(+)
hw/ppc/spapr.c +30 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
   #include "kvm_ppc.h"
   #include "mmu-hash64.h"
   #include "cpu-models.h"
+#include "qom/cpu.h"
     #include "hw/boards.h"
   #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr,
 target_ulong size)
   {
       void *fdt;
       sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
         size -= sizeof(hdr);
         fdt = g_malloc0(size);
       _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;

hw/ppc/spapr.c int spapr_h_cas_compose_response(target_ulong addr, · line 638

Quoted 10 lines
hw/ppc/spapr.c +10 -0
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));

Why is this so much code? Can we only replace full nodes?

Quoted 3 lines
Quoted 1 line

It is a diff tree, in only has properties to change.

So why do we change so much then? :)

3 (three) properties are "much" now? :)

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

Then please
extract the original CPU node creation into a function and just call it from the original generation and from here.

If we can also replace single properties I'd say we only need to override cpu-version.

Mmm. The user could run qemu with threads=8 on POWER8 with SLES11 which must not see 8 threads but it can update itself and reboot with the kernel which is aware of POWER8. You are saying we do not want to support that?

Quoted 11 lines
Quoted 3 lines

First off, I think that practically speaking people will want to use 2-thread granularity on POWER8 because that gives them the best load exploitation on the system.

Practically speaking, people will want to use kernels which can work on POWER8 in raw mode, no? Here we are trying to fix older guests.

Quoted 4 lines

So if we just disable CPU nodes that would not be visible usually (there was a disabled flag in cpu nodes, right?) for threads that are incompatible with a new CAS mode, we can then remove the disabled flag when the guest accepts more threads again.

I just realized where misunderstanding happened - when I switch from 4 threads per core to 2 threads per core, the number of CPU nodes does not change, only server#s and gserver#s properties do and this is the only way of telling the guest the new number of threads.

So if you still want to disable some nodes, please explain more. Thanks!

Quoted 18 lines
Quoted 3 lines

That means we could expose 8 threads (POWER8), guest only supports 2 threads (POWER6), so we waste 6 threads. But the remaining 2 will be fast ;). We basically degrade the system to SMT2 mode.

We do not want to show more threads (i.e. bigger ibm,ppc-interrupt-server#s properties) if we do not support more threads as we do not really know what guest kernel (including AIX) or some ppc64_cpu/drmgr/whatever tool will do if they find more.

Quoted 1 line

What does pHyp do here?

I wish it was easy to verify :)

I fail to see what exactly your objections are all about, I definitely miss something big here. Is it a minor code duplication or some dangerous bug? If it is just a code duplication, I could do something about it.

Signature · 1 line
Alexey
#24 lore raw

Re: [Qemu-devel] [PATCH 8/9] spapr: Implement processor compatibility in ibm, client-architecture-support

In reply to Alexey Kardashevskiy
Quoted 122 lines · Alexey Kardashevskiy
Quoted 88 lines · Alexander Graf
Quoted 87 lines · Alexey Kardashevskiy
Quoted 86 lines · Alexander Graf
Quoted 74 lines · Alexey Kardashevskiy

Modern Linux kernels support last POWERPC CPUs so when a kernel boots, in most cases it can find a matching cpu_spec in the kernel's cpu_specs list. However if the kernel is quite old, it may be missing a definition of the actual CPU. To provide an ability for old kernels to work on modern hardware, a Processor Compatibility Mode has been introduced by the PowerISA specification.

From the hardware prospective, it is supported by the Processor
Compatibility Register (PCR) which is defined in PowerISA. The register enables one of the compatibility modes (2.05/2.06/2.07).
Since PCR is a hypervisor privileged register and cannot be accessed from the guest, the mode selection is done via ibm,client-architecture-support (CAS) RTAS call using which the guest specifies what "raw" and "architected" CPU versions it supports. QEMU works out the best match, changes a "cpu-version" property of every CPU and notifies the guest about the change by setting these properties in the buffer passed as a response on a custom H_CAS hypercall.

---
    hw/ppc/spapr.c       | 40 +++++++++++++++++++++++++
    hw/ppc/spapr_hcall.c | 83
++++++++++++++++++++++++++++++++++++++++++++++++++++
    trace-events         |  5 ++++
    3 files changed, 128 insertions(+)
hw/ppc/spapr.c +30 -0
index a2c9106..a0882a1 100644
@@ -35,6 +35,7 @@
    #include "kvm_ppc.h"
    #include "mmu-hash64.h"
    #include "cpu-models.h"
+#include "qom/cpu.h"
      #include "hw/boards.h"
    #include "hw/ppc/ppc.h"
@@ -592,11 +593,50 @@ int spapr_h_cas_compose_response(target_ulong addr,
 target_ulong size)
    {
        void *fdt;
        sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
+    CPUState *cs;
+    int smt = kvmppc_smt_threads();
          size -= sizeof(hdr);
          fdt = g_malloc0(size);
        _FDT((fdt_create(fdt, size)));
+    _FDT((fdt_begin_node(fdt, "cpus")));
+
+    CPU_FOREACH(cs) {
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+        DeviceClass *dc = DEVICE_GET_CLASS(cpu);
+        int smpt = spapr_get_compat_smp_threads(cpu);
+        int i, index = ppc_get_vcpu_dt_id(cpu);
+        uint32_t servers_prop[smpt];
+        uint32_t gservers_prop[smpt * 2];
+        char tmp[32];
+
+        if ((index % smt) != 0) {
+            continue;
+        }
+
+        snprintf(tmp, 32, "%s@%x", dc->fw_name, index);
+        trace_spapr_cas_add_subnode(tmp);
+
+        _FDT((fdt_begin_node(fdt, tmp)));
+        _FDT((fdt_property_cell(fdt, "cpu-version", cpu->cpu_version)));
+
+        /* Build interrupt servers and gservers properties */
+        for (i = 0; i < smpt; i++) {
+            servers_prop[i] = cpu_to_be32(index + i);
+            /* Hack, direct the group queues back to cpu 0 */
+            gservers_prop[i*2] = cpu_to_be32(index + i);
+            gservers_prop[i*2 + 1] = 0;

hw/ppc/spapr.c int spapr_h_cas_compose_response(target_ulong addr, · line 638

Quoted 10 lines
hw/ppc/spapr.c +10 -0
+        }
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s",
+                           servers_prop, sizeof(servers_prop))));
+        _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
+                           gservers_prop, sizeof(gservers_prop))));
+
+        _FDT((fdt_end_node(fdt)));
+    }
+
+    _FDT((fdt_end_node(fdt)));

Why is this so much code? Can we only replace full nodes?

Quoted 2 lines
Quoted 1 line

It is a diff tree, in only has properties to change.

So why do we change so much then? :)

3 (three) properties are "much" now? :)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Then please
extract the original CPU node creation into a function and just call it from the original generation and from here.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If we can also replace single properties I'd say we only need to override cpu-version.

Mmm. The user could run qemu with threads=8 on POWER8 with SLES11 which must not see 8 threads but it can update itself and reboot with the kernel which is aware of POWER8. You are saying we do not want to support that?

First off, I think that practically speaking people will want to use 2-thread granularity on POWER8 because that gives them the best load exploitation on the system.

Practically speaking, people will want to use kernels which can work on POWER8 in raw mode, no? Here we are trying to fix older guests.

Quoted 8 lines

So if we just disable CPU nodes that would not be visible usually (there was a disabled flag in cpu nodes, right?) for threads that are incompatible with a new CAS mode, we can then remove the disabled flag when the guest accepts more threads again.

That means we could expose 8 threads (POWER8), guest only supports 2 threads (POWER6), so we waste 6 threads. But the remaining 2 will be fast ;). We basically degrade the system to SMT2 mode.

We do not want to show more threads (i.e. bigger ibm,ppc-interrupt-server#s properties) if we do not support more threads as we do not really know what guest kernel (including AIX) or some ppc64_cpu/drmgr/whatever tool will do if they find more.

Quoted 6 lines
Quoted 1 line

What does pHyp do here?

I wish it was easy to verify :)

I fail to see what exactly your objections are all about, I definitely miss something big here. Is it a minor code duplication or some dangerous bug? If it is just a code duplication, I could do something about it.

My main concern is that this is a big chunk of magic code that swizzles around random device tree properties without an easy to follow explanation that would show people what exactly the code does.

I think you can overcome all of this by combining the function you introduce here with the one that we already have for cpu node generation. You would of course need to parameterize it.

While you're at the process of combining the functions, you will realize that some things are not exactly obvious to every reader. For example

+ if ((index % smt) != 0) {
+ continue;
+ }

is based on the fact that only cores are listed in /cpus. But the code doesn't tell you, so if anyone who is not Alexey wants to debug this code and find out what's going wrong, he has to sit down for a few minutes are read up on that fact. It'd be a lot nicer to hint him towards the correct direction. This could either be a comment or reader friendly code such as

  for_each_core(...) {
  }

at which point the reader would immediately know what we're trying to do.

The same goes for the interrupt servers and gservers properties. If we don't explain the format at least by variable / function names in the code, you either have to know the format off the top of your head or constantly have the sPAPR spec (which is not public) lying next to you. This increases the barrier to understanding the code.

For example, if you would just extract the interrupt server generation into a function and give it parameters such as "num_threads" and give every value a good name before you assign it to the property array, the code suddenly becomes self-documenting. If you then share that function with the normal cpu node generation, anyone who fixes a bug in it also only has to look at a single spot.

Alex

#25 lore raw

PATCH 9/9 KVM: PPC: Enable compatibility mode

In reply to Alexey Kardashevskiy

The host kernel implements a KVM_REG_PPC_ARCH_COMPAT register which this uses to enable a compatibility mode if any chosen.

---
 hw/ppc/spapr.c       | 6 ++++++
 hw/ppc/spapr_hcall.c | 4 ++++
 target-ppc/kvm.c     | 5 +++++
 target-ppc/kvm_ppc.h | 6 ++++++
 4 files changed, 21 insertions(+)
hw/ppc/spapr.c +6 -0
index a0882a1..f89be10 100644
@@ -1376,6 +1376,12 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
         /* Tell KVM that we're in PAPR mode */
         if (kvm_enabled()) {
             kvmppc_set_papr(cpu);
+
+            if (cpu->max_compat &&
+                kvmppc_set_compat(cpu, cpu->max_compat) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                exit(1);
+            }
         }
 
         if (cpu->max_compat) {
hw/ppc/spapr_hcall.c +4 -0
index cb815c3..2ab21d3 100644
@@ -834,6 +834,10 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
         CPU_FOREACH(cs) {
             PowerPCCPU *cpu = POWERPC_CPU(cs);
 
+            if (kvmppc_set_compat(cpu, cpu_version) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                return H_HARDWARE;
+            }
             ppc_set_compat(cpu, cpu_version);
         }
     }
target-ppc/kvm.c +5 -0
index ff319fc..f8e8453 100644
@@ -1513,6 +1513,11 @@ void kvmppc_set_papr(PowerPCCPU *cpu)
     cap_papr = 1;
 }
 
+int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    return kvm_set_one_reg(CPU(cpu), KVM_REG_PPC_ARCH_COMPAT, &cpu_version);
+}
+
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
 {
     CPUState *cs = CPU(cpu);
target-ppc/kvm_ppc.h +6 -0
index ff077ec..716c33d 100644
@@ -23,6 +23,7 @@ int kvmppc_get_hasidle(CPUPPCState *env);
 int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
 int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
 void kvmppc_set_papr(PowerPCCPU *cpu);
+int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
 int kvmppc_smt_threads(void);
 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -95,6 +96,11 @@ static inline void kvmppc_set_papr(PowerPCCPU *cpu)
 {
 }
 
+static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    return 0;
+}
+
 static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
 {
 }
Signature · 1 line
1.9.rc0
#26 lore raw

Re: [Qemu-devel] [PATCH 9/9] KVM: PPC: Enable compatibility mode

Quoted 16 lines · Alexey Kardashevskiy

The host kernel implements a KVM_REG_PPC_ARCH_COMPAT register which this uses to enable a compatibility mode if any chosen.

---
  hw/ppc/spapr.c       | 6 ++++++
  hw/ppc/spapr_hcall.c | 4 ++++
  target-ppc/kvm.c     | 5 +++++
  target-ppc/kvm_ppc.h | 6 ++++++
  4 files changed, 21 insertions(+)
hw/ppc/spapr.c +0 -0
index a0882a1..f89be10 100644

hw/ppc/spapr.c static void ppc_spapr_init(QEMUMachineInitArgs *args) · line 1383

Quoted 8 lines
hw/ppc/spapr.c +5 -0
@@ -1376,6 +1376,12 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
          /* Tell KVM that we're in PAPR mode */
          if (kvm_enabled()) {
              kvmppc_set_papr(cpu);
+
+            if (cpu->max_compat &&
+                kvmppc_set_compat(cpu, cpu->max_compat) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                exit(1);

Why is KVM special here?

Quoted 9 lines
hw/ppc/spapr.c +1 -0
+            }
          }
 
          if (cpu->max_compat) {
hw/ppc/spapr_hcall.c +0 -0
index cb815c3..2ab21d3 100644

hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, · line 840

Quoted 7 lines
hw/ppc/spapr_hcall.c +4 -0
@@ -834,6 +834,10 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
          CPU_FOREACH(cs) {
              PowerPCCPU *cpu = POWERPC_CPU(cs);
 
+            if (kvmppc_set_compat(cpu, cpu_version) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                return H_HARDWARE;
+            }

Just fold this into ppc_set_compat which will run from vcpu context.

Alex

Quoted 43 lines
hw/ppc/spapr_hcall.c +0 -0
              ppc_set_compat(cpu, cpu_version);
          }
      }
target-ppc/kvm.c +5 -0
index ff319fc..f8e8453 100644
@@ -1513,6 +1513,11 @@ void kvmppc_set_papr(PowerPCCPU *cpu)
      cap_papr = 1;
  }
 
+int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    return kvm_set_one_reg(CPU(cpu), KVM_REG_PPC_ARCH_COMPAT, &cpu_version);
+}
+
  void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
  {
      CPUState *cs = CPU(cpu);
target-ppc/kvm_ppc.h +6 -0
index ff077ec..716c33d 100644
@@ -23,6 +23,7 @@ int kvmppc_get_hasidle(CPUPPCState *env);
  int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
  int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
  void kvmppc_set_papr(PowerPCCPU *cpu);
+int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
  void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
  int kvmppc_smt_threads(void);
  int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -95,6 +96,11 @@ static inline void kvmppc_set_papr(PowerPCCPU *cpu)
  {
  }
 
+static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    return 0;
+}
+
  static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
  {
  }
#27 lore raw

Re: [Qemu-devel] [PATCH 9/9] KVM: PPC: Enable compatibility mode

Quoted 13 lines · Alexander Graf
Quoted 11 lines · Alexey Kardashevskiy

The host kernel implements a KVM_REG_PPC_ARCH_COMPAT register which this uses to enable a compatibility mode if any chosen.

---
  hw/ppc/spapr.c       | 6 ++++++
  hw/ppc/spapr_hcall.c | 4 ++++
  target-ppc/kvm.c     | 5 +++++
  target-ppc/kvm_ppc.h | 6 ++++++
  4 files changed, 21 insertions(+)
Quoted 15 lines

hw/ppc/spapr.c static void ppc_spapr_init(QEMUMachineInitArgs *args) · line 1383

Quoted 13 lines
hw/ppc/spapr.c +5 -0
index a0882a1..f89be10 100644
@@ -1376,6 +1376,12 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
          /* Tell KVM that we're in PAPR mode */
          if (kvm_enabled()) {
              kvmppc_set_papr(cpu);
+
+            if (cpu->max_compat &&
+                kvmppc_set_compat(cpu, cpu->max_compat) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                exit(1);

Why is KVM special here?

Sorry, I am not following you here. There is no SPR for that which guest kernel could change, this is a register from "kvm set/get one reg" interface.

Quoted 10 lines
Quoted 10 lines
hw/ppc/spapr.c +1 -0
+            }
          }
            if (cpu->max_compat) {
hw/ppc/spapr_hcall.c +0 -0
index cb815c3..2ab21d3 100644
@@ -834,6 +834,10 @@ static target_ulong
 h_client_architecture_support(PowerPCCPU *cpu_,
Quoted 8 lines

hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, · line 840

Quoted 6 lines
hw/ppc/spapr_hcall.c +3 -0
          CPU_FOREACH(cs) {
              PowerPCCPU *cpu = POWERPC_CPU(cs);
  +            if (kvmppc_set_compat(cpu, cpu_version) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                return H_HARDWARE;
+            }

Just fold this into ppc_set_compat which will run from vcpu context.

TCG version cannot fail and KVM's one can. Adding non-void return value would give impression that ppc_set_compat may fail while it cannot. Still fold?

Quoted 48 lines

Alex

Quoted 43 lines
hw/ppc/spapr_hcall.c +0 -0
              ppc_set_compat(cpu, cpu_version);
          }
      }
target-ppc/kvm.c +4 -0
index ff319fc..f8e8453 100644
@@ -1513,6 +1513,11 @@ void kvmppc_set_papr(PowerPCCPU *cpu)
      cap_papr = 1;
  }
  +int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version)
+{
+    return kvm_set_one_reg(CPU(cpu), KVM_REG_PPC_ARCH_COMPAT,
 &cpu_version);
+}
+
  void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
  {
      CPUState *cs = CPU(cpu);
target-ppc/kvm_ppc.h +5 -0
index ff077ec..716c33d 100644
@@ -23,6 +23,7 @@ int kvmppc_get_hasidle(CPUPPCState *env);
  int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
  int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
  void kvmppc_set_papr(PowerPCCPU *cpu);
+int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
  void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
  int kvmppc_smt_threads(void);
  int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -95,6 +96,11 @@ static inline void kvmppc_set_papr(PowerPCCPU *cpu)
  {
  }
  +static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t
 cpu_version)
+{
+    return 0;
+}
+
  static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
  {
  }
Signature · 1 line
Alexey
#28 lore raw

Re: [Qemu-devel] [PATCH 9/9] KVM: PPC: Enable compatibility mode

Quoted 27 lines · Alexey Kardashevskiy
Quoted 12 lines · Alexander Graf
Quoted 11 lines · Alexey Kardashevskiy

The host kernel implements a KVM_REG_PPC_ARCH_COMPAT register which this uses to enable a compatibility mode if any chosen.

---
   hw/ppc/spapr.c       | 6 ++++++
   hw/ppc/spapr_hcall.c | 4 ++++
   target-ppc/kvm.c     | 5 +++++
   target-ppc/kvm_ppc.h | 6 ++++++
   4 files changed, 21 insertions(+)
Quoted 14 lines

hw/ppc/spapr.c static void ppc_spapr_init(QEMUMachineInitArgs *args) · line 1383

Quoted 13 lines
hw/ppc/spapr.c +5 -0
index a0882a1..f89be10 100644
@@ -1376,6 +1376,12 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
           /* Tell KVM that we're in PAPR mode */
           if (kvm_enabled()) {
               kvmppc_set_papr(cpu);
+
+            if (cpu->max_compat &&
+                kvmppc_set_compat(cpu, cpu->max_compat) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                exit(1);

Why is KVM special here?

Quoted 2 lines

Sorry, I am not following you here. There is no SPR for that which guest kernel could change, this is a register from "kvm set/get one reg" interface.

So semantically, what is ppc_set_compat() then? Why would we have to set the KVM SPR that represents which compat mode we're in here, but not the TCG version of it?

Quoted 18 lines
Quoted 17 lines
Quoted 9 lines
hw/ppc/spapr.c +1 -0
+            }
           }
             if (cpu->max_compat) {
hw/ppc/spapr_hcall.c +0 -0
index cb815c3..2ab21d3 100644

hw/ppc/spapr_hcall.c static target_ulong · line 840

Quoted 7 lines
hw/ppc/spapr_hcall.c +3 -0
@@ -834,6 +834,10 @@ static target_ulong
 h_client_architecture_support(PowerPCCPU *cpu_,
           CPU_FOREACH(cs) {
               PowerPCCPU *cpu = POWERPC_CPU(cs);
   +            if (kvmppc_set_compat(cpu, cpu_version) < 0) {
+                fprintf(stderr, "Unable to set compatibility mode\n");
+                return H_HARDWARE;
+            }

Just fold this into ppc_set_compat which will run from vcpu context.

Quoted 2 lines

TCG version cannot fail and KVM's one can. Adding non-void return value would give impression that ppc_set_compat may fail while it cannot. Still fold?

Yes, please.

Alex