Skip to contentSkip to conversation

iommu/dma: Per-domain flag to control size-alignment

PATCH/RFC Magnus Damm 3 participants 4 messages Jan 27, 2017 – Jan 30, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Magnus Damm <[email protected]>

Introduce the flag "no_size_align" to allow disabling size-alignment on a per-domain basis. This follows the suggestion by the comment in the code, however a per-device control may be preferred?

Needed to make virtual space contiguous for certain devices.

---

 drivers/iommu/dma-iommu.c |    6 +++++-
 include/linux/iommu.h     |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/iommu/dma-iommu.c +5 -1
@@ -209,14 +209,18 @@ static struct iova *__alloc_iova(struct
 	struct iova_domain *iovad = cookie_iovad(domain);
 	unsigned long shift = iova_shift(iovad);
 	unsigned long length = iova_align(iovad, size) >> shift;
+	bool size_aligned = true;
 
 	if (domain->geometry.force_aperture)
 		dma_limit = min(dma_limit, domain->geometry.aperture_end);
+
+	if (domain->no_size_align)
+		size_aligned = false;
 	/*
 	 * Enforce size-alignment to be safe - there could perhaps be an
 	 * attribute to control this per-device, or at least per-domain...
 	 */
-	return alloc_iova(iovad, length, dma_limit >> shift, true);
+	return alloc_iova(iovad, length, dma_limit >> shift, size_aligned);
 }
 
 /* The IOVA allocator knows what we mapped, so just unmap whatever that was */
include/linux/iommu.h +1 -0
@@ -83,6 +83,7 @@ struct iommu_domain {
 	iommu_fault_handler_t handler;
 	void *handler_token;
 	struct iommu_domain_geometry geometry;
+	bool no_size_align;
 	void *iova_cookie;
 };
 
#1 lore raw

Hi Magnus,

Quoted 7 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the flag "no_size_align" to allow disabling size-alignment on a per-domain basis. This follows the suggestion by the comment in the code, however a per-device control may be preferred?

Needed to make virtual space contiguous for certain devices.

That sounds very suspicious - a single allocation is contiguous with itself by definition, and anyone relying on multiple allocations being contiguous with one another is doing it wrong, because there's no way we could ever guarantee that (with this allocator, at any rate). I'd be very reticent to touch this without a specific example of what problem it solves.

Since I understand all this stuff a lot more deeply now that back when I first wrote that comment, I'd say that if there really is some real need to implement this feature, it should be a dma_attr flag, i.e. not even per-device, but per-allocation. We'd be breaking a behaviour currently guaranteed by the DMA API, so we need to be really sure the caller is OK with that - having it be their responsibility to explicitly ask is definitely safest.

Robin.

Quoted 40 lines

---

 drivers/iommu/dma-iommu.c |    6 +++++-
 include/linux/iommu.h     |    1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/iommu/dma-iommu.c +5 -1
@@ -209,14 +209,18 @@ static struct iova *__alloc_iova(struct
 	struct iova_domain *iovad = cookie_iovad(domain);
 	unsigned long shift = iova_shift(iovad);
 	unsigned long length = iova_align(iovad, size) >> shift;
+	bool size_aligned = true;
 
 	if (domain->geometry.force_aperture)
 		dma_limit = min(dma_limit, domain->geometry.aperture_end);
+
+	if (domain->no_size_align)
+		size_aligned = false;
 	/*
 	 * Enforce size-alignment to be safe - there could perhaps be an
 	 * attribute to control this per-device, or at least per-domain...
 	 */
-	return alloc_iova(iovad, length, dma_limit >> shift, true);
+	return alloc_iova(iovad, length, dma_limit >> shift, size_aligned);
 }
 
 /* The IOVA allocator knows what we mapped, so just unmap whatever that was */
include/linux/iommu.h +1 -0
@@ -83,6 +83,7 @@ struct iommu_domain {
 	iommu_fault_handler_t handler;
 	void *handler_token;
 	struct iommu_domain_geometry geometry;
+	bool no_size_align;
 	void *iova_cookie;
 };
 

A message that is not in the archive (sent off-list or not yet received): 464656f9-970e-1271-0d9e-b62a0673e1dd-5wv7dgnIgG8@public.gmane.org

#3 lore raw

Hi Robin, Magnus,

Quoted 13 lines

-----Original Message-----
From: Robin Murphy
Sent: Saturday, January 28, 2017 2:38 AM

Hi Magnus,

Quoted 6 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the flag "no_size_align" to allow disabling size-alignment on a per-domain basis. This follows the suggestion by the comment in the code, however a per-device control may be preferred?

Quoted 8 lines
Quoted 1 line

Needed to make virtual space contiguous for certain devices.

That sounds very suspicious - a single allocation is contiguous with itself by definition, and anyone relying on multiple allocations being contiguous with one another is doing it wrong, because there's no way we could ever guarantee that (with this allocator, at any rate). I'd be very reticent to touch this without a specific example of what problem it solves.

Thank you for the comment! This patch was from my request. But, I completely misunderstood this "size-alignment" behavior. And, my concern was already resolved by the following patch at last April:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/iommu?id=809eac54cdd62c67afea1e17080e681dfa33dc09

So, no one needs this patch anymore.

Best regards,
Yoshihiro Shimoda

A message that is not in the archive (sent off-list or not yet received): HK2PR06MB05481A6F9E20CCAC13F9A336D84B0-jAC1QCBx2F3DOGFS7+tQZW0DtJ1/[email protected]

#5 lore raw
Quoted 24 lines · Yoshihiro Shimoda

Hi Robin, Magnus,

Quoted 13 lines

-----Original Message-----
From: Robin Murphy
Sent: Saturday, January 28, 2017 2:38 AM

Hi Magnus,

Quoted 6 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the flag "no_size_align" to allow disabling size-alignment on a per-domain basis. This follows the suggestion by the comment in the code, however a per-device control may be preferred?

Quoted 8 lines
Quoted 1 line

Needed to make virtual space contiguous for certain devices.

That sounds very suspicious - a single allocation is contiguous with itself by definition, and anyone relying on multiple allocations being contiguous with one another is doing it wrong, because there's no way we could ever guarantee that (with this allocator, at any rate). I'd be very reticent to touch this without a specific example of what problem it solves.

Quoted 6 lines

Thank you for the comment! This patch was from my request. But, I completely misunderstood this "size-alignment" behavior. And, my concern was already resolved by the following patch at last April:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/iommu?id=809eac54cdd62c67afea1e17080e681dfa33dc09

So, no one needs this patch anymore.

Cool, thanks for the clarification :)

Robin.

Quoted 4 lines

Best regards,
Yoshihiro Shimoda