Skip to contentSkip to conversation

target/arm: Flag PMCNTENCLR with ARM_CP_NO_RAW

PATCH In review Akihiko Odaki 2 participants 8 messages Mar 17, 2025 – Mar 18, 2025

lore
Share & tools
lore
#0 lore raw

cover target/arm: Flag PMCNTENCLR with ARM_CP_NO_RAW

Supersedes: <[email protected]> ("[PATCH v2] target/arm: Define raw write for PMU CLR registers")

A normal write to PMCNTENCLR clears written bits so it is not appropriate for writing a raw value. This kind of situation is usually handled by setting a raw write function, but flag the register with ARM_CP_NO_RAW instead to workaround a problem with KVM.

KVM also has the same problem with PMINTENSET so add a comment to note that. This register is already flagged with ARM_CP_NO_RAW.

---
Akihiko Odaki (4):
target/arm: Explicitly set ARM_CP_NO_GDB target/arm: Do not imply ARM_CP_NO_GDB target/arm: Expose PMINTENCLR to GDB target/arm: Flag PMCNTENCLR with ARM_CP_NO_RAW

 target/arm/cpregs.h        |   8 +-
 hw/intc/arm_gicv3_cpuif.c  | 100 +++++++++---------
 hw/intc/arm_gicv3_kvm.c    |   2 +-
 target/arm/debug_helper.c  |   2 +-
 target/arm/gdbstub.c       |   2 +-
 target/arm/helper.c        | 229 +++++++++++++++++++++++-----------------
 target/arm/tcg/tlb-insns.c | 256 +++++++++++++++++++++++++--------------------
 7 files changed, 336 insertions(+), 263 deletions(-)

---
base-commit: 825b96dbcee23d134b691fc75618b59c5f53da32
change-id: 20250314-raw-198885f67b73

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw

PATCH 1/4 target/arm: Explicitly set ARM_CP_NO_GDB

Explicitly set ARM_CP_NO_GDB when ARM_CP_NO_RAW is set.

---
 hw/intc/arm_gicv3_cpuif.c  | 100 +++++++++---------
 hw/intc/arm_gicv3_kvm.c    |   2 +-
 target/arm/debug_helper.c  |   2 +-
 target/arm/helper.c        | 219 +++++++++++++++++++++-----------------
 target/arm/tcg/tlb-insns.c | 256 +++++++++++++++++++++++++--------------------
 5 files changed, 321 insertions(+), 258 deletions(-)
hw/intc/arm_gicv3_cpuif.c +50 -50
index 7f1d071c198b..e02854204d25 100644
@@ -2432,7 +2432,7 @@ static void icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)
 static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     { .name = "ICC_PMR_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 4, .crm = 6, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irqfiq_access,
       .readfn = icc_pmr_read,
       .writefn = icc_pmr_write,
@@ -2444,32 +2444,32 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     },
     { .name = "ICC_IAR0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_R, .accessfn = gicv3_fiq_access,
       .readfn = icc_iar0_read,
     },
     { .name = "ICC_EOIR0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_fiq_access,
       .writefn = icc_eoir_write,
     },
     { .name = "ICC_HPPIR0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 2,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_R, .accessfn = gicv3_fiq_access,
       .readfn = icc_hppir0_read,
     },
     { .name = "ICC_BPR0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_fiq_access,
       .readfn = icc_bpr_read,
       .writefn = icc_bpr_write,
     },
     { .name = "ICC_AP0R0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 4,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_fiq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
@@ -2477,81 +2477,81 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     /* All the ICC_AP1R*_EL1 registers are banked */
     { .name = "ICC_AP1R0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 9, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
     },
     { .name = "ICC_DIR_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_dir_access,
       .writefn = icc_dir_write,
     },
     { .name = "ICC_RPR_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_R, .accessfn = gicv3_irqfiq_access,
       .readfn = icc_rpr_read,
     },
     { .name = "ICC_SGI1R_EL1", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 5,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_sgi_access,
       .writefn = icc_sgi1r_write,
     },
     { .name = "ICC_SGI1R",
       .cp = 15, .opc1 = 0, .crm = 12,
-      .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_sgi_access,
       .writefn = icc_sgi1r_write,
     },
     { .name = "ICC_ASGI1R_EL1", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 6,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_sgi_access,
       .writefn = icc_asgi1r_write,
     },
     { .name = "ICC_ASGI1R",
       .cp = 15, .opc1 = 1, .crm = 12,
-      .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_sgi_access,
       .writefn = icc_asgi1r_write,
     },
     { .name = "ICC_SGI0R_EL1", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 11, .opc2 = 7,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_sgi_access,
       .writefn = icc_sgi0r_write,
     },
     { .name = "ICC_SGI0R",
       .cp = 15, .opc1 = 2, .crm = 12,
-      .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_64BIT | ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_sgi_access,
       .writefn = icc_sgi0r_write,
     },
     { .name = "ICC_IAR1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_R, .accessfn = gicv3_irq_access,
       .readfn = icc_iar1_read,
     },
     { .name = "ICC_EOIR1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_W, .accessfn = gicv3_irq_access,
       .writefn = icc_eoir_write,
     },
     { .name = "ICC_HPPIR1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 2,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_R, .accessfn = gicv3_irq_access,
       .readfn = icc_hppir1_read,
     },
     /* This register is banked */
     { .name = "ICC_BPR1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irq_access,
       .readfn = icc_bpr_read,
       .writefn = icc_bpr_write,
@@ -2559,14 +2559,14 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     /* This register is banked */
     { .name = "ICC_CTLR_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 4,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irqfiq_access,
       .readfn = icc_ctlr_el1_read,
       .writefn = icc_ctlr_el1_write,
     },
     { .name = "ICC_SRE_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 5,
-      .type = ARM_CP_NO_RAW | ARM_CP_CONST,
+      .type = ARM_CP_NO_RAW | ARM_CP_NO_GDB | ARM_CP_CONST,
       .access = PL1_RW,
       /* We don't support IRQ/FIQ bypass and system registers are
        * always enabled, so all our bits are RAZ/WI or RAO/WI.
@@ -2577,7 +2577,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     },
     { .name = "ICC_IGRPEN0_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 6,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_fiq_access,
       .fgt = FGT_ICC_IGRPENN_EL1,
       .readfn = icc_igrpen_read,
@@ -2586,7 +2586,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     /* This register is banked */
     { .name = "ICC_IGRPEN1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 12, .opc2 = 7,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irq_access,
       .fgt = FGT_ICC_IGRPENN_EL1,
       .readfn = icc_igrpen_read,
@@ -2594,7 +2594,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     },
     { .name = "ICC_SRE_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 5,
-      .type = ARM_CP_NO_RAW | ARM_CP_CONST,
+      .type = ARM_CP_NO_RAW | ARM_CP_NO_GDB | ARM_CP_CONST,
       .access = PL2_RW,
       /* We don't support IRQ/FIQ bypass and system registers are
        * always enabled, so all our bits are RAZ/WI or RAO/WI.
@@ -2603,14 +2603,14 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     },
     { .name = "ICC_CTLR_EL3", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 6, .crn = 12, .crm = 12, .opc2 = 4,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL3_RW,
       .readfn = icc_ctlr_el3_read,
       .writefn = icc_ctlr_el3_write,
     },
     { .name = "ICC_SRE_EL3", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 6, .crn = 12, .crm = 12, .opc2 = 5,
-      .type = ARM_CP_NO_RAW | ARM_CP_CONST,
+      .type = ARM_CP_NO_RAW | ARM_CP_NO_GDB | ARM_CP_CONST,
       .access = PL3_RW,
       /* We don't support IRQ/FIQ bypass and system registers are
        * always enabled, so all our bits are RAZ/WI or RAO/WI.
@@ -2619,7 +2619,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
     },
     { .name = "ICC_IGRPEN1_EL3", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 6, .crn = 12, .crm = 12, .opc2 = 7,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL3_RW,
       .readfn = icc_igrpen1_el3_read,
       .writefn = icc_igrpen1_el3_write,
@@ -2629,14 +2629,14 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
 static const ARMCPRegInfo gicv3_cpuif_icc_apxr1_reginfo[] = {
     { .name = "ICC_AP0R1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 5,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_fiq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
     },
     { .name = "ICC_AP1R1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 9, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
@@ -2646,28 +2646,28 @@ static const ARMCPRegInfo gicv3_cpuif_icc_apxr1_reginfo[] = {
 static const ARMCPRegInfo gicv3_cpuif_icc_apxr23_reginfo[] = {
     { .name = "ICC_AP0R2_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 6,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_fiq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
     },
     { .name = "ICC_AP0R3_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 8, .opc2 = 7,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_fiq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
     },
     { .name = "ICC_AP1R2_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 9, .opc2 = 2,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
     },
     { .name = "ICC_AP1R3_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 9, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW, .accessfn = gicv3_irq_access,
       .readfn = icc_ap_read,
       .writefn = icc_ap_write,
@@ -2677,7 +2677,7 @@ static const ARMCPRegInfo gicv3_cpuif_icc_apxr23_reginfo[] = {
 static const ARMCPRegInfo gicv3_cpuif_gicv3_nmi_reginfo[] = {
     { .name = "ICC_NMIAR1_EL1", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 9, .opc2 = 5,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_R, .accessfn = gicv3_irq_access,
       .readfn = icc_nmiar1_read,
     },
@@ -2893,7 +2893,7 @@ static uint64_t ich_elrsr_read(CPUARMState *env, const ARMCPRegInfo *ri)
 static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo[] = {
     { .name = "ICH_AP0R0_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x480,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2901,7 +2901,7 @@ static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo[] = {
     },
     { .name = "ICH_AP1R0_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x4a0,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2909,7 +2909,7 @@ static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo[] = {
     },
     { .name = "ICH_HCR_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 0,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x4c0,
       .access = PL2_RW,
       .readfn = ich_hcr_read,
@@ -2917,31 +2917,31 @@ static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo[] = {
     },
     { .name = "ICH_VTR_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL2_R,
       .readfn = ich_vtr_read,
     },
     { .name = "ICH_MISR_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 2,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL2_R,
       .readfn = ich_misr_read,
     },
     { .name = "ICH_EISR_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL2_R,
       .readfn = ich_eisr_read,
     },
     { .name = "ICH_ELRSR_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 5,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL2_R,
       .readfn = ich_elrsr_read,
     },
     { .name = "ICH_VMCR_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 11, .opc2 = 7,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x4c8,
       .access = PL2_RW,
       .readfn = ich_vmcr_read,
@@ -2952,7 +2952,7 @@ static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo[] = {
 static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo[] = {
     { .name = "ICH_AP0R1_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x488,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2960,7 +2960,7 @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo[] = {
     },
     { .name = "ICH_AP1R1_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 1,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x4a8,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2971,7 +2971,7 @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo[] = {
 static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo[] = {
     { .name = "ICH_AP0R2_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 2,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x490,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2979,7 +2979,7 @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo[] = {
     },
     { .name = "ICH_AP0R3_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 8, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x498,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2987,7 +2987,7 @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo[] = {
     },
     { .name = "ICH_AP1R2_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 2,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x4b0,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -2995,7 +2995,7 @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo[] = {
     },
     { .name = "ICH_AP1R3_EL2", .state = ARM_CP_STATE_BOTH,
       .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 9, .opc2 = 3,
-      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .nv2_redirect_offset = 0x4b8,
       .access = PL2_RW,
       .readfn = ich_ap_read,
@@ -3130,7 +3130,7 @@ void gicv3_init_cpuif(GICv3State *s)
                     { .name = "ICH_LRn_EL2", .state = ARM_CP_STATE_BOTH,
                       .opc0 = 3, .opc1 = 4, .crn = 12,
                       .crm = 12 + (j >> 3), .opc2 = j & 7,
-                      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+                      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
                       .nv2_redirect_offset = 0x400 + 8 * j,
                       .access = PL2_RW,
                       .readfn = ich_lr_read,
@@ -3139,7 +3139,7 @@ void gicv3_init_cpuif(GICv3State *s)
                     { .name = "ICH_LRCn_EL2", .state = ARM_CP_STATE_AA32,
                       .cp = 15, .opc1 = 4, .crn = 12,
                       .crm = 14 + (j >> 3), .opc2 = j & 7,
-                      .type = ARM_CP_IO | ARM_CP_NO_RAW,
+                      .type = ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
                       .access = PL2_RW,
                       .readfn = ich_lr_read,
                       .writefn = ich_lr_write,
hw/intc/arm_gicv3_kvm.c +1 -1
index 8e17cab2a0fe..910ffe7c2baa 100644
@@ -736,7 +736,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
        * If ARM_CP_NOP is used, resetfn is not called,
        * So ARM_CP_NO_RAW is appropriate type.
        */
-      .type = ARM_CP_NO_RAW,
+      .type = ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .access = PL1_RW,
       .readfn = arm_cp_read_zero,
       .writefn = arm_cp_write_ignore,
target/arm/debug_helper.c +1 -1
index a9a619ba6b1b..1c0a633e0f09 100644
@@ -1013,7 +1013,7 @@ static const ARMCPRegInfo debug_cp_reginfo[] = {
       .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1), },
     { .name = "OSLAR_EL1", .state = ARM_CP_STATE_BOTH,
       .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 1, .crm = 0, .opc2 = 4,
-      .access = PL1_W, .type = ARM_CP_NO_RAW,
+      .access = PL1_W, .type = ARM_CP_NO_RAW | ARM_CP_NO_GDB,
       .accessfn = access_tdosa,
       .fgt = FGT_OSLAR_EL1,
       .writefn = oslar_write },
target/arm/helper.c +125 -94

711 lines not on this page · raw message

target/arm/tcg/tlb-insns.c +144 -112

678 lines not on this page · raw message

Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/4 target/arm: Do not imply ARM_CP_NO_GDB

In reply to Akihiko Odaki

Do not imply ARM_CP_NO_GDB when ARM_CP_NO_RAW.

A register without raw access support may still expose some state to GDB that is managed by something else.

A register may its state with another register but may not be used for either migration or KVM state synchronization. For example, a multiplexing register cannot support raw access. KVM may also have a problem when synchronizing a register.

Such a register can be flagged with ARM_CP_ALIAS | ARM_CP_NO_RAW, but its value can be still exposed to GDB as it's usually the case for registers flagged with ARM_CP_ALIAS. ARM_CP_NO_GDB should not be implied in this case.

---
 target/arm/cpregs.h  | 8 ++++----
 target/arm/gdbstub.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
target/arm/cpregs.h +4 -4
index 52377c6eb50f..99e2afc84250 100644
@@ -75,10 +75,10 @@ enum {
      */
     ARM_CP_IO                    = 1 << 9,
     /*
-     * Flag: Register has no underlying state and does not support raw access
-     * for state saving/loading; it will not be used for either migration or
-     * KVM state synchronization. Typically this is for "registers" which are
-     * actually used as instructions for cache maintenance and so on.
+     * Flag: Register does not support raw access for state saving/loading; it
+     * will not be used for either migration or KVM state synchronization.
+     * Typically this is for "registers" which are actually used as instructions
+     * for cache maintenance and so on.
      */
     ARM_CP_NO_RAW                = 1 << 10,
     /*
target/arm/gdbstub.c +1 -1
index 30068c226273..4459e90811b8 100644
@@ -270,7 +270,7 @@ static void arm_register_sysreg_for_feature(gpointer key, gpointer value,
     CPUARMState *env = &cpu->env;
     DynamicGDBFeatureInfo *dyn_feature = &cpu->dyn_sysreg_feature;
 
-    if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_NO_GDB))) {
+    if (!(ri->type & ARM_CP_NO_GDB)) {
         if (arm_feature(env, ARM_FEATURE_AARCH64)) {
             if (ri->state == ARM_CP_STATE_AA64) {
                 arm_gen_one_feature_sysreg(&param->builder, dyn_feature,
Signature · 1 line
2.48.1
#3 lore raw

PATCH 3/4 target/arm: Expose PMINTENCLR to GDB

In reply to Akihiko Odaki

PMINTENCLR and PMINTENCLR_EL1 are aliases of PMINTENSET_EL1. Expose them as we do for other alias registers.

---
 target/arm/helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/helper.c +2 -2
index 5ce468ac2693..2dd8f4d56a1e 100644
@@ -2025,14 +2025,14 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
     { .name = "PMINTENCLR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 2,
       .access = PL1_RW, .accessfn = access_tpm,
       .fgt = FGT_PMINTEN,
-      .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
+      .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
       .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten),
       .writefn = pmintenclr_write, },
     { .name = "PMINTENCLR_EL1", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 2,
       .access = PL1_RW, .accessfn = access_tpm,
       .fgt = FGT_PMINTEN,
-      .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW | ARM_CP_NO_GDB,
+      .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
       .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten),
       .writefn = pmintenclr_write },
     { .name = "CCSIDR", .state = ARM_CP_STATE_BOTH,
Signature · 1 line
2.48.1
#4 lore raw

PATCH 4/4 target/arm: Flag PMCNTENCLR with ARM_CP_NO_RAW

In reply to Akihiko Odaki

A normal write to PMCNTENCLR clears written bits so it is not appropriate for writing a raw value. This kind of situation is usually handled by setting a raw write function, but flag the register with ARM_CP_NO_RAW instead to workaround a problem with KVM.

KVM also has the same problem with PMINTENSET so add a comment to note that. This register is already flagged with ARM_CP_NO_RAW.

---
 target/arm/helper.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
target/arm/helper.c +12 -2
index 2dd8f4d56a1e..ee15132aadea 100644
@@ -1901,12 +1901,21 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
       .accessfn = pmreg_access,
       .fgt = FGT_PMCNTEN,
       .writefn = pmcntenclr_write,
-      .type = ARM_CP_ALIAS | ARM_CP_IO },
+      /*
+       * Flag PMCNTENCLR with ARM_CP_NO_RAW instead of implementing raw
+       * access to workaround a problem with KVM; KVM applies bit operations
+       * that prevents writing back raw values since Linux 6.7:
+       * https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a45f41d754e0b37de4b7dc1fb3c6b7a1285882fc
+       *
+       * It is fine to lack raw access with PMCNTENCLR because KVM still
+       * exposes PMCNTENSET, which shares the underlying state.
+       */
+      .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW },
     { .name = "PMCNTENCLR_EL0", .state = ARM_CP_STATE_AA64,
       .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 2,
       .access = PL0_RW, .accessfn = pmreg_access,
       .fgt = FGT_PMCNTEN,
-      .type = ARM_CP_ALIAS | ARM_CP_IO,
+      .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
       .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten),
       .writefn = pmcntenclr_write },
     { .name = "PMOVSR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 3,
@@ -2025,6 +2034,7 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
     { .name = "PMINTENCLR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 2,
       .access = PL1_RW, .accessfn = access_tpm,
       .fgt = FGT_PMINTEN,
+      /* Flag PMINTENCLR with ARM_CP_NO_RAW, as with PMCNTENCLR. */
       .type = ARM_CP_ALIAS | ARM_CP_IO | ARM_CP_NO_RAW,
       .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten),
       .writefn = pmintenclr_write, },
Signature · 1 line
2.48.1
#5 lore raw
In reply to Akihiko Odaki
Quoted 8 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2] target/arm: Define raw write for PMU CLR registers")

A normal write to PMCNTENCLR clears written bits so it is not appropriate for writing a raw value. This kind of situation is usually handled by setting a raw write function, but flag the register with ARM_CP_NO_RAW instead to workaround a problem with KVM.

I'm not sure there's a "problem with KVM" here -- it implements the write to PMCNTENCLR to have the semantics the architecture specifies.

Quoted 2 lines

KVM also has the same problem with PMINTENSET so add a comment to note that. This register is already flagged with ARM_CP_NO_RAW.

What are we trying to achieve with this patchset? You can't write to registers from gdb, and reading PMCNTENCLR just gives you the same value as PMCNTENSET, so you might as well read that, which we already expose.

More generally, the gdb-stub access to system registers is something we put in on a "this is a minimal amount of code to provide something that more or less works" basis. If we want it to work better (i.e. more comprehensively, possibly with write support) then we should address that by looking at the design of doing that more holistically, not by making tweaks to address individual registers.

Specifically, I'm not really happy with adding explicit ARM_CP_NO_GDB flags to everything we currently mark as ARM_CP_NO_RAW. Either we stick with our existing "minimal changes to produce something that works" approach, in which case we deny gdb access to NO_RAW registers because that's easy and most of them it won't work or doesn't make sense. Or else we do the actual design work. That might turn out to mean "we explicitly mark no-gdb registers rather than overloading NO_RAW for this", or it might mean something else. But we won't know until we actually do that design work.

(see also https://gitlab.com/qemu-project/qemu/-/issues/2760 )

thanks
-- PMM

#6 lore raw
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2] target/arm: Define raw write for PMU CLR registers")

Quoted 7 lines
Quoted 4 lines

A normal write to PMCNTENCLR clears written bits so it is not appropriate for writing a raw value. This kind of situation is usually handled by setting a raw write function, but flag the register with ARM_CP_NO_RAW instead to workaround a problem with KVM.

I'm not sure there's a "problem with KVM" here -- it implements the write to PMCNTENCLR to have the semantics the architecture specifies.

The inline comment includes a reference:

Quoted 5 lines

KVM applies bit operations that prevents writing back raw values since Linux 6.7:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a45f41d754e0b37de4b7dc1fb3c6b7a1285882fc

Quoted 7 lines
Quoted 2 lines

KVM also has the same problem with PMINTENSET so add a comment to note that. This register is already flagged with ARM_CP_NO_RAW.

What are we trying to achieve with this patchset? You can't write to registers from gdb, and reading PMCNTENCLR just gives you the same value as PMCNTENSET, so you might as well read that, which we already expose.

That's also true for other registers marked with ARM_CP_ALIAS and exposed to GDB so I followed those examples. It's up to user what register to choose after all.

Quoted 20 lines

More generally, the gdb-stub access to system registers is something we put in on a "this is a minimal amount of code to provide something that more or less works" basis. If we want it to work better (i.e. more comprehensively, possibly with write support) then we should address that by looking at the design of doing that more holistically, not by making tweaks to address individual registers.

Specifically, I'm not really happy with adding explicit ARM_CP_NO_GDB flags to everything we currently mark as ARM_CP_NO_RAW. Either we stick with our existing "minimal changes to produce something that works" approach, in which case we deny gdb access to NO_RAW registers because that's easy and most of them it won't work or doesn't make sense. Or else we do the actual design work. That might turn out to mean "we explicitly mark no-gdb registers rather than overloading NO_RAW for this", or it might mean something else. But we won't know until we actually do that design work.

Quoted 1 line

(see also https://gitlab.com/qemu-project/qemu/-/issues/2760 )

I suspect that some registers with ARM_CP_NO_RAW cannot be determined as GDB-visible or GDB-invisible based on the current ARMCPRegInfo fields, and explicit marking with some flag is inevitable for them.

That said, I understand explicit markings with ARM_CP_NO_GDB may interfere with the future design work, and I think I can still solve the problem with PMCNTENCLR and similar registers without it. Below is a detailed explanation:

The underlying problem here is that the current definitions of ARM_CP_ALIAS and ARM_CP_NO_RAW are contradicting and incompatible.

Now let me describe characteristics of PMCNTENCLR with yes/no table:
1) It has a state - yes
2) It will handle migration and reset - no
3) The state can be synchronized with KVM - no
4) The state is shared with another register - yes

1) the presence of the state usually implies it is visible to GDB.

The documentation of ARM_CP_ALIAS says:

Quoted 5 lines

Register is an alias view of some underlying state which is also visible via another register, and that the other register is handling migration and reset; registers marked ARM_CP_ALIAS will not be migrated but may have their state set by syncing of register state from KVM.

So ARM_CP_ALIAS implies:
1) It has a state - yes
2) It will handle migration and reset - no
3) The state can be synchronized with KVM - yes
4) The state is shared with another register - yes

1) is implied from 3) and 4); if there is no state, the state cannot be synchronized and cannot be shared with another register.

The documentation of ARM_CP_NO_RAW says:

Quoted 4 lines

Register has no underlying state and does not support raw access for state saving/loading; it will not be used for either migration or KVM state synchronization. Typically this is for "registers" which are actually used as instructions for cache maintenance and so on.

So ARM_CP_NO_RAW implies:
1) It has a state - no
2) It will handle migration and reset - no
3) The state can be synchronized with KVM - no
4) The state is shared with another register - n/a (there is no state)

It also makes the register invisible from GDB since there is no underlying state.

As you can see, ARM_CP_ALIAS and ARM_CP_NO_RAW have contradicting semantics. A minimal change to make them compatible is to explicitly define what (ARM_CP_ALIAS | ARM_CP_NO_RAW) implies:
1) It has a state - yes (it has a state shared with its alias)
2) It will handle migration and reset - no
3) The state can be synchronized with KVM - no (due to no raw access)
4) The state is shared with another register - yes

More concretely, the documentation of ARM_CP_NO_RAW can be changed as follows:
"Register does not support raw access for state saving/loading; it will not be used for either migration of KVM state synchronization. It also implies reading the register does not expose a state and hides it from GDB unless ARM_CP_ALIAS is set."

With this change, we can express the semantics of PMCNTENCLR without extra explicit markings of ARM_CP_NO_GDB and any contradiction in code. This explanation is long but the code change should be minimal.

What do you think?

Regards,
Akihiko Odaki

Quoted 3 lines

thanks
-- PMM

#7 lore raw
In reply to Peter Maydell
Quoted 6 lines · Peter Maydell
Quoted 4 lines · Akihiko Odaki

Supersedes: <[email protected]> ("[PATCH v2] target/arm: Define raw write for PMU CLR registers")

Quoted 7 lines
Quoted 4 lines

A normal write to PMCNTENCLR clears written bits so it is not appropriate for writing a raw value. This kind of situation is usually handled by setting a raw write function, but flag the register with ARM_CP_NO_RAW instead to workaround a problem with KVM.

I'm not sure there's a "problem with KVM" here -- it implements the write to PMCNTENCLR to have the semantics the architecture specifies.

I checked with the KVM developers on this one, and you are correct that this is a KVM issue, so I was wrong here; sorry about that. There is a fix queued:

https://web.git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git/commit/?h=next&id=f2aeb7bbd5745fbcf7f0769e29a184e24924b9a9

which will restore the "just writes the value" semantics. This is apparently the intended semantics for KVM_SET_ONE_REG for all cases: the write is supposed to do "sets register to the specified value", not "behaves as if the guest vCPU had done the register write insn, with attendant side effects".

thanks
-- PMM