* [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
@ 2014-11-14 15:40 Charles Keepax
[not found] ` <1415979645-26264-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Charles Keepax @ 2014-11-14 15:40 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A
Cc: lgirdwood-Re5JQEeQqe8AvxtiuMwx3w,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
We can only use page_address on memory that has been mapped using kmap,
when the buffer passed to the SPI has been allocated by vmalloc the page
has not necessarily been mapped through kmap. This means sometimes
page_address will return NULL causing the pointer we pass to sg_set_buf
to be invalid.
As we only call page_address such that we can pass a virtual address to
sg_set_buf which will then immediately call virt_to_page on it, fix this
by calling sg_set_page directly rather then relying on the sg_set_buf
helper.
Signed-off-by: Charles Keepax <ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
drivers/spi/spi.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ebcb33d..50f20f2 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -615,13 +615,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
sg_free_table(sgt);
return -ENOMEM;
}
- sg_buf = page_address(vm_page) +
- ((size_t)buf & ~PAGE_MASK);
+ sg_set_page(&sgt->sgl[i], vm_page,
+ min, offset_in_page(buf));
} else {
sg_buf = buf;
+ sg_set_buf(&sgt->sgl[i], sg_buf, min);
}
- sg_set_buf(&sgt->sgl[i], sg_buf, min);
buf += min;
len -= min;
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1415979645-26264-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-14 15:52 ` Mark Brown
[not found] ` <20141114155222.GF3815-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Mark Brown @ 2014-11-14 15:52 UTC (permalink / raw)
To: Charles Keepax
Cc: lgirdwood-Re5JQEeQqe8AvxtiuMwx3w,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
[-- Attachment #1: Type: text/plain, Size: 568 bytes --]
On Fri, Nov 14, 2014 at 03:40:44PM +0000, Charles Keepax wrote:
> We can only use page_address on memory that has been mapped using kmap,
> when the buffer passed to the SPI has been allocated by vmalloc the page
> has not necessarily been mapped through kmap. This means sometimes
> page_address will return NULL causing the pointer we pass to sg_set_buf
> to be invalid.
Hrm, this is a bug in the mxs driver (which is where we copied the core
code from) - care to fix that too?
> As we only call page_address such that we can pass a virtual address to
s/such/so/
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <20141114155222.GF3815-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-11-14 16:06 ` Charles Keepax
[not found] ` <20141114160607.GB12443-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Charles Keepax @ 2014-11-14 16:06 UTC (permalink / raw)
To: Mark Brown
Cc: lgirdwood-Re5JQEeQqe8AvxtiuMwx3w,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
On Fri, Nov 14, 2014 at 03:52:22PM +0000, Mark Brown wrote:
> On Fri, Nov 14, 2014 at 03:40:44PM +0000, Charles Keepax wrote:
> > We can only use page_address on memory that has been mapped using kmap,
> > when the buffer passed to the SPI has been allocated by vmalloc the page
> > has not necessarily been mapped through kmap. This means sometimes
> > page_address will return NULL causing the pointer we pass to sg_set_buf
> > to be invalid.
>
> Hrm, this is a bug in the mxs driver (which is where we copied the core
> code from) - care to fix that too?
Yeah no problem, won't be able to test it, but should be a fairly
trivial change and hopefully someone else can test.
>
> > As we only call page_address such that we can pass a virtual address to
>
> s/such/so/
Will ping a respin and include the mxs fixup too.
Thanks,
Charles
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <20141114160607.GB12443-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-14 17:11 ` Charles Keepax
[not found] ` <20141114171133.GC12443-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Charles Keepax @ 2014-11-14 17:11 UTC (permalink / raw)
To: Mark Brown
Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E,
lgirdwood-Re5JQEeQqe8AvxtiuMwx3w,
linux-spi-u79uwXL29TY76Z2rM5mHXA
On Fri, Nov 14, 2014 at 04:06:07PM +0000, Charles Keepax wrote:
> On Fri, Nov 14, 2014 at 03:52:22PM +0000, Mark Brown wrote:
> > On Fri, Nov 14, 2014 at 03:40:44PM +0000, Charles Keepax wrote:
> > > We can only use page_address on memory that has been mapped using kmap,
> > > when the buffer passed to the SPI has been allocated by vmalloc the page
> > > has not necessarily been mapped through kmap. This means sometimes
> > > page_address will return NULL causing the pointer we pass to sg_set_buf
> > > to be invalid.
> >
> > Hrm, this is a bug in the mxs driver (which is where we copied the core
> > code from) - care to fix that too?
>
> Yeah no problem, won't be able to test it, but should be a fairly
> trivial change and hopefully someone else can test.
Ah... ok I think I see the difference here. The MXS architecture
has CONFIG_HIGHMEM=n whereas Arndale has CONFIG_HIGHMEM=y. So
that means on MXS all the pages will always be in low mem so I
think will always be mapped into the kernel logical address space
hence no problems. Not sure if it would be worth updating the
driver or not, what do you think?
Thanks,
Charles
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <20141114171133.GC12443-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-14 17:26 ` Mark Brown
[not found] ` <20141114172626.GI3815-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Mark Brown @ 2014-11-14 17:26 UTC (permalink / raw)
To: Charles Keepax
Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E,
lgirdwood-Re5JQEeQqe8AvxtiuMwx3w,
linux-spi-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 637 bytes --]
On Fri, Nov 14, 2014 at 05:11:33PM +0000, Charles Keepax wrote:
> Ah... ok I think I see the difference here. The MXS architecture
> has CONFIG_HIGHMEM=n whereas Arndale has CONFIG_HIGHMEM=y. So
> that means on MXS all the pages will always be in low mem so I
> think will always be mapped into the kernel logical address space
> hence no problems. Not sure if it would be worth updating the
> driver or not, what do you think?
This is a user configurable option, it's not something that depends on
the architecture (and in any case it's better not to leave people
wondering why things are different when they consider consolidation).
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <20141114172626.GI3815-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-11-14 17:41 ` Charles Keepax
0 siblings, 0 replies; 10+ messages in thread
From: Charles Keepax @ 2014-11-14 17:41 UTC (permalink / raw)
To: Mark Brown
Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E,
lgirdwood-Re5JQEeQqe8AvxtiuMwx3w,
linux-spi-u79uwXL29TY76Z2rM5mHXA
On Fri, Nov 14, 2014 at 05:26:26PM +0000, Mark Brown wrote:
> On Fri, Nov 14, 2014 at 05:11:33PM +0000, Charles Keepax wrote:
>
> > Ah... ok I think I see the difference here. The MXS architecture
> > has CONFIG_HIGHMEM=n whereas Arndale has CONFIG_HIGHMEM=y. So
> > that means on MXS all the pages will always be in low mem so I
> > think will always be mapped into the kernel logical address space
> > hence no problems. Not sure if it would be worth updating the
> > driver or not, what do you think?
>
> This is a user configurable option, it's not something that depends on
> the architecture (and in any case it's better not to leave people
> wondering why things are different when they consider consolidation).
Cool, I will do the respin then.
Thanks,
Charles
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
@ 2014-11-17 9:14 Charles Keepax
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: Charles Keepax @ 2014-11-17 9:14 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
We can only use page_address on memory that has been mapped using kmap,
when the buffer passed to the SPI has been allocated by vmalloc the page
has not necessarily been mapped through kmap. This means sometimes
page_address will return NULL causing the pointer we pass to sg_set_buf
to be invalid.
As we only call page_address so that we can pass a virtual address to
sg_set_buf which will then immediately call virt_to_page on it, fix this
by calling sg_set_page directly rather then relying on the sg_set_buf
helper.
Signed-off-by: Charles Keepax <ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
drivers/spi/spi.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ebcb33d..50f20f2 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -615,13 +615,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
sg_free_table(sgt);
return -ENOMEM;
}
- sg_buf = page_address(vm_page) +
- ((size_t)buf & ~PAGE_MASK);
+ sg_set_page(&sgt->sgl[i], vm_page,
+ min, offset_in_page(buf));
} else {
sg_buf = buf;
+ sg_set_buf(&sgt->sgl[i], sg_buf, min);
}
- sg_set_buf(&sgt->sgl[i], sg_buf, min);
buf += min;
len -= min;
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] spi: spi-mxs: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-17 9:14 ` Charles Keepax
[not found] ` <1416215672-31554-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-17 10:40 ` [PATCH 1/2] spi: " Mark Brown
1 sibling, 1 reply; 10+ messages in thread
From: Charles Keepax @ 2014-11-17 9:14 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
We can only use page_address on memory that has been mapped using kmap,
when the buffer passed to the SPI has been allocated by vmalloc the page
has not necessarily been mapped through kmap. This means sometimes
page_address will return NULL causing the pointer we pass to sg_init_one
to be invalid. Currently, this issue doesn't show up on the MXS
architecture as the defconfig defines CONFIG_HIGHMEM=n which means all
pages are mapped. For the sake of robustness though it is best to
correct the issue.
As we only call page_address so that we can pass a virtual address to
sg_init_one which will eventually call virt_to_page on it, fix this
by calling sg_set_page directly rather then relying on the sg_init_one
helper.
Note this patch is only build tested as I don't have an MXS system to
test on.
Signed-off-by: Charles Keepax <ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
drivers/spi/spi-mxs.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
index a9e72f9..06a1154 100644
--- a/drivers/spi/spi-mxs.c
+++ b/drivers/spi/spi-mxs.c
@@ -182,7 +182,6 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi,
int min, ret;
u32 ctrl0;
struct page *vm_page;
- void *sg_buf;
struct {
u32 pio[4];
struct scatterlist sg;
@@ -232,13 +231,14 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi,
ret = -ENOMEM;
goto err_vmalloc;
}
- sg_buf = page_address(vm_page) +
- ((size_t)buf & ~PAGE_MASK);
+
+ sg_init_table(&dma_xfer[sg_count].sg, 1);
+ sg_set_page(&dma_xfer[sg_count].sg, vm_page,
+ min, offset_in_page(buf));
} else {
- sg_buf = buf;
+ sg_init_one(&dma_xfer[sg_count].sg, buf, min);
}
- sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min);
ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
(flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-17 9:14 ` [PATCH 2/2] spi: spi-mxs: " Charles Keepax
@ 2014-11-17 10:40 ` Mark Brown
1 sibling, 0 replies; 10+ messages in thread
From: Mark Brown @ 2014-11-17 10:40 UTC (permalink / raw)
To: Charles Keepax
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
[-- Attachment #1: Type: text/plain, Size: 391 bytes --]
On Mon, Nov 17, 2014 at 09:14:31AM +0000, Charles Keepax wrote:
> We can only use page_address on memory that has been mapped using kmap,
> when the buffer passed to the SPI has been allocated by vmalloc the page
> has not necessarily been mapped through kmap. This means sometimes
> page_address will return NULL causing the pointer we pass to sg_set_buf
> to be invalid.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] spi: spi-mxs: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1416215672-31554-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-24 18:58 ` Mark Brown
0 siblings, 0 replies; 10+ messages in thread
From: Mark Brown @ 2014-11-24 18:58 UTC (permalink / raw)
To: Charles Keepax
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
On Mon, Nov 17, 2014 at 09:14:32AM +0000, Charles Keepax wrote:
> We can only use page_address on memory that has been mapped using kmap,
> when the buffer passed to the SPI has been allocated by vmalloc the page
> has not necessarily been mapped through kmap. This means sometimes
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-11-24 18:58 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-17 9:14 [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list Charles Keepax
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-17 9:14 ` [PATCH 2/2] spi: spi-mxs: " Charles Keepax
[not found] ` <1416215672-31554-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-24 18:58 ` Mark Brown
2014-11-17 10:40 ` [PATCH 1/2] spi: " Mark Brown
-- strict thread matches above, loose matches on Subject: below --
2014-11-14 15:40 Charles Keepax
[not found] ` <1415979645-26264-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-14 15:52 ` Mark Brown
[not found] ` <20141114155222.GF3815-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-11-14 16:06 ` Charles Keepax
[not found] ` <20141114160607.GB12443-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-14 17:11 ` Charles Keepax
[not found] ` <20141114171133.GC12443-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-14 17:26 ` Mark Brown
[not found] ` <20141114172626.GI3815-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-11-14 17:41 ` Charles Keepax
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).