From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIqc1-0001HA-RR for qemu-devel@nongnu.org; Mon, 11 Jan 2016 23:31:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIqbz-0001iK-FT for qemu-devel@nongnu.org; Mon, 11 Jan 2016 23:31:17 -0500 Date: Tue, 12 Jan 2016 15:03:18 +1100 From: David Gibson Message-ID: <20160112040318.GJ22925@voom.redhat.com> References: <1452236119-24452-1-git-send-email-bharata@linux.vnet.ibm.com> <1452236119-24452-2-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kswDJesP0akhmDn8" Content-Disposition: inline In-Reply-To: <1452236119-24452-2-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v6 01/11] machine: Don't allow CPU toplogies with partially filled cores List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: mdroth@linux.vnet.ibm.com, aik@ozlabs.ru, agraf@suse.de, qemu-devel@nongnu.org, pbonzini@redhat.com, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de, ehabkost@redhat.com --kswDJesP0akhmDn8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 08, 2016 at 12:25:09PM +0530, Bharata B Rao wrote: > Prevent guests from booting with CPU topologies that have partially > filled CPU cores or can result in partially filled CPU cores after > CPU hotplug like >=20 > -smp 15,sockets=3D1,cores=3D4,threads=3D4,maxcpus=3D16 or > -smp 15,sockets=3D1,cores=3D4,threads=3D4,maxcpus=3D17. >=20 > This is enforced by introducing MachineClass::validate_smp_config() > that gets called from generic SMP parsing code. Machine type versions > that don't want to enforce this can override this method. >=20 > TODO: Only sPAPR and PC changes are done in this patch, other archs > will be touched after there is agreement on this approach. >=20 > Signed-off-by: Bharata B Rao Personally, I think this restriciton should be enforced always, and for non-full sockets as well. But I'm happy enough with this if it lets us move forwards. Reviewed-by: David Gibson > --- > hw/core/machine.c | 20 ++++++++++++++++++++ > hw/i386/pc_piix.c | 7 +++++++ > hw/i386/pc_q35.c | 7 +++++++ > hw/ppc/spapr.c | 7 +++++++ > include/hw/boards.h | 1 + > vl.c | 4 ++++ > 6 files changed, 46 insertions(+) >=20 > diff --git a/hw/core/machine.c b/hw/core/machine.c > index c46ddc7..b66c101 100644 > --- a/hw/core/machine.c > +++ b/hw/core/machine.c > @@ -336,6 +336,25 @@ static void machine_init_notify(Notifier *notifier, = void *data) > foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL); > } > =20 > +static int validate_smp_config_generic(int smp_cpus, int max_cpus, > + int smp_threads) > +{ > + if (smp_cpus % smp_threads) { > + error_report("cpu topology: " > + "smp_cpus (%u) should be multiple of threads (%= u) ", > + smp_cpus, smp_threads); > + return 1; > + } > + > + if (max_cpus % smp_threads) { > + error_report("cpu topology: " > + "max_cpus (%u) should be multiple of threads (%= u) ", > + max_cpus, smp_threads); > + return 1; > + } > + return 0; > +} > + > static void machine_class_init(ObjectClass *oc, void *data) > { > MachineClass *mc =3D MACHINE_CLASS(oc); > @@ -343,6 +362,7 @@ static void machine_class_init(ObjectClass *oc, void = *data) > /* Default 128 MB as guest ram size */ > mc->default_ram_size =3D 128 * M_BYTE; > mc->rom_file_has_mr =3D true; > + mc->validate_smp_config =3D validate_smp_config_generic; > } > =20 > static void machine_class_base_init(ObjectClass *oc, void *data) > diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c > index 438cdae..dd4bba1 100644 > --- a/hw/i386/pc_piix.c > +++ b/hw/i386/pc_piix.c > @@ -397,6 +397,12 @@ static void pc_xen_hvm_init(MachineState *machine) > } > #endif > =20 > +static int pc_validate_smp_config_default(int smp_cpus, int max_cpus, > + int smp_threads) > +{ > + return 0; > +} > + > #define DEFINE_I440FX_MACHINE(suffix, name, compatfn, optionfn) \ > static void pc_init_##suffix(MachineState *machine) \ > { \ > @@ -434,6 +440,7 @@ static void pc_i440fx_2_5_machine_options(MachineClas= s *m) > pc_i440fx_2_6_machine_options(m); > m->alias =3D NULL; > m->is_default =3D 0; > + m->validate_smp_config =3D pc_validate_smp_config_default; > SET_MACHINE_COMPAT(m, PC_COMPAT_2_5); > } > =20 > diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c > index 412b3cd..80ce9e8 100644 > --- a/hw/i386/pc_q35.c > +++ b/hw/i386/pc_q35.c > @@ -325,6 +325,12 @@ static void pc_compat_1_4(MachineState *machine) > pc_compat_1_5(machine); > } > =20 > +static int pc_q35_validate_smp_config_default(int smp_cpus, int max_cpus, > + int smp_threads) > +{ > + return 0; > +} > + > #define DEFINE_Q35_MACHINE(suffix, name, compatfn, optionfn) \ > static void pc_init_##suffix(MachineState *machine) \ > { \ > @@ -362,6 +368,7 @@ static void pc_q35_2_5_machine_options(MachineClass *= m) > { > pc_q35_2_6_machine_options(m); > m->alias =3D NULL; > + m->validate_smp_config =3D pc_q35_validate_smp_config_default; > SET_MACHINE_COMPAT(m, PC_COMPAT_2_5); > } > =20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 414e0f9b..a330169 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -2320,6 +2320,12 @@ static const TypeInfo spapr_machine_info =3D { > }, > }; > =20 > +static int spapr_validate_smp_config_default(int smp_cpus, int max_cpus, > + int smp_threads) > +{ > + return 0; > +} > + > #define DEFINE_SPAPR_MACHINE(suffix, verstr, latest) \ > static void spapr_machine_##suffix##_class_init(ObjectClass *oc, \ > void *data) \ > @@ -2379,6 +2385,7 @@ static void spapr_machine_2_5_class_options(Machine= Class *mc) > spapr_machine_2_6_class_options(mc); > smc->use_ohci_by_default =3D true; > SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_5); > + mc->validate_smp_config =3D spapr_validate_smp_config_default; > } > =20 > DEFINE_SPAPR_MACHINE(2_5, "2.5", false); > diff --git a/include/hw/boards.h b/include/hw/boards.h > index 0f30959..39091bf 100644 > --- a/include/hw/boards.h > +++ b/include/hw/boards.h > @@ -99,6 +99,7 @@ struct MachineClass { > HotplugHandler *(*get_hotplug_handler)(MachineState *machine, > DeviceState *dev); > unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); > + int (*validate_smp_config)(int smp_cpus, int max_cpus, int smp_threa= ds); > }; > =20 > /** > diff --git a/vl.c b/vl.c > index 5aaea77..4b36a49 100644 > --- a/vl.c > +++ b/vl.c > @@ -4132,6 +4132,10 @@ int main(int argc, char **argv, char **envp) > =20 > smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); > =20 > + if (machine_class->validate_smp_config(smp_cpus, max_cpus, smp_threa= ds)) { > + exit(1); > + } > + > machine_class->max_cpus =3D machine_class->max_cpus ?: 1; /* Default= to UP */ > if (max_cpus > machine_class->max_cpus) { > error_report("Number of SMP CPUs requested (%d) exceeds max CPUs= " --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --kswDJesP0akhmDn8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWlHsFAAoJEGw4ysog2bOSKR8P/i/XsDWD3nwvAnfLxApqBCBT NzpJ9uULB+sGjPfzRTZNt3Mxtm/hSCt21je3prhVgQ44mMoNvhJesql7YrcYD4sn y0jHiOaMMqV+9K6c8z30VL8idUrceef3socn+24eIv9cviOE9BCOdCs2LHHlQDB8 oZpE7E/cAL6/A/sxxdFXnoO+jsuQMCiR1C72Z+eYyT6r07KZwuPr8ATIfq/DtWfO /hfMtn/EuQkOGtUGGciswVtMA6K4ZmkAkWIzsXmDsz2xoEPRsZdEIc431z9RXjHH X5VzKRNr+Dx/7CmK3t0Yzvmlv2Ghs7rmvhIV1du1VDB9Pu31FLFZFs8l+4n9Stal Cs5BxzQU4iMr9xLrm/odl7zp5coHkbPuFPOiT16ykBmCgJSxCDN8rA5wDHtpRCTG pJNuXxAYhrHxwQIMA01IpKDYs8Un9PbH/tGQkH3BE4K1iromKNiJIZO/AWszgYh6 v/d+jaB5DpMEH8DmNqcqfA6dgZuRf+iACC6ceVOaNmddLLd67+MlyJwRf+JHtzr9 KGXtFFxFLFZOBxCCZHcp6XP7OQFEHZxApJTDsEv1hTfp89aTXGDV0RhS/EntIEg5 gDkG0PKkmUqb9M0KHh+hHrZKb32+g6aoHGfZH02UBOIme4tpTczCB4M4SV2twtXi 038qg8fqSaAc3SGFV87b =m4sC -----END PGP SIGNATURE----- --kswDJesP0akhmDn8--