All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments
@ 2026-06-03  1:37 ` lirongqing
  2026-06-03 16:25   ` Marek Szyprowski
  0 siblings, 1 reply; 5+ messages in thread
From: lirongqing @ 2026-06-03  1:37 UTC (permalink / raw)
  To: Marek Szyprowski, Robin Murphy, Lu Baolu, Luis Chamberlain,
	Leon Romanovsky, Logan Gunthorpe, Bjorn Helgaas, iommu,
	linux-kernel, hch
  Cc: Li RongQing

From: Li RongQing <lirongqing@baidu.com>

In dma_direct_map_sg(), the case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE
incorrectly used 'break' instead of falling through to MAP_NONE.
As a result, segments traversing the host bridge skipped the required
dma_direct_map_phys() call entirely, leaving sg->dma_address
uninitialized and leading to DMA failures. Fix this by using
'fallthrough;'.

Fixes: a25e7962db0d79 ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 kernel/dma/direct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 583c592..4391b79 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -476,7 +476,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 			 * must be mapped with CPU physical address and not PCI
 			 * bus addresses.
 			 */
-			break;
+			fallthrough;
 		case PCI_P2PDMA_MAP_NONE:
 			need_sync = true;
 			sg->dma_address = dma_direct_map_phys(dev, sg_phys(sg),
-- 
2.9.4


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

* Re: [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments
  2026-06-03  1:37 ` [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments lirongqing
@ 2026-06-03 16:25   ` Marek Szyprowski
  2026-06-04  7:18     ` Leon Romanovsky
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Szyprowski @ 2026-06-03 16:25 UTC (permalink / raw)
  To: lirongqing, Robin Murphy, Lu Baolu, Luis Chamberlain,
	Leon Romanovsky, Logan Gunthorpe, Bjorn Helgaas, iommu,
	linux-kernel, hch

On 03.06.2026 03:37, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> In dma_direct_map_sg(), the case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE
> incorrectly used 'break' instead of falling through to MAP_NONE.
> As a result, segments traversing the host bridge skipped the required
> dma_direct_map_phys() call entirely, leaving sg->dma_address
> uninitialized and leading to DMA failures. Fix this by using
> 'fallthrough;'.
>
> Fixes: a25e7962db0d79 ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
> Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

Applied to dma-mapping-fixes, thanks!


> ---
>  kernel/dma/direct.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 583c592..4391b79 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -476,7 +476,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
>  			 * must be mapped with CPU physical address and not PCI
>  			 * bus addresses.
>  			 */
> -			break;
> +			fallthrough;
>  		case PCI_P2PDMA_MAP_NONE:
>  			need_sync = true;
>  			sg->dma_address = dma_direct_map_phys(dev, sg_phys(sg),

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

* Re: [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments
  2026-06-03 16:25   ` Marek Szyprowski
@ 2026-06-04  7:18     ` Leon Romanovsky
  2026-06-04  7:46       ` Pranjal Shrivastava
  2026-06-08  9:13       ` Marek Szyprowski
  0 siblings, 2 replies; 5+ messages in thread
From: Leon Romanovsky @ 2026-06-04  7:18 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: lirongqing, Robin Murphy, Lu Baolu, Luis Chamberlain,
	Logan Gunthorpe, Bjorn Helgaas, iommu, linux-kernel, hch

On Wed, Jun 03, 2026 at 06:25:22PM +0200, Marek Szyprowski wrote:
> On 03.06.2026 03:37, lirongqing wrote:
> > From: Li RongQing <lirongqing@baidu.com>
> >
> > In dma_direct_map_sg(), the case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE
> > incorrectly used 'break' instead of falling through to MAP_NONE.
> > As a result, segments traversing the host bridge skipped the required
> > dma_direct_map_phys() call entirely, leaving sg->dma_address
> > uninitialized and leading to DMA failures. Fix this by using
> > 'fallthrough;'.
> >
> > Fixes: a25e7962db0d79 ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
> > Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> 
> Applied to dma-mapping-fixes, thanks!

The change looks correct, but it will be better if this change will
improve d0d08f4bd7f6 ("dma-direct: Fix missing sg_dma_len assignment in
P2PDMA bus mappings") too.

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index ec887f443741..e98b6547c950 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -489,9 +489,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
                case PCI_P2PDMA_MAP_BUS_ADDR:
                        sg->dma_address = pci_p2pdma_bus_addr_map(
                                p2pdma_state.mem, sg_phys(sg));
-                       sg_dma_len(sg) = sg->length;
                        sg_dma_mark_bus_address(sg);
-                       continue;
+                       break;
                default:
                        ret = -EREMOTEIO;
                        goto out_unmap;

Thanks

> 
> 
> > ---
> >  kernel/dma/direct.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> > index 583c592..4391b79 100644
> > --- a/kernel/dma/direct.c
> > +++ b/kernel/dma/direct.c
> > @@ -476,7 +476,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
> >  			 * must be mapped with CPU physical address and not PCI
> >  			 * bus addresses.
> >  			 */
> > -			break;
> > +			fallthrough;
> >  		case PCI_P2PDMA_MAP_NONE:
> >  			need_sync = true;
> >  			sg->dma_address = dma_direct_map_phys(dev, sg_phys(sg),
> 
> Best regards
> -- 
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
> 

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

* Re: [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments
  2026-06-04  7:18     ` Leon Romanovsky
@ 2026-06-04  7:46       ` Pranjal Shrivastava
  2026-06-08  9:13       ` Marek Szyprowski
  1 sibling, 0 replies; 5+ messages in thread
From: Pranjal Shrivastava @ 2026-06-04  7:46 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Marek Szyprowski, lirongqing, Robin Murphy, Lu Baolu,
	Luis Chamberlain, Logan Gunthorpe, Bjorn Helgaas, iommu,
	linux-kernel, hch

On Thu, Jun 04, 2026 at 10:18:56AM +0300, Leon Romanovsky wrote:
> On Wed, Jun 03, 2026 at 06:25:22PM +0200, Marek Szyprowski wrote:
> > On 03.06.2026 03:37, lirongqing wrote:
> > > From: Li RongQing <lirongqing@baidu.com>
> > >
> > > In dma_direct_map_sg(), the case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE
> > > incorrectly used 'break' instead of falling through to MAP_NONE.
> > > As a result, segments traversing the host bridge skipped the required
> > > dma_direct_map_phys() call entirely, leaving sg->dma_address
> > > uninitialized and leading to DMA failures. Fix this by using
> > > 'fallthrough;'.
> > >
> > > Fixes: a25e7962db0d79 ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
> > > Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
> > > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > 
> > Applied to dma-mapping-fixes, thanks!
> 
> The change looks correct, but it will be better if this change will
> improve d0d08f4bd7f6 ("dma-direct: Fix missing sg_dma_len assignment in
> P2PDMA bus mappings") too.

I was thinking the same and was about to post a fix.

> 
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index ec887f443741..e98b6547c950 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -489,9 +489,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
>                 case PCI_P2PDMA_MAP_BUS_ADDR:
>                         sg->dma_address = pci_p2pdma_bus_addr_map(
>                                 p2pdma_state.mem, sg_phys(sg));
> -                       sg_dma_len(sg) = sg->length;
>                         sg_dma_mark_bus_address(sg);
> -                       continue;
> +                       break;
>                 default:
>                         ret = -EREMOTEIO;
>                         goto out_unmap;
> 
> Thanks
> 

For this fix:
Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

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

* Re: [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments
  2026-06-04  7:18     ` Leon Romanovsky
  2026-06-04  7:46       ` Pranjal Shrivastava
@ 2026-06-08  9:13       ` Marek Szyprowski
  1 sibling, 0 replies; 5+ messages in thread
From: Marek Szyprowski @ 2026-06-08  9:13 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: lirongqing, Robin Murphy, Lu Baolu, Luis Chamberlain,
	Logan Gunthorpe, Bjorn Helgaas, iommu, linux-kernel, hch

On 04.06.2026 09:18, Leon Romanovsky wrote:
> On Wed, Jun 03, 2026 at 06:25:22PM +0200, Marek Szyprowski wrote:
>> On 03.06.2026 03:37, lirongqing wrote:
>>> From: Li RongQing <lirongqing@baidu.com>
>>>
>>> In dma_direct_map_sg(), the case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE
>>> incorrectly used 'break' instead of falling through to MAP_NONE.
>>> As a result, segments traversing the host bridge skipped the required
>>> dma_direct_map_phys() call entirely, leaving sg->dma_address
>>> uninitialized and leading to DMA failures. Fix this by using
>>> 'fallthrough;'.
>>>
>>> Fixes: a25e7962db0d79 ("PCI/P2PDMA: Refactor the p2pdma mapping helpers")
>>> Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
>>> Signed-off-by: Li RongQing <lirongqing@baidu.com>
>> Applied to dma-mapping-fixes, thanks!
> The change looks correct, but it will be better if this change will
> improve d0d08f4bd7f6 ("dma-direct: Fix missing sg_dma_len assignment in
> P2PDMA bus mappings") too.
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index ec887f443741..e98b6547c950 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -489,9 +489,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
>                 case PCI_P2PDMA_MAP_BUS_ADDR:
>                         sg->dma_address = pci_p2pdma_bus_addr_map(
>                                 p2pdma_state.mem, sg_phys(sg));
> -                       sg_dma_len(sg) = sg->length;
>                         sg_dma_mark_bus_address(sg);
> -                       continue;
> +                       break;
>                 default:
>                         ret = -EREMOTEIO;
>                         goto out_unmap;
>
This makes the code a bit more consistent, but it doesn't fix any bug, so I would prefer it as a separate patch, which would go to -next.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

end of thread, other threads:[~2026-06-08  9:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20260603013739eucas1p2acd3cd59c1083639deb58723d57558af@eucas1p2.samsung.com>
2026-06-03  1:37 ` [PATCH] dma-mapping: direct: fix missing mapping for THRU_HOST_BRIDGE segments lirongqing
2026-06-03 16:25   ` Marek Szyprowski
2026-06-04  7:18     ` Leon Romanovsky
2026-06-04  7:46       ` Pranjal Shrivastava
2026-06-08  9:13       ` Marek Szyprowski

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.