Thread (28 messages) flat view 28 messages, 5 authors, 2022-09-13

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

From: Nicolin Chen <hidden>
Date: 2022-09-13 05:07:51
Also in: asahi, kvm, linux-arm-msm, linux-iommu, linux-s390, linux-tegra, lkml
Subsystem: iommu subsystem, the rest · Maintainers: Joerg Roedel, Will Deacon, Linus Torvalds

On Tue, Sep 13, 2022 at 02:22:17AM +0000, Tian, Kevin wrote:
External email: Use caution opening links or attachments

quoted
From: Jason Gunthorpe <jgg@nvidia.com>
Sent: Friday, September 9, 2022 8:08 PM

quoted
As discussed in a side thread a note might be added to exempt calling
kAPI outside of the iommu driver.
Sadly, not really.. The driver is responsible to santize this if it is
relevant. It is the main downside of this approach.
Better provide a clarification on what sanitization means.

e.g. I don't think we should change errno in those kAPIs to match the
definition in iommu subsystem since e.g. -EINVAL really means different
things in different context.

So the sanitization in iommu driver is probably that:

  - If an external kAPI returns -EINVAL, convert it to -ENODEV given iommu
    domain is iommu internal object hence unlikely for external kAPIs to
    capture incompatibility issue between domain/device;
  - Otherwise just pass whatever returned to the caller, following the definition
    of "Same behavior as -ENODEV" above
I added something similar. Thanks!
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ea30f00dc145..190647d018f9 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -266,6 +266,17 @@ struct iommu_ops {
 /**
  * struct iommu_domain_ops - domain specific operations
  * @attach_dev: attach an iommu domain to a device
+ *              Rules of its return errno:
+ *               EINVAL  - Exclusively, device and domain are incompatible. Must
+ *                         avoid kernel prints along with this errno. An EINVAL
+ *                         returned from a kAPI must be coverted to ENODEV if it
+ *                         is device specific, or to some other reasonable errno
+ *                         being listed below
+ *               ENOMEM  - Out of memory
+ *               ENOSPC  - No space left on device
+ *               EBUSY   - Device is attached to a domain and cannot be changed
+ *               ENODEV  - Device specific errors, not able to be attached
+ *              <others> - Treated as ENODEV by the caller. Use is discouraged
  * @detach_dev: detach an iommu domain from a device
  * @map: map a physically contiguous memory region to an iommu domain
  * @map_pages: map a physically contiguous set of pages of the same size to
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help