Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1375432 > unrolled thread
| Started by | Shawn Guo <shawnguo@kernel.org> |
|---|---|
| First post | 2016-04-11 04:50 +0200 |
| Last post | 2016-04-11 14:40 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] scatterlist: use sg_dma_len() in sg_set_page() Shawn Guo <shawnguo@kernel.org> - 2016-04-11 04:50 +0200
Re: [PATCH] scatterlist: use sg_dma_len() in sg_set_page() Robin Murphy <robin.murphy@arm.com> - 2016-04-11 12:40 +0200
Re: [PATCH] scatterlist: use sg_dma_len() in sg_set_page() Shawn Guo <shawnguo@kernel.org> - 2016-04-11 14:40 +0200
| From | Shawn Guo <shawnguo@kernel.org> |
|---|---|
| Date | 2016-04-11 04:50 +0200 |
| Subject | [PATCH] scatterlist: use sg_dma_len() in sg_set_page() |
| Message-ID | <rmA5k-71S-11@gated-at.bofh.it> |
The macro sg_dma_len(sg) is commonly used to retrieve length of sg,
which could be 'dma_length' or 'length' field, depending on whether
NEED_SG_DMA_LENGTH is enabled or not. On the other hand, many driver
code use helper function sg_set_page() to set an sg entry pointing at
a page, with offset and length set up in one call. But sg_set_page()
does not consider NEED_SG_DMA_LENGTH case and only set up 'length'
field. This causes problem on platforms like ARM64, where
NEED_SG_DMA_LENGTH is enabled by default, i.e. sg_set_page() sets up
'length' while sg_dma_len(sg) returns 'dma_length' field.
The patch changes sg_set_page() to use sg_dma_len() for sg length setup
as well, so that NEED_SG_DMA_LENGTH case can be handled.
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
---
include/linux/scatterlist.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 556ec1ea2574..b0e32ea594c3 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -114,7 +114,7 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page,
{
sg_assign_page(sg, page);
sg->offset = offset;
- sg->length = len;
+ sg_dma_len(sg) = len;
}
static inline struct page *sg_page(struct scatterlist *sg)
--
1.9.1
[toc] | [next] | [standalone]
| From | Robin Murphy <robin.murphy@arm.com> |
|---|---|
| Date | 2016-04-11 12:40 +0200 |
| Message-ID | <rmHq9-4eH-1@gated-at.bofh.it> |
| In reply to | #1375432 |
Hi Shawn,
On 11/04/16 03:47, Shawn Guo wrote:
> The macro sg_dma_len(sg) is commonly used to retrieve length of sg,
> which could be 'dma_length' or 'length' field, depending on whether
> NEED_SG_DMA_LENGTH is enabled or not. On the other hand, many driver
> code use helper function sg_set_page() to set an sg entry pointing at
> a page, with offset and length set up in one call. But sg_set_page()
> does not consider NEED_SG_DMA_LENGTH case and only set up 'length'
> field. This causes problem on platforms like ARM64, where
> NEED_SG_DMA_LENGTH is enabled by default, i.e. sg_set_page() sets up
> 'length' while sg_dma_len(sg) returns 'dma_length' field.
>
> The patch changes sg_set_page() to use sg_dma_len() for sg length setup
> as well, so that NEED_SG_DMA_LENGTH case can be handled.
>
> Signed-off-by: Shawn Guo <shawnguo@kernel.org>
> ---
> include/linux/scatterlist.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
> index 556ec1ea2574..b0e32ea594c3 100644
> --- a/include/linux/scatterlist.h
> +++ b/include/linux/scatterlist.h
> @@ -114,7 +114,7 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page,
> {
> sg_assign_page(sg, page);
> sg->offset = offset;
> - sg->length = len;
> + sg_dma_len(sg) = len;
This looks wrong. If a driver is building a scatterlist, then it needs
to fill in the page, offset and length fields to describe the physical
layout - leaving sg->length uninitialised would be a recipe for disaster
- then pass it to the DMA API. Only the DMA API implementation should be
setting dma_addr and dma_len, and they may not correspond to the
physical layout at all (e.g. an IOMMU could concatenate the entire list
into a single much longer segment at whatever arbitrary DMA address it
chooses).
Is there some particular driver hiccup behind this?
Robin.
> }
>
> static inline struct page *sg_page(struct scatterlist *sg)
>
[toc] | [prev] | [next] | [standalone]
| From | Shawn Guo <shawnguo@kernel.org> |
|---|---|
| Date | 2016-04-11 14:40 +0200 |
| Message-ID | <rmJih-5XE-1@gated-at.bofh.it> |
| In reply to | #1375670 |
On Mon, Apr 11, 2016 at 11:31:04AM +0100, Robin Murphy wrote:
> Hi Shawn,
>
> On 11/04/16 03:47, Shawn Guo wrote:
> >The macro sg_dma_len(sg) is commonly used to retrieve length of sg,
> >which could be 'dma_length' or 'length' field, depending on whether
> >NEED_SG_DMA_LENGTH is enabled or not. On the other hand, many driver
> >code use helper function sg_set_page() to set an sg entry pointing at
> >a page, with offset and length set up in one call. But sg_set_page()
> >does not consider NEED_SG_DMA_LENGTH case and only set up 'length'
> >field. This causes problem on platforms like ARM64, where
> >NEED_SG_DMA_LENGTH is enabled by default, i.e. sg_set_page() sets up
> >'length' while sg_dma_len(sg) returns 'dma_length' field.
> >
> >The patch changes sg_set_page() to use sg_dma_len() for sg length setup
> >as well, so that NEED_SG_DMA_LENGTH case can be handled.
> >
> >Signed-off-by: Shawn Guo <shawnguo@kernel.org>
> >---
> > include/linux/scatterlist.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
> >index 556ec1ea2574..b0e32ea594c3 100644
> >--- a/include/linux/scatterlist.h
> >+++ b/include/linux/scatterlist.h
> >@@ -114,7 +114,7 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page,
> > {
> > sg_assign_page(sg, page);
> > sg->offset = offset;
> >- sg->length = len;
> >+ sg_dma_len(sg) = len;
>
> This looks wrong. If a driver is building a scatterlist, then it
> needs to fill in the page, offset and length fields to describe the
> physical layout - leaving sg->length uninitialised would be a recipe
> for disaster - then pass it to the DMA API. Only the DMA API
> implementation should be setting dma_addr and dma_len, and they may
> not correspond to the physical layout at all (e.g. an IOMMU could
> concatenate the entire list into a single much longer segment at
> whatever arbitrary DMA address it chooses).
Thanks for the hint, Robin. Yes, you're right, the proposed change is
just wrong. I just found the correct fix to my problem, i.e. commit
70bc916b2c80 (staging: android: ion: Set the length of the DMA sg entries
in buffer). It should be applied for stable kernel, IMO.
Shawn
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web