Skip to contentSkip to conversation

PPC64 Linux bringup patches v2

PATCH In review Alexander Graf 4 participants 16 messages Mar 5, 2009 – Mar 6, 2009

lore
Share & tools
lore
#0 lore raw

cover PPC64 Linux bringup patches v2

After spending even more time trying to get qemu-system-ppc64 to run Linux, I get up to the pretty penguin on the screen now ;-).

I am aware that this patchset is not 100% accurate and perfect for emulation, but I think that it can't get worse than it is now.

This patchset enhances MMU support to work with large pages, implement tlbiel, and fixes random issues I ran into while getting closer to the kernel running userspace code :).

Keep in mind that this also requires an OpenBIOS update, as the current code is not aware that it gets run in 64 bit mode.

Also, I am now stuck at a kernel panic in the pmz initialization, because the Device Tree doesn't contain proper interrupt line propagation. I am seriously lost there and it would be awesome if someone with more OpenFirmware knowledge could step in here.

Alexander Graf (7):
PPC64: Implement slbmte
PPC64: Implement large pages
PPC64: Implment tlbiel
Activate uninorth AGP bridge
PPC64: Nop some SPRs on 970fx
PPC64: Enable 64bit mode on interrupts
PPC64: Don't fault at lwsync

 hw/unin_pci.c               |   27 +++------
 target-ppc/cpu.h            |    4 +-
 target-ppc/helper.c         |  141 +++++++++++++++++++++++++++++--------------
 target-ppc/op_helper.c      |    6 +-
 target-ppc/translate.c      |   41 +++++++++++-
 target-ppc/translate_init.c |   12 ++++
 6 files changed, 160 insertions(+), 71 deletions(-)
#1 lore raw

PATCH 1/7 PPC64: Implement slbmte

In order to modify SLB entries on recent PPC64 machines, the slbmte instruction is used.

This patch implements the slbmte instruction and makes the "bridge" mode code use the slb set functions, so we can move the SLB into the CPU struct later.

This is required for Linux to run on PPC64.

---
 target-ppc/cpu.h       |    3 +-
 target-ppc/helper.c    |   57 ++++++++++++++++++++++++++++++++++++-----------
 target-ppc/op_helper.c |    6 +++-
 target-ppc/translate.c |   23 ++++++++++++++++---
 4 files changed, 68 insertions(+), 21 deletions(-)
target-ppc/cpu.h +2 -1
index bdc3cf9..f53be5a 100644
@@ -714,7 +714,8 @@ void ppc_store_sdr1 (CPUPPCState *env, target_ulong value);
 #if defined(TARGET_PPC64)
 void ppc_store_asr (CPUPPCState *env, target_ulong value);
 target_ulong ppc_load_slb (CPUPPCState *env, int slb_nr);
-void ppc_store_slb (CPUPPCState *env, int slb_nr, target_ulong rs);
+target_ulong ppc_load_sr (CPUPPCState *env, int sr_nr);
+void ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs);
 #endif /* defined(TARGET_PPC64) */
 void ppc_store_sr (CPUPPCState *env, int srnum, target_ulong value);
 #endif /* !defined(CONFIG_USER_ONLY) */
target-ppc/helper.c +43 -14

81 lines not on this page · raw message

target-ppc/op_helper.c +4 -2
index 3afd217..527f8de 100644
@@ -3752,6 +3752,8 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
 /* Segment registers load and store */
 target_ulong helper_load_sr (target_ulong sr_num)
 {
+    if (env->mmu_model & POWERPC_MMU_64)
+        return ppc_load_sr(env, sr_num);
     return env->sr[sr_num];
 }
 
@@ -3767,9 +3769,9 @@ target_ulong helper_load_slb (target_ulong slb_nr)
     return ppc_load_slb(env, slb_nr);
 }
 
-void helper_store_slb (target_ulong slb_nr, target_ulong rs)
+void helper_store_slb (target_ulong rb, target_ulong rs)
 {
-    ppc_store_slb(env, slb_nr, rs);
+    ppc_store_slb(env, rb, rs);
 }
 
 void helper_slbia (void)
target-ppc/translate.c +19 -4
index 489ba09..f48ab20 100644
@@ -4296,7 +4296,7 @@ GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B)
         return;
     }
     t0 = tcg_const_tl(SR(ctx->opcode));
-    gen_helper_load_slb(cpu_gpr[rD(ctx->opcode)], t0);
+    gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
     tcg_temp_free(t0);
 #endif
 }
@@ -4316,7 +4316,7 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
     t0 = tcg_temp_new();
     tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
     tcg_gen_andi_tl(t0, t0, 0xF);
-    gen_helper_load_slb(cpu_gpr[rD(ctx->opcode)], t0);
+    gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
     tcg_temp_free(t0);
 #endif
 }
@@ -4333,7 +4333,7 @@ GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B)
         return;
     }
     t0 = tcg_const_tl(SR(ctx->opcode));
-    gen_helper_store_slb(t0, cpu_gpr[rS(ctx->opcode)]);
+    gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
     tcg_temp_free(t0);
 #endif
 }
@@ -4353,10 +4353,25 @@ GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
     t0 = tcg_temp_new();
     tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
     tcg_gen_andi_tl(t0, t0, 0xF);
-    gen_helper_store_slb(t0, cpu_gpr[rS(ctx->opcode)]);
+    gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
     tcg_temp_free(t0);
 #endif
 }
+
+/* slbmte */
+GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x00000000, PPC_SEGMENT_64B)
+{
+#if defined(CONFIG_USER_ONLY)
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
+#else
+    if (unlikely(!ctx->mem_idx)) {
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
+        return;
+    }
+    gen_helper_store_slb(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
+#endif
+}
+
 #endif /* defined(TARGET_PPC64) */
 
 /***                      Lookaside buffer management                      ***/
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/7 PPC64: Implement large pages

The current SLB/PTE code does not support large pages, which are required by Linux, as it boots up with the kernel regions up as large.

This patch implements large page support, so we can run Linux.

---
 target-ppc/cpu.h    |    1 +
 target-ppc/helper.c |   78 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 49 insertions(+), 30 deletions(-)
target-ppc/cpu.h +1 -0
index f53be5a..c88f81b 100644
@@ -675,6 +675,7 @@ struct CPUPPCState {
 typedef struct mmu_ctx_t mmu_ctx_t;
 struct mmu_ctx_t {
     target_phys_addr_t raddr;      /* Real address              */
+    target_phys_addr_t eaddr;      /* Effective address         */
     int prot;                      /* Protection bits           */
     target_phys_addr_t pg_addr[2]; /* PTE tables base addresses */
     target_ulong ptem;             /* Virtual segment ID | API  */
target-ppc/helper.c +48 -30

176 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/7 PPC64: Implment tlbiel

Linux uses tlbiel to flush TLB entries in PPC64 mode. This special TLB flush opcode only flushes an entry for the CPU it runs on, not across all CPUs in the system.

---
 target-ppc/translate.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
target-ppc/translate.c +14 -0
index f48ab20..b5de33b 100644
@@ -4390,6 +4390,20 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
 #endif
 }
 
+/* tlbiel */
+GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE)
+{
+#if defined(CONFIG_USER_ONLY)
+    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
+#else
+    if (unlikely(!ctx->mem_idx)) {
+        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
+        return;
+    }
+    gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
+#endif
+}
+
 /* tlbie */
 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
 {
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/7 Activate uninorth AGP bridge

Linux tries to poke the AGP bridge port and is pretty sad when it can't, so let's activate the old code again and throw out the bit modifications, as we don't really do anything with the values anyways.

---
 hw/unin_pci.c |   27 ++++++++-------------------
 1 files changed, 8 insertions(+), 19 deletions(-)
hw/unin_pci.c +8 -19
index 949e63f..c734f1c 100644
@@ -92,17 +92,12 @@ static CPUReadMemoryFunc *pci_unin_main_read[] = {
     &pci_host_data_readl,
 };
 
-#if 0
-
 static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr,
                                     uint32_t val)
 {
     UNINState *s = opaque;
 
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    s->config_reg = 0x80000000 | (val & ~0x00000001);
+    s->config_reg = val;
 }
 
 static uint32_t pci_unin_config_readl (void *opaque,
@@ -111,12 +106,7 @@ static uint32_t pci_unin_config_readl (void *opaque,
     UNINState *s = opaque;
     uint32_t val;
 
-    val = (s->config_reg | 0x00000001) & ~0x80000000;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-
-    return val;
+    return s->config_reg;
 }
 
 static CPUWriteMemoryFunc *pci_unin_config_write[] = {
@@ -131,6 +121,7 @@ static CPUReadMemoryFunc *pci_unin_config_read[] = {
     &pci_unin_config_readl,
 };
 
+#if 0
 static CPUWriteMemoryFunc *pci_unin_write[] = {
     &pci_host_pci_writeb,
     &pci_host_pci_writew,
@@ -233,18 +224,17 @@ PCIBus *pci_pmac_init(qemu_irq *pic)
     d->config[0x27] = 0x7F;
     // d->config[0x34] = 0xdc // capabilities_pointer
 #endif
-#if 0 // XXX: not needed for now
+
     /* Uninorth AGP bus */
-    s = &pci_bridge[1];
     pci_mem_config = cpu_register_io_memory(0, pci_unin_config_read,
                                             pci_unin_config_write, s);
-    pci_mem_data = cpu_register_io_memory(0, pci_unin_read,
-                                          pci_unin_write, s);
+    pci_mem_data = cpu_register_io_memory(0, pci_unin_main_read,
+                                          pci_unin_main_write, s);
     cpu_register_physical_memory(0xf0800000, 0x1000, pci_mem_config);
     cpu_register_physical_memory(0xf0c00000, 0x1000, pci_mem_data);
 
-    d = pci_register_device("Uni-north AGP", sizeof(PCIDevice), 0, 11 << 3,
-                            NULL, NULL);
+    d = pci_register_device(s->bus, "Uni-north AGP", sizeof(PCIDevice),
+                            11 << 3, NULL, NULL);
     pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE);
     pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_AGP);
     d->config[0x08] = 0x00; // revision
@@ -253,7 +243,6 @@ PCIBus *pci_pmac_init(qemu_irq *pic)
     d->config[0x0D] = 0x10; // latency_timer
     d->config[0x0E] = 0x00; // header_type
     //    d->config[0x34] = 0x80; // capabilities_pointer
-#endif
 
 #if 0 // XXX: not needed for now
     /* Uninorth internal bus */
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/7 PPC64: Nop some SPRs on 970fx

Linux tries to access some SPRs on PPC64 boot. Let's just ignore those for the 970fx for now to make it happy.

---
 target-ppc/translate_init.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
target-ppc/translate_init.c +12 -0
index 6b7ab98..815a0c5 100644
@@ -6043,6 +6043,18 @@ static void init_proc_970FX (CPUPPCState *env)
                  SPR_NOACCESS, SPR_NOACCESS,
                  &spr_read_hior, &spr_write_hior,
                  0x00000000);
+    spr_register(env, SPR_CTRL, "SPR_CTRL",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 &spr_read_generic, &spr_write_generic,
+                 0x00000000);
+    spr_register(env, SPR_UCTRL, "SPR_UCTRL",
+                 SPR_NOACCESS, SPR_NOACCESS,
+                 &spr_read_generic, &spr_write_generic,
+                 0x00000000);
+    spr_register(env, SPR_VRSAVE, "SPR_VRSAVE",
+                 &spr_read_generic, SPR_NOACCESS,
+                 &spr_read_generic, &spr_write_generic,
+                 0x00000000);
 #if !defined(CONFIG_USER_ONLY)
     env->slb_nr = 32;
 #endif
Signature · 1 line
1.6.0.2
#6 lore raw

PATCH 6/7 PPC64: Enable 64bit mode on interrupts

Real 970s enable MSR_SF on all interrupts. The current code didn't do this until now, so let's activate it!

---
 target-ppc/helper.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
target-ppc/helper.c +5 -1
index 0fa87dc..7fe3f8f 100644
@@ -2607,7 +2607,7 @@ static always_inline void powerpc_excp (CPUState *env,
             new_msr |= (target_ulong)1 << MSR_CM;
         }
     } else {
-        if (!msr_isf) {
+        if (!msr_isf && !(env->mmu_model & POWERPC_MMU_64)) {
             new_msr &= ~((target_ulong)1 << MSR_SF);
             vector = (uint32_t)vector;
         } else {
@@ -2788,6 +2788,10 @@ void cpu_ppc_reset (void *opaque)
         ppc_tlb_invalidate_all(env);
 #endif
     env->msr = msr & env->msr_mask;
+#if defined(TARGET_PPC64)
+    if (env->mmu_model & POWERPC_MMU_64)
+        env->msr |= (1ULL << MSR_SF);
+#endif
     hreg_compute_hflags(env);
     env->reserve = (target_ulong)-1ULL;
     /* Be sure no exception or interrupt is pending */
Signature · 1 line
1.6.0.2
#7 lore raw

PATCH 7/7 PPC64: Don't fault at lwsync

Right now we can throw a fault on lwsync, even though the fault is actually caused by the instruction after lwsync.

I haven't found the magic that messed this up, but for now we can just end the TB on lwsync, forcing the next command to issue faults itself.

If anyone knows how to really fix this, please step forward and do so. This only makes things work at all for me :-).

---
 target-ppc/translate.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
target-ppc/translate.c +4 -0
index b5de33b..c994ad7 100644
@@ -3289,6 +3289,10 @@ GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
 /* sync */
 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC)
 {
+    // XXX without stopping here a page fault thinks it happens
+    //     in the sync, which is obviously wrong. Let's just keep
+    //     a sync as one TB as long as we don't do real SMP.
+    gen_stop_exception(ctx);
 }
 
 /* wait */
Signature · 1 line
1.6.0.2
#8 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

Quoted 9 lines · Alexander Graf

Right now we can throw a fault on lwsync, even though the fault is actually caused by the instruction after lwsync.

I haven't found the magic that messed this up, but for now we can just end the TB on lwsync, forcing the next command to issue faults itself.

If anyone knows how to really fix this, please step forward and do so. This only makes things work at all for me :-).

Where is the subsequent fault coming from? I suspect the real bug is nothing to do with lwsync, and the subsequent fault is actually just corrupting the CPU state. As discussed recently this is the same bug SPARC has with its unassigned access handlers.

Paul

#9 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

Quoted 13 lines · Paul Brook
Quoted 10 lines · Alexander Graf

Right now we can throw a fault on lwsync, even though the fault is actually caused by the instruction after lwsync.

I haven't found the magic that messed this up, but for now we can just end the TB on lwsync, forcing the next command to issue faults itself.

If anyone knows how to really fix this, please step forward and do so. This only makes things work at all for me :-).

Quoted 7 lines

Where is the subsequent fault coming from? I suspect the real bug is nothing to do with lwsync, and the subsequent fault is actually just corrupting the CPU state. As discussed recently this is the same bug SPARC has with its unassigned access handlers.

Paul

Without the patch I get:

Unable to handle kernel paging request for data at address 0x00000000
Faulting instruction address: 0xc0000000000ba524
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=1024 NUMA PowerMac
Modules linked in:

Supported: Yes
NIP: c0000000000ba524 LR: c000000000775a0c CTR: c0000000007759e8
REGS: c0000000061afb10 TRAP: 0300 Not tainted (2.6.27.7-9-ppc64)
MSR: 8000000000009032 <EE,ME,IR,DR> CR: 84000044 XER: 20000000
DAR: 0000000000000000, DSISR: 0000000040000000
TASK = c00000000619d560[1] 'swapper' THREAD: c0000000061ac000 CPU: 0
GPR00: ffffffffffffffff c0000000061afd90 c0000000009bbce8 0000000000000000
GPR04: 0000000000000000 0000000000000000 0000000000000000 c000000000a82c80
GPR08: 0000000000000613 c00000000619d560 c0000000070704c0 c0000000061ac000
GPR12: 0000000088000044 c000000000a82c80 0000000000051b63 0000000000051a41
GPR16: 0000000000051b5b 000000000004003c 0000000000053958 000000000005345e
GPR20: 0000000000052fd4 0000000000063dc8 0000000000063db4 00000000fff0245c
GPR24: 4000000002110000 c0000000007932f8 c000000000b077a8 0000000000000000
GPR28: c0000000009621f0 c0000000007b01c8 c000000000938f18 c0000000007afce0 NIP [c0000000000ba524] .cmpxchg_futex_value_locked+0x38/0x78 LR [c000000000775a0c] .futex_init+0x24/0xac

Call Trace:
[c0000000061afd90] [c0000000007759c0] .init_tstats_procfs+0x2c/0x54

(unreliable)
[c0000000061afe10] [c00000000000944c] .do_one_initcall+0x78/0x194 [c0000000061aff00] [c000000000750440] .kernel_init+0xd0/0x148 [c0000000061aff90] [c00000000002ad84] .kernel_thread+0x4c/0x68 Instruction dump:
39290001 912b0014 7c8407b4 7ca507b4 e92d01b0 e8090520 7fa30040 419d0038 e92d01b0 e8090520 2ba00003 409d0028 <7c2004ac> 7c001828 7c002000 40c20010

---[ end trace 561bb236c800851f ]---
note: swapper[1] exited with preempt_count 1
swapper used greatest stack depth: 9296 bytes left
Kernel panic - not syncing: Attempted to kill init!

Which is this translation block:

NIP c0000000000ba524 LR c000000000775a0c CTR c0000000007759e8 XER 20000000
MSR 8000000000009032 HID0 0000000060000000 HF 8000000000000000 idx 1 TB 00000000 d8b159bb DECR 0007c417
GPR00 ffffffffffffffff c0000000061afd90 c0000000009bbce8 0000000000000000 GPR04 0000000000000000 0000000000000000 0000000000000000 c000000000a82c80 GPR08 0000000000000613 c00000000619d560 c0000000070704c0 c0000000061ac000 GPR12 0000000088000044 c000000000a82c80 0000000000051b63 0000000000051a41 GPR16 0000000000051b5b 000000000004003c 0000000000053958 000000000005345e GPR20 0000000000052fd4 0000000000063dc8 0000000000063db4 00000000fff0245c GPR24 4000000002110000 c0000000007932f8 c000000000b077a8 0000000000000000 GPR28 c0000000009621f0 c0000000007b01c8 c000000000938f18 c0000000007afce0
CR 84000044 [ L G - - - - G G ] RES ffffffffffffffff
FPR00 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR04 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR08 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR12 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR16 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR20 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR24 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR28 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPSCR 00000000
SRR0 c000000000774950 SRR1 8000000000009032 SDR1 0000000007c00003 IN:

0xc0000000000ba524:  lwsync
0xc0000000000ba528:  lwarx   r0,0,r3
0xc0000000000ba52c:  cmpw    r0,r4
0xc0000000000ba530:  bne-    0xc0000000000ba540

And I seriously have trouble understanding how a data storage exception could happen on the lwsync opcode. It looks like R3 became 0 from the guest's point of view after lwsync though - hum.

Alex

#10 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

Quoted 94 lines · Alexander Graf
Quoted 14 lines · Paul Brook
Quoted 11 lines · Alexander Graf

Right now we can throw a fault on lwsync, even though the fault is actually caused by the instruction after lwsync.

I haven't found the magic that messed this up, but for now we can just end the TB on lwsync, forcing the next command to issue faults itself.

If anyone knows how to really fix this, please step forward and do so. This only makes things work at all for me :-).

Quoted 8 lines

Where is the subsequent fault coming from? I suspect the real bug is nothing to do with lwsync, and the subsequent fault is actually just corrupting the CPU state. As discussed recently this is the same bug SPARC has with its unassigned access handlers.

Paul

Without the patch I get:

Unable to handle kernel paging request for data at address 0x00000000
Faulting instruction address: 0xc0000000000ba524
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=1024 NUMA PowerMac
Modules linked in:

Supported: Yes
NIP: c0000000000ba524 LR: c000000000775a0c CTR: c0000000007759e8
REGS: c0000000061afb10 TRAP: 0300 Not tainted (2.6.27.7-9-ppc64)
MSR: 8000000000009032 <EE,ME,IR,DR> CR: 84000044 XER: 20000000
DAR: 0000000000000000, DSISR: 0000000040000000
TASK = c00000000619d560[1] 'swapper' THREAD: c0000000061ac000 CPU: 0
GPR00: ffffffffffffffff c0000000061afd90 c0000000009bbce8 0000000000000000
GPR04: 0000000000000000 0000000000000000 0000000000000000 c000000000a82c80
GPR08: 0000000000000613 c00000000619d560 c0000000070704c0 c0000000061ac000
GPR12: 0000000088000044 c000000000a82c80 0000000000051b63 0000000000051a41
GPR16: 0000000000051b5b 000000000004003c 0000000000053958 000000000005345e
GPR20: 0000000000052fd4 0000000000063dc8 0000000000063db4 00000000fff0245c
GPR24: 4000000002110000 c0000000007932f8 c000000000b077a8 0000000000000000
GPR28: c0000000009621f0 c0000000007b01c8 c000000000938f18 c0000000007afce0 NIP [c0000000000ba524] .cmpxchg_futex_value_locked+0x38/0x78 LR [c000000000775a0c] .futex_init+0x24/0xac

Call Trace:
[c0000000061afd90] [c0000000007759c0] .init_tstats_procfs+0x2c/0x54

(unreliable)
[c0000000061afe10] [c00000000000944c] .do_one_initcall+0x78/0x194 [c0000000061aff00] [c000000000750440] .kernel_init+0xd0/0x148 [c0000000061aff90] [c00000000002ad84] .kernel_thread+0x4c/0x68 Instruction dump:
39290001 912b0014 7c8407b4 7ca507b4 e92d01b0 e8090520 7fa30040 419d0038 e92d01b0 e8090520 2ba00003 409d0028 <7c2004ac> 7c001828 7c002000 40c20010

---[ end trace 561bb236c800851f ]---
note: swapper[1] exited with preempt_count 1
swapper used greatest stack depth: 9296 bytes left
Kernel panic - not syncing: Attempted to kill init!

Which is this translation block:

NIP c0000000000ba524 LR c000000000775a0c CTR c0000000007759e8 XER 20000000
MSR 8000000000009032 HID0 0000000060000000 HF 8000000000000000 idx 1 TB 00000000 d8b159bb DECR 0007c417
GPR00 ffffffffffffffff c0000000061afd90 c0000000009bbce8 0000000000000000 GPR04 0000000000000000 0000000000000000 0000000000000000 c000000000a82c80 GPR08 0000000000000613 c00000000619d560 c0000000070704c0 c0000000061ac000 GPR12 0000000088000044 c000000000a82c80 0000000000051b63 0000000000051a41 GPR16 0000000000051b5b 000000000004003c 0000000000053958 000000000005345e GPR20 0000000000052fd4 0000000000063dc8 0000000000063db4 00000000fff0245c GPR24 4000000002110000 c0000000007932f8 c000000000b077a8 0000000000000000 GPR28 c0000000009621f0 c0000000007b01c8 c000000000938f18 c0000000007afce0
CR 84000044 [ L G - - - - G G ] RES ffffffffffffffff
FPR00 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR04 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR08 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR12 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR16 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR20 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR24 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPR28 0000000000000000 0000000000000000 0000000000000000 0000000000000000 FPSCR 00000000
SRR0 c000000000774950 SRR1 8000000000009032 SDR1 0000000007c00003 IN:

0xc0000000000ba524:  lwsync
0xc0000000000ba528:  lwarx   r0,0,r3
0xc0000000000ba52c:  cmpw    r0,r4
0xc0000000000ba530:  bne-    0xc0000000000ba540
Quoted 4 lines

And I seriously have trouble understanding how a data storage exception could happen on the lwsync opcode. It looks like R3 became 0 from the guest's point of view after lwsync though - hum.

Ah I remember that one now :-). The futex_init function tests if cmpxchg works with NULL values and that's why R3 is 0. It's actually _supposed_ to fault here. But something gets messed up when the fault happens on IP=lwsync instead of IP=lwarx and I haven't really researched into why.

Alex

#11 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

Quoted 6 lines
Quoted 6 lines
0xc0000000000ba524:  lwsync
0xc0000000000ba528:  lwarx   r0,0,r3
0xc0000000000ba52c:  cmpw    r0,r4
0xc0000000000ba530:  bne-    0xc0000000000ba540
Quoted 8 lines
Quoted 3 lines

And I seriously have trouble understanding how a data storage exception could happen on the lwsync opcode. It looks like R3 became 0 from the guest's point of view after lwsync though - hum.

Ah I remember that one now :-). The futex_init function tests if cmpxchg works with NULL values and that's why R3 is 0. It's actually _supposed_ to fault here. But something gets messed up when the fault happens on IP=lwsync instead of IP=lwarx and I haven't really researched into why.

That's what you need to fix then :-)

I'm pretty sure that terminating the TB after the lwsync is not the correct solution, and is just hiding the real bug.

Paul

#12 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

In reply to Alexander Graf
Quoted 2 lines

If anyone knows how to really fix this, please step forward and do so. This only makes things work at all for me :-).

I bet lwsync being a nop is a clue.

When an MMU exception occurs, qemu figures out the guest location from the location of the MMU access in guest code (see cpu_restore_state). My guess is that this breaks when two guest instructions have the same location. I'm not entirely sure what the correct fix is, or where the bug lies (cpu_restore_state, gen_intermediate_code_pc, or tcg_gen_code_search_pc) but hopefully this will point you in the right direction.

One thing to try (to confirm this theory) is make lwsync do domething (write to a dummy register or call a helper function) and see if the problem goes away.

Paul

#13 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

Quoted 6 lines · Paul Brook

When an MMU exception occurs, qemu figures out the guest location from the location of the MMU access in guest code (see cpu_restore_state). My guess is that this breaks when two guest instructions have the same location. I'm not entirely sure what the correct fix is, or where the bug lies (cpu_restore_state, gen_intermediate_code_pc, or tcg_gen_code_search_pc) but hopefully this will point you in the right direction.

Automatically pick the second instruction, on the principle that an instruction with no opcodes is unlikely to trigger a synchronous fault?

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery
#14 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

Quoted 9 lines · Daniel Jacobowitz
Quoted 7 lines · Paul Brook

When an MMU exception occurs, qemu figures out the guest location from the location of the MMU access in guest code (see cpu_restore_state). My guess is that this breaks when two guest instructions have the same location. I'm not entirely sure what the correct fix is, or where the bug lies
(cpu_restore_state, gen_intermediate_code_pc, or tcg_gen_code_search_pc) but hopefully this will point you in the right direction.

Quoted 3 lines

Automatically pick the second instruction, on the principle that an instruction with no opcodes is unlikely to trigger a synchronous fault?

Yes, that sounds like the right fix.

Paul

#15 lore raw

Re: [Qemu-devel] [PATCH 7/7] PPC64: Don't fault at lwsync

In reply to Paul Brook
Quoted 13 lines · Paul Brook
Quoted 3 lines

If anyone knows how to really fix this, please step forward and do so. This only makes things work at all for me :-).

I bet lwsync being a nop is a clue.

When an MMU exception occurs, qemu figures out the guest location from the location of the MMU access in guest code (see cpu_restore_state). My guess is that this breaks when two guest instructions have the same location. I'm not entirely sure what the correct fix is, or where the bug lies (cpu_restore_state, gen_intermediate_code_pc, or tcg_gen_code_search_pc) but hopefully this will point you in the right direction.

Quoted 4 lines

One thing to try (to confirm this theory) is make lwsync do domething (write to a dummy register or call a helper function) and see if the problem goes away.

Yep, that's the root cause. I just put in a movi to a temp var and that works as well. Mind to fix it? I'm actually only fixing the qemu ppc64 parts to debug kvm inside and am slowly running out of time to work on the kvm part of things ;).

I'll also send a new patch series tomorrow - userspace works now and I can boot an openSUSE 11.1 DVD up to the installer prompt, though keyboard and serial ports don't work (but that's an OpenBIOS issue).

Alex