From: Eric Auger <eric.auger@redhat.com>
To: Khushit Shah <khushit.shah@nutanix.com>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org,
kvmarm@lists.linux.dev
Cc: cohuck@redhat.com, peter.maydell@linaro.org,
richard.henderson@linaro.org, maz@kernel.org,
oliver.upton@linux.dev, berrange@redhat.com, abologna@redhat.com,
jdenemar@redhat.com, gshan@redhat.com, skolothumtho@nvidia.com,
sebott@redhat.com, armbru@redhat.com, philmd@linaro.org,
yangjinqian1@huawei.com, shaju.abraham@nutanix.com,
mark.caveayland@nutanix.com, ping@khushitshah.com,
sandesh.patel@nutanix.com
Subject: Re: [RFC PATCH v4 08/25] target/arm/kvm: handle writeback for special ID register fields
Date: Thu, 24 Sep 2026 11:57:16 +0200 [thread overview]
Message-ID: <aabcb61b-8341-423f-b113-e7ab2b34c2ac@redhat.com> (raw)
In-Reply-To: <20260921123249.1708067-9-khushit.shah@nutanix.com>
On 9/21/26 2:32 PM, Khushit Shah wrote:
> Some fields should not be written back to KVM for various reasons:
> - ID_AA64PFR0_EL1.GIC / ID_PFR1_EL1.GIC are fabricated by KVM based on
> the gic-version property.
> - KVM does not allow writing 0 to ID_DFR0_EL1.CopDbg, which breaks
> booting an AArch64-only guest on a host that also supports AArch32.
> - ID_DFR0_EL1.PerfMon is populated by KVM even for AArch64-only guests
> but is not writable there.
> - MPIDR_EL1 is managed by KVM based on vCPU index.
> - Hold off writing back CLIDR_EL1 until we properly support exposing
> cache topology to a KVM guest.
>
> Signed-off-by: Khushit Shah <khushit.shah@nutanix.com>
> ---
> target/arm/cpu-idregs.c | 6 ++++++
> target/arm/cpu-idregs.h | 2 ++
> target/arm/kvm.c | 40 +++++++++++++++++++++++++++++++++++++++-
> 3 files changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/target/arm/cpu-idregs.c b/target/arm/cpu-idregs.c
> index d58b8ed063..1f7ebfe9bb 100644
> --- a/target/arm/cpu-idregs.c
> +++ b/target/arm/cpu-idregs.c
> @@ -107,3 +107,9 @@ bool arm_field_is_writable(const ARM64SysRegField *field)
> return (arm64_id_regs[field->index].writable_mask & field_mask)
> == field_mask;
> }
> +
> +bool field_matches(const ARM64SysRegField *field, ARMIDRegisterIdx index,
> + const char *name)
> +{
> + return field->index == index && !strcmp(field->name, name);
> +}
> diff --git a/target/arm/cpu-idregs.h b/target/arm/cpu-idregs.h
> index aab1a79db1..8ef3f9350e 100644
> --- a/target/arm/cpu-idregs.h
> +++ b/target/arm/cpu-idregs.h
> @@ -35,4 +35,6 @@ extern ARM64SysReg arm64_id_regs[NUM_ID_IDX];
>
> uint64_t arm_get_field_mask(const ARM64SysRegField *field);
> bool arm_field_is_writable(const ARM64SysRegField *field);
> +bool field_matches(const ARM64SysRegField *field, ARMIDRegisterIdx index,
> + const char *name);
> #endif
> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
> index 2d94b3a884..70d9a07580 100644
> --- a/target/arm/kvm.c
> +++ b/target/arm/kvm.c
> @@ -1317,10 +1317,40 @@ bool kvm_arm_cpu_post_load(ARMCPU *cpu)
> return true;
> }
>
> +static bool arm_field_skip_writeback_always(const ARM64SysRegField *field)
> +{
> + /*
> + * GIC is controlled by the gic-version property and fabricated by KVM
> + * when the vGIC device is created, so a named CPU model must not touch
> + * it. KVM also rejects writing 0 to ID_DFR0_EL1.CopDbg, which breaks
> + * booting a model that lacks AArch32 support on a host that supports
> + * it. MPIDR_EL1 is managed by KVM based on vCPU index, skip writing it
> + * back. Similarly, skip writing back CLIDR_EL1 till we properly
> + * support exposing cache for KVM guest.
> + */
> + return field_matches(field, ID_AA64PFR0_EL1_IDX, "GIC")
> + || field_matches(field, ID_PFR1_EL1_IDX, "GIC")
> + || field_matches(field, ID_DFR0_EL1_IDX, "CopDbg")
> + || field->index == MPIDR_EL1_IDX
> + || field->index == CLIDR_EL1_IDX;
what does happen for SMIDR_EL1 and GMID_EL1 whose value could not be
initialized from host. The setter for any of their field shall fail.
> +}
> +
> +static bool
> +arm_field_skip_writeback_if_not_writable(const ARM64SysRegField *field)
> +{
> + /*
> + * KVM populates ID_DFR0_EL1.PerfMon even for AArch64-only guests but
> + * does not expose it as writable there, so skip it when it is not
> + * writable.
> + */
> + return field_matches(field, ID_DFR0_EL1_IDX, "PerfMon");
> +}
> +
> /*
> * Copy writable ID reg fields from isar.idregs[] into the KVM cpreg list,
> * so the subsequent write_list_to_kvmstate() pushes them to KVM.
> - * Only writable fields are copied.
> + * Only writable fields are copied; fields that must not be written back
> + * (see arm_field_skip_writeback_*) are skipped.
> * Returns -1 if any vCPU's ID reg value differs from the host value and the
> * field is not writable.
> */
> @@ -1357,6 +1387,14 @@ static int kvm_arm_write_idregs_to_cpreg_list(ARMCPU *cpu)
> continue;
> }
>
> + if (arm_field_skip_writeback_always(field) ||
> + (!arm_field_is_writable(field) &&
> + arm_field_skip_writeback_if_not_writable(field))) {
> + /* Never write this field back; keep KVM's value. */
> + writable_mask &= ~field_mask;
> + continue;
> + }
> +
> if (!arm_field_is_writable(field)) {
> error_report("%s.%s is not writable: host=0x%" PRIx64
> ", requested=0x%" PRIx64,
v9 has changed the way new field values are stored. writable field props
and non writable field props could have different setters. A non
writable field setter just needs to check the new value is the same as
the current host value. No need to record the new value in the hashtable
for further commitment.
Eric
next prev parent reply other threads:[~2026-09-24 9:58 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 12:32 [RFC PATCH v4 00/25] named CPU models for Arm64 on KVM Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 01/25] target/arm: expose SYSREG_ props for REVIDR_EL1 and AIDR_EL1 Khushit Shah
2026-09-23 16:22 ` Eric Auger
2026-09-29 12:54 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 02/25] target/arm: expose all non-res ID reg fields as properties Khushit Shah
2026-09-23 16:37 ` Eric Auger
2026-09-24 6:46 ` Eric Auger
2026-09-29 12:55 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 03/25] target/arm: move SYSREG_ prop infra to cpu64.c Khushit Shah
2026-09-24 6:54 ` Eric Auger
2026-09-29 12:56 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 04/25] target/arm/kvm: enable writable implementation ID registers Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 05/25] target/arm/kvm: read all ID registers from KVM Khushit Shah
2026-09-24 7:52 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 06/25] target/arm/kvm: handle special ID registers when reading " Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 07/25] target/arm/kvm: process ID register writeback per field Khushit Shah
2026-09-24 9:41 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 08/25] target/arm/kvm: handle writeback for special ID register fields Khushit Shah
2026-09-24 9:57 ` Eric Auger [this message]
2026-09-24 10:21 ` Khushit Shah
2026-09-24 11:47 ` Eric Auger
2026-09-29 13:09 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 09/25] target/arm: introduce named CPU model infrastructure Khushit Shah
2026-09-24 13:35 ` Eric Auger
2026-09-29 13:40 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 10/25] target/arm: fix SVE and PAuth finalize for named CPU models Khushit Shah
2026-10-15 13:01 ` Eric Auger
2026-10-16 7:34 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 11/25] target/arm: disable PMU support " Khushit Shah
2026-10-15 13:12 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 12/25] target/arm: add arm-v9.0-a-v1 named CPU model Khushit Shah
2026-10-16 12:07 ` Eric Auger
2026-10-16 12:24 ` Peter Maydell
2026-09-21 12:32 ` [RFC PATCH v4 13/25] target/arm: add neoverse-v2-v1 " Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 14/25] target/arm: add neoverse-v2-v2 " Khushit Shah
2026-10-15 12:13 ` Eric Auger
2026-10-15 12:22 ` Peter Maydell
2026-10-15 14:05 ` Eric Auger
2026-10-16 6:48 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 15/25] target/arm: add graviton4-v1 " Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 16/25] target/arm: add grace-v1 " Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 17/25] target/arm: fail named CPU models on unknown non-zero feature ID regs Khushit Shah
2026-10-16 12:27 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 18/25] target/arm: add cpu-models-stub.c Khushit Shah
2026-09-29 15:00 ` Philippe Mathieu-Daudé
2026-09-29 15:37 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 19/25] target/arm/qmp: allow named CPU models on cpu-model-expansion Khushit Shah
2026-10-16 12:32 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 20/25] target/arm/kvm: compute host-supported values for ID register fields Khushit Shah
2026-10-16 13:10 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 21/25] target/arm: report 0 as supported for ID fields gated by vCPU init flags Khushit Shah
2026-10-16 13:12 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 22/25] target/arm/kvm: add kvm_arm_get_host_isar helper Khushit Shah
2026-09-29 15:02 ` Philippe Mathieu-Daudé
2026-09-21 12:32 ` [RFC PATCH v4 23/25] qmp: add query-cpu-props-info command Khushit Shah
2026-10-15 14:20 ` Eric Auger
2026-10-16 6:57 ` Khushit Shah
2026-10-16 7:18 ` Eric Auger
2026-10-16 7:28 ` Khushit Shah
2026-09-21 12:32 ` [RFC PATCH v4 24/25] target/arm/qmp: implement query-cpu-props-info for KVM Khushit Shah
2026-10-16 13:21 ` Eric Auger
2026-10-16 13:23 ` Eric Auger
2026-09-21 12:32 ` [RFC PATCH v4 25/25] target/arm/qmp: hook blockers in query-cpu-definitions Khushit Shah
2026-10-16 13:54 ` Eric Auger
2026-09-29 15:09 ` [RFC PATCH v4 00/25] named CPU models for Arm64 on KVM Philippe Mathieu-Daudé
2026-09-29 16:38 ` Khushit Shah
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=aabcb61b-8341-423f-b113-e7ab2b34c2ac@redhat.com \
--to=eric.auger@redhat.com \
--cc=abologna@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=cohuck@redhat.com \
--cc=gshan@redhat.com \
--cc=jdenemar@redhat.com \
--cc=khushit.shah@nutanix.com \
--cc=kvmarm@lists.linux.dev \
--cc=mark.caveayland@nutanix.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=ping@khushitshah.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sandesh.patel@nutanix.com \
--cc=sebott@redhat.com \
--cc=shaju.abraham@nutanix.com \
--cc=skolothumtho@nvidia.com \
--cc=yangjinqian1@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.