From patchwork Tue Nov 30 13:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 1561677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=mD5uZpqJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J3Nvh4rs0z9sVc for ; Wed, 1 Dec 2021 00:52:48 +1100 (AEDT) Received: from localhost ([::1]:37100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ms3Yq-0007bC-Dg for incoming@patchwork.ozlabs.org; Tue, 30 Nov 2021 08:52:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ms3P2-0007ae-Ap for qemu-devel@nongnu.org; Tue, 30 Nov 2021 08:42:36 -0500 Received: from [2607:7c80:54:e::133] (port=35972 helo=bombadil.infradead.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ms3Oy-0002ke-GF for qemu-devel@nongnu.org; Tue, 30 Nov 2021 08:42:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type:References: In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7hcgYWMR3MkB8+ukK2xR4RyZNhmUMDTZrKRYFFYNDX0=; b=mD5uZpqJspwU3NFtuz5+FFS2WC ju+rbIQ+/KYp+UVaBMH95aNGCC3ZbQ/QNpfqbwdnxcYk5oofG4KCIkeCNKrQN691Vq+l0YqMX51z4 VwJ66gwJHzbQFU71F2bOsikl2JXov+PjrUAPJ88/y2hK6oZ6y4GNog3Cwc8K0zcrh7D/bhe77uvd7 C4AHki4wD5v6N0Vw0ZKvUd1kw8/KyafH/w5J3p9I9eLUkY4X+HRO4J/ybu6LKyGIINjKYRzgP+a4m qO6K4FHTMFJRuAKMm4Hz+rYwz+Hz/GkUCEAD3199Qkks/6BhruHgBSZBaEOhgBlbGUMRQbwq1kNqG YoIeGhGA==; Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=freeip.amazon.com) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ms3Op-005NWg-LT; Tue, 30 Nov 2021 13:42:24 +0000 Message-ID: <194bfe3eec78527c4ee916028586371bd143d2dc.camel@infradead.org> Subject: [PATCH 1/2] target/i386: Fix sanity check on max APIC ID / X2APIC enablement From: David Woodhouse To: Claudio Fontana , "peter.maydell@linaro.org" , "pbonzini@redhat.com" Date: Tue, 30 Nov 2021 13:42:20 +0000 In-Reply-To: <41878a65209a3e1fc00bdafd216004c9f71b90fa.camel@infradead.org> References: <20210723112921.12637-1-cfontana@suse.de> <1102c315addf2f2fffc49222ab5be118e7ae9b0f.camel@amazon.co.uk> <483ebe21-2972-90c0-bc9a-ce922518632d@suse.de> <93efa230-fb6b-fdc7-a696-c555676da2b4@suse.de> <9990ade1-ccfa-a712-94c0-1667f5b3094f@suse.de> <41878a65209a3e1fc00bdafd216004c9f71b90fa.camel@infradead.org> User-Agent: Evolution 3.36.5-0ubuntu1 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:7c80:54:e::133 (failed) Received-SPF: none client-ip=2607:7c80:54:e::133; envelope-from=BATV+3d53dfa5199d6a29bf1d+6673+infradead.org+dwmw2@bombadil.srs.infradead.org; helo=bombadil.infradead.org X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alxndr@bu.edu" , "philmd@redhat.com" , "lovemrd@gmail.com" , "ehabkost@redhat.com" , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The check on x86ms->apic_id_limit in pc_machine_done() had two problems. Firstly, we need KVM to support the X2APIC API in order to allow IRQ delivery to APICs >= 255. So we need to call/check kvm_enable_x2apic(), which was done elsewhere in *some* cases but not all. Secondly, microvm needs the same check. So move it from pc_machine_done() to x86_cpus_init() where it will work for both. The check in kvm_cpu_instance_init() is now redundant and can be dropped. Signed-off-by: David Woodhouse --- hw/i386/pc.c | 8 -------- hw/i386/x86.c | 16 ++++++++++++++++ target/i386/kvm/kvm-cpu.c | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index a2ef40ecbc..9959f93216 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -736,14 +736,6 @@ void pc_machine_done(Notifier *notifier, void *data) /* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); } - - - if (x86ms->apic_id_limit > 255 && !xen_enabled() && - !kvm_irqchip_in_kernel()) { - error_report("current -smp configuration requires kernel " - "irqchip support."); - exit(EXIT_FAILURE); - } } void pc_guest_info_init(PCMachineState *pcms) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index b84840a1bb..660e9413f5 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -39,6 +39,7 @@ #include "sysemu/replay.h" #include "sysemu/sysemu.h" #include "sysemu/cpu-timers.h" +#include "sysemu/xen.h" #include "trace.h" #include "hw/i386/x86.h" @@ -136,6 +137,21 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) */ x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms, ms->smp.max_cpus - 1) + 1; + + /* + * Can we support APIC ID 255 or higher? + * + * Under Xen: yes. + * With userspace emulated lapic: no + * With KVM's in-kernel lapic: only if X2APIC API is enabled. + */ + if (x86ms->apic_id_limit > 255 && !xen_enabled() && + (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) { + error_report("current -smp configuration requires kernel " + "irqchip and X2APIC API support."); + exit(EXIT_FAILURE); + } + possible_cpus = mc->possible_cpu_arch_ids(ms); for (i = 0; i < ms->smp.cpus; i++) { x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index d95028018e..c60cb2dafb 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -165,7 +165,7 @@ static void kvm_cpu_instance_init(CPUState *cs) /* only applies to builtin_x86_defs cpus */ if (!kvm_irqchip_in_kernel()) { x86_cpu_change_kvm_default("x2apic", "off"); - } else if (kvm_irqchip_is_split() && kvm_enable_x2apic()) { + } else if (kvm_irqchip_is_split()) { x86_cpu_change_kvm_default("kvm-msi-ext-dest-id", "on"); }