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.
Unified · Split
| @@ -334,8 +334,7 @@ tee_ioctl_shm_register(struct tee_context *ctx, · 333 unmodified lines | ||
| 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 | |
| @@ -58,5 +58,7 @@ void teedev_ctx_get(struct tee_context *ctx); · 57 unmodified lines | ||
| 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*/ |
| @@ -299,6 +299,39 @@ err: · 298 unmodified lines | ||
| 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); |
| @@ -287,6 +287,8 @@ struct tee_shm *tee_shm_alloc_kernel_buf(struct tee_context *ctx, size_t size); · 286 unmodified lines | ||
| 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 |