pseries: Correct behaviour change for older machine types
cover pseries: Correct behaviour change for older machine types
152ef80 "pseries: Rewrite CAS PVR compatibility logic" incorrectly introduced a guest-visible behaviour change into existing versioned machine type. Patch 2/2 corrects this change, while 1/2 is a preliminary clean up to make that easier.
Unfortunately, this bug is already in the released qemu-2.9.0. Once this is ready to merge for master, I'll make a backport to apply for 2.9.1 as well.
David Gibson (2):
pseries: Split CAS PVR negotiation out into a separate function
pseries: Restore PVR negotiation logic for pre-2.9 machine types
hw/ppc/spapr.c | 3 ++ hw/ppc/spapr_hcall.c | 131 +++++++++++++++++++++++++++++++++++++++++++------ include/hw/ppc/spapr.h | 1 + 3 files changed, 119 insertions(+), 16 deletions(-)
Signature · 1 line
2.9.4
RFC 1/2 pseries: Split CAS PVR negotiation out into a separate function
Guests of the qemu machine type go through a feature negotiation process known as "client architecture support" (CAS) during early boot. This does a number of things, one of which is finding a CPU compatibility mode which can be supported by both guest and host.
In fact the CPU negotiation is probably the single most complex part of the CAS process, so this splits it out into a helper function. We've recently made some mistakes in maintaining backward compatibility for old machine types here. Splitting this out will also make it easier to fix this.
This also adds a possibly useful error message if the negotiation fails (i.e. if there is CPU mode that's suitable for both guest and host).
--- hw/ppc/spapr_hcall.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-)
hw/ppc/spapr_hcall.c +27 -16
@@ -1047,19 +1047,13 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, } } -static target_ulong h_client_architecture_support (PowerPCCPU *cpu, -sPAPRMachineState *spapr, -target_ulong opcode, -target_ulong *args) +static uint32_t cas_check_pvr (PowerPCCPU *cpu,target_ulong list, +Error **errp) { -target_ulong list =ppc64_phys_to_real (args[0 ]); -target_ulong ov_table;bool explicit_match = false;/* Matched the CPU's real PVR */ uint32_t max_compat = cpu->max_compat;uint32_t best_compat =0 ;int i; -sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; -bool guest_radix;/* * We scan the supplied table of PVRs looking for two things
@@ -1090,26 +1084,43 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,/* We couldn't find a suitable compatibility mode, and either * the guest doesn't support "raw" mode for this CPU, or raw * mode is disabled because a maximum compat mode is set */ -return H_HARDWARE ; +error_setg (errp,"Couldn't negotiate a suitable PVR during CAS" ); +return 0 ; }/* Parsing finished */ trace_spapr_cas_pvr (cpu->compat_pvr, explicit_match, best_compat); -/* Update CPUs */ -if (cpu->compat_pvr != best_compat) { -Error *local_err =NULL ; +return best_compat; +} + +static target_ulong h_client_architecture_support (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +/* @ov_table points to the first option vector */ +target_ulong ov_table =ppc64_phys_to_real (args[0 ]); +uint32_t cas_pvr; +sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; +bool guest_radix; +Error *local_err =NULL ; -ppc_set_compat_all (best_compat, &local_err); + cas_pvr =cas_check_pvr (cpu, ov_table, &local_err); +if (local_err) { +error_report_err (local_err); +return H_HARDWARE ; + } + +/* Update CPUs */ +if (cpu->compat_pvr != cas_pvr) { +ppc_set_compat_all (cas_pvr, &local_err);if (local_err) {error_report_err (local_err);return H_HARDWARE ; } } -/* For the future use: here @ov_table points to the first option vector */ - ov_table = list; - ov1_guest =spapr_ovec_parse_vector (ov_table,1 ); ov5_guest =spapr_ovec_parse_vector (ov_table,5 );if (spapr_ovec_test (ov5_guest,OV5_MMU_BOTH )) {
Signature · 1 line
2.9.4
Re: [Qemu-devel] [RFC 1/2] pseries: Split CAS PVR negotiation out into a separate function
Quoted 83 lines · David Gibson
Guests of the qemu machine type go through a feature negotiation process known as "client architecture support" (CAS) during early boot. This does a number of things, one of which is finding a CPU compatibility mode which can be supported by both guest and host.
In fact the CPU negotiation is probably the single most complex part of the CAS process, so this splits it out into a helper function. We've recently made some mistakes in maintaining backward compatibility for old machine types here. Splitting this out will also make it easier to fix this.
This also adds a possibly useful error message if the negotiation fails (i.e. if there is CPU mode that's suitable for both guest and host).
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr_hcall.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-)hw/ppc/spapr_hcall.c +26
-13@@ -1047,19 +1047,13 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, } } -static target_ulong h_client_architecture_support (PowerPCCPU *cpu, -sPAPRMachineState *spapr, -target_ulong opcode, -target_ulong *args) +static uint32_t cas_check_pvr (PowerPCCPU *cpu,target_ulong list, +Error **errp) { -target_ulong list =ppc64_phys_to_real (args[0 ]); -target_ulong ov_table;bool explicit_match = false;/* Matched the CPU's real PVR */ uint32_t max_compat = cpu->max_compat;uint32_t best_compat =0 ;int i; -sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; -bool guest_radix;/* * We scan the supplied table of PVRs looking for two things @@ -1090,26 +1084,43 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,/* We couldn't find a suitable compatibility mode, and either * the guest doesn't support "raw" mode for this CPU, or raw * mode is disabled because a maximum compat mode is set */ -return H_HARDWARE ; +error_setg (errp,"Couldn't negotiate a suitable PVR during CAS" ); +return 0 ; }/* Parsing finished */ trace_spapr_cas_pvr (cpu->compat_pvr, explicit_match, best_compat); -/* Update CPUs */ -if (cpu->compat_pvr != best_compat) { -Error *local_err =NULL ; +return best_compat; +} + +static target_ulong h_client_architecture_support (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args) +{ +/* @ov_table points to the first option vector */ +target_ulong ov_table =ppc64_phys_to_real (args[0 ]); +uint32_t cas_pvr; +sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; +bool guest_radix; +Error *local_err =NULL ; -ppc_set_compat_all (best_compat, &local_err); + cas_pvr =cas_check_pvr (cpu, ov_table, &local_err); +if (local_err) { +error_report_err (local_err); +return H_HARDWARE ; + } + +/* Update CPUs */ +if (cpu->compat_pvr != cas_pvr) {
hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu, · line 1112
Quoted 10 lines
hw/ppc/spapr_hcall.c +1
-3+ppc_set_compat_all (cas_pvr, &local_err);if (local_err) {error_report_err (local_err);return H_HARDWARE ; } } -/* For the future use: here @ov_table points to the first option vector */ - ov_table = list; -
I think there is a change here: now ov_table is always ppc64_phys_to_real(args[0]), as it is not updated by cas_check() as list was by h_client_architecture_support().
hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu, · line 1126
Quoted 3 lines
hw/ppc/spapr_hcall.c +0
-0ov1_guest =spapr_ovec_parse_vector (ov_table,1 ); ov5_guest =spapr_ovec_parse_vector (ov_table,5 );if (spapr_ovec_test (ov5_guest,OV5_MMU_BOTH )) {
Laurent
Re: [Qemu-devel] [Qemu-ppc] [RFC 1/2] pseries: Split CAS PVR negotiation out into a separate function
In reply to David GibsonQuoted 5 lines · On Wed, 17 May 2017 16:35:46 +1000 David Gibson <[email protected]>…
Guests of the qemu machine type go through a feature negotiation process known as "client architecture support" (CAS) during early boot. This does a number of things, one of which is finding a CPU compatibility mode which can be supported by both guest and host.
Quoted 7 lines
In fact the CPU negotiation is probably the single most complex part of the CAS process, so this splits it out into a helper function. We've recently made some mistakes in maintaining backward compatibility for old machine types here. Splitting this out will also make it easier to fix this.
This also adds a possibly useful error message if the negotiation fails (i.e. if there is CPU mode that's suitable for both guest and host).
s/if there is/if there isn't a/ ?
Quoted 54 lines
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr_hcall.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-)hw/ppc/spapr_hcall.c +11
-12@@ -1047,19 +1047,13 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, } } -static target_ulong h_client_architecture_support (PowerPCCPU *cpu, -sPAPRMachineState *spapr, -target_ulong opcode, -target_ulong *args) +static uint32_t cas_check_pvr (PowerPCCPU *cpu,target_ulong list, +Error **errp) { -target_ulong list =ppc64_phys_to_real (args[0 ]); -target_ulong ov_table;bool explicit_match = false;/* Matched the CPU's real PVR */ uint32_t max_compat = cpu->max_compat;uint32_t best_compat =0 ;int i; -sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; -bool guest_radix;/* * We scan the supplied table of PVRs looking for two things @@ -1090,26 +1084,43 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,/* We couldn't find a suitable compatibility mode, and either * the guest doesn't support "raw" mode for this CPU, or raw * mode is disabled because a maximum compat mode is set */ -return H_HARDWARE ; +error_setg (errp,"Couldn't negotiate a suitable PVR during CAS" ); +return 0 ; }/* Parsing finished */ trace_spapr_cas_pvr (cpu->compat_pvr, explicit_match, best_compat); -/* Update CPUs */ -if (cpu->compat_pvr != best_compat) { -Error *local_err =NULL ; +return best_compat; +} + +static target_ulong h_client_architecture_support (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args)
hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu, · line 1109
Quoted 10 lines
hw/ppc/spapr_hcall.c +8
-1+{ +/* @ov_table points to the first option vector */ +target_ulong ov_table =ppc64_phys_to_real (args[0 ]); +uint32_t cas_pvr; +sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; +bool guest_radix; +Error *local_err =NULL ; -ppc_set_compat_all (best_compat, &local_err); + cas_pvr =cas_check_pvr (cpu, ov_table, &local_err);
Shouldn't cas_check_pvr() take a target_ulong * so that we can get the address of the first option vector...
Quoted 7 lines
hw/ppc/spapr_hcall.c +7
-0+if (local_err) { +error_report_err (local_err); +return H_HARDWARE ; + } + +/* Update CPUs */ +if (cpu->compat_pvr != cas_pvr) {
hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu, · line 1112
Quoted 10 lines
hw/ppc/spapr_hcall.c +1
-3+ppc_set_compat_all (cas_pvr, &local_err);if (local_err) {error_report_err (local_err);return H_HARDWARE ; } } -/* For the future use: here @ov_table points to the first option vector */ - ov_table = list; -
... and address Laurent's comment ?
Quoted 3 lines
hw/ppc/spapr_hcall.c +0
-0ov1_guest =spapr_ovec_parse_vector (ov_table,1 ); ov5_guest =spapr_ovec_parse_vector (ov_table,5 );if (spapr_ovec_test (ov5_guest,OV5_MMU_BOTH )) {
Re: [Qemu-devel] [Qemu-ppc] [RFC 1/2] pseries: Split CAS PVR negotiation out into a separate function
Quoted 13 lines · Greg Kurz
Quoted 10 lines · On Wed, 17 May 2017 16:35:46 +1000 David Gibson <[email protected]>…
Guests of the qemu machine type go through a feature negotiation process known as "client architecture support" (CAS) during early boot. This does a number of things, one of which is finding a CPU compatibility mode which can be supported by both guest and host.
In fact the CPU negotiation is probably the single most complex part of the CAS process, so this splits it out into a helper function. We've recently made some mistakes in maintaining backward compatibility for old machine types here. Splitting this out will also make it easier to fix this.
Quoted 4 lines
Quoted 2 lines
This also adds a possibly useful error message if the negotiation fails (i.e. if there is CPU mode that's suitable for both guest and host).
s/if there is/if there isn't a/ ?
Oops, I'll correct that.
Quoted 83 lines
Quoted 55 lines
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr_hcall.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-)hw/ppc/spapr_hcall.c +11
-12@@ -1047,19 +1047,13 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, } } -static target_ulong h_client_architecture_support (PowerPCCPU *cpu, -sPAPRMachineState *spapr, -target_ulong opcode, -target_ulong *args) +static uint32_t cas_check_pvr (PowerPCCPU *cpu,target_ulong list, +Error **errp) { -target_ulong list =ppc64_phys_to_real (args[0 ]); -target_ulong ov_table;bool explicit_match = false;/* Matched the CPU's real PVR */ uint32_t max_compat = cpu->max_compat;uint32_t best_compat =0 ;int i; -sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; -bool guest_radix;/* * We scan the supplied table of PVRs looking for two things @@ -1090,26 +1084,43 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,/* We couldn't find a suitable compatibility mode, and either * the guest doesn't support "raw" mode for this CPU, or raw * mode is disabled because a maximum compat mode is set */ -return H_HARDWARE ; +error_setg (errp,"Couldn't negotiate a suitable PVR during CAS" ); +return 0 ; }/* Parsing finished */ trace_spapr_cas_pvr (cpu->compat_pvr, explicit_match, best_compat); -/* Update CPUs */ -if (cpu->compat_pvr != best_compat) { -Error *local_err =NULL ; +return best_compat; +} + +static target_ulong h_client_architecture_support (PowerPCCPU *cpu, +sPAPRMachineState *spapr, +target_ulong opcode, +target_ulong *args)hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu, · line 1109
Quoted 10 lines
hw/ppc/spapr_hcall.c +8
-1+{ +/* @ov_table points to the first option vector */ +target_ulong ov_table =ppc64_phys_to_real (args[0 ]); +uint32_t cas_pvr; +sPAPROptionVector *ov1_guest, *ov5_guest, *ov5_cas_old, *ov5_updates; +bool guest_radix; +Error *local_err =NULL ; -ppc_set_compat_all (best_compat, &local_err); + cas_pvr =cas_check_pvr (cpu, ov_table, &local_err);Shouldn't
cas_check_pvr()take atarget_ulong* so that we can get the address of the first option vector...Quoted 14 lines
hw/ppc/spapr_hcall.c +8
-0+if (local_err) { +error_report_err (local_err); +return H_HARDWARE ; + } + +/* Update CPUs */ +if (cpu->compat_pvr != cas_pvr) { +ppc_set_compat_all (cas_pvr, &local_err);if (local_err) {error_report_err (local_err);return H_HARDWARE ; } }
Quoted 5 lines
hw/ppc/spapr_hcall.c static target_ulong h_client_architecture_support(PowerPCCPU *cpu, · line 1112
Quoted 3 lines
hw/ppc/spapr_hcall.c +0
-3-/* For the future use: here @ov_table points to the first option vector */ - ov_table = list; -... and address Laurent's comment ?
Yes, I completely misread what was happening with the pvr_list vs. the option vectors. I'll correct that.
Quoted 5 lines
Quoted 4 lines
hw/ppc/spapr_hcall.c +0
-0ov1_guest =spapr_ovec_parse_vector (ov_table,1 ); ov5_guest =spapr_ovec_parse_vector (ov_table,5 );if (spapr_ovec_test (ov5_guest,OV5_MMU_BOTH )) {
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 2/2 pseries: Restore PVR negotiation logic for pre-2.9 machine types
In reply to David Gibson"pseries" guests go through a hypervisor<->guest feature negotiation during early boot. Part of this is finding a CPU compatibility mode which works for both.
In 152ef80 "pseries: Rewrite CAS PVR compatibility logic" this logic was changed to strongly prefer architecture defined CPU compatibility modes, rather than CPU "raw" modes. However, this change was made universally, which introduces a guest visible change for the previously existing machine types (pseries-2.8 and earlier). That's never supposed to happen.
This corrects the behaviour, reverting to the old PVR negotiation logic for machine types prior to pseries-2.9.
--- hw/ppc/spapr.c | 3 ++ hw/ppc/spapr_hcall.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 1 + 3 files changed, 93 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +3 -0
@@ -3308,9 +3308,12 @@ static void spapr_machine_2_8_instance_options(MachineState *machine)static void spapr_machine_2_8_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_9_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_8 ); mc->numa_mem_align_shift =23 ; + smc->pre_2_9_cas_pvr = true; } DEFINE_SPAPR_MACHINE(2_8, "2.8", false);
hw/ppc/spapr_hcall.c +89 -1
108 lines not on this page · raw message
include/hw/ppc/spapr.h +1 -0
@@ -52,6 +52,7 @@ struct sPAPRMachineClass {/*< public >*/ bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ +bool pre_2_9_cas_pvr;/* Use old logic for PVR compat negotiation */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,
Signature · 1 line
2.9.4
Re: [Qemu-devel] [RFC 2/2] pseries: Restore PVR negotiation logic for pre-2.9 machine types
Quoted 116 lines · David Gibson
"pseries" guests go through a hypervisor<->guest feature negotiation during early boot. Part of this is finding a CPU compatibility mode which works for both.
In 152ef80 "pseries: Rewrite CAS PVR compatibility logic" this logic was changed to strongly prefer architecture defined CPU compatibility modes, rather than CPU "raw" modes. However, this change was made universally, which introduces a guest visible change for the previously existing machine types (pseries-2.8 and earlier). That's never supposed to happen.
This corrects the behaviour, reverting to the old PVR negotiation logic for machine types prior to pseries-2.9.
Fixes 152ef803ceb1959e2380a1da7736b935b109222eReported-by Andrea Bolognani <[email protected]>Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr.c | 3 ++ hw/ppc/spapr_hcall.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 1 + 3 files changed, 93 insertions(+), 1 deletion(-)hw/ppc/spapr.c +3
-0@@ -3308,9 +3308,12 @@ static void spapr_machine_2_8_instance_options(MachineState *machine)static void spapr_machine_2_8_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_9_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_8 ); mc->numa_mem_align_shift =23 ; + smc->pre_2_9_cas_pvr = true; } DEFINE_SPAPR_MACHINE(2_8, "2.8", false);hw/ppc/spapr_hcall.c +69
-0@@ -1047,6 +1047,89 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, } } +/* +* Old logic for PVR negotiation, used old <2.9 machine types for +* compatibility with old qemu versions +*/ +#define get_compat_level (cpuver) ( \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_05) ? 2050 : \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_06) ? 2060 : \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_06_PLUS) ? 2061 : \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0) + +static void cas_handle_compat_cpu (PowerPCCPUClass *pcc,uint32_t pvr, +unsigned max_lvl,unsigned *compat_lvl, +unsigned *compat_pvr) +{ +unsigned lvl =get_compat_level (pvr); +bool is205, is206, is207; + +if (!lvl) { +return ; + } + +/* If it is a logical PVR, try to determine the highest level */ + is205 = (pcc->pcr_supported &PCR_COMPAT_2_05 ) && + (lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_05 )); + is206 = (pcc->pcr_supported &PCR_COMPAT_2_06 ) && + ((lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_06 )) || + (lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_06_PLUS ))); + is207 = (pcc->pcr_supported &PCR_COMPAT_2_07 ) && + (lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_07 )); + +if (is205 || is206 || is207) { +if (!max_lvl) { +/* User did not set the level, choose the highest */ +if (*compat_lvl <= lvl) { + *compat_lvl = lvl; + *compat_pvr = pvr; + } + }else if (max_lvl >= lvl) { +/* User chose the level, don't set higher than this */ + *compat_lvl = lvl; + *compat_pvr = pvr; + } + } +} + +static uint32_t cas_check_pvr_pre_2_9 (PowerPCCPU *cpu,target_ulong list, +Error **errp) +{ +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +int counter; +unsigned max_lvl =get_compat_level (cpu->max_compat); +bool cpu_match = false; +unsigned compat_lvl =0 , compat_pvr =0 ; + +for (counter =0 ; counter <512 ; ++counter) { +uint32_t pvr, pvr_mask; + + pvr_mask =ldl_be_phys (&address_space_memory, list); + pvr =ldl_be_phys (&address_space_memory, list +4 ); + list +=8 ; + +if (~pvr_mask & pvr) { +break ;/* Terminator record */ + } + +trace_spapr_cas_pvr_try (pvr); +if (!max_lvl && + ((cpu->env.spr[SPR_PVR ] & pvr_mask) == (pvr & pvr_mask))) { + cpu_match = true;
hw/ppc/spapr_hcall.c static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, · line 1128
Quoted 10 lines
hw/ppc/spapr_hcall.c +10
-0+ compat_pvr =0 ; + }else if (pvr == cpu->compat_pvr) { + cpu_match = true; + compat_pvr = cpu->compat_pvr; + }else if (!cpu_match) { +cas_handle_compat_cpu (pcc, pvr, max_lvl, &compat_lvl, &compat_pvr); + } + } + +trace_spapr_cas_pvr (cpu->compat_pvr, cpu_match, compat_pvr);
Perhaps you can add a new function or a parameter to show which path (pre_2_9 or not) we use to compute the CAS PVR?
anyway:
Laurent
Re: [Qemu-devel] [Qemu-ppc] [RFC 2/2] pseries: Restore PVR negotiation logic for pre-2.9 machine types
In reply to David GibsonQuoted 44 lines · On Wed, 17 May 2017 16:35:47 +1000 David Gibson <[email protected]>…
"pseries" guests go through a hypervisor<->guest feature negotiation during early boot. Part of this is finding a CPU compatibility mode which works for both.
In 152ef80 "pseries: Rewrite CAS PVR compatibility logic" this logic was changed to strongly prefer architecture defined CPU compatibility modes, rather than CPU "raw" modes. However, this change was made universally, which introduces a guest visible change for the previously existing machine types (pseries-2.8 and earlier). That's never supposed to happen.
This corrects the behaviour, reverting to the old PVR negotiation logic for machine types prior to pseries-2.9.
Fixes 152ef803ceb1959e2380a1da7736b935b109222eReported-by Andrea Bolognani <[email protected]>Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr.c | 3 ++ hw/ppc/spapr_hcall.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++- include/hw/ppc/spapr.h | 1 + 3 files changed, 93 insertions(+), 1 deletion(-)hw/ppc/spapr.c +3
-0@@ -3308,9 +3308,12 @@ static void spapr_machine_2_8_instance_options(MachineState *machine)static void spapr_machine_2_8_class_options (MachineClass *mc) { +sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc); +spapr_machine_2_9_class_options (mc);SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_8 ); mc->numa_mem_align_shift =23 ; + smc->pre_2_9_cas_pvr = true; } DEFINE_SPAPR_MACHINE(2_8, "2.8", false);hw/ppc/spapr_hcall.c +0
-0
hw/ppc/spapr_hcall.c static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, · line 1051
Quoted 5 lines
hw/ppc/spapr_hcall.c +2
-0@@ -1047,6 +1047,89 @@ static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, } } +/* +* Old logic for PVR negotiation, used old <2.9 machine types for
s/used old/used by old/
Quoted 34 lines
hw/ppc/spapr_hcall.c +34
-0+* compatibility with old qemu versions +*/ +#define get_compat_level (cpuver) ( \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_05) ? 2050 : \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_06) ? 2060 : \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_06_PLUS) ? 2061 : \ + ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0) + +static void cas_handle_compat_cpu (PowerPCCPUClass *pcc,uint32_t pvr, +unsigned max_lvl,unsigned *compat_lvl, +unsigned *compat_pvr) +{ +unsigned lvl =get_compat_level (pvr); +bool is205, is206, is207; + +if (!lvl) { +return ; + } + +/* If it is a logical PVR, try to determine the highest level */ + is205 = (pcc->pcr_supported &PCR_COMPAT_2_05 ) && + (lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_05 )); + is206 = (pcc->pcr_supported &PCR_COMPAT_2_06 ) && + ((lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_06 )) || + (lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_06_PLUS ))); + is207 = (pcc->pcr_supported &PCR_COMPAT_2_07 ) && + (lvl ==get_compat_level (CPU_POWERPC_LOGICAL_2_07 )); + +if (is205 || is206 || is207) { +if (!max_lvl) { +/* User did not set the level, choose the highest */ +if (*compat_lvl <= lvl) { + *compat_lvl = lvl; + *compat_pvr = pvr;
hw/ppc/spapr_hcall.c static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, · line 1095
Quoted 10 lines
hw/ppc/spapr_hcall.c +10
-0+ } + }else if (max_lvl >= lvl) { +/* User chose the level, don't set higher than this */ + *compat_lvl = lvl; + *compat_pvr = pvr; + } + } +} + +static uint32_t cas_check_pvr_pre_2_9(PowerPCCPU *cpu, target_ulong list,
Same remark as for cas_check_pvr() in patch 1.
Quoted 73 lines
hw/ppc/spapr_hcall.c +43
-1+ Error **errp) +{ +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +int counter; +unsigned max_lvl =get_compat_level (cpu->max_compat); +bool cpu_match = false; +unsigned compat_lvl =0 , compat_pvr =0 ; + +for (counter =0 ; counter <512 ; ++counter) { +uint32_t pvr, pvr_mask; + + pvr_mask =ldl_be_phys (&address_space_memory, list); + pvr =ldl_be_phys (&address_space_memory, list +4 ); + list +=8 ; + +if (~pvr_mask & pvr) { +break ;/* Terminator record */ + } + +trace_spapr_cas_pvr_try (pvr); +if (!max_lvl && + ((cpu->env.spr[SPR_PVR ] & pvr_mask) == (pvr & pvr_mask))) { + cpu_match = true; + compat_pvr =0 ; + }else if (pvr == cpu->compat_pvr) { + cpu_match = true; + compat_pvr = cpu->compat_pvr; + }else if (!cpu_match) { +cas_handle_compat_cpu (pcc, pvr, max_lvl, &compat_lvl, &compat_pvr); + } + } + +trace_spapr_cas_pvr (cpu->compat_pvr, cpu_match, compat_pvr); + +return compat_pvr; +} +static uint32_t cas_check_pvr (PowerPCCPU *cpu,target_ulong list,Error **errp) {@@ -1099,6 +1182,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,target_ulong opcode, target_ulong *args) { + sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);/* @ov_table points to the first option vector */ target_ulong ov_table =ppc64_phys_to_real (args[0 ]);uint32_t cas_pvr;@@ -1106,7 +1190,11 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,bool guest_radix;Error *local_err =NULL ; - cas_pvr =cas_check_pvr (cpu, ov_table, &local_err); +if (smc->pre_2_9_cas_pvr) { + cas_pvr =cas_check_pvr_pre_2_9 (cpu, ov_table, &local_err); + }else { + cas_pvr =cas_check_pvr (cpu, ov_table, &local_err); + }if (local_err) {error_report_err (local_err);return H_HARDWARE ;include/hw/ppc/spapr.h +1
-0@@ -52,6 +52,7 @@ struct sPAPRMachineClass {/*< public >*/ bool dr_lmb_enabled;/* enable dynamic-reconfig/hotplug of LMBs */ bool use_ohci_by_default;/* use USB-OHCI instead of XHCI */ +bool pre_2_9_cas_pvr;/* Use old logic for PVR compat negotiation */ const char *tcg_default_cpu;/* which (TCG) CPU to simulate by default */ void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index, uint64_t *buid, hwaddr *pio,
Quoted 16 lines · David Gibson
152ef80 "pseries: Rewrite CAS PVR compatibility logic" incorrectly introduced a guest-visible behaviour change into existing versioned machine type. Patch 2/2 corrects this change, while 1/2 is a preliminary clean up to make that easier.
Unfortunately, this bug is already in the released qemu-2.9.0. Once this is ready to merge for master, I'll make a backport to apply for 2.9.1 as well.
David Gibson (2):
pseries: Split CAS PVR negotiation out into a separate function
pseries: Restore PVR negotiation logic for pre-2.9 machine types
hw/ppc/spapr.c | 3 ++
hw/ppc/spapr_hcall.c | 131 +++++++++++++++++++++++++++++++++++++++++++------include/hw/ppc/spapr.h| 1 +
Quoted 1 line
3 files changed, 119 insertions(+), 16 deletions(-)
I gave it a spin and I can no longer reproduce the issue, so for the entire series:
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 19 lines · Andrea Bolognani
Quoted 16 lines · David Gibson
152ef80 "pseries: Rewrite CAS PVR compatibility logic" incorrectly introduced a guest-visible behaviour change into existing versioned machine type. Patch 2/2 corrects this change, while 1/2 is a preliminary clean up to make that easier.
Unfortunately, this bug is already in the released qemu-2.9.0. Once this is ready to merge for master, I'll make a backport to apply for 2.9.1 as well.
David Gibson (2):
pseries: Split CAS PVR negotiation out into a separate function
pseries: Restore PVR negotiation logic for pre-2.9 machine types
hw/ppc/spapr.c | 3 ++
hw/ppc/spapr_hcall.c | 131 +++++++++++++++++++++++++++++++++++++++++++------include/hw/ppc/spapr.h| 1 +Quoted 1 line
3 files changed, 119 insertions(+), 16 deletions(-)
Quoted 4 lines
I gave it a spin and I can no longer reproduce the issue, so for the entire series:
Tested-by Andrea Bolognani <[email protected]>
I'm actually kind of astonished it worked at all given the bug that Laurent pointed out.
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
Quoted 7 lines · David Gibson
Quoted 4 lines
I gave it a spin and I can no longer reproduce the issue, so for the entire series:
Tested-by Andrea Bolognani <[email protected]>I'm actually kind of astonished it worked at all given the bug that Laurent pointed out.
¯\_(ツ)_/¯
Signature · 1 line
Andrea Bolognani / Red Hat / Virtualization