From patchwork Thu Jan 28 05:49:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 8146371 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 E093CBEEE5 for ; Thu, 28 Jan 2016 05:53:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 252B120256 for ; Thu, 28 Jan 2016 05:53:16 +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 31B9720122 for ; Thu, 28 Jan 2016 05:53:15 +0000 (UTC) Received: from localhost ([::1]:54089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOfW6-0005WS-Ky for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Jan 2016 00:53:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOfU8-000274-Uz for qemu-devel@nongnu.org; Thu, 28 Jan 2016 00:51:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOfU5-0005Bf-HM for qemu-devel@nongnu.org; Thu, 28 Jan 2016 00:51:12 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:53631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOfU4-00059w-TZ for qemu-devel@nongnu.org; Thu, 28 Jan 2016 00:51:09 -0500 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Jan 2016 15:51:04 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 28 Jan 2016 15:50:59 +1000 X-IBM-Helo: d23dlp02.au.ibm.com X-IBM-MailFrom: bharata@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d23relay08.au.ibm.com (d23relay08.au.ibm.com [9.185.71.33]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 5EB072BB0057; Thu, 28 Jan 2016 16:50:56 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0S5oPoE31785212; Thu, 28 Jan 2016 16:50:33 +1100 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0S5oNc2001864; Thu, 28 Jan 2016 16:50:23 +1100 Received: from bharata.in.ibm.com ([9.124.35.121]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u0S5oG80001110; Thu, 28 Jan 2016 16:50:20 +1100 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Thu, 28 Jan 2016 11:19:43 +0530 Message-Id: <1453960195-15181-2-git-send-email-bharata@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1453960195-15181-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1453960195-15181-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16012805-0009-0000-0000-000002DC93F5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.145 Cc: mjrosato@linux.vnet.ibm.com, ehabkost@redhat.com, aik@ozlabs.ru, Bharata B Rao , mdroth@linux.vnet.ibm.com, agraf@suse.de, pbonzini@redhat.com, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de, david@gibson.dropbear.id.au Subject: [Qemu-devel] [PATCH v7 01/13] machine: Don't allow CPU toplogies with partially filled cores 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 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 -smp 15,sockets=1,cores=4,threads=4,maxcpus=16 or -smp 15,sockets=1,cores=4,threads=4,maxcpus=17. This is enforced by introducing MachineClass::validate_smp_config() that gets called from generic SMP parsing code. Machine type versions that want to enforce this can define this to the generic version provided. Only sPAPR and PC machine types starting from version 2.6 enforce this in this patch. Signed-off-by: Bharata B Rao --- hw/core/machine.c | 23 +++++++++++++++++++++++ hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + hw/ppc/spapr.c | 2 ++ include/hw/boards.h | 4 ++++ vl.c | 5 +++++ 7 files changed, 37 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index c46ddc7..4505995 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -336,6 +336,29 @@ static void machine_init_notify(Notifier *notifier, void *data) foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL); } +/* + * Machine types that want to prevent starting of guests with + * partially filled CPU cores can use this routine as their + * MachineClass:validate_smp_config(). + */ +void validate_smp_config_generic(int smp_cpus, int max_cpus, + int smp_threads, Error **errp) +{ + if (smp_cpus % smp_threads) { + error_setg(errp, "cpu topology: " + "smp_cpus (%u) should be multiple of threads (%u) ", + smp_cpus, smp_threads); + return; + } + + if (max_cpus % smp_threads) { + error_setg(errp, "cpu topology: " + "max_cpus (%u) should be multiple of threads (%u) ", + max_cpus, smp_threads); + return; + } +} + static void machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 78cf8fa..a54e0a0 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1971,6 +1971,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) mc->hot_add_cpu = pc_hot_add_cpu; mc->max_cpus = 255; mc->reset = pc_machine_reset; + mc->validate_smp_config = validate_smp_config_generic; hc->plug = pc_machine_device_plug_cb; hc->unplug_request = pc_machine_device_unplug_request_cb; hc->unplug = pc_machine_device_unplug_cb; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index bc74557..98b8b69 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -435,6 +435,7 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m) pc_i440fx_2_6_machine_options(m); m->alias = NULL; m->is_default = 0; + m->validate_smp_config = NULL; pcmc->save_tsc_khz = false; SET_MACHINE_COMPAT(m, PC_COMPAT_2_5); } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 6128b02..c5f4935 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -362,6 +362,7 @@ static void pc_q35_2_5_machine_options(MachineClass *m) PCMachineClass *pcmc = PC_MACHINE_CLASS(m); pc_q35_2_6_machine_options(m); m->alias = NULL; + m->validate_smp_config = NULL; pcmc->save_tsc_khz = false; SET_MACHINE_COMPAT(m, PC_COMPAT_2_5); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a9c9a95..6ac9f06 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2317,6 +2317,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->has_dynamic_sysbus = true; mc->pci_allow_0_address = true; mc->get_hotplug_handler = spapr_get_hotpug_handler; + mc->validate_smp_config = validate_smp_config_generic; hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; @@ -2402,6 +2403,7 @@ static void spapr_machine_2_5_class_options(MachineClass *mc) spapr_machine_2_6_class_options(mc); smc->use_ohci_by_default = true; SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_5); + mc->validate_smp_config = NULL; } DEFINE_SPAPR_MACHINE(2_5, "2.5", false); diff --git a/include/hw/boards.h b/include/hw/boards.h index 0f30959..435c339 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -40,6 +40,8 @@ int machine_kvm_shadow_mem(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); bool machine_mem_merge(MachineState *machine); +void validate_smp_config_generic(int smp_cpus, int max_cpus, + int smp_threads, Error **errp); /** * MachineClass: @@ -99,6 +101,8 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + void (*validate_smp_config)(int smp_cpus, int max_cpus, int smp_threads, + Error **errp); }; /** diff --git a/vl.c b/vl.c index f043009..9e4da46 100644 --- a/vl.c +++ b/vl.c @@ -4126,6 +4126,11 @@ int main(int argc, char **argv, char **envp) smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); + if (machine_class->validate_smp_config) { + machine_class->validate_smp_config(smp_cpus, max_cpus, smp_threads, + &error_abort); + } + machine_class->max_cpus = 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 "