Skip to contentSkip to conversation

optee: make tee_shm_register vmalloc supported

PATCH In review Phil Chang 2 participants 2 messages Feb 4, 2022

Subsystems (3)
lore
Share & tools
lore

Phil Chang

author
#0 lore raw

PATCH 1/1 optee: make tee_shm_register vmalloc supported

This patch allowed the tee shm use vmalloc area buffer.

---

Hi,

In some low-memory devices, it's hard to aquire large-orders pages, this pathes is allowed user use scatter pages to register shm.

Thanks.

 drivers/tee/optee/call.c |  2 +-
 drivers/tee/tee_shm.c    | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/tee/optee/call.c +1 -1
index b25cc1fac945..937bcc7df8e4 100644
@@ -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 +14 -0
index 499fccba3d74..31d0c10485ff 100644
@@ -195,6 +195,20 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
 	if (flags & TEE_SHM_USER_MAPPED) {
 		rc = pin_user_pages_fast(start, num_pages, FOLL_WRITE,
 					 shm->pages);
+	} else if (is_vmalloc_addr((void *)start)) {
+		struct page *page;
+		int i;
+
+		for (i = 0; i < num_pages; i++) {
+			page = vmalloc_to_page((void *)(start + PAGE_SIZE * i));
+			if (!page) {
+				ret = ERR_PTR(-ENOMEM);
+				goto err;
+			}
+			get_page(page);
+			shm->pages[i] = page;
+		}
+		rc = num_pages;
 	} else {
 		struct kvec *kiov;
 		int i;

--
2.25.1

#1 lore raw

Hi,

Quoted 10 lines · Phil Chang

This patch allowed the tee shm use vmalloc area buffer.

---

Hi,

In some low-memory devices, it's hard to aquire large-orders pages, this pathes is allowed user use scatter pages to register shm.

This kind of info should go into the commit description describing why this change is needed.

Quoted 7 lines

Thanks.

 drivers/tee/optee/call.c |  2 +-
 drivers/tee/tee_shm.c    | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

Also, I would like this patch to be rebased on top of SHM updates series [1] from Jens as there has been a lot of refactoring touching these files.

[1] https://lists.trustedfirmware.org/archives/list/op-tee(a)lists.trustedfirmware.org/thread/3J2IJX5LG2X4CZBYDLVA4PDVM4APMZSD/

-Sumit

Quoted 40 lines
drivers/tee/optee/call.c +1 -1
index b25cc1fac945..937bcc7df8e4 100644
@@ -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 +14 -1
index 499fccba3d74..31d0c10485ff 100644
@@ -195,6 +195,20 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
        if (flags & TEE_SHM_USER_MAPPED) {
                rc = pin_user_pages_fast(start, num_pages, FOLL_WRITE,
                                         shm->pages);
+       } else if (is_vmalloc_addr((void *)start)) {
+               struct page *page;
+               int i;
+
+               for (i = 0; i < num_pages; i++) {
+                       page = vmalloc_to_page((void *)(start + PAGE_SIZE * i));
+                       if (!page) {
+                               ret = ERR_PTR(-ENOMEM);
+                               goto err;
+                       }
+                       get_page(page);
+                       shm->pages[i] = page;
+               }
+               rc = num_pages;
        } else {
                struct kvec *kiov;
                int i;
--

2.25.1