Commit 3e47235e authored by Phil Chang's avatar Phil Chang Committed by Jens Wiklander
Browse files

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.

Signed-off-by: default avatarPhil Chang <phil.chang@mediatek.com>
Reviewed-by: default avatarSumit Garg <sumit.garg@linaro.org>
Signed-off-by: default avatarJens Wiklander <jens.wiklander@linaro.org>
parent 31231092
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+25 −10
Original line number Diff line number Diff line
@@ -23,10 +23,24 @@ 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;

	if (is_vmalloc_addr((void *)start)) {
		struct page *page;

		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;
@@ -38,6 +52,7 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count,

		rc = get_kernel_pages(kiov, page_count, 0, pages);
		kfree(kiov);
	}

	return rc;
}