diff mbox

drm/ttm: dma: Don't crash on memory in the vmalloc range

Message ID 1431673794-16169-1-git-send-email-acourbot@nvidia.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alexandre Courbot May 15, 2015, 7:09 a.m. UTC
dma_alloc_coherent() can return memory in the vmalloc range.
virt_to_page() cannot handle such addresses and crashes. This
patch detects such cases and obtains the struct page * using
vmalloc_to_page() instead.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
This patch is a follow-up of the following discussion:

https://www.marc.info/?l=dri-devel&m=141579595431254&w=3

It works for me on both 32-bit and 64-bit Tegra, so I am not convinced
that Thierry's initial change from virt_to_page() to phys_to_page() is
still required - Thierry, can you confirm whether your patch is still
relevant after this one?

 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Thierry Reding May 15, 2015, 10:48 a.m. UTC | #1
On Fri, May 15, 2015 at 04:09:54PM +0900, Alexandre Courbot wrote:
> dma_alloc_coherent() can return memory in the vmalloc range.
> virt_to_page() cannot handle such addresses and crashes. This
> patch detects such cases and obtains the struct page * using
> vmalloc_to_page() instead.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
> This patch is a follow-up of the following discussion:
> 
> https://www.marc.info/?l=dri-devel&m=141579595431254&w=3
> 
> It works for me on both 32-bit and 64-bit Tegra, so I am not convinced
> that Thierry's initial change from virt_to_page() to phys_to_page() is
> still required - Thierry, can you confirm whether your patch is still
> relevant after this one?

If this works for you on both 32-bit and 64-bit Tegra I don't think the
earlier patch is still relevant and this looks indeed like a much more
appropriate solution.

Thierry
Konrad Rzeszutek Wilk May 15, 2015, 7:55 p.m. UTC | #2
On Fri, May 15, 2015 at 04:09:54PM +0900, Alexandre Courbot wrote:
> dma_alloc_coherent() can return memory in the vmalloc range.
> virt_to_page() cannot handle such addresses and crashes. This
> patch detects such cases and obtains the struct page * using
> vmalloc_to_page() instead.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
> This patch is a follow-up of the following discussion:
> 
> https://www.marc.info/?l=dri-devel&m=141579595431254&w=3
> 
> It works for me on both 32-bit and 64-bit Tegra, so I am not convinced
> that Thierry's initial change from virt_to_page() to phys_to_page() is
> still required - Thierry, can you confirm whether your patch is still
> relevant after this one?
> 
>  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> index 01e1d27eb078..3077f1554099 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> @@ -342,9 +342,12 @@ static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool)
>  	d_page->vaddr = dma_alloc_coherent(pool->dev, pool->size,
>  					   &d_page->dma,
>  					   pool->gfp_flags);
> -	if (d_page->vaddr)
> -		d_page->p = virt_to_page(d_page->vaddr);
> -	else {
> +	if (d_page->vaddr) {
> +		if (is_vmalloc_addr(d_page->vaddr))
> +			d_page->p = vmalloc_to_page(d_page->vaddr);
> +		else
> +			d_page->p = virt_to_page(d_page->vaddr);
> +	} else {


Looks OK to me.

>  		kfree(d_page);
>  		d_page = NULL;
>  	}
> -- 
> 2.4.0
>
Alexandre Courbot May 19, 2015, 11:33 a.m. UTC | #3
On 05/16/2015 04:55 AM, Konrad Rzeszutek Wilk wrote:
> On Fri, May 15, 2015 at 04:09:54PM +0900, Alexandre Courbot wrote:
>> dma_alloc_coherent() can return memory in the vmalloc range.
>> virt_to_page() cannot handle such addresses and crashes. This
>> patch detects such cases and obtains the struct page * using
>> vmalloc_to_page() instead.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> ---
>> This patch is a follow-up of the following discussion:
>>
>> https://www.marc.info/?l=dri-devel&m=141579595431254&w=3
>>
>> It works for me on both 32-bit and 64-bit Tegra, so I am not convinced
>> that Thierry's initial change from virt_to_page() to phys_to_page() is
>> still required - Thierry, can you confirm whether your patch is still
>> relevant after this one?
>>
>>   drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
>> index 01e1d27eb078..3077f1554099 100644
>> --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
>> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
>> @@ -342,9 +342,12 @@ static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool)
>>   	d_page->vaddr = dma_alloc_coherent(pool->dev, pool->size,
>>   					   &d_page->dma,
>>   					   pool->gfp_flags);
>> -	if (d_page->vaddr)
>> -		d_page->p = virt_to_page(d_page->vaddr);
>> -	else {
>> +	if (d_page->vaddr) {
>> +		if (is_vmalloc_addr(d_page->vaddr))
>> +			d_page->p = vmalloc_to_page(d_page->vaddr);
>> +		else
>> +			d_page->p = virt_to_page(d_page->vaddr);
>> +	} else {
>
>
> Looks OK to me.

Thanks guys. Could we translate these approvals into 
Acked-bys/Reviewed-bys so Dave (?) can merge this patch?
Konrad Rzeszutek Wilk June 1, 2015, 5:28 p.m. UTC | #4
On Tue, May 19, 2015 at 08:33:59PM +0900, Alexandre Courbot wrote:
> On 05/16/2015 04:55 AM, Konrad Rzeszutek Wilk wrote:
> >On Fri, May 15, 2015 at 04:09:54PM +0900, Alexandre Courbot wrote:
> >>dma_alloc_coherent() can return memory in the vmalloc range.
> >>virt_to_page() cannot handle such addresses and crashes. This
> >>patch detects such cases and obtains the struct page * using
> >>vmalloc_to_page() instead.
> >>
> >>Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> >>---
> >>This patch is a follow-up of the following discussion:
> >>
> >>https://www.marc.info/?l=dri-devel&m=141579595431254&w=3
> >>
> >>It works for me on both 32-bit and 64-bit Tegra, so I am not convinced
> >>that Thierry's initial change from virt_to_page() to phys_to_page() is
> >>still required - Thierry, can you confirm whether your patch is still
> >>relevant after this one?
> >>
> >>  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++++---
> >>  1 file changed, 6 insertions(+), 3 deletions(-)
> >>
> >>diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> >>index 01e1d27eb078..3077f1554099 100644
> >>--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> >>+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> >>@@ -342,9 +342,12 @@ static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool)
> >>  	d_page->vaddr = dma_alloc_coherent(pool->dev, pool->size,
> >>  					   &d_page->dma,
> >>  					   pool->gfp_flags);
> >>-	if (d_page->vaddr)
> >>-		d_page->p = virt_to_page(d_page->vaddr);
> >>-	else {
> >>+	if (d_page->vaddr) {
> >>+		if (is_vmalloc_addr(d_page->vaddr))
> >>+			d_page->p = vmalloc_to_page(d_page->vaddr);
> >>+		else
> >>+			d_page->p = virt_to_page(d_page->vaddr);
> >>+	} else {
> >
> >
> >Looks OK to me.
> 
> Thanks guys. Could we translate these approvals into Acked-bys/Reviewed-bys
> so Dave (?) can merge this patch?

Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
diff mbox

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index 01e1d27eb078..3077f1554099 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -342,9 +342,12 @@  static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool)
 	d_page->vaddr = dma_alloc_coherent(pool->dev, pool->size,
 					   &d_page->dma,
 					   pool->gfp_flags);
-	if (d_page->vaddr)
-		d_page->p = virt_to_page(d_page->vaddr);
-	else {
+	if (d_page->vaddr) {
+		if (is_vmalloc_addr(d_page->vaddr))
+			d_page->p = vmalloc_to_page(d_page->vaddr);
+		else
+			d_page->p = virt_to_page(d_page->vaddr);
+	} else {
 		kfree(d_page);
 		d_page = NULL;
 	}