From nobody Mon Feb 9 19:37:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1562049362; cv=none; d=zoho.com; s=zohoarc; b=JWf9ZNhs+4tb+3mdDCBazuIkJl3OAUUz0FFK6+uSym+jVMCs4cd/VRAOOGTkWrVk9+tvrKIKsVkjy0p02gU6MX2Zp6FMV2ZJZ24Mq4SXe/L7AeVtZsnPwXyOmw8PIYNt7n5mNitld+8C88V7FT8tVxZoCp2evdeUF22BDHWAxGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562049362; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0dpYb10928dRj+QGvj16TWfm0onjNeZG84JBrfI4yW0=; b=Wt1ryh9cD4Gw0c4BpP/QvQR2CEMjqrrtwc4PImWYdZmHmZJF70L1nFo9JI/frmmS5PIGJxLz6x68gpNfCg0UwQYgZQoCWtNxUR0Xa2Ulmem/RZcnO1CQKbh1kp4r/CA7drrPtPzugZMidniQYCB4UwXYpNzBxdumWOVw8YKNtrw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562049343048266.50533026239054; Mon, 1 Jul 2019 23:35:43 -0700 (PDT) Received: from localhost ([::1]:49542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiCOA-00023i-Dn for importer@patchew.org; Tue, 02 Jul 2019 02:35:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58332) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiByi-0004rt-6J for qemu-devel@nongnu.org; Tue, 02 Jul 2019 02:09:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hiByg-0002se-Qf for qemu-devel@nongnu.org; Tue, 02 Jul 2019 02:09:20 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:42717 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hiByg-0002oK-3k; Tue, 02 Jul 2019 02:09:18 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 45dDMh1Fssz9sPM; Tue, 2 Jul 2019 16:09:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1562047744; bh=vIFJ6a3uhpNiBYk44KaDMXM3ZdKaVq+9WdCp8TsZy5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KI226gt/kbZZbj1BpmtvmV5ux6ekHlWEFzl0obYVq1EOmkjE8lWmFlGjs/XEwpsBh Rna9/CSJD2M7cW7hqzzA6qWye/FxlRwlwIwKYwtGtYEwNb0G94d2G6qfijtQV6rrSJ UiEuNvqtvdk7ikDjeC0LM4yLmmgKEiSmRfM/3B6Q= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 2 Jul 2019 16:08:17 +1000 Message-Id: <20190702060857.3926-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190702060857.3926-1-david@gibson.dropbear.id.au> References: <20190702060857.3926-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 09/49] xics/spapr: Detect old KVM XICS on POWER9 hosts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, aik@ozlabs.ru, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson , rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Greg Kurz Older KVMs on POWER9 don't support destroying/recreating a KVM XICS device, which is required by 'dual' interrupt controller mode. This causes QEMU to emit a warning when the guest is rebooted and to fall back on XICS emulation: qemu-system-ppc64: warning: kernel_irqchip allowed but unavailable: Error on KVM_CREATE_DEVICE for XICS: File exists If kernel irqchip is required, QEMU will thus exit when the guest is first rebooted. Failing QEMU this late may be a painful experience for the user. Detect that and exit at machine init instead. Signed-off-by: Greg Kurz Message-Id: <156044430517.125694.6207865998817342638.stgit@bahia.lab.toulou= se-stg.fr.ibm.com> Signed-off-by: David Gibson --- docs/specs/ppc-spapr-xive.rst | 4 ++-- hw/intc/xics_kvm.c | 30 ++++++++++++++++++++++++++++++ hw/ppc/spapr_irq.c | 13 +++++++++++++ include/hw/ppc/xics_spapr.h | 1 + 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/docs/specs/ppc-spapr-xive.rst b/docs/specs/ppc-spapr-xive.rst index 7a64c9d049..6159bc6eed 100644 --- a/docs/specs/ppc-spapr-xive.rst +++ b/docs/specs/ppc-spapr-xive.rst @@ -142,8 +142,8 @@ xics XICS KVM XICS emul. XICS KVM (3) QEMU fails at CAS with ``Guest requested unavailable interrupt mode (XICS), either don't set the ic-mode machine property or try ic-mode=3Dxics or ic-mode=3Ddual`` -(4) QEMU/KVM incompatibility due to device destruction in reset. This - needs to be addressed more cleanly with an error. +(4) QEMU/KVM incompatibility due to device destruction in reset. QEMU fails + with ``KVM is too old to support ic-mode=3Ddual,kernel-irqchip=3Don`` =20 =20 XIVE Device tree properties diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c index 5c4208f430..c7f8f5edd2 100644 --- a/hw/intc/xics_kvm.c +++ b/hw/intc/xics_kvm.c @@ -452,3 +452,33 @@ void xics_kvm_disconnect(SpaprMachineState *spapr, Err= or **errp) /* Clear the presenter from the VCPUs */ kvm_disable_icps(); } + +/* + * This is a heuristic to detect older KVMs on POWER9 hosts that don't + * support destruction of a KVM XICS device while the VM is running. + * Required to start a spapr machine with ic-mode=3Ddual,kernel-irqchip=3D= on. + */ +bool xics_kvm_has_broken_disconnect(SpaprMachineState *spapr) +{ + int rc; + + rc =3D kvm_create_device(kvm_state, KVM_DEV_TYPE_XICS, false); + if (rc < 0) { + /* + * The error is ignored on purpose. The KVM XICS setup code + * will catch it again anyway. The goal here is to see if + * close() actually destroys the device or not. + */ + return false; + } + + close(rc); + + rc =3D kvm_create_device(kvm_state, KVM_DEV_TYPE_XICS, false); + if (rc >=3D 0) { + close(rc); + return false; + } + + return errno =3D=3D EEXIST; +} diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index dfb99f35ea..75654fc67a 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -669,6 +669,19 @@ static void spapr_irq_check(SpaprMachineState *spapr, = Error **errp) return; } } + + /* + * On a POWER9 host, some older KVM XICS devices cannot be destroyed a= nd + * re-created. Detect that early to avoid QEMU to exit later when the + * guest reboots. + */ + if (kvm_enabled() && + spapr->irq =3D=3D &spapr_irq_dual && + machine_kernel_irqchip_required(machine) && + xics_kvm_has_broken_disconnect(spapr)) { + error_setg(errp, "KVM is too old to support ic-mode=3Ddual,kernel-= irqchip=3Don"); + return; + } } =20 /* diff --git a/include/hw/ppc/xics_spapr.h b/include/hw/ppc/xics_spapr.h index 6c1d9ee559..d968f2499c 100644 --- a/include/hw/ppc/xics_spapr.h +++ b/include/hw/ppc/xics_spapr.h @@ -35,6 +35,7 @@ void spapr_dt_xics(SpaprMachineState *spapr, uint32_t nr_= servers, void *fdt, uint32_t phandle); int xics_kvm_init(SpaprMachineState *spapr, Error **errp); void xics_kvm_disconnect(SpaprMachineState *spapr, Error **errp); +bool xics_kvm_has_broken_disconnect(SpaprMachineState *spapr); void xics_spapr_init(SpaprMachineState *spapr); void xics_spapr_connect(SpaprMachineState *spapr); =20 --=20 2.21.0