From patchwork Wed May 7 16:21:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 29807 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 168CC20534 for ; Wed, 7 May 2014 16:24:08 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id db11sf3904095veb.0 for ; Wed, 07 May 2014 09:24:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=pk/DkdyWzD2zeYlj3Ogj/YHt+fRy9M+WN25SNYARyGw=; b=H5a5hsmCdiCjw/6Wqr4sXfVHdLUDEMQQzHz1nseY3+P2bVgxssI2O9pcqD6mHEaWyT GjeV/e9OYSRf+i02si9jsBykheKjmRzeHdvAUqx6+iiPLCy6JYK2u4w/RIpJWI4kIoUj +H9TOrXNnOj8d0nZb4lZUQtaJ+rQg0PhiwiJcw7TGLhIuTD/y3mRuA5vMnQAJtW5ZcWQ JPjYtc9bzEKNTgLHy83uLeGNkRDWgX+I6dtXdIggo0nT3k4dG4/d3nmjziEqkuRyn00H dUOCRHEr99wDMczNAvgzz8qvEIoJA+52R6x2c0MIWjxm5T/Y7EhjcNIK4C5z5fd/H73/ ZOsQ== X-Gm-Message-State: ALoCoQnZ8P0oKCV01GR5ww10feBdmEa8+kvho0op5sDuoY9hWsZRALtFUTgHcYz4D8yRmuSdwwj0 X-Received: by 10.236.36.33 with SMTP id v21mr3862319yha.53.1399479848524; Wed, 07 May 2014 09:24:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.71 with SMTP id k65ls3385047qgf.88.gmail; Wed, 07 May 2014 09:24:08 -0700 (PDT) X-Received: by 10.220.87.211 with SMTP id x19mr1440818vcl.68.1399479848367; Wed, 07 May 2014 09:24:08 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id oo7si2998775vcb.22.2014.05.07.09.24.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 09:24:08 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id pa12so1573682veb.26 for ; Wed, 07 May 2014 09:24:08 -0700 (PDT) X-Received: by 10.220.191.134 with SMTP id dm6mr40228344vcb.16.1399479847960; Wed, 07 May 2014 09:24:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp323696vcb; Wed, 7 May 2014 09:24:07 -0700 (PDT) X-Received: by 10.52.228.134 with SMTP id si6mr28510054vdc.5.1399479847593; Wed, 07 May 2014 09:24:07 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ej2si2993696veb.149.2014.05.07.09.24.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 07 May 2014 09:24:07 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wi4c3-00053W-Kp; Wed, 07 May 2014 16:22:31 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wi4c1-00052J-Rd for xen-devel@lists.xensource.com; Wed, 07 May 2014 16:22:30 +0000 Received: from [85.158.139.211:6456] by server-12.bemta-5.messagelabs.com id 19/51-03824-5CD5A635; Wed, 07 May 2014 16:22:29 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1399479746!2883866!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6609 invoked from network); 7 May 2014 16:22:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 7 May 2014 16:22:28 -0000 X-IronPort-AV: E=Sophos; i="4.97,1004,1389744000"; d="scan'208"; a="128670646" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 07 May 2014 16:22:26 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Wed, 7 May 2014 12:22:25 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Wi4bs-0005PV-90; Wed, 07 May 2014 17:22:20 +0100 From: Stefano Stabellini To: Date: Wed, 7 May 2014 17:21:53 +0100 Message-ID: <1399479718-7351-2-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 Cc: olaf@aepfle.de, xen-devel@lists.xensource.com, Stefano Stabellini , qemu-devel@nongnu.org, Zhenzhong Duan , anthony@codemonkey.ws, Anthony.Perard@citrix.com, pbonzini@redhat.com Subject: [Xen-devel] [PULL 2/7] qemu-xen: free all the pirqs for msi/msix when driver unload X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Zhenzhong Duan Pirqs are not freed when driver unload, then new pirqs are allocated when driver reload. This could exhaust pirqs if do it in a loop. This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg. There is also other way of fixing it such as reuse pirqs between driver reload, but this way is better. Xen-devel: http://marc.info/?l=xen-devel&m=136800120304275&w=2 Signed-off-by: Zhenzhong Duan Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Stefano Stabellini --- hw/xen/xen_pt_config_init.c | 6 ++++-- hw/xen/xen_pt_msi.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 8ccc2e4..de9a20f 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -1123,8 +1123,8 @@ static int xen_pt_msgctrl_reg_write(XenPCIPassthroughState *s, msi->mapped = true; } msi->flags |= PCI_MSI_FLAGS_ENABLE; - } else { - msi->flags &= ~PCI_MSI_FLAGS_ENABLE; + } else if (msi->mapped) { + xen_pt_msi_disable(s); } /* pass through MSI_ENABLE bit */ @@ -1397,6 +1397,8 @@ static int xen_pt_msixctrl_reg_write(XenPCIPassthroughState *s, if ((*val & PCI_MSIX_FLAGS_ENABLE) && !(*val & PCI_MSIX_FLAGS_MASKALL)) { xen_pt_msix_update(s); + } else if (!(*val & PCI_MSIX_FLAGS_ENABLE) && s->msix->enabled) { + xen_pt_msix_disable(s); } debug_msix_enabled_old = s->msix->enabled; diff --git a/hw/xen/xen_pt_msi.c b/hw/xen/xen_pt_msi.c index 6fbe0cc..12b4c45 100644 --- a/hw/xen/xen_pt_msi.c +++ b/hw/xen/xen_pt_msi.c @@ -282,7 +282,8 @@ void xen_pt_msi_disable(XenPCIPassthroughState *s) msi->initialized); /* clear msi info */ - msi->flags = 0; + msi->flags &= ~PCI_MSI_FLAGS_ENABLE; + msi->initialized = false; msi->mapped = false; msi->pirq = XEN_PT_UNASSIGNED_PIRQ; } @@ -446,7 +447,8 @@ static void pci_msix_write(void *opaque, hwaddr addr, if (offset != PCI_MSIX_ENTRY_VECTOR_CTRL) { const volatile uint32_t *vec_ctrl; - if (get_entry_value(entry, offset) == val) { + if (get_entry_value(entry, offset) == val + && entry->pirq != XEN_PT_UNASSIGNED_PIRQ) { return; }