All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/6] target/ppc: Assorted ppc target fixes
@ 2023-05-30 13:25 Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt Nicholas Piggin
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc; +Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza

Reposting these since two were merged, and I moved the PMU fix out
of the series since that's a crash fix. Should be no real change
other than rebase and kvm-only build fix.

Thanks,
Nick

Nicholas Piggin (6):
  target/ppc: Fix instruction loading endianness in alignment interrupt
  target/ppc: Change partition-scope translate interface
  target/ppc: Add SRR1 prefix indication to interrupt handlers
  target/ppc: Implement HEIR SPR
  target/ppc: Add ISA v3.1 LEV indication in SRR1 for system call
    interrupts
  target/ppc: Better CTRL SPR implementation

 target/ppc/cpu.h         |  1 +
 target/ppc/cpu_init.c    | 23 +++++++++++
 target/ppc/excp_helper.c | 83 +++++++++++++++++++++++++++++++++++++++-
 target/ppc/mmu-radix64.c | 38 ++++++++++++------
 target/ppc/translate.c   |  9 ++++-
 5 files changed, 140 insertions(+), 14 deletions(-)

-- 
2.40.1



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

* [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt
  2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
@ 2023-05-30 13:25 ` Nicholas Piggin
  2023-06-14  5:51   ` Anushree Mathur
  2023-05-30 13:25 ` [PATCH v4 2/6] target/ppc: Change partition-scope translate interface Nicholas Piggin
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza, Fabiano Rosas

powerpc ifetch endianness depends on MSR[LE] so it has to byteswap
after cpu_ldl_code(). This corrects DSISR bits in alignment
interrupts when running in little endian mode.

Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/excp_helper.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index c13f2afa04..0274617b4a 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -133,6 +133,26 @@ static void dump_hcall(CPUPPCState *env)
                   env->nip);
 }
 
+#ifdef CONFIG_TCG
+/* Return true iff byteswap is needed in a scalar memop */
+static inline bool need_byteswap(CPUArchState *env)
+{
+    /* SOFTMMU builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */
+    return !!(env->msr & ((target_ulong)1 << MSR_LE));
+}
+
+static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
+{
+    uint32_t insn = cpu_ldl_code(env, addr);
+
+    if (need_byteswap(env)) {
+        insn = bswap32(insn);
+    }
+
+    return insn;
+}
+#endif
+
 static void ppc_excp_debug_sw_tlb(CPUPPCState *env, int excp)
 {
     const char *es;
@@ -3100,7 +3120,7 @@ void ppc_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
 
     /* Restore state and reload the insn we executed, for filling in DSISR.  */
     cpu_restore_state(cs, retaddr);
-    insn = cpu_ldl_code(env, env->nip);
+    insn = ppc_ldl_code(env, env->nip);
 
     switch (env->mmu_model) {
     case POWERPC_MMU_SOFT_4xx:
-- 
2.40.1



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

* [PATCH v4 2/6] target/ppc: Change partition-scope translate interface
  2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt Nicholas Piggin
@ 2023-05-30 13:25 ` Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 3/6] target/ppc: Add SRR1 prefix indication to interrupt handlers Nicholas Piggin
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc; +Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza

Rather than always performing partition scope page table translation
with access type of 0 (MMU_DATA_LOAD), pass through the processor
access type which first initiated the translation sequence. Process-
scoped page table loads are then set to MMU_DATA_LOAD access type in
the xlate function.

This will allow more information to be passed to the exception
handler in the next patch.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/mmu-radix64.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
index 031efda0df..1fc1ba3ecf 100644
--- a/target/ppc/mmu-radix64.c
+++ b/target/ppc/mmu-radix64.c
@@ -380,6 +380,14 @@ static int ppc_radix64_partition_scoped_xlate(PowerPCCPU *cpu,
     hwaddr pte_addr;
     uint64_t pte;
 
+    if (pde_addr) {
+        /*
+         * Translation of process-scoped tables/directories is performed as
+         * a read-access.
+         */
+        access_type = MMU_DATA_LOAD;
+    }
+
     qemu_log_mask(CPU_LOG_MMU, "%s for %s @0x%"VADDR_PRIx
                   " mmu_idx %u 0x%"HWADDR_PRIx"\n",
                   __func__, access_str(access_type),
@@ -477,10 +485,10 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu,
          * is only used to translate the effective addresses of the
          * process table entries.
          */
-        ret = ppc_radix64_partition_scoped_xlate(cpu, 0, eaddr, prtbe_addr,
-                                                 pate, &h_raddr, &h_prot,
-                                                 &h_page_size, true,
-            /* mmu_idx is 5 because we're translating from hypervisor scope */
+        /* mmu_idx is 5 because we're translating from hypervisor scope */
+        ret = ppc_radix64_partition_scoped_xlate(cpu, access_type, eaddr,
+                                                 prtbe_addr, pate, &h_raddr,
+                                                 &h_prot, &h_page_size, true,
                                                  5, guest_visible);
         if (ret) {
             return ret;
@@ -519,11 +527,11 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu,
          * translation
          */
         do {
-            ret = ppc_radix64_partition_scoped_xlate(cpu, 0, eaddr, pte_addr,
-                                                     pate, &h_raddr, &h_prot,
-                                                     &h_page_size, true,
             /* mmu_idx is 5 because we're translating from hypervisor scope */
-                                                     5, guest_visible);
+            ret = ppc_radix64_partition_scoped_xlate(cpu, access_type, eaddr,
+                                                     pte_addr, pate, &h_raddr,
+                                                     &h_prot, &h_page_size,
+                                                     true, 5, guest_visible);
             if (ret) {
                 return ret;
             }
-- 
2.40.1



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

* [PATCH v4 3/6] target/ppc: Add SRR1 prefix indication to interrupt handlers
  2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 2/6] target/ppc: Change partition-scope translate interface Nicholas Piggin
@ 2023-05-30 13:25 ` Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 4/6] target/ppc: Implement HEIR SPR Nicholas Piggin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza, Fabiano Rosas

ISA v3.1 introduced prefix instructions. Among the changes, various
synchronous interrupts report whether they were caused by a prefix
instruction in (H)SRR1.

The case of instruction fetch that causes an HDSI due to access of a
process-scoped table faulting on the partition scoped translation is the
tricky one. As with ISIs and HISIs, this does not try to set the prefix
bit because there is no instruction image to be loaded. The HDSI needs
the originating access type to be passed through to the handler to
distinguish this from HDSIs that fault translating process scoped tables
originating from a load or store instruction (in that case the prefix
bit should be provided).

Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/excp_helper.c | 44 ++++++++++++++++++++++++++++++++++++++++
 target/ppc/mmu-radix64.c | 14 ++++++++++---
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 0274617b4a..b4fcaa1d88 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -1348,12 +1348,21 @@ static bool books_vhyp_handles_hv_excp(PowerPCCPU *cpu)
     return false;
 }
 
+static bool is_prefix_excp(CPUPPCState *env, uint32_t insn)
+{
+    if (!(env->insns_flags2 & PPC2_ISA310)) {
+        return false;
+    }
+    return ((insn & 0xfc000000) == 0x04000000);
+}
+
 static void powerpc_excp_books(PowerPCCPU *cpu, int excp)
 {
     CPUState *cs = CPU(cpu);
     CPUPPCState *env = &cpu->env;
     target_ulong msr, new_msr, vector;
     int srr0, srr1, lev = -1;
+    uint32_t insn = 0;
 
     /* new srr1 value excluding must-be-zero bits */
     msr = env->msr & ~0x783f0000ULL;
@@ -1392,6 +1401,41 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp)
 
     vector |= env->excp_prefix;
 
+    switch (excp) {
+    case POWERPC_EXCP_HDSI:
+        /* HDSI PRTABLE_FAULT has the originating access type in error_code */
+        if ((env->spr[SPR_HDSISR] & DSISR_PRTABLE_FAULT) &&
+            (env->error_code == MMU_INST_FETCH)) {
+            /*
+             * Fetch failed due to partition scope translation, so prefix
+             * indication is not relevant (and attempting to load the
+             * instruction at NIP would cause recursive faults with the same
+             * translation).
+             */
+            break;
+        }
+        /* fall through */
+    case POWERPC_EXCP_MCHECK:
+    case POWERPC_EXCP_DSI:
+    case POWERPC_EXCP_DSEG:
+    case POWERPC_EXCP_ALIGN:
+    case POWERPC_EXCP_PROGRAM:
+    case POWERPC_EXCP_FPU:
+    case POWERPC_EXCP_TRACE:
+    case POWERPC_EXCP_HV_EMU:
+    case POWERPC_EXCP_VPU:
+    case POWERPC_EXCP_VSXU:
+    case POWERPC_EXCP_FU:
+    case POWERPC_EXCP_HV_FU:
+        insn = ppc_ldl_code(env, env->nip);
+        if (is_prefix_excp(env, insn)) {
+            msr |= PPC_BIT(34);
+        }
+        break;
+    default:
+        break;
+    }
+
     switch (excp) {
     case POWERPC_EXCP_MCHECK:    /* Machine check exception                  */
         if (!FIELD_EX64(env->msr, MSR, ME)) {
diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
index 1fc1ba3ecf..920084bd8f 100644
--- a/target/ppc/mmu-radix64.c
+++ b/target/ppc/mmu-radix64.c
@@ -145,6 +145,13 @@ static void ppc_radix64_raise_hsi(PowerPCCPU *cpu, MMUAccessType access_type,
     CPUState *cs = CPU(cpu);
     CPUPPCState *env = &cpu->env;
 
+    env->error_code = 0;
+    if (cause & DSISR_PRTABLE_FAULT) {
+        /* HDSI PRTABLE_FAULT gets the originating access type in error_code */
+        env->error_code = access_type;
+        access_type = MMU_DATA_LOAD;
+    }
+
     qemu_log_mask(CPU_LOG_MMU, "%s for %s @0x%"VADDR_PRIx" 0x%"
                   HWADDR_PRIx" cause %08x\n",
                   __func__, access_str(access_type),
@@ -166,7 +173,6 @@ static void ppc_radix64_raise_hsi(PowerPCCPU *cpu, MMUAccessType access_type,
         env->spr[SPR_HDSISR] = cause;
         env->spr[SPR_HDAR] = eaddr;
         env->spr[SPR_ASDR] = g_raddr;
-        env->error_code = 0;
         break;
     default:
         g_assert_not_reached();
@@ -369,13 +375,14 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *pate)
 }
 
 static int ppc_radix64_partition_scoped_xlate(PowerPCCPU *cpu,
-                                              MMUAccessType access_type,
+                                              MMUAccessType orig_access_type,
                                               vaddr eaddr, hwaddr g_raddr,
                                               ppc_v3_pate_t pate,
                                               hwaddr *h_raddr, int *h_prot,
                                               int *h_page_size, bool pde_addr,
                                               int mmu_idx, bool guest_visible)
 {
+    MMUAccessType access_type = orig_access_type;
     int fault_cause = 0;
     hwaddr pte_addr;
     uint64_t pte;
@@ -404,7 +411,8 @@ static int ppc_radix64_partition_scoped_xlate(PowerPCCPU *cpu,
             fault_cause |= DSISR_PRTABLE_FAULT;
         }
         if (guest_visible) {
-            ppc_radix64_raise_hsi(cpu, access_type, eaddr, g_raddr, fault_cause);
+            ppc_radix64_raise_hsi(cpu, orig_access_type,
+                                  eaddr, g_raddr, fault_cause);
         }
         return 1;
     }
-- 
2.40.1



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

* [PATCH v4 4/6] target/ppc: Implement HEIR SPR
  2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
                   ` (2 preceding siblings ...)
  2023-05-30 13:25 ` [PATCH v4 3/6] target/ppc: Add SRR1 prefix indication to interrupt handlers Nicholas Piggin
@ 2023-05-30 13:25 ` Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 5/6] target/ppc: Add ISA v3.1 LEV indication in SRR1 for system call interrupts Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 6/6] target/ppc: Better CTRL SPR implementation Nicholas Piggin
  5 siblings, 0 replies; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc; +Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza

The hypervisor emulation assistance interrupt modifies HEIR to
contain the value of the instruction which caused the exception.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/cpu.h         |  1 +
 target/ppc/cpu_init.c    | 23 +++++++++++++++++++++++
 target/ppc/excp_helper.c | 13 ++++++++++++-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 0f9f2e1a0c..1f23b81e90 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1652,6 +1652,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_HMER              (0x150)
 #define SPR_HMEER             (0x151)
 #define SPR_PCR               (0x152)
+#define SPR_HEIR              (0x153)
 #define SPR_BOOKE_LPIDR       (0x152)
 #define SPR_BOOKE_TCR         (0x154)
 #define SPR_BOOKE_TLB0PS      (0x158)
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 723f28fb5a..aa364f36f6 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -1629,6 +1629,7 @@ static void register_8xx_sprs(CPUPPCState *env)
  * HSRR0   => SPR 314 (Power 2.04 hypv)
  * HSRR1   => SPR 315 (Power 2.04 hypv)
  * LPIDR   => SPR 317 (970)
+ * HEIR    => SPR 339 (Power 2.05 hypv) (64-bit reg from 3.1)
  * EPR     => SPR 702 (Power 2.04 emb)
  * perf    => 768-783 (Power 2.04)
  * perf    => 784-799 (Power 2.04)
@@ -5522,6 +5523,24 @@ static void register_power6_common_sprs(CPUPPCState *env)
                  0x00000000);
 }
 
+static void register_HEIR32_spr(CPUPPCState *env)
+{
+    spr_register_hv(env, SPR_HEIR, "HEIR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 &spr_read_generic, &spr_write_generic32,
+                 0x00000000);
+}
+
+static void register_HEIR64_spr(CPUPPCState *env)
+{
+    spr_register_hv(env, SPR_HEIR, "HEIR",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 &spr_read_generic, &spr_write_generic,
+                 0x00000000);
+}
+
 static void register_power8_tce_address_control_sprs(CPUPPCState *env)
 {
     spr_register_kvm(env, SPR_TAR, "TAR",
@@ -5950,6 +5969,7 @@ static void init_proc_POWER7(CPUPPCState *env)
     register_power5p_ear_sprs(env);
     register_power5p_tb_sprs(env);
     register_power6_common_sprs(env);
+    register_HEIR32_spr(env);
     register_power6_dbg_sprs(env);
     register_power7_book4_sprs(env);
 
@@ -6072,6 +6092,7 @@ static void init_proc_POWER8(CPUPPCState *env)
     register_power5p_ear_sprs(env);
     register_power5p_tb_sprs(env);
     register_power6_common_sprs(env);
+    register_HEIR32_spr(env);
     register_power6_dbg_sprs(env);
     register_power8_tce_address_control_sprs(env);
     register_power8_ids_sprs(env);
@@ -6234,6 +6255,7 @@ static void init_proc_POWER9(CPUPPCState *env)
     register_power5p_ear_sprs(env);
     register_power5p_tb_sprs(env);
     register_power6_common_sprs(env);
+    register_HEIR32_spr(env);
     register_power6_dbg_sprs(env);
     register_power8_tce_address_control_sprs(env);
     register_power8_ids_sprs(env);
@@ -6426,6 +6448,7 @@ static void init_proc_POWER10(CPUPPCState *env)
     register_power5p_ear_sprs(env);
     register_power5p_tb_sprs(env);
     register_power6_common_sprs(env);
+    register_HEIR64_spr(env);
     register_power6_dbg_sprs(env);
     register_power8_tce_address_control_sprs(env);
     register_power8_ids_sprs(env);
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index b4fcaa1d88..1533ad0f13 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -1611,13 +1611,24 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp)
     case POWERPC_EXCP_HDECR:     /* Hypervisor decrementer exception         */
     case POWERPC_EXCP_HDSI:      /* Hypervisor data storage exception        */
     case POWERPC_EXCP_SDOOR_HV:  /* Hypervisor Doorbell interrupt            */
-    case POWERPC_EXCP_HV_EMU:
     case POWERPC_EXCP_HVIRT:     /* Hypervisor virtualization                */
         srr0 = SPR_HSRR0;
         srr1 = SPR_HSRR1;
         new_msr |= (target_ulong)MSR_HVB;
         new_msr |= env->msr & ((target_ulong)1 << MSR_RI);
         break;
+    case POWERPC_EXCP_HV_EMU:
+        env->spr[SPR_HEIR] = insn;
+        if (is_prefix_excp(env, insn)) {
+            uint32_t insn2 = ppc_ldl_code(env, env->nip + 4);
+            env->spr[SPR_HEIR] <<= 32;
+            env->spr[SPR_HEIR] |= insn2;
+        }
+        srr0 = SPR_HSRR0;
+        srr1 = SPR_HSRR1;
+        new_msr |= (target_ulong)MSR_HVB;
+        new_msr |= env->msr & ((target_ulong)1 << MSR_RI);
+        break;
     case POWERPC_EXCP_VPU:       /* Vector unavailable exception             */
     case POWERPC_EXCP_VSXU:       /* VSX unavailable exception               */
     case POWERPC_EXCP_FU:         /* Facility unavailable exception          */
-- 
2.40.1



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

* [PATCH v4 5/6] target/ppc: Add ISA v3.1 LEV indication in SRR1 for system call interrupts
  2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
                   ` (3 preceding siblings ...)
  2023-05-30 13:25 ` [PATCH v4 4/6] target/ppc: Implement HEIR SPR Nicholas Piggin
@ 2023-05-30 13:25 ` Nicholas Piggin
  2023-05-30 13:25 ` [PATCH v4 6/6] target/ppc: Better CTRL SPR implementation Nicholas Piggin
  5 siblings, 0 replies; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc; +Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza

System call interrupts in ISA v3.1 CPUs add a LEV indication in SRR1
that corresponds with the LEV field of the instruction that caused the
interrupt.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/excp_helper.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 1533ad0f13..d69bd0033a 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -1561,6 +1561,10 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp)
             vhc->hypercall(cpu->vhyp, cpu);
             return;
         }
+        if (env->insns_flags2 & PPC2_ISA310) {
+            /* ISAv3.1 puts LEV into SRR1 */
+            msr |= lev << 20;
+        }
         if (lev == 1) {
             new_msr |= (target_ulong)MSR_HVB;
         }
-- 
2.40.1



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

* [PATCH v4 6/6] target/ppc: Better CTRL SPR implementation
  2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
                   ` (4 preceding siblings ...)
  2023-05-30 13:25 ` [PATCH v4 5/6] target/ppc: Add ISA v3.1 LEV indication in SRR1 for system call interrupts Nicholas Piggin
@ 2023-05-30 13:25 ` Nicholas Piggin
  5 siblings, 0 replies; 10+ messages in thread
From: Nicholas Piggin @ 2023-05-30 13:25 UTC (permalink / raw)
  To: qemu-ppc; +Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza

The CTRL register is able to write bit zero, and that is reflected in a
bit field in the register that reflects the state of all threads in the
core.

TCG does not implement SMT, so this just requires mirroring that bit into
the first bit of the thread state field.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/translate.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 9b7884586c..b6bab4c234 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -425,7 +425,14 @@ void spr_write_generic32(DisasContext *ctx, int sprn, int gprn)
 
 void spr_write_CTRL(DisasContext *ctx, int sprn, int gprn)
 {
-    spr_write_generic32(ctx, sprn, gprn);
+    /* This does not implement >1 thread */
+    TCGv t0 = tcg_temp_new();
+    TCGv t1 = tcg_temp_new();
+    tcg_gen_extract_tl(t0, cpu_gpr[gprn], 0, 1); /* Extract RUN field */
+    tcg_gen_shli_tl(t1, t0, 8); /* Duplicate the bit in TS */
+    tcg_gen_or_tl(t1, t1, t0);
+    gen_store_spr(sprn, t1);
+    spr_store_dump_spr(sprn);
 
     /*
      * SPR_CTRL writes must force a new translation block,
-- 
2.40.1



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

* Re: [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt
  2023-05-30 13:25 ` [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt Nicholas Piggin
@ 2023-06-14  5:51   ` Anushree Mathur
  2023-06-15  2:51     ` Nicholas Piggin
  0 siblings, 1 reply; 10+ messages in thread
From: Anushree Mathur @ 2023-06-14  5:51 UTC (permalink / raw)
  To: Nicholas Piggin, qemu-ppc
  Cc: Nicholas Piggin, qemu-devel, Daniel Henrique Barboza, harshpb

[-- Attachment #1: Type: text/plain, Size: 4195 bytes --]


On 5/30/23 18:55, Nicholas Piggin wrote:
> powerpc ifetch endianness depends on MSR[LE] so it has to byteswap
> after cpu_ldl_code(). This corrects DSISR bits in alignment
> interrupts when running in little endian mode.
>
> Reviewed-by: Fabiano Rosas<farosas@suse.de>
> Signed-off-by: Nicholas Piggin<npiggin@gmail.com>
> ---
>   target/ppc/excp_helper.c | 22 +++++++++++++++++++++-
>   1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
> index c13f2afa04..0274617b4a 100644
> --- a/target/ppc/excp_helper.c
> +++ b/target/ppc/excp_helper.c
> @@ -133,6 +133,26 @@ static void dump_hcall(CPUPPCState *env)
>                     env->nip);
>   }
>   
> +#ifdef CONFIG_TCG
> +/* Return true iff byteswap is needed in a scalar memop */
> +static inline bool need_byteswap(CPUArchState *env)
> +{
> +    /* SOFTMMU builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */
> +    return !!(env->msr & ((target_ulong)1 << MSR_LE));
> +}
> +
> +static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)

This hunk fails to compile with configure --disable-tcg

> FAILED: libqemu-ppc64-softmmu.fa.p/target_ppc_excp_helper.c.o
> cc -m64 -mlittle-endian -Ilibqemu-ppc64-softmmu.fa.p -I. -I..
> -Itarget/ppc -I../target/ppc -I../dtc/libfdt -Iqapi -Itrace -Iui
> -Iui/shader -I/usr/include/pixman-1 -I/usr/include/glib-2.0
> -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4
> -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g
> -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wundef
> -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes
> -Wredundant-decls -Wold-style-declaration -Wold-style-definition
> -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self
> -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels
> -Wexpansion-to-defined -Wimplicit-fallthrough=2
> -Wmissing-format-attribute -Wno-missing-include-dirs
> -Wno-shift-negative-value -Wno-psabi -isystem
> /home/Shreya/qemu/linux-headers -isystem linux-headers -iquote . -iquote
> /home/Shreya/qemu -iquote /home/Shreya/qemu/include -pthread
> -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
> -fno-strict-aliasing -fno-common -fwrapv -fPIE -isystem../linux-headers
> -isystemlinux-headers -DNEED_CPU_H
> '-DCONFIG_TARGET="ppc64-softmmu-config-target.h"'
> '-DCONFIG_DEVICES="ppc64-softmmu-config-devices.h"' -MD -MQ
> libqemu-ppc64-softmmu.fa.p/target_ppc_excp_helper.c.o -MF
> libqemu-ppc64-softmmu.fa.p/target_ppc_excp_helper.c.o.d -o
> libqemu-ppc64-softmmu.fa.p/target_ppc_excp_helper.c.o -c
> ../target/ppc/excp_helper.c
> ../target/ppc/excp_helper.c:143:49: error: unknown type name ‘abi_ptr’;
> did you mean ‘si_ptr’?
>     143 | static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
>         |                                                 ^~~~~~~
>         |                                                 si_ptr
> ../target/ppc/excp_helper.c: In function ‘powerpc_excp_books’:
> ../target/ppc/excp_helper.c:1416:16: error: implicit declaration of
> function ‘ppc_ldl_code’ [-Werror=implicit-function-declaration]
>    1416 |         insn = ppc_ldl_code(env, env->nip);
>         |                ^~~~~~~~~~~~
> ../target/ppc/excp_helper.c:1416:16: error: nested extern declaration of
> ‘ppc_ldl_code’ [-Werror=nested-externs]
> cc1: all warnings being treated as errors

> +{
> +    uint32_t insn = cpu_ldl_code(env, addr);
> +
> +    if (need_byteswap(env)) {
> +        insn = bswap32(insn);
> +    }
> +
> +    return insn;
> +}
> +#endif
> +
>   static void ppc_excp_debug_sw_tlb(CPUPPCState *env, int excp)
>   {
>       const char *es;
> @@ -3100,7 +3120,7 @@ void ppc_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
>   
>       /* Restore state and reload the insn we executed, for filling in DSISR.  */
>       cpu_restore_state(cs, retaddr);
> -    insn = cpu_ldl_code(env, env->nip);
> +    insn = ppc_ldl_code(env, env->nip);
>   
>       switch (env->mmu_model) {
>       case POWERPC_MMU_SOFT_4xx:

[-- Attachment #2: Type: text/html, Size: 7037 bytes --]

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

* Re: [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt
  2023-06-14  5:51   ` Anushree Mathur
@ 2023-06-15  2:51     ` Nicholas Piggin
  2023-06-16  9:48       ` Anushree Mathur
  0 siblings, 1 reply; 10+ messages in thread
From: Nicholas Piggin @ 2023-06-15  2:51 UTC (permalink / raw)
  To: Anushree Mathur, qemu-ppc; +Cc: qemu-devel, Daniel Henrique Barboza, harshpb

On Wed Jun 14, 2023 at 3:51 PM AEST, Anushree Mathur wrote:
>
> On 5/30/23 18:55, Nicholas Piggin wrote:
> > powerpc ifetch endianness depends on MSR[LE] so it has to byteswap
> > after cpu_ldl_code(). This corrects DSISR bits in alignment
> > interrupts when running in little endian mode.
> >
> > Reviewed-by: Fabiano Rosas<farosas@suse.de>
> > Signed-off-by: Nicholas Piggin<npiggin@gmail.com>
> > ---
> >   target/ppc/excp_helper.c | 22 +++++++++++++++++++++-
> >   1 file changed, 21 insertions(+), 1 deletion(-)
> >
> > diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
> > index c13f2afa04..0274617b4a 100644
> > --- a/target/ppc/excp_helper.c
> > +++ b/target/ppc/excp_helper.c
> > @@ -133,6 +133,26 @@ static void dump_hcall(CPUPPCState *env)
> >                     env->nip);
> >   }
> >   
> > +#ifdef CONFIG_TCG
> > +/* Return true iff byteswap is needed in a scalar memop */
> > +static inline bool need_byteswap(CPUArchState *env)
> > +{
> > +    /* SOFTMMU builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */
> > +    return !!(env->msr & ((target_ulong)1 << MSR_LE));
> > +}
> > +
> > +static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
>
> This hunk fails to compile with configure --disable-tcg

I don't see how since it's inside CONFIG_TCG. Seems to work here.
You don't have an old version of the patch applied?

What configure options exactly?

Thanks,
Nick


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

* Re: [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt
  2023-06-15  2:51     ` Nicholas Piggin
@ 2023-06-16  9:48       ` Anushree Mathur
  0 siblings, 0 replies; 10+ messages in thread
From: Anushree Mathur @ 2023-06-16  9:48 UTC (permalink / raw)
  To: Nicholas Piggin, qemu-ppc; +Cc: qemu-devel, Daniel Henrique Barboza, harshpb


On 6/15/23 08:21, Nicholas Piggin wrote:
> On Wed Jun 14, 2023 at 3:51 PM AEST, Anushree Mathur wrote:
>> On 5/30/23 18:55, Nicholas Piggin wrote:
>>> powerpc ifetch endianness depends on MSR[LE] so it has to byteswap
>>> after cpu_ldl_code(). This corrects DSISR bits in alignment
>>> interrupts when running in little endian mode.
>>>
>>> Reviewed-by: Fabiano Rosas<farosas@suse.de>
>>> Signed-off-by: Nicholas Piggin<npiggin@gmail.com>
>>> ---
>>>    target/ppc/excp_helper.c | 22 +++++++++++++++++++++-
>>>    1 file changed, 21 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
>>> index c13f2afa04..0274617b4a 100644
>>> --- a/target/ppc/excp_helper.c
>>> +++ b/target/ppc/excp_helper.c
>>> @@ -133,6 +133,26 @@ static void dump_hcall(CPUPPCState *env)
>>>                      env->nip);
>>>    }
>>>    
>>> +#ifdef CONFIG_TCG
>>> +/* Return true iff byteswap is needed in a scalar memop */
>>> +static inline bool need_byteswap(CPUArchState *env)
>>> +{
>>> +    /* SOFTMMU builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */
>>> +    return !!(env->msr & ((target_ulong)1 << MSR_LE));
>>> +}
>>> +
>>> +static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
>> This hunk fails to compile with configure --disable-tcg
> I don't see how since it's inside CONFIG_TCG. Seems to work here.
> You don't have an old version of the patch applied?
>
> What configure options exactly?
>
> Thanks,
> Nick

The configure options i used are:

./configure --target-list=ppc64-softmmu --disable-tcg --prefix=/usr

I applied the latest patches but still i was seeing the same issue. Can 
you check this once!

Thanks,

Anushree-Mathur



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

end of thread, other threads:[~2023-06-16  9:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 13:25 [PATCH v4 0/6] target/ppc: Assorted ppc target fixes Nicholas Piggin
2023-05-30 13:25 ` [PATCH v4 1/6] target/ppc: Fix instruction loading endianness in alignment interrupt Nicholas Piggin
2023-06-14  5:51   ` Anushree Mathur
2023-06-15  2:51     ` Nicholas Piggin
2023-06-16  9:48       ` Anushree Mathur
2023-05-30 13:25 ` [PATCH v4 2/6] target/ppc: Change partition-scope translate interface Nicholas Piggin
2023-05-30 13:25 ` [PATCH v4 3/6] target/ppc: Add SRR1 prefix indication to interrupt handlers Nicholas Piggin
2023-05-30 13:25 ` [PATCH v4 4/6] target/ppc: Implement HEIR SPR Nicholas Piggin
2023-05-30 13:25 ` [PATCH v4 5/6] target/ppc: Add ISA v3.1 LEV indication in SRR1 for system call interrupts Nicholas Piggin
2023-05-30 13:25 ` [PATCH v4 6/6] target/ppc: Better CTRL SPR implementation Nicholas Piggin

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