From 41346263c4039fd2edca61c031c9396577693036 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Thu, 12 May 2016 09:18:15 +0530 Subject: qdev: hotplug: Introduce HotplugHandler.pre_plug() callback pre_plug callback is to be called before device.realize() is executed. This would allow to check/set device's properties from HotplugHandler. Signed-off-by: Igor Mammedov Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Signed-off-by: David Gibson --- include/hw/hotplug.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index da1d0e4..c0db869 100644 --- a/include/hw/hotplug.h +++ b/include/hw/hotplug.h @@ -45,7 +45,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler, * hardware (un)plug functions. * * @parent: Opaque parent interface. - * @plug: plug callback. + * @pre_plug: pre plug callback called at start of device.realize(true) + * @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. @@ -58,6 +59,7 @@ typedef struct HotplugHandlerClass { InterfaceClass parent; /* */ + hotplug_fn pre_plug; hotplug_fn plug; hotplug_fn unplug_request; hotplug_fn unplug; @@ -73,6 +75,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp); /** + * hotplug_handler_pre_plug: + * + * Call #HotplugHandlerClass.pre_plug callback of @plug_handler. + */ +void hotplug_handler_pre_plug(HotplugHandler *plug_handler, + DeviceState *plugged_dev, + Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler. -- cgit v1.1 From f1020c2c2647a62df870ce243424ee23ea95ae6f Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Thu, 12 May 2016 09:18:16 +0530 Subject: cpu: Abstract CPU core type Add an abstract CPU core type that could be used by machines that want to define and hotplug CPUs in core granularity. Signed-off-by: Bharata B Rao Signed-off-by: Igor Mammedov [Integer core property] Reviewed-by: David Gibson Reviewed-by: Igor Mammedov [dwg: changed property names to 'core-id' and 'nr-threads'] Signed-off-by: David Gibson --- include/hw/cpu/core.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 include/hw/cpu/core.h (limited to 'include') diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h new file mode 100644 index 0000000..4540a7d --- /dev/null +++ b/include/hw/cpu/core.h @@ -0,0 +1,31 @@ +/* + * CPU core abstract device + * + * Copyright (C) 2016 Bharata B Rao + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef HW_CPU_CORE_H +#define HW_CPU_CORE_H + +#include "qemu/osdep.h" +#include "hw/qdev.h" + +#define TYPE_CPU_CORE "cpu-core" + +#define CPU_CORE(obj) \ + OBJECT_CHECK(CPUCore, (obj), TYPE_CPU_CORE) + +typedef struct CPUCore { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + int core_id; + int nr_threads; +} CPUCore; + +#define CPU_CORE_PROP_CORE_ID "core-id" + +#endif -- cgit v1.1 From 4a4b344c7ccdeac28c2e65e51ddbe3acfb41b883 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Thu, 12 May 2016 09:18:20 +0530 Subject: xics,xics_kvm: Handle CPU unplug correctly XICS is setup for each CPU during initialization. Provide a routine to undo the same when CPU is unplugged. While here, move ss->cs management into xics from xics_kvm since there is nothing KVM specific in it. Also ensure xics reset doesn't set irq for CPUs that are already unplugged. This allows reboot of a VM that has undergone CPU hotplug and unplug to work correctly. Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Signed-off-by: David Gibson --- include/hw/ppc/xics.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h index f60b06a..9091054 100644 --- a/include/hw/ppc/xics.h +++ b/include/hw/ppc/xics.h @@ -167,5 +167,6 @@ int xics_alloc_block(XICSState *icp, int src, int num, bool lsi, bool align, void xics_free(XICSState *icp, int irq, int num); void xics_cpu_setup(XICSState *icp, PowerPCCPU *cpu); +void xics_cpu_destroy(XICSState *icp, PowerPCCPU *cpu); #endif /* __XICS_H__ */ -- cgit v1.1 From aab99135b63522267c6fdae04712cb2f02c8c7de Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Thu, 12 May 2016 09:18:21 +0530 Subject: spapr_drc: Prevent detach racing against attach for CPU DR If a CPU is hot removed while hotplug of the same is still in progress, the guest crashes. Prevent this by ensuring that detach is done only after attach has completed. The existing code already prevents such race for PCI hotplug. However given that CPU is a logical DR unlike PCI and starts with ISOLATED state, we need a logic that works for CPU too. Signed-off-by: Bharata B Rao Reviewed-by: Michael Roth Signed-off-by: Michael Roth [Don't set awaiting_attach for PCI devices] Signed-off-by: David Gibson --- include/hw/ppc/spapr_drc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index fa21ba0..08e8411 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -152,6 +152,7 @@ typedef struct sPAPRDRConnector { bool awaiting_release; bool signalled; + bool awaiting_allocation; /* device pointer, via link property */ DeviceState *dev; -- cgit v1.1 From 3f97b53a682d2595747c926c00d78b9d406f1be0 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 10 Jun 2016 06:29:00 +0530 Subject: qom: API to get instance_size of a type Add an API object_type_get_size(const char *typename) that returns the instance_size of the give typename. Signed-off-by: Bharata B Rao Signed-off-by: David Gibson --- include/qom/object.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/qom/object.h b/include/qom/object.h index 99de539..2f8ac47 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1607,5 +1607,11 @@ int object_child_foreach_recursive(Object *obj, */ Object *container_get(Object *root, const char *path); - +/** + * object_type_get_instance_size: + * @typename: Name of the Type whose instance_size is required + * + * Returns the instance_size of the given @typename. + */ +size_t object_type_get_instance_size(const char *typename); #endif -- cgit v1.1 From 3b542549661eb216580e8b7683e13caa3950da45 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 10 Jun 2016 06:29:01 +0530 Subject: spapr: Abstract CPU core device and type specific core devices Add sPAPR specific abastract CPU core device that is based on generic CPU core device. Use this as base type to create sPAPR CPU specific core devices. TODO: - Add core types for other remaining CPU types - Handle CPU model alias correctly Signed-off-by: Bharata B Rao Signed-off-by: David Gibson --- include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 include/hw/ppc/spapr_cpu_core.h (limited to 'include') diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 3ac85c0..f597cc2 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -582,6 +582,7 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType drc_type, uint32_t count); void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type, uint32_t count); +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp); /* rtas-configure-connector state */ struct sPAPRConfigureConnectorState { diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h new file mode 100644 index 0000000..424edec --- /dev/null +++ b/include/hw/ppc/spapr_cpu_core.h @@ -0,0 +1,29 @@ +/* + * sPAPR CPU core device. + * + * Copyright (C) 2016 Bharata B Rao + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef HW_SPAPR_CPU_CORE_H +#define HW_SPAPR_CPU_CORE_H + +#include "hw/qdev.h" +#include "hw/cpu/core.h" +#include "target-ppc/cpu-qom.h" + +#define TYPE_SPAPR_CPU_CORE "spapr-cpu-core" +#define SPAPR_CPU_CORE(obj) \ + OBJECT_CHECK(sPAPRCPUCore, (obj), TYPE_SPAPR_CPU_CORE) + +typedef struct sPAPRCPUCore { + /*< private >*/ + CPUCore parent_obj; + + /*< public >*/ + void *threads; + ObjectClass *cpu_class; +} sPAPRCPUCore; + +#endif -- cgit v1.1 From afd10a0fa6e90b79bad981c7334df2995d667de2 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 10 Jun 2016 06:29:02 +0530 Subject: spapr: Move spapr_cpu_init() to spapr_cpu_core.c Start consolidating CPU init related routines in spapr_cpu_core.c. As part of this, move spapr_cpu_init() and its dependencies from spapr.c to spapr_cpu_core.c No functionality change in this patch. Signed-off-by: Bharata B Rao [dwg: Rename TIMEBASE_FREQ to SPAPR_TIMEBASE_FREQ, since it's now in a public(ish) header] Signed-off-by: David Gibson --- include/hw/ppc/spapr.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index f597cc2..3277692 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -16,6 +16,8 @@ typedef struct sPAPREventLogEntry sPAPREventLogEntry; #define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL #define SPAPR_ENTRY_POINT 0x100 +#define SPAPR_TIMEBASE_FREQ 512000000ULL + typedef struct sPAPRMachineClass sPAPRMachineClass; typedef struct sPAPRMachineState sPAPRMachineState; -- cgit v1.1 From 94a94e4c49197d10e5ee7710bb0538ddeff75ba9 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 10 Jun 2016 06:29:03 +0530 Subject: spapr: convert boot CPUs into CPU core devices Introduce sPAPRMachineClass.dr_cpu_enabled to indicate support for CPU core hotplug. Initialize boot time CPUs as core deivces and prevent topologies that result in partially filled cores. Both of these are done only if CPU core hotplug is supported. Note: An unrelated change in the call to xics_system_init() is done in this patch as it makes sense to use the local variable smt introduced in this patch instead of kvmppc_smt_threads() call here. TODO: We derive sPAPR core type by looking at -cpu . However we don't take care of "compat=" feature yet for boot time as well as hotplug CPUs. Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Signed-off-by: David Gibson --- include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 3 +++ 2 files changed, 5 insertions(+) (limited to 'include') diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 3277692..2a892bd 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -38,6 +38,7 @@ struct sPAPRMachineClass { /*< public >*/ bool dr_lmb_enabled; /* enable dynamic-reconfig/hotplug of LMBs */ + bool dr_cpu_enabled; /* enable dynamic-reconfig/hotplug of CPUs */ bool use_ohci_by_default; /* use USB-OHCI instead of XHCI */ }; @@ -81,6 +82,7 @@ struct sPAPRMachineState { /*< public >*/ char *kvm_type; MemoryHotplugState hotplug_memory; + Object **cores; }; #define H_SUCCESS 0 diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index 424edec..401381b 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -26,4 +26,7 @@ typedef struct sPAPRCPUCore { ObjectClass *cpu_class; } sPAPRCPUCore; +void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp); +char *spapr_get_cpu_core_type(const char *model); #endif -- cgit v1.1 From af81cf323c17083a3e016f9556c521357b46ab40 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 10 Jun 2016 06:29:04 +0530 Subject: spapr: CPU hotplug support Set up device tree entries for the hotplugged CPU core and use the exising RTAS event logging infrastructure to send CPU hotplug notification to the guest. Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Signed-off-by: David Gibson --- include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'include') diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 2a892bd..e1f8274 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -587,6 +587,8 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType drc_type, void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type, uint32_t count); void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp); +void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset, + sPAPRMachineState *spapr); /* rtas-configure-connector state */ struct sPAPRConfigureConnectorState { diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index 401381b..7cb0515 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -29,4 +29,6 @@ typedef struct sPAPRCPUCore { void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); char *spapr_get_cpu_core_type(const char *model); +void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp); #endif -- cgit v1.1 From 6f4b5c3ec590b04ba58fda753a81a93f316b77a4 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Fri, 10 Jun 2016 06:29:05 +0530 Subject: spapr: CPU hot unplug support Remove the CPU core device by removing the underlying CPU thread devices. Hot removal of CPU for sPAPR guests is achieved by sending the hot unplug notification to the guest. Release the vCPU object after CPU hot unplug so that vCPU fd can be parked and reused. Signed-off-by: Bharata B Rao Signed-off-by: David Gibson --- include/hw/ppc/spapr_cpu_core.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index 7cb0515..1c9b319 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -31,4 +31,6 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, char *spapr_get_cpu_core_type(const char *model); void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); +void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp); #endif -- cgit v1.1 From d4633541ee0ec266ef4e55e1d71a98a18762d80c Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Fri, 10 Jun 2016 06:29:06 +0530 Subject: QMP: Add query-hotpluggable-cpus It will allow mgmt to query present and hotpluggable CPU objects, it is required from a target platform that wishes to support command to implement and set MachineClass.query_hotpluggable_cpus callback, which will return a list of possible CPU objects with options that would be needed for hotplugging possible CPU objects. There are: 'type': 'str' - QOM CPU object type for usage with device_add 'vcpus-count': 'int' - number of logical VCPU threads per CPU object (mgmt needs to know) and a set of optional fields that are to used for hotplugging a CPU objects and would allows mgmt tools to know what/where it could be hotplugged; [node],[socket],[core],[thread] For present CPUs there is a 'qom-path' field which would allow mgmt to inspect whatever object/abstraction the target platform considers as CPU object. Signed-off-by: Igor Mammedov Signed-off-by: Bharata B Rao Reviewed-by: David Gibson Signed-off-by: David Gibson --- include/hw/boards.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/hw/boards.h b/include/hw/boards.h index d268bd0..3ed6155 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -81,6 +81,10 @@ typedef struct { * Returns an array of @CPUArchId architecture-dependent CPU IDs * which includes CPU IDs for present and possible to hotplug CPUs. * Caller is responsible for freeing returned list. + * @query_hotpluggable_cpus: + * Returns a @HotpluggableCPUList, which describes CPUs objects which + * could be added with -device/device_add. + * Caller is responsible for freeing returned list. */ struct MachineClass { /*< private >*/ @@ -124,6 +128,7 @@ struct MachineClass { DeviceState *dev); unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); + HotpluggableCPUList *(*query_hotpluggable_cpus)(MachineState *machine); }; /** -- cgit v1.1