Skip to contentSkip to conversation

target/arm: Implement Cortex Neoverse-V1

PATCH In review Peter Maydell 5 participants 12 messages Jul 4, 2023 – Jul 6, 2023

lore
Share & tools
lore
#0 lore raw

cover target/arm: Implement Cortex Neoverse-V1

This patchset implements the Cortex Neoverse-V1 CPU type, as a representative Armv8.3 (+ some extras from 8.4) CPU matching real hardware. The main thing we were waiting for to be able to define this was FEAT_LSE2, and that is now supported.

There are a few things the real hardware implements that QEMU does not yet, which patch 1 ensures we don't advertise to the guest:

* FEAT_TRF (Self-hosted Trace Extension)
* Trace Macrocell system register access
* Memory mapped trace
* FEAT_AMU (Activity Monitors Extension)
* FEAT_MPAM (Memory Partitioning and Monitoring Extension)
* FEAT_NV (Nested Virtualization)

Most of these, like FEAT_SPE which we were already suppressing, are "introspection/trace" type features which QEMU is unlikely to ever implement. The odd-one-out here is FEAT_NV -- we could implement that and at some point we probably will.

Patch 2 then implements the CPU itself.

thanks
-- PMM

Peter Maydell (2):
target/arm: Suppress more TCG unimplemented features in ID registers target/arm: Define neoverse-v1

 docs/system/arm/virt.rst |   1 +
 hw/arm/sbsa-ref.c        |   1 +
 hw/arm/virt.c            |   1 +
 target/arm/cpu.c         |  33 ++++++++--
 target/arm/tcg/cpu64.c   | 128 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 160 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 target/arm: Suppress more TCG unimplemented features in ID registers

We already squash the ID register field for FEAT_SPE (the Statistical Profiling Extension) because TCG does not implement it and if we advertise it to the guest the guest will crash trying to look at non-existent system registers. Do the same for some other features which a real hardware Neoverse-V1 implements but which TCG doesn't:
* FEAT_TRF (Self-hosted Trace Extension)
* Trace Macrocell system register access
* Memory mapped trace
* FEAT_AMU (Activity Monitors Extension)
* FEAT_MPAM (Memory Partitioning and Monitoring Extension)
* FEAT_NV (Nested Virtualization)

Most of these, like FEAT_SPE, are "introspection/trace" type features which QEMU is unlikely to ever implement. The odd-one-out here is FEAT_NV -- we could implement that and at some point we probably will.

---
 target/arm/cpu.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)
target/arm/cpu.c +29 -4
index a1e77698ba2..7eb7e909097 100644
@@ -2048,13 +2048,38 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
 
     if (tcg_enabled()) {
         /*
-         * Don't report the Statistical Profiling Extension in the ID
-         * registers, because TCG doesn't implement it yet (not even a
-         * minimal stub version) and guests will fall over when they
-         * try to access the non-existent system registers for it.
+         * Don't report some architectural features in the ID registers
+         * where TCG does not yet implement it (not even a minimal
+         * stub version). This avoids guests falling over when they
+         * try to access the non-existent system registers for them.
          */
+        /* FEAT_SPE (Statistical Profiling Extension) */
         cpu->isar.id_aa64dfr0 =
             FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, PMSVER, 0);
+        /* FEAT_TRF (Self-hosted Trace Extension) */
+        cpu->isar.id_aa64dfr0 =
+            FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEFILT, 0);
+        cpu->isar.id_dfr0 =
+            FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, TRACEFILT, 0);
+        /* Trace Macrocell system register access */
+        cpu->isar.id_aa64dfr0 =
+            FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEVER, 0);
+        cpu->isar.id_dfr0 =
+            FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, COPTRC, 0);
+        /* Memory mapped trace */
+        cpu->isar.id_dfr0 =
+            FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, MMAPTRC, 0);
+        /* FEAT_AMU (Activity Monitors Extension) */
+        cpu->isar.id_aa64pfr0 =
+            FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, AMU, 0);
+        cpu->isar.id_pfr0 =
+            FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, AMU, 0);
+        /* FEAT_MPAM (Memory Partitioning and Monitoring Extension) */
+        cpu->isar.id_aa64pfr0 =
+            FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, MPAM, 0);
+        /* FEAT_NV (Nested Virtualization) */
+        cpu->isar.id_aa64mmfr2 =
+            FIELD_DP64(cpu->isar.id_aa64mmfr2, ID_AA64MMFR2, NV, 0);
     }
 
     /* MPU can be configured out of a PMSA CPU either by setting has-mpu
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] target/arm: Suppress more TCG unimplemented features in ID registers

Quoted 12 lines · Peter Maydell

We already squash the ID register field for FEAT_SPE (the Statistical Profiling Extension) because TCG does not implement it and if we advertise it to the guest the guest will crash trying to look at non-existent system registers. Do the same for some other features which a real hardware Neoverse-V1 implements but which TCG doesn't:
* FEAT_TRF (Self-hosted Trace Extension)
* Trace Macrocell system register access
* Memory mapped trace
* FEAT_AMU (Activity Monitors Extension)
* FEAT_MPAM (Memory Partitioning and Monitoring Extension)
* FEAT_NV (Nested Virtualization)

Quoted 6 lines

Most of these, like FEAT_SPE, are "introspection/trace" type features which QEMU is unlikely to ever implement. The odd-one-out here is FEAT_NV -- we could implement that and at some point we probably will.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] target/arm: Suppress more TCG unimplemented features in ID registers

In reply to Peter Maydell
Quoted 17 lines · Peter Maydell

We already squash the ID register field for FEAT_SPE (the Statistical Profiling Extension) because TCG does not implement it and if we advertise it to the guest the guest will crash trying to look at non-existent system registers. Do the same for some other features which a real hardware Neoverse-V1 implements but which TCG doesn't:
* FEAT_TRF (Self-hosted Trace Extension)
* Trace Macrocell system register access
* Memory mapped trace
* FEAT_AMU (Activity Monitors Extension)
* FEAT_MPAM (Memory Partitioning and Monitoring Extension)
* FEAT_NV (Nested Virtualization)

Most of these, like FEAT_SPE, are "introspection/trace" type features which QEMU is unlikely to ever implement. The odd-one-out here is FEAT_NV -- we could implement that and at some point we probably will.

Quoted 4 lines
---
  target/arm/cpu.c | 33 +++++++++++++++++++++++++++++----
  1 file changed, 29 insertions(+), 4 deletions(-)

r~

#4 lore raw

PATCH 2/2 target/arm: Define neoverse-v1

In reply to Peter Maydell

Now that we have implemented support for FEAT_LSE2, we can define a CPU model for the Neoverse-V1, and enable it for the virt and sbsa-ref boards.

---
If you're checking the values against the TRM, note that the summary tables differ from the register description in the TRM for ID_AA64DFR0_EL1, ID_AA64ZFR0_EL1 and ID_PFR0_EL1: we trust the versions in the register descriptions. Also the MIDR value in the r1p2 TRM isn't updated from r1p1. The CCSIDR_EL1 values in the TRM unfortunately seem to be wrong:
the comment in the patch describes how I've calculated the values used here.

I've stuck with the existing approach for aarch64_add_*_properties in the interests of getting this in before softfreeze, though there does seem like there ought to be a workable refactoring there somewhere.

---
 docs/system/arm/virt.rst |   1 +
 hw/arm/sbsa-ref.c        |   1 +
 hw/arm/virt.c            |   1 +
 target/arm/tcg/cpu64.c   | 128 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 131 insertions(+)
docs/system/arm/virt.rst +1 -0
index 1cab33f02e3..51cdac68410 100644
@@ -61,6 +61,7 @@ Supported guest CPU types:
 - ``a64fx`` (64-bit)
 - ``host`` (with KVM only)
 - ``neoverse-n1`` (64-bit)
+- ``neoverse-v1`` (64-bit)
 - ``max`` (same as ``host`` for KVM; best possible emulation with TCG)
 
 Note that the default is ``cortex-a15``, so for an AArch64 guest you must
hw/arm/sbsa-ref.c +1 -0
index 0639f97dd5f..f0857198983 100644
@@ -150,6 +150,7 @@ static const char * const valid_cpus[] = {
     ARM_CPU_TYPE_NAME("cortex-a57"),
     ARM_CPU_TYPE_NAME("cortex-a72"),
     ARM_CPU_TYPE_NAME("neoverse-n1"),
+    ARM_CPU_TYPE_NAME("neoverse-v1"),
     ARM_CPU_TYPE_NAME("max"),
 };
 
hw/arm/virt.c +1 -0
index 9b9f7d9c687..20b134fe477 100644
@@ -213,6 +213,7 @@ static const char *valid_cpus[] = {
     ARM_CPU_TYPE_NAME("cortex-a76"),
     ARM_CPU_TYPE_NAME("a64fx"),
     ARM_CPU_TYPE_NAME("neoverse-n1"),
+    ARM_CPU_TYPE_NAME("neoverse-v1"),
 #endif
     ARM_CPU_TYPE_NAME("cortex-a53"),
     ARM_CPU_TYPE_NAME("cortex-a57"),
target/arm/tcg/cpu64.c +128 -0

146 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] target/arm: Define neoverse-v1

Quoted 5 lines · Peter Maydell

Now that we have implemented support for FEAT_LSE2, we can define a CPU model for the Neoverse-V1, and enable it for the virt and sbsa-ref boards.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] target/arm: Define neoverse-v1

In reply to Peter Maydell
Quoted 8 lines · Peter Maydell

If you're checking the values against the TRM, note that the summary tables differ from the register description in the TRM for ID_AA64DFR0_EL1, ID_AA64ZFR0_EL1 and ID_PFR0_EL1: we trust the versions in the register descriptions. Also the MIDR value in the r1p2 TRM isn't updated from r1p1. The CCSIDR_EL1 values in the TRM unfortunately seem to be wrong:
the comment in the patch describes how I've calculated the values used here.

...

Quoted 1 line

+ cpu->isar.id_aa64mmfr2 = 0x0000000000001011ull;

I see 0x0220011102101011, not in your list of exceptions above.

Otherwise,

r~

#7 lore raw

Re: [PATCH 2/2] target/arm: Define neoverse-v1

Quoted 10 lines · Richard Henderson
Quoted 8 lines · Peter Maydell

If you're checking the values against the TRM, note that the summary tables differ from the register description in the TRM for ID_AA64DFR0_EL1, ID_AA64ZFR0_EL1 and ID_PFR0_EL1: we trust the versions in the register descriptions. Also the MIDR value in the r1p2 TRM isn't updated from r1p1. The CCSIDR_EL1 values in the TRM unfortunately seem to be wrong:
the comment in the patch describes how I've calculated the values used here.

Quoted 4 lines

...

Quoted 1 line

+ cpu->isar.id_aa64mmfr2 = 0x0000000000001011ull;

I see 0x0220011102101011, not in your list of exceptions above.

Good catch -- I must have cut-and-pasted the neoverse-n1 code and then forgotten to update that value in it.

-- PMM

Tested-by on the v1 series
#8 lore raw
In reply to Peter Maydell

W dniu 4.07.2023 o 15:06, Peter Maydell pisze:

Quoted 4 lines

This patchset implements the Cortex Neoverse-V1 CPU type, as a representative Armv8.3 (+ some extras from 8.4) CPU matching real hardware. The main thing we were waiting for to be able to define this was FEAT_LSE2, and that is now supported.

Now I can add "reach SBSA level 4" to todo list as it requires v8.3 cpu (I do not count 'max' cpu type).

#9 lore raw
Quoted 8 lines · Marcin Juszkiewicz

W dniu 4.07.2023 o 15:06, Peter Maydell pisze:

Quoted 4 lines

This patchset implements the Cortex Neoverse-V1 CPU type, as a representative Armv8.3 (+ some extras from 8.4) CPU matching real hardware.  The main thing we were waiting for to be able to define this was FEAT_LSE2, and that is now supported.

Now I can add "reach SBSA level 4" to todo list as it requires v8.3 cpu (I do not count 'max' cpu type).

Do we need to introduce machine variants, such sbsa-lvl3-ref and sbsa-lvl4-ref? Or simply sbsa-level3/sbsa-level4?

#10 lore raw

W dniu 4.07.2023 o 16:54, Philippe Mathieu-Daudé pisze:

Quoted 8 lines · Marcin Juszkiewicz
Quoted 7 lines

W dniu 4.07.2023 o 15:06, Peter Maydell pisze:

Quoted 4 lines

This patchset implements the Cortex Neoverse-V1 CPU type, as a representative Armv8.3 (+ some extras from 8.4) CPU matching real hardware.  The main thing we were waiting for to be able to define this was FEAT_LSE2, and that is now supported.

Quoted 4 lines
Quoted 1 line

Now I can add "reach SBSA level 4" to todo list as it requires v8.3 cpu (I do not count 'max' cpu type).

Do we need to introduce machine variants, such sbsa-lvl3-ref and sbsa-lvl4-ref? Or simply sbsa-level3/sbsa-level4?

No such combinations. The plan for sbsa-ref is to have only one platform.

Version of platform is exported in DeviceTree already. TF-A reads it and exports via SMC call to EDK2. What changes between versions is present in documentation.

#11 lore raw
Quoted 9 lines · Marcin Juszkiewicz

W dniu 4.07.2023 o 16:54, Philippe Mathieu-Daudé pisze:

Quoted 8 lines · Marcin Juszkiewicz
Quoted 7 lines

W dniu 4.07.2023 o 15:06, Peter Maydell pisze:

Quoted 4 lines

This patchset implements the Cortex Neoverse-V1 CPU type, as a representative Armv8.3 (+ some extras from 8.4) CPU matching real hardware.  The main thing we were waiting for to be able to define this was FEAT_LSE2, and that is now supported.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Now I can add "reach SBSA level 4" to todo list as it requires v8.3 cpu (I do not count 'max' cpu type).

Do we need to introduce machine variants, such sbsa-lvl3-ref and sbsa-lvl4-ref? Or simply sbsa-level3/sbsa-level4?

No such combinations. The plan for sbsa-ref is to have only one platform.

Version of platform is exported in DeviceTree already. TF-A reads it and exports via SMC call to EDK2. What changes between versions is present in documentation.

Great! I like simplicity :)