From patchwork Thu Apr 28 08:22:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8966421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AF5EFBF29F for ; Thu, 28 Apr 2016 08:25:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D11C2027D for ; Thu, 28 Apr 2016 08:25:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E6A4E20274 for ; Thu, 28 Apr 2016 08:25:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1avhF2-0001mQ-S0; Thu, 28 Apr 2016 08:24:08 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1avhE6-0000gp-RA for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2016 08:23:11 +0000 Received: by mail-wm0-x236.google.com with SMTP id a17so51928061wme.0 for ; Thu, 28 Apr 2016 01:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7nepP/wtS5Ts/YwIWwtl58cICGxIlbBVask6aVS/qMc=; b=GxfNdLqpgk4IbPsi0njsfHbXUO1jDRAuRLJW6fhtCKNgQPhZ9+UCGE2sNrT1X4JBvL hcvouRYR2cuQYHoZ/mvWr0i7mCbuBIrwb69kAxxEwQ8uB4uLjlesr1FpQ3TfelCiNHIW csufazdEJaNEaIAJHltBDXyQlGiT21L0qzFgw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7nepP/wtS5Ts/YwIWwtl58cICGxIlbBVask6aVS/qMc=; b=d7zIRwqLgAIBT/AXU6iHJjurILb2gz/T6JH01UFfQ1MnMvMuhxBoDoPznhxZ6cn5o4 bLge8atk548HX8nR04QOXUcC87ul/4m5kdptnpDLCcd94TrD5wdQSVo4UtrQxCSOxlnD 9sPU6U74e3H34ExelggaXuZIGDwgfka07IKN/Nq/18Oj3hd6byUhdU0/qI1nk/J95wn/ tFRoTu0n4i5p4GN8sfFBoI3iayNkuT7HAGq/GBFf7qex6KI16ADN0OPhR2CCsRBkATl1 MmAzV2BE8P+sYwDndJMefN8vnzuRvevibm/vMr6Sm6ll7BTLZdfMWqQcirMjg5eXgrve 8kuw== X-Gm-Message-State: AOPr4FUA6xLtbJ0TqvYw7h/bepXR5vSqaWC9Y5KWdespeD+fpEiE+f3RBfpnIxnpN1w/xy8K X-Received: by 10.194.186.242 with SMTP id fn18mr14752613wjc.65.1461831769574; Thu, 28 Apr 2016 01:22:49 -0700 (PDT) Received: from new-host-46.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id b124sm3568725wmb.1.2016.04.28.01.22.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 01:22:47 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, robin.murphy@arm.com, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs Date: Thu, 28 Apr 2016 08:22:09 +0000 Message-Id: <1461831730-5575-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461831730-5575-1-git-send-email-eric.auger@linaro.org> References: <1461831730-5575-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160428_012311_122273_C0F8C5CB X-CRM114-Status: GOOD ( 18.08 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: julien.grall@arm.com, patches@linaro.org, Jean-Philippe.Brucker@arm.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 This patch handles the iommu mapping of MSI doorbells that require to be mapped in an iommu domain. This happens on msi_domain_alloc/free_irqs since this is called in code that can sleep (pci_enable/disable_msi): iommu_map/unmap is not stated as atomic. On msi_domain_(de)activate and msi_domain_set_affinity, which must be atomic, we just lookup for this pre-allocated/mapped IOVA. Signed-off-by: Eric Auger --- v7 -> v8: - new percpu pointer type - exit from the irq domain hierarchy parsing on first map/unmap success - reset desc->irq to 0 on mapping failure v7: creation --- kernel/irq/msi.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 72bf4d6..d5f95e6 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include /* Temparory solution for building, will be removed later */ #include @@ -322,6 +324,56 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, } /** + * msi_handle_doorbell_mappings: in case the irq data corresponds to an + * MSI that requires iommu mapping, traverse the irq domain hierarchy + * to retrieve the doorbells to handle and iommu_map/unmap them according + * to @map boolean. + * + * @data: irq data handle + * @map: mapping if true, unmapping if false + */ +static int msi_handle_doorbell_mappings(struct irq_data *data, bool map) +{ + for (; data; data = data->parent_data) { + struct device *dev = + msi_desc_to_dev(irq_data_get_msi_desc(data)); + struct irq_chip *chip = irq_data_get_irq_chip(data); + const struct irq_chip_msi_doorbell_info *dbinfo; + struct iommu_domain *domain; + phys_addr_t __percpu *db_addr; + dma_addr_t iova; + int ret = 0, i; + + domain = iommu_msi_domain(dev); + if (!domain) + continue; + + if (!chip->msi_doorbell_info) + continue; + + dbinfo = chip->msi_doorbell_info(data); + if (!dbinfo) + return -EINVAL; + + for (i = 0; i < dbinfo->nb_doorbells; i++) { + db_addr = per_cpu_ptr(dbinfo->percpu_doorbells, i); + if (map) { + ret = iommu_msi_get_doorbell_iova(domain, + *db_addr, + dbinfo->size, + dbinfo->prot, + &iova); + if (ret) + return ret; + } else + iommu_msi_put_doorbell_iova(domain, *db_addr); + } + break; + } + return 0; +} + +/** * msi_domain_alloc_irqs - Allocate interrupts from a MSI interrupt domain * @domain: The domain to allocate from * @dev: Pointer to device struct of the device for which the interrupts @@ -352,17 +404,26 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, virq = __irq_domain_alloc_irqs(domain, virq, desc->nvec_used, dev_to_node(dev), &arg, false); - if (virq < 0) { - ret = -ENOSPC; - if (ops->handle_error) - ret = ops->handle_error(domain, desc, ret); - if (ops->msi_finish) - ops->msi_finish(&arg, ret); - return ret; - } + if (virq < 0) + goto error; for (i = 0; i < desc->nvec_used; i++) irq_set_msi_desc_off(virq, i, desc); + + for (i = 0; i < desc->nvec_used; i++) { + ret = msi_handle_doorbell_mappings( + irq_get_irq_data(virq + i), true); + if (ret) + break; + } + if (ret) { + for (; i >= 0; i--) + msi_handle_doorbell_mappings( + irq_get_irq_data(virq + i), false); + irq_domain_free_irqs(virq, desc->nvec_used); + desc->irq = 0; + goto error; + } } if (ops->msi_finish) @@ -377,6 +438,13 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, } return 0; +error: + ret = -ENOSPC; + if (ops->handle_error) + ret = ops->handle_error(domain, desc, ret); + if (ops->msi_finish) + ops->msi_finish(&arg, ret); + return ret; } /** @@ -396,6 +464,9 @@ void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev) * entry. If that's the case, don't do anything. */ if (desc->irq) { + msi_handle_doorbell_mappings( + irq_get_irq_data(desc->irq), + false); irq_domain_free_irqs(desc->irq, desc->nvec_used); desc->irq = 0; }