ppc/spapr: Fix migration of radix guests
cover ppc/spapr: Fix migration of radix guests
Migrating radix guests fails with the following error on the target side:
qemu-system-ppc64: htab_load() bad index 2113929216 (5378+0 entries) in htab stream (htab_shift=0)
qemu-system-ppc64: error while loading state for instance 0x0 of device 'spapr/htab'
qemu-system-ppc64: load of migration failed: Invalid argument
Fix this by not registering htab savevm handler for radix case.
Patches apply against ppc-for-2.10 branch of dwg's tree.
Bharata B Rao (2):
spapr: Make h_register_process_table hcall flags global
spapr: Fix migration of Radix guests
hw/ppc/spapr.c | 18 +++++++++++++++--- hw/ppc/spapr_hcall.c | 36 +++++++++++++++++++----------------- include/hw/ppc/spapr.h | 13 +++++++++++++ 3 files changed, 47 insertions(+), 20 deletions(-)
Signature · 1 line
2.7.4
RFC PATCH 1/2 spapr: Make h_register_process_table hcall flags global
The flags used in h_register_process_table hcall are needed in spapr.c and hence move them to a header file. While doing so, give them slightly specific names.
--- hw/ppc/spapr_hcall.c | 31 ++++++++++++++----------------- include/hw/ppc/spapr.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 17 deletions(-)
hw/ppc/spapr_hcall.c +14 -17
@@ -924,13 +924,6 @@ static void spapr_check_setup_free_hpt(sPAPRMachineState *spapr,return ; } -#define FLAGS_MASK 0x01FULL -#define FLAG_MODIFY 0x10 -#define FLAG_REGISTER 0x08 -#define FLAG_RADIX 0x04 -#define FLAG_HASH_PROC_TBL 0x02 -#define FLAG_GTSE 0x01 - static target_ulong h_register_process_table(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode,
@@ -943,12 +936,13 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu,target_ulong table_size = args[3 ];uint64_t cproc; -if (flags & ~FLAGS_MASK ) {/* Check no reserved bits are set */ +if (flags & ~SPAPR_PROC_TABLE_MASK ) {/* Check no reserved bits are set */ return H_PARAMETER ; } -if (flags &FLAG_MODIFY ) { -if (flags &FLAG_REGISTER ) { -if (flags &FLAG_RADIX ) {/* Register new RADIX process table */ +if (flags &SPAPR_PROC_TABLE_MODIFY ) { +if (flags &SPAPR_PROC_TABLE_REGISTER ) { +if (flags &SPAPR_PROC_TABLE_RADIX ) { +/* Register new RADIX process table */ if (proc_tbl &0xfff || proc_tbl >>60 ) {return H_P2 ; }else if (page_size) {
@@ -958,7 +952,8 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu, } cproc =PATBE1_GR | proc_tbl | table_size; }else {/* Register new HPT process table */ -if (flags &FLAG_HASH_PROC_TBL ) {/* Hash with Segment Tables */ +if (flags &SPAPR_PROC_TABLE_HPT_PT ) { +/* Hash with Segment Tables */ /* TODO - Not Supported */ /* Technically caused by flag bits => H_PARAMETER */ return H_PARAMETER ;
@@ -981,7 +976,8 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu, cproc = spapr->patb_entry &PATBE1_GR ; } }else {/* Maintain current registration */ -if (!(flags &FLAG_RADIX ) != !(spapr->patb_entry &PATBE1_GR )) { +if (!(flags &SPAPR_PROC_TABLE_RADIX ) != + !(spapr->patb_entry &PATBE1_GR )) {/* Technically caused by flag bits => H_PARAMETER */ return H_PARAMETER ;/* Existing Process Table Mismatch */ }
@@ -996,13 +992,14 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu,/* Update the UPRT and GTSE bits in the LPCR for all cpus */ CPU_FOREACH (cs) {set_spr (cs,SPR_LPCR ,LPCR_UPRT |LPCR_GTSE , - ((flags & (FLAG_RADIX |FLAG_HASH_PROC_TBL )) ?LPCR_UPRT :0 ) | - ((flags &FLAG_GTSE ) ?LPCR_GTSE :0 )); + ((flags & (SPAPR_PROC_TABLE_RADIX |SPAPR_PROC_TABLE_HPT_PT )) ? +LPCR_UPRT :0 ) | ((flags &SPAPR_PROC_TABLE_GTSE ) ? +SPAPR_PROC_TABLE_GTSE :0 )); }if (kvm_enabled ()) { -return kvmppc_configure_v3_mmu (cpu, flags &FLAG_RADIX , - flags &FLAG_GTSE , cproc); +return kvmppc_configure_v3_mmu (cpu, flags &SPAPR_PROC_TABLE_RADIX , + flags &SPAPR_PROC_TABLE_GTSE , cproc); }return H_SUCCESS ; }
include/hw/ppc/spapr.h +10 -0
@@ -681,4 +681,14 @@ int spapr_rng_populate_dt(void *fdt);void spapr_do_system_reset_on_cpu (CPUState *cs,run_on_cpu_data arg); +/* +* Defines for flag value used in H_REGISTER_PROC_TBL hcall. +*/ +#define SPAPR_PROC_TABLE_MASK 0x01FULL +#define SPAPR_PROC_TABLE_MODIFY 0x10 +#define SPAPR_PROC_TABLE_REGISTER 0x08 +#define SPAPR_PROC_TABLE_RADIX 0x04 +#define SPAPR_PROC_TABLE_HPT_PT 0x02 +#define SPAPR_PROC_TABLE_GTSE 0x01 +#endif /* HW_SPAPR_H */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH 1/2] spapr: Make h_register_process_table hcall flags global
Quoted 5 lines · Bharata B Rao
The flags used in
h_register_process_tablehcall are needed inspapr.cand hence move them to a header file. While doing so, give them slightly specific names.Signed-off-by Bharata B Rao <[email protected]>
Quoted 99 lines
--- hw/ppc/spapr_hcall.c | 31 ++++++++++++++----------------- include/hw/ppc/spapr.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 17 deletions(-)hw/ppc/spapr_hcall.c +14
-17@@ -924,13 +924,6 @@ static void spapr_check_setup_free_hpt(sPAPRMachineState *spapr,return ; } -#define FLAGS_MASK 0x01FULL -#define FLAG_MODIFY 0x10 -#define FLAG_REGISTER 0x08 -#define FLAG_RADIX 0x04 -#define FLAG_HASH_PROC_TBL 0x02 -#define FLAG_GTSE 0x01 - static target_ulong h_register_process_table(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode,@@ -943,12 +936,13 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu,target_ulong table_size = args[3 ];uint64_t cproc; -if (flags & ~FLAGS_MASK ) {/* Check no reserved bits are set */ +if (flags & ~SPAPR_PROC_TABLE_MASK ) {/* Check no reserved bits are set */ return H_PARAMETER ; } -if (flags &FLAG_MODIFY ) { -if (flags &FLAG_REGISTER ) { -if (flags &FLAG_RADIX ) {/* Register new RADIX process table */ +if (flags &SPAPR_PROC_TABLE_MODIFY ) { +if (flags &SPAPR_PROC_TABLE_REGISTER ) { +if (flags &SPAPR_PROC_TABLE_RADIX ) { +/* Register new RADIX process table */ if (proc_tbl &0xfff || proc_tbl >>60 ) {return H_P2 ; }else if (page_size) {@@ -958,7 +952,8 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu, } cproc =PATBE1_GR | proc_tbl | table_size; }else {/* Register new HPT process table */ -if (flags &FLAG_HASH_PROC_TBL ) {/* Hash with Segment Tables */ +if (flags &SPAPR_PROC_TABLE_HPT_PT ) { +/* Hash with Segment Tables */ /* TODO - Not Supported */ /* Technically caused by flag bits => H_PARAMETER */ return H_PARAMETER ;@@ -981,7 +976,8 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu, cproc = spapr->patb_entry &PATBE1_GR ; } }else {/* Maintain current registration */ -if (!(flags &FLAG_RADIX ) != !(spapr->patb_entry &PATBE1_GR )) { +if (!(flags &SPAPR_PROC_TABLE_RADIX ) != + !(spapr->patb_entry &PATBE1_GR )) {/* Technically caused by flag bits => H_PARAMETER */ return H_PARAMETER ;/* Existing Process Table Mismatch */ }@@ -996,13 +992,14 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu,/* Update the UPRT and GTSE bits in the LPCR for all cpus */ CPU_FOREACH (cs) {set_spr (cs,SPR_LPCR ,LPCR_UPRT |LPCR_GTSE , - ((flags & (FLAG_RADIX |FLAG_HASH_PROC_TBL )) ?LPCR_UPRT :0 ) | - ((flags &FLAG_GTSE ) ?LPCR_GTSE :0 )); + ((flags & (SPAPR_PROC_TABLE_RADIX |SPAPR_PROC_TABLE_HPT_PT )) ? +LPCR_UPRT :0 ) | ((flags &SPAPR_PROC_TABLE_GTSE ) ? +SPAPR_PROC_TABLE_GTSE :0 )); }if (kvm_enabled ()) { -return kvmppc_configure_v3_mmu (cpu, flags &FLAG_RADIX , - flags &FLAG_GTSE , cproc); +return kvmppc_configure_v3_mmu (cpu, flags &SPAPR_PROC_TABLE_RADIX , + flags &SPAPR_PROC_TABLE_GTSE , cproc); }return H_SUCCESS ; }include/hw/ppc/spapr.h +10
-0@@ -681,4 +681,14 @@ int spapr_rng_populate_dt(void *fdt);void spapr_do_system_reset_on_cpu (CPUState *cs,run_on_cpu_data arg); +/* +* Defines for flag value used in H_REGISTER_PROC_TBL hcall. +*/ +#define SPAPR_PROC_TABLE_MASK 0x01FULL +#define SPAPR_PROC_TABLE_MODIFY 0x10 +#define SPAPR_PROC_TABLE_REGISTER 0x08 +#define SPAPR_PROC_TABLE_RADIX 0x04 +#define SPAPR_PROC_TABLE_HPT_PT 0x02 +#define SPAPR_PROC_TABLE_GTSE 0x01 +#endif /* HW_SPAPR_H */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
RFC PATCH 2/2 spapr: Fix migration of Radix guests
In reply to Bharata B RaoCurrently HTAB savevm handlers get registered by default and migration of radix guest will fail.
- Ensure that HTAB savevm handlers are not registered for radix case.
- Ensure that we issue KVM_PPC_CONFIGURE_V3_MMU for radix case post migration.
TODO: Right now I have delayed the HTAB savevm handler registration to CAS call where we know if the guest is radix or hash. Another approach is to let the HTAB handlers to be registered by default (as it is being done currently, but unregister them from CAS when we discover radix capability).
--- hw/ppc/spapr.c | 18 +++++++++++++++--- hw/ppc/spapr_hcall.c | 5 +++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +15 -3
@@ -1436,6 +1436,14 @@ static int spapr_post_load(void *opaque, int version_id) err =spapr_rtc_import_offset (&spapr->rtc, spapr->rtc_offset); } +if (spapr->patb_entry && (spapr->patb_flags &SPAPR_PROC_TABLE_RADIX ) && +kvmppc_has_cap_mmu_radix () &&kvm_enabled ()) { + err =kvmppc_configure_v3_mmu (POWERPC_CPU (first_cpu), + spapr->patb_flags & +SPAPR_PROC_TABLE_RADIX , + spapr->patb_flags &SPAPR_PROC_TABLE_GTSE , + spapr->patb_entry); + }return err; }
@@ -1520,6 +1528,7 @@ static const VMStateDescription vmstate_spapr_patb_entry = { .needed = spapr_patb_entry_needed, .fields = (VMStateField []) {VMSTATE_UINT64 (patb_entry, sPAPRMachineState), +VMSTATE_UINT64 (patb_flags, sPAPRMachineState),VMSTATE_END_OF_LIST () }, };
@@ -1869,6 +1878,12 @@ static SaveVMHandlers savevm_htab_handlers = { .load_state = htab_load, }; +void spapr_htab_savevm_register (sPAPRMachineState *spapr) +{ +register_savevm_live (NULL ,"spapr/htab" ,-1 ,1 , + &savevm_htab_handlers, spapr); +} +static void spapr_boot_set (void *opaque,const char *boot_device,Error **errp) {
@@ -2331,9 +2346,6 @@ static void ppc_spapr_init(MachineState *machine)* interface, this is a legacy from the sPAPREnvironment structure * which predated MachineState but had a similar function */ vmstate_register (NULL ,0 , &vmstate_spapr, spapr); -register_savevm_live (NULL ,"spapr/htab" ,-1 ,1 , - &savevm_htab_handlers, spapr); -/* used by RTAS */ QTAILQ_INIT (&spapr->ccs_list);qemu_register_reset (spapr_ccs_reset_hook, spapr);
hw/ppc/spapr_hcall.c +5 -0
@@ -988,6 +988,7 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu,spapr_check_setup_free_hpt (spapr, spapr->patb_entry, cproc); spapr->patb_entry = cproc;/* Save new process table */ + spapr->patb_flags = flags;/* Save the flags */ /* Update the UPRT and GTSE bits in the LPCR for all cpus */ CPU_FOREACH (cs) {
@@ -1169,6 +1170,10 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, } } +/* Register savevm handlers for HTAB case */ +if (!guest_radix || !kvmppc_has_cap_mmu_radix ()) { +spapr_htab_savevm_register (spapr); + }return H_SUCCESS ; }
include/hw/ppc/spapr.h +3 -0
@@ -75,6 +75,7 @@ struct sPAPRMachineState {void *htab;uint32_t htab_shift;uint64_t patb_entry;/* Process tbl registed in H_REGISTER_PROCESS_TABLE */ +uint64_t patb_flags;hwaddr rma_size;int vrma_adjust;ssize_t rtas_size;
@@ -691,4 +692,6 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);#define SPAPR_PROC_TABLE_HPT_PT 0x02#define SPAPR_PROC_TABLE_GTSE 0x01 +void spapr_htab_savevm_register (sPAPRMachineState *spapr); +#endif /* HW_SPAPR_H */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH 2/2] spapr: Fix migration of Radix guests
Quoted 7 lines · Bharata B Rao
Currently HTAB savevm handlers get registered by default and migration of radix guest will fail.
- Ensure that HTAB savevm handlers are not registered for radix case.
- Ensure that we issueKVM_PPC_CONFIGURE_V3_MMUfor radix case post migration.
Quoted 5 lines
TODO: Right now I have delayed the HTAB savevm handler registration to CAS call where we know if the guest is radix or hash. Another approach is to let the HTAB handlers to be registered by default (as it is being done currently, but unregister them from CAS when we discover radix capability).
Option 2 there sounds messy. I also suspect it could break if you try to migrate an (eventually) radix guest before it's done CAS.
Strictly speaking only registering at CAS time will break old hash guests that don't do CAS at all. However such guests are really, really ancient, and I suspect we don't work with them already.
You do, however, need to deregister (and allow the choice to be made again) on guest reset. On KVM we can only (for now) support either hash or radix guests. Under TCG, however, we could run a radix guest then reboot to a hash guest or vice versa.
Quoted 14 lines
Reported-by Nageswara R Sastry <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 18 +++++++++++++++--- hw/ppc/spapr_hcall.c | 5 +++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c static int spapr_post_load(void *opaque, int version_id) · line 1439
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -1436,6 +1436,14 @@ static int spapr_post_load(void *opaque, int version_id) err =spapr_rtc_import_offset (&spapr->rtc, spapr->rtc_offset); } + if (spapr->patb_entry && (spapr->patb_flags & SPAPR_PROC_TABLE_RADIX) &&
patb_entry already tells you whether the guest is radix or not (PATBE1_GR), you shouldn't need extra flags.
hw/ppc/spapr.c static int spapr_post_load(void *opaque, int version_id) · line 1440
Quoted 1 line
hw/ppc/spapr.c +1
-0+ kvmppc_has_cap_mmu_radix() && kvm_enabled()) {
You should also fail the migration if you have an incoming radix guest, but the your new KVM host can't do radix. Or the reverse, for that matter.
Quoted 82 lines
hw/ppc/spapr.c +13
-3+ err =kvmppc_configure_v3_mmu (POWERPC_CPU (first_cpu), + spapr->patb_flags & +SPAPR_PROC_TABLE_RADIX , + spapr->patb_flags &SPAPR_PROC_TABLE_GTSE , + spapr->patb_entry); + }return err; }@@ -1520,6 +1528,7 @@ static const VMStateDescription vmstate_spapr_patb_entry = { .needed = spapr_patb_entry_needed, .fields = (VMStateField []) {VMSTATE_UINT64 (patb_entry, sPAPRMachineState), +VMSTATE_UINT64 (patb_flags, sPAPRMachineState),VMSTATE_END_OF_LIST () }, };@@ -1869,6 +1878,12 @@ static SaveVMHandlers savevm_htab_handlers = { .load_state = htab_load, }; +void spapr_htab_savevm_register (sPAPRMachineState *spapr) +{ +register_savevm_live (NULL ,"spapr/htab" ,-1 ,1 , + &savevm_htab_handlers, spapr); +} +static void spapr_boot_set (void *opaque,const char *boot_device,Error **errp) {@@ -2331,9 +2346,6 @@ static void ppc_spapr_init(MachineState *machine)* interface, this is a legacy from the sPAPREnvironment structure * which predated MachineState but had a similar function */ vmstate_register (NULL ,0 , &vmstate_spapr, spapr); -register_savevm_live (NULL ,"spapr/htab" ,-1 ,1 , - &savevm_htab_handlers, spapr); -/* used by RTAS */ QTAILQ_INIT (&spapr->ccs_list);qemu_register_reset (spapr_ccs_reset_hook, spapr);hw/ppc/spapr_hcall.c +5
-0@@ -988,6 +988,7 @@ static target_ulong h_register_process_table(PowerPCCPU *cpu,spapr_check_setup_free_hpt (spapr, spapr->patb_entry, cproc); spapr->patb_entry = cproc;/* Save new process table */ + spapr->patb_flags = flags;/* Save the flags */ /* Update the UPRT and GTSE bits in the LPCR for all cpus */ CPU_FOREACH (cs) {@@ -1169,6 +1170,10 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, } } +/* Register savevm handlers for HTAB case */ +if (!guest_radix || !kvmppc_has_cap_mmu_radix ()) { +spapr_htab_savevm_register (spapr); + }return H_SUCCESS ; }include/hw/ppc/spapr.h +3
-0@@ -75,6 +75,7 @@ struct sPAPRMachineState {void *htab;uint32_t htab_shift;uint64_t patb_entry;/* Process tbl registed in H_REGISTER_PROCESS_TABLE */ +uint64_t patb_flags;hwaddr rma_size;int vrma_adjust;ssize_t rtas_size;@@ -691,4 +692,6 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);#define SPAPR_PROC_TABLE_HPT_PT 0x02#define SPAPR_PROC_TABLE_GTSE 0x01 +void spapr_htab_savevm_register (sPAPRMachineState *spapr); +#endif /* HW_SPAPR_H */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC PATCH 2/2] spapr: Fix migration of Radix guests
Quoted 17 lines · David Gibson
Quoted 7 lines · Bharata B Rao
Currently HTAB savevm handlers get registered by default and migration of radix guest will fail.
- Ensure that HTAB savevm handlers are not registered for radix case.
- Ensure that we issueKVM_PPC_CONFIGURE_V3_MMUfor radix case post migration.Quoted 5 lines
TODO: Right now I have delayed the HTAB savevm handler registration to CAS call where we know if the guest is radix or hash. Another approach is to let the HTAB handlers to be registered by default (as it is being done currently, but unregister them from CAS when we discover radix capability).
Option 2 there sounds messy. I also suspect it could break if you try to migrate an (eventually) radix guest before it's done CAS.
Quoted 8 lines
Strictly speaking only registering at CAS time will break old hash guests that don't do CAS at all. However such guests are really, really ancient, and I suspect we don't work with them already.
You do, however, need to deregister (and allow the choice to be made again) on guest reset. On KVM we can only (for now) support either hash or radix guests. Under TCG, however, we could run a radix guest then reboot to a hash guest or vice versa.
Took care of this in v1.
Quoted 24 lines
Quoted 16 lines
Reported-by Nageswara R Sastry <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 18 +++++++++++++++--- hw/ppc/spapr_hcall.c | 5 +++++ include/hw/ppc/spapr.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0hw/ppc/spapr.c static int spapr_post_load(void *opaque, int version_id) · line 1439
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -1436,6 +1436,14 @@ static int spapr_post_load(void *opaque, int version_id) err =spapr_rtc_import_offset (&spapr->rtc, spapr->rtc_offset); } + if (spapr->patb_entry && (spapr->patb_flags & SPAPR_PROC_TABLE_RADIX) &&
patb_entryalready tells you whether the guest is radix or not (PATBE1_GR), you shouldn't need extra flags.
Quoted 5 lines
hw/ppc/spapr.c static int spapr_post_load(void *opaque, int version_id) · line 1440
Quoted 1 line
hw/ppc/spapr.c +1
-0+ kvmppc_has_cap_mmu_radix() && kvm_enabled()) {You should also fail the migration if you have an incoming radix guest, but the your new KVM host can't do radix. Or the reverse, for that matter.
I have checks in v1 to fail migration of radix guest to a host that doesn't support radix. But I don't see how we can detect and fail the migration of hash guests into hosts that don't support hash from here (i,e., from spapr_post_load). The hash guest's migration stream would have htab savevm entries and the target will fail as it knows not about htab savevm entries.
Regards,
Bharata.