static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)
{
- GICv3State *s;
- GICv3CPUState *c;
+ GICv3CPUState *c = (GICv3CPUState *)env->gicv3state;
- c = (GICv3CPUState *)env->gicv3state;
- s = c->gic;
+ /*
+ * This function is called when each vcpu resets. The kernel
+ * API for the GIC assumes that it is only to be used when the
+ * whole VM is paused, so if we attempt to read the kernel's
+ * reset values here we might get EBUSY failures.
+ * So instead we assume we know what the kernel's reset values
+ * are (mostly zeroes) and only update the QEMU state struct
+ * fields. The exception is that we do need to know the kernel's
+ * idea of the ICC_CTLR_EL1 reset value, so we cache that at
+ * device realize time.
+ *
+ * This makes these sysregs different from the usual CPU ones,
+ * which can be validly read and written when only the single
+ * vcpu they apply to is paused, and where (in target/arm code)
+ * we read the reset values out of the kernel on every reset.
+ */
c->icc_pmr_el1 = 0;
/*
memset(c->icc_apr, 0, sizeof(c->icc_apr));
memset(c->icc_igrpen, 0, sizeof(c->icc_igrpen));
- if (s->migration_blocker) {
- return;
- }
-
- /* Initialize to actual HW supported configuration */
- kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
- KVM_VGIC_ATTR(ICC_CTLR_EL1, c->gicr_typer),
- &c->icc_ctlr_el1[GICV3_NS], false, &error_abort);
-
- c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS];
+ c->icc_ctlr_el1[GICV3_NS] = c->kvm_reset_icc_ctlr_el1;
+ c->icc_ctlr_el1[GICV3_S] = c->kvm_reset_icc_ctlr_el1;
}
static void kvm_arm_gicv3_reset_hold(Object *obj, ResetType type)
kvm_arm_gicv3_notifier,
MIG_MODE_CPR_TRANSFER);
}
+
+ /*
+ * Now we can read the kernel's initial value of ICC_CTLR_EL1, which
+ * we will need if a CPU interface is reset. If the kernel is ancient
+ * and doesn't support writing the GIC state then we don't need to
+ * care what reset does to QEMU's data structures.
+ */
+ if (!s->migration_blocker) {
+ for (i = 0; i < s->num_cpu; i++) {
+ GICv3CPUState *c = &s->cpu[i];
+
+ kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS,
+ KVM_VGIC_ATTR(ICC_CTLR_EL1, c->gicr_typer),
+ &c->kvm_reset_icc_ctlr_el1, false, &error_abort);
+ }
+ }
}
static void kvm_arm_gicv3_class_init(ObjectClass *klass, const void *data)