Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tee: add tee_shm_register_{user,kernel}_buf()

Adds the two new functions tee_shm_register_user_buf() and
tee_shm_register_kernel_buf() which should be used instead of the old
tee_shm_register().

This avoids having the caller supplying the flags parameter which
exposes a bit more than desired of the internals of the TEE subsystem.

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

+38 -2
+1 -2
drivers/tee/tee_core.c
··· 334 334 if (data.flags) 335 335 return -EINVAL; 336 336 337 - shm = tee_shm_register(ctx, data.addr, data.length, 338 - TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED); 337 + shm = tee_shm_register_user_buf(ctx, data.addr, data.length); 339 338 if (IS_ERR(shm)) 340 339 return PTR_ERR(shm); 341 340
+2
drivers/tee/tee_private.h
··· 58 58 void teedev_ctx_put(struct tee_context *ctx); 59 59 60 60 struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size); 61 + struct tee_shm *tee_shm_register_user_buf(struct tee_context *ctx, 62 + unsigned long addr, size_t length); 61 63 62 64 #endif /*TEE_PRIVATE_H*/
+33
drivers/tee/tee_shm.c
··· 299 299 } 300 300 EXPORT_SYMBOL_GPL(tee_shm_register); 301 301 302 + /** 303 + * tee_shm_register_user_buf() - Register a userspace shared memory buffer 304 + * @ctx: Context that registers the shared memory 305 + * @addr: The userspace address of the shared buffer 306 + * @length: Length of the shared buffer 307 + * 308 + * @returns a pointer to 'struct tee_shm' 309 + */ 310 + struct tee_shm *tee_shm_register_user_buf(struct tee_context *ctx, 311 + unsigned long addr, size_t length) 312 + { 313 + return tee_shm_register(ctx, addr, length, 314 + TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED); 315 + } 316 + 317 + /** 318 + * tee_shm_register_kernel_buf() - Register kernel memory to be shared with 319 + * secure world 320 + * @ctx: Context that registers the shared memory 321 + * @addr: The buffer 322 + * @length: Length of the buffer 323 + * 324 + * @returns a pointer to 'struct tee_shm' 325 + */ 326 + 327 + struct tee_shm *tee_shm_register_kernel_buf(struct tee_context *ctx, 328 + void *addr, size_t length) 329 + { 330 + return tee_shm_register(ctx, (unsigned long)addr, length, 331 + TEE_SHM_DMA_BUF | TEE_SHM_KERNEL_MAPPED); 332 + } 333 + EXPORT_SYMBOL_GPL(tee_shm_register_kernel_buf); 334 + 302 335 static int tee_shm_fop_release(struct inode *inode, struct file *filp) 303 336 { 304 337 tee_shm_put(filp->private_data);
+2
include/linux/tee_drv.h
··· 287 287 */ 288 288 struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, 289 289 size_t length, u32 flags); 290 + struct tee_shm *tee_shm_register_kernel_buf(struct tee_context *ctx, 291 + void *addr, size_t length); 290 292 291 293 /** 292 294 * tee_shm_is_registered() - Check if shared memory object in registered in TEE