linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area
@ 2018-02-05  2:30 ` Masami Hiramatsu
  2018-02-05  4:54   ` Masami Hiramatsu
  2018-02-05  8:47   ` Marek Szyprowski
  0 siblings, 2 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2018-02-05  2:30 UTC (permalink / raw)
  To: Pawel Osciak, Marek Szyprowski, Kyungmin Park
  Cc: mhiramat, Mauro Carvalho Chehab, linux-media, linux-kernel,
	orito.takao

Fixes vb2_vmalloc_get_userptr() to ioremap correct area.
Since the current code does ioremap the page address, if the offset > 0,
it does not do ioremap the last page and results in kernel panic.

This fixes to pass the page address + offset to ioremap so that ioremap
can map correct area. Also, this uses __pfn_to_phys() to get the physical
address of given PFN.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Reported-by: Takao Orito <orito.takao@socionext.com>
---
 drivers/media/v4l2-core/videobuf2-vmalloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 3a7c80cd1a17..896f2f378b40 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -106,7 +106,7 @@ static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr,
 			if (nums[i-1] + 1 != nums[i])
 				goto fail_map;
 		buf->vaddr = (__force void *)
-				ioremap_nocache(nums[0] << PAGE_SHIFT, size);
+			ioremap_nocache(__pfn_to_phys(nums[0]) + offset, size);
 	} else {
 		buf->vaddr = vm_map_ram(frame_vector_pages(vec), n_pages, -1,
 					PAGE_KERNEL);

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

* Re: [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area
  2018-02-05  2:30 ` [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area Masami Hiramatsu
@ 2018-02-05  4:54   ` Masami Hiramatsu
  2018-02-05  8:47   ` Marek Szyprowski
  1 sibling, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2018-02-05  4:54 UTC (permalink / raw)
  To: Pawel Osciak, Marek Szyprowski, Kyungmin Park, Masami Hiramatsu
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, orito.takao,
	masami.hiramatsu

On Mon,  5 Feb 2018 11:30:41 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Fixes vb2_vmalloc_get_userptr() to ioremap correct area.
> Since the current code does ioremap the page address, if the offset > 0,
> it does not do ioremap the last page and results in kernel panic.
> 
> This fixes to pass the page address + offset to ioremap so that ioremap
> can map correct area. Also, this uses __pfn_to_phys() to get the physical
> address of given PFN.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> Reported-by: Takao Orito <orito.takao@socionext.com>

Oops, I've missed the original reporter.

Reported-by: Fumihiro ATSUMI <atsumi@infinitegra.co.jp>

Thank you,

> ---
>  drivers/media/v4l2-core/videobuf2-vmalloc.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
> index 3a7c80cd1a17..896f2f378b40 100644
> --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
> +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
> @@ -106,7 +106,7 @@ static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr,
>  			if (nums[i-1] + 1 != nums[i])
>  				goto fail_map;
>  		buf->vaddr = (__force void *)
> -				ioremap_nocache(nums[0] << PAGE_SHIFT, size);
> +			ioremap_nocache(__pfn_to_phys(nums[0]) + offset, size);
>  	} else {
>  		buf->vaddr = vm_map_ram(frame_vector_pages(vec), n_pages, -1,
>  					PAGE_KERNEL);
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area
  2018-02-05  2:30 ` [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area Masami Hiramatsu
  2018-02-05  4:54   ` Masami Hiramatsu
@ 2018-02-05  8:47   ` Marek Szyprowski
  2018-02-05 13:51     ` Masami Hiramatsu
  1 sibling, 1 reply; 4+ messages in thread
From: Marek Szyprowski @ 2018-02-05  8:47 UTC (permalink / raw)
  To: Masami Hiramatsu, Pawel Osciak, Kyungmin Park
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, orito.takao,
	Fumihiro ATSUMI

Hi Masami,

On 2018-02-05 03:30, Masami Hiramatsu wrote:
> Fixes vb2_vmalloc_get_userptr() to ioremap correct area.
> Since the current code does ioremap the page address, if the offset > 0,
> it does not do ioremap the last page and results in kernel panic.
>
> This fixes to pass the page address + offset to ioremap so that ioremap
> can map correct area. Also, this uses __pfn_to_phys() to get the physical
> address of given PFN.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> Reported-by: Takao Orito <orito.takao@socionext.com>
> ---
>   drivers/media/v4l2-core/videobuf2-vmalloc.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
> index 3a7c80cd1a17..896f2f378b40 100644
> --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
> +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
> @@ -106,7 +106,7 @@ static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr,
>   			if (nums[i-1] + 1 != nums[i])
>   				goto fail_map;
>   		buf->vaddr = (__force void *)
> -				ioremap_nocache(nums[0] << PAGE_SHIFT, size);
> +			ioremap_nocache(__pfn_to_phys(nums[0]) + offset, size);

Thanks for reporting this issue. However the above line doesn't look like
a proper fix. Please note that at the end of that function there is already
"buf->vaddr += offset;".

IMHO the proper fix is to create a larger mapping, which would include the
in-page start offset:

ioremap_nocache(__pfn_to_phys(nums[0]), offset + size);

BTW, thanks for updating "<< PAGE_SHIFT" to better __pfn_to_phys() macro!

>   	} else {
>   		buf->vaddr = vm_map_ram(frame_vector_pages(vec), n_pages, -1,
>   					PAGE_KERNEL);
>
>
>
>

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

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

* Re: [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area
  2018-02-05  8:47   ` Marek Szyprowski
@ 2018-02-05 13:51     ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2018-02-05 13:51 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: Pawel Osciak, Kyungmin Park, Mauro Carvalho Chehab, linux-media,
	linux-kernel, orito.takao, Fumihiro ATSUMI

On Mon, 05 Feb 2018 09:47:46 +0100
Marek Szyprowski <m.szyprowski@samsung.com> wrote:

> Hi Masami,
> 
> On 2018-02-05 03:30, Masami Hiramatsu wrote:
> > Fixes vb2_vmalloc_get_userptr() to ioremap correct area.
> > Since the current code does ioremap the page address, if the offset > 0,
> > it does not do ioremap the last page and results in kernel panic.
> >
> > This fixes to pass the page address + offset to ioremap so that ioremap
> > can map correct area. Also, this uses __pfn_to_phys() to get the physical
> > address of given PFN.
> >
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > Reported-by: Takao Orito <orito.takao@socionext.com>
> > ---
> >   drivers/media/v4l2-core/videobuf2-vmalloc.c |    2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
> > index 3a7c80cd1a17..896f2f378b40 100644
> > --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
> > +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
> > @@ -106,7 +106,7 @@ static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr,
> >   			if (nums[i-1] + 1 != nums[i])
> >   				goto fail_map;
> >   		buf->vaddr = (__force void *)
> > -				ioremap_nocache(nums[0] << PAGE_SHIFT, size);
> > +			ioremap_nocache(__pfn_to_phys(nums[0]) + offset, size);
> 
> Thanks for reporting this issue. However the above line doesn't look like
> a proper fix. Please note that at the end of that function there is already
> "buf->vaddr += offset;".

I see.

> 
> IMHO the proper fix is to create a larger mapping, which would include the
> in-page start offset:
> 
> ioremap_nocache(__pfn_to_phys(nums[0]), offset + size);

Yes, sorry it's my mistake. I misunderstood ioremap_nocache(addr, size) remaps
the PAGE of addr to PAGE of (addr+size). Yours is correct.

Thank you,

> BTW, thanks for updating "<< PAGE_SHIFT" to better __pfn_to_phys() macro!
> 
> >   	} else {
> >   		buf->vaddr = vm_map_ram(frame_vector_pages(vec), n_pages, -1,
> >   					PAGE_KERNEL);
> >
> >
> >
> >
> 
> Best regards
> -- 
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

end of thread, other threads:[~2018-02-05 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20180205023108epcas5p18456b3ecc412b6709dc27fe5af14b1f6@epcas5p1.samsung.com>
2018-02-05  2:30 ` [PATCH] [BUGFIX] media: vb2: Fix videobuf2 to map correct area Masami Hiramatsu
2018-02-05  4:54   ` Masami Hiramatsu
2018-02-05  8:47   ` Marek Szyprowski
2018-02-05 13:51     ` Masami Hiramatsu

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).