From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
qemu-devel@nongnu.org, qemu-arm@nongnu.org,
peter.maydell@linaro.org, cohuck@redhat.com, maz@kernel.org,
oliver.upton@linux.dev, sebott@redhat.com, gshan@redhat.com,
ddutile@redhat.com, peterx@redhat.com, philmd@linaro.org,
pbonzini@redhat.com
Subject: [PATCH v2 3/8] target/arm/machine: Allow extra regs in the incoming stream
Date: Tue, 18 Nov 2025 17:07:33 +0100 [thread overview]
Message-ID: <20251118160920.554809-4-eric.auger@redhat.com> (raw)
In-Reply-To: <20251118160920.554809-1-eric.auger@redhat.com>
Newer kernels may revoke exposure of KVM regs to userspace. This can
happen when one notices that some registers were unconditionnally
exposed whether they shall be conditionnally exposed for example.
An example of such situation is: TCR2_EL1, PIRE0_EL1, PIR_EL1.
Associated kernel commits were:
0fcb4eea5345 KVM: arm64: Hide TCR2_EL1 from userspace when disabled for guests
a68cddbe47ef KVM: arm64: Hide S1PIE registers from userspace when disabled for guests
Those commits were actual fixes but the cons is that is breaks forward
migration on some HW. Indeed when migrating from an old kernel that
does not feature those commits to a more recent one, destination
qemu detects there are more KVM regs in the input migration stream than
exposed by the destination host and the migration fails with:
"failed to load cpu:cpreg_vmstate_array_len"
This patchs adds the capability to define an array of register indexes
that may exist in the migration incoming stream but may be not
exposed by KVM on the destination.
We provision for extra space in cpreg_vmstate_* arrays during the preload
phase to allow the state to be saved without overflow, in case the
registers only are in the inbound data.
On postload we make sure to ignore them when analyzing potential
mismatch between registers. The actual cpreg array is never altered
meaning those registers are never accessed nor saved.
The array will be populated with a dedicated array property.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v1 -> v2:
- get rid of the enforced/fake terminology
- remove the useless array of fake regs. Only the number of missing
regs is needed
RFC -> v1:
- improve comment in target/arm/cpu.h (Connie)
---
target/arm/cpu.h | 22 ++++++++++++++++++++++
target/arm/machine.c | 27 ++++++++++++++++++---------
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 0a283940be..82fc21dcc5 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1056,6 +1056,15 @@ struct ArchCPU {
uint64_t *hidden_regs;
uint32_t nr_hidden_regs;
+ /*
+ * Registers that are likely to be part of the migration
+ * incoming stream but not exposed on destination. If
+ * their indexes are stored in this array, it is OK to
+ * ignore those registers in the inbound data.
+ */
+ uint64_t *mig_safe_missing_regs;
+ uint32_t nr_mig_safe_missing_regs;
+
/* Uniprocessor system with MP extensions */
bool mp_is_up;
@@ -1207,6 +1216,19 @@ arm_cpu_hidden_reg(ARMCPU *cpu, uint64_t regidx)
return false;
}
+
+static inline bool
+arm_cpu_safe_missing_reg(ARMCPU *cpu, uint64_t regidx)
+{
+ for (int i = 0; i < cpu->nr_mig_safe_missing_regs; i++) {
+ if (regidx == cpu->mig_safe_missing_regs[i]) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
/* Callback functions for the generic timer's timers. */
void arm_gt_ptimer_cb(void *opaque);
void arm_gt_vtimer_cb(void *opaque);
diff --git a/target/arm/machine.c b/target/arm/machine.c
index f06a920aba..f420879134 100644
--- a/target/arm/machine.c
+++ b/target/arm/machine.c
@@ -991,7 +991,8 @@ static int cpu_pre_load(void *opaque)
{
ARMCPU *cpu = opaque;
CPUARMState *env = &cpu->env;
- int arraylen = cpu->cpreg_vmstate_array_len + MAX_CPREG_VMSTATE_ANOMALIES;
+ int arraylen = cpu->cpreg_vmstate_array_len +
+ cpu->nr_mig_safe_missing_regs + MAX_CPREG_VMSTATE_ANOMALIES;
cpu->cpreg_vmstate_indexes = g_renew(uint64_t, cpu->cpreg_vmstate_indexes,
arraylen);
@@ -1058,6 +1059,10 @@ static int cpu_post_load(void *opaque, int version_id)
* entries with the right slots in our own values array.
*/
+ /*
+ * at this point cpu->cpreg_vmstate_array_len was migrated with the
+ * actual length saved on source
+ */
trace_cpu_post_load_len(cpu->cpreg_array_len, cpu->cpreg_vmstate_array_len);
for (; i < cpu->cpreg_array_len && v < cpu->cpreg_vmstate_array_len;) {
trace_cpu_post_load(i, v , cpu->cpreg_indexes[i]);
@@ -1072,10 +1077,12 @@ static int cpu_post_load(void *opaque, int version_id)
}
if (cpu->cpreg_vmstate_indexes[v] < cpu->cpreg_indexes[i]) {
/* register in their list but not ours: those will fail migration */
- trace_cpu_post_load_unexpected(v, cpu->cpreg_vmstate_indexes[v], i);
- if (k < MAX_CPREG_VMSTATE_ANOMALIES) {
- cpu->cpreg_vmstate_unexpected_indexes[k++] =
- cpu->cpreg_vmstate_indexes[v];
+ if (!arm_cpu_safe_missing_reg(cpu, cpu->cpreg_vmstate_indexes[v])) {
+ trace_cpu_post_load_unexpected(v, cpu->cpreg_vmstate_indexes[v], i);
+ if (k < MAX_CPREG_VMSTATE_ANOMALIES) {
+ cpu->cpreg_vmstate_unexpected_indexes[k++] =
+ cpu->cpreg_vmstate_indexes[v];
+ }
}
v++;
continue;
@@ -1101,10 +1108,12 @@ static int cpu_post_load(void *opaque, int version_id)
* still regs in the input stream, continue parsing the vmstate array
*/
for ( ; v < cpu->cpreg_vmstate_array_len; v++) {
- if (k < MAX_CPREG_VMSTATE_ANOMALIES) {
- trace_cpu_post_load_unexpected(v, cpu->cpreg_vmstate_indexes[v], i);
- cpu->cpreg_vmstate_unexpected_indexes[k++] =
- cpu->cpreg_vmstate_indexes[v];
+ if (!arm_cpu_safe_missing_reg(cpu, cpu->cpreg_vmstate_indexes[v])) {
+ if (k < MAX_CPREG_VMSTATE_ANOMALIES) {
+ trace_cpu_post_load_unexpected(v, cpu->cpreg_vmstate_indexes[v], i);
+ cpu->cpreg_vmstate_unexpected_indexes[k++] =
+ cpu->cpreg_vmstate_indexes[v];
+ }
}
}
--
2.51.1
next prev parent reply other threads:[~2025-11-18 16:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 16:07 [PATCH v2 0/8] Mitigation of "failed to load cpu:cpreg_vmstate_array_len" migration failures Eric Auger
2025-11-18 16:07 ` [PATCH v2 1/8] target/arm/machine: Improve traces on register mismatch during migration Eric Auger
2025-11-19 14:51 ` Cornelia Huck
2025-11-18 16:07 ` [PATCH v2 2/8] target/arm/cpu: Allow registers to be hidden Eric Auger
2025-11-19 16:35 ` Cornelia Huck
2025-11-19 17:35 ` Eric Auger
2025-11-18 16:07 ` Eric Auger [this message]
2025-11-18 16:07 ` [PATCH v2 4/8] target/arm/helper: Skip hidden registers Eric Auger
2025-11-19 8:32 ` Eric Auger
2025-11-18 16:07 ` [PATCH v2 5/8] kvm-all: Add the capability to blacklist some KVM regs Eric Auger
2025-11-18 16:07 ` [PATCH v2 6/8] target/arm/cpu: Implement hide_reg callback() Eric Auger
2025-11-18 16:07 ` [PATCH v2 7/8] target/arm/cpu: Expose x-mig-hidden-regs and x-mig-safe-missing-regs properties Eric Auger
2025-11-18 16:07 ` [PATCH v2 8/8] hw/arm/virt: [DO NOT UPSTREAM] Enforce compatibility with older kernels Eric Auger
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=20251118160920.554809-4-eric.auger@redhat.com \
--to=eric.auger@redhat.com \
--cc=cohuck@redhat.com \
--cc=ddutile@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=gshan@redhat.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sebott@redhat.com \
/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).