xics/spapr: Register RTAS/hypercalls once at machine init
commitd9293c4843b2503c905d35899077fc415824783e
authorGreg Kurz <groug@kaod.org>
Thu, 13 Jun 2019 16:44:59 +0000 (13 18:44 +0200)
committerDavid Gibson <david@gibson.dropbear.id.au>
Mon, 1 Jul 2019 23:43:58 +0000 (2 09:43 +1000)
treeb57ed1fba68d250317c5f5783241f3f4f4f7548f
parentd9715d67722ebd7198a35681cfc9a6595bdb08f0
xics/spapr: Register RTAS/hypercalls once at machine init

QEMU may crash when running a spapr machine in 'dual' interrupt controller
mode on some older (but not that old, eg. ubuntu 18.04.2) KVMs with partial
XIVE support:

qemu-system-ppc64: hw/ppc/spapr_rtas.c:411: spapr_rtas_register:
 Assertion `!name || !rtas_table[token].name' failed.

XICS is controlled by the guest thanks to a set of RTAS calls. Depending
on whether KVM XICS is used or not, the RTAS calls are handled by KVM or
QEMU. In both cases, QEMU needs to expose the RTAS calls to the guest
through the "rtas" node of the device tree.

The spapr_rtas_register() helper takes care of all of that: it adds the
RTAS call token to the "rtas" node and registers a QEMU callback to be
invoked when the guest issues the RTAS call. In the KVM XICS case, QEMU
registers a dummy callback that just prints an error since it isn't
supposed to be invoked, ever.

Historically, the XICS controller was setup during machine init and
released during final teardown. This changed when the 'dual' interrupt
controller mode was added to the spapr machine: in this case we need
to tear the XICS down and set it up again during machine reset. The
crash happens because we indeed have an incompatibility with older
KVMs that forces QEMU to fallback on emulated XICS, which tries to
re-registers the same RTAS calls.

This could be fixed by adding proper rollback that would unregister
RTAS calls on error. But since the emulated RTAS calls in QEMU can
now detect when they are mistakenly called while KVM XICS is in
use, it seems simpler to register them once and for all at machine
init. This fixes the crash and allows to remove some now useless
lines of code.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <156044429963.125694.13710679451927268758.stgit@bahia.lab.toulouse-stg.fr.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
hw/intc/xics_kvm.c
hw/intc/xics_spapr.c
hw/ppc/spapr_irq.c
include/hw/ppc/spapr.h
include/hw/ppc/xics.h
include/hw/ppc/xics_spapr.h