From: Greg Kurz <groug@kaod.org>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
qemu-s390x@nongnu.org, "Alexey Kardashevskiy" <aik@ozlabs.ru>,
"Cédric Le Goater" <clg@kaod.org>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Marcel Apfelbaum" <marcel@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
"Thomas Huth" <thuth@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 03/19] xics: Disintricate allocation and type setting of interrupts
Date: Fri, 18 Jan 2019 12:47:47 +0100 [thread overview]
Message-ID: <20190118124747.2d78dfe6@bahia.lan> (raw)
In-Reply-To: <154774528595.1208625.15523908858345133758.stgit@bahia.lan>
On Thu, 17 Jan 2019 18:14:46 +0100
Greg Kurz <groug@kaod.org> wrote:
> The current code assumes that an interrupt is allocated as soon as its
> type is set to MSI or LSI. PHB hotplug will require to be able to set
> the type of an interrupt before actually allocating it.
>
> Disintricate type setting from allocation by using another flag bit for
> the latter. Introduce a new ics_claim_irq() function for allocation. The
> behavior of aborting if the same irq gets allocated twice is kept.
>
> ics_set_irq_type() now only sets the type to MSI or LSI. It doesn't bring
> anything to abort if the type was already set before. Drop the assert
> and XICS_FLAGS_IRQ_MASK on the way.
>
With some more testing (and thinking :) I now realize that the type of
the irq should survive PHB unplug, which is not the case with this patch.
This calls for a v4.
> Older QEMUs don't know about XICS_FLAGS_IRQ_CLAIMED. In order to safely
> handle incoming migration, we must fix the irq flags. This is done at
> post load thanks to a compat property. We don't need to do anything for
> backward migration since older machines only care for the irq type.
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> hw/core/machine.c | 4 ++++
> hw/intc/xics.c | 28 +++++++++++++++++++++++++---
> hw/ppc/pnv_psi.c | 1 +
> hw/ppc/spapr_irq.c | 4 +---
> include/hw/ppc/xics.h | 8 ++++++--
> 5 files changed, 37 insertions(+), 8 deletions(-)
>
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 1a0a9ab1117a..536a34092367 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -25,6 +25,10 @@
>
> GlobalProperty hw_compat_3_1[] = {
> {
> + .driver = "ics-base",
> + .property = "has-claimed-flag",
> + .value = "off",
> + },{
> .driver = "pcie-root-port",
> .property = "x-speed",
> .value = "2_5",
> diff --git a/hw/intc/xics.c b/hw/intc/xics.c
> index 16e8ffa2aaf7..82cf04548907 100644
> --- a/hw/intc/xics.c
> +++ b/hw/intc/xics.c
> @@ -75,7 +75,7 @@ void ics_pic_print_info(ICSState *ics, Monitor *mon)
> for (i = 0; i < ics->nr_irqs; i++) {
> ICSIRQState *irq = ics->irqs + i;
>
> - if (!(irq->flags & XICS_FLAGS_IRQ_MASK)) {
> + if (!(irq->flags & XICS_FLAGS_IRQ_CLAIMED)) {
> continue;
> }
> monitor_printf(mon, " %4x %s %02x %02x\n",
> @@ -662,6 +662,22 @@ static int ics_base_dispatch_post_load(void *opaque, int version_id)
> ICSState *ics = opaque;
> ICSStateClass *info = ICS_BASE_GET_CLASS(ics);
>
> + if (!ics->has_claimed_flag) {
> + int i;
> +
> + for (i = 0; i < ics->nr_irqs; i++) {
> + ICSIRQState *irq = ics->irqs + i;
> +
> + /*
> + * For older machines, allocating the irq and setting its type is
> + * the same thing.
> + */
> + if (irq->flags & (XICS_FLAGS_IRQ_LSI| XICS_FLAGS_IRQ_MSI)) {
> + irq->flags |= XICS_FLAGS_IRQ_CLAIMED;
> + }
> + }
> + }
> +
> if (info->post_load) {
> return info->post_load(ics, version_id);
> }
> @@ -702,6 +718,7 @@ static const VMStateDescription vmstate_ics_base = {
>
> static Property ics_base_properties[] = {
> DEFINE_PROP_UINT32("nr-irqs", ICSState, nr_irqs, 0),
> + DEFINE_PROP_BOOL("has-claimed-flag", ICSState, has_claimed_flag, true),
> DEFINE_PROP_END_OF_LIST(),
> };
>
> @@ -741,10 +758,15 @@ ICPState *xics_icp_get(XICSFabric *xi, int server)
> return xic->icp_get(xi, server);
> }
>
> -void ics_set_irq_type(ICSState *ics, int srcno, bool lsi)
> +void ics_claim_irq(ICSState *ics, int srcno)
> {
> - assert(!(ics->irqs[srcno].flags & XICS_FLAGS_IRQ_MASK));
> + assert(ICS_IRQ_FREE(ics, srcno));
> +
> + ics->irqs[srcno].flags |= XICS_FLAGS_IRQ_CLAIMED;
> +}
>
> +void ics_set_irq_type(ICSState *ics, int srcno, bool lsi)
> +{
> ics->irqs[srcno].flags |=
> lsi ? XICS_FLAGS_IRQ_LSI : XICS_FLAGS_IRQ_MSI;
> }
> diff --git a/hw/ppc/pnv_psi.c b/hw/ppc/pnv_psi.c
> index 8ced09506321..ced34e1119dc 100644
> --- a/hw/ppc/pnv_psi.c
> +++ b/hw/ppc/pnv_psi.c
> @@ -488,6 +488,7 @@ static void pnv_psi_realize(DeviceState *dev, Error **errp)
>
> for (i = 0; i < ics->nr_irqs; i++) {
> ics_set_irq_type(ics, i, true);
> + ics_claim_irq(ics, i);
> }
>
> psi->qirqs = qemu_allocate_irqs(ics_simple_set_irq, ics, ics->nr_irqs);
> diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c
> index 1da7a32348fc..86c712d15382 100644
> --- a/hw/ppc/spapr_irq.c
> +++ b/hw/ppc/spapr_irq.c
> @@ -125,9 +125,6 @@ error:
> error_propagate(errp, local_err);
> }
>
> -#define ICS_IRQ_FREE(ics, srcno) \
> - (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_MASK)))
> -
> static int spapr_irq_claim_xics(sPAPRMachineState *spapr, int irq, bool lsi,
> Error **errp)
> {
> @@ -146,6 +143,7 @@ static int spapr_irq_claim_xics(sPAPRMachineState *spapr, int irq, bool lsi,
> }
>
> ics_set_irq_type(ics, irq - ics->offset, lsi);
> + ics_claim_irq(ics, irq - ics->offset);
> return 0;
> }
>
> diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h
> index fad786e8b22d..e3be5cc663c5 100644
> --- a/include/hw/ppc/xics.h
> +++ b/include/hw/ppc/xics.h
> @@ -131,6 +131,7 @@ struct ICSState {
> /*< public >*/
> uint32_t nr_irqs;
> uint32_t offset;
> + bool has_claimed_flag;
> ICSIRQState *irqs;
> XICSFabric *xics;
> };
> @@ -153,13 +154,15 @@ struct ICSIRQState {
> #define XICS_STATUS_PRESENTED 0x10
> #define XICS_STATUS_QUEUED 0x20
> uint8_t status;
> -/* (flags & XICS_FLAGS_IRQ_MASK) == 0 means the interrupt is not allocated */
> #define XICS_FLAGS_IRQ_LSI 0x1
> #define XICS_FLAGS_IRQ_MSI 0x2
> -#define XICS_FLAGS_IRQ_MASK 0x3
> +#define XICS_FLAGS_IRQ_CLAIMED 0x4
> uint8_t flags;
> };
>
> +#define ICS_IRQ_FREE(ics, srcno) \
> + (!((ics)->irqs[(srcno)].flags & (XICS_FLAGS_IRQ_CLAIMED)))
> +
> struct XICSFabric {
> Object parent;
> };
> @@ -193,6 +196,7 @@ void ics_simple_write_xive(ICSState *ics, int nr, int server,
> void ics_simple_set_irq(void *opaque, int srcno, int val);
> void ics_kvm_set_irq(void *opaque, int srcno, int val);
>
> +void ics_claim_irq(ICSState *ics, int srcno);
> void ics_set_irq_type(ICSState *ics, int srcno, bool lsi);
> void icp_pic_print_info(ICPState *icp, Monitor *mon);
> void ics_pic_print_info(ICSState *ics, Monitor *mon);
>
next prev parent reply other threads:[~2019-01-18 11:48 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-17 17:14 [Qemu-devel] [PATCH v3 00/19] spapr: Add support for PHB hotplug Greg Kurz
2019-01-17 17:14 ` [Qemu-devel] [PATCH v3 01/19] ppc: Move spapr-related prototypes from xics.h into a seperate header file Greg Kurz
2019-01-17 17:14 ` [Qemu-devel] [PATCH v3 02/19] spapr: Rename xics to intc in interrupt controller agnostic code Greg Kurz
2019-01-18 13:56 ` Cédric Le Goater
2019-01-20 14:22 ` Greg Kurz
2019-02-05 6:03 ` David Gibson
2019-01-17 17:14 ` [Qemu-devel] [PATCH v3 03/19] xics: Disintricate allocation and type setting of interrupts Greg Kurz
2019-01-18 11:47 ` Greg Kurz [this message]
2019-01-18 12:26 ` Cédric Le Goater
2019-01-20 14:24 ` Greg Kurz
2019-02-05 6:13 ` David Gibson
2019-02-05 14:59 ` Greg Kurz
2019-02-06 1:47 ` David Gibson
2019-01-17 17:14 ` [Qemu-devel] [PATCH v3 04/19] spapr/xive: Don't set irq type in spapr_xive_irq_claim() Greg Kurz
2019-01-18 12:27 ` Cédric Le Goater
2019-01-17 17:14 ` [Qemu-devel] [PATCH v3 05/19] spapr: Set irq type in a dedicated function Greg Kurz
2019-01-18 12:34 ` Cédric Le Goater
2019-01-20 14:31 ` Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 06/19] spapr: Identify LSIs of all possible PHBs at machine init Greg Kurz
2019-01-18 12:38 ` Cédric Le Goater
2019-01-20 14:37 ` Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 07/19] spapr_pci: add PHB unrealize Greg Kurz
2019-01-18 11:54 ` Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 08/19] spapr: create DR connectors for PHBs Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 09/19] spapr: populate PHB DRC entries for root DT node Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 10/19] spapr_events: add support for phb hotplug events Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 11/19] qdev: pass an Object * to qbus_set_hotplug_handler() Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 12/19] spapr_pci: provide node start offset via spapr_populate_pci_dt() Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 13/19] spapr_pci: add ibm, my-drc-index property for PHB hotplug Greg Kurz
2019-01-17 17:15 ` [Qemu-devel] [PATCH v3 14/19] spapr: Factor out setting of "phandle" DT property to sPAPR irq frontend Greg Kurz
2019-01-18 12:45 ` Cédric Le Goater
2019-01-20 15:41 ` Greg Kurz
2019-01-17 17:16 ` [Qemu-devel] [PATCH v3 15/19] spapr_xive: Cache device tree nodename in sPAPRXive Greg Kurz
2019-01-18 13:38 ` Cédric Le Goater
2019-01-22 13:27 ` Greg Kurz
2019-01-22 14:26 ` Cédric Le Goater
2019-01-22 14:35 ` Greg Kurz
2019-01-17 17:16 ` [Qemu-devel] [PATCH v3 16/19] spapr: Expose the name of the interrupt controller node Greg Kurz
2019-01-18 13:44 ` Cédric Le Goater
2019-01-17 17:16 ` [Qemu-devel] [PATCH v3 17/19] spapr_irq: Expose the phandle of the interrupt controller Greg Kurz
2019-01-18 13:46 ` Cédric Le Goater
2019-01-22 13:32 ` Greg Kurz
2019-01-17 17:16 ` [Qemu-devel] [PATCH v3 18/19] spapr: add hotplug hooks for PHB hotplug Greg Kurz
2019-01-18 13:55 ` Cédric Le Goater
2019-01-17 17:16 ` [Qemu-devel] [PATCH v3 19/19] spapr: enable PHB hotplug for default pseries machine type Greg Kurz
2019-01-22 5:44 ` [Qemu-devel] [PATCH v3 00/19] spapr: Add support for PHB hotplug Alexey Kardashevskiy
2019-01-22 7:22 ` Greg Kurz
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=20190118124747.2d78dfe6@bahia.lan \
--to=groug@kaod.org \
--cc=aik@ozlabs.ru \
--cc=clg@kaod.org \
--cc=cohuck@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=dmitry.fleytman@gmail.com \
--cc=ehabkost@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcel@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=thuth@redhat.com \
/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).