mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	tee: optee: Fix dynamic shm pool allocations
In case of dynamic shared memory pool, kernel memory allocated using
dmabuf_mgr pool needs to be registered with OP-TEE prior to its usage
during optee_open_session() or optee_invoke_func().
So fix dmabuf_mgr pool allocations via an additional call to
optee_shm_register().
Also, allow kernel pages to be registered as shared memory with OP-TEE.
Fixes: 9733b072a1 ("optee: allow to work without static shared memory")
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
			
			
This commit is contained in:
		
							parent
							
								
									4f5cafb5cb
								
							
						
					
					
						commit
						a249dd200d
					
				
					 2 changed files with 18 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -554,6 +554,13 @@ static int check_mem_type(unsigned long start, size_t num_pages)
 | 
			
		|||
	struct mm_struct *mm = current->mm;
 | 
			
		||||
	int rc;
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * Allow kernel address to register with OP-TEE as kernel
 | 
			
		||||
	 * pages are configured as normal memory only.
 | 
			
		||||
	 */
 | 
			
		||||
	if (virt_addr_valid(start))
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	down_read(&mm->mmap_sem);
 | 
			
		||||
	rc = __check_mem_type(find_vma(mm, start),
 | 
			
		||||
			      start + num_pages * PAGE_SIZE);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
 | 
			
		|||
{
 | 
			
		||||
	unsigned int order = get_order(size);
 | 
			
		||||
	struct page *page;
 | 
			
		||||
	int rc = 0;
 | 
			
		||||
 | 
			
		||||
	page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
 | 
			
		||||
	if (!page)
 | 
			
		||||
| 
						 | 
				
			
			@ -26,12 +27,21 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
 | 
			
		|||
	shm->paddr = page_to_phys(page);
 | 
			
		||||
	shm->size = PAGE_SIZE << order;
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
	if (shm->flags & TEE_SHM_DMA_BUF) {
 | 
			
		||||
		shm->flags |= TEE_SHM_REGISTER;
 | 
			
		||||
		rc = optee_shm_register(shm->ctx, shm, &page, 1 << order,
 | 
			
		||||
					(unsigned long)shm->kaddr);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return rc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void pool_op_free(struct tee_shm_pool_mgr *poolm,
 | 
			
		||||
			 struct tee_shm *shm)
 | 
			
		||||
{
 | 
			
		||||
	if (shm->flags & TEE_SHM_DMA_BUF)
 | 
			
		||||
		optee_shm_unregister(shm->ctx, shm);
 | 
			
		||||
 | 
			
		||||
	free_pages((unsigned long)shm->kaddr, get_order(shm->size));
 | 
			
		||||
	shm->kaddr = NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue