From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
christoffer.dall@linaro.org, greg.bellows@linaro.org
Subject: [Qemu-devel] [PATCH v6 5/5] target-arm: kvm64 fix save/restore of SPSR regs
Date: Wed, 1 Apr 2015 16:39:16 +0100 [thread overview]
Message-ID: <1427902756-30567-6-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1427902756-30567-1-git-send-email-alex.bennee@linaro.org>
The current code was negatively indexing the cpu state array and not
synchronizing banked spsr register state with the current mode's spsr
state, causing occasional failures with migration.
Some munging is done to take care of the aarch64 mapping and also to
ensure the most current value of the spsr is updated to the banked
registers (relevant for KVM<->TCG migration).
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2 (ajb)
- minor tweaks and clarifications
v3
- Use the correct bank index function for setting/getting env->spsr
- only deal with spsrs in elevated exception levels
v4
- try and make commentary clearer
- ensure env->banked_spsr[0] = env->spsr before we sync
v5
- fix banking index now banking fixed
- keep wide spacing on [ ] forms
- claimed authorship
v6
- only save/restore env->spsr if not in aarch64 mode
- rm stray space
diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c
index d6c83b0..b020b96 100644
--- a/target-arm/kvm64.c
+++ b/target-arm/kvm64.c
@@ -140,6 +140,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
uint64_t val;
int i;
int ret;
+ unsigned int el;
ARMCPU *cpu = ARM_CPU(cs);
CPUARMState *env = &cpu->env;
@@ -206,9 +207,22 @@ int kvm_arch_put_registers(CPUState *cs, int level)
return ret;
}
+ /* Saved Program State Registers
+ *
+ * Before we restore from the banked_spsr[] array we need to
+ * ensure that any modifications to env->spsr are correctly
+ * reflected in the banks.
+ */
+ el = arm_current_el(env);
+ if (el > 0 && !is_a64(env)) {
+ i = bank_number(env->uncached_cpsr & CPSR_M);
+ env->banked_spsr[i] = env->spsr;
+ }
+
+ /* KVM 0-4 map to QEMU banks 1-5 */
for (i = 0; i < KVM_NR_SPSR; i++) {
reg.id = AARCH64_CORE_REG(spsr[i]);
- reg.addr = (uintptr_t) &env->banked_spsr[i - 1];
+ reg.addr = (uintptr_t) &env->banked_spsr[i + 1];
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
if (ret) {
return ret;
@@ -265,6 +279,7 @@ int kvm_arch_get_registers(CPUState *cs)
struct kvm_one_reg reg;
uint64_t val;
uint32_t fpr;
+ unsigned int el;
int i;
int ret;
@@ -337,15 +352,25 @@ int kvm_arch_get_registers(CPUState *cs)
return ret;
}
+ /* Fetch the SPSR registers
+ *
+ * KVM SPSRs 0-4 map to QEMU banks 1-5
+ */
for (i = 0; i < KVM_NR_SPSR; i++) {
reg.id = AARCH64_CORE_REG(spsr[i]);
- reg.addr = (uintptr_t) &env->banked_spsr[i - 1];
+ reg.addr = (uintptr_t) &env->banked_spsr[i + 1];
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
if (ret) {
return ret;
}
}
+ el = arm_current_el(env);
+ if (el > 0 && !is_a64(env)) {
+ i = bank_number(env->uncached_cpsr & CPSR_M);
+ env->spsr = env->banked_spsr[i];
+ }
+
/* Advanced SIMD and FP registers
* We map Qn = regs[2n+1]:regs[2n]
*/
--
2.3.4
next prev parent reply other threads:[~2015-04-01 15:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-01 15:39 [Qemu-devel] [PATCH v6 0/5] QEMU ARM64 Migration Fixes Alex Bennée
2015-04-01 15:39 ` [Qemu-devel] [PATCH v6 1/5] target-arm: Store SPSR_EL1 state in banked_spsr[1] (SPSR_svc) Alex Bennée
2015-04-01 15:39 ` [Qemu-devel] [PATCH v6 2/5] target-arm: kvm: save/restore mp state Alex Bennée
2015-04-01 16:31 ` Peter Maydell
2015-04-01 15:39 ` [Qemu-devel] [PATCH v6 3/5] hw/intc: arm_gic_kvm.c restore config first Alex Bennée
2015-04-01 15:39 ` [Qemu-devel] [PATCH v6 4/5] target-arm: kvm64 sync FP register state Alex Bennée
2015-04-01 15:39 ` Alex Bennée [this message]
2015-04-01 16:31 ` [Qemu-devel] [PATCH v6 5/5] target-arm: kvm64 fix save/restore of SPSR regs Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1427902756-30567-6-git-send-email-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=christoffer.dall@linaro.org \
--cc=greg.bellows@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).