Skip to contentSkip to conversation

hw/arm/smmuv3: Add GBPA register

PATCH Superseded Mostafa Saleh 4 participants 9 messages Feb 10, 2023 – Feb 13, 2023

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 hw/arm/smmuv3: Add GBPA register

GBPA register can be used to globally abort all
transactions.

It is described in the SMMU manual in "6.3.14 SMMU_GBPA". ABORT reset value is IMPLEMENTATION DEFINED, it is chosen to be zero(Do not abort incoming transactions).

Other fields have default values of Use Incoming.

If UPDATE is not set, the write is ignored. This is the only permitted behavior in SMMUv3.2 and later.(6.3.14.1 Update procedure)

As this patch adds a new state to the SMMU (GBPA), it is added in a new subsection for forward migration compatibility. GBPA is only migrated if its value is different from the reset value. It does this to be backward migration compatible if SW didn't write the register.

---
Changes in v4:
- Migrate if GBPA is different from reset value, not only ABORT bit.

Changes in v3:
- Remove migrate_gbpa property as it was unnecessary.

Changes in v2:
- GBPA is effective only when SMMU is not enabled.
- Ignore GBPA write when UPDATE is not set.
- Default value for SHCFG is "Use Incoming".
- Support migration.

---
 hw/arm/smmuv3-internal.h |  7 ++++++
 hw/arm/smmuv3.c          | 47 +++++++++++++++++++++++++++++++++++++++-
 include/hw/arm/smmuv3.h  |  1 +
 3 files changed, 54 insertions(+), 1 deletion(-)
hw/arm/smmuv3-internal.h +7 -0
index bce161870f..e8f0ebf25e 100644
@@ -79,6 +79,13 @@ REG32(CR0ACK,              0x24)
 REG32(CR1,                 0x28)
 REG32(CR2,                 0x2c)
 REG32(STATUSR,             0x40)
+REG32(GBPA,                0x44)
+    FIELD(GBPA, ABORT,        20, 1)
+    FIELD(GBPA, UPDATE,       31, 1)
+
+/* Use incoming. */
+#define SMMU_GBPA_RESET_VAL 0x1000
+
 REG32(IRQ_CTRL,            0x50)
     FIELD(IRQ_CTRL, GERROR_IRQEN,        0, 1)
     FIELD(IRQ_CTRL, PRI_IRQEN,           1, 1)
hw/arm/smmuv3.c +46 -1

83 lines not on this page · raw message

include/hw/arm/smmuv3.h +1 -0
index f1921fdf9e..9899fa1860 100644
@@ -46,6 +46,7 @@ struct SMMUv3State {
     uint32_t cr[3];
     uint32_t cr0ack;
     uint32_t statusr;
+    uint32_t gbpa;
     uint32_t irq_ctrl;
     uint32_t gerror;
     uint32_t gerrorn;
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
Reviewed-by on v4 1/1
#1 lore raw

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3_queue = { · line 1512

Quoted 10 lines · Mostafa Saleh
hw/arm/smmuv3.c +10 -0
+static bool smmuv3_gbpa_needed(void *opaque)
+{
+    SMMUv3State *s = opaque;
+
+    /* Only migrate GBPA if it has different reset value. */
+    if (s->gbpa != SMMU_GBPA_RESET_VAL) {
+        return true;
+    }
+
+    return false;

Just "return s->gbpa != SMMU_GBPA_RESET_VAL;".

Otherwise,

r~

#3 lore raw
In reply to Mostafa Saleh

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3 = { · line 1559

Quoted 8 lines · Mostafa Saleh
hw/arm/smmuv3.c +4 -0
@@ -1512,6 +1553,10 @@ static const VMStateDescription vmstate_smmuv3 = {
 
          VMSTATE_END_OF_LIST(),
      },
+    .subsections = (const VMStateDescription * []) {
+        &vmstate_gbpa,
+        NULL
+    }

Actually, I suspect that you need a pre_load hook that resets gbpa, which will then be overwritten if and only if the saved value != reset value.

r~

#4 lore raw
Quoted 1 line · Richard Henderson

Just "return s->gbpa != SMMU_GBPA_RESET_VAL;".

I will update it.

Quoted 11 lines

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3 = { · line 1558

Quoted 7 lines
hw/arm/smmuv3.c +4 -0
@@ -1512,6 +1553,10 @@ static const VMStateDescription vmstate_smmuv3 = {
          VMSTATE_END_OF_LIST(),
      },
+    .subsections = (const VMStateDescription * []) {
+        &vmstate_gbpa,
+        NULL
+    }

Actually, I suspect that you need a pre_load hook that resets gbpa, which will then be overwritten if and only if the saved value != reset value.

Please correct me if I am wrong. From what I see, the initial for value GBPA will be set from smmu_reset_hold which is called from context of qemu_system_reset from qemu_init context.
And migration will start after that in migration_incoming_process from qemu_main_loop context.

I validated that also by printing the value of GBPA from vmstate_smmuv3 pre_load at migration without GPBA, and it is the same as SMMU_GBPA_RESET_VAL.

Thanks,
Mostafa

#5 lore raw
Quoted 24 lines · Mostafa Saleh
Quoted 1 line · Richard Henderson

Just "return s->gbpa != SMMU_GBPA_RESET_VAL;".

I will update it.

Quoted 11 lines

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3 = { · line 1558

Quoted 7 lines
hw/arm/smmuv3.c +4 -0
@@ -1512,6 +1553,10 @@ static const VMStateDescription vmstate_smmuv3 = {
           VMSTATE_END_OF_LIST(),
       },
+    .subsections = (const VMStateDescription * []) {
+        &vmstate_gbpa,
+        NULL
+    }

Actually, I suspect that you need a pre_load hook that resets gbpa, which will then be overwritten if and only if the saved value != reset value.

Please correct me if I am wrong. From what I see, the initial for value GBPA will be set from smmu_reset_hold which is called from context of qemu_system_reset from qemu_init context.
And migration will start after that in migration_incoming_process from qemu_main_loop context.

Quoted 3 lines

I validated that also by printing the value of GBPA from vmstate_smmuv3 pre_load at migration without GPBA, and it is the same as SMMU_GBPA_RESET_VAL.

Is that from -loadvm on the command-line, or the loadvm command from the monitor? It's the latter that I suspect requires the pre_load.

r~

#6 lore raw
Quoted 6 lines · Richard Henderson
Quoted 6 lines

Please correct me if I am wrong. From what I see, the initial for value GBPA will be set from smmu_reset_hold which is called from context of qemu_system_reset from qemu_init context.
And migration will start after that in migration_incoming_process from qemu_main_loop context.

Quoted 6 lines
Quoted 3 lines

I validated that also by printing the value of GBPA from vmstate_smmuv3 pre_load at migration without GPBA, and it is the same as SMMU_GBPA_RESET_VAL.

Is that from -loadvm on the command-line, or the loadvm command from the monitor? It's the latter that I suspect requires the pre_load.

I was testing before with migration
-From qemu monitor with migrate command
-Load it from cmdline with -incoming

I tested now with savevm/loadvm from qemu monitor
On vmload command, load_snapshot is called which in the following order calls:
- qemu_system_reset which calls smmu_reset_hold initializing the SMMU registers.
- qemu_loadvm_state which loads the saved state.

So From what I see, pre_load won’t be needed in this case also.

Thanks,
Mostafa

#7 lore raw
In reply to Richard Henderson
Quoted 4 lines · Richard Henderson
Quoted 2 lines · Mostafa Saleh
(quoted diff) +0 -0
@@ -1512,6 +1553,10 @@ static const VMStateDescription vmstate_smmuv3 = {
 
Quoted 9 lines

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3 = { · line 1559

Quoted 6 lines
hw/arm/smmuv3.c +4 -0
          VMSTATE_END_OF_LIST(),
      },
+    .subsections = (const VMStateDescription * []) {
+        &vmstate_gbpa,
+        NULL
+    }

Actually, I suspect that you need a pre_load hook that resets gbpa, which will then be overwritten if and only if the saved value != reset value.

VM loads are guaranteed to start from a VM state which is freshly reset, so the device's reset method is sufficient for this.

thanks
-- PMM

Reviewed-by
#2 lore raw
In reply to Richard Henderson

Hi Mostafa,

Quoted 14 lines · Richard Henderson

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3_queue = { · line 1512

Quoted 10 lines · Mostafa Saleh
hw/arm/smmuv3.c +10 -0
+static bool smmuv3_gbpa_needed(void *opaque)
+{
+    SMMUv3State *s = opaque;
+
+    /* Only migrate GBPA if it has different reset value. */
+    if (s->gbpa != SMMU_GBPA_RESET_VAL) {
+        return true;
+    }
+
+    return false;

Just "return s->gbpa != SMMU_GBPA_RESET_VAL;".

Quoted 2 lines

Otherwise,

With this suggestion, it looks good to me.

Thanks

Eric

Quoted 4 lines

r~

#8 lore raw
In reply to Peter Maydell
Quoted 16 lines · Peter Maydell
Quoted 4 lines · Richard Henderson
Quoted 2 lines · Mostafa Saleh
(quoted diff) +0 -0
@@ -1512,6 +1553,10 @@ static const VMStateDescription vmstate_smmuv3 = {
 
Quoted 9 lines

hw/arm/smmuv3.c static const VMStateDescription vmstate_smmuv3 = { · line 1559

Quoted 6 lines
hw/arm/smmuv3.c +4 -0
           VMSTATE_END_OF_LIST(),
       },
+    .subsections = (const VMStateDescription * []) {
+        &vmstate_gbpa,
+        NULL
+    }

Actually, I suspect that you need a pre_load hook that resets gbpa, which will then be overwritten if and only if the saved value != reset value.

Quoted 2 lines

VM loads are guaranteed to start from a VM state which is freshly reset, so the device's reset method is sufficient for this.

Thanks for the confirmation.

r~