[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 18/22] arm/cpuhp: Changes to update GIC with vcpu hot-plug no
From: |
Salil Mehta |
Subject: |
[PATCH RFC 18/22] arm/cpuhp: Changes to update GIC with vcpu hot-plug notification |
Date: |
Sat, 13 Jun 2020 22:36:25 +0100 |
Adds the notification support about vcpu hot-(un)plug required to update the
GIC so that it can update its vcpu to GIC cpu interface association.
NOTE: This is using 'struct VirtMachineState' inside the notifier function.
Question: Not sure if it is right to use machine related data structure
inside GIC related files? Its design looks to be pretty much abstracted
from any machine related stuff. @Peter Maydell
Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
hw/arm/virt.c | 12 +++++--
hw/intc/arm_gicv3_common.c | 54 ++++++++++++++++++++++++++++++
hw/intc/arm_gicv3_cpuif.c | 5 +++
hw/intc/gicv3_internal.h | 1 +
include/hw/arm/virt.h | 1 +
include/hw/intc/arm_gicv3_common.h | 1 +
6 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index f0295e940e..b4cfd53a59 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1928,6 +1928,8 @@ static void machvirt_init(MachineState *machine)
create_fdt(vms);
+ notifier_list_init(&vms->cpuhp_notifiers);
+
possible_cpus = mc->possible_cpu_arch_ids(machine);
for (n = 0; n < possible_cpus->len; n++) {
Object *cpuobj;
@@ -2378,6 +2380,12 @@ out:
error_propagate(errp, local_err);
}
+static void virt_update_gic(VirtMachineState *vms, CPUState *cs)
+{
+ /* notify gic to stitch GICC to this new cpu */
+ notifier_list_notify(&vms->cpuhp_notifiers, cs);
+}
+
static void virt_cpu_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
Error **errp)
{
@@ -2432,7 +2440,7 @@ static void virt_cpu_pre_plug(HotplugHandler
*hotplug_dev, DeviceState *dev,
virt_cpu_set_properties(OBJECT(cs), cpu_slot);
if (dev->hotplugged) {
- /* TODO: update GIC about this hotplug change here */
+ virt_update_gic(vms, cs);
}
}
@@ -2506,7 +2514,7 @@ static void virt_cpu_unplug(HotplugHandler *hotplug_dev,
DeviceState *dev,
/* TODO: update the acpi cpu hotplug state for cpu hot-unplug */
unwire_gic_cpu_irqs(vms, cs);
- /* TODO: update the GIC about this hot unplug change */
+ virt_update_gic(vms, cs);
/* TODO: unregister this cpu for reset & update F/W info for the next boot
*/
diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c
index bfa514444a..f6b7b359cb 100644
--- a/hw/intc/arm_gicv3_common.c
+++ b/hw/intc/arm_gicv3_common.c
@@ -31,6 +31,7 @@
#include "gicv3_internal.h"
#include "hw/arm/linux-boot-if.h"
#include "sysemu/kvm.h"
+#include "hw/arm/virt.h"
static void gicv3_gicd_no_migration_shift_bug_post_load(GICv3State *cs)
@@ -305,8 +306,57 @@ void gicv3_init_irqs_and_mmio(GICv3State *s,
qemu_irq_handler handler,
}
}
+static int arm_gicv3_get_proc_num(GICv3State *s, CPUState *cpu)
+{
+ uint64_t mp_affinity;
+ uint64_t gicr_typer;
+ uint64_t cpu_affid;
+ int i;
+
+ mp_affinity = object_property_get_uint(OBJECT(cpu), "mp-affinity", NULL);
+ /* match the cpu mp-affinity to get the gic cpuif number */
+ for (i = 0; i < s->num_cpu; i++) {
+ gicr_typer = s->cpu[i].gicr_typer;
+ cpu_affid = (gicr_typer >> 32) & 0xFFFFFF;
+ if (cpu_affid == mp_affinity) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+static void arm_gicv3_cpu_update_notifier(Notifier * notifier, void * data)
+{
+ VirtMachineState *vms = VIRT_MACHINE(qdev_get_machine());
+ GICv3State *s = ARM_GICV3_COMMON(vms->gic);
+ CPUState *cpu = (CPUState *)data;
+ int gic_cpuif_num;
+
+ /* this shall get us mapped gicv3 cpuif corresponding to mpidr */
+ gic_cpuif_num = arm_gicv3_get_proc_num(s, cpu);
+ if (gic_cpuif_num < 0) {
+ error_report("Failed to associate cpu %d with any GIC cpuif",
+ cpu->cpu_index);
+ abort();
+ }
+
+ /* check if update is for vcpu hot-unplug */
+ if (qemu_present_cpu(cpu)) {
+ s->cpu[gic_cpuif_num].cpu = NULL;
+ return;
+ }
+
+ /* re-stitch the gic cpuif to this new cpu */
+ gicv3_set_gicv3state(cpu, &s->cpu[gic_cpuif_num]);
+ gicv3_set_cpustate(&s->cpu[gic_cpuif_num], cpu);
+
+ /* TODO: initialize the registers info for this newly added cpu */
+}
+
static void arm_gicv3_common_realize(DeviceState *dev, Error **errp)
{
+ VirtMachineState *vms = VIRT_MACHINE(qdev_get_machine());
GICv3State *s = ARM_GICV3_COMMON(dev);
int i;
@@ -386,12 +436,16 @@ static void arm_gicv3_common_realize(DeviceState *dev,
Error **errp)
(i << 8) |
(last << 4);
}
+
+ s->cpu_update_notifier.notify = arm_gicv3_cpu_update_notifier;
+ notifier_list_add(&vms->cpuhp_notifiers, &s->cpu_update_notifier);
}
static void arm_gicv3_finalize(Object *obj)
{
GICv3State *s = ARM_GICV3_COMMON(obj);
+ notifier_remove(&s->cpu_update_notifier);
g_free(s->redist_region_count);
}
diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c
index 90d8b0118e..b3aa5979ca 100644
--- a/hw/intc/arm_gicv3_cpuif.c
+++ b/hw/intc/arm_gicv3_cpuif.c
@@ -20,6 +20,11 @@
#include "hw/irq.h"
#include "cpu.h"
+void gicv3_set_cpustate(GICv3CPUState *s, CPUState *cpu)
+{
+ s->cpu = cpu;
+}
+
void gicv3_set_gicv3state(CPUState *cpu, GICv3CPUState *s)
{
ARMCPU *arm_cpu = ARM_CPU(cpu);
diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
index 05303a55c8..6e14a7a6cd 100644
--- a/hw/intc/gicv3_internal.h
+++ b/hw/intc/gicv3_internal.h
@@ -409,5 +409,6 @@ static inline void
gicv3_cache_all_target_cpustates(GICv3State *s)
}
void gicv3_set_gicv3state(CPUState *cpu, GICv3CPUState *s);
+void gicv3_set_cpustate(GICv3CPUState *s, CPUState *cpu);
#endif /* QEMU_ARM_GICV3_INTERNAL_H */
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index e8468d8cf6..c287433219 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -158,6 +158,7 @@ typedef struct {
DeviceState *gic;
DeviceState *acpi_dev;
Notifier powerdown_notifier;
+ NotifierList cpuhp_notifiers;
} VirtMachineState;
#define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
diff --git a/include/hw/intc/arm_gicv3_common.h
b/include/hw/intc/arm_gicv3_common.h
index 31ec9a1ae4..b51f74c728 100644
--- a/include/hw/intc/arm_gicv3_common.h
+++ b/include/hw/intc/arm_gicv3_common.h
@@ -248,6 +248,7 @@ struct GICv3State {
GICv3CPUState *gicd_irouter_target[GICV3_MAXIRQ];
uint32_t gicd_nsacr[DIV_ROUND_UP(GICV3_MAXIRQ, 16)];
+ Notifier cpu_update_notifier;
GICv3CPUState *cpu;
};
--
2.17.1
- [PATCH RFC 08/22] arm/cpuhp: Enable ACPI support for vcpu hotplug, (continued)
- [PATCH RFC 08/22] arm/cpuhp: Enable ACPI support for vcpu hotplug, Salil Mehta, 2020/06/13
- [PATCH RFC 09/22] arm/cpuhp: Init GED framework with cpu hotplug events, Salil Mehta, 2020/06/13
- [PATCH RFC 10/22] arm/cpuhp: Update CPUs AML with cpu-(ctrl)dev change, Salil Mehta, 2020/06/13
- [PATCH RFC 11/22] arm/cpuhp: Update GED _EVT method AML with cpu scan, Salil Mehta, 2020/06/13
- [PATCH RFC 12/22] arm/cpuhp: MADT Tbl change to size the guest with possible vcpus, Salil Mehta, 2020/06/13
- [PATCH RFC 13/22] arm/cpuhp: Add ACPI _MAT entry for Processor object, Salil Mehta, 2020/06/13
- [PATCH RFC 14/22] arm/cpuhp: Release objects for *disabled* possible vcpus after init, Salil Mehta, 2020/06/13
- [PATCH RFC 15/22] arm/cpuhp: Update ACPI GED framework to support vcpu hotplug, Salil Mehta, 2020/06/13
- [PATCH RFC 16/22] arm/cpuhp: Add/update basic hot-(un)plug framework, Salil Mehta, 2020/06/13
- [PATCH RFC 17/22] arm/cpuhp: Changes to (un)wire GICC<->VCPU IRQs during hot-(un)plug, Salil Mehta, 2020/06/13
- [PATCH RFC 18/22] arm/cpuhp: Changes to update GIC with vcpu hot-plug notification,
Salil Mehta <=
- [PATCH RFC 19/22] arm/cpuhp: Changes required to (re)init the vcpu register info, Salil Mehta, 2020/06/13
- [PATCH RFC 20/22] arm/cpuhp: Update the guest(via GED) about cpu hot-(un)plug events, Salil Mehta, 2020/06/13
- [PATCH RFC 21/22] arm/cpuhp: Changes required for reset and to support next boot, Salil Mehta, 2020/06/13
- [PATCH RFC 22/22] arm/cpuhp: Add support of *unrealize* ARMCPU during vcpu hot-unplug, Salil Mehta, 2020/06/13
- Re: [PATCH RFC 00/22] Support of Virtual CPU Hotplug for ARMv8 Arch, no-reply, 2020/06/13
- Re: [PATCH RFC 00/22] Support of Virtual CPU Hotplug for ARMv8 Arch, no-reply, 2020/06/13
- Re: [PATCH RFC 00/22] Support of Virtual CPU Hotplug for ARMv8 Arch, Marc Zyngier, 2020/06/14
- Re: [PATCH RFC 00/22] Support of Virtual CPU Hotplug for ARMv8 Arch, Andrew Jones, 2020/06/23