qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

xics/spapr: Detect old KVM XICS on POWER9 hosts

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 <groug@kaod.org>
Message-Id: <156044430517.125694.6207865998817342638.stgit@bahia.lab.toulouse-stg.fr.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

authored by

Greg Kurz and committed by
David Gibson
7abc0c6d d9293c48

+46 -2
+2 -2
docs/specs/ppc-spapr-xive.rst
··· 142 142 (3) QEMU fails at CAS with ``Guest requested unavailable interrupt 143 143 mode (XICS), either don't set the ic-mode machine property or try 144 144 ic-mode=xics or ic-mode=dual`` 145 - (4) QEMU/KVM incompatibility due to device destruction in reset. This 146 - needs to be addressed more cleanly with an error. 145 + (4) QEMU/KVM incompatibility due to device destruction in reset. QEMU fails 146 + with ``KVM is too old to support ic-mode=dual,kernel-irqchip=on`` 147 147 148 148 149 149 XIVE Device tree properties
+30
hw/intc/xics_kvm.c
··· 452 452 /* Clear the presenter from the VCPUs */ 453 453 kvm_disable_icps(); 454 454 } 455 + 456 + /* 457 + * This is a heuristic to detect older KVMs on POWER9 hosts that don't 458 + * support destruction of a KVM XICS device while the VM is running. 459 + * Required to start a spapr machine with ic-mode=dual,kernel-irqchip=on. 460 + */ 461 + bool xics_kvm_has_broken_disconnect(SpaprMachineState *spapr) 462 + { 463 + int rc; 464 + 465 + rc = kvm_create_device(kvm_state, KVM_DEV_TYPE_XICS, false); 466 + if (rc < 0) { 467 + /* 468 + * The error is ignored on purpose. The KVM XICS setup code 469 + * will catch it again anyway. The goal here is to see if 470 + * close() actually destroys the device or not. 471 + */ 472 + return false; 473 + } 474 + 475 + close(rc); 476 + 477 + rc = kvm_create_device(kvm_state, KVM_DEV_TYPE_XICS, false); 478 + if (rc >= 0) { 479 + close(rc); 480 + return false; 481 + } 482 + 483 + return errno == EEXIST; 484 + }
+13
hw/ppc/spapr_irq.c
··· 669 669 return; 670 670 } 671 671 } 672 + 673 + /* 674 + * On a POWER9 host, some older KVM XICS devices cannot be destroyed and 675 + * re-created. Detect that early to avoid QEMU to exit later when the 676 + * guest reboots. 677 + */ 678 + if (kvm_enabled() && 679 + spapr->irq == &spapr_irq_dual && 680 + machine_kernel_irqchip_required(machine) && 681 + xics_kvm_has_broken_disconnect(spapr)) { 682 + error_setg(errp, "KVM is too old to support ic-mode=dual,kernel-irqchip=on"); 683 + return; 684 + } 672 685 } 673 686 674 687 /*
+1
include/hw/ppc/xics_spapr.h
··· 35 35 uint32_t phandle); 36 36 int xics_kvm_init(SpaprMachineState *spapr, Error **errp); 37 37 void xics_kvm_disconnect(SpaprMachineState *spapr, Error **errp); 38 + bool xics_kvm_has_broken_disconnect(SpaprMachineState *spapr); 38 39 void xics_spapr_init(SpaprMachineState *spapr); 39 40 void xics_spapr_connect(SpaprMachineState *spapr); 40 41