All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] Preparation to .map_page and .unmap_page removal
@ 2025-07-20  9:35 Leon Romanovsky
  2025-07-20  9:35 ` [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address Leon Romanovsky
  2025-07-20  9:35 ` [PATCH v1 2/2] dma-mapping: convert dummy ops to physical address mapping Leon Romanovsky
  0 siblings, 2 replies; 5+ messages in thread
From: Leon Romanovsky @ 2025-07-20  9:35 UTC (permalink / raw)
  To: Marek Szyprowski; +Cc: iommu

Changelog:
v1:
 * Changed "else if" instead of "if".
v0: https://lore.kernel.org/all/cover.1752734252.git.leon@kernel.org
---------------------------------------------------------------------

This is followup to "dma-mapping: migrate to physical address-based API"
series https://lore.kernel.org/all/cover.1750854543.git.leon@kernel.org/

These preparation changes are limited to DMA subsystem to avoid possible
complications with submission to multiple trees.

Thanks

Leon Romanovsky (2):
  dma-mapping: prepare dma_map_ops to conversion to physical address
  dma-mapping: convert dummy ops to physical address mapping

 include/linux/dma-map-ops.h |  6 ++++++
 kernel/dma/dummy.c          | 13 ++++++-------
 kernel/dma/mapping.c        | 24 ++++++++++++++++++++----
 kernel/dma/ops_helpers.c    | 14 +++++++++++---
 4 files changed, 43 insertions(+), 14 deletions(-)

-- 
2.50.1


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

* [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address
  2025-07-20  9:35 [PATCH v1 0/2] Preparation to .map_page and .unmap_page removal Leon Romanovsky
@ 2025-07-20  9:35 ` Leon Romanovsky
  2025-07-20 11:28   ` kernel test robot
  2025-07-20  9:35 ` [PATCH v1 2/2] dma-mapping: convert dummy ops to physical address mapping Leon Romanovsky
  1 sibling, 1 reply; 5+ messages in thread
From: Leon Romanovsky @ 2025-07-20  9:35 UTC (permalink / raw)
  To: Marek Szyprowski; +Cc: Leon Romanovsky, iommu

From: Leon Romanovsky <leonro@nvidia.com>

Add new .map_phys() and .unmap_phys() callbacks to dma_map_ops as a
preparation to replace .map_page() and .unmap_page() respectively.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 include/linux/dma-map-ops.h |  6 ++++++
 kernel/dma/mapping.c        | 24 ++++++++++++++++++++----
 kernel/dma/ops_helpers.c    | 14 +++++++++++---
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 71f5b30254159..0048ec28ed43b 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -37,6 +37,12 @@ struct dma_map_ops {
 	void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
 			size_t size, enum dma_data_direction dir,
 			unsigned long attrs);
+	dma_addr_t (*map_phys)(struct device *dev, phys_addr_t phys,
+			size_t size, enum dma_data_direction dir,
+			unsigned long attrs);
+	void (*unmap_phys)(struct device *dev, dma_addr_t dma_handle,
+			size_t size, enum dma_data_direction dir,
+			unsigned long attrs);
 	/*
 	 * map_sg should return a negative error code on error. See
 	 * dma_map_sgtable() for a list of appropriate error codes
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 8d29ff76aa4db..bf700abe0a4fa 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -173,9 +173,13 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
 		size_t offset = offset_in_page(phys);
 		bool is_pfn_valid = true;
 
-		if (IS_ENABLED(CONFIG_DMA_API_DEBUG))
+		if (IS_ENABLED(CONFIG_DMA_API_DEBUG)) {
 			is_pfn_valid = pfn_valid(PHYS_PFN(phys));
 
+			/* We shouldn't have both functions */
+			WARN_ON_ONCE(ops->map_page && ops->map_phys);
+		}
+
 		if (unlikely(!is_pfn_valid))
 			return DMA_MAPPING_ERROR;
 
@@ -183,7 +187,11 @@ dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
 		 * All platforms which implement .map_page() don't support
 		 * non-struct page backed addresses.
 		 */
-		addr = ops->map_page(dev, page, offset, size, dir, attrs);
+		if (ops->map_phys)
+			addr = ops->map_phys(dev, phys, size, dir, attrs);
+		else if (ops->map_page)
+			addr = ops->map_page(dev, page, offset, size, dir,
+					     attrs);
 	}
 
 	kmsan_handle_dma(phys, size, dir);
@@ -213,8 +221,16 @@ void dma_unmap_phys(struct device *dev, dma_addr_t addr, size_t size,
 		dma_direct_unmap_phys(dev, addr, size, dir, attrs);
 	else if (use_dma_iommu(dev))
 		iommu_dma_unmap_phys(dev, addr, size, dir, attrs);
-	else
-		ops->unmap_page(dev, addr, size, dir, attrs);
+	else {
+		if (IS_ENABLED(CONFIG_DMA_API_DEBUG))
+			/* We shouldn't have both functions */
+			WARN_ON_ONCE(ops->unmap_page && ops->unmap_phys);
+
+		if (ops->unmap_phys)
+			ops->unmap_phys(dev, addr, size, dir, attrs);
+		else if (ops->unmap_page)
+			ops->unmap_page(dev, addr, size, dir, attrs);
+	}
 	trace_dma_unmap_phys(dev, addr, size, dir, attrs);
 	debug_dma_unmap_phys(dev, addr, size, dir);
 }
diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c
index 6f9d604d9d406..64daa1428c022 100644
--- a/kernel/dma/ops_helpers.c
+++ b/kernel/dma/ops_helpers.c
@@ -64,6 +64,7 @@ struct page *dma_common_alloc_pages(struct device *dev, size_t size,
 {
 	const struct dma_map_ops *ops = get_dma_ops(dev);
 	struct page *page;
+	phys_addr_t phys;
 
 	page = dma_alloc_contiguous(dev, size, gfp);
 	if (!page)
@@ -71,10 +72,14 @@ struct page *dma_common_alloc_pages(struct device *dev, size_t size,
 	if (!page)
 		return NULL;
 
+	phys = page_to_phys(page);
 	if (use_dma_iommu(dev))
-		*dma_handle = iommu_dma_map_phys(dev, page_to_phys(page), size,
-						 dir, DMA_ATTR_SKIP_CPU_SYNC);
-	else
+		*dma_handle = iommu_dma_map_phys(dev, phys, size, dir,
+						 DMA_ATTR_SKIP_CPU_SYNC);
+	else if (ops->map_phys)
+		*dma_handle = ops->map_phys(dev, phys, size, dir,
+					    DMA_ATTR_SKIP_CPU_SYNC);
+	else if (ops->map_page)
 		*dma_handle = ops->map_page(dev, page, 0, size, dir,
 					    DMA_ATTR_SKIP_CPU_SYNC);
 	if (*dma_handle == DMA_MAPPING_ERROR) {
@@ -94,6 +99,9 @@ void dma_common_free_pages(struct device *dev, size_t size, struct page *page,
 	if (use_dma_iommu(dev))
 		iommu_dma_unmap_phys(dev, dma_handle, size, dir,
 				     DMA_ATTR_SKIP_CPU_SYNC);
+	else if (ops->unmap_phys)
+		ops->unmap_phys(dev, dma_handle, size, dir,
+				DMA_ATTR_SKIP_CPU_SYNC);
 	else if (ops->unmap_page)
 		ops->unmap_page(dev, dma_handle, size, dir,
 				DMA_ATTR_SKIP_CPU_SYNC);
-- 
2.50.1


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

* [PATCH v1 2/2] dma-mapping: convert dummy ops to physical address mapping
  2025-07-20  9:35 [PATCH v1 0/2] Preparation to .map_page and .unmap_page removal Leon Romanovsky
  2025-07-20  9:35 ` [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address Leon Romanovsky
@ 2025-07-20  9:35 ` Leon Romanovsky
  1 sibling, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2025-07-20  9:35 UTC (permalink / raw)
  To: Marek Szyprowski; +Cc: Leon Romanovsky, iommu

From: Leon Romanovsky <leonro@nvidia.com>

Change dma_dummy_map_page and dma_dummy_unmap_page routines
to accept physical address and rename them.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 kernel/dma/dummy.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/kernel/dma/dummy.c b/kernel/dma/dummy.c
index 92de80e5b057e..dcc4c619b1389 100644
--- a/kernel/dma/dummy.c
+++ b/kernel/dma/dummy.c
@@ -11,17 +11,16 @@ static int dma_dummy_mmap(struct device *dev, struct vm_area_struct *vma,
 	return -ENXIO;
 }
 
-static dma_addr_t dma_dummy_map_page(struct device *dev, struct page *page,
-		unsigned long offset, size_t size, enum dma_data_direction dir,
-		unsigned long attrs)
+static dma_addr_t dma_dummy_map_phys(struct device *dev, phys_addr_t phys,
+		size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
 	return DMA_MAPPING_ERROR;
 }
-static void dma_dummy_unmap_page(struct device *dev, dma_addr_t dma_handle,
+static void dma_dummy_unmap_phys(struct device *dev, dma_addr_t dma_handle,
 		size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
 	/*
-	 * Dummy ops doesn't support map_page, so unmap_page should never be
+	 * Dummy ops doesn't support map_phys, so unmap_phys should never be
 	 * called.
 	 */
 	WARN_ON_ONCE(true);
@@ -51,8 +50,8 @@ static int dma_dummy_supported(struct device *hwdev, u64 mask)
 
 const struct dma_map_ops dma_dummy_ops = {
 	.mmap                   = dma_dummy_mmap,
-	.map_page               = dma_dummy_map_page,
-	.unmap_page             = dma_dummy_unmap_page,
+	.map_phys               = dma_dummy_map_phys,
+	.unmap_phys             = dma_dummy_unmap_phys,
 	.map_sg                 = dma_dummy_map_sg,
 	.unmap_sg               = dma_dummy_unmap_sg,
 	.dma_supported          = dma_dummy_supported,
-- 
2.50.1


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

* Re: [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address
  2025-07-20  9:35 ` [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address Leon Romanovsky
@ 2025-07-20 11:28   ` kernel test robot
  2025-07-20 13:10     ` Leon Romanovsky
  0 siblings, 1 reply; 5+ messages in thread
From: kernel test robot @ 2025-07-20 11:28 UTC (permalink / raw)
  To: Leon Romanovsky; +Cc: llvm, oe-kbuild-all

Hi Leon,

kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20250718]
[cannot apply to linus/master v6.16-rc6 v6.16-rc5 v6.16-rc4 v6.16-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Leon-Romanovsky/dma-mapping-prepare-dma_map_ops-to-conversion-to-physical-address/20250720-173726
base:   next-20250718
patch link:    https://lore.kernel.org/r/184fc9bda626efc62c5022ace01a20b80d1dc93b.1753003879.git.leon%40kernel.org
patch subject: [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address
config: s390-randconfig-001-20250720 (https://download.01.org/0day-ci/archive/20250720/202507201935.hwB4Ebxp-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 16534d19bf50bde879a83f0ae62875e2c5120e64)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250720/202507201935.hwB4Ebxp-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507201935.hwB4Ebxp-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> kernel/dma/mapping.c:192:12: warning: variable 'addr' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
     192 |                 else if (ops->map_page)
         |                          ^~~~~~~~~~~~~
   kernel/dma/mapping.c:198:32: note: uninitialized use occurs here
     198 |         trace_dma_map_phys(dev, phys, addr, size, dir, attrs);
         |                                       ^~~~
   kernel/dma/mapping.c:192:8: note: remove the 'if' if its condition is always true
     192 |                 else if (ops->map_page)
         |                      ^~~~~~~~~~~~~~~~~~
     193 |                         addr = ops->map_page(dev, page, offset, size, dir,
   kernel/dma/mapping.c:159:17: note: initialize the variable 'addr' to silence this warning
     159 |         dma_addr_t addr;
         |                        ^
         |                         = 0
   1 warning generated.


vim +192 kernel/dma/mapping.c

   154	
   155	dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
   156			enum dma_data_direction dir, unsigned long attrs)
   157	{
   158		const struct dma_map_ops *ops = get_dma_ops(dev);
   159		dma_addr_t addr;
   160	
   161		BUG_ON(!valid_dma_direction(dir));
   162	
   163		if (WARN_ON_ONCE(!dev->dma_mask))
   164			return DMA_MAPPING_ERROR;
   165	
   166		if (dma_map_direct(dev, ops) ||
   167		    arch_dma_map_phys_direct(dev, phys + size))
   168			addr = dma_direct_map_phys(dev, phys, size, dir, attrs);
   169		else if (use_dma_iommu(dev))
   170			addr = iommu_dma_map_phys(dev, phys, size, dir, attrs);
   171		else {
   172			struct page *page = phys_to_page(phys);
   173			size_t offset = offset_in_page(phys);
   174			bool is_pfn_valid = true;
   175	
   176			if (IS_ENABLED(CONFIG_DMA_API_DEBUG)) {
   177				is_pfn_valid = pfn_valid(PHYS_PFN(phys));
   178	
   179				/* We shouldn't have both functions */
   180				WARN_ON_ONCE(ops->map_page && ops->map_phys);
   181			}
   182	
   183			if (unlikely(!is_pfn_valid))
   184				return DMA_MAPPING_ERROR;
   185	
   186			/*
   187			 * All platforms which implement .map_page() don't support
   188			 * non-struct page backed addresses.
   189			 */
   190			if (ops->map_phys)
   191				addr = ops->map_phys(dev, phys, size, dir, attrs);
 > 192			else if (ops->map_page)
   193				addr = ops->map_page(dev, page, offset, size, dir,
   194						     attrs);
   195		}
   196	
   197		kmsan_handle_dma(phys, size, dir);
   198		trace_dma_map_phys(dev, phys, addr, size, dir, attrs);
   199		debug_dma_map_phys(dev, phys, size, dir, addr, attrs);
   200	
   201		return addr;
   202	}
   203	EXPORT_SYMBOL_GPL(dma_map_phys);
   204	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address
  2025-07-20 11:28   ` kernel test robot
@ 2025-07-20 13:10     ` Leon Romanovsky
  0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2025-07-20 13:10 UTC (permalink / raw)
  To: kernel test robot; +Cc: llvm, oe-kbuild-all

On Sun, Jul 20, 2025 at 07:28:05PM +0800, kernel test robot wrote:
> Hi Leon,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on next-20250718]
> [cannot apply to linus/master v6.16-rc6 v6.16-rc5 v6.16-rc4 v6.16-rc6]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Leon-Romanovsky/dma-mapping-prepare-dma_map_ops-to-conversion-to-physical-address/20250720-173726
> base:   next-20250718
> patch link:    https://lore.kernel.org/r/184fc9bda626efc62c5022ace01a20b80d1dc93b.1753003879.git.leon%40kernel.org
> patch subject: [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address
> config: s390-randconfig-001-20250720 (https://download.01.org/0day-ci/archive/20250720/202507201935.hwB4Ebxp-lkp@intel.com/config)
> compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 16534d19bf50bde879a83f0ae62875e2c5120e64)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250720/202507201935.hwB4Ebxp-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202507201935.hwB4Ebxp-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
> >> kernel/dma/mapping.c:192:12: warning: variable 'addr' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>      192 |                 else if (ops->map_page)
>          |                          ^~~~~~~~~~~~~
>    kernel/dma/mapping.c:198:32: note: uninitialized use occurs here
>      198 |         trace_dma_map_phys(dev, phys, addr, size, dir, attrs);
>          |                                       ^~~~
>    kernel/dma/mapping.c:192:8: note: remove the 'if' if its condition is always true
>      192 |                 else if (ops->map_page)
>          |                      ^~~~~~~~~~~~~~~~~~
>      193 |                         addr = ops->map_page(dev, page, offset, size, dir,
>    kernel/dma/mapping.c:159:17: note: initialize the variable 'addr' to silence this warning
>      159 |         dma_addr_t addr;
>          |                        ^
>          |                         = 0
>    1 warning generated.

Strange, I didn't get any warning about it for v1.

Thanks

> 
> 
> vim +192 kernel/dma/mapping.c
> 
>    154	
>    155	dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
>    156			enum dma_data_direction dir, unsigned long attrs)
>    157	{
>    158		const struct dma_map_ops *ops = get_dma_ops(dev);
>    159		dma_addr_t addr;
>    160	
>    161		BUG_ON(!valid_dma_direction(dir));
>    162	
>    163		if (WARN_ON_ONCE(!dev->dma_mask))
>    164			return DMA_MAPPING_ERROR;
>    165	
>    166		if (dma_map_direct(dev, ops) ||
>    167		    arch_dma_map_phys_direct(dev, phys + size))
>    168			addr = dma_direct_map_phys(dev, phys, size, dir, attrs);
>    169		else if (use_dma_iommu(dev))
>    170			addr = iommu_dma_map_phys(dev, phys, size, dir, attrs);
>    171		else {
>    172			struct page *page = phys_to_page(phys);
>    173			size_t offset = offset_in_page(phys);
>    174			bool is_pfn_valid = true;
>    175	
>    176			if (IS_ENABLED(CONFIG_DMA_API_DEBUG)) {
>    177				is_pfn_valid = pfn_valid(PHYS_PFN(phys));
>    178	
>    179				/* We shouldn't have both functions */
>    180				WARN_ON_ONCE(ops->map_page && ops->map_phys);
>    181			}
>    182	
>    183			if (unlikely(!is_pfn_valid))
>    184				return DMA_MAPPING_ERROR;
>    185	
>    186			/*
>    187			 * All platforms which implement .map_page() don't support
>    188			 * non-struct page backed addresses.
>    189			 */
>    190			if (ops->map_phys)
>    191				addr = ops->map_phys(dev, phys, size, dir, attrs);
>  > 192			else if (ops->map_page)
>    193				addr = ops->map_page(dev, page, offset, size, dir,
>    194						     attrs);
>    195		}
>    196	
>    197		kmsan_handle_dma(phys, size, dir);
>    198		trace_dma_map_phys(dev, phys, addr, size, dir, attrs);
>    199		debug_dma_map_phys(dev, phys, size, dir, addr, attrs);
>    200	
>    201		return addr;
>    202	}
>    203	EXPORT_SYMBOL_GPL(dma_map_phys);
>    204	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2025-07-20 13:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20  9:35 [PATCH v1 0/2] Preparation to .map_page and .unmap_page removal Leon Romanovsky
2025-07-20  9:35 ` [PATCH v1 1/2] dma-mapping: prepare dma_map_ops to conversion to physical address Leon Romanovsky
2025-07-20 11:28   ` kernel test robot
2025-07-20 13:10     ` Leon Romanovsky
2025-07-20  9:35 ` [PATCH v1 2/2] dma-mapping: convert dummy ops to physical address mapping Leon Romanovsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.