All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: lvivier@redhat.com, qemu-devel@nongnu.org, groug@kaod.org,
	qemu-ppc@nongnu.org, clg@kaod.org,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 32/38] spapr: introduce routines to delete the KVM IRQ device
Date: Wed, 22 May 2019 14:45:54 +1000	[thread overview]
Message-ID: <20190522044600.16534-33-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20190522044600.16534-1-david@gibson.dropbear.id.au>

From: Cédric Le Goater <clg@kaod.org>

If a new interrupt mode is chosen by CAS, the machine generates a
reset to reconfigure. At this point, the connection with the previous
KVM device needs to be closed and a new connection needs to opened
with the KVM device operating the chosen interrupt mode.

New routines are introduced to destroy the XICS and the XIVE KVM
devices. They make use of a new KVM device ioctl which destroys the
device and also disconnects the IRQ presenters from the vCPUs.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Message-Id: <20190513084245.25755-10-clg@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/intc/spapr_xive_kvm.c    | 56 +++++++++++++++++++++++++++++++++++++
 hw/intc/xics_kvm.c          | 51 +++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr_xive.h |  1 +
 include/hw/ppc/xics_spapr.h |  1 +
 4 files changed, 109 insertions(+)

diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c
index 3999e4b7ed..259cd1db95 100644
--- a/hw/intc/spapr_xive_kvm.c
+++ b/hw/intc/spapr_xive_kvm.c
@@ -58,6 +58,16 @@ static void kvm_cpu_enable(CPUState *cs)
     QLIST_INSERT_HEAD(&kvm_enabled_cpus, enabled_cpu, node);
 }
 
+static void kvm_cpu_disable_all(void)
+{
+    KVMEnabledCPU *enabled_cpu, *next;
+
+    QLIST_FOREACH_SAFE(enabled_cpu, &kvm_enabled_cpus, node, next) {
+        QLIST_REMOVE(enabled_cpu, node);
+        g_free(enabled_cpu);
+    }
+}
+
 /*
  * XIVE Thread Interrupt Management context (KVM)
  */
@@ -709,3 +719,49 @@ void kvmppc_xive_connect(SpaprXive *xive, Error **errp)
     /* Map all regions */
     spapr_xive_map_mmio(xive);
 }
+
+void kvmppc_xive_disconnect(SpaprXive *xive, Error **errp)
+{
+    XiveSource *xsrc;
+    size_t esb_len;
+
+    /* The KVM XIVE device is not in use */
+    if (!xive || xive->fd == -1) {
+        return;
+    }
+
+    if (!kvmppc_has_cap_xive()) {
+        error_setg(errp, "IRQ_XIVE capability must be present for KVM");
+        return;
+    }
+
+    /* Clear the KVM mapping */
+    xsrc = &xive->source;
+    esb_len = (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
+
+    sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 0);
+    munmap(xsrc->esb_mmap, esb_len);
+
+    sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 1);
+
+    sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 2);
+    munmap(xive->tm_mmap, 4ull << TM_SHIFT);
+
+    /*
+     * When the KVM device fd is closed, the KVM device is destroyed
+     * and removed from the list of devices of the VM. The VCPU
+     * presenters are also detached from the device.
+     */
+    close(xive->fd);
+    xive->fd = -1;
+
+    kvm_kernel_irqchip = false;
+    kvm_msi_via_irqfd_allowed = false;
+    kvm_gsi_direct_mapping = false;
+
+    /* Clear the local list of presenter (hotplug) */
+    kvm_cpu_disable_all();
+
+    /* VM Change state handler is not needed anymore */
+    qemu_del_vm_change_state_handler(xive->change);
+}
diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index 78a252e6df..1185846ff1 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -51,6 +51,16 @@ typedef struct KVMEnabledICP {
 static QLIST_HEAD(, KVMEnabledICP)
     kvm_enabled_icps = QLIST_HEAD_INITIALIZER(&kvm_enabled_icps);
 
+static void kvm_disable_icps(void)
+{
+    KVMEnabledICP *enabled_icp, *next;
+
+    QLIST_FOREACH_SAFE(enabled_icp, &kvm_enabled_icps, node, next) {
+        QLIST_REMOVE(enabled_icp, node);
+        g_free(enabled_icp);
+    }
+}
+
 /*
  * ICP-KVM
  */
@@ -360,3 +370,44 @@ fail:
     kvmppc_define_rtas_kernel_token(0, "ibm,int-off");
     return -1;
 }
+
+void xics_kvm_disconnect(SpaprMachineState *spapr, Error **errp)
+{
+    /* The KVM XICS device is not in use */
+    if (kernel_xics_fd == -1) {
+        return;
+    }
+
+    if (!kvm_enabled() || !kvm_check_extension(kvm_state, KVM_CAP_IRQ_XICS)) {
+        error_setg(errp,
+                   "KVM and IRQ_XICS capability must be present for KVM XICS device");
+        return;
+    }
+
+    /*
+     * Only on P9 using the XICS-on XIVE KVM device:
+     *
+     * When the KVM device fd is closed, the device is destroyed and
+     * removed from the list of devices of the VM. The VCPU presenters
+     * are also detached from the device.
+     */
+    close(kernel_xics_fd);
+    kernel_xics_fd = -1;
+
+    spapr_rtas_unregister(RTAS_IBM_SET_XIVE);
+    spapr_rtas_unregister(RTAS_IBM_GET_XIVE);
+    spapr_rtas_unregister(RTAS_IBM_INT_OFF);
+    spapr_rtas_unregister(RTAS_IBM_INT_ON);
+
+    kvmppc_define_rtas_kernel_token(0, "ibm,set-xive");
+    kvmppc_define_rtas_kernel_token(0, "ibm,get-xive");
+    kvmppc_define_rtas_kernel_token(0, "ibm,int-on");
+    kvmppc_define_rtas_kernel_token(0, "ibm,int-off");
+
+    kvm_kernel_irqchip = false;
+    kvm_msi_via_irqfd_allowed = false;
+    kvm_gsi_direct_mapping = false;
+
+    /* Clear the presenter from the VCPUs */
+    kvm_disable_icps();
+}
diff --git a/include/hw/ppc/spapr_xive.h b/include/hw/ppc/spapr_xive.h
index 04294b0ca2..0b5e972d52 100644
--- a/include/hw/ppc/spapr_xive.h
+++ b/include/hw/ppc/spapr_xive.h
@@ -71,6 +71,7 @@ int spapr_xive_end_to_target(uint8_t end_blk, uint32_t end_idx,
  * KVM XIVE device helpers
  */
 void kvmppc_xive_connect(SpaprXive *xive, Error **errp);
+void kvmppc_xive_disconnect(SpaprXive *xive, Error **errp);
 void kvmppc_xive_reset(SpaprXive *xive, Error **errp);
 void kvmppc_xive_set_source_config(SpaprXive *xive, uint32_t lisn, XiveEAS *eas,
                                    Error **errp);
diff --git a/include/hw/ppc/xics_spapr.h b/include/hw/ppc/xics_spapr.h
index 15a8dcff66..2476b540ed 100644
--- a/include/hw/ppc/xics_spapr.h
+++ b/include/hw/ppc/xics_spapr.h
@@ -34,6 +34,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);
 void xics_spapr_init(SpaprMachineState *spapr);
 
 #endif /* XICS_SPAPR_H */
-- 
2.21.0



  parent reply	other threads:[~2019-05-22  5:04 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22  4:45 [Qemu-devel] [PULL 00/38] ppc-for-4.1 queue 20190522 David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 01/38] target/ppc/kvm: Fix trace typo David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 02/38] configure: Distinguish ppc64 and ppc64le hosts David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 03/38] configure: Use quotes around uses of $CPU_CFLAGS David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 04/38] hw/ppc/prep: use TYPE_MC146818_RTC instead of a hardcoded string David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 05/38] hw/ppc/40p: Move the MC146818 RTC to the board where it belongs David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 06/38] hw/ppc/40p: use 1900 as a base year David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 07/38] target/ppc: Add ibm, purr and ibm, spurr device-tree properties David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 08/38] target/ppc: Fix xvxsigdp David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 09/38] target/ppc: Fix xxbrq, xxbrw David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 10/38] target/ppc: Fix vslv and vsrv David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 11/38] target/ppc: Fix vsum2sws David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 12/38] target/ppc: Fix xxspltib David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 13/38] spapr/xive: EQ page should be naturally aligned David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 14/38] spapr/xive: fix EQ page addresses above 64GB David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 15/38] spapr/xive: print out the EQ page address in the monitor David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 16/38] Fix typo on "info pic" monitor cmd output for xive David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 17/38] target/ppc: Optimise VSX_LOAD_SCALAR_DS and VSX_VECTOR_LOAD_STORE David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 18/38] target/ppc: Fix xvabs[sd]p, xvnabs[sd]p, xvneg[sd]p, xvcpsgn[sd]p David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 19/38] spapr/xive: Sanity checks of OV5 during CAS David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 20/38] target/ppc: Set PSSCR_EC on cpu halt to prevent spurious wakeup David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 21/38] spapr: Add forgotten capability to migration stream David Gibson
2019-05-22  7:58   ` Greg Kurz
2019-05-22 11:10     ` David Gibson
2019-05-22 12:22       ` Greg Kurz
2019-05-22  4:45 ` [Qemu-devel] [PULL 22/38] target/ppc: Use vector variable shifts for VSL, VSR, VSRA David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 23/38] spapr: Fix phb_placement backwards compatibility David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 24/38] spapr: Print out extra hints when CAS negotiation of interrupt mode fails David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 25/38] spapr/xive: add KVM support David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 26/38] spapr/xive: add hcall support when under KVM David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 27/38] spapr/xive: add state synchronization with KVM David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 28/38] spapr/xive: introduce a VM state change handler David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 29/38] spapr/xive: add migration support for KVM David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 30/38] spapr/xive: activate KVM support David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 31/38] sysbus: add a sysbus_mmio_unmap() helper David Gibson
2019-05-22  4:45 ` David Gibson [this message]
2019-05-22  4:45 ` [Qemu-devel] [PULL 33/38] spapr: check for the activation of the KVM IRQ device David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 34/38] spapr/irq: introduce a spapr_irq_init_device() helper David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 35/38] spapr/irq: initialize the IRQ device only once David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 36/38] ppc/xics: fix irq priority in ics_set_irq_type() David Gibson
2019-05-22  4:45 ` [Qemu-devel] [PULL 37/38] spapr/irq: add KVM support to the 'dual' machine David Gibson
2019-05-22  4:46 ` [Qemu-devel] [PULL 38/38] docs: provide documentation on the POWER9 XIVE interrupt controller David Gibson
2019-05-23  9:29 ` [Qemu-devel] [PULL 00/38] ppc-for-4.1 queue 20190522 Peter Maydell
2019-05-24  0:46   ` David Gibson
2019-05-24  2:17     ` David Gibson
2019-05-24  6:30       ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190522044600.16534-33-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=clg@kaod.org \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.