From: David Gibson <david@gibson.dropbear.id.au>
To: "Cédric Le Goater" <clg@kaod.org>
Cc: Greg Kurz <groug@kaod.org>, qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 10/13] spapr: introduce routines to delete the KVM IRQ device
Date: Tue, 26 Feb 2019 12:10:18 +1100 [thread overview]
Message-ID: <20190226011018.GH6872@umbus.fritz.box> (raw)
In-Reply-To: <20190222131322.26079-11-clg@kaod.org>
[-- Attachment #1: Type: text/plain, Size: 7016 bytes --]
On Fri, Feb 22, 2019 at 02:13:19PM +0100, Cédric Le Goater wrote:
> 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>
Ugly, but necessary
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> include/hw/ppc/spapr_xive.h | 1 +
> include/hw/ppc/xics_spapr.h | 1 +
> hw/intc/spapr_xive_kvm.c | 60 +++++++++++++++++++++++++++++++++++++
> hw/intc/xics_kvm.c | 56 ++++++++++++++++++++++++++++++++++
> 4 files changed, 118 insertions(+)
>
> diff --git a/include/hw/ppc/spapr_xive.h b/include/hw/ppc/spapr_xive.h
> index 22d70650b51f..a7c4c275a747 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 b8d924baf437..bddf09821cb0 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);
> +int xics_kvm_disconnect(sPAPRMachineState *spapr, Error **errp);
> void xics_spapr_init(sPAPRMachineState *spapr);
>
> #endif /* XICS_SPAPR_H */
> diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c
> index 119fd59fc9ae..e31035c90260 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)
> */
> @@ -674,3 +684,53 @@ 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;
> + struct kvm_destroy_device xive_destroy_device;
> + size_t esb_len;
> + int rc;
> +
> + /* 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);
> +
> + /* Destroy the KVM device. This also clears the VCPU presenters */
> + xive_destroy_device.fd = xive->fd;
> + xive_destroy_device.flags = 0;
> + rc = kvm_vm_ioctl(kvm_state, KVM_DESTROY_DEVICE, &xive_destroy_device);
> + if (rc < 0) {
> + error_setg_errno(errp, -rc, "Error on KVM_DESTROY_DEVICE for XIVE");
> + }
> + 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 c6e1b630a404..373de3155f6b 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,49 @@ fail:
> kvmppc_define_rtas_kernel_token(0, "ibm,int-off");
> return -1;
> }
> +
> +int xics_kvm_disconnect(sPAPRMachineState *spapr, Error **errp)
> +{
> + int rc;
> + struct kvm_destroy_device xics_destroy_device = {
> + .fd = kernel_xics_fd,
> + .flags = 0,
> + };
> +
> + /* The KVM XICS device is not in use */
> + if (kernel_xics_fd == -1) {
> + return 0;
> + }
> +
> + 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 -1;
> + }
> +
> + rc = kvm_vm_ioctl(kvm_state, KVM_DESTROY_DEVICE, &xics_destroy_device);
> + if (rc < 0) {
> + error_setg_errno(errp, -rc, "Error on KVM_DESTROY_DEVICE for XICS");
> + }
> + 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();
> +
> + return rc;
> +}
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-02-26 3:17 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 13:13 [Qemu-devel] [PATCH v2 00/13] spapr: add KVM support to the XIVE interrupt mode Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 01/13] spapr/xive: add KVM support Cédric Le Goater
2019-02-25 5:55 ` David Gibson
2019-03-11 15:53 ` Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 02/13] spapr/xive: add hcall support when under KVM Cédric Le Goater
2019-02-25 23:22 ` David Gibson
2019-03-11 17:32 ` Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 03/13] spapr/xive: activate KVM support Cédric Le Goater
2019-02-25 23:49 ` David Gibson
2019-02-25 23:49 ` David Gibson
2019-03-11 20:44 ` Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 04/13] spapr/xive: add state synchronization with KVM Cédric Le Goater
2019-02-26 0:01 ` David Gibson
2019-03-11 20:41 ` Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 05/13] spapr/xive: introduce a VM state change handler Cédric Le Goater
2019-02-26 0:39 ` David Gibson
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 06/13] spapr/xive: add migration support for KVM Cédric Le Goater
2019-02-26 0:58 ` David Gibson
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 07/13] spapr/xive: fix migration of the XiveTCTX under TCG Cédric Le Goater
2019-02-26 1:02 ` David Gibson
2019-03-11 20:45 ` Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 08/13] spapr/rtas: modify spapr_rtas_register() to remove RTAS handlers Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 09/13] sysbus: add a sysbus_mmio_unmap() helper Cédric Le Goater
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 10/13] spapr: introduce routines to delete the KVM IRQ device Cédric Le Goater
2019-02-26 1:10 ` David Gibson [this message]
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 11/13] spapr: check for the activation of " Cédric Le Goater
2019-02-26 1:27 ` David Gibson
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 12/13] spapr: add KVM support to the 'dual' machine Cédric Le Goater
2019-02-28 5:15 ` David Gibson
2019-02-22 13:13 ` [Qemu-devel] [PATCH v2 13/13] spapr/xive: fix device hotplug when VM is stopped Cédric Le Goater
2019-02-26 4:17 ` David Gibson
2019-03-11 20:59 ` Cédric Le Goater
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=20190226011018.GH6872@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=clg@kaod.org \
--cc=groug@kaod.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).