media: vb2: Fix videobuf2 to map correct area
PATCH 1/1 media: vb2: Fix videobuf2 to map correct area
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.
--- drivers/media/v4l2-core/videobuf2-vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/v4l2-core/videobuf2-vmalloc.c +1 -1
@@ -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 );
Quoted 10 lines · On Mon, 5 Feb 2018 11:30:41 +0900 Masami Hiramatsu <[email protected]> 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 <[email protected]>Reported-by Takao Orito <[email protected]>
Oops, I've missed the original reporter.
Thank you,
Quoted 18 lines
--- drivers/media/v4l2-core/videobuf2-vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/v4l2-core/videobuf2-vmalloc.c +1
-1@@ -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 );
Signature · 1 line
Masami Hiramatsu <[email protected]>
Hi Masami,
Quoted 19 lines · Masami Hiramatsu
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 <[email protected]>Reported-by Takao Orito <[email protected]>--- drivers/media/v4l2-core/videobuf2-vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/v4l2-core/videobuf2-vmalloc.c +0
-0
drivers/media/v4l2-core/videobuf2-vmalloc.c static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr, · line 109
Quoted 5 lines
drivers/media/v4l2-core/videobuf2-vmalloc.c +1
-1@@ -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!
drivers/media/v4l2-core/videobuf2-vmalloc.c static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr, · line 112
Quoted 7 lines
drivers/media/v4l2-core/videobuf2-vmalloc.c +0
-0}else { buf->vaddr =vm_map_ram (frame_vector_pages (vec), n_pages,-1 ,PAGE_KERNEL );
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Quoted 17 lines · On Mon, 05 Feb 2018 09:47:46 +0100 Marek Szyprowski <[email protected]>…
Hi Masami,
Quoted 14 lines · Masami Hiramatsu
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 <[email protected]>Reported-by Takao Orito <[email protected]>--- drivers/media/v4l2-core/videobuf2-vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
drivers/media/v4l2-core/videobuf2-vmalloc.c static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr, · line 109
Quoted 10 lines
drivers/media/v4l2-core/videobuf2-vmalloc.c +1
-1@@ -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.
Quoted 5 lines
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,
Quoted 15 lines
BTW, thanks for updating "<<
PAGE_SHIFT" to better__pfn_to_phys()macro!drivers/media/v4l2-core/videobuf2-vmalloc.c static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr, · line 112
Quoted 7 lines
drivers/media/v4l2-core/videobuf2-vmalloc.c +0
-0}else { buf->vaddr =vm_map_ram (frame_vector_pages (vec), n_pages,-1 ,PAGE_KERNEL );Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Signature · 1 line
Masami Hiramatsu <[email protected]>