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: Auger Eric X-Patchwork-Id: 66873 Delivered-To: patches@linaro.org Received: by 10.140.93.198 with SMTP id d64csp78202qge; Thu, 28 Apr 2016 01:22:51 -0700 (PDT) X-Received: by 10.28.227.130 with SMTP id a124mr15146068wmh.2.1461831769813; Thu, 28 Apr 2016 01:22:49 -0700 (PDT) Return-Path: Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com. [2a00:1450:400c:c09::22f]) by mx.google.com with ESMTPS id l12si35674360wmd.110.2016.04.28.01.22.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2016 01:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22f as permitted sender) client-ip=2a00:1450:400c:c09::22f; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22f as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-wm0-x22f.google.com with SMTP id a17so51928056wme.0 for ; Thu, 28 Apr 2016 01:22:49 -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=DKbfoq2NnkQ5zBEGmwbURuUH31pLVKRdtz5QzolzrfGG58gM+EnPOFSgxh43nl0nGo yxXWIUTOAABNlAOtNnGgrU1PnQT9XfuDPzSFb3KxKYBJExm2Rr/Wf/4WfGiv4qomJtkW BqMczvX26hkfQIByqkGPqKFeaoqcrXb5jVyVlAUBeAw0ulC9+4d6Ao5CNhygZLbaV510 zfn4suIdPUh08wrmncs0HCzet9FHpwHRx5cWlrXc/sKMWksLSXE//MgGkT8yo9JRwZ/i xbbY/SryaSZJkDCltHHAzRnsl6g1bZFzDIiBR5lAZi7bsCGax2lxIcx9itZkTP+wq/rE hcFw== X-Gm-Message-State: AOPr4FW5M0exrIaWqZapHz4ohOy2J+Sj9/+rn/M2gm556UmqPonXKcv2genyLvbw8KUj9Pyitnk= X-Received: by 10.194.186.242 with SMTP id fn18mr14752613wjc.65.1461831769574; Thu, 28 Apr 2016 01:22:49 -0700 (PDT) Return-Path: 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 Cc: patches@linaro.org, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, Jean-Philippe.Brucker@arm.com, julien.grall@arm.com 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> 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(-) -- 1.9.1 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; }