From patchwork Tue Mar 1 21:13:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Rosato X-Patchwork-Id: 8470181 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 459B4C0553 for ; Tue, 1 Mar 2016 21:14:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2B4DC20304 for ; Tue, 1 Mar 2016 21:14:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2DCC202EC for ; Tue, 1 Mar 2016 21:13:59 +0000 (UTC) Received: from localhost ([::1]:52290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aarcE-0000QA-Ny for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 16:13:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aarbu-0000EX-08 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 16:13:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aarbq-0002Hy-Mm for qemu-devel@nongnu.org; Tue, 01 Mar 2016 16:13:37 -0500 Received: from e19.ny.us.ibm.com ([129.33.205.209]:48111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aarbq-0002Hq-IJ for qemu-devel@nongnu.org; Tue, 01 Mar 2016 16:13:34 -0500 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Mar 2016 16:13:34 -0500 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 1 Mar 2016 16:13:31 -0500 X-IBM-Helo: d01dlp02.pok.ibm.com X-IBM-MailFrom: mjrosato@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 7C2EA6E8047 for ; Tue, 1 Mar 2016 16:00:22 -0500 (EST) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u21LDVWU30408936 for ; Tue, 1 Mar 2016 21:13:31 GMT Received: from d01av05.pok.ibm.com (localhost [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u21L9LIu002482 for ; Tue, 1 Mar 2016 16:09:22 -0500 Received: from rosatomj-ThinkPad-W530.endicott.ibm.com (rosatomj-thinkpad-w530.endicott.ibm.com [9.60.84.71]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u21L9IYO002351; Tue, 1 Mar 2016 16:09:20 -0500 From: Matthew Rosato To: qemu-devel@nongnu.org Date: Tue, 1 Mar 2016 16:13:25 -0500 Message-Id: <1456866806-31466-6-git-send-email-mjrosato@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456866806-31466-1-git-send-email-mjrosato@linux.vnet.ibm.com> References: <1456866806-31466-1-git-send-email-mjrosato@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16030121-0057-0000-0000-000003919691 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 129.33.205.209 Cc: dahi@linux.vnet.ibm.com, agraf@suse.de, borntraeger@de.ibm.com, imammedo@redhat.com, bharata@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, afaerber@suse.de, rth@twiddle.net Subject: [Qemu-devel] [PATCH v7 5/6] s390x/cpu: Add error handling to cpu creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check for and propogate errors during s390 cpu creation. Signed-off-by: Matthew Rosato --- hw/s390x/s390-virtio-ccw.c | 30 +++++++++++++++++++++ hw/s390x/s390-virtio.c | 2 +- hw/s390x/s390-virtio.h | 1 + target-s390x/cpu-qom.h | 3 +++ target-s390x/cpu.c | 65 ++++++++++++++++++++++++++++++++++++++++++++-- target-s390x/cpu.h | 1 + target-s390x/helper.c | 31 ++++++++++++++++++++-- 7 files changed, 128 insertions(+), 5 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 3090e76..4886dbf 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -112,6 +112,36 @@ void s390_memory_init(ram_addr_t mem_size) s390_skeys_init(); } +S390CPU *s390_new_cpu(MachineState *machine, int64_t id, Error **errp) +{ + S390CPU *cpu = NULL; + Error *local_err = NULL; + + if (id >= max_cpus) { + error_setg(errp, "Unable to add CPU: %" PRIi64 + ", max allowed: %d", id, max_cpus - 1); + goto out; + } + + cpu = cpu_s390x_create(machine->cpu_model, &local_err); + if (local_err != NULL) { + goto out; + } + + object_property_set_int(OBJECT(cpu), id, "id", &local_err); + object_property_set_bool(OBJECT(cpu), true, "realized", &local_err); + +out: + if (cpu != NULL) { + object_unref(OBJECT(cpu)); + } + if (local_err) { + error_propagate(errp, local_err); + cpu = NULL; + } + return cpu; +} + static void ccw_init(MachineState *machine) { int ret; diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index 6bd9803..6f71ab0 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -118,7 +118,7 @@ void s390_init_cpus(MachineState *machine) } for (i = 0; i < smp_cpus; i++) { - cpu_s390x_init(machine->cpu_model); + s390_new_cpu(machine, i, &error_fatal); } } diff --git a/hw/s390x/s390-virtio.h b/hw/s390x/s390-virtio.h index ffd014c..fbcfdb8 100644 --- a/hw/s390x/s390-virtio.h +++ b/hw/s390x/s390-virtio.h @@ -29,4 +29,5 @@ void s390_create_virtio_net(BusState *bus, const char *name); void s390_nmi(NMIState *n, int cpu_index, Error **errp); void s390_machine_reset(void); void s390_memory_init(ram_addr_t mem_size); +S390CPU *s390_new_cpu(MachineState *machine, int64_t id, Error **errp); #endif diff --git a/target-s390x/cpu-qom.h b/target-s390x/cpu-qom.h index 029a44a..1c90933 100644 --- a/target-s390x/cpu-qom.h +++ b/target-s390x/cpu-qom.h @@ -47,6 +47,8 @@ typedef struct S390CPUClass { CPUClass parent_class; /*< public >*/ + int64_t next_cpu_id; + DeviceRealize parent_realize; void (*parent_reset)(CPUState *cpu); void (*load_normal)(CPUState *cpu); @@ -66,6 +68,7 @@ typedef struct S390CPU { /*< public >*/ CPUS390XState env; + int64_t id; /* needed for live migration */ void *irqstate; uint32_t irqstate_saved_size; diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 8dfd063..ec66ed6 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -30,6 +30,7 @@ #include "qemu/error-report.h" #include "hw/hw.h" #include "trace.h" +#include "qapi/visitor.h" #ifndef CONFIG_USER_ONLY #include "sysemu/arch_init.h" #endif @@ -197,11 +198,26 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) S390CPUClass *scc = S390_CPU_GET_CLASS(dev); S390CPU *cpu = S390_CPU(dev); CPUS390XState *env = &cpu->env; + Error *local_err = NULL; + + if (cpu->id != scc->next_cpu_id) { + error_setg(errp, "Unable to add CPU: %" PRIi64 + ", The next available id is %" PRIi64, cpu->id, + scc->next_cpu_id); + return; + } + + cpu_exec_init(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + scc->next_cpu_id = cs->cpu_index + 1; #if !defined(CONFIG_USER_ONLY) qemu_register_reset(s390_cpu_machine_reset_cb, cpu); #endif - env->cpu_num = cs->cpu_index; + env->cpu_num = cpu->id; s390_cpu_gdb_init(cs); qemu_init_vcpu(cs); #if !defined(CONFIG_USER_ONLY) @@ -213,6 +229,49 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) scc->parent_realize(dev, errp); } +static void s390_cpu_get_id(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + S390CPU *cpu = S390_CPU(obj); + int64_t value = cpu->id; + + visit_type_int(v, name, &value, errp); +} + +static void s390_cpu_set_id(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + S390CPU *cpu = S390_CPU(obj); + DeviceState *dev = DEVICE(obj); + const int64_t min = 0; + const int64_t max = UINT32_MAX; + Error *local_err = NULL; + int64_t value; + + if (dev->realized) { + error_setg(errp, "Attempt to set property '%s' on '%s' after " + "it was realized", name, object_get_typename(obj)); + return; + } + + visit_type_int(v, name, &value, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + if (value < min || value > max) { + error_setg(errp, "Property %s.%s doesn't take value %" PRId64 + " (minimum: %" PRId64 ", maximum: %" PRId64 ")" , + object_get_typename(obj), name, value, min, max); + return; + } + if ((value != cpu->id) && cpu_exists(value)) { + error_setg(errp, "CPU with ID %" PRIi64 " exists", value); + return; + } + cpu->id = value; +} + static void s390_cpu_initfn(Object *obj) { CPUState *cs = CPU(obj); @@ -226,7 +285,8 @@ static void s390_cpu_initfn(Object *obj) cs->env_ptr = env; cs->halted = 1; cs->exception_index = EXCP_HLT; - cpu_exec_init(cs, &error_abort); + object_property_add(OBJECT(cpu), "id", "int64_t", s390_cpu_get_id, + s390_cpu_set_id, NULL, NULL, NULL); #if !defined(CONFIG_USER_ONLY) qemu_get_timedate(&tm, 0); env->tod_offset = TOD_UNIX_EPOCH + @@ -342,6 +402,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) CPUClass *cc = CPU_CLASS(scc); DeviceClass *dc = DEVICE_CLASS(oc); + scc->next_cpu_id = 0; scc->parent_realize = dc->realize; dc->realize = s390_cpu_realizefn; diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 6ae5699..2c7d6bd 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -413,6 +413,7 @@ void trigger_pgm_exception(CPUS390XState *env, uint32_t code, uint32_t ilen); #endif S390CPU *cpu_s390x_init(const char *cpu_model); +S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp); void s390x_translate_init(void); int cpu_s390x_exec(CPUState *cpu); diff --git a/target-s390x/helper.c b/target-s390x/helper.c index 838bdd9..e562cb7 100644 --- a/target-s390x/helper.c +++ b/target-s390x/helper.c @@ -65,14 +65,41 @@ void s390x_cpu_timer(void *opaque) } #endif -S390CPU *cpu_s390x_init(const char *cpu_model) +S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp) { S390CPU *cpu; cpu = S390_CPU(object_new(TYPE_S390_CPU)); - object_property_set_bool(OBJECT(cpu), true, "realized", NULL); + return cpu; +} + +S390CPU *cpu_s390x_init(const char *cpu_model) +{ + Error *error = NULL; + S390CPU *cpu; + S390CPUClass *scc; + int64_t id; + cpu = cpu_s390x_create(cpu_model, &error); + if (error) { + goto out; + } + + scc = S390_CPU_GET_CLASS(cpu); + id = scc->next_cpu_id; + + object_property_set_int(OBJECT(cpu), id, "id", &error); + object_property_set_bool(OBJECT(cpu), true, "realized", &error); + + out: + if (error) { + error_report_err(error); + if (cpu != NULL) { + object_unref(OBJECT(cpu)); + cpu = NULL; + } + } return cpu; }