From: Jean-Philippe Brucker <Jean-Philippe.Brucker@arm.com>
To: Eric Auger <eric.auger@linaro.org>
Cc: eric.auger@st.com, 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,
kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
patches@linaro.org, Manish.Jaggi@caviumnetworks.com,
linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org
Subject: Re: [RFC v5 06/17] dma-reserved-iommu: iommu_get/put_single_reserved
Date: Thu, 10 Mar 2016 11:52:54 +0000 [thread overview]
Message-ID: <20160310115253.GA14609@e106794-lin.cambridge.arm.com> (raw)
In-Reply-To: <1456856877-4817-7-git-send-email-eric.auger@linaro.org>
Hi Eric,
On Tue, Mar 01, 2016 at 06:27:46PM +0000, Eric Auger wrote:
>[...]
> +
> +int iommu_get_single_reserved(struct iommu_domain *domain,
> + phys_addr_t addr, int prot,
> + dma_addr_t *iova)
> +{
> + unsigned long order = __ffs(domain->ops->pgsize_bitmap);
> + size_t page_size = 1 << order;
> + phys_addr_t mask = page_size - 1;
> + phys_addr_t aligned_addr = addr & ~mask;
> + phys_addr_t offset = addr - aligned_addr;
> + struct iommu_reserved_binding *b;
> + struct iova *p_iova;
> + struct iova_domain *iovad =
> + (struct iova_domain *)domain->reserved_iova_cookie;
> + int ret;
> +
> + if (!iovad)
> + return -EINVAL;
> +
> + mutex_lock(&domain->reserved_mutex);
I believe this function could get called from the chunk of __setup_irq
that is executed atomically:
* request_threaded_irq
* __setup_irq
* irq_startup
* irq_domain_activate_irq
* msi_domain_activate
* msi_compose
* iommu_get_single_reserved
If this is the case, we should probably use a spinlock to protect the
iova_domain...
> +
> + b = find_reserved_binding(domain, aligned_addr, page_size);
> + if (b) {
> + *iova = b->iova + offset;
> + kref_get(&b->kref);
> + ret = 0;
> + goto unlock;
> + }
> +
> + /* there is no existing reserved iova for this pa */
> + p_iova = alloc_iova(iovad, 1, iovad->dma_32bit_pfn, true);
> + if (!p_iova) {
> + ret = -ENOMEM;
> + goto unlock;
> + }
> + *iova = p_iova->pfn_lo << order;
> +
> + b = kzalloc(sizeof(*b), GFP_KERNEL);
... and GFP_ATOMIC here.
Thanks,
Jean-Philippe
> + if (!b) {
> + ret = -ENOMEM;
> + goto free_iova_unlock;
> + }
> +
> + ret = iommu_map(domain, *iova, aligned_addr, page_size, prot);
> + if (ret)
> + goto free_binding_iova_unlock;
> +
> + kref_init(&b->kref);
> + kref_get(&b->kref);
> + b->domain = domain;
> + b->addr = aligned_addr;
> + b->iova = *iova;
> + b->size = page_size;
> +
> + link_reserved_binding(domain, b);
> +
> + *iova += offset;
> + goto unlock;
> +
> +free_binding_iova_unlock:
> + kfree(b);
> +free_iova_unlock:
> + free_iova(iovad, *iova >> order);
> +unlock:
> + mutex_unlock(&domain->reserved_mutex);
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(iommu_get_single_reserved);
next prev parent reply other threads:[~2016-03-10 11:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-01 18:27 [RFC v5 00/17] KVM PCIe/MSI passthrough on ARM/ARM64 Eric Auger
2016-03-01 18:27 ` [RFC v5 01/17] iommu: Add DOMAIN_ATTR_MSI_MAPPING attribute Eric Auger
2016-03-01 18:27 ` [RFC v5 02/17] iommu/arm-smmu: advertise " Eric Auger
2016-03-01 18:27 ` [RFC v5 03/17] iommu: introduce a reserved iova cookie Eric Auger
2016-03-03 16:26 ` Julien Grall
2016-03-29 17:26 ` Eric Auger
2016-03-01 18:27 ` [RFC v5 04/17] dma-reserved-iommu: alloc/free_reserved_iova_domain Eric Auger
2016-03-01 18:27 ` [RFC v5 05/17] dma-reserved-iommu: reserved binding rb-tree and helpers Eric Auger
2016-03-01 18:27 ` [RFC v5 06/17] dma-reserved-iommu: iommu_get/put_single_reserved Eric Auger
2016-03-10 11:52 ` Jean-Philippe Brucker [this message]
2016-03-29 17:07 ` Eric Auger
2016-03-01 18:27 ` [RFC v5 07/17] dma-reserved-iommu: iommu_unmap_reserved Eric Auger
2016-03-01 18:27 ` [RFC v5 08/17] msi: Add a new MSI_FLAG_IRQ_REMAPPING flag Eric Auger
2016-03-01 18:27 ` [RFC v5 09/17] irqchip/gic-v3-its: ITS advertises MSI_FLAG_IRQ_REMAPPING Eric Auger
2016-03-01 18:27 ` [RFC v5 10/17] msi: export msi_get_domain_info Eric Auger
2016-03-01 18:27 ` [RFC v5 11/17] msi: msi_compose wrapper Eric Auger
2016-03-01 18:27 ` [RFC v5 12/17] msi: IOMMU map the doorbell address when needed Eric Auger
2016-03-01 18:27 ` [RFC v5 13/17] vfio: introduce VFIO_IOVA_RESERVED vfio_dma type Eric Auger
2016-03-01 18:27 ` [RFC v5 14/17] vfio: allow the user to register reserved iova range for MSI mapping Eric Auger
2016-03-01 18:27 ` [RFC v5 15/17] vfio/type1: also check IRQ remapping capability at msi domain Eric Auger
2016-03-01 18:27 ` [RFC v5 16/17] iommu/arm-smmu: do not advertise IOMMU_CAP_INTR_REMAP Eric Auger
2016-03-01 18:27 ` [RFC v5 17/17] vfio/type1: return MSI mapping requirements with VFIO_IOMMU_GET_INFO Eric Auger
2016-03-02 8:11 ` [RFC v5 00/17] KVM PCIe/MSI passthrough on ARM/ARM64 Jaggi, Manish
2016-03-02 12:30 ` Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160310115253.GA14609@e106794-lin.cambridge.arm.com \
--to=jean-philippe.brucker@arm.com \
--cc=Manish.Jaggi@caviumnetworks.com \
--cc=alex.williamson@redhat.com \
--cc=christoffer.dall@linaro.org \
--cc=eric.auger@linaro.org \
--cc=eric.auger@st.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jason@lakedaemon.net \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=patches@linaro.org \
--cc=robin.murphy@arm.com \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®