IOMMU Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] dma-mapping: do not mapping module memory
@ 2019-11-29 11:03 lijiazi
  2019-12-02  7:22 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: lijiazi @ 2019-11-29 11:03 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Robin Murphy, Andrew Morton
  Cc: lijiazi, linux-mm, iommu

On ARM, x86_64, sparc64 platform, virt_to_page only convert a
_valid_ virtual address to struct page *, virt_addr_valid(x)
indicates whether a virtual address is valid. If ptr is point
to a static variable in module area, virt_to_page will return
a invalid value.

Signed-off-by: lijiazi <lijiazi@xiaomi.com>
---
 include/linux/dma-mapping.h | 10 +++++++---
 mm/vmalloc.c                |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 330ad58..37e645d 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -580,9 +580,13 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev)
 static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
 		size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
-	/* DMA must never operate on areas that might be remapped. */
-	if (dev_WARN_ONCE(dev, is_vmalloc_addr(ptr),
-			  "rejecting DMA map of vmalloc memory\n"))
+	/* DMA must never operate on areas that might be remapped.
+	 * ARM, X86_64, sparc64 put module in a special place, if ptr
+	 * point to static variable in module area, virt_to_page will
+	 * return err page *.
+	 */
+	if (dev_WARN_ONCE(dev, is_vmalloc_or_module_addr(ptr),
+			  "rejecting DMA map of vmalloc or module memory\n"))
 		return DMA_MAPPING_ERROR;
 	debug_dma_map_single(dev, ptr, size);
 	return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr),
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 588303a..71ce6dc 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -262,6 +262,7 @@ int is_vmalloc_or_module_addr(const void *x)
 #endif
 	return is_vmalloc_addr(x);
 }
+EXPORT_SYMBOL(is_vmalloc_or_module_addr);
 
 /*
  * Walk a vmap address to the struct page it maps.
-- 
2.7.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH] dma-mapping: do not mapping module memory
  2019-11-29 11:03 [PATCH] dma-mapping: do not mapping module memory lijiazi
@ 2019-12-02  7:22 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2019-12-02  7:22 UTC (permalink / raw)
  To: lijiazi
  Cc: linux-mm, iommu, lijiazi, Andrew Morton, Robin Murphy, Christoph Hellwig

On Fri, Nov 29, 2019 at 07:03:40PM +0800, lijiazi wrote:
> On ARM, x86_64, sparc64 platform, virt_to_page only convert a
> _valid_ virtual address to struct page *, virt_addr_valid(x)
> indicates whether a virtual address is valid. If ptr is point
> to a static variable in module area, virt_to_page will return
> a invalid value.

While the path isn't wrong, why bother? 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 11:03 [PATCH] dma-mapping: do not mapping module memory lijiazi
2019-12-02  7:22 ` Christoph Hellwig

IOMMU Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iommu/0 linux-iommu/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iommu linux-iommu/ https://lore.kernel.org/linux-iommu \
		iommu@lists.linux-foundation.org
	public-inbox-index linux-iommu

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linux-foundation.lists.iommu


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git