Skip to content

Commit

Permalink
spapr: Fix machine reset deadlock from replay-record
Browse files Browse the repository at this point in the history
When the machine is reset to load a new snapshot while being debugged
with replay-record, it is done from another thread, so the CPU does
not run the register setting operations. Set CPU registers directly in
machine reset.

Cc: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
  • Loading branch information
npiggin authored and legoater committed Sep 4, 2023
1 parent f61349e commit 5698c68
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
20 changes: 18 additions & 2 deletions hw/ppc/spapr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,22 @@ void spapr_set_all_lpcrs(target_ulong value, target_ulong mask)
}
}

/* May be used when the machine is not running */
void spapr_init_all_lpcrs(target_ulong value, target_ulong mask)
{
CPUState *cs;
CPU_FOREACH(cs) {
PowerPCCPU *cpu = POWERPC_CPU(cs);
CPUPPCState *env = &cpu->env;
target_ulong lpcr;

lpcr = env->spr[SPR_LPCR];
lpcr &= ~(LPCR_HR | LPCR_UPRT);
ppc_store_lpcr(cpu, lpcr);
}
}


static bool spapr_get_pate(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu,
target_ulong lpid, ppc_v3_pate_t *entry)
{
Expand Down Expand Up @@ -1583,7 +1599,7 @@ int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp)
}
/* We're setting up a hash table, so that means we're not radix */
spapr->patb_entry = 0;
spapr_set_all_lpcrs(0, LPCR_HR | LPCR_UPRT);
spapr_init_all_lpcrs(0, LPCR_HR | LPCR_UPRT);
return 0;
}

Expand Down Expand Up @@ -1661,7 +1677,7 @@ static void spapr_machine_reset(MachineState *machine, ShutdownCause reason)
spapr_ovec_cleanup(spapr->ov5_cas);
spapr->ov5_cas = spapr_ovec_new();

ppc_set_compat_all(spapr->max_compat_pvr, &error_fatal);
ppc_init_compat_all(spapr->max_compat_pvr, &error_fatal);

/*
* This is fixing some of the default configuration of the XIVE
Expand Down
1 change: 1 addition & 0 deletions include/hw/ppc/spapr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ bool spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,
#define SPAPR_OV5_XIVE_BOTH 0x80 /* Only to advertise on the platform */

void spapr_set_all_lpcrs(target_ulong value, target_ulong mask);
void spapr_init_all_lpcrs(target_ulong value, target_ulong mask);
hwaddr spapr_get_rtas_addr(void);
bool spapr_memory_hot_unplug_supported(SpaprMachineState *spapr);

Expand Down
19 changes: 19 additions & 0 deletions target/ppc/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ int ppc_set_compat_all(uint32_t compat_pvr, Error **errp)
return 0;
}

/* To be used when the machine is not running */
int ppc_init_compat_all(uint32_t compat_pvr, Error **errp)
{
CPUState *cs;

CPU_FOREACH(cs) {
PowerPCCPU *cpu = POWERPC_CPU(cs);
int ret;

ret = ppc_set_compat(cpu, compat_pvr, errp);

if (ret < 0) {
return ret;
}
}

return 0;
}

int ppc_compat_max_vthreads(PowerPCCPU *cpu)
{
const CompatInfo *compat = compat_by_pvr(cpu->compat_pvr);
Expand Down
1 change: 1 addition & 0 deletions target/ppc/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@ int ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp);

#if !defined(CONFIG_USER_ONLY)
int ppc_set_compat_all(uint32_t compat_pvr, Error **errp);
int ppc_init_compat_all(uint32_t compat_pvr, Error **errp);
#endif
int ppc_compat_max_vthreads(PowerPCCPU *cpu);
void ppc_compat_add_property(Object *obj, const char *name,
Expand Down

0 comments on commit 5698c68

Please sign in to comment.