mm: Introduce new vm_insert_range API
Subsystems (5)
PATCH v2 1/9 mm: Introduce new vm_insert_range API
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking vm_insert_page() within a loop.
As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_range is the new API which will be used to map a range of kernel memory/pages to user vma.
This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)
include/linux/mm_types.h +3 -0
@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );
mm/memory.c +38 -0
@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page
mm/nommu.c +7 -0
@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty
Signature · 1 line
1.9.1
Quoted 28 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0
include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 6 lines
include/linux/mm_types.h +3
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +
This seem to belong to include/linux/mm.h, near vm_insert_page()
Quoted 73 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-0@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty Signature · 1 line
1.9.1
Signature · 2 lines
Sincerely yours, Mike.
Quoted 28 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0
include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 6 lines
include/linux/mm_types.h +3
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +
This seem to belong to include/linux/mm.h, near vm_insert_page()
Quoted 73 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-0@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty Signature · 1 line
1.9.1
Signature · 8 lines
Sincerely yours, Mike. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Mike,
Quoted 33 lines · Mike Rapoport
Quoted 31 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end);
Quoted 5 lines
include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 3 lines
include/linux/mm_types.h +3
-0+int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +This seem to belong to
include/linux/mm.h, nearvm_insert_page()
Ok, I will change it. Apart from this change does it looks good ?
Quoted 79 lines
Quoted 72 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-1@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty -- Quoted 2 lines
1.9.1
--
Sincerely yours,
Mike.
Hi Mike,
Quoted 33 lines · Mike Rapoport
Quoted 31 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end);
Quoted 5 lines
include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 3 lines
include/linux/mm_types.h +3
-0+int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +This seem to belong to
include/linux/mm.h, nearvm_insert_page()
Ok, I will change it. Apart from this change does it looks good ?
Quoted 70 lines
Quoted 70 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-0@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel
Quoted 9 lines
Quoted 4 lines
mm/nommu.c +0
-1* lock, except when an application is doing something nasty --1.9.1
--
Sincerely yours,
Mike.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Mike Rapoport
Reviewed-byQuoted 36 lines · Souptick Joarder
Hi Mike,
Quoted 33 lines · Mike Rapoport
Quoted 31 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end);
Quoted 7 lines
Quoted 5 lines
include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 3 lines
include/linux/mm_types.h +3
-0+int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +This seem to belong to
include/linux/mm.h, nearvm_insert_page()Ok, I will change it. Apart from this change does it looks good ?
With this change you can add
Quoted 80 lines
Quoted 79 lines
Quoted 72 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-1@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty -- Quoted 2 lines
1.9.1
--
Sincerely yours,
Mike.
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
Reviewed-byQuoted 36 lines · Souptick Joarder
Hi Mike,
Quoted 33 lines · Mike Rapoport
Quoted 31 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end);
Quoted 7 lines
Quoted 5 lines
include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 3 lines
include/linux/mm_types.h +3
-0+int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +This seem to belong to
include/linux/mm.h, nearvm_insert_page()Ok, I will change it. Apart from this change does it looks good ?
With this change you can add
Quoted 80 lines
Quoted 79 lines
Quoted 72 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-1@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty -- Quoted 2 lines
1.9.1
--
Sincerely yours,
Mike.
Signature · 8 lines
Sincerely yours, Mike. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 44 lines · Mike Rapoport
Quoted 42 lines · Souptick Joarder
Hi Mike,
Quoted 38 lines · Mike Rapoport
Quoted 28 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 6 lines
include/linux/mm_types.h +3
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +This seem to belong to
include/linux/mm.h, nearvm_insert_page()
Quoted 5 lines
Quoted 1 line
Ok, I will change it. Apart from this change does it looks good ?
With this change you can add
Reviewed-by Mike Rapoport <[email protected]>
Thanks Mike.
Quoted 86 lines
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-0@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
--
1.9.1--
Sincerely yours,
Mike.--
Sincerely yours,
Mike.
Quoted 44 lines · Mike Rapoport
Quoted 42 lines · Souptick Joarder
Hi Mike,
Quoted 38 lines · Mike Rapoport
Quoted 28 lines · Souptick Joarder
Previouly drivers have their own way of mapping range of kernel pages/memory into user vma and this was done by invoking
vm_insert_page()within a loop.As this pattern is common across different drivers, it can be generalized by creating a new function and use it across the drivers.
vm_insert_rangeis the new API which will be used to map a range of kernel memory/pages to user vma.This API is tested by Heiko for Rockchip drm driver, on rk3188, rk3288, rk3328 and rk3399 with graphics.
Signed-off-by Souptick Joarder <[email protected]>Reviewed-by Matthew Wilcox <[email protected]>Tested-by Heiko Stuebner <[email protected]>--- include/linux/mm_types.h | 3 +++ mm/memory.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/nommu.c | 7 +++++++ 3 files changed, 48 insertions(+)include/linux/mm_types.h +0
-0include/linux/mm_types.h extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, · line 528
Quoted 6 lines
include/linux/mm_types.h +3
-0@@ -523,6 +523,9 @@ extern void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count); +This seem to belong to
include/linux/mm.h, nearvm_insert_page()
Quoted 5 lines
Quoted 1 line
Ok, I will change it. Apart from this change does it looks good ?
With this change you can add
Reviewed-by Mike Rapoport <[email protected]>
Thanks Mike.
Quoted 82 lines
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
include/linux/mm_types.h +0
-0static inline void init_tlb_flush_pending (struct mm_struct *mm) {atomic_set (&mm->tlb_flush_pending,0 );mm/memory.c +38
-0@@ -1478,6 +1478,44 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, }/** +* vm_insert_range - insert range of kernel pages into user vma +* @vma: user vma to map to +* @addr: target user address of this page +* @pages: pointer to array of source kernel pages +* @page_count: number of pages need to insert into user vma +* +* This allows drivers to insert range of kernel pages they've allocated +* into a user vma. This is a generic function which drivers can use +* rather than using their own way of mapping range of kernel pages into +* user vma. +* +* If we fail to insert any page into the vma, the function will return +* immediately leaving any previously-inserted pages present. Callers +* from the mmap handler may immediately return the error as their caller +* will destroy the vma, removing any successfully-inserted pages. Other +* callers should make their own arrangements for calling unmap_region(). +* +* Context: Process context. Called by mmap handlers. +* Return: 0 on success and error code otherwise +*/ +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +unsigned long uaddr = addr; +int ret =0 , i; + +for (i =0 ; i < page_count; i++) { + ret =vm_insert_page (vma, uaddr, pages[i]); +if (ret <0 ) +return ret; + uaddr +=PAGE_SIZE ; + } + +return ret; +} +EXPORT_SYMBOL (vm_insert_range); + +/** * vm_insert_page - insert single page into user vma * @vma: user vma to map to * @addr: target user address of this page mm/nommu.c +7
-0@@ -473,6 +473,13 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, }EXPORT_SYMBOL (vm_insert_page); +int vm_insert_range (struct vm_area_struct *vma,unsigned long addr, +struct page **pages,unsigned long page_count) +{ +return -EINVAL ; +} +EXPORT_SYMBOL (vm_insert_range); +/* * sys_brk() for the most part doesn't need the global kernel * lock, except when an application is doing something nasty Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
--
1.9.1--
Sincerely yours,
Mike.
Quoted 4 lines
--
Sincerely yours,
Mike.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel