* [PATCH] iommu/io-pgtable-arm: Don't use dma_to_phys()
@ 2015-09-17 14:22 Robin Murphy
[not found] ` <1c591836f1ec6e676a8889cdccd042650eadb73b.1442499554.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Robin Murphy @ 2015-09-17 14:22 UTC (permalink / raw)
To: will.deacon-5wv7dgnIgG8
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
In checking whether DMA addresses differ from physical addresses, using
dma_to_phys() is actually the wrong thing to do, since it may hide any
DMA offset, which is precisely one of the things we are checking for.
Simply casting between the two address types, whilst ugly, is in fact
the appropriate course of action.
We can also reject any device with a fixed DMA offset up-front at page
table creation, leaving the allocation-time check for the more subtle
cases like bounce buffering due to an incorrect DMA mask.
Furthermore, we can then fix the hackish KConfig dependency so that
architectures without a dma_to_phys() implementation may still
COMPILE_TEST (or even use!) the code. The true dependency is on the
DMA API, so use the appropriate symbol for that.
Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
---
drivers/iommu/Kconfig | 3 +--
drivers/iommu/io-pgtable-arm.c | 16 ++++++++--------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 4664c2a..3dc1bcb 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -23,8 +23,7 @@ config IOMMU_IO_PGTABLE
config IOMMU_IO_PGTABLE_LPAE
bool "ARMv7/v8 Long Descriptor Format"
select IOMMU_IO_PGTABLE
- # SWIOTLB guarantees a dma_to_phys() implementation
- depends on ARM || ARM64 || (COMPILE_TEST && SWIOTLB)
+ depends on HAS_DMA && (ARM || ARM64 || COMPILE_TEST)
help
Enable support for the ARM long descriptor pagetable format.
This allocator supports 4K/2M/1G, 16K/32M and 64K/512M page
diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
index 73c0748..e7f9ab9 100644
--- a/drivers/iommu/io-pgtable-arm.c
+++ b/drivers/iommu/io-pgtable-arm.c
@@ -202,11 +202,6 @@ typedef u64 arm_lpae_iopte;
static bool selftest_running = false;
-static dma_addr_t __arm_lpae_dma_addr(struct device *dev, void *pages)
-{
- return phys_to_dma(dev, virt_to_phys(pages));
-}
-
static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp,
struct io_pgtable_cfg *cfg)
{
@@ -226,7 +221,7 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp,
* address directly, so if the DMA layer suggests it can't by
* giving us back some translation, that bodes very badly...
*/
- if (dma != __arm_lpae_dma_addr(dev, pages))
+ if ((u64)dma != (u64)virt_to_phys(pages))
goto out_unmap;
}
@@ -246,7 +241,7 @@ static void __arm_lpae_free_pages(void *pages, size_t size,
struct device *dev = cfg->iommu_dev;
if (!selftest_running)
- dma_unmap_single(dev, __arm_lpae_dma_addr(dev, pages),
+ dma_unmap_single(dev, (dma_addr_t)virt_to_phys(pages),
size, DMA_TO_DEVICE);
free_pages_exact(pages, size);
}
@@ -259,7 +254,7 @@ static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte,
*ptep = pte;
if (!selftest_running)
- dma_sync_single_for_device(dev, __arm_lpae_dma_addr(dev, ptep),
+ dma_sync_single_for_device(dev, (dma_addr_t)virt_to_phys(ptep),
sizeof(pte), DMA_TO_DEVICE);
}
@@ -629,6 +624,11 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg)
if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS)
return NULL;
+ if (cfg->iommu_dev->dma_pfn_offset) {
+ dev_err(cfg->iommu_dev, "Cannot accommodate DMA offset for IOMMU page tables\n");
+ return NULL;
+ }
+
data = kmalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return NULL;
--
1.9.1
^ permalink raw reply related [flat|nested] 10+ messages in thread[parent not found: <1c591836f1ec6e676a8889cdccd042650eadb73b.1442499554.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <1c591836f1ec6e676a8889cdccd042650eadb73b.1442499554.git.robin.murphy-5wv7dgnIgG8@public.gmane.org> @ 2015-09-17 14:52 ` Will Deacon [not found] ` <20150917145216.GJ25634-5wv7dgnIgG8@public.gmane.org> 2015-09-17 16:42 ` [PATCH v2] " Robin Murphy 1 sibling, 1 reply; 10+ messages in thread From: Will Deacon @ 2015-09-17 14:52 UTC (permalink / raw) To: Robin Murphy Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org On Thu, Sep 17, 2015 at 03:22:20PM +0100, Robin Murphy wrote: > In checking whether DMA addresses differ from physical addresses, using > dma_to_phys() is actually the wrong thing to do, since it may hide any > DMA offset, which is precisely one of the things we are checking for. > Simply casting between the two address types, whilst ugly, is in fact > the appropriate course of action. Urgh... yes. > We can also reject any device with a fixed DMA offset up-front at page > table creation, leaving the allocation-time check for the more subtle > cases like bounce buffering due to an incorrect DMA mask. > > Furthermore, we can then fix the hackish KConfig dependency so that > architectures without a dma_to_phys() implementation may still > COMPILE_TEST (or even use!) the code. The true dependency is on the > DMA API, so use the appropriate symbol for that. > > Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> > --- > drivers/iommu/Kconfig | 3 +-- > drivers/iommu/io-pgtable-arm.c | 16 ++++++++-------- > 2 files changed, 9 insertions(+), 10 deletions(-) > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > index 4664c2a..3dc1bcb 100644 > --- a/drivers/iommu/Kconfig > +++ b/drivers/iommu/Kconfig > @@ -23,8 +23,7 @@ config IOMMU_IO_PGTABLE > config IOMMU_IO_PGTABLE_LPAE > bool "ARMv7/v8 Long Descriptor Format" > select IOMMU_IO_PGTABLE > - # SWIOTLB guarantees a dma_to_phys() implementation > - depends on ARM || ARM64 || (COMPILE_TEST && SWIOTLB) > + depends on HAS_DMA && (ARM || ARM64 || COMPILE_TEST) > help > Enable support for the ARM long descriptor pagetable format. > This allocator supports 4K/2M/1G, 16K/32M and 64K/512M page > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index 73c0748..e7f9ab9 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -202,11 +202,6 @@ typedef u64 arm_lpae_iopte; > > static bool selftest_running = false; > > -static dma_addr_t __arm_lpae_dma_addr(struct device *dev, void *pages) > -{ > - return phys_to_dma(dev, virt_to_phys(pages)); > -} Can we keep this helper kicking around, at least to contain the ugliness of the virt_to_phys + cast? Will ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <20150917145216.GJ25634-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <20150917145216.GJ25634-5wv7dgnIgG8@public.gmane.org> @ 2015-09-17 15:53 ` Robin Murphy 0 siblings, 0 replies; 10+ messages in thread From: Robin Murphy @ 2015-09-17 15:53 UTC (permalink / raw) To: Will Deacon Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org On 17/09/15 15:52, Will Deacon wrote: [...] >> -static dma_addr_t __arm_lpae_dma_addr(struct device *dev, void *pages) >> -{ >> - return phys_to_dma(dev, virt_to_phys(pages)); >> -} > > Can we keep this helper kicking around, at least to contain the ugliness > of the virt_to_phys + cast? Can do for the sync and unmap cases - the alloc_pages one needs to avoid truncation in the comparison if dma_addr_t and phys_addr_t are different sizes, so can't safely cast one to the other either way. I can at least get rid of the u64 casts there though, as they seem superfluous after a bit of experimentation and another read of the good old "Usual arithmetic conversions". I'll fix up and repost. Robin. > > Will > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <1c591836f1ec6e676a8889cdccd042650eadb73b.1442499554.git.robin.murphy-5wv7dgnIgG8@public.gmane.org> 2015-09-17 14:52 ` Will Deacon @ 2015-09-17 16:42 ` Robin Murphy [not found] ` <59f4ebbf06e75a6176a366495211afd16d0048a3.1442507940.git.robin.murphy-5wv7dgnIgG8@public.gmane.org> 1 sibling, 1 reply; 10+ messages in thread From: Robin Murphy @ 2015-09-17 16:42 UTC (permalink / raw) To: will.deacon-5wv7dgnIgG8 Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA In checking whether DMA addresses differ from physical addresses, using dma_to_phys() is actually the wrong thing to do, since it may hide any DMA offset, which is precisely one of the things we are checking for. Simply casting between the two address types, whilst ugly, is in fact the appropriate course of action. Further care (and ugliness) is also necessary in the comparison to avoid truncation if phys_addr_t and dma_addr_t differ in size. We can also reject any device with a fixed DMA offset up-front at page table creation, leaving the allocation-time check for the more subtle cases like bounce buffering due to an incorrect DMA mask. Furthermore, we can then fix the hackish KConfig dependency so that architectures without a dma_to_phys() implementation may still COMPILE_TEST (or even use!) the code. The true dependency is on the DMA API, so use the appropriate symbol for that. Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> --- drivers/iommu/Kconfig | 3 +-- drivers/iommu/io-pgtable-arm.c | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 4664c2a..3dc1bcb 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -23,8 +23,7 @@ config IOMMU_IO_PGTABLE config IOMMU_IO_PGTABLE_LPAE bool "ARMv7/v8 Long Descriptor Format" select IOMMU_IO_PGTABLE - # SWIOTLB guarantees a dma_to_phys() implementation - depends on ARM || ARM64 || (COMPILE_TEST && SWIOTLB) + depends on HAS_DMA && (ARM || ARM64 || COMPILE_TEST) help Enable support for the ARM long descriptor pagetable format. This allocator supports 4K/2M/1G, 16K/32M and 64K/512M page diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 73c0748..96a4baa 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -202,9 +202,9 @@ typedef u64 arm_lpae_iopte; static bool selftest_running = false; -static dma_addr_t __arm_lpae_dma_addr(struct device *dev, void *pages) +static dma_addr_t __arm_lpae_dma_addr(void *pages) { - return phys_to_dma(dev, virt_to_phys(pages)); + return (dma_addr_t)virt_to_phys(pages); } static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, @@ -223,10 +223,10 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, goto out_free; /* * We depend on the IOMMU being able to work with any physical - * address directly, so if the DMA layer suggests it can't by - * giving us back some translation, that bodes very badly... + * address directly, so if the DMA layer suggests otherwise by + * translating or truncating them, that bodes very badly... */ - if (dma != __arm_lpae_dma_addr(dev, pages)) + if (dma != virt_to_phys(pages)) goto out_unmap; } @@ -243,10 +243,8 @@ out_free: static void __arm_lpae_free_pages(void *pages, size_t size, struct io_pgtable_cfg *cfg) { - struct device *dev = cfg->iommu_dev; - if (!selftest_running) - dma_unmap_single(dev, __arm_lpae_dma_addr(dev, pages), + dma_unmap_single(cfg->iommu_dev, __arm_lpae_dma_addr(pages), size, DMA_TO_DEVICE); free_pages_exact(pages, size); } @@ -254,12 +252,11 @@ static void __arm_lpae_free_pages(void *pages, size_t size, static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte, struct io_pgtable_cfg *cfg) { - struct device *dev = cfg->iommu_dev; - *ptep = pte; if (!selftest_running) - dma_sync_single_for_device(dev, __arm_lpae_dma_addr(dev, ptep), + dma_sync_single_for_device(cfg->iommu_dev, + __arm_lpae_dma_addr(ptep), sizeof(pte), DMA_TO_DEVICE); } @@ -629,6 +626,11 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg) if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS) return NULL; + if (cfg->iommu_dev->dma_pfn_offset) { + dev_err(cfg->iommu_dev, "Cannot accommodate DMA offset for IOMMU page tables\n"); + return NULL; + } + data = kmalloc(sizeof(*data), GFP_KERNEL); if (!data) return NULL; -- 1.9.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
[parent not found: <59f4ebbf06e75a6176a366495211afd16d0048a3.1442507940.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <59f4ebbf06e75a6176a366495211afd16d0048a3.1442507940.git.robin.murphy-5wv7dgnIgG8@public.gmane.org> @ 2015-09-18 8:55 ` Yong Wu 2015-09-18 11:04 ` Robin Murphy 0 siblings, 1 reply; 10+ messages in thread From: Yong Wu @ 2015-09-18 8:55 UTC (permalink / raw) To: Robin Murphy Cc: will.deacon-5wv7dgnIgG8, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r On Thu, 2015-09-17 at 17:42 +0100, Robin Murphy wrote: > In checking whether DMA addresses differ from physical addresses, using > dma_to_phys() is actually the wrong thing to do, since it may hide any > DMA offset, which is precisely one of the things we are checking for. > Simply casting between the two address types, whilst ugly, is in fact > the appropriate course of action. Further care (and ugliness) is also > necessary in the comparison to avoid truncation if phys_addr_t and > dma_addr_t differ in size. > > We can also reject any device with a fixed DMA offset up-front at page > table creation, leaving the allocation-time check for the more subtle > cases like bounce buffering due to an incorrect DMA mask. > > Furthermore, we can then fix the hackish KConfig dependency so that > architectures without a dma_to_phys() implementation may still > COMPILE_TEST (or even use!) the code. The true dependency is on the > DMA API, so use the appropriate symbol for that. > > Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> > --- [...] > > static bool selftest_running = false; > > -static dma_addr_t __arm_lpae_dma_addr(struct device *dev, void *pages) > +static dma_addr_t __arm_lpae_dma_addr(void *pages) > { > - return phys_to_dma(dev, virt_to_phys(pages)); > + return (dma_addr_t)virt_to_phys(pages); > } > > static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, > @@ -223,10 +223,10 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, > goto out_free; > /* > * We depend on the IOMMU being able to work with any physical > - * address directly, so if the DMA layer suggests it can't by > - * giving us back some translation, that bodes very badly... > + * address directly, so if the DMA layer suggests otherwise by > + * translating or truncating them, that bodes very badly... > */ > - if (dma != __arm_lpae_dma_addr(dev, pages)) > + if (dma != virt_to_phys(pages)) Could I ask why not use __arm_lpae_dma_addr(pages) here? dma is dma_addr_t. > goto out_unmap; > } > > @@ -243,10 +243,8 @@ out_free: > static void __arm_lpae_free_pages(void *pages, size_t size, > struct io_pgtable_cfg *cfg) > { > - struct device *dev = cfg->iommu_dev; > - > if (!selftest_running) > - dma_unmap_single(dev, __arm_lpae_dma_addr(dev, pages), > + dma_unmap_single(cfg->iommu_dev, __arm_lpae_dma_addr(pages), > size, DMA_TO_DEVICE); > free_pages_exact(pages, size); > } > @@ -254,12 +252,11 @@ static void __arm_lpae_free_pages(void *pages, size_t size, > static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte, > struct io_pgtable_cfg *cfg) > { > - struct device *dev = cfg->iommu_dev; > - > *ptep = pte; > > if (!selftest_running) > - dma_sync_single_for_device(dev, __arm_lpae_dma_addr(dev, ptep), > + dma_sync_single_for_device(cfg->iommu_dev, > + __arm_lpae_dma_addr(ptep), > sizeof(pte), DMA_TO_DEVICE); > } > > @@ -629,6 +626,11 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg) > if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS) > return NULL; > > + if (cfg->iommu_dev->dma_pfn_offset) { > + dev_err(cfg->iommu_dev, "Cannot accommodate DMA offset for IOMMU page tables\n"); > + return NULL; > + } > + > data = kmalloc(sizeof(*data), GFP_KERNEL); > if (!data) > return NULL; ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() 2015-09-18 8:55 ` Yong Wu @ 2015-09-18 11:04 ` Robin Murphy [not found] ` <55FBEFBA.6000606-5wv7dgnIgG8@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Robin Murphy @ 2015-09-18 11:04 UTC (permalink / raw) To: Yong Wu Cc: Will Deacon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org On 18/09/15 09:55, Yong Wu wrote: > On Thu, 2015-09-17 at 17:42 +0100, Robin Murphy wrote: [...] >> the appropriate course of action. Further care (and ugliness) is also >> necessary in the comparison to avoid truncation if phys_addr_t and >> dma_addr_t differ in size. [...] >> /* >> * We depend on the IOMMU being able to work with any physical >> - * address directly, so if the DMA layer suggests it can't by >> - * giving us back some translation, that bodes very badly... >> + * address directly, so if the DMA layer suggests otherwise by >> + * translating or truncating them, that bodes very badly... >> */ >> - if (dma != __arm_lpae_dma_addr(dev, pages)) >> + if (dma != virt_to_phys(pages)) > > Could I ask why not use __arm_lpae_dma_addr(pages) here? > dma is dma_addr_t. Specifically, the problem case for that is when phys_addr_t is 64-bit but dma_addr_t is 32-bit. The cast in __arm_lpae_dma_addr is necessary to avoid a truncation warning when we make the DMA API calls, but we actually need the opposite in the comparison here - comparing the different types directly allows integer promotion to kick in appropriately so we don't lose the top half of the larger address. Otherwise, you'd never spot the difference between, say, your original page at 0x88c0000000 and a bounce-buffered copy that happened to end up mapped to 0xc0000000. Robin. ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <55FBEFBA.6000606-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <55FBEFBA.6000606-5wv7dgnIgG8@public.gmane.org> @ 2015-09-18 12:29 ` Russell King - ARM Linux 2015-09-22 13:25 ` Yong Wu 1 sibling, 0 replies; 10+ messages in thread From: Russell King - ARM Linux @ 2015-09-18 12:29 UTC (permalink / raw) To: Robin Murphy Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Will Deacon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org On Fri, Sep 18, 2015 at 12:04:26PM +0100, Robin Murphy wrote: > Specifically, the problem case for that is when phys_addr_t is 64-bit but > dma_addr_t is 32-bit. The cast in __arm_lpae_dma_addr is necessary to avoid > a truncation warning when we make the DMA API calls, but we actually need > the opposite in the comparison here - comparing the different types directly > allows integer promotion to kick in appropriately so we don't lose the top > half of the larger address. Otherwise, you'd never spot the difference > between, say, your original page at 0x88c0000000 and a bounce-buffered copy > that happened to end up mapped to 0xc0000000. Hmm. Thinking about this, I think we ought to add to arch/arm/mm/Kconfig: config ARCH_PHYS_ADDR_T_64BIT def_bool ARM_LPAE config ARCH_DMA_ADDR_T_64BIT bool + select ARCH_PHYS_ADDR_T_64BIT I seem to remember that you're quite right that dma_addr_t <= phys_addr_t but dma_addr_t must never be bigger than phys_addr_t. -- FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <55FBEFBA.6000606-5wv7dgnIgG8@public.gmane.org> 2015-09-18 12:29 ` Russell King - ARM Linux @ 2015-09-22 13:25 ` Yong Wu 2015-09-22 16:23 ` Robin Murphy 1 sibling, 1 reply; 10+ messages in thread From: Yong Wu @ 2015-09-22 13:25 UTC (permalink / raw) To: Robin Murphy Cc: Will Deacon, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org On Fri, 2015-09-18 at 12:04 +0100, Robin Murphy wrote: > On 18/09/15 09:55, Yong Wu wrote: > > On Thu, 2015-09-17 at 17:42 +0100, Robin Murphy wrote: > [...] > >> the appropriate course of action. Further care (and ugliness) is also > >> necessary in the comparison to avoid truncation if phys_addr_t and > >> dma_addr_t differ in size. > [...] > >> /* > >> * We depend on the IOMMU being able to work with any physical > >> - * address directly, so if the DMA layer suggests it can't by > >> - * giving us back some translation, that bodes very badly... > >> + * address directly, so if the DMA layer suggests otherwise by > >> + * translating or truncating them, that bodes very badly... > >> */ > >> - if (dma != __arm_lpae_dma_addr(dev, pages)) > >> + if (dma != virt_to_phys(pages)) > > > > Could I ask why not use __arm_lpae_dma_addr(pages) here? > > dma is dma_addr_t. > > Specifically, the problem case for that is when phys_addr_t is 64-bit > but dma_addr_t is 32-bit. The cast in __arm_lpae_dma_addr is necessary > to avoid a truncation warning when we make the DMA API calls, but we > actually need the opposite in the comparison here - comparing the > different types directly allows integer promotion to kick in > appropriately so we don't lose the top half of the larger address. > Otherwise, you'd never spot the difference between, say, your original > page at 0x88c0000000 and a bounce-buffered copy that happened to end up > mapped to 0xc0000000. Thanks. About here: > @@ -629,6 +626,11 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg) > if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS) > return NULL; > > + if (cfg->iommu_dev->dma_pfn_offset) { Do we need change to : if (!selftest_running && cfg->iommu_dev->dma_pfn_offset) { cfg->iommu_dev will be null while self test. > + dev_err(cfg->iommu_dev, "Cannot accommodate DMA offset for IOMMU page tables\n"); > + return NULL; > + } > + > data = kmalloc(sizeof(*data), GFP_KERNEL); > if (!data) > return NULL; > > Robin. > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() 2015-09-22 13:25 ` Yong Wu @ 2015-09-22 16:23 ` Robin Murphy [not found] ` <56018074.2010104-5wv7dgnIgG8@public.gmane.org> 0 siblings, 1 reply; 10+ messages in thread From: Robin Murphy @ 2015-09-22 16:23 UTC (permalink / raw) To: Yong Wu, Will Deacon Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org On 22/09/15 14:25, Yong Wu wrote: [...] > About here: >> @@ -629,6 +626,11 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg > *cfg) >> if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS) >> return NULL; >> >> + if (cfg->iommu_dev->dma_pfn_offset) { > > Do we need change to : > if (!selftest_running && cfg->iommu_dev->dma_pfn_offset) { > > cfg->iommu_dev will be null while self test. Urgh, you're absolutely right. Must have been one of those days when I had loads of noisy debug in there and turned the self-tests off :( Will; since the branch hasn't gone anywhere yet, are you OK to take the below? Robin. ----->8----- From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> Date: Tue, 22 Sep 2015 14:52:27 +0100 Subject: [PATCH] fixup! iommu/io-pgtable-arm: Don't use dma_to_phys() Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org> --- drivers/iommu/io-pgtable-arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 1f08ce7..2ba2323 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -628,7 +628,7 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg) if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS) return NULL; - if (cfg->iommu_dev->dma_pfn_offset) { + if (!selftest_running && cfg->iommu_dev->dma_pfn_offset) { dev_err(cfg->iommu_dev, "Cannot accommodate DMA offset for IOMMU page tables\n"); return NULL; } ^ permalink raw reply related [flat|nested] 10+ messages in thread
[parent not found: <56018074.2010104-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH v2] iommu/io-pgtable-arm: Don't use dma_to_phys() [not found] ` <56018074.2010104-5wv7dgnIgG8@public.gmane.org> @ 2015-09-22 16:26 ` Will Deacon 0 siblings, 0 replies; 10+ messages in thread From: Will Deacon @ 2015-09-22 16:26 UTC (permalink / raw) To: Robin Murphy Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org On Tue, Sep 22, 2015 at 05:23:16PM +0100, Robin Murphy wrote: > On 22/09/15 14:25, Yong Wu wrote: > [...] > > About here: > >> @@ -629,6 +626,11 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg > > *cfg) > >> if (cfg->oas > ARM_LPAE_MAX_ADDR_BITS) > >> return NULL; > >> > >> + if (cfg->iommu_dev->dma_pfn_offset) { > > > > Do we need change to : > > if (!selftest_running && cfg->iommu_dev->dma_pfn_offset) { > > > > cfg->iommu_dev will be null while self test. > > Urgh, you're absolutely right. Must have been one of those days when I > had loads of noisy debug in there and turned the self-tests off :( > > Will; since the branch hasn't gone anywhere yet, are you OK to take the below? Yeah, no problem. I'll fold it in when I get a chance. Will ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-09-22 16:26 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-17 14:22 [PATCH] iommu/io-pgtable-arm: Don't use dma_to_phys() Robin Murphy
[not found] ` <1c591836f1ec6e676a8889cdccd042650eadb73b.1442499554.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-09-17 14:52 ` Will Deacon
[not found] ` <20150917145216.GJ25634-5wv7dgnIgG8@public.gmane.org>
2015-09-17 15:53 ` Robin Murphy
2015-09-17 16:42 ` [PATCH v2] " Robin Murphy
[not found] ` <59f4ebbf06e75a6176a366495211afd16d0048a3.1442507940.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-09-18 8:55 ` Yong Wu
2015-09-18 11:04 ` Robin Murphy
[not found] ` <55FBEFBA.6000606-5wv7dgnIgG8@public.gmane.org>
2015-09-18 12:29 ` Russell King - ARM Linux
2015-09-22 13:25 ` Yong Wu
2015-09-22 16:23 ` Robin Murphy
[not found] ` <56018074.2010104-5wv7dgnIgG8@public.gmane.org>
2015-09-22 16:26 ` Will Deacon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox