From patchwork Wed May 4 15:18:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9015981 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 C2EF3BF29F for ; Wed, 4 May 2016 15:21:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23B68203AE for ; Wed, 4 May 2016 15:21:32 +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 A0E3F20395 for ; Wed, 4 May 2016 15:21:30 +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 1axyar-00019Z-KC; Wed, 04 May 2016 15:20:05 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1axyZp-0000B3-TD for linux-arm-kernel@lists.infradead.org; Wed, 04 May 2016 15:19:03 +0000 Received: by mail-wm0-x231.google.com with SMTP id n129so193476371wmn.1 for ; Wed, 04 May 2016 08:18:40 -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=E3N2o151PrMYT1H0n6nwAA9pPdnYfRzif02BHkavJng=; b=kezhl2hDZhh58slotGd3lQTRY3wNdHsc0whDVvZXadeLv/te8sWATYgdhxrWDWN5IG zZ2WlxP+Iycojs1+u7jjBzuOubRpSuZXWFt//6jydBLFbixpqOibLnE3ihVPMwvhanGS QsUxdKztaixVJN32//sAXt7Zeb5+SXQMN9byc= 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=E3N2o151PrMYT1H0n6nwAA9pPdnYfRzif02BHkavJng=; b=gTj9Al9AVeIeTpLhOh8n2akmYd+aH8dsIzw2doveDTKQIb3B3gnyS8jj0HfsWXS5Va lxp1/H/DzeblPNCtfvN+hxjbT38/HwPSJCIBe3HVp2UvwOm6Cc3cM7ZWI73g3jd6scr6 TH/BEeBIQZQmAS62lPi/ralXsmxOhYqsvT57UsKLwbHw7hlQGGCvfl2+LCpFKC9oqOtd qRqYi1Uba2g6A+uP3299aHy3jiLISjC/rrFdqHhewqDFRdlKbFiqUeRC1GGz45H2rCjG 9SNz8+JOtRVN9gw6BAEu1XzztyDfkvEebcfOuNQihDs7wDXji2GywpReUeg5qhfy9KMZ ZWzw== X-Gm-Message-State: AOPr4FV9knQewnEX7owcJqOPCa8DbRobrHCDUwxVz1iq57dF3tViiVTqfMOHKjxPpEAnbz5M X-Received: by 10.28.126.145 with SMTP id z139mr30281486wmc.81.1462375119396; Wed, 04 May 2016 08:18:39 -0700 (PDT) Received: from new-host-57.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id c4sm4773821wjm.24.2016.05.04.08.18.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 May 2016 08:18:38 -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 v9 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs Date: Wed, 4 May 2016 15:18:13 +0000 Message-Id: <1462375094-2390-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462375094-2390-1-git-send-email-eric.auger@linaro.org> References: <1462375094-2390-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160504_081902_285364_FFA3377F X-CRM114-Status: GOOD ( 19.16 ) 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, yehuday@marvell.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=-6.2 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 --- v8 -> v9: - decouple irq_data parsing from the actual mapping/unmapping 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 | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 8 deletions(-) diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 72bf4d6..d654524 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,74 @@ 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) +{ + const struct irq_chip_msi_doorbell_info *dbinfo; + struct iommu_domain *domain; + struct irq_chip *chip; + struct device *dev; + dma_addr_t iova; + int ret = 0, cpu; + + while (data) { + dev = msi_desc_to_dev(irq_data_get_msi_desc(data)); + domain = iommu_msi_domain(dev); + if (domain) { + chip = irq_data_get_irq_chip(data); + if (chip->msi_doorbell_info) + break; + } + data = data->parent_data; + } + + if (!data) + return 0; + + dbinfo = chip->msi_doorbell_info(data); + if (!dbinfo) + return -EINVAL; + + if (!dbinfo->doorbell_is_percpu) { + if (!map) { + iommu_msi_put_doorbell_iova(domain, + dbinfo->global_doorbell); + return 0; + } + return iommu_msi_get_doorbell_iova(domain, + dbinfo->global_doorbell, + dbinfo->size, dbinfo->prot, + &iova); + } + + /* percpu doorbells */ + for_each_possible_cpu(cpu) { + phys_addr_t __percpu *db_addr = + per_cpu_ptr(dbinfo->percpu_doorbells, cpu); + + if (!map) { + iommu_msi_put_doorbell_iova(domain, *db_addr); + } else { + + ret = iommu_msi_get_doorbell_iova(domain, *db_addr, + dbinfo->size, + dbinfo->prot, &iova); + if (ret) + return ret; + } + } + + 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 +422,29 @@ 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++) { + struct irq_data *d = irq_get_irq_data(virq + i); + + ret = msi_handle_doorbell_mappings(d, true); + if (ret) + break; + } + if (ret) { + for (; i >= 0; i--) { + struct irq_data *d = irq_get_irq_data(virq + i); + + msi_handle_doorbell_mappings(d, false); + } + irq_domain_free_irqs(virq, desc->nvec_used); + desc->irq = 0; + goto error; + } } if (ops->msi_finish) @@ -377,6 +459,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 +485,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; }