Skip to contentSkip to conversation

Break up monolithic iommu table/lock into finer graularity pools and lock

PATCH Superseded Sowmini Varadhan 3 participants 4 messages Dec 22, 2014 – Mar 3, 2015 Library code

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Break up monolithic iommu table/lock into finer graularity pools and lock

Investigation of multithreaded iperf experiments on an ethernet interface show the iommu->lock as the hottest lock identified by lockstat, with something of the order of 21M contentions out of 27M acquisitions, and an average wait time of 26 us for the lock. This is not efficient. A more scalable design is to follow the ppc model, where the iommu_table has multiple pools, each stretching over a segment of the map, and with a separate lock for each pool. This model allows for better parallelization of the iommu map search.

This patch adds the iommu range alloc/free function infrastructure.

---
 include/linux/iommu-common.h |   70 +++++++++++++++
 lib/Makefile                 |    2 +-
 lib/iommu-common.c           |  200 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 271 insertions(+), 1 deletions(-)
 create mode 100644 include/linux/iommu-common.h
 create mode 100644 lib/iommu-common.c
include/linux/iommu-common.h new file +70 -0
new file mode 100644
index 0000000..e1ae2d5
@@ -0,0 +1,70 @@
+#ifndef _LINUX_IOMMU_COMMON_H
+#define _LINUX_IOMMU_COMMON_H
+
+#include <asm/page.h>
+#include <linux/spinlock_types.h>
+#include <linux/device.h>
+
+#define IOMMU_NUM_CTXS  4096
+
+#define IOMMU_POOL_HASHBITS     4
+#define IOMMU_NR_POOLS          (1 << IOMMU_POOL_HASHBITS)
+#define	IOMMU_ERROR_CODE	(~(dma_addr_t)0x0)
+
+struct iommu_pool {
+	unsigned long	start;
+	unsigned long	end;
+	unsigned long	hint;
+	spinlock_t	lock;
+};
+
+struct iommu_table;
+
+struct iommu_ops {
+	void	(*demap)(void *, unsigned long, unsigned long);
+};
+
+struct iommu_table {
+	spinlock_t		table_lock;
+	void			(*flush_all)(struct iommu_table *);
+	iopte_t			*page_table;
+	u32			page_table_map_base;
+	unsigned long		iommu_control;
+	unsigned long		iommu_tsbbase;
+	unsigned long		iommu_flush;
+	unsigned long		iommu_flushinv;
+	unsigned long		iommu_tags;
+	unsigned long		iommu_ctxflush;
+	unsigned long		write_complete_reg;
+	unsigned long		dummy_page;
+	unsigned long		dummy_page_pa;
+	unsigned long		ctx_lowest_free;
+	DECLARE_BITMAP(ctx_bitmap, IOMMU_NUM_CTXS);
+	u32			dma_addr_mask;
+	u32			page_table_shift;
+	unsigned long		nr_pools;
+	const struct iommu_ops  *iommu_ops;
+	unsigned long		poolsize;
+	struct iommu_pool	arena_pool[IOMMU_NR_POOLS];
+	bool			has_large_pool;
+	struct iommu_pool	large_pool;
+	unsigned long		*map;
+};
+
+extern void iommu_tbl_pool_init(struct iommu_table *iommu,
+				unsigned long num_entries,
+				u32 page_table_shift,
+				const struct iommu_ops *iommu_ops,
+				bool large_pool);
+
+extern unsigned long iommu_tbl_range_alloc(struct device *dev,
+                                struct iommu_table *iommu,
+                                unsigned long npages,
+                                unsigned long *handle,
+                                unsigned int pool_hash);
+
+extern void iommu_tbl_range_free(struct iommu_table *iommu,
+				 dma_addr_t dma_addr, unsigned long npages,
+				 bool do_demap, void *demap_arg);
+
+#endif
lib/Makefile +1 -1
index 3c3b30b..0ea2ac6 100644
@@ -102,7 +102,7 @@ obj-$(CONFIG_AUDIT_GENERIC) += audit.o
 obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o
 
 obj-$(CONFIG_SWIOTLB) += swiotlb.o
-obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
+obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o iommu-common.o
 obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
 obj-$(CONFIG_NOTIFIER_ERROR_INJECTION) += notifier-error-inject.o
 obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o
lib/iommu-common.c new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

From: Sowmini Varadhan <[email protected]>
Date: Mon, 22 Dec 2014 17:43:21 -0500

Quoted 10 lines

Investigation of multithreaded iperf experiments on an ethernet interface show the iommu->lock as the hottest lock identified by lockstat, with something of the order of 21M contentions out of 27M acquisitions, and an average wait time of 26 us for the lock. This is not efficient. A more scalable design is to follow the ppc model, where the iommu_table has multiple pools, each stretching over a segment of the map, and with a separate lock for each pool. This model allows for better parallelization of the iommu map search.

Quoted 3 lines

This patch adds the iommu range alloc/free function infrastructure.

You're putting tons of sparc specific junk into the "generic" abstraction.

There's nothing generic about a flush_all callback, or an opaque write_complete_reg address. I could go on and on.

Please rewrite this so that only the truly generic stuff, which is %100 agnostic to IOMMU design or architecutre, goes into the new "generic" code.

#2 lore raw
In reply to Sowmini Varadhan
Quoted 3 lines

Please rewrite this so that only the truly generic stuff, which is %100 agnostic to IOMMU design or architecutre, goes into the new "generic" code.

I just remembered that I forgot to note the changes since V1 in each patch of the V2 version of the set that I just sent out, though I have a detailed description in the cover letter.

Sorry about that. I can send out v3, if a description of the per-patch deltas are needed.

--Sowmini

#3 lore raw
In reply to Sowmini Varadhan

Hi Sowmini,

Quoted 10 lines · Sowmini Varadhan
Quoted 3 lines

Please rewrite this so that only the truly generic stuff, which is %100 agnostic to IOMMU design or architecutre, goes into the new "generic" code.

I just remembered that I forgot to note the changes since V1 in each patch of the V2 version of the set that I just sent out, though I have a detailed description in the cover letter.

Sorry about that. I can send out v3, if a description of the per-patch deltas are needed.

You might want to re-read David's email, I think you're missing the point here.

The issue isn't the lack of change descriptions, the issue is that you've added lots of Sparc specific stuff to the generic implementation.

You might want to re-read your changes with that in mind and either justify or change things appropriately. (By justify, I mean point out that some other arch needs whatever facility too)

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/