Skip to contentSkip to conversation

hw/intc/arm_gicv3_kvm: Implement get/put functions

RFC PATCH Peter Maydell 2 participants 2 messages Oct 7, 2016 – Nov 9, 2016 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 8 lines · On 20 September 2016 at 07:55, <[email protected]> wrote:

From: Vijaya Kumar K <[email protected]>

This actually implements pre_save and post_load methods for in-kernel vGICv3.

Quoted 15 lines

[PMM:
* use decimal, not 0bnnn
* fixed typo in names of ICC_APR0R_EL1 and ICC_AP1R_EL1
* completely rearranged the get and put functions to read and write the state in a natural order, rather than mixing distributor and redistributor state together]
[Vijay:
* Update macro KVM_VGIC_ATTR
* Use 32 bit access for gicd and gicr
* GICD_IROUTER, GICD_TYPER, GICR_PROPBASER and GICR_PENDBASER reg access are changed from 64-bit to 32-bit access
* s->edge_trigger stores only even bits value of an irq config. Update translate_edge_trigger() accordingly.
* Add ICC_SRE_EL1 save and restore
* Initialized ICC registers during reset

These sorts of [] changes should go above the sign-off of the person who did them, to indicate where in the chain they happened. Also, yours is missing the closing ].

Quoted 16 lines

---
---

(quoted diff) +13 -0
+/* Translate from the in-kernel field for an IRQ value to/from the qemu
+ * representation. Note that these are only expected to be used for
+ * SPIs (that is, for interrupts whose state is in the distributor
+ * rather than the redistributor).
+ */
+typedef void (*vgic_translate_fn)(GICv3State *s, int irq,
+                                  uint32_t *field, bool to_kernel);
+
+static void translate_edge_trigger(GICv3State *s, int irq,
+    uint32_t *field, bool to_kernel)
+{
+    /*
+     * s->edge_trigger stores only even bits value of an irq config.

Review

Quoted 10 lines
(quoted diff) +10 -0
+     * Consider only even bits and translate accordingly.
+     */
+    if (to_kernel) {
+        *field = gicv3_gicd_edge_trigger_test(s, irq);
+        *field = (*field << 1) & 3;
+    } else {
+        *field = (*field >> 1) & 1;
+        gicv3_gicd_edge_trigger_replace(s, irq, *field);
+    }
+}

I would prefer that we just open-coded a for-loop for these, as then you can use half_shuffle32 and half_unshuffle32 to deal with the bits 32 at a time.

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+static void translate_priority(GICv3State *s, int irq,
+                               uint32_t *field, bool to_kernel)
+{
+    if (to_kernel) {
+        *field = s->gicd_ipriority[irq];
+    } else {
+        s->gicd_ipriority[irq] = *field;
+    }
+}

Similarly, this would be better with open-coded for loops. Then we can dump the translate_fn machinery entirely.

Quoted 12 lines
(quoted diff) +12 -0
+
+static void kvm_arm_gicv3_reset_reg(GICv3State *s)
+{
+    int ncpu;
+
+    for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
+        GICv3CPUState *c = &s->cpu[ncpu];
+
+        /* Initialize to actual HW supported configuration */
+        kvm_gicc_access(s, ICC_CTLR_EL1, ncpu,
+                        &c->icc_ctlr_el1[GICV3_NS], false);
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+        c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS];
+        c->icc_pmr_el1 = 0;
+        c->icc_bpr[GICV3_G0] = GIC_MIN_BPR;
+        c->icc_bpr[GICV3_G1] = GIC_MIN_BPR;
+        c->icc_bpr[GICV3_G1NS] = GIC_MIN_BPR;
+
+        c->icc_sre_el1 = 0x7;
+        memset(c->icc_apr, 0, sizeof(c->icc_apr));
+        memset(c->icc_igrpen, 0, sizeof(c->icc_igrpen));
+    }

This shouldn't be in this patch. If we need to fix reset we should do it as a separate patch.

Also this isn't the right place, really, because the CPU interface registers need to be reset when the CPU is reset, not when the GIC device is reset.

include/hw/intc/arm_gicv3_common.h struct GICv3CPUState { · line 169

Quoted 12 lines

}

static void kvm_arm_gicv3_class_init(ObjectClass *klass, void *data)

include/hw/intc/arm_gicv3_common.h +1 -0
index 341a311..183c7f8 100644
@@ -166,6 +166,7 @@ struct GICv3CPUState {
     uint8_t gicr_ipriorityr[GIC_INTERNAL];
 
     /* CPU interface */
+    uint64_t icc_sre_el1;

Where has this come from? If we need to add a new field then it needs to be in a different patch (and we need to make sure we add it to the VMState struct as well). But neither the emulated GIC nor the kernel will support writing any bits in this register as far as I'm aware, so it's always constant 0x7...

thanks
-- PMM

#3 lore raw
Quoted 51 lines · Peter Maydell
Quoted 8 lines · On 20 September 2016 at 07:55, <[email protected]> wrote:

From: Vijaya Kumar K <[email protected]>

This actually implements pre_save and post_load methods for in-kernel vGICv3.

Quoted 15 lines

[PMM:
* use decimal, not 0bnnn
* fixed typo in names of ICC_APR0R_EL1 and ICC_AP1R_EL1
* completely rearranged the get and put functions to read and write the state in a natural order, rather than mixing distributor and redistributor state together]
[Vijay:
* Update macro KVM_VGIC_ATTR
* Use 32 bit access for gicd and gicr
* GICD_IROUTER, GICD_TYPER, GICR_PROPBASER and GICR_PENDBASER reg access are changed from 64-bit to 32-bit access
* s->edge_trigger stores only even bits value of an irq config. Update translate_edge_trigger() accordingly.
* Add ICC_SRE_EL1 save and restore
* Initialized ICC registers during reset

These sorts of [] changes should go above the sign-off of the person who did them, to indicate where in the chain they happened. Also, yours is missing the closing ].

Quoted 22 lines

---
---

(quoted diff) +19 -0
+/* Translate from the in-kernel field for an IRQ value to/from the qemu
+ * representation. Note that these are only expected to be used for
+ * SPIs (that is, for interrupts whose state is in the distributor
+ * rather than the redistributor).
+ */
+typedef void (*vgic_translate_fn)(GICv3State *s, int irq,
+                                  uint32_t *field, bool to_kernel);
+
+static void translate_edge_trigger(GICv3State *s, int irq,
+    uint32_t *field, bool to_kernel)
+{
+    /*
+     * s->edge_trigger stores only even bits value of an irq config.
+     * Consider only even bits and translate accordingly.
+     */
+    if (to_kernel) {
+        *field = gicv3_gicd_edge_trigger_test(s, irq);
+        *field = (*field << 1) & 3;
+    } else {
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+        *field = (*field >> 1) & 1;
+        gicv3_gicd_edge_trigger_replace(s, irq, *field);
+    }
+}

I would prefer that we just open-coded a for-loop for these, as then you can use half_shuffle32 and half_unshuffle32 to deal with the bits 32 at a time.

You mean to completely drop this translate_fn which is called from kvm_dist_put/get() and have a direct function to handle edge_trigger?

Quoted 41 lines

Review

Quoted 11 lines
(quoted diff) +10 -0
+
+static void translate_priority(GICv3State *s, int irq,
+                               uint32_t *field, bool to_kernel)
+{
+    if (to_kernel) {
+        *field = s->gicd_ipriority[irq];
+    } else {
+        s->gicd_ipriority[irq] = *field;
+    }
+}

Similarly, this would be better with open-coded for loops. Then we can dump the translate_fn machinery entirely.

Quoted 12 lines
(quoted diff) +12 -0
+
+static void kvm_arm_gicv3_reset_reg(GICv3State *s)
+{
+    int ncpu;
+
+    for (ncpu = 0; ncpu < s->num_cpu; ncpu++) {
+        GICv3CPUState *c = &s->cpu[ncpu];
+
+        /* Initialize to actual HW supported configuration */
+        kvm_gicc_access(s, ICC_CTLR_EL1, ncpu,
+                        &c->icc_ctlr_el1[GICV3_NS], false);
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+        c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS];
+        c->icc_pmr_el1 = 0;
+        c->icc_bpr[GICV3_G0] = GIC_MIN_BPR;
+        c->icc_bpr[GICV3_G1] = GIC_MIN_BPR;
+        c->icc_bpr[GICV3_G1NS] = GIC_MIN_BPR;
+
+        c->icc_sre_el1 = 0x7;
+        memset(c->icc_apr, 0, sizeof(c->icc_apr));
+        memset(c->icc_igrpen, 0, sizeof(c->icc_igrpen));
+    }

This shouldn't be in this patch. If we need to fix reset we should do it as a separate patch.

Quoted 3 lines

Also this isn't the right place, really, because the CPU interface registers need to be reset when the CPU is reset, not when the GIC device is reset.

To make GIC cpuif registers to reset upon cpu reset, I propose to add Interface for gicv3_common class and call this interface from arm_cpu_reset() similar to ARMLinuxBootIf. This will be more generic way rather than searching for gicv3 object and reset the registers

Quoted 11 lines
Quoted 11 lines

}

static void kvm_arm_gicv3_class_init(ObjectClass *klass, void *data)

include/hw/intc/arm_gicv3_common.h +0 -0
index 341a311..183c7f8 100644
@@ -166,6 +166,7 @@ struct GICv3CPUState {
     uint8_t gicr_ipriorityr[GIC_INTERNAL];
 
Quoted 4 lines

include/hw/intc/arm_gicv3_common.h struct GICv3CPUState { · line 169

Quoted 2 lines
include/hw/intc/arm_gicv3_common.h +1 -0
     /* CPU interface */
+    uint64_t icc_sre_el1;

Where has this come from? If we need to add a new field then it

This was part of review comment from Christoffer to add icc_sre_el1 save and restore

Quoted 1 line

needs to be in a different patch (and we need to make sure we

OK. I will spin a new patch

Quoted 3 lines

add it to the VMState struct as well). But neither the emulated GIC nor the kernel will support writing any bits in this register as far as I'm aware, so it's always constant 0x7...

Kernel will not allow write on this. But make a check for SRE bit.

Quoted 3 lines

thanks
-- PMM