Skip to contentSkip to conversation

remove various dma_declare_coherent related exports

PATCH In review Christoph Hellwig 2 participants 7 messages Sep 2, 2019 – Sep 4, 2019

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

Hi all,

this is a refresh of and older series that tries to ensure that drivers don't use the dma_declare_coherent function, which is intende for platform code. Unfortunately we've actually grown a user in remoteproc since then. While the maintainers havee promised to fix that up that hasn't happened so far, so for now this disabled the modular build for remoteproc until that has been solved.

#1 lore raw

PATCH 1/4 dma-mapping: remove dma_release_declared_memory

This function is entirely unused given that declared memory is generally provided by platform setup code.

---
 Documentation/DMA-API.txt   | 11 -----------
 include/linux/dma-mapping.h |  6 ------
 kernel/dma/coherent.c       | 11 -----------
 3 files changed, 28 deletions(-)
Documentation/DMA-API.txt +0 -11
index e47c63bd4887..c0865ca664b8 100644
@@ -595,17 +595,6 @@ For reasons of efficiency, most platforms choose to track the declared
 region only at the granularity of a page.  For smaller allocations,
 you should use the dma_pool() API.
 
-::
-
-	void
-	dma_release_declared_memory(struct device *dev)
-
-Remove the memory region previously declared from the system.  This
-API performs *no* in-use checking for this region and will return
-unconditionally having removed all the required structures.  It is the
-driver's job to ensure that no parts of this memory region are
-currently in use.
-
 Part III - Debug drivers use of the DMA-API
 -------------------------------------------
 
include/linux/dma-mapping.h +0 -6
index 48ebe8295987..165cd61f1c6e 100644
@@ -753,7 +753,6 @@ static inline int dma_get_cache_alignment(void)
 #ifdef CONFIG_DMA_DECLARE_COHERENT
 int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
 				dma_addr_t device_addr, size_t size);
-void dma_release_declared_memory(struct device *dev);
 #else
 static inline int
 dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
@@ -761,11 +760,6 @@ dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
 {
 	return -ENOSYS;
 }
-
-static inline void
-dma_release_declared_memory(struct device *dev)
-{
-}
 #endif /* CONFIG_DMA_DECLARE_COHERENT */
 
 static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
kernel/dma/coherent.c +0 -11
index 29fd6590dc1e..7271cda86a37 100644
@@ -124,17 +124,6 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
 }
 EXPORT_SYMBOL(dma_declare_coherent_memory);
 
-void dma_release_declared_memory(struct device *dev)
-{
-	struct dma_coherent_mem *mem = dev->dma_mem;
-
-	if (!mem)
-		return;
-	dma_release_coherent_memory(mem);
-	dev->dma_mem = NULL;
-}
-EXPORT_SYMBOL(dma_release_declared_memory);
-
 static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
 		ssize_t size, dma_addr_t *dma_handle)
 {
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/4 dma-mapping: remove the dma_mmap_from_dev_coherent export

In reply to Christoph Hellwig

dma_mmap_from_dev_coherent is only used by dma_map_ops instances, none of which is modular.

---
 kernel/dma/coherent.c | 1 -
 1 file changed, 1 deletion(-)
kernel/dma/coherent.c +0 -1
index 7271cda86a37..7cafe1affdc9 100644
@@ -277,7 +277,6 @@ int dma_mmap_from_dev_coherent(struct device *dev, struct vm_area_struct *vma,
 
 	return __dma_mmap_from_coherent(mem, vma, vaddr, size, ret);
 }
-EXPORT_SYMBOL(dma_mmap_from_dev_coherent);
 
 int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *vaddr,
 				   size_t size, int *ret)
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/4 remoteproc: don't allow modular build

In reply to Christoph Hellwig

Remoteproc started using dma_declare_coherent_memory recently, which is a bad idea from drivers, and the maintainers agreed to fix that. But until that is fixed only allow building the driver built in so that we can remove the dma_declare_coherent_memory export and prevent other drivers from "accidentally" using it like remoteproc. Note that the driver would also leak the declared coherent memory on unload if it actually was built as a module at the moment.

---
 drivers/remoteproc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/Kconfig +1 -1
index 28ed306982f7..94afdde4bc9f 100644
@@ -2,7 +2,7 @@
 menu "Remoteproc drivers"
 
 config REMOTEPROC
-	tristate "Support for Remote Processor subsystem"
+	bool "Support for Remote Processor subsystem"
 	depends on HAS_DMA
 	select CRC32
 	select FW_LOADER
Signature · 1 line
2.20.1
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] remoteproc: don't allow modular build

Quoted 9 lines · Christoph Hellwig

Remoteproc started using dma_declare_coherent_memory recently, which is a bad idea from drivers, and the maintainers agreed to fix that. But until that is fixed only allow building the driver built in so that we can remove the dma_declare_coherent_memory export and prevent other drivers from "accidentally" using it like remoteproc. Note that the driver would also leak the declared coherent memory on unload if it actually was built as a module at the moment.

Please pick this together with the other patches.

Regards,
Bjorn

Quoted 20 lines
---
 drivers/remoteproc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/Kconfig +1 -1
index 28ed306982f7..94afdde4bc9f 100644
@@ -2,7 +2,7 @@
 menu "Remoteproc drivers"
 
 config REMOTEPROC
-	tristate "Support for Remote Processor subsystem"
+	bool "Support for Remote Processor subsystem"
 	depends on HAS_DMA
 	select CRC32
 	select FW_LOADER
Signature · 1 line
2.20.1
#6 lore raw

PATCH 4/4 dma-mapping: remove the dma_declare_coherent_memory export

In reply to Christoph Hellwig

dma_declare_coherent_memory is something that the platform setup code (which pretty much means the device tree these days) need to do so that drivers can use the memory as declared by the platform. Drivers themselves have no business calling this function.

---
 kernel/dma/coherent.c | 1 -
 1 file changed, 1 deletion(-)
kernel/dma/coherent.c +0 -1
index 7cafe1affdc9..545e3869b0e3 100644
@@ -122,7 +122,6 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
 		dma_release_coherent_memory(mem);
 	return ret;
 }
-EXPORT_SYMBOL(dma_declare_coherent_memory);
 
 static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
 		ssize_t size, dma_addr_t *dma_handle)
Signature · 1 line
2.20.1