Skip to contentSkip to conversation

iommu: Always define struct iommu_ops

PATCH In review Thierry Reding 2 participants 6 messages Aug 1, 2014 – Oct 23, 2014 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iommu: Always define struct iommu_ops

From: Thierry Reding <[email protected]>

With this structure always defined, drivers can be always compiled, irrespective of whether or not IOMMU_API is enabled. This helps to increase compile coverage without having to build with two separate configurations.

Unused code can still be discarded by the compiler if the IS_ENABLED() macro is properly used in an if condition, such as shown below:

	static const struct iommu_ops iommu_ops = {
		...
	};

	static int iommu_setup(...)
	{
		...

		bus_set_iommu(..., &iommu_ops);

		...
	}

	...

	static int iommu_probe(...)
	{
		...

		if (IS_ENABLED(CONFIG_IOMMU_API)) {
			err = iommu_setup(...);
			...
		}

		...
	}

That pattern will allow the compiler to notice that setup_iommu() is never called if IOMMU_API is not selected, which will allow it to discard its code and all data referenced from it.

---
 include/linux/iommu.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
include/linux/iommu.h +2 -5
index 20f9a527922a..0b5222c7ff97 100644
@@ -83,8 +83,6 @@ enum iommu_attr {
 	DOMAIN_ATTR_MAX,
 };
 
-#ifdef CONFIG_IOMMU_API
-
 /**
  * struct iommu_ops - iommu ops and capabilities
  * @domain_init: init iommu domain
@@ -140,6 +138,8 @@ struct iommu_ops {
 #define IOMMU_GROUP_NOTIFY_UNBIND_DRIVER	5 /* Pre Driver unbind */
 #define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER	6 /* Post Driver unbind */
 
+#ifdef CONFIG_IOMMU_API
+
 extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
 extern bool iommu_present(struct bus_type *bus);
 extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
@@ -242,9 +242,6 @@ static inline int report_iommu_fault(struct iommu_domain *domain,
 
 #else /* CONFIG_IOMMU_API */
 
-struct iommu_ops {};
-struct iommu_group {};
-
 static inline bool iommu_present(struct bus_type *bus)
 {
 	return false;
Signature · 1 line
2.0.3
#1 lore raw

PATCH 2/2 iommu: Implement a dummy bus_set_iommu()

From: Thierry Reding <[email protected]>

This allows IOMMU drivers to compile even if IOMMU_API is not selected and helps improve compile coverage.

---
 include/linux/iommu.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/linux/iommu.h +6 -0
index 0b5222c7ff97..415608ea2999 100644
@@ -242,6 +242,12 @@ static inline int report_iommu_fault(struct iommu_domain *domain,
 
 #else /* CONFIG_IOMMU_API */
 
+static inline int bus_set_iommu(struct bus_type *bus,
+				const struct iommu_ops *ops)
+{
+	return -ENOSYS;
+}
+
 static inline bool iommu_present(struct bus_type *bus)
 {
 	return false;
Signature · 1 line
2.0.3
maintainer
#2 lore raw

Re: [PATCH 2/2] iommu: Implement a dummy bus_set_iommu()

Quoted 4 lines · Thierry Reding

From: Thierry Reding <[email protected]>

This allows IOMMU drivers to compile even if IOMMU_API is not selected and helps improve compile coverage.

IOMMU drivers usually implement the IOMMU-API, so they have a strong dependency to it. Why do you want to compile-test an iommu driver without testing the iommu core-code as well?

Joerg

#3 lore raw

Re: [PATCH 2/2] iommu: Implement a dummy bus_set_iommu()

Quoted 9 lines · Joerg Roedel
Quoted 4 lines · Thierry Reding

From: Thierry Reding <[email protected]>

This allows IOMMU drivers to compile even if IOMMU_API is not selected and helps improve compile coverage.

IOMMU drivers usually implement the IOMMU-API, so they have a strong dependency to it. Why do you want to compile-test an iommu driver without testing the iommu core-code as well?

It seems like I never got back to you on this. The reason here is that for Tegra the IOMMU is part of a larger IP block. The IP block is primarily a memory controller with a bunch of configuration knobs for arbitration, prioritization and whatnot. A smaller part of the device does the IOMMU translation. Therefore the IOMMU implementation would be part of a larger driver, and having this dummy would reduce the amount of #ifdefs required.

bus_set_iommu() is also the only function in include/linux/iommu.h that doesn't have a dummy, so it seemed like a natural thing to do.

That said, I can work around this being absent for !IOMMU_API.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141015/cc11222d/attachment.sig>

maintainer
#4 lore raw

Re: [PATCH 2/2] iommu: Implement a dummy bus_set_iommu()

Quoted 8 lines · Thierry Reding

It seems like I never got back to you on this. The reason here is that for Tegra the IOMMU is part of a larger IP block. The IP block is primarily a memory controller with a bunch of configuration knobs for arbitration, prioritization and whatnot. A smaller part of the device does the IOMMU translation. Therefore the IOMMU implementation would be part of a larger driver, and having this dummy would reduce the amount of #ifdefs required.

Quoted 4 lines

bus_set_iommu() is also the only function in include/linux/iommu.h that doesn't have a dummy, so it seemed like a natural thing to do.

That said, I can work around this being absent for !IOMMU_API.

Or you make this "larger driver" just depend on IOMMU_API? Otherwise you need the #ifdefs anyway to not carry around the iommu-ops functions in the driver without having the iommu core enabled, no?

Joerg

#5 lore raw

Re: [PATCH 2/2] iommu: Implement a dummy bus_set_iommu()

Quoted 9 lines · Joerg Roedel
Quoted 8 lines · Thierry Reding

It seems like I never got back to you on this. The reason here is that for Tegra the IOMMU is part of a larger IP block. The IP block is primarily a memory controller with a bunch of configuration knobs for arbitration, prioritization and whatnot. A smaller part of the device does the IOMMU translation. Therefore the IOMMU implementation would be part of a larger driver, and having this dummy would reduce the amount of #ifdefs required.

Quoted 8 lines
Quoted 4 lines

bus_set_iommu() is also the only function in include/linux/iommu.h that doesn't have a dummy, so it seemed like a natural thing to do.

That said, I can work around this being absent for !IOMMU_API.

Or you make this "larger driver" just depend on IOMMU_API? Otherwise you need the #ifdefs anyway to not carry around the iommu-ops functions in the driver without having the iommu core enabled, no?

I can do that using IS_ENABLED() magic, which will cause the iommu_ops to be thrown away automatically when IOMMU_API is disabled. That allows the driver to be compiled with full coverage and still only include the needed parts in the final binary.

Then again, going forward it doesn't seem likely that we'll ever want to disable IOMMU on Tegra once it's been enabled, so this isn't really a big issue.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141023/f7908fa3/attachment.sig>