From: xieyisheng1@huawei.com (Yisheng Xie)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/37] iommu/sva: Manage process address spaces
Date: Thu, 22 Feb 2018 17:03:41 +0800 [thread overview]
Message-ID: <63e4b545-c6e5-f4b4-3ba1-cf7a142b64ec@huawei.com> (raw)
In-Reply-To: <1519280641-30258-3-git-send-email-xieyisheng1@huawei.com>
Hi Jean,
On 2018/2/22 14:23, Jean-Philippe Brucker wrote:
> @@ -129,7 +439,10 @@ int iommu_sva_device_shutdown(struct device *dev)
> int iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, int *pasid,
> unsigned long flags, void *drvdata)
> {
> + int i, ret;
> + struct io_mm *io_mm = NULL;
> struct iommu_domain *domain;
> + struct iommu_bond *bond = NULL, *tmp;
> struct iommu_param *dev_param = dev->iommu_param;
>
> domain = iommu_get_domain_for_dev(dev);
> @@ -145,7 +458,42 @@ int iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, int *pasid,
> if (flags != (IOMMU_SVA_FEAT_PASID | IOMMU_SVA_FEAT_IOPF))
> return -EINVAL;
>
> - return -ENOSYS; /* TODO */
> + /* If an io_mm already exists, use it */
> + spin_lock(&iommu_sva_lock);
> + idr_for_each_entry(&iommu_pasid_idr, io_mm, i) {
> + if (io_mm->mm != mm || !io_mm_get_locked(io_mm))
> + continue;
> +
> + /* Is it already bound to this device? */
> + list_for_each_entry(tmp, &io_mm->devices, mm_head) {
> + if (tmp->dev != dev)
> + continue;
> +
> + bond = tmp;
> + refcount_inc(&bond->refs);
> + io_mm_put_locked(io_mm);
Should io_mm->pasid still be set to *pasid when the device already bond? so driver can
always get the right pasid if it bond to a mm multi-times, without keeping the pasid itself?
Thanks
Yisheng
> + break;
> + }
> + break;
> + }
> + spin_unlock(&iommu_sva_lock);
> +
> + if (bond)
> + return 0;
> +
> + if (!io_mm) {
> + io_mm = io_mm_alloc(domain, dev, mm);
> + if (IS_ERR(io_mm))
> + return PTR_ERR(io_mm);
> + }
> +
> + ret = io_mm_attach(domain, dev, io_mm, drvdata);
> + if (ret)
> + io_mm_put(io_mm);
> + else
> + *pasid = io_mm->pasid;
> +
> + return ret;
> }
> EXPORT_SYMBOL_GPL(iommu_sva_bind_device);
next parent reply other threads:[~2018-02-22 9:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1519280641-30258-1-git-send-email-xieyisheng1@huawei.com>
[not found] ` <1519280641-30258-3-git-send-email-xieyisheng1@huawei.com>
2018-02-22 9:03 ` Yisheng Xie [this message]
2018-02-22 13:17 ` [PATCH 03/37] iommu/sva: Manage process address spaces Jean-Philippe Brucker
[not found] ` <1519280641-30258-37-git-send-email-xieyisheng1@huawei.com>
2018-03-19 9:47 ` [PATCH 37/37] vfio: Add support for Shared Virtual Addressing Yisheng Xie
2018-03-21 13:40 ` Jean-Philippe Brucker
[not found] ` <1519280641-30258-27-git-send-email-xieyisheng1@huawei.com>
2018-03-19 11:03 ` [PATCH 27/37] iommu/arm-smmu-v3: Register fault workqueue Yisheng Xie
2018-03-21 13:24 ` Jean-Philippe Brucker
2018-03-22 1:09 ` Yisheng Xie
2018-04-04 10:13 ` Jean-Philippe Brucker
2018-02-12 18:33 [PATCH 00/37] Shared Virtual Addressing for the IOMMU Jean-Philippe Brucker
2018-02-12 18:33 ` [PATCH 03/37] iommu/sva: Manage process address spaces Jean-Philippe Brucker
2018-03-01 6:52 ` Lu Baolu
2018-03-01 8:04 ` Christian König
2018-03-02 16:42 ` Jean-Philippe Brucker
2018-03-02 16:19 ` Jean-Philippe Brucker
2018-03-05 15:28 ` Sinan Kaya
2018-03-06 10:37 ` Jean-Philippe Brucker
2018-04-10 18:53 ` Sinan Kaya
2018-04-13 10:59 ` Jean-Philippe Brucker
2018-04-24 1:32 ` Sinan Kaya
2018-04-24 9:33 ` Jean-Philippe Brucker
2018-04-24 17:17 ` Sinan Kaya
2018-04-24 18:52 ` Jean-Philippe Brucker
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=63e4b545-c6e5-f4b4-3ba1-cf7a142b64ec@huawei.com \
--to=xieyisheng1@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).