CPU hotplug for qemu-xen for 4.3.
v2 cover CPU hotplug for qemu-xen for 4.3.
Hi all,
This series back-port recently added QEMU patches to our qemu-xen. The interface between the guest and QEMU is the same as with qemu-traditional. Only the interface between libxl and qemu change, instead of xenstore we are using QMP to hotplug vcpus.
Three more patches will follow this series.
- two for libxl which implement the QMP command cpu-add.
- one for SeaBIOS which workaround a bug.
When using adding vcpus with this series, libxl will report many "error". This is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even those that have been plugged before. There is currently no way to list cpus that are plugged by QEMU. Also, the ways errors are handle by libxl_qmp those not help yet to suppress this error printing.
Unplug of vcpu is not supported by the series.
Change since the first set:
- back-port of QEMU patches instead of forth-port from qemu-traditional
- added a SeaBIOS patch
Regards,
Anthony PERARD (2):
xen: Fix vcpus initialisation.
xen: Implement hot_add_cpu hook.
Igor Mammedov (4):
cpu: Introduce get_arch_id() method and override it for X86CPU
acpi_piix4: Add infrastructure to send CPU hot-plug GPE to guest Add hot_add_cpu hook to QEMUMachine
QMP: Add cpu-add command
Michael S. Tsirkin (1):
cpu: Add qemu_for_each_cpu()
docs/specs/acpi_cpu_hotplug.txt | 22 +++++++++ exec.c | 10 ++++ hw/acpi_piix4.c | 101 +++++++++++++++++++++++++++++++++++++++- hw/boards.h | 3 ++ hw/pc_piix.c | 1 + include/qemu/cpu.h | 11 +++++ qapi-schema.json | 13 ++++++ qmp-commands.hx | 23 +++++++++ qmp.c | 10 ++++ qom/cpu.c | 8 ++++ sysemu.h | 2 + target-i386/cpu.c | 10 ++++ xen-all.c | 8 ++-- 13 files changed, 216 insertions(+), 6 deletions(-) create mode 100644 docs/specs/acpi_cpu_hotplug.txt
Signature · 1 line
Anthony PERARD
PATCH v2 1/7 cpu: Introduce get_arch_id() method and override it for X86CPU
From: Igor Mammedov <[email protected]>
get_arch_id() adds possibility for generic code to get a guest-visible CPU ID without accessing CPUArchState.
If derived classes don't override it, it will return cpu_index.
Override it on target-i386 in X86CPU to return the APIC ID.
(cherry picked from QEMU commit 997395d3888fcde6ce41535a8208d7aa919d824b)
--- include/qemu/cpu.h | 2 ++ qom/cpu.c | 8 ++++++++ target-i386/cpu.c | 10 ++++++++++ 3 files changed, 20 insertions(+)
include/qemu/cpu.h +2 -0
@@ -41,6 +41,7 @@ typedef struct CPUState CPUState;/** * CPUClass: * @reset: Callback to reset the #CPUState to its initial state. +* @get_arch_id: Callback for getting architecture-dependent CPU ID. * * Represents a CPU family or model. */
@@ -50,6 +51,7 @@ typedef struct CPUClass {/*< public >*/ void (*reset)(CPUState *cpu); +int64_t (*get_arch_id)(CPUState *cpu); } CPUClass;/**
qom/cpu.c +8 -0
@@ -34,11 +34,19 @@ static void cpu_common_reset(CPUState *cpu) { } +static int64_t cpu_common_get_arch_id (CPUState *cpu) +{ +/* Not used in Xen, so no backport. +* There is a missing cpu_index field in CPUState. */ +abort (); +} +static void cpu_class_init (ObjectClass *klass,void *data) {CPUClass *k =CPU_CLASS (klass); k->reset = cpu_common_reset; + k->get_arch_id = cpu_common_get_arch_id; }static TypeInfo cpu_type_info = {
target-i386/cpu.c +10 -0
@@ -2111,6 +2111,14 @@ static void x86_cpu_initfn(Object *obj) } } +static int64_t x86_cpu_get_arch_id (CPUState *cs) +{ +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; + +return env->cpuid_apic_id; +} +static void x86_cpu_common_class_init (ObjectClass *oc,void *data) {X86CPUClass *xcc =X86_CPU_CLASS (oc);
@@ -2118,6 +2126,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) xcc->parent_reset = cc->reset; cc->reset = x86_cpu_reset; + + cc->get_arch_id = x86_cpu_get_arch_id; }static const TypeInfo x86_cpu_type_info = {
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 2/7 cpu: Add qemu_for_each_cpu()
From: "Michael S. Tsirkin" <[email protected]>
Wrapper to avoid open-coded loops and to make CPUState iteration independent of CPUArchState.
(cherry picked from QEMU commit d6b9e0d60cc511eca210834428bb74508cff3d33)
--- exec.c | 10 ++++++++++ include/qemu/cpu.h | 9 +++++++++ 2 files changed, 19 insertions(+)
exec.c +10 -0
@@ -692,6 +692,16 @@ CPUArchState *qemu_get_cpu(int cpu)return env; } +void qemu_for_each_cpu (void (*func)(CPUState *cpu,void *data),void *data) +{ +CPUArchState *env = first_cpu; + +while (env) { +func (ENV_GET_CPU (env), data); + env = env->next_cpu; + } +} +void cpu_exec_init (CPUArchState *env) {#ifndef CONFIG_USER_ONLY
include/qemu/cpu.h +9 -0
@@ -138,5 +138,14 @@ bool cpu_is_stopped(CPUState *cpu);*/ void run_on_cpu (CPUState *cpu,void (*func)(void *data),void *data); +/** +* qemu_for_each_cpu: +* @func: The function to be executed. +* @data: Data to pass to the function. +* +* Executes @func for each CPU. +*/ +void qemu_for_each_cpu (void (*func)(CPUState *cpu,void *data),void *data); +#endif
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 3/7 acpi_piix4: Add infrastructure to send CPU hot-plug GPE to guest
In reply to Anthony PERARDFrom: Igor Mammedov <[email protected]>
* introduce processor status bitmask visible to guest at 0xaf00 addr, where ACPI asl code expects it
* set bit corresponding to APIC ID in processor status bitmask on receiving CPU hot-plug notification
* trigger CPU hot-plug SCI, to notify guest about CPU hot-plug event
(cherry picked from QEMU commit b8622725cf0196f672f272922b0941dc8ba1c408)
The function piix4_cpu_hotplug_req() has been modified to take an integer instead of a CPU object.
There was a cpu_added_notifier in the original commit, this haven't been back-ported, as it can't be used.
--- docs/specs/acpi_cpu_hotplug.txt | 22 ++++++++++++ hw/acpi_piix4.c | 80 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 docs/specs/acpi_cpu_hotplug.txt
docs/specs/acpi_cpu_hotplug.txt new file +22 -0
@@ -0,0 +1,22 @@ +QEMU<->ACPI BIOS CPU hotplug interface +-------------------------------------- + +QEMU supports CPU hotplug via ACPI. This document +describes the interface between QEMU and the ACPI BIOS. + +ACPI GPE block (IO ports 0xafe0-0xafe3, byte access): +----------------------------------------- + +Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU +hot-add/remove event to ACPI BIOS, via SCI interrupt. + +CPU present bitmap (IO port 0xaf00-0xae1f, 1-byte access): +--------------------------------------------------------------- +One bit per CPU. Bit position reflects corresponding CPU APIC ID. +Read-only. + +CPU hot-add/remove notification: +----------------------------------------------------- +QEMU sets/clears corresponding CPU bit on hot-add/remove event. +CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU +hot-(un)plug events.
hw/acpi_piix4.c +78 -2
126 lines not on this page · raw message
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 4/7 Add hot_add_cpu hook to QEMUMachine
In reply to Anthony PERARDFrom: Igor Mammedov <[email protected]>
Hook should be set by machines that implement CPU hot-add via cpu-add QMP command.
(cherry picked from QEMU commit b4fc7b4326112538e0dbdc7fd019652ba8cc3281)
--- hw/boards.h | 3 +++ 1 file changed, 3 insertions(+)
hw/boards.h +3 -0
@@ -18,6 +18,8 @@ typedef void QEMUMachineInitFunc(QEMUMachineInitArgs *args);typedef void QEMUMachineResetFunc (void ); +typedef void QEMUMachineHotAddCPUFunc (const int64_t id,Error **errp); + typedef struct QEMUMachine { const char *name; const char *alias;
@@ -25,6 +27,7 @@ typedef struct QEMUMachine {QEMUMachineInitFunc *init;QEMUMachineResetFunc *reset;int use_scsi; +QEMUMachineHotAddCPUFunc *hot_add_cpu;int max_cpus; unsigned int no_serial:1, no_parallel:1,
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 5/7 QMP: Add cpu-add command
In reply to Anthony PERARDFrom: Igor Mammedov <[email protected]>
Adds "cpu-add id=xxx" QMP command.
cpu-add's "id" argument is a CPU number in a range [0..max-cpus)
Example QMP command:
-> { "execute": "cpu-add", "arguments": { "id": 2 } } <- { "return": {} }
(cherry picked from QEMU commit 69ca3ea5e192251f27510554611bcff6f036a00b)
--- qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 23 +++++++++++++++++++++++ qmp.c | 10 ++++++++++ 3 files changed, 46 insertions(+)
qapi-schema.json +13 -0
@@ -1284,6 +1284,19 @@ { 'command': 'cpu', 'data': {'index': 'int'} } ## +# @cpu-add +# +# Adds CPU with specified ID +# +# @id: ID of CPU to be created, valid values [0..max_cpus) +# +# Returns: Nothing on success +# +# Since 1.5 +## +{ 'command': 'cpu-add', 'data': {'id': 'int'} } + +## # @memsave: # # Save a portion of guest memory to a file.
qmp-commands.hx +23 -0
@@ -385,6 +385,29 @@ Note: CPUs' indexes are obtained with the 'query-cpus' command. EQMP { + .name = "cpu-add", + .args_type = "id:i", + .mhandler.cmd_new = qmp_marshal_input_cpu_add, + }, + +SQMP +cpu-add +------- + +Adds virtual cpu + +Arguments: + +- "id": cpu id (json-int) + +Example: + +-> { "execute": "cpu-add", "arguments": { "id": 2 } } +<- { "return": {} } + +EQMP + + { .name = "memsave", .args_type = "val:l,size:i,filename:s,cpu:i?", .mhandler.cmd_new = qmp_marshal_input_memsave,
qmp.c +10 -0
@@ -23,6 +23,7 @@#include "hw/qdev.h" #include "blockdev.h" #include "qemu/qom-qobject.h" +#include "hw/boards.h" NameInfo *qmp_query_name (Error **errp) {
@@ -107,6 +108,15 @@ void qmp_cpu(int64_t index, Error **errp)/* Just do nothing */ } +void qmp_cpu_add (int64_t id,Error **errp) +{ +if (current_machine->hot_add_cpu) { + current_machine->hot_add_cpu (id, errp); + }else { +error_setg (errp,"Not supported" ); + } +} +#ifndef CONFIG_VNC /* If VNC support is enabled, the "true" query-vnc command is defined in the VNC subsystem */
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 6/7 xen: Fix vcpus initialisation.
In reply to Anthony PERARDEach vcpu needs a call to xc_evtchn_bind_interdomain in QEMU, even those that are unplug at QEMU initialisation.
Without this patch, any hot-plugged CPU will be "Stuck ??" when Linux will try to use them.
--- xen-all.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen-all.c +4 -4
@@ -632,13 +632,13 @@ static ioreq_t *cpu_get_ioreq(XenIOState *state) }if (port !=-1 ) { -for (i =0 ; i < smp_cpus; i++) { +for (i =0 ; i < max_cpus; i++) {if (state->ioreq_local_port[i] == port) {break ; } } -if (i == smp_cpus) { +if (i == max_cpus) {hw_error ("Fatal error while trying to get io event!\n" ); }
@@ -1123,10 +1123,10 @@ int xen_hvm_init(void)hw_error ("map buffered IO page returned error %d" , errno); } - state->ioreq_local_port =g_malloc0 (smp_cpus *sizeof (evtchn_port_t)); + state->ioreq_local_port =g_malloc0 (max_cpus *sizeof (evtchn_port_t));/* FIXME: how about if we overflow the page here? */ -for (i =0 ; i < smp_cpus; i++) { +for (i =0 ; i < max_cpus; i++) { rc =xc_evtchn_bind_interdomain (state->xce_handle, xen_domid,xen_vcpu_eport (state->shared_page, i));if (rc ==-1 ) {
Signature · 1 line
Anthony PERARD
PATCH v2 7/7 xen: Implement hot_add_cpu hook.
In reply to Anthony PERARD--- hw/acpi_piix4.c | 21 +++++++++++++++++++++ hw/pc_piix.c | 1 + sysemu.h | 2 ++ 3 files changed, 24 insertions(+)
hw/acpi_piix4.c +21 -0
@@ -662,6 +662,26 @@ static void piix4_cpu_hotplug_req(PIIX4PMState *s, int64_t cpu_id,pm_update_sci (s); } +static PIIX4PMState *piix4pm_state; +void piix4_cpu_hotplug_add (const int64_t cpu_id,Error **errp) +{ +CPUStatus *g = &piix4pm_state->gpe_cpu; + +if (cpu_id >= max_cpus) { +error_setg (errp,"Unable to add CPU: %" PRIi64 +", max allowed: %d" , cpu_id, max_cpus -1 ); +return ; + } +if (g->sts[cpu_id /8 ] & (1 << (cpu_id %8 ))) { +/* Already requested to be hotplug. */ +error_setg (errp,"Unable to add CPU: %" PRIi64 +", it already exists" , cpu_id); +return ; + } + +piix4_cpu_hotplug_req (piix4pm_state, cpu_id,PLUG ); +} +static void piix4_init_cpu_status (CPUState *cpu,void *data) {CPUStatus *g = (CPUStatus *)data;
@@ -697,6 +717,7 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s) PIIX4_PROC_LEN);memory_region_add_subregion (pci_address_space_io (&s->dev),PIIX4_PROC_BASE , &s->io_cpu); + piix4pm_state = s; }static void enable_device (PIIX4PMState *s,int slot)
hw/pc_piix.c +1 -0
@@ -621,6 +621,7 @@ static QEMUMachine xenfv_machine = { .init = pc_xen_hvm_init, .max_cpus = HVM_MAX_VCPUS, .default_machine_opts = "accel=xen", + .hot_add_cpu = piix4_cpu_hotplug_add, };#endif
sysemu.h +2 -0
@@ -183,4 +183,6 @@ char *get_boot_devices_list(uint32_t *size);bool usb_enabled (bool default_usb); +void piix4_cpu_hotplug_add (const int64_t cpu_id,Error **errp); +#endif
Signature · 1 line
Anthony PERARD
PATCH v2 1/2 libxl: Add "cpu-add" QMP command.
In reply to Anthony PERARD--- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_qmp.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
tools/libxl/libxl_internal.h +2 -0
@@ -1412,6 +1412,8 @@ _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename);/* Set dirty bitmap logging status */ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable); _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk); +/* Add a virtual CPU */ +_hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index);/* close and free the QMP handler */ _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);/* remove the socket file, if the file has already been removed,
tools/libxl/libxl_qmp.c +21 -0
@@ -668,6 +668,18 @@ static void qmp_parameters_add_bool(libxl__gc *gc,qmp_parameters_common_add (gc, param, name, obj); } +static void qmp_parameters_add_integer (libxl__gc *gc, +libxl__json_object **param, +const char *name,const int i) +{ +libxl__json_object *obj; + + obj =libxl__json_object_alloc (gc,JSON_INTEGER ); + obj->u.i = i; + +qmp_parameters_common_add (gc, param, name, obj); +} +#define QMP_PARAMETERS_SPRINTF (args, name, format, ...) \ qmp_parameters_add_string(gc, args, name, \ libxl__sprintf(gc, format, __VA_ARGS__))
@@ -929,6 +941,15 @@ int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, } } +int libxl__qmp_cpu_add (libxl__gc *gc,int domid,int index) +{ +libxl__json_object *args =NULL ; + +qmp_parameters_add_integer (gc, &args,"id" , index); + +return qmp_run_command (gc, domid,"cpu-add" , args,NULL ,NULL ); +} +int libxl__qmp_initializations (libxl__gc *gc,uint32_t domid,const libxl_domain_config *guest_config) {
Signature · 1 line
Anthony PERARD
PATCH v2 2/2 libxl: Use QMP cpu-add to hotplug CPU with qemu-xen.
--- tools/libxl/libxl.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
tools/libxl/libxl.c +40 -1
@@ -4237,7 +4237,8 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,return 0 ; } -int libxl_set_vcpuonline (libxl_ctx *ctx,uint32_t domid,libxl_bitmap *cpumap) +static int libxl__set_vcpuonline_xenstore (libxl_ctx *ctx,uint32_t domid, +libxl_bitmap *cpumap) {GC_INIT (ctx);libxl_dominfo info;
@@ -4268,6 +4269,44 @@ out:return rc; } +static int libxl__set_vcpuonline_qmp (libxl__gc *gc,uint32_t domid, +libxl_bitmap *cpumap) +{ +libxl_dominfo info; +int i, rc =0 ; + +if (libxl_domain_info (CTX , &info, domid) <0 ) { +LIBXL__LOG_ERRNO (CTX ,LIBXL__LOG_ERROR ,"getting domain info list" ); + rc =ERROR_FAIL ; + goto out; + } +for (i =0 ; i <= info.vcpu_max_id; i++) { +if (libxl_bitmap_test (cpumap, i)) { + rc =libxl__qmp_cpu_add (gc, domid, i); + } + } +out: +return rc; +} + +int libxl_set_vcpuonline (libxl_ctx *ctx,uint32_t domid,libxl_bitmap *cpumap) +{ +GC_INIT (ctx); +int rc; +switch (libxl__device_model_version_running (gc, domid)) { +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : + rc =libxl__set_vcpuonline_xenstore (ctx, domid, cpumap); +break ; +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : + rc =libxl__set_vcpuonline_qmp (gc, domid, cpumap); +break ; +default : + rc =ERROR_INVAL ; + } +GC_FREE ; +return rc; +} +libxl_scheduler libxl_get_scheduler (libxl_ctx *ctx) {libxl_scheduler sched, ret;
Signature · 1 line
Anthony PERARD
PATCH v2 1/1 xen: Allow CPU to be counted than currently "plugged".
In reply to Anthony PERARDUnder Xen, SeaBIOS can count more CPU than there should be. This patch will allow more CPU to come up instead of going to infinite loop waiting for the CPU counter to be decremented.
--- src/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/smp.c +1 -1
@@ -132,7 +132,7 @@ smp_probe(void)msleep (10 ); }else {u8 cmos_smp_count =inb_cmos (CMOS_BIOS_SMP_COUNT ); -while (cmos_smp_count +1 !=readl (&CountCPUs)) +while (cmos_smp_count +1 >readl (&CountCPUs))yield (); }
Signature · 1 line
Anthony PERARD
Re: [PATCH v2] xen: Allow CPU to be counted than currently "plugged".
Quoted 3 lines · Anthony PERARD
Under Xen, SeaBIOS can count more CPU than there should be. This patch will allow more CPU to come up instead of going to infinite loop waiting for the CPU counter to be decremented.
Current upstream SeaBIOS has this very different and only runs this loop on Qemu.
At a minimum I think we would need to backport:
5dbf173 Only perform SMP setup on QEMU.
897fb11 Consistently use CONFIG_COREBOOT, CONFIG_QEMU, and runningOnXen().
We've currently got SeaBIOS 1.7.1 in our tree and these are only in the master branch, but I think backporting is the way to go.
Hrm, 897fb11 doesn't backport cleanly (lots of changes) and without it 5dbf173 doesn't backport cleanly either. But I think the net affect when running on Xen would be the same as the following, can you try it?
src/smp.c +3 -0
@@ -84,6 +84,9 @@ int apic_id_is_present(u8 apic_id)void smp_probe (void ) { +if (usingXen ()) +return ; +ASSERT32FLAT ();u32 eax, ebx, ecx, cpuid_features;cpuid (1 , &eax, &ebx, &ecx, &cpuid_features);
Re: [PATCH v2 1/2] libxl: Add "cpu-add" QMP command.
In reply to Anthony PERARDQuoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>
I suppose I should hold off applying until the qemu side is approved etc.
Ian.
Re: [PATCH v2 1/2] libxl: Add "cpu-add" QMP command.
Quoted 7 lines · Ian Campbell
Quoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>Acked-by Ian Campbell <[email protected]>I suppose I should hold off applying until the qemu side is approved etc.
Well, there will be an error message "explaining" that does not know anything about "cpu-add". So nothing will happen.
Signature · 1 line
Anthony PERARD
Re: [PATCH v2 2/2] libxl: Use QMP cpu-add to hotplug CPU with qemu-xen.
In reply to Anthony PERARDQuoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>
I'm not sure but I think we might want to do both the xenstore and the qmp thing on qemu-xen for the benefit of PVHVM guests. I've added Konrad to the CC.
Quoted 9 lines
--- tools/libxl/libxl.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)tools/libxl/libxl.c +0
-0
tools/libxl/libxl.c int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid, · line 4241
Quoted 6 lines
tools/libxl/libxl.c +2
-1@@ -4237,7 +4237,8 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,return 0 ; } -int libxl_set_vcpuonline (libxl_ctx *ctx,uint32_t domid,libxl_bitmap *cpumap) +static int libxl__set_vcpuonline_xenstore (libxl_ctx *ctx,uint32_t domid, +libxl_bitmap *cpumap)
It's a bit tedious but really you ought to make this take a gc not a ctx when you internalise it. You can start the function with "libxl__ctx*ctx = libxl__gc_owner(gc)", or s/ctx/CTX/ in the body.
Quoted 5 lines
tools/libxl/libxl.c +0
-0{GC_INIT (ctx);libxl_dominfo info;@@ -4268,6 +4269,44 @@ out:return rc;
tools/libxl/libxl.c out: · line 4279
Quoted 10 lines
tools/libxl/libxl.c +8
-0} +static int libxl__set_vcpuonline_qmp (libxl__gc *gc,uint32_t domid, +libxl_bitmap *cpumap) +{ +libxl_dominfo info; +int i, rc =0 ; + +if (libxl_domain_info (CTX , &info, domid) <0 ) { +LIBXL__LOG_ERRNO (CTX ,LIBXL__LOG_ERROR ,"getting domain info list" );
The LOG() macros is useful here.
Quoted 11 lines
tools/libxl/libxl.c +11
-0+ rc =ERROR_FAIL ; + goto out; + } +for (i =0 ; i <= info.vcpu_max_id; i++) { +if (libxl_bitmap_test (cpumap, i)) { + rc =libxl__qmp_cpu_add (gc, domid, i); + } + } +out: +return rc; +}
Re: [PATCH v2 1/2] libxl: Add "cpu-add" QMP command.
In reply to Anthony PERARDQuoted 11 lines · Anthony PERARD
Quoted 7 lines · Ian Campbell
Quoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>Acked-by Ian Campbell <[email protected]>I suppose I should hold off applying until the qemu side is approved etc.
Well, there will be an error message "explaining" that does not know anything about "cpu-add". So nothing will happen.
I meant more from the point of view of agreeing both sides of the protocol before proceeding.
Ian.
Re: [PATCH v2] xen: Allow CPU to be counted than currently "plugged".
In reply to Ian CampbellQuoted 26 lines · Ian Campbell
Quoted 3 lines · Anthony PERARD
Under Xen, SeaBIOS can count more CPU than there should be. This patch will allow more CPU to come up instead of going to infinite loop waiting for the CPU counter to be decremented.
Current upstream SeaBIOS has this very different and only runs this loop on Qemu.
At a minimum I think we would need to backport:
5dbf173 Only perform SMP setup on QEMU.
897fb11 Consistently useCONFIG_COREBOOT,CONFIG_QEMU, andrunningOnXen().We've currently got SeaBIOS 1.7.1 in our tree and these are only in the master branch, but I think backporting is the way to go.
Hrm, 897fb11 doesn't backport cleanly (lots of changes) and without it 5dbf173 doesn't backport cleanly either. But I think the net affect when running on Xen would be the same as the following, can you try it?
src/smp.c +0
-0
src/smp.c int apic_id_is_present(u8 apic_id) · line 92
Quoted 9 lines
src/smp.c +3
-0@@ -84,6 +84,9 @@ int apic_id_is_present(u8 apic_id)void smp_probe (void ) { +if (usingXen ()) +return ; +ASSERT32FLAT ();u32 eax, ebx, ecx, cpuid_features;cpuid (1 , &eax, &ebx, &ecx, &cpuid_features);
This patch definitely works. It was one of my two choices.
I though the other approch was better because of mtrr_setup() called before this function, and some mtrr stuff in this function, but I did not realize that mtrr_setup is not doing anything under Xen. So this patch (no smp_probe) is better.
Signature · 1 line
Anthony PERARD
Re: [PATCH v2 2/2] libxl: Use QMP cpu-add to hotplug CPU with qemu-xen.
In reply to Ian CampbellQuoted 6 lines · Ian Campbell
Quoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>I'm not sure but I think we might want to do both the xenstore and the qmp thing on qemu-xen for the benefit of PVHVM guests. I've added Konrad to the CC.
ok, that should be not to complicated to do, if necessary.
Quoted 12 lines
Quoted 12 lines
--- tools/libxl/libxl.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)tools/libxl/libxl.c +0
-0@@ -4237,7 +4237,8 @@ int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,return 0 ; }
Quoted 7 lines
tools/libxl/libxl.c int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid, · line 4241
Quoted 3 lines
tools/libxl/libxl.c +2
-1-int libxl_set_vcpuonline (libxl_ctx *ctx,uint32_t domid,libxl_bitmap *cpumap) +static int libxl__set_vcpuonline_xenstore (libxl_ctx *ctx,uint32_t domid, +libxl_bitmap *cpumap)It's a bit tedious but really you ought to make this take a gc not a ctx when you internalise it. You can start the function with "libxl__ctx*ctx =
libxl__gc_owner(gc)", or s/ctx/CTX/ in the body.
OK, will change this.
Quoted 7 lines
Quoted 7 lines
tools/libxl/libxl.c +0
-0{GC_INIT (ctx);libxl_dominfo info;@@ -4268,6 +4269,44 @@ out:return rc; }
Quoted 10 lines
tools/libxl/libxl.c out: · line 4279
Quoted 8 lines
tools/libxl/libxl.c +8
-0+static int libxl__set_vcpuonline_qmp (libxl__gc *gc,uint32_t domid, +libxl_bitmap *cpumap) +{ +libxl_dominfo info; +int i, rc =0 ; + +if (libxl_domain_info (CTX , &info, domid) <0 ) { +LIBXL__LOG_ERRNO (CTX ,LIBXL__LOG_ERROR ,"getting domain info list" );The
LOG()macros is useful here.
will change this.
Quoted 13 lines
Quoted 11 lines
tools/libxl/libxl.c +11
-0+ rc =ERROR_FAIL ; + goto out; + } +for (i =0 ; i <= info.vcpu_max_id; i++) { +if (libxl_bitmap_test (cpumap, i)) { + rc =libxl__qmp_cpu_add (gc, domid, i); + } + } +out: +return rc; +}
Signature · 1 line
Anthony PERARD
Re: [PATCH v2 2/2] libxl: Use QMP cpu-add to hotplug CPU with qemu-xen.
Quoted 9 lines · Anthony PERARD
Quoted 6 lines · Ian Campbell
Quoted 1 line · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>I'm not sure but I think we might want to do both the xenstore and the qmp thing on qemu-xen for the benefit of PVHVM guests. I've added Konrad to the CC.
ok, that should be not to complicated to do, if necessary.
PV on HVM guests use the emulated path for cpu hotplug.
Re: [PATCH 6/7] xen: Fix vcpus initialisation.
In reply to Anthony PERARDQuoted 7 lines · Anthony PERARD
Each vcpu needs a call to
xc_evtchn_bind_interdomainin QEMU, even those that are unplug at QEMU initialisation.Without this patch, any hot-plugged CPU will be "Stuck ??" when Linux will try to use them.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 39 lines
xen-all.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)xen-all.c +4
-4@@ -632,13 +632,13 @@ static ioreq_t *cpu_get_ioreq(XenIOState *state) }if (port !=-1 ) { -for (i =0 ; i < smp_cpus; i++) { +for (i =0 ; i < max_cpus; i++) {if (state->ioreq_local_port[i] == port) {break ; } } -if (i == smp_cpus) { +if (i == max_cpus) {hw_error ("Fatal error while trying to get io event!\n" ); }@@ -1123,10 +1123,10 @@ int xen_hvm_init(void)hw_error ("map buffered IO page returned error %d" , errno); } - state->ioreq_local_port =g_malloc0 (smp_cpus *sizeof (evtchn_port_t)); + state->ioreq_local_port =g_malloc0 (max_cpus *sizeof (evtchn_port_t));/* FIXME: how about if we overflow the page here? */ -for (i =0 ; i < smp_cpus; i++) { +for (i =0 ; i < max_cpus; i++) { rc =xc_evtchn_bind_interdomain (state->xce_handle, xen_domid,xen_vcpu_eport (state->shared_page, i));if (rc ==-1 ) {Signature · 1 line
Anthony PERARD
Re: [PATCH 7/7] xen: Implement hot_add_cpu hook.
In reply to Anthony PERARDCan't we just call pc_new_cpu and cpu_x86_create like upstream QEMU does?
Are there any reasons why we can't introduce the same cpu_added_notifier that is upstream?
Quoted 72 lines · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>--- hw/acpi_piix4.c | 21 +++++++++++++++++++++ hw/pc_piix.c | 1 + sysemu.h | 2 ++ 3 files changed, 24 insertions(+)hw/acpi_piix4.c +21
-0@@ -662,6 +662,26 @@ static void piix4_cpu_hotplug_req(PIIX4PMState *s, int64_t cpu_id,pm_update_sci (s); } +static PIIX4PMState *piix4pm_state; +void piix4_cpu_hotplug_add (const int64_t cpu_id,Error **errp) +{ +CPUStatus *g = &piix4pm_state->gpe_cpu; + +if (cpu_id >= max_cpus) { +error_setg (errp,"Unable to add CPU: %" PRIi64 +", max allowed: %d" , cpu_id, max_cpus -1 ); +return ; + } +if (g->sts[cpu_id /8 ] & (1 << (cpu_id %8 ))) { +/* Already requested to be hotplug. */ +error_setg (errp,"Unable to add CPU: %" PRIi64 +", it already exists" , cpu_id); +return ; + } + +piix4_cpu_hotplug_req (piix4pm_state, cpu_id,PLUG ); +} +static void piix4_init_cpu_status (CPUState *cpu,void *data) {CPUStatus *g = (CPUStatus *)data;@@ -697,6 +717,7 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s) PIIX4_PROC_LEN);memory_region_add_subregion (pci_address_space_io (&s->dev),PIIX4_PROC_BASE , &s->io_cpu); + piix4pm_state = s; }static void enable_device (PIIX4PMState *s,int slot)hw/pc_piix.c +1
-0@@ -621,6 +621,7 @@ static QEMUMachine xenfv_machine = { .init = pc_xen_hvm_init, .max_cpus = HVM_MAX_VCPUS, .default_machine_opts = "accel=xen", + .hot_add_cpu = piix4_cpu_hotplug_add, };#endif sysemu.h +2
-0@@ -183,4 +183,6 @@ char *get_boot_devices_list(uint32_t *size);bool usb_enabled (bool default_usb); +void piix4_cpu_hotplug_add (const int64_t cpu_id,Error **errp); +#endif Signature · 1 line
Anthony PERARD
Re: [PATCH 7/7] xen: Implement hot_add_cpu hook.
Quoted 4 lines · Stefano Stabellini
Can't we just call
pc_new_cpuandcpu_x86_createlike upstream QEMU does?
Are there any reasons why we can't introduce the samecpu_added_notifierthat is upstream?
Yes, in our current version of qemu-xen, a CPU can not be hotplug.
When pc_new_cpu is called, there is a check to see if this object (cpu) can be hotplug to the machine. The original patch series was introducing that, I think. So it would require few more patches from QEMU which would made the backport more complicated.
And the notifier depend on the creation of new object cpu.
Signature · 1 line
Anthony PERARD
Re: [PATCH 7/7] xen: Implement hot_add_cpu hook.
In reply to Anthony PERARDQuoted 12 lines · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>--- hw/acpi_piix4.c | 21 +++++++++++++++++++++ hw/pc_piix.c | 1 + sysemu.h | 2 ++ 3 files changed, 24 insertions(+)hw/acpi_piix4.c +0
-0
hw/acpi_piix4.c static void piix4_cpu_hotplug_req(PIIX4PMState *s, int64_t cpu_id, · line 665
Quoted 4 lines
hw/acpi_piix4.c +1
-0@@ -662,6 +662,26 @@ static void piix4_cpu_hotplug_req(PIIX4PMState *s, int64_t cpu_id,pm_update_sci (s); } +static PIIX4PMState *piix4pm_state;
I really dislike this static variable. Isn't there a way to retrieve the PIIX4PMState from the cpu_id?
Quoted 56 lines
hw/acpi_piix4.c +20
-0+void piix4_cpu_hotplug_add (const int64_t cpu_id,Error **errp) +{ +CPUStatus *g = &piix4pm_state->gpe_cpu; + +if (cpu_id >= max_cpus) { +error_setg (errp,"Unable to add CPU: %" PRIi64 +", max allowed: %d" , cpu_id, max_cpus -1 ); +return ; + } +if (g->sts[cpu_id /8 ] & (1 << (cpu_id %8 ))) { +/* Already requested to be hotplug. */ +error_setg (errp,"Unable to add CPU: %" PRIi64 +", it already exists" , cpu_id); +return ; + } + +piix4_cpu_hotplug_req (piix4pm_state, cpu_id,PLUG ); +} +static void piix4_init_cpu_status (CPUState *cpu,void *data) {CPUStatus *g = (CPUStatus *)data;@@ -697,6 +717,7 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s) PIIX4_PROC_LEN);memory_region_add_subregion (pci_address_space_io (&s->dev),PIIX4_PROC_BASE , &s->io_cpu); + piix4pm_state = s; }static void enable_device (PIIX4PMState *s,int slot)hw/pc_piix.c +1
-0@@ -621,6 +621,7 @@ static QEMUMachine xenfv_machine = { .init = pc_xen_hvm_init, .max_cpus = HVM_MAX_VCPUS, .default_machine_opts = "accel=xen", + .hot_add_cpu = piix4_cpu_hotplug_add, };#endif sysemu.h +2
-0@@ -183,4 +183,6 @@ char *get_boot_devices_list(uint32_t *size);bool usb_enabled (bool default_usb); +void piix4_cpu_hotplug_add (const int64_t cpu_id,Error **errp); +#endif Signature · 1 line
Anthony PERARD
Re: [PATCH 7/7] xen: Implement hot_add_cpu hook.
Quoted 11 lines · Stefano Stabellini
Quoted 9 lines
hw/acpi_piix4.c static void piix4_cpu_hotplug_req(PIIX4PMState *s, int64_t cpu_id, · line 665
Quoted 9 lines
hw/acpi_piix4.c +1
-0@@ -662,6 +662,26 @@ static void piix4_cpu_hotplug_req(PIIX4PMState *s, int64_t cpu_id,pm_update_sci (s); } +static PIIX4PMState *piix4pm_state;I really dislike this static variable. Isn't there a way to retrieve the PIIX4PMState from the
cpu_id?
There is currently no other way to get the state from. The way it's done upsteam is by introducing a new notifier for added cpus, but it just another static variable hidden somewhere else.
The patch introducing the new notifier could be backported but not as is, as it would require other change on the CPU object (as explain in an other mail in this thread).
So this static global variable seams to me the simple thing to do for the release instead of backporting more and more patches.
Signature · 1 line
Anthony PERARD
Quoted 17 lines · Anthony PERARD
Hi all,
This series back-port recently added QEMU patches to our qemu-xen. The interface between the guest and QEMU is the same as with qemu-traditional. Only the interface between libxl and qemu change, instead of xenstore we are using QMP to hotplug vcpus.
Three more patches will follow this series.
- two for libxl which implement the QMP command cpu-add.
- one for SeaBIOS which workaround a bug.When using adding vcpus with this series, libxl will report many "error". This is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even those that have been plugged before. There is currently no way to list cpus that are plugged by QEMU. Also, the ways errors are handle by
libxl_qmpthose not help yet to suppress this error printing.
Quoted 7 lines
Unplug of vcpu is not supported by the series.
Change since the first set:
- back-port of QEMU patches instead of forth-port from qemu-traditional
- added a SeaBIOS patchRegards,
George,
the patches are OK to go in qemu-xen as far as I am concerned. Should I go ahead and apply them?
Quoted 24 lines · Stefano Stabellini
Quoted 23 lines · Anthony PERARD
Hi all,
This series back-port recently added QEMU patches to our qemu-xen. The interface between the guest and QEMU is the same as with qemu-traditional. Only the interface between libxl and qemu change, instead of xenstore we are using QMP to hotplug vcpus.
Three more patches will follow this series.
- two for libxl which implement the QMP command cpu-add.
- one for SeaBIOS which workaround a bug.When using adding vcpus with this series, libxl will report many "error". This is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even those that have been plugged before. There is currently no way to list cpus that are plugged by QEMU. Also, the ways errors are handle by
libxl_qmpthose not help yet to suppress this error printing.Unplug of vcpu is not supported by the series.
Change since the first set:
- back-port of QEMU patches instead of forth-port from qemu-traditional
- added a SeaBIOS patch
Quoted 6 lines
Quoted 1 line
Regards,
George,
the patches are OK to go in qemu-xen as far as I am concerned. Should I go ahead and apply them?
BTW Anthony, do you have a git branch based on qemu-xen that I can pull?
Quoted 25 lines · Stefano Stabellini
Quoted 24 lines · Stefano Stabellini
Quoted 23 lines · Anthony PERARD
Hi all,
This series back-port recently added QEMU patches to our qemu-xen. The interface between the guest and QEMU is the same as with qemu-traditional. Only the interface between libxl and qemu change, instead of xenstore we are using QMP to hotplug vcpus.
Three more patches will follow this series.
- two for libxl which implement the QMP command cpu-add.
- one for SeaBIOS which workaround a bug.When using adding vcpus with this series, libxl will report many "error". This is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even those that have been plugged before. There is currently no way to list cpus that are plugged by QEMU. Also, the ways errors are handle by
libxl_qmpthose not help yet to suppress this error printing.Unplug of vcpu is not supported by the series.
Change since the first set:
- back-port of QEMU patches instead of forth-port from qemu-traditional
- added a SeaBIOS patch
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Regards,
George,
the patches are OK to go in qemu-xen as far as I am concerned. Should I go ahead and apply them?BTW Anthony, do you have a git branch based on qemu-xen that I can pull?
git://xenbits.xen.org/people/aperard/qemu-dm.git
branch cpu-hotplug-port-v2
Signature · 1 line
Anthony PERARD
Quoted 24 lines · Stefano Stabellini
Quoted 23 lines · Anthony PERARD
Hi all,
This series back-port recently added QEMU patches to our qemu-xen. The interface between the guest and QEMU is the same as with qemu-traditional. Only the interface between libxl and qemu change, instead of xenstore we are using QMP to hotplug vcpus.
Three more patches will follow this series.
- two for libxl which implement the QMP command cpu-add.
- one for SeaBIOS which workaround a bug.When using adding vcpus with this series, libxl will report many "error". This is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even those that have been plugged before. There is currently no way to list cpus that are plugged by QEMU. Also, the ways errors are handle by
libxl_qmpthose not help yet to suppress this error printing.Unplug of vcpu is not supported by the series.
Change since the first set:
- back-port of QEMU patches instead of forth-port from qemu-traditional
- added a SeaBIOS patch
Quoted 6 lines
Quoted 1 line
Regards,
George,
the patches are OK to go in qemu-xen as far as I am concerned. Should I go ahead and apply them?
Yes, please do.
-George
Quoted 31 lines · George Dunlap
Quoted 30 lines · Stefano Stabellini
Quoted 29 lines · Anthony PERARD
Hi all,
This series back-port recently added QEMU patches to our qemu-xen. The interface between the guest and QEMU is the same as with qemu-traditional. Only
the interface between libxl and qemu change, instead of xenstore we are using
QMP to hotplug vcpus.Three more patches will follow this series.
- two for libxl which implement the QMP command cpu-add.
- one for SeaBIOS which workaround a bug.When using adding vcpus with this series, libxl will report many "error". This
is because libxl call the QMP command 'cpu-add' for every plugged vcpus, even
those that have been plugged before. There is currently no way to list cpus
that are plugged by QEMU. Also, the ways errors are handle bylibxl_qmpthose
not help yet to suppress this error printing.Unplug of vcpu is not supported by the series.
Change since the first set:
- back-port of QEMU patches instead of forth-port from qemu-traditional
- added a SeaBIOS patch
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Regards,
George,
the patches are OK to go in qemu-xen as far as I am concerned. Should I go ahead and apply them?Yes, please do.
done