All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] target/ppc: Fixes for hash MMU for ISA v3.0
@ 2023-07-21  5:02 Nicholas Piggin
  2023-07-21  5:02 ` [PATCH 1/2] target/ppc: Implement ASDR register for ISA v3.0 for HPT Nicholas Piggin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nicholas Piggin @ 2023-07-21  5:02 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: Nicholas Piggin, Cédric Le Goater,
	Frédéric Barrat, David Gibson, Greg Kurz,
	Harsh Prateek Bora, qemu-ppc, qemu-devel, qemu-stable

This fixes a couple of deficiencies in the v3.0 and later (POWER9, 10)
HPT MMU implementation. With these fixes, KVM is unable to boot hash
guests on powernv9/10 machines. Bare metal hash or pseries machine with
hash works, because VRMA is only used when a real hypervisor is
virtualizing a hash guest's real mode addressing.

Thanks,
Nick

Nicholas Piggin (2):
  target/ppc: Implement ASDR register for ISA v3.0 for HPT
  target/ppc: Fix VRMA page size for ISA v3.0

 target/ppc/mmu-hash64.c | 68 ++++++++++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 17 deletions(-)

-- 
2.40.1



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

* [PATCH 1/2] target/ppc: Implement ASDR register for ISA v3.0 for HPT
  2023-07-21  5:02 [PATCH 0/2] target/ppc: Fixes for hash MMU for ISA v3.0 Nicholas Piggin
@ 2023-07-21  5:02 ` Nicholas Piggin
  2023-07-21  5:02 ` [PATCH 2/2] target/ppc: Fix VRMA page size for ISA v3.0 Nicholas Piggin
  2023-07-21  7:27 ` [PATCH 0/2] target/ppc: Fixes for hash MMU " Cédric Le Goater
  2 siblings, 0 replies; 4+ messages in thread
From: Nicholas Piggin @ 2023-07-21  5:02 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: Nicholas Piggin, Cédric Le Goater,
	Frédéric Barrat, David Gibson, Greg Kurz,
	Harsh Prateek Bora, qemu-ppc, qemu-devel, qemu-stable

The ASDR register was introduced in ISA v3.0. It has not been
implemented for HPT. With HPT, ASDR is the format of the slbmte RS
operand (containing VSID), which matches the ppc_slb_t field.

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

diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 900f906990..a0c90df3ce 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -770,7 +770,8 @@ static bool ppc_hash64_use_vrma(CPUPPCState *env)
     }
 }
 
-static void ppc_hash64_set_isi(CPUState *cs, int mmu_idx, uint64_t error_code)
+static void ppc_hash64_set_isi(CPUState *cs, int mmu_idx, uint64_t slb_vsid,
+                               uint64_t error_code)
 {
     CPUPPCState *env = &POWERPC_CPU(cs)->env;
     bool vpm;
@@ -782,13 +783,15 @@ static void ppc_hash64_set_isi(CPUState *cs, int mmu_idx, uint64_t error_code)
     }
     if (vpm && !mmuidx_hv(mmu_idx)) {
         cs->exception_index = POWERPC_EXCP_HISI;
+        env->spr[SPR_ASDR] = slb_vsid;
     } else {
         cs->exception_index = POWERPC_EXCP_ISI;
     }
     env->error_code = error_code;
 }
 
-static void ppc_hash64_set_dsi(CPUState *cs, int mmu_idx, uint64_t dar, uint64_t dsisr)
+static void ppc_hash64_set_dsi(CPUState *cs, int mmu_idx, uint64_t slb_vsid,
+                               uint64_t dar, uint64_t dsisr)
 {
     CPUPPCState *env = &POWERPC_CPU(cs)->env;
     bool vpm;
@@ -802,6 +805,7 @@ static void ppc_hash64_set_dsi(CPUState *cs, int mmu_idx, uint64_t dar, uint64_t
         cs->exception_index = POWERPC_EXCP_HDSI;
         env->spr[SPR_HDAR] = dar;
         env->spr[SPR_HDSISR] = dsisr;
+        env->spr[SPR_ASDR] = slb_vsid;
     } else {
         cs->exception_index = POWERPC_EXCP_DSI;
         env->spr[SPR_DAR] = dar;
@@ -963,13 +967,13 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
                 }
                 switch (access_type) {
                 case MMU_INST_FETCH:
-                    ppc_hash64_set_isi(cs, mmu_idx, SRR1_PROTFAULT);
+                    ppc_hash64_set_isi(cs, mmu_idx, 0, SRR1_PROTFAULT);
                     break;
                 case MMU_DATA_LOAD:
-                    ppc_hash64_set_dsi(cs, mmu_idx, eaddr, DSISR_PROTFAULT);
+                    ppc_hash64_set_dsi(cs, mmu_idx, 0, eaddr, DSISR_PROTFAULT);
                     break;
                 case MMU_DATA_STORE:
-                    ppc_hash64_set_dsi(cs, mmu_idx, eaddr,
+                    ppc_hash64_set_dsi(cs, mmu_idx, 0, eaddr,
                                        DSISR_PROTFAULT | DSISR_ISSTORE);
                     break;
                 default:
@@ -1022,7 +1026,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
     /* 3. Check for segment level no-execute violation */
     if (access_type == MMU_INST_FETCH && (slb->vsid & SLB_VSID_N)) {
         if (guest_visible) {
-            ppc_hash64_set_isi(cs, mmu_idx, SRR1_NOEXEC_GUARD);
+            ppc_hash64_set_isi(cs, mmu_idx, slb->vsid, SRR1_NOEXEC_GUARD);
         }
         return false;
     }
@@ -1035,13 +1039,14 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
         }
         switch (access_type) {
         case MMU_INST_FETCH:
-            ppc_hash64_set_isi(cs, mmu_idx, SRR1_NOPTE);
+            ppc_hash64_set_isi(cs, mmu_idx, slb->vsid, SRR1_NOPTE);
             break;
         case MMU_DATA_LOAD:
-            ppc_hash64_set_dsi(cs, mmu_idx, eaddr, DSISR_NOPTE);
+            ppc_hash64_set_dsi(cs, mmu_idx, slb->vsid, eaddr, DSISR_NOPTE);
             break;
         case MMU_DATA_STORE:
-            ppc_hash64_set_dsi(cs, mmu_idx, eaddr, DSISR_NOPTE | DSISR_ISSTORE);
+            ppc_hash64_set_dsi(cs, mmu_idx, slb->vsid, eaddr,
+                               DSISR_NOPTE | DSISR_ISSTORE);
             break;
         default:
             g_assert_not_reached();
@@ -1075,7 +1080,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
             if (PAGE_EXEC & ~amr_prot) {
                 srr1 |= SRR1_IAMR; /* Access violates virt pg class key prot */
             }
-            ppc_hash64_set_isi(cs, mmu_idx, srr1);
+            ppc_hash64_set_isi(cs, mmu_idx, slb->vsid, srr1);
         } else {
             int dsisr = 0;
             if (need_prot & ~pp_prot) {
@@ -1087,7 +1092,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
             if (need_prot & ~amr_prot) {
                 dsisr |= DSISR_AMR;
             }
-            ppc_hash64_set_dsi(cs, mmu_idx, eaddr, dsisr);
+            ppc_hash64_set_dsi(cs, mmu_idx, slb->vsid, eaddr, dsisr);
         }
         return false;
     }
-- 
2.40.1



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

* [PATCH 2/2] target/ppc: Fix VRMA page size for ISA v3.0
  2023-07-21  5:02 [PATCH 0/2] target/ppc: Fixes for hash MMU for ISA v3.0 Nicholas Piggin
  2023-07-21  5:02 ` [PATCH 1/2] target/ppc: Implement ASDR register for ISA v3.0 for HPT Nicholas Piggin
@ 2023-07-21  5:02 ` Nicholas Piggin
  2023-07-21  7:27 ` [PATCH 0/2] target/ppc: Fixes for hash MMU " Cédric Le Goater
  2 siblings, 0 replies; 4+ messages in thread
From: Nicholas Piggin @ 2023-07-21  5:02 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: Nicholas Piggin, Cédric Le Goater,
	Frédéric Barrat, David Gibson, Greg Kurz,
	Harsh Prateek Bora, qemu-ppc, qemu-devel, qemu-stable

Until v2.07s, the VRMA page size (L||LP) was encoded in LPCR[VRMASD].
In v3.0 that moved to the partition table PS field.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/mmu-hash64.c | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index a0c90df3ce..bda0ba90ea 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -874,12 +874,41 @@ static target_ulong rmls_limit(PowerPCCPU *cpu)
     return rma_sizes[rmls];
 }
 
-static int build_vrma_slbe(PowerPCCPU *cpu, ppc_slb_t *slb)
+/* Return the LLP in SLB_VSID format */
+static uint64_t get_vrma_llp(PowerPCCPU *cpu)
 {
     CPUPPCState *env = &cpu->env;
-    target_ulong lpcr = env->spr[SPR_LPCR];
-    uint32_t vrmasd = (lpcr & LPCR_VRMASD) >> LPCR_VRMASD_SHIFT;
-    target_ulong vsid = SLB_VSID_VRMA | ((vrmasd << 4) & SLB_VSID_LLP_MASK);
+    uint64_t llp;
+
+    if (env->mmu_model == POWERPC_MMU_3_00) {
+        ppc_v3_pate_t pate;
+        uint64_t ps;
+
+        /*
+         * ISA v3.0 removes the LPCR[VRMASD] field and puts the VRMA base
+         * page size (L||LP equivalent) in the PS field in the HPT partition
+         * table entry.
+         */
+        if (!ppc64_v3_get_pate(cpu, cpu->env.spr[SPR_LPIDR], &pate)) {
+            error_report("Bad VRMA with no partition table entry\n");
+            return 0;
+        }
+        ps = pate.dw0 >> (63 - 58);
+        llp = ((ps & 0x4) << (63 - 55 - 2)) | ((ps & 0x3) << (63 - 59));
+
+    } else {
+        uint64_t lpcr = env->spr[SPR_LPCR];
+        target_ulong vrmasd = (lpcr & LPCR_VRMASD) >> LPCR_VRMASD_SHIFT;
+
+        llp = (vrmasd << 4) & SLB_VSID_LLP_MASK;
+    }
+
+    return llp;
+}
+
+static int build_vrma_slbe(PowerPCCPU *cpu, ppc_slb_t *slb)
+{
+    target_ulong vsid = SLB_VSID_VRMA | get_vrma_llp(cpu);
     int i;
 
     for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
@@ -897,8 +926,8 @@ static int build_vrma_slbe(PowerPCCPU *cpu, ppc_slb_t *slb)
         }
     }
 
-    error_report("Bad page size encoding in LPCR[VRMASD]; LPCR=0x"
-                 TARGET_FMT_lx, lpcr);
+    error_report("Bad VRMA page size encoding 0x" TARGET_FMT_lx,
+                 get_vrma_llp(cpu));
 
     return -1;
 }
-- 
2.40.1



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

* Re: [PATCH 0/2] target/ppc: Fixes for hash MMU for ISA v3.0
  2023-07-21  5:02 [PATCH 0/2] target/ppc: Fixes for hash MMU for ISA v3.0 Nicholas Piggin
  2023-07-21  5:02 ` [PATCH 1/2] target/ppc: Implement ASDR register for ISA v3.0 for HPT Nicholas Piggin
  2023-07-21  5:02 ` [PATCH 2/2] target/ppc: Fix VRMA page size for ISA v3.0 Nicholas Piggin
@ 2023-07-21  7:27 ` Cédric Le Goater
  2 siblings, 0 replies; 4+ messages in thread
From: Cédric Le Goater @ 2023-07-21  7:27 UTC (permalink / raw)
  To: Nicholas Piggin, Daniel Henrique Barboza
  Cc: Frédéric Barrat, David Gibson, Greg Kurz,
	Harsh Prateek Bora, qemu-ppc, qemu-devel, qemu-stable

Hello Nick,

On 7/21/23 07:02, Nicholas Piggin wrote:
> This fixes a couple of deficiencies in the v3.0 and later (POWER9, 10)
> HPT MMU implementation. With these fixes, KVM is unable to boot hash
> guests on powernv9/10 machines. Bare metal hash or pseries machine with
> hash works, because VRMA is only used when a real hypervisor is
> virtualizing a hash guest's real mode addressing.
> 
> Thanks,
> Nick

Could please add Fixes tags to your 'fix' patches ? No need to resend
just reply on the mailing list with :

   Fixes: <commit> "subject"

Also for the "target/ppc: Fix pending HDEC when entering PM state" patch.

Thanks,

C.

  
> Nicholas Piggin (2):
>    target/ppc: Implement ASDR register for ISA v3.0 for HPT
>    target/ppc: Fix VRMA page size for ISA v3.0
> 
>   target/ppc/mmu-hash64.c | 68 ++++++++++++++++++++++++++++++-----------
>   1 file changed, 51 insertions(+), 17 deletions(-)
> 



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

end of thread, other threads:[~2023-07-21  7:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21  5:02 [PATCH 0/2] target/ppc: Fixes for hash MMU for ISA v3.0 Nicholas Piggin
2023-07-21  5:02 ` [PATCH 1/2] target/ppc: Implement ASDR register for ISA v3.0 for HPT Nicholas Piggin
2023-07-21  5:02 ` [PATCH 2/2] target/ppc: Fix VRMA page size for ISA v3.0 Nicholas Piggin
2023-07-21  7:27 ` [PATCH 0/2] target/ppc: Fixes for hash MMU " Cédric Le Goater

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.