ppc: misc ppc patches
cover ppc: misc ppc patches
These are a bunch of small fixes and improvements for ppc. I've posted these before so I'll just end up merging them this cycle.
Thanks,
Nick
Nicholas Piggin (5):
target/ppc: fix timebase register reset state
spapr: Fix vpa dispatch count for record-replay
spapr: Generate random HASHPKEYR for spapr machines target/ppc: Avoid warning message for zero process table entries target/ppc: Wire up BookE ATB registers for e500 family
include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 3 +++ hw/ppc/ppc.c | 11 +++++++--- hw/ppc/spapr.c | 39 +++++---------------------------- hw/ppc/spapr_cpu_core.c | 2 ++ hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 + target/ppc/cpu_init.c | 17 ++++++++++++++ target/ppc/mmu-radix64.c | 14 ++++++++++++ 9 files changed, 84 insertions(+), 37 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/5 target/ppc: fix timebase register reset state
(H)DEC and PURR get reset before icount does, which causes them to be skewed and not match the init state. This can cause replay to not match the recorded trace exactly. For DEC and HDEC this is usually not noticable since they tend to get programmed before affecting the target machine. PURR has been observed to cause replay bugs when running Linux.
Fix this by resetting using a time of 0.
--- hw/ppc/ppc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
hw/ppc/ppc.c +8 -3
@@ -1123,16 +1123,21 @@ void cpu_ppc_tb_reset(CPUPPCState *env)timer_del (tb_env->hdecr_timer);ppc_set_irq (cpu,PPC_INTERRUPT_HDECR ,0 ); tb_env->hdecr_next =0 ; +_cpu_ppc_store_hdecr (cpu,0 ,0 ,0 ,64 ); }/* * There is a bug in Linux 2.4 kernels: * if a decrementer exception is pending when it enables msr_ee at startup, * it's not ready to handle it... +* +* On machine reset, this is called before icount is reset, so for +* icount-mode, setting TB registers using now == qemu_clock_get_ns() +* results in them being garbage after icount is reset. Use an +* explicit now == 0 to get a consistent reset state. */ -cpu_ppc_store_decr (env,-1 ); -cpu_ppc_store_hdecr (env,-1 ); -cpu_ppc_store_purr (env,0x0000000000000000ULL ); +_cpu_ppc_store_decr (cpu,0 ,0 ,-1 ,64 ); +_cpu_ppc_store_purr (env,0 ,0 ); }void cpu_ppc_tb_free (CPUPPCState *env)
Signature · 1 line
2.45.2
PATCH 2/5 spapr: Fix vpa dispatch count for record-replay
In reply to Nicholas PigginThe dispatch count is a field in guest memory that the hypervisor increments when preempting and dispatching the guest. This was not being done deterministically with respect to icount, because tcg exec exit is not deterministic (e.g., an async event could cause it).
Change vpa dispatch count increment to keep track of whether the vCPU is considered dispatched or not, and only consider it preempted when calling cede / confer / join / stop-self / etc.
--- include/hw/ppc/spapr_cpu_core.h | 3 +++ hw/ppc/spapr.c | 36 ++------------------------------- hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 + 4 files changed, 39 insertions(+), 34 deletions(-)
include/hw/ppc/spapr_cpu_core.h +3 -0
@@ -46,6 +46,7 @@ typedef struct SpaprCpuState {uint64_t vpa_addr;uint64_t slb_shadow_addr, slb_shadow_size;uint64_t dtl_addr, dtl_size; +bool dispatched;/* for vpa dispatch counter tracking */ bool prod;/* not migrated, only used to improve dispatch latencies */ struct ICPState *icp;struct XiveTCTX *tctx;
@@ -60,4 +61,6 @@ static inline SpaprCpuState *spapr_cpu_state(PowerPCCPU *cpu) return (SpaprCpuState *)cpu->machine_data; } +void vpa_dispatch (CPUState *cs,SpaprCpuState *spapr_cpu,bool dispatch); +#endif
hw/ppc/spapr.c +2 -34
@@ -4519,47 +4519,15 @@ static void spapr_cpu_exec_enter(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) {SpaprCpuState *spapr_cpu =spapr_cpu_state (cpu); -/* These are only called by TCG, KVM maintains dispatch state */ - spapr_cpu->prod = false; -if (spapr_cpu->vpa_addr) { +if (!spapr_cpu->dispatched) {CPUState *cs =CPU (cpu); -uint32_t dispatch; - - dispatch =ldl_be_phys (cs->as, - spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER ); - dispatch++; -if ((dispatch &1 ) !=0 ) { -qemu_log_mask (LOG_GUEST_ERROR , -"VPA: incorrect dispatch counter value for " -"dispatched partition %u, correcting.\n" , dispatch); - dispatch++; - } -stl_be_phys (cs->as, - spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER , dispatch); +vpa_dispatch (cs, spapr_cpu, true); } }static void spapr_cpu_exec_exit (PPCVirtualHypervisor *vhyp,PowerPCCPU *cpu) { -SpaprCpuState *spapr_cpu =spapr_cpu_state (cpu); - -if (spapr_cpu->vpa_addr) { -CPUState *cs =CPU (cpu); -uint32_t dispatch; - - dispatch =ldl_be_phys (cs->as, - spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER ); - dispatch++; -if ((dispatch &1 ) !=1 ) { -qemu_log_mask (LOG_GUEST_ERROR , -"VPA: incorrect dispatch counter value for " -"preempted partition %u, correcting.\n" , dispatch); - dispatch++; - } -stl_be_phys (cs->as, - spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER , dispatch); - } }static void spapr_machine_class_init (ObjectClass *oc,void *data)
hw/ppc/spapr_hcall.c +33 -0
@@ -487,6 +487,36 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr,return ret; } +void vpa_dispatch (CPUState *cs,SpaprCpuState *spapr_cpu,bool dispatch) +{ +uint32_t counter; + +if (!dispatch) { +assert (spapr_cpu->dispatched); + }else { +assert (!spapr_cpu->dispatched); + } + spapr_cpu->dispatched = dispatch; + +return ; + +if (!spapr_cpu->vpa_addr) { +return ; + } + +/* These are only called by TCG, KVM maintains dispatch state */ + counter =ldl_be_phys (cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER ); + counter++; +if ((counter &1 ) != dispatch) { +qemu_log_mask (LOG_GUEST_ERROR , +"VPA: incorrect dispatch counter value for " +"%s partition %u, correcting.\n" , + dispatch ?"preempted" :"running" , counter); + counter++; + } +stl_be_phys (cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER , counter); +} +static target_ulong h_cede (PowerPCCPU *cpu,SpaprMachineState *spapr,target_ulong opcode,target_ulong *args) {
@@ -505,6 +535,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr,if (!cpu_has_work (cs)) { cs->halted =1 ; +vpa_dispatch (cs, spapr_cpu, false); cs->exception_index =EXCP_HLT ; cs->exit_request =1 ;ppc_maybe_interrupt (env);
@@ -531,6 +562,8 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) cs->exit_request =1 ;ppc_maybe_interrupt (&cpu->env); +vpa_dispatch (cs, spapr_cpu, false); +return H_SUCCESS ; }
hw/ppc/spapr_rtas.c +1 -0
@@ -216,6 +216,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, SpaprMachineState *spapr,*/ env->spr[SPR_PSSCR ] |=PSSCR_EC ; cs->halted =1 ; +vpa_dispatch (cs,spapr_cpu_state (cpu), false);ppc_store_lpcr (cpu, env->spr[SPR_LPCR ] & ~pcc->lpcr_pm);kvmppc_set_reg_ppc_online (cpu,0 );qemu_cpu_kick (cs);
Signature · 1 line
2.45.2
Re: [PATCH 2/5] spapr: Fix vpa dispatch count for record-replay
Hi Nick,
Quoted 17 lines · Nicholas Piggin
The dispatch count is a field in guest memory that the hypervisor increments when preempting and dispatching the guest. This was not being done deterministically with respect to icount, because tcg exec exit is not deterministic (e.g., an async event could cause it).
Change vpa dispatch count increment to keep track of whether the vCPU is considered dispatched or not, and only consider it preempted when calling cede / confer / join / stop-self / etc.
Signed-off-by Nicholas Piggin <[email protected]>--- include/hw/ppc/spapr_cpu_core.h | 3 +++ hw/ppc/spapr.c | 36 ++------------------------------- hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 + 4 files changed, 39 insertions(+), 34 deletions(-)
<snipped>
Quoted 7 lines
hw/ppc/spapr_hcall.c +0
-0@@ -487,6 +487,36 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr,return ret; }
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 498
Quoted 10 lines
hw/ppc/spapr_hcall.c +9
-0+void vpa_dispatch (CPUState *cs,SpaprCpuState *spapr_cpu,bool dispatch) +{ +uint32_t counter; + +if (!dispatch) { +assert (spapr_cpu->dispatched); + }else { +assert (!spapr_cpu->dispatched); + }
Would it look better as:
assert(!(dispatch == spapr_cpu->dispatched));
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 501
Quoted 3 lines
hw/ppc/spapr_hcall.c +3
-0+ spapr_cpu->dispatched = dispatch; + +return ;
Returning here unconditionally makes below code unreachable.
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 505
Quoted 4 lines
hw/ppc/spapr_hcall.c +4
-0+ +if (!spapr_cpu->vpa_addr) { +return ; + }
This could be moved to beginning or just after assert.
regards,
Harsh
Quoted 46 lines
hw/ppc/spapr_hcall.c +17
-0+ +/* These are only called by TCG, KVM maintains dispatch state */ + counter =ldl_be_phys (cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER ); + counter++; +if ((counter &1 ) != dispatch) { +qemu_log_mask (LOG_GUEST_ERROR , +"VPA: incorrect dispatch counter value for " +"%s partition %u, correcting.\n" , + dispatch ?"preempted" :"running" , counter); + counter++; + } +stl_be_phys (cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER , counter); +} +static target_ulong h_cede (PowerPCCPU *cpu,SpaprMachineState *spapr,target_ulong opcode,target_ulong *args) {@@ -505,6 +535,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr,if (!cpu_has_work (cs)) { cs->halted =1 ; +vpa_dispatch (cs, spapr_cpu, false); cs->exception_index =EXCP_HLT ; cs->exit_request =1 ;ppc_maybe_interrupt (env);@@ -531,6 +562,8 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) cs->exit_request =1 ;ppc_maybe_interrupt (&cpu->env); +vpa_dispatch (cs, spapr_cpu, false); +return H_SUCCESS ; }hw/ppc/spapr_rtas.c +1
-0@@ -216,6 +216,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, SpaprMachineState *spapr,*/ env->spr[SPR_PSSCR ] |=PSSCR_EC ; cs->halted =1 ; +vpa_dispatch (cs,spapr_cpu_state (cpu), false);ppc_store_lpcr (cpu, env->spr[SPR_LPCR ] & ~pcc->lpcr_pm);kvmppc_set_reg_ppc_online (cpu,0 );qemu_cpu_kick (cs);
Re: [PATCH 2/5] spapr: Fix vpa dispatch count for record-replay
Quoted 42 lines · Harsh Prateek Bora
Hi Nick,
Quoted 17 lines · Nicholas Piggin
The dispatch count is a field in guest memory that the hypervisor increments when preempting and dispatching the guest. This was not being done deterministically with respect to icount, because tcg exec exit is not deterministic (e.g., an async event could cause it).
Change vpa dispatch count increment to keep track of whether the vCPU is considered dispatched or not, and only consider it preempted when calling cede / confer / join / stop-self / etc.
Signed-off-by Nicholas Piggin <[email protected]>--- include/hw/ppc/spapr_cpu_core.h | 3 +++ hw/ppc/spapr.c | 36 ++------------------------------- hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 + 4 files changed, 39 insertions(+), 34 deletions(-)<snipped>
Quoted 7 lines
hw/ppc/spapr_hcall.c +0
-0@@ -487,6 +487,36 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu,SpaprMachineState *spapr, return ret;hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, · line 498
Quoted 10 lines
hw/ppc/spapr_hcall.c +8
-0} +void vpa_dispatch(CPUState *cs, SpaprCpuState *spapr_cpu, bool dispatch) +{ +uint32_t counter; + +if (!dispatch) { +assert (spapr_cpu->dispatched); + }else { +assert (!spapr_cpu->dispatched); + }Would it look better as:
Quoted 1 line
assert(!(dispatch == spapr_cpu->dispatched));
That's more cryptic than the one above. Maybe with ternary operator to avoid the if? Like assert(dispatch ? spapr_cpu->dispatched : !spapr_cpu->dispatched)
Regards,
BALATON Zoltan
Quoted 65 lines
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 501
Quoted 3 lines
hw/ppc/spapr_hcall.c +3
-0+ spapr_cpu->dispatched = dispatch; + +return ;Returning here unconditionally makes below code unreachable.
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 505
Quoted 4 lines
hw/ppc/spapr_hcall.c +4
-0+ +if (!spapr_cpu->vpa_addr) { +return ; + }This could be moved to beginning or just after assert.
regards,
HarshQuoted 47 lines
hw/ppc/spapr_hcall.c +16
-0+ +/* These are only called by TCG, KVM maintains dispatch state */ + counter =ldl_be_phys (cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER ); + counter++; +if ((counter &1 ) != dispatch) { +qemu_log_mask (LOG_GUEST_ERROR , +"VPA: incorrect dispatch counter value for " +"%s partition %u, correcting.\n" , + dispatch ?"preempted" :"running" , counter); + counter++; + } +stl_be_phys (cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER , counter); +} +static target_ulong h_cede (PowerPCCPU *cpu,SpaprMachineState *spapr,target_ulong opcode,target_ulong *args) {@@ -505,6 +535,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, if (!cpu_has_work(cs)) { cs->halted =1 ; +vpa_dispatch (cs, spapr_cpu, false); cs->exception_index =EXCP_HLT ; cs->exit_request =1 ;ppc_maybe_interrupt (env);@@ -531,6 +562,8 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) cs->exit_request =1 ;ppc_maybe_interrupt (&cpu->env); +vpa_dispatch (cs, spapr_cpu, false); +return H_SUCCESS ; } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.cindex
f329693c554..8ce42302234100644hw/ppc/spapr_rtas.c +1
-0@@ -216,6 +216,7 @@ static void rtas_stop_self(PowerPCCPU *cpu,SpaprMachineState *spapr, */ env->spr[SPR_PSSCR ] |=PSSCR_EC ; cs->halted =1 ; +vpa_dispatch (cs,spapr_cpu_state (cpu), false);ppc_store_lpcr (cpu, env->spr[SPR_LPCR ] & ~pcc->lpcr_pm);kvmppc_set_reg_ppc_online (cpu,0 );qemu_cpu_kick(cs);
Re: [PATCH 2/5] spapr: Fix vpa dispatch count for record-replay
Quoted 45 lines · BALATON Zoltan
Quoted 35 lines · Harsh Prateek Bora
Hi Nick,
Quoted 17 lines · Nicholas Piggin
The dispatch count is a field in guest memory that the hypervisor increments when preempting and dispatching the guest. This was not being done deterministically with respect to icount, because tcg exec exit is not deterministic (e.g., an async event could cause it).
Change vpa dispatch count increment to keep track of whether the vCPU is considered dispatched or not, and only consider it preempted when calling cede / confer / join / stop-self / etc.
Signed-off-by Nicholas Piggin <[email protected]>---
include/hw/ppc/spapr_cpu_core.h| 3 +++
hw/ppc/spapr.c | 36 ++------------------------------- hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 +4 files changed, 39 insertions(+), 34 deletions(-)<snipped>
Quoted 12 lines
hw/ppc/spapr_hcall.c +3
-0@@ -487,6 +487,36 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, return ret; } +void vpa_dispatch(CPUState *cs, SpaprCpuState *spapr_cpu, bool dispatch) +{ + uint32_t counter; +Quoted 8 lines
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 498
Quoted 5 lines
hw/ppc/spapr_hcall.c +5
-0+ if (!dispatch) { + assert(spapr_cpu->dispatched); + } else { + assert(!spapr_cpu->dispatched); + }Would it look better as:
assert(!(dispatch == spapr_cpu->dispatched));
Quoted 3 lines
That's more cryptic than the one above. Maybe with ternary operator to avoid the if? Like
assert(dispatch ? spapr_cpu->dispatched : !spapr_cpu->dispatched)
Yeh, initially I thought of ternary op, but thought of it as more cryptic. I guess either is fine. Minor correction though:
assert(dispatch ? !spapr_cpu->dispatched : spapr_cpu->dispatched)
regards,
Harsh
Quoted 68 lines
Regards,
BALATON ZoltanQuoted 65 lines
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 501
Quoted 3 lines
hw/ppc/spapr_hcall.c +3
-0+ spapr_cpu->dispatched = dispatch; + + return;Returning here unconditionally makes below code unreachable.
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 505
Quoted 4 lines
hw/ppc/spapr_hcall.c +4
-0+ + if (!spapr_cpu->vpa_addr) { + return; + }This could be moved to beginning or just after assert.
regards,
HarshQuoted 47 lines
hw/ppc/spapr_hcall.c +14
-0+ + /* These are only called by TCG, KVM maintains dispatch state */ + counter = ldl_be_phys(cs->as, spapr_cpu->vpa_addr +VPA_DISPATCH_COUNTER ); + counter++; + if ((counter & 1) != dispatch) { + qemu_log_mask(LOG_GUEST_ERROR, + "VPA: incorrect dispatch counter value for " + "%s partition %u, correcting.\n", + dispatch ? "preempted" : "running", counter); + counter++; + } + stl_be_phys(cs->as, spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, counter); +} +static
target_ulongh_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, target_ulong *args){hw/ppc/spapr_hcall.c +2
-0@@ -505,6 +535,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, if (!cpu_has_work(cs)) { cs->halted = 1; + vpa_dispatch(cs, spapr_cpu, false); cs->exception_index = EXCP_HLT; cs->exit_request = 1; ppc_maybe_interrupt(env);@@ -531,6 +562,8 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) cs->exit_request = 1; ppc_maybe_interrupt(&cpu->env); + vpa_dispatch(cs, spapr_cpu, false); + return H_SUCCESS; }diff --git
a/hw/ppc/spapr_rtas.cb/hw/ppc/spapr_rtas.cindexf329693c554..8ce42302234100644hw/ppc/spapr_rtas.c +1
-0@@ -216,6 +216,7 @@ static void rtas_stop_self(PowerPCCPU *cpu,SpaprMachineState *spapr, */ env->spr[SPR_PSSCR] |= PSSCR_EC; cs->halted = 1; + vpa_dispatch(cs, spapr_cpu_state(cpu), false); ppc_store_lpcr(cpu, env->spr[SPR_LPCR] & ~pcc->lpcr_pm); kvmppc_set_reg_ppc_online(cpu, 0);
qemu_cpu_kick(cs);
Re: [PATCH 2/5] spapr: Fix vpa dispatch count for record-replay
In reply to Harsh Prateek BoraQuoted 42 lines · Harsh Prateek Bora
Hi Nick,
Quoted 17 lines · Nicholas Piggin
The dispatch count is a field in guest memory that the hypervisor increments when preempting and dispatching the guest. This was not being done deterministically with respect to icount, because tcg exec exit is not deterministic (e.g., an async event could cause it).
Change vpa dispatch count increment to keep track of whether the vCPU is considered dispatched or not, and only consider it preempted when calling cede / confer / join / stop-self / etc.
Signed-off-by Nicholas Piggin <[email protected]>--- include/hw/ppc/spapr_cpu_core.h | 3 +++ hw/ppc/spapr.c | 36 ++------------------------------- hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 + 4 files changed, 39 insertions(+), 34 deletions(-)<snipped>
Quoted 7 lines
hw/ppc/spapr_hcall.c +0
-0@@ -487,6 +487,36 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr,return ret; }hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 498
Quoted 10 lines
hw/ppc/spapr_hcall.c +9
-0+void vpa_dispatch (CPUState *cs,SpaprCpuState *spapr_cpu,bool dispatch) +{ +uint32_t counter; + +if (!dispatch) { +assert (spapr_cpu->dispatched); + }else { +assert (!spapr_cpu->dispatched); + }Would it look better as:
Quoted 1 line
assert(!(dispatch == spapr_cpu->dispatched));
I think I wanted to know which way it was failing, but I guess assert_cmpint() will tell us? I'll change.
Quoted 6 lines
hw/ppc/spapr_hcall.c static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, · line 501
Quoted 4 lines
hw/ppc/spapr_hcall.c +3
-0+ spapr_cpu->dispatched = dispatch; + +return ;Returning here unconditionally makes below code unreachable.
Good catch. That was a testing hack. Will respin and retest.
Thanks,
Nick
PATCH 3/5 spapr: Generate random HASHPKEYR for spapr machines
In reply to Nicholas PigginThe hypervisor is expected to create a value for the HASHPKEY SPR for each partition. Currently it uses zero for all partitions, use a random number instead, which in theory might make kernel ROP protection more secure.
--- include/hw/ppc/spapr.h | 1 + hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_cpu_core.c | 2 ++ 3 files changed, 6 insertions(+)
include/hw/ppc/spapr.h +1 -0
@@ -201,6 +201,7 @@ struct SpaprMachineState {uint32_t fdt_initial_size;void *fdt_blob;uint8_t fdt_rng_seed[32 ]; +uint64_t hashpkey_val;long kernel_size;bool kernel_le;uint64_t kernel_addr;
hw/ppc/spapr.c +3 -0
@@ -2888,6 +2888,9 @@ static void spapr_machine_init(MachineState *machine)spapr_ovec_set (spapr->ov5,OV5_XIVE_EXPLOIT ); } +qemu_guest_getrandom_nofail (&spapr->hashpkey_val, +sizeof (spapr->hashpkey_val)); +/* init CPUs */ spapr_init_cpus (spapr);
hw/ppc/spapr_cpu_core.c +2 -0
@@ -273,6 +273,8 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr, env->spr_cb[SPR_PIR ].default_value = cs->cpu_index; env->spr_cb[SPR_TIR ].default_value = thread_index; + env->spr_cb[SPR_HASHPKEYR ].default_value = spapr->hashpkey_val; +cpu_ppc_set_1lpar (cpu);/* Set time-base frequency to 512 MHz. vhyp must be set first. */
Signature · 1 line
2.45.2
Re: [PATCH 3/5] spapr: Generate random HASHPKEYR for spapr machines
Quoted 6 lines · Nicholas Piggin
The hypervisor is expected to create a value for the HASHPKEY SPR for each partition. Currently it uses zero for all partitions, use a random number instead, which in theory might make kernel ROP protection more secure.
Signed-of-by Nicholas Piggin <[email protected]>
Quoted 45 lines
--- include/hw/ppc/spapr.h | 1 + hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_cpu_core.c | 2 ++ 3 files changed, 6 insertions(+)include/hw/ppc/spapr.h +1
-0@@ -201,6 +201,7 @@ struct SpaprMachineState {uint32_t fdt_initial_size;void *fdt_blob;uint8_t fdt_rng_seed[32 ]; +uint64_t hashpkey_val;long kernel_size;bool kernel_le;uint64_t kernel_addr;hw/ppc/spapr.c +3
-0@@ -2888,6 +2888,9 @@ static void spapr_machine_init(MachineState *machine)spapr_ovec_set (spapr->ov5,OV5_XIVE_EXPLOIT ); } +qemu_guest_getrandom_nofail (&spapr->hashpkey_val, +sizeof (spapr->hashpkey_val)); +/* init CPUs */ spapr_init_cpus (spapr);hw/ppc/spapr_cpu_core.c +2
-0@@ -273,6 +273,8 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr, env->spr_cb[SPR_PIR ].default_value = cs->cpu_index; env->spr_cb[SPR_TIR ].default_value = thread_index; + env->spr_cb[SPR_HASHPKEYR ].default_value = spapr->hashpkey_val; +cpu_ppc_set_1lpar (cpu);/* Set time-base frequency to 512 MHz. vhyp must be set first. */
Re: [PATCH 3/5] spapr: Generate random HASHPKEYR for spapr machines
In reply to Nicholas PigginQuoted 11 lines · Nicholas Piggin
The hypervisor is expected to create a value for the HASHPKEY SPR for each partition. Currently it uses zero for all partitions, use a random number instead, which in theory might make kernel ROP protection more secure.
Signed-of-by Nicholas Piggin <[email protected]>--- include/hw/ppc/spapr.h | 1 + hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_cpu_core.c | 2 ++ 3 files changed, 6 insertions(+)
PATCH 4/5 target/ppc: Avoid warning message for zero process table entries
In reply to Nicholas PigginA translation that encounters a process table entry that is zero is something that Linux does to cause certain kernel NULL pointer dereferences to fault. It is not itself a programming error, so avoid the guest error log.
--- target/ppc/mmu-radix64.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/ppc/mmu-radix64.c +14 -0
@@ -571,6 +571,20 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, prtbe0 =ldq_phys (cs->as, h_raddr); } +/* +* Some Linux uses a zero process table entry in PID!=0 for kernel context +* without userspace in order to fault on NULL dereference, because using +* PIDR=0 for the kernel causes the Q0 page table to be used to translate +* Q3 as well. Check for that case here to avoid the invalid configuration +* message. +*/ +if (unlikely (!prtbe0)) { +if (guest_visible) { +ppc_radix64_raise_si (cpu, access_type, eaddr,DSISR_R_BADCONFIG ); + } +return 1 ; + } +/* Walk Radix Tree from Process Table Entry to Convert EA to RA */ *g_page_size =PRTBE_R_GET_RTS (prtbe0); base_addr = prtbe0 &PRTBE_R_RPDB ;
Signature · 1 line
2.45.2
PATCH 5/5 target/ppc: Wire up BookE ATB registers for e500 family
In reply to Nicholas PigginFrom the Freescale PowerPC Architecture Primer:
Alternate time base APU. This APU, implemented on the e500v2, defines a 64-bit time base counter that differs from the PowerPC defined time base in that it is not writable and counts at a different, and typically much higher, frequency. The alternate time base always counts up, wrapping when the 64-bit count overflows.
This implementation of ATB uses the same frequency as the TB. The existing spr_read_atbu/l functions are unused without this patch to wire them into the SPR.
RTEMS uses this SPR on the e6500, though this hasn't been tested.
--- target/ppc/cpu_init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
target/ppc/cpu_init.c +17 -0
@@ -922,6 +922,18 @@ static void register_BookE206_sprs(CPUPPCState *env, uint32_t mas_mask,#endif } +static void register_atb_sprs (CPUPPCState *env) +{ +spr_register (env,SPR_ATBL ,"ATBL" , + &spr_read_atbl,SPR_NOACCESS , + &spr_read_atbl,SPR_NOACCESS , +0x00000000 ); +spr_register (env,SPR_ATBU ,"ATBU" , + &spr_read_atbu,SPR_NOACCESS , + &spr_read_atbu,SPR_NOACCESS , +0x00000000 ); +} +/* SPR specific to PowerPC 440 implementation */ static void register_440_sprs (CPUPPCState *env) {
@@ -2911,6 +2923,11 @@ static void init_proc_e500(CPUPPCState *env, int version)register_BookE206_sprs (env,0x000000DF , tlbncfg, mmucfg);register_usprgh_sprs (env); +if (version != fsl_e500v1) { +/* e500v1 has no support for alternate timebase */ +register_atb_sprs (env); + } + spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic,
Signature · 1 line
2.45.2