Received: from eggs.gnu.org ([2001:4830:134:3::10]:53701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGrXW-00067I-T0 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 11:01:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGrXR-0003H2-Ky for qemu-devel@nongnu.org; Thu, 29 Jan 2015 11:01:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGrXR-0003GQ-E3 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 11:01:49 -0500 Date: Thu, 29 Jan 2015 14:01:39 -0200 From: Eduardo Habkost Message-ID: <20150129160139.GD30651@thinpad.lan.raisama.net> References: <54b41fb0134597f3a1bba41febdbe59acc268fa5.1421214155.git.zhugh.fnst@cn.fujitsu.com> <20150129154603.7cbfffcb@nial.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150129154603.7cbfffcb@nial.brq.redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 6/7] cpu: add device_add foo-x86_64-cpu support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: Zhu Guihua , Andrew Jones , qemu-devel@nongnu.org, tangchen@cn.fujitsu.com, chen.fan.fnst@cn.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com, Paolo Bonzini , guz.fnst@cn.fujitsu.com, anshul.makkar@profitbricks.com, afaerber@suse.de On Thu, Jan 29, 2015 at 03:46:03PM +0100, Igor Mammedov wrote: [...] > > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > > index 3406fe8..4347948 100644 > > --- a/target-i386/cpu.c > > +++ b/target-i386/cpu.c > > @@ -1705,6 +1705,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, > > const int64_t max = UINT32_MAX; > > Error *error = NULL; > > int64_t value; > > + X86CPUTopoInfo topo; > > > > if (dev->realized) { > > error_setg(errp, "Attempt to set property '%s' on '%s' after " > > @@ -1724,6 +1725,19 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, > > return; > > } > > > > + if (value > x86_cpu_apic_id_from_index(max_cpus - 1)) { > > + error_setg(errp, "CPU with APIC ID %" PRIi64 > > + " is more than MAX APIC ID limits", value); > > + return; > > + } > > + > > + x86_topo_ids_from_apic_id(smp_cores, smp_threads, value, &topo); > > + if (topo.smt_id >= smp_threads || topo.core_id >= smp_cores) { > If I recall correctly, APIC id also encodes socket and numa node it belongs to, > so why it's not checked here? APIC ID doesn't encode NUMA node information, just the socket, core, and thread IDs. If I understand it coreectly, the check above is to ensure we are within the limits configured in the command-line. There's a cores-per-socket and threads-per-core option, but not an explicit limit for the number of sockets. The limit for the number of sockets is implicit (it depends on max_cpus), and we are already checking the value against max_cpus above. This is related to a previous discussion about the semantics of the "sockets" option. I always assumed the "sockets" option was about non-hotplug VCPUs (smp_cpus = threads * cores * sockets) but Drew recently sent some patches assuming the "sockets" option should include sockets for CPU hotplug as well (max_cpus = threads * cores * sockets), and it may make more sense. In either case, we need to define and document those semantics more clearly to avoid confusion. > > > + error_setg(errp, "CPU with APIC ID %" PRIi64 " does not match " > > + "topology configuration.", value); > > + return; > > + } > > + > > if ((value != cpu->env.cpuid_apic_id) && cpu_exists(value)) { > > error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value); > > return; [...] > > +#define APIC_ID_NOT_SET (~0U) > > + > > static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) > > { > > - CPUX86State *env = &cpu->env; > > DeviceState *dev = DEVICE(cpu); > > APICCommonState *apic; > > const char *apic_type = "apic"; > > + uint32_t apic_id; > > > > if (kvm_irqchip_in_kernel()) { > > apic_type = "kvm-apic"; > > @@ -2742,7 +2776,14 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) > > > > object_property_add_child(OBJECT(cpu), "apic", > > OBJECT(cpu->apic_state), NULL); > > - qdev_prop_set_uint8(cpu->apic_state, "id", env->cpuid_apic_id); > > + > > + apic_id = object_property_get_int(OBJECT(cpu), "apic-id", NULL); > > + if (apic_id == APIC_ID_NOT_SET) { > Do we have in QOM a way to check if property was ever set? I don't believe the QOM property model has any abstraction for unset properties. > > > + apic_id = get_free_apic_id(); > > + object_property_set_int(OBJECT(cpu), apic_id, "apic-id", errp); > > + } > > + > > + qdev_prop_set_uint8(cpu->apic_state, "id", apic_id); -- Eduardo