iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/dma: Setup iova_domain granule for IOMMU_DMA_MSI cookies
@ 2017-04-13  8:55 Nate Watterson
       [not found] ` <1492073715-7811-1-git-send-email-nwatters-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Nate Watterson @ 2017-04-13  8:55 UTC (permalink / raw)
  To: robin.murphy-5wv7dgnIgG8, Joerg Roedel,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: shankerd-sgV2jX0FEOL9JmXXK+q4OQ

Currently, the __iommu_dma_{map/free} functions call iova_{offset/align}
making them unsuitable for use with iommu_domains having an IOMMU_DMA_MSI
cookie since the cookie's iova_domain member, iovad, is uninitialized.

Now that iommu_dma_get_msi_page() calls __iommu_dma_map() regardless
of cookie type, failures are being seen when mapping MSI target
addresses for devices attached to UNMANAGED domains. To work around
this issue, the iova_domain granule for IOMMU_DMA_MSI cookies is
initialized to the value returned by cookie_msi_granule().

Fixes: a44e6657585b ("iommu/dma: Clean up MSI IOVA allocation")
Signed-off-by: Nate Watterson <nwatters-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
---
 drivers/iommu/dma-iommu.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 8348f366..d7b0816 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -127,6 +127,16 @@ int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
 
 	cookie->msi_iova = base;
 	domain->iova_cookie = cookie;
+
+	/*
+	 * Setup granule for compatibility with __iommu_dma_{alloc/free} and
+	 * add a compile time check to ensure that writing granule won't
+	 * clobber msi_iova.
+	 */
+	cookie->iovad.granule = cookie_msi_granule(cookie);
+	BUILD_BUG_ON(offsetof(struct iova_domain, granule) <
+			sizeof(cookie->msi_iova));
+
 	return 0;
 }
 EXPORT_SYMBOL(iommu_get_msi_cookie);
-- 
Qualcomm Datacenter Technologies, Inc. on behalf of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux
Foundation Collaborative Project.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-05-16 20:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-13  8:55 [PATCH] iommu/dma: Setup iova_domain granule for IOMMU_DMA_MSI cookies Nate Watterson
     [not found] ` <1492073715-7811-1-git-send-email-nwatters-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-13 11:21   ` Robin Murphy
     [not found]     ` <90fe2111-42e5-ecb1-d0bd-10e06883ae5d-5wv7dgnIgG8@public.gmane.org>
2017-04-13 14:29       ` Shanker Donthineni
     [not found]         ` <383509cb-ae33-e0c4-1c06-8b162acdb555-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-05-04 13:32           ` Bharat Bhushan
2017-04-13 19:38       ` Nate Watterson
     [not found]         ` <95dfaf27-9a74-7a6c-fa77-0fcfe1edbe6e-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-05-16 19:55           ` Auger Eric
     [not found]             ` <694f109c-78ec-ec1e-037f-0a3807c4ef6d-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-05-16 20:07               ` Nate Watterson
     [not found]                 ` <2fa1c68c-2c9a-850c-d5b8-0e30cfd077b0-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-05-16 20:20                   ` Auger Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).