Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

From
Yong Wu <yong.wu@mediatek.com>
Date
2022-06-24 10:36:13
Also in
kvm, linux-arm-msm, linux-iommu, linux-mediatek, linux-s390, linux-tegra, lkml
Reply to
Tian, Kevin, 2022-06-24
On Fri, 2022-06-24 at 06:16 +0000, Tian, Kevin wrote:
quoted
From: Yong Wu
Sent: Friday, June 24, 2022 1:39 PM

On Thu, 2022-06-23 at 19:44 -0700, Nicolin Chen wrote:
quoted
On Fri, Jun 24, 2022 at 09:35:49AM +0800, Baolu Lu wrote:
quoted
External email: Use caution opening links or attachments


On 2022/6/24 04:00, Nicolin Chen wrote:
quoted
diff --git a/drivers/iommu/mtk_iommu_v1.c
b/drivers/iommu/mtk_iommu_v1.c
index e1cb51b9866c..5386d889429d 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -304,7 +304,7 @@ static int
mtk_iommu_v1_attach_device(struct
iommu_domain *domain, struct device
      /* Only allow the domain created internally. */
      mtk_mapping = data->mapping;
      if (mtk_mapping->domain != domain)
-             return 0;
+             return -EMEDIUMTYPE;

      if (!data->m4u_dom) {
              data->m4u_dom = dom;
This change looks odd. It turns the return value from success
to
failure. Is it a bug? If so, it should go through a separated
fix
patch.
Thanks for the review:)
quoted
Makes sense.

I read the commit log of the original change:
https://lore.kernel.org/r/1589530123-30240-1-git-send-email-
yong.wu@mediatek.com
quoted
It doesn't seem to allow devices to get attached to different
domains other than the shared mapping->domain, created in the
in the mtk_iommu_probe_device(). So it looks like returning 0
is intentional. Though I am still very confused by this return
value here, I doubt it has ever been used in a VFIO context.
It's not used in VFIO context. "return 0" just satisfy the iommu
framework to go ahead. and yes, here we only allow the shared
"mapping-
quoted
domain" (All the devices share a domain created internally).
thus I think we should still keep "return 0" here.
What prevent this driver from being used in VFIO context?
Nothing prevent this. Just I didn't test. mtk_iommu_v1.c only is used
in mt2701 and there is no VFIO scenario. I'm not sure if it supports
VFIO. (mtk_iommu.c support VFIO.)
and why would we want to go ahead when an obvious error occurs
i.e. when a device is attached to an unexpected domain?
The iommu flow in this file always is a bit odd as we need share iommu
domain in ARM32. As I tested before in the above link, "The iommu
framework will create a iommu domain for each a device.", therefore we
have to *workaround* in this file.

And this was expected to be fixed by:

https://lore.kernel.org/linux-iommu/cover.1597931875.git.robin.murphy@arm.com/ (local)

sorry, I don't know its current status.

Thanks.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thread (23 messages) 23 messages, 6 authors, last reply 2022-06-30
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help