Linux KVM/arm64 development list
 help / color / mirror / Atom feed
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,
	kvmarm@lists.linux.dev, peter.maydell@linaro.org,
	shaju.abraham@nutanix.com, khushit.shah@nutanix.com,
	yangjinqian1@huawei.com, cohuck@redhat.com,
	richard.henderson@linaro.org, sebott@redhat.com,
	skolothumtho@nvidia.com, philmd@oss.qualcomm.com
Cc: maz@kernel.org, oliver.upton@linux.dev, pbonzini@redhat.com,
	armbru@redhat.com, berrange@redhat.com, abologna@redhat.com,
	jdenemar@redhat.com
Subject: [PATCH v10 03/26] target/arm: Enforce MPIDR into isar.idregs[] storage
Date: Sat, 10 Oct 2026 15:36:07 +0200	[thread overview]
Message-ID: <20261010133725.642498-4-eric.auger@redhat.com> (raw)
In-Reply-To: <20261010133725.642498-1-eric.auger@redhat.com>

At the moment MPIDR_EL1 has no real storage. Instead cpu
mp_affinity field stores the Aff0-Aff2 bits only and the
ID register is reconstructed when needed. There is also
an mp-affinity property used for TCG only.

Keep the mp-affinity property and its associated storage
while making sure the MPIDR_EL1 full register is stored
in cpu->isar.idregs[] as other ID registers.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 target/arm/cpu.h             |  8 +++++++-
 target/arm/cpu-sysregs.h.inc |  1 +
 target/arm/cpu.c             | 17 +++++++++++++++++
 target/arm/helper.c          | 14 +-------------
 target/arm/hvf/hvf.c         |  2 +-
 target/arm/kvm.c             |  1 +
 target/arm/whpx/whpx-all.c   |  2 +-
 7 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index dcdd4eb18e..639be0713e 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1128,7 +1128,13 @@ struct ArchCPU {
     uint32_t reset_sctlr;
     uint64_t pmceid0;
     uint64_t pmceid1;
-    uint64_t mp_affinity; /* MP ID without feature bits */
+    /*
+     * MP ID without feature bits, ie. Aff0..Aff3 only
+     * used to store the corresponding property value for TCG vcpus.
+     * The MPIDR_EL1 value (affinity + feature bits) is stored in a
+     * consistent manner in isar.idregs[MPIDR_EL1_IDX].
+     */
+    uint64_t mp_affinity;
     uint64_t reset_cbar;
     uint32_t reset_auxcr;
     bool reset_hivecs;
diff --git a/target/arm/cpu-sysregs.h.inc b/target/arm/cpu-sysregs.h.inc
index 709dc8fc97..f148f6f565 100644
--- a/target/arm/cpu-sysregs.h.inc
+++ b/target/arm/cpu-sysregs.h.inc
@@ -42,6 +42,7 @@ DEF(ID_PFR0_EL1, 3, 0, 0, 1, 0)
 DEF(ID_PFR1_EL1, 3, 0, 0, 1, 1)
 DEF(ID_PFR2_EL1, 3, 0, 0, 3, 4)
 DEF(MIDR_EL1, 3, 0, 0, 0, 0)
+DEF(MPIDR_EL1, 3, 0, 0, 0, 5)
 DEF(MVFR0_EL1, 3, 0, 0, 3, 0)
 DEF(MVFR1_EL1, 3, 0, 0, 3, 1)
 DEF(MVFR2_EL1, 3, 0, 0, 3, 2)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 2f545482bc..bee74c0f94 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2174,6 +2174,23 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
                                                  ARM_DEFAULT_CPUS_PER_CLUSTER);
     }
 
+    /* Consistently update MPIDR_EL1 in isar.idregs[] by adding feature bits */
+    {
+        uint64_t mpidr = cpu->mp_affinity;
+
+        if (arm_feature(env, ARM_FEATURE_V7MP)) {
+            mpidr |= (1U << 31);
+            /*
+             * Uniprocessor (non-coherent) cores that still implement the MP
+             * extensions set U (bit 30), e.g. Cortex-R5.
+             */
+            if (cpu->mp_is_up) {
+                mpidr |= (1u << 30);
+            }
+        }
+        SET_IDREG(&cpu->isar, MPIDR, mpidr);
+    }
+
     if (cpu->reset_hivecs) {
             cpu->reset_sctlr |= (1 << 13);
     }
diff --git a/target/arm/helper.c b/target/arm/helper.c
index dfd71f1b51..36e8119f79 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -3176,20 +3176,8 @@ static uint64_t midr_read(CPUARMState *env, const ARMCPRegInfo *ri)
 static uint64_t mpidr_read_val(CPUARMState *env)
 {
     ARMCPU *cpu = env_archcpu(env);
-    uint64_t mpidr = cpu->mp_affinity;
 
-    if (arm_feature(env, ARM_FEATURE_V7MP)) {
-        mpidr |= (1U << 31);
-        /*
-         * Cores which are uniprocessor (non-coherent)
-         * but still implement the MP extensions set
-         * bit 30. (For instance, Cortex-R5).
-         */
-        if (cpu->mp_is_up) {
-            mpidr |= (1u << 30);
-        }
-    }
-    return mpidr;
+    return GET_IDREG(&cpu->isar, MPIDR);
 }
 
 static uint64_t mpidr_read(CPUARMState *env, const ARMCPRegInfo *ri)
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index f9f3d22014..4b947e9ba5 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1476,7 +1476,7 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     assert_hvf_ok(ret);
 
     ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_MPIDR_EL1,
-                              arm_cpu->mp_affinity);
+                              GET_IDREG(&arm_cpu->isar, MPIDR));
     assert_hvf_ok(ret);
 
     pfr = GET_IDREG(&arm_cpu->isar, ID_AA64PFR0);
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 3d905f8565..9d68801c26 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -2096,6 +2096,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
     if (ret) {
         return ret;
     }
+    SET_IDREG(&cpu->isar, MPIDR, mpidr);
     cpu->mp_affinity = mpidr & ARM64_AFFINITY_MASK;
 
     return kvm_arm_init_cpreg_list(cpu);
diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c
index 18009d6c8d..024d18df04 100644
--- a/target/arm/whpx/whpx-all.c
+++ b/target/arm/whpx/whpx-all.c
@@ -842,7 +842,7 @@ int whpx_init_vcpu(CPUState *cpu)
 
     clean_whv_register_value(&val);
 
-    val.Reg64 = deposit64(arm_cpu->mp_affinity, 31, 1, 1 /* RES1 */);
+    val.Reg64 = GET_IDREG(&arm_cpu->isar, MPIDR);
     whpx_set_reg(cpu, WHvArm64RegisterMpidrEl1, val);
 
     clamp_id_aa64mmfr0_parange_to_ipa_size(&arm_cpu->isar);
-- 
2.53.0


  parent reply	other threads:[~2026-10-10 13:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10 13:36 [PATCH v10 00/26] kvm/arm: Introduce a customizable aarch64 KVM host model Eric Auger
2026-10-10 13:36 ` [PATCH v10 01/26] target/arm: Move REVIDR into isar.idregs[] storage Eric Auger
2026-10-22 10:28   ` Peter Maydell
2026-10-10 13:36 ` [PATCH v10 02/26] target/arm: Move MIDR " Eric Auger
2026-10-22 10:28   ` Peter Maydell
2026-10-10 13:36 ` Eric Auger [this message]
2026-10-22 10:28   ` [PATCH v10 03/26] target/arm: Enforce MPIDR " Peter Maydell
2026-10-10 13:36 ` [PATCH v10 04/26] target/arm/cpu-sysregs.h.inc: Update with automatic generation Eric Auger
2026-10-10 13:36 ` [PATCH v10 05/26] arm/cpu: Add infra to handle generated ID register definitions Eric Auger
2026-10-10 13:36 ` [PATCH v10 06/26] target/arm/cpu-idregs.h.inc: Generate with script Eric Auger
2026-10-10 13:36 ` [PATCH v10 07/26] target/arm/cpu-idregs.h.inc: Generate enum values Eric Auger
2026-10-10 13:36 ` [PATCH v10 08/26] target/arm/cpu-idregs.h.inc: Generate reserved fields Eric Auger
2026-10-10 13:36 ` [PATCH v10 09/26] target/arm/cpu_idregs: Generate tables for Arm64 ID registers and fields Eric Auger
2026-10-10 13:36 ` [PATCH v10 10/26] target/arm/kvm: Retrieve writable ID reg map Eric Auger
2026-10-10 13:36 ` [PATCH v10 11/26] hw/arm/virt: Make sure virt_get_caches() keeps on reading CLIDR_EL1 as 0 Eric Auger
2026-10-10 13:36 ` [PATCH v10 12/26] arm/kvm: Initialize isar.idregs[] with all writable host ID regs Eric Auger
2026-10-12  8:25   ` Khushit Shah
2026-10-10 13:36 ` [PATCH v10 13/26] target/arm/cpu64: Add properties for writable IDReg fields Eric Auger
2026-10-12  6:17   ` Khushit Shah
2026-10-10 13:36 ` [PATCH v10 14/26] target/arm/kvm: Implement SYSREG property setter and getter Eric Auger
2026-10-10 13:36 ` [PATCH v10 15/26] target/arm/kvm: Let kvm_arm_init_cpreg_list propagate an error handle Eric Auger
2026-10-10 13:36 ` [PATCH v10 16/26] target/arm/kvm: Pass an Error handle to kvm_arch_init_vcpu Eric Auger
2026-10-10 13:36 ` [PATCH v10 17/26] target/arm/kvm: Introduce kvm_arm_override_idreg_field helper Eric Auger
2026-10-10 13:36 ` [PATCH v10 18/26] target/arm/cpu64: Introduce arm_cpu_apply_sysreg_props Eric Auger
2026-10-10 13:36 ` [PATCH v10 19/26] target/arm/kvm: Apply SYSREG props Eric Auger
2026-10-10 13:36 ` [PATCH v10 20/26] target/arm/kvm: Add consistency checking for " Eric Auger
2026-10-10 13:36 ` [PATCH v10 21/26] target/arm/cpu64: Add helper to test SYSREG props against a scratch vcpu Eric Auger
2026-10-10 13:36 ` [PATCH v10 22/26] target/arm/kvm: Add an error handle to kvm_arm_create_scratch_host_vcpu Eric Auger
2026-10-10 13:36 ` [PATCH v10 23/26] target/arm/kvm: Introduce kvm_arm_vcpu_prepare_init_features helper Eric Auger
2026-10-10 13:36 ` [PATCH v10 24/26] target/arm/kvm: Introduce kvm_arm_create_init_scratch_vcpu() Eric Auger
2026-10-10 13:36 ` [PATCH v10 25/26] arm-qmp-cmds: introspection for ID register props Eric Auger
2026-10-10 13:36 ` [PATCH v10 26/26] arm/cpu-features: Document ID reg properties Eric Auger
2026-10-12  4:38 ` [PATCH v10 00/26] kvm/arm: Introduce a customizable aarch64 KVM host model Khushit Shah
2026-10-12  5:30   ` Eric Auger
2026-10-23 11:44 ` Peter Maydell
2026-10-26 13:55   ` 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=20261010133725.642498-4-eric.auger@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=abologna@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=jdenemar@redhat.com \
    --cc=khushit.shah@nutanix.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@oss.qualcomm.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox