From patchwork Fri Feb 5 08:43:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 8232681 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 771D29F1C1 for ; Fri, 5 Feb 2016 08:44:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFC672039C for ; Fri, 5 Feb 2016 08:44:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA08220375 for ; Fri, 5 Feb 2016 08:44:07 +0000 (UTC) Received: from localhost ([::1]:46830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRbzq-0002uM-8B for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Feb 2016 03:44:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRbzd-0002uC-Rf for qemu-devel@nongnu.org; Fri, 05 Feb 2016 03:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRbza-0007u2-PF for qemu-devel@nongnu.org; Fri, 05 Feb 2016 03:43:53 -0500 Received: from e06smtp08.uk.ibm.com ([195.75.94.104]:54413) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRbza-0007tT-Gm for qemu-devel@nongnu.org; Fri, 05 Feb 2016 03:43:50 -0500 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 5 Feb 2016 08:43:46 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp08.uk.ibm.com (192.168.101.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 5 Feb 2016 08:43:43 -0000 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: gkurz@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id AF41617D8056; Fri, 5 Feb 2016 08:43:55 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u158hgFf8323516; Fri, 5 Feb 2016 08:43:43 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u158hgxR004880; Fri, 5 Feb 2016 03:43:42 -0500 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u158hgD0004869; Fri, 5 Feb 2016 03:43:42 -0500 Received: from bahia.huguette.org (sig-9-84-79-61.evts.de.ibm.com [9.84.79.61]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 38CEA220465; Fri, 5 Feb 2016 09:43:41 +0100 (CET) From: Greg Kurz To: David Gibson Date: Fri, 05 Feb 2016 09:43:40 +0100 Message-ID: <20160205084340.4178.52171.stgit@bahia.huguette.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16020508-0033-0000-0000-0000059F6505 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.104 Cc: qemu-ppc@nongnu.org, Alexander Graf , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] hw/intc: fix failure return for xics_alloc_block() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Brian W. Hart 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 [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 --- 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"