tee: make tee_shm_register_kernel_buf vmalloc supported
Subsystems (3)
PATCH v4 1/1 tee: make tee_shm_register_kernel_buf vmalloc supported
In some low-memory devices, it's hard to aquire large-orders pages, this patch allowed user using scatter pages to register shm.
--- drivers/tee/optee/call.c | 2 +- drivers/tee/tee_shm.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-)
drivers/tee/optee/call.c +1 -1
@@ -362,7 +362,7 @@ int optee_check_mem_type(unsigned long start, size_t num_pages)* Allow kernel address to register with OP-TEE as kernel * pages are configured as normal memory only. */ -if (virt_addr_valid (start)) +if (virt_addr_valid (start) ||is_vmalloc_addr ((void *)start))return 0 ;mmap_read_lock (mm);
drivers/tee/tee_shm.c +25 -10
@@ -23,21 +23,36 @@ static void shm_put_kernel_pages(struct page **pages, size_t page_count)static int shm_get_kernel_pages (unsigned long start,size_t page_count,struct page **pages) { -struct kvec *kiov;size_t n;int rc; - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (is_vmalloc_addr ((void *)start)) { +struct page *page; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } +for (n =0 ; n < page_count; n++) { + page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); +if (!page) +return -ENOMEM ; + +get_page (page); + pages[n] = page; + } + rc = page_count; + }else { +struct kvec *kiov; + + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; + } + + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); + }return rc; }
Signature · 1 line
2.25.1
Quoted 10 lines · Phil Chang
In some low-memory devices, it's hard to aquire large-orders pages, this patch allowed user using scatter pages to register shm.
Signed-off-by Phil Chang <[email protected]>Reviewed-by Sumit Garg <[email protected]>--- drivers/tee/optee/call.c | 2 +- drivers/tee/tee_shm.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-)
Looks good to me. Unfortunately this is too late for the coming merge window, so it's going to be the one after that. Meanwhile it will be in linux-next.
Thanks,
Jens
Quoted 68 lines
drivers/tee/optee/call.c +1
-1@@ -362,7 +362,7 @@ int optee_check_mem_type(unsigned long start, size_t num_pages)* Allow kernel address to register with OP-TEE as kernel * pages are configured as normal memory only. */ -if (virt_addr_valid (start)) +if (virt_addr_valid (start) ||is_vmalloc_addr ((void *)start))return 0 ;mmap_read_lock (mm);drivers/tee/tee_shm.c +25
-11@@ -23,21 +23,36 @@ static void shm_put_kernel_pages(struct page **pages, size_t page_count)static int shm_get_kernel_pages (unsigned long start,size_t page_count,struct page **pages) { -struct kvec *kiov;size_t n;int rc; - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; +if (is_vmalloc_addr ((void *)start)) { +struct page *page; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } +for (n =0 ; n < page_count; n++) { + page =vmalloc_to_page ((void *)(start +PAGE_SIZE * n)); +if (!page) +return -ENOMEM ; + +get_page (page); + pages[n] = page; + } + rc = page_count; + }else { +struct kvec *kiov; + + kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); +if (!kiov) +return -ENOMEM ; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); +for (n =0 ; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); + kiov[n].iov_len =PAGE_SIZE ; + } + + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); + }return rc; } --2.25.1
Quoted 13 lines
Quoted 10 lines · Phil Chang
In some low-memory devices, it's hard to aquire large-orders pages, this patch allowed user using scatter pages to register shm.
Signed-off-by Phil Chang <[email protected]>Reviewed-by Sumit Garg <[email protected]>--- drivers/tee/optee/call.c | 2 +- drivers/tee/tee_shm.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-)
Quoted 6 lines
Looks good to me. Unfortunately this is too late for the coming merge window, so it's going to be the one after that. Meanwhile it will be in linux-next.
Thanks,
Jens
Hi Jens
thanks for your review, did I push again wile merge window open ? Or just wait ?
Thanks
Quoted 72 lines
Quoted 72 lines
drivers/tee/optee/call.c +1
-1@@ -362,7 +362,7 @@ int optee_check_mem_type(unsigned long start,size_t num_pages) * Allow kernel address to register with OP-TEE as kernel * pages are configured as normal memory only. */ -if (virt_addr_valid (start)) +if (virt_addr_valid (start) ||is_vmalloc_addr ((void *)start))return 0 ;mmap_read_lock(mm);drivers/tee/tee_shm.c +19
-10@@ -23,21 +23,36 @@ static void shm_put_kernel_pages(struct page **pages, size_t page_count) static int shm_get_kernel_pages(unsigned long start, size_t page_count, struct page **pages) { -struct kvec *kiov; size_t n; int rc; - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; + if (is_vmalloc_addr((void *)start)) { + struct page *page; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + for (n = 0; n < page_count; n++) { + page = vmalloc_to_page((void *)(start + PAGE_SIZE * n)); + if (!page) + return -ENOMEM; + + get_page(page); + pages[n] = page; + } + rc = page_count; + } else { + struct kvec *kiov; + + kiov = kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); + if (!kiov) + return -ENOMEM; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); + for (n = 0; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *
PAGE_SIZE);drivers/tee/tee_shm.c +6
-1+ kiov[n].iov_len =PAGE_SIZE ; + } + + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); + }return rc; } --2.25.1
Hi Phil,
Quoted 18 lines · Phil Chang
Quoted 18 lines
Quoted 10 lines · Phil Chang
In some low-memory devices, it's hard to aquire large-orders pages, this patch allowed user using scatter pages to register shm.
Signed-off-by Phil Chang <[email protected]>Reviewed-by Sumit Garg <[email protected]>--- drivers/tee/optee/call.c | 2 +- drivers/tee/tee_shm.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-)Looks good to me. Unfortunately this is too late for the coming merge window, so it's going to be the one after that. Meanwhile it will be in linux-next.
Quoted 6 lines
Quoted 2 lines
Thanks,
JensHi Jens
thanks for your review, did I push again wile merge window open ? Or just wait ?
Just wait. You should be able to see it in linux-next for now.
Cheers,
Jens
Quoted 75 lines
Thanks
Quoted 72 lines
Quoted 72 lines
drivers/tee/optee/call.c +1
-1@@ -362,7 +362,7 @@ int optee_check_mem_type(unsigned long start,size_t num_pages) * Allow kernel address to register with OP-TEE as kernel * pages are configured as normal memory only. */ -if (virt_addr_valid (start)) +if (virt_addr_valid (start) ||is_vmalloc_addr ((void *)start))return 0 ;mmap_read_lock(mm);drivers/tee/tee_shm.c +19
-10@@ -23,21 +23,36 @@ static void shm_put_kernel_pages(struct page **pages, size_t page_count) static int shm_get_kernel_pages(unsigned long start, size_t page_count, struct page **pages) { -struct kvec *kiov; size_t n; int rc; - kiov =kcalloc (page_count,sizeof (*kiov),GFP_KERNEL ); -if (!kiov) -return -ENOMEM ; + if (is_vmalloc_addr((void *)start)) { + struct page *page; -for (n =0 ; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n *PAGE_SIZE ); - kiov[n].iov_len =PAGE_SIZE ; - } + for (n = 0; n < page_count; n++) { + page = vmalloc_to_page((void *)(start + PAGE_SIZE * n)); + if (!page) + return -ENOMEM; + + get_page(page); + pages[n] = page; + } + rc = page_count; + } else { + struct kvec *kiov; + + kiov = kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); + if (!kiov) + return -ENOMEM; - rc =get_kernel_pages (kiov, page_count,0 , pages); -kfree (kiov); + for (n = 0; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n *
PAGE_SIZE);drivers/tee/tee_shm.c +6
-1+ kiov[n].iov_len =PAGE_SIZE ; + } + + rc =get_kernel_pages (kiov, page_count,0 , pages); +kfree (kiov); + }return rc; } --2.25.1