From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <gkurz@linux.vnet.ibm.com>
Cc: qemu-ppc@nongnu.org, Alexander Graf <agraf@suse.de>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] hw/intc: fix failure return for xics_alloc_block()
Date: Mon, 8 Feb 2016 11:45:19 +1000 [thread overview]
Message-ID: <20160208014519.GD3702@voom> (raw)
In-Reply-To: <20160205084340.4178.52171.stgit@bahia.huguette.org>
[-- Attachment #1: Type: text/plain, Size: 4669 bytes --]
On Fri, Feb 05, 2016 at 09:43:40AM +0100, Greg Kurz wrote:
> From: Brian W. Hart <hartb@linux.vnet.ibm.com>
>
> xics_alloc_block() does not return a clear error code when it
> fails to allocate a block of interrupts. Instead it returns the
> base interrupt number minus 1. This change updates it to return a
> clear -1 in case of failure (following the example of xics_alloc()).
>
> The two callers of xics_alloc_block() are updated to check for
> a negative return as an error. They had previously checked for
> a 0 return as an error, which wrongly treated most failures as
> successes.
>
> Fixes: bee763dbfb8cfceea112131970da07f215f293a6
> Signed-off-by: Brian W. Hart <hartb@linux.vnet.ibm.com>
> [only pass src and num to trace_xics_alloc_block_failed_no_left,
> added trace_xics_alloc_block_failed_no_left definition to trace-events]
> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Hrm, it would probably be better to give xics_alloc_block() an Error
** argument so it can report errors using the new API.
TBH the whole xics_alloc_block() interface is kind of dubious, or at
least the ics_find_free_block() part of it. Dynamically allocating
irqs to devices is basically awful for migration, so it's better to
have fixed allocations of all interrupts at the machine level.
> ---
> hw/intc/xics.c | 10 ++++++----
> hw/ppc/spapr_pci.c | 9 +++++----
> trace-events | 1 +
> 3 files changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/hw/intc/xics.c b/hw/intc/xics.c
> index cd91ddc4d1d9..3bb77ff96e7b 100644
> --- a/hw/intc/xics.c
> +++ b/hw/intc/xics.c
> @@ -763,11 +763,13 @@ int xics_alloc_block(XICSState *icp, int src, int num, bool lsi, bool align)
> } else {
> first = ics_find_free_block(ics, num, 1);
> }
> + if (first < 0) {
> + trace_xics_alloc_block_failed_no_left(src, num);
> + return -1;
> + }
>
> - if (first >= 0) {
> - for (i = first; i < first + num; ++i) {
> - ics_set_irq_type(ics, i, lsi);
> - }
> + for (i = first; i < first + num; ++i) {
> + ics_set_irq_type(ics, i, lsi);
> }
> first += ics->offset;
>
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index cca9257fecc5..ba33cee2a465 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -275,7 +275,8 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,
> unsigned int req_num = rtas_ld(args, 4); /* 0 == remove all */
> unsigned int seq_num = rtas_ld(args, 5);
> unsigned int ret_intr_type;
> - unsigned int irq, max_irqs = 0, num = 0;
> + unsigned int max_irqs = 0, num = 0;
> + int irq;
> sPAPRPHBState *phb = NULL;
> PCIDevice *pdev = NULL;
> spapr_pci_msi *msi;
> @@ -354,7 +355,7 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPRMachineState *spapr,
> /* Allocate MSIs */
> irq = xics_alloc_block(spapr->icp, 0, req_num, false,
> ret_intr_type == RTAS_TYPE_MSI);
> - if (!irq) {
> + if (irq < 0) {
> error_report("Cannot allocate MSIs for device %x", config_addr);
> rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
> return;
> @@ -1359,10 +1360,10 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
>
> /* Initialize the LSI table */
> for (i = 0; i < PCI_NUM_PINS; i++) {
> - uint32_t irq;
> + int32_t irq;
>
> irq = xics_alloc_block(spapr->icp, 0, 1, true, false);
> - if (!irq) {
> + if (irq < 0) {
> error_setg(errp, "spapr_allocate_lsi failed");
> return;
> }
> diff --git a/trace-events b/trace-events
> index c9ac144ceee4..07b0250aaf11 100644
> --- a/trace-events
> +++ b/trace-events
> @@ -1393,6 +1393,7 @@ xics_alloc(int src, int irq) "source#%d, irq %d"
> xics_alloc_failed_hint(int src, int irq) "source#%d, irq %d is already in use"
> xics_alloc_failed_no_left(int src) "source#%d, no irq left"
> xics_alloc_block(int src, int first, int num, bool lsi, int align) "source#%d, first irq %d, %d irqs, lsi=%d, alignnum %d"
> +xics_alloc_block_failed_no_left(int src, int num) "source#%d, cannot find %d consecutive irqs"
> xics_ics_free(int src, int irq, int num) "Source#%d, first irq %d, %d irqs"
> xics_ics_free_warn(int src, int irq) "Source#%d, irq %d is already free"
>
>
--
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: 819 bytes --]
next prev parent reply other threads:[~2016-02-08 1:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 8:43 [Qemu-devel] [PATCH] hw/intc: fix failure return for xics_alloc_block() Greg Kurz
2016-02-08 1:45 ` David Gibson [this message]
2016-02-08 8:31 ` Greg Kurz
2016-02-10 9:41 ` Greg Kurz
2016-02-23 17:46 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-02-23 20:24 ` Greg Kurz
2016-02-24 0:36 ` David Gibson
2016-02-24 20: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=20160208014519.GD3702@voom \
--to=david@gibson.dropbear.id.au \
--cc=agraf@suse.de \
--cc=gkurz@linux.vnet.ibm.com \
--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).