From patchwork Tue Apr 19 17:13: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: 8882111 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 3D3FFBF29F for ; Tue, 19 Apr 2016 17:16:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D948202D1 for ; Tue, 19 Apr 2016 17:16:45 +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 50F85202BE for ; Tue, 19 Apr 2016 17:16:44 +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 1asZEp-0006Wu-Vi; Tue, 19 Apr 2016 17:14:59 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1asZDi-0005JI-2L for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2016 17:13:52 +0000 Received: by mail-wm0-x22e.google.com with SMTP id n3so41300319wmn.0 for ; Tue, 19 Apr 2016 10:13:31 -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=6kbqZXNKgpBWL5BcQrXqd0Gzat06Ze/JThQkTlbESTQ=; b=cExzSaK5ei3Aw9LTsOtCp/6PhZG+6UhLIFNzptCiBPCWJiajWo976cbcTgxyXu0SBX E+3Iiw618Xxvx7GJwuBK8XLKUqg765o8GVG4wxBifNhO3tba65uLXDifvtC5cYW8zg77 bZhJzQqtiG2bzFiDA4dtQONZc5+Cvl4hpqfeA= 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=6kbqZXNKgpBWL5BcQrXqd0Gzat06Ze/JThQkTlbESTQ=; b=PIiAuijD7OFqYk7EJXufLoPy8JcUVxuJXNiyS+JGQQ5dkpJEh8GrNnlH6WLqXzzhpc DpDU7c01c1t8REi0tiKsyU56gTQRySkM9W4GrbwwfpmcWkLsoF9Hx41Q1UVVMWnzpC5Q j5WA6Y2X0ej7jru2VUOcV7cMyMBdK29kwkJehgIJ3IXkefVjOjMUIlzBOTIwlOFX69Y/ DIfIqVhkyUeO0ZJ4Cx260SvWJqojZ65akuN24wWIrKzC9AGA5W1OVI/QOjtXrKQR+Ofk m5SH+HxkBu3WOQass5hzpq7xJmdm9B5bv4j2J0Jx0s90ge35bkmaAGD+Hu/djLq0mv5G UKPQ== X-Gm-Message-State: AOPr4FUzv5aOrFldTVyMbCoijo84Bihaq51fyzwwwGz+a7pHbwsVCXzJLviVGRb6yGIRkxu9 X-Received: by 10.194.61.40 with SMTP id m8mr4262339wjr.106.1461086010446; Tue, 19 Apr 2016 10:13:30 -0700 (PDT) Received: from new-host-34.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id gr4sm1243604wjd.23.2016.04.19.10.13.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 10:13:29 -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 v7 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs Date: Tue, 19 Apr 2016 17:13:09 +0000 Message-Id: <1461085990-2547-8-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461085990-2547-1-git-send-email-eric.auger@linaro.org> References: <1461085990-2547-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160419_101350_501558_C7846C15 X-CRM114-Status: GOOD ( 18.68 ) 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: creation --- kernel/irq/msi.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 72bf4d6..e45907e 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,59 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, } /** + * msi_handle_doorbell_mapping: 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) { + const struct irq_chip_msi_doorbell_info *dbinfo; + struct iommu_domain *domain; + struct msi_desc *desc; + struct irq_chip *chip; + dma_addr_t iova; + int ret = 0, i; + + chip = irq_data_get_irq_chip(data); + desc = irq_data_get_msi_desc(data); + + domain = iommu_msi_mapping_desc_to_domain(desc); + 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++) { + struct irq_chip_msi_doorbell __percpu *db; + + db = per_cpu_ptr(dbinfo->percpu_doorbells, i); + if (map) { + ret = iommu_get_reserved_iova(domain, + db->base, + db->size, + db->prot, + &iova); + if (ret) + return ret; + } else + iommu_put_reserved_iova(domain, db->base); + } + } + 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 +407,25 @@ 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++) + for (i = 0; i < desc->nvec_used; i++) { irq_set_msi_desc_off(virq, i, desc); + ret = msi_handle_doorbell_mappings( + irq_get_irq_data(virq + i), true); + if (ret) + break; + } + + if (ret) { + for (; i >= 0; i--) { + ret = msi_handle_doorbell_mappings( + irq_get_irq_data(virq + i), false); + irq_set_msi_desc_off(virq, i, NULL); + } + goto error; + } } if (ops->msi_finish) @@ -377,6 +440,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 +466,12 @@ 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) { + int ret; + + ret = msi_handle_doorbell_mappings( + irq_get_irq_data(desc->irq), + false); + WARN_ON(ret); irq_domain_free_irqs(desc->irq, desc->nvec_used); desc->irq = 0; }