AMD-TEE update for 7.2

Store buffer ID in tee_shm->sec_world_id and remove internal tracking
 structures to align with other TEE drivers
 -----BEGIN PGP SIGNATURE-----
 
 iQJOBAABCgA4FiEE0qerISgy2SKkqO79Wr/6JGat8H4FAmoZY4waHGplbnMud2lr
 bGFuZGVyQGxpbmFyby5vcmcACgkQWr/6JGat8H42Cg//fPRFZ8igbCvGZMmfkUrc
 jLJfplUW3sLPONEC5/j3mzgrtK5bCkGqh2PYCfbtVYfW67fuGzA2BJXDSrPtIaiH
 tkwXL1vzTGZHHGfUpV8fHEsQM75jSyeXumptY/aIr9FkaLsaOIxz+YRbyzMAuOYn
 aP3wPy3ORCgbhd51mJ+aQvbu0xC7C/JJuWGfv+UmdVFaGLUYIzLp8pzJ3LESnHQq
 R8lqDUfLxu2NXmGRSZkxNQYRx9yxosmxraVSEpQYjlihz0urwQrXI55NFiHT2VRx
 mks6k/ykCKHDCszYnbWIrDtuhQ7AN09iNePfkXK/6SWoAyI5vGqaotRlqyFKSIde
 2AD/eQJm9jtBaGASjI2lOzlCRlbzNh9KFihPlVHCA669ho30hPAvX8ZxpgEKdj1x
 JLwgrqikow9VW6wGtF5uyUyWgsRuK/adQb1s5FrL+130rAW0t0MkvDBbx3EJKBvx
 yLqnmdHKIs45U8nrGA5ke9FyLuGk4Wf99r2cXoG4ZQGzIQ76irR4CFpK2LIKQMHl
 WQwBCLdh/2KmB1F8dKfHFQwaFVNvhE+fuGpaetnVOBMoA0QjmTHYI0m9Ll9ZUBnU
 6iKsMw1QukPaToEy6XAuAW59F1txiUB/n6Wenhgsr0UhhWRFaD4uqEx7EzwnbQnB
 YKFqRKZX4KMQgtihgrRKU3s=
 =D25u
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEo6/YBQwIrVS28WGKmmx57+YAGNkFAmoaEfQACgkQmmx57+YA
 GNlNuw/8DcwlczkJeD4yaOHGoHiR/91QhxZEnsbJ47xyf6Mz4NTPRqhUob2Hm2NE
 1F2gBEe8hX+ywYkaQBozopRVXSeiAtz9yhfNUxaFK9/B4QK5QDQPj2rTqreUtshy
 qMyb0Y+dCzuKxM1Zt1vVKr2NnCbZ6vGfrzsrLOS2HLWfIGAPoN7vur1ffgTipsBW
 XxbVGj9mLVBiBBGOAiZFJMuLsqKasQS+RbuRmA3E1sZ+GT9ilLkj14dUvoK3pLU6
 4OQZH3JfkHJDoziHz/qJdgRhr7gVWdiWhhLv8WnG40xjcnFAbeLoNeHUgG9JjaBM
 7yOnRsQyChRVYDHNMko//7Thi2p5pL2lqSTBcllP4quP7jeM209fi2zOKzqbty0Q
 N4PcMpJUctGailBYYnOBT3Cma+jKY7wQ08z3illC1yVaWtHkn4VwQmnKuS0da7+X
 NkQU5tvQ8lb1OUSqEE3klvSGM/sUk/g95vjGbnx3ftkwDeN1YJjmzd1ft+WdzWrj
 FD0ia88OHyKkXGA+/5NW92mOW36Kd2OMtKy84MMbuUGYXVY4ExMz3jTw9XztJ07s
 rwdY2LNVPan2bqZXkhJjBW++LMpAC/JQfsSnOtv2KPAE2X7wHi4UM61WWgv0IOxc
 yu6v7asMca4Ie15IV0u7684xiaRNH9OzP2hYY43vrS4QpmhTwoE=
 =pc2V
 -----END PGP SIGNATURE-----

Merge tag 'amdtee-for-v7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee into soc/drivers

AMD-TEE update for 7.2

Store buffer ID in tee_shm->sec_world_id and remove internal tracking
structures to align with other TEE drivers

* tag 'amdtee-for-v7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee:
  tee: amdtee: store buffer ID in tee_shm->sec_world_id

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2026-05-30 00:23:15 +02:00
commit 1e09b55daf
3 changed files with 5 additions and 65 deletions

View File

@ -65,13 +65,9 @@ struct amdtee_session {
/**
* struct amdtee_context_data - AMD-TEE driver context data
* @sess_list: Keeps track of sessions opened in current TEE context
* @shm_list: Keeps track of buffers allocated and mapped in current TEE
* context
*/
struct amdtee_context_data {
struct list_head sess_list;
struct list_head shm_list;
struct mutex shm_mutex; /* synchronizes access to @shm_list */
};
struct amdtee_driver_data {
@ -83,17 +79,6 @@ struct shmem_desc {
u64 size;
};
/**
* struct amdtee_shm_data - Shared memory data
* @kaddr: Kernel virtual address of shared memory
* @buf_id: Buffer id of memory mapped by TEE_CMD_ID_MAP_SHARED_MEM
*/
struct amdtee_shm_data {
struct list_head shm_node;
void *kaddr;
u32 buf_id;
};
/**
* struct amdtee_ta_data - Keeps track of all TAs loaded in AMD Secure
* Processor
@ -168,5 +153,4 @@ int handle_invoke_cmd(struct tee_ioctl_invoke_arg *arg, u32 sinfo,
struct tee_shm_pool *amdtee_config_shm(void);
u32 get_buffer_id(struct tee_shm *shm);
#endif /*AMDTEE_PRIVATE_H*/

View File

@ -45,7 +45,7 @@ static int tee_params_to_amd_params(struct tee_param *tee, u32 count,
/* It is assumed that all values are within 2^32-1 */
if (type > TEE_OP_PARAM_TYPE_VALUE_INOUT) {
u32 buf_id = get_buffer_id(tee[i].u.memref.shm);
u32 buf_id = (u32)tee[i].u.memref.shm->sec_world_id;
amd->params[i].mref.buf_id = buf_id;
amd->params[i].mref.offset = tee[i].u.memref.shm_offs;

View File

@ -43,8 +43,6 @@ static int amdtee_open(struct tee_context *ctx)
return -ENOMEM;
INIT_LIST_HEAD(&ctxdata->sess_list);
INIT_LIST_HEAD(&ctxdata->shm_list);
mutex_init(&ctxdata->shm_mutex);
ctx->data = ctxdata;
return 0;
@ -87,7 +85,6 @@ static void amdtee_release(struct tee_context *ctx)
list_del(&sess->list_node);
release_session(sess);
}
mutex_destroy(&ctxdata->shm_mutex);
kfree(ctxdata);
ctx->data = NULL;
@ -152,23 +149,6 @@ static struct amdtee_session *find_session(struct amdtee_context_data *ctxdata,
return NULL;
}
u32 get_buffer_id(struct tee_shm *shm)
{
struct amdtee_context_data *ctxdata = shm->ctx->data;
struct amdtee_shm_data *shmdata;
u32 buf_id = 0;
mutex_lock(&ctxdata->shm_mutex);
list_for_each_entry(shmdata, &ctxdata->shm_list, shm_node)
if (shmdata->kaddr == shm->kaddr) {
buf_id = shmdata->buf_id;
break;
}
mutex_unlock(&ctxdata->shm_mutex);
return buf_id;
}
static DEFINE_MUTEX(drv_mutex);
static int copy_ta_binary(struct tee_context *ctx, void *ptr, void **ta,
size_t *ta_size)
@ -342,8 +322,6 @@ int amdtee_close_session(struct tee_context *ctx, u32 session)
int amdtee_map_shmem(struct tee_shm *shm)
{
struct amdtee_context_data *ctxdata;
struct amdtee_shm_data *shmnode;
struct shmem_desc shmem;
int rc, count;
u32 buf_id;
@ -351,10 +329,6 @@ int amdtee_map_shmem(struct tee_shm *shm)
if (!shm)
return -EINVAL;
shmnode = kmalloc_obj(*shmnode);
if (!shmnode)
return -ENOMEM;
count = 1;
shmem.kaddr = shm->kaddr;
shmem.size = shm->size;
@ -366,44 +340,26 @@ int amdtee_map_shmem(struct tee_shm *shm)
rc = handle_map_shmem(count, &shmem, &buf_id);
if (rc) {
pr_err("map_shmem failed: ret = %d\n", rc);
kfree(shmnode);
return rc;
}
shmnode->kaddr = shm->kaddr;
shmnode->buf_id = buf_id;
ctxdata = shm->ctx->data;
mutex_lock(&ctxdata->shm_mutex);
list_add(&shmnode->shm_node, &ctxdata->shm_list);
mutex_unlock(&ctxdata->shm_mutex);
shm->sec_world_id = buf_id;
pr_debug("buf_id :[%x] kaddr[%p]\n", shmnode->buf_id, shmnode->kaddr);
pr_debug("buf_id :[%x] kaddr[%p]\n", buf_id, shm->kaddr);
return 0;
}
void amdtee_unmap_shmem(struct tee_shm *shm)
{
struct amdtee_context_data *ctxdata;
struct amdtee_shm_data *shmnode;
u32 buf_id;
if (!shm)
return;
buf_id = get_buffer_id(shm);
/* Unmap the shared memory from TEE */
buf_id = (u32)shm->sec_world_id;
handle_unmap_shmem(buf_id);
ctxdata = shm->ctx->data;
mutex_lock(&ctxdata->shm_mutex);
list_for_each_entry(shmnode, &ctxdata->shm_list, shm_node)
if (buf_id == shmnode->buf_id) {
list_del(&shmnode->shm_node);
kfree(shmnode);
break;
}
mutex_unlock(&ctxdata->shm_mutex);
shm->sec_world_id = 0;
}
int amdtee_invoke_func(struct tee_context *ctx,