ppc: fix spapr migration (TCG)
cover ppc: fix spapr migration (TCG)
Hello,
Here a couple of patches to fix the migration of spapr guests running in TCG. This is not of the highest priority but it should work.
Waiting for your comments. Thanks !
C.
Cédric Le Goater (2):
target-ppc: migrate interrupt vectors address for spapr VM
target-ppc: fix interrupt vectors address migration
target-ppc/helper_regs.h | 8 +++++--- target-ppc/machine.c | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
RFC PATCH 1/2 target-ppc: migrate interrupt vectors address for spapr VM
This address is changed by the linux kernel using the H_SET_MODE hcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.
--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)
target-ppc/machine.c +3 -0
@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = {VMSTATE_UINTTL (env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ +/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
Signature · 1 line
2.1.4
Re: [Qemu-devel] [RFC PATCH 1/2] target-ppc: migrate interrupt vectors address for spapr VM
Quoted 14 lines · Cédric Le Goater
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)target-ppc/machine.c +0
-0
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu = { · line 561
Quoted 9 lines
target-ppc/machine.c +3
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = {VMSTATE_UINTTL (env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ +/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
I'm really no expert with all this migration stuff, but don't you have to bump the version_id when you add new fields to the vmstate? ... and/or use VMSTATE_UINTTL_V() so that migration from older versions of QEMU to the current one also still works with KVM? For example, is it still possible to migrate from QEMU 2.5 to QEMU 2.6 in KVM if you only use VMSTATE_UINTTL without the _V suffix?
Thomas
Re: [Qemu-devel] [Qemu-ppc] [RFC PATCH 1/2] target-ppc: migrate interrupt vectors address for spapr VM
Quoted 18 lines · On Mon, 21 Mar 2016 17:18:17 +0100 Thomas Huth <[email protected]> wrote:
Quoted 17 lines · Cédric Le Goater
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)target-ppc/machine.c +0
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = { VMSTATE_UINTTL(env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */
Quoted 9 lines
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu = { · line 561
Quoted 6 lines
target-ppc/machine.c +3
-0+/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),I'm really no expert with all this migration stuff, but don't you have to bump the
version_idwhen you add new fields to the vmstate?
Yes...
Quoted 1 line
... and/or use
VMSTATE_UINTTL_V()so that migration from older versions
... and also yes.
Quoted 4 lines
of QEMU to the current one also still works with KVM? For example, is it still possible to migrate from QEMU 2.5 to QEMU 2.6 in KVM if you only use
VMSTATE_UINTTLwithout the _V suffix?
No we really want to use the _V version here: it indicates that starting with this version (v6), cpu objects stream env.excp_prefix.
Quoted 3 lines
Thomas
--
Greg
Re: [Qemu-devel] [RFC PATCH 1/2] target-ppc: migrate interrupt vectors address for spapr VM
In reply to Thomas HuthQuoted 18 lines · Thomas Huth
Quoted 17 lines · Cédric Le Goater
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)target-ppc/machine.c +0
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = { VMSTATE_UINTTL(env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */
Quoted 13 lines
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu = { · line 561
Quoted 6 lines
target-ppc/machine.c +3
-0+/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),I'm really no expert with all this migration stuff, but don't you have to bump the
version_idwhen you add new fields to the vmstate? ... and/or useVMSTATE_UINTTL_V()so that migration from older versions of QEMU to the current one also still works with KVM? For example, is it still possible to migrate from QEMU 2.5 to QEMU 2.6 in KVM if you only useVMSTATE_UINTTLwithout the _V suffix?
Yes. You are right. I think we need something like below.
Thanks,
C.
target-ppc: migrate interrupt vectors address for spapr VM
This address is changed by the linux kernel using the H_SET_MODE hcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.
--- target-ppc/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target-ppc/machine.c +4 -1
@@ -522,7 +522,7 @@ static const VMStateDescription vmstate_const VMStateDescription vmstate_ppc_cpu = { .name ="cpu" , - .version_id =5 , + .version_id =6 , .minimum_version_id =5 , .minimum_version_id_old =4 , .load_state_old = cpu_load_old,
@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpuVMSTATE_UINTTL (env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ +/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL_V (env.excp_prefix, PowerPCCPU,6 ), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
Quoted 2 lines
Thomas
Greg Kurz
Reviewed-byRe: [Qemu-devel] [Qemu-ppc] [RFC PATCH 1/2] target-ppc: migrate interrupt vectors address for spapr VM
Quoted 33 lines · On Mon, 21 Mar 2016 17:51:22 +0100 Cédric Le Goater <[email protected]> wrote:
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Cédric Le Goater
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)target-ppc/machine.c +0
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = { VMSTATE_UINTTL(env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ Quoted 13 lines
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu · line 561
Quoted 6 lines
target-ppc/machine.c +3
-0+/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),I'm really no expert with all this migration stuff, but don't you have to bump the
version_idwhen you add new fields to the vmstate? ... and/or useVMSTATE_UINTTL_V()so that migration from older versions of QEMU to the current one also still works with KVM? For example, is it still possible to migrate from QEMU 2.5 to QEMU 2.6 in KVM if you only useVMSTATE_UINTTLwithout the _V suffix?
Quoted 2 lines
Yes. You are right. I think we need something like below.
It looks much better !
And just to be sure: this only affects TCG because excp_prefix isn't accessed by QEMU when running with KVM, right ?
If the answer is as simple as yes, then:
Quoted 46 lines
Thanks,
C.
target-ppc: migrate interrupt vectors address for spapr VM
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
qemu-dgibson-for-2.6.git/target-ppc/machine.c
===================================================================target-ppc/machine.c +4
-1@@ -522,7 +522,7 @@ static const VMStateDescription vmstate_const VMStateDescription vmstate_ppc_cpu = { .name ="cpu" , - .version_id =5 , + .version_id =6 , .minimum_version_id =5 , .minimum_version_id_old =4 , .load_state_old = cpu_load_old,@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpuVMSTATE_UINTTL (env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ +/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL_V (env.excp_prefix, PowerPCCPU,6 ), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),Quoted 5 lines
Thomas
Re: [Qemu-devel] [RFC PATCH 1/2] target-ppc: migrate interrupt vectors address for spapr VM
In reply to Cédric Le GoaterQuoted 65 lines · Cédric Le Goater
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Cédric Le Goater
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)target-ppc/machine.c +0
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = { VMSTATE_UINTTL(env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ Quoted 13 lines
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu · line 561
Quoted 6 lines
target-ppc/machine.c +3
-0+/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),I'm really no expert with all this migration stuff, but don't you have to bump the
version_idwhen you add new fields to the vmstate? ... and/or useVMSTATE_UINTTL_V()so that migration from older versions of QEMU to the current one also still works with KVM? For example, is it still possible to migrate from QEMU 2.5 to QEMU 2.6 in KVM if you only useVMSTATE_UINTTLwithout the _V suffix?Yes. You are right. I think we need something like below.
Thanks,
C.
target-ppc: migrate interrupt vectors address for spapr VM
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
qemu-dgibson-for-2.6.git/target-ppc/machine.c
===================================================================target-ppc/machine.c +1
-1@@ -522,7 +522,7 @@ static const VMStateDescription vmstate_const VMStateDescription vmstate_ppc_cpu = { .name ="cpu" , - .version_id =5 , + .version_id =6 , .minimum_version_id =5 , .minimum_version_id_old =4 , .load_state_old = cpu_load_old,
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu · line 557
Quoted 5 lines
target-ppc/machine.c +2
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpuVMSTATE_UINTTL (env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ +/* Effective Address of interrupt vectors */ + VMSTATE_UINTTL_V(env.excp_prefix, PowerPCCPU, 6),
So, I dislike putting what's essentially emulator internal state (as opposed to architected state) into the migration stream if we can possibly avoid it.
I think recalculating excp_prefix from the MSR on incoming migration is the correct approach here - I see that there are bugs with that in the other patch, but so far I'm not seeing a reason to migrate excp_prefix itself.
Quoted 9 lines
target-ppc/machine.c +0
-0/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),Quoted 5 lines
Thomas
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 1/2] target-ppc: migrate interrupt vectors address for spapr VM
Quoted 77 lines · David Gibson
Quoted 65 lines · Cédric Le Goater
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Cédric Le Goater
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 3 +++ 1 file changed, 3 insertions(+)target-ppc/machine.c +0
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpu = { VMSTATE_UINTTL(env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ Quoted 13 lines
target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu · line 561
Quoted 6 lines
target-ppc/machine.c +3
-0+/* Effective Address of interrupt vectors */ +VMSTATE_UINTTL (env.excp_prefix, PowerPCCPU), +/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),I'm really no expert with all this migration stuff, but don't you have to bump the
version_idwhen you add new fields to the vmstate? ... and/or useVMSTATE_UINTTL_V()so that migration from older versions of QEMU to the current one also still works with KVM? For example, is it still possible to migrate from QEMU 2.5 to QEMU 2.6 in KVM if you only useVMSTATE_UINTTLwithout the _V suffix?Yes. You are right. I think we need something like below.
Thanks,
C.
target-ppc: migrate interrupt vectors address for spapr VM
This address is changed by the linux kernel using the
H_SET_MODEhcall and needs to be migrated in order to restart a spapr VM running in TCG. Other platforms should not be affected.Signed-off-by Cédric Le Goater <[email protected]>--- target-ppc/machine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Index:
qemu-dgibson-for-2.6.git/target-ppc/machine.c
===================================================================target-ppc/machine.c +1
-1@@ -522,7 +522,7 @@ static const VMStateDescription vmstate_const VMStateDescription vmstate_ppc_cpu = { .name ="cpu" , - .version_id =5 , + .version_id =6 , .minimum_version_id =5 , .minimum_version_id_old =4 , .load_state_old = cpu_load_old,target-ppc/machine.c const VMStateDescription vmstate_ppc_cpu · line 557
Quoted 5 lines
target-ppc/machine.c +2
-0@@ -553,6 +553,9 @@ const VMStateDescription vmstate_ppc_cpuVMSTATE_UINTTL (env.hflags_nmsr, PowerPCCPU),/* FIXME: access_type? */ +/* Effective Address of interrupt vectors */ + VMSTATE_UINTTL_V(env.excp_prefix, PowerPCCPU, 6),So, I dislike putting what's essentially emulator internal state (as opposed to architected state) into the migration stream if we can possibly avoid it.
Quoted 4 lines
I think recalculating
excp_prefixfrom the MSR on incoming migration is the correct approach here - I see that there are bugs with that in the other patch, but so far I'm not seeing a reason to migrateexcp_prefixitself.
OK. It seems quite feasible as we can compute the value from the LPCR_AIL bits in SPR_LPCR. I will give it a try.
Thanks,
C.
Quoted 10 lines
Quoted 9 lines
target-ppc/machine.c +0
-0/* Sanity checking */ VMSTATE_UINTTL_EQUAL (env.msr_mask, PowerPCCPU), VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),Quoted 5 lines
Thomas
RFC PATCH 2/2 target-ppc: fix interrupt vectors address migration
In reply to Cédric Le Goatercommit 2360b6e84f78 ("target-ppc: force update of msr bits in cpu_post_load") introduced a change to restore env->excp_prefix of a guest which could have altered its MSR_EP. To do this, cpu_post_load() invalidates msr and then calls ppc_store_msr() with the expected value in argument.
The problem is that ppc_store_msr() relies on a 'valid' current msr before changing its value. The MSR_HVB and MSR_TGPR bits are excluded from the msr reset to keep the checks valid but the MSR_IR, MSR_DR, MSR_EP bits which are also used through the msr_{ir,dr,ep} macros, are reseted.
This is an issue for CPUs not using MSR_EP, on the spapr platform for instance but all book3s are impacted. If excp_prefix is restored to some value, it will be reseted by this call, causing an ISEG exception on spapr guests.
This patch proposal is to test the msr_mask before actually testing the MSR_EP bit and protect excp_prefix.
---
Should we just move the test in cpu_post_load() and not reset MSR_EP if it is not present in msr_mask ? like this is done for MSR_HVB and MSR_TGPR. I think this is making assumptions on what ppc_store_msr() is up to though.
Maybe we could add a POWERPC_FLAGS_ for this purpose ? or test the excp_model ?
There is room for improvement in ppc_store_msr(). It might need a new helper like ppc_restore_msr() ?
Suggestions welcomed.
target-ppc/helper_regs.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
target-ppc/helper_regs.h +5 -3
@@ -92,9 +92,11 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,/* Swap temporary saved registers with GPRs */ hreg_swap_gpr_tgpr(env); } -if (unlikely ((value >>MSR_EP ) &1 ) != msr_ep) { -/* Change the exception prefix on PowerPC 601 */ - env->excp_prefix = ((value >>MSR_EP ) &1 ) *0xFFF00000 ; +if ((env->msr_mask >>MSR_EP ) &1 ) { +if (unlikely ((value >>MSR_EP ) &1 ) != msr_ep) { +/* Change the exception prefix on PowerPC 601 */ + env->excp_prefix = ((value >>MSR_EP ) &1 ) *0xFFF00000 ; + } }#endif env->msr = value;
Signature · 1 line
2.1.4
Re: [Qemu-devel] [RFC PATCH 2/2] target-ppc: fix interrupt vectors address migration
Quoted 28 lines · Cédric Le Goater
commit
2360b6e84f78("target-ppc: force update of msr bits incpu_post_load") introduced a change to restoreenv->excp_prefixof a guest which could have altered itsMSR_EP. To do this,cpu_post_load()invalidates msr and then callsppc_store_msr()with the expected value in argument.The problem is that
ppc_store_msr()relies on a 'valid' current msr before changing its value. TheMSR_HVBandMSR_TGPRbits are excluded from the msr reset to keep the checks valid but theMSR_IR,MSR_DR,MSR_EPbits which are also used through the msr_{ir,dr,ep} macros, are reseted.This is an issue for CPUs not using
MSR_EP, on the spapr platform for instance but all book3s are impacted. Ifexcp_prefixis restored to some value, it will be reseted by this call, causing an ISEG exception on spapr guests.This patch proposal is to test the
msr_maskbefore actually testing theMSR_EPbit and protectexcp_prefix.Signed-off-by Cédric Le Goater <[email protected]>---
Should we just move the test in
cpu_post_load()and not resetMSR_EPif it is not present inmsr_mask? like this is done forMSR_HVBandMSR_TGPR. I think this is making assumptions on whatppc_store_msr()is up to though.
Quoted 7 lines
Maybe we could add a
POWERPC_FLAGS_for this purpose ? or test theexcp_model?There is room for improvement in
ppc_store_msr(). It might need a new helper likeppc_restore_msr()?Suggestions welcomed.
So, IIUC, in spapr MSR[EP] can't be set with mtmsr or rfid, but can be set with H_SET_MODE?
I think what we need to do is to make sure the full MSR value is migrated then, even if EP is not in the msr_mask. Once that's done, we should be able to correctly calculate excp_prefix from the MSR value after migration.
Or am I missing something?
Quoted 22 lines
target-ppc/helper_regs.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)target-ppc/helper_regs.h +5
-3@@ -92,9 +92,11 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,/* Swap temporary saved registers with GPRs */ hreg_swap_gpr_tgpr(env); } -if (unlikely ((value >>MSR_EP ) &1 ) != msr_ep) { -/* Change the exception prefix on PowerPC 601 */ - env->excp_prefix = ((value >>MSR_EP ) &1 ) *0xFFF00000 ; +if ((env->msr_mask >>MSR_EP ) &1 ) { +if (unlikely ((value >>MSR_EP ) &1 ) != msr_ep) { +/* Change the exception prefix on PowerPC 601 */ + env->excp_prefix = ((value >>MSR_EP ) &1 ) *0xFFF00000 ; + } }#endif env->msr = value;
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