staticvoid release_session(struct amdtee_session *sess)
{ int i;
/* Close any open session */ for (i = 0; i < TEE_NUM_SESSIONS; ++i) { /* Check if session entry 'i' is valid */ if (!test_bit(i, sess->sess_mask)) continue;
/** * alloc_session() - Allocate a session structure * @ctxdata: TEE Context data structure * @session: Session ID for which 'struct amdtee_session' structure is to be * allocated. * * Scans the TEE context's session list to check if TA is already loaded in to * TEE. If yes, returns the 'session' structure for that TA. Else allocates, * initializes a new 'session' structure and adds it to context's session list. * * The caller must hold a mutex. * * Returns: * 'struct amdtee_session *' on success and NULL on failure.
*/ staticstruct amdtee_session *alloc_session(struct amdtee_context_data *ctxdata,
u32 session)
{ struct amdtee_session *sess;
u32 ta_handle = get_ta_handle(session);
/* Scan session list to check if TA is already loaded in to TEE */
list_for_each_entry(sess, &ctxdata->sess_list, list_node) if (sess->ta_handle == ta_handle) {
kref_get(&sess->refcount); return sess;
}
/* Allocate a new session and add to list */
sess = kzalloc(sizeof(*sess), GFP_KERNEL); if (sess) {
sess->ta_handle = ta_handle;
kref_init(&sess->refcount);
spin_lock_init(&sess->lock);
list_add(&sess->list_node, &ctxdata->sess_list);
}
return sess;
}
/* Requires mutex to be held */ staticstruct amdtee_session *find_session(struct amdtee_context_data *ctxdata,
u32 session)
{
u32 ta_handle = get_ta_handle(session);
u32 index = get_session_index(session); struct amdtee_session *sess;
if (!sess) {
handle_unload_ta(ta_handle);
rc = -ENOMEM; goto out;
}
/* Open session with loaded TA */
handle_open_session(arg, &session_info, param); if (arg->ret != TEEC_SUCCESS) {
pr_err("open_session failed %d\n", arg->ret);
handle_unload_ta(ta_handle);
kref_put_mutex(&sess->refcount, destroy_session,
&session_list_mutex); goto out;
}
/* Find an empty session index for the given TA */
spin_lock(&sess->lock);
i = find_first_zero_bit(sess->sess_mask, TEE_NUM_SESSIONS); if (i < TEE_NUM_SESSIONS) {
sess->session_info[i] = session_info;
set_session_id(ta_handle, i, &arg->session);
set_bit(i, sess->sess_mask);
}
spin_unlock(&sess->lock);
if (i >= TEE_NUM_SESSIONS) {
pr_err("reached maximum session count %d\n", TEE_NUM_SESSIONS);
handle_close_session(ta_handle, session_info);
handle_unload_ta(ta_handle);
kref_put_mutex(&sess->refcount, destroy_session,
&session_list_mutex);
rc = -ENOMEM; goto out;
}
int amdtee_close_session(struct tee_context *ctx, u32 session)
{ struct amdtee_context_data *ctxdata = ctx->data;
u32 i, ta_handle, session_info; struct amdtee_session *sess;
pr_debug("%s: sid = 0x%x\n", __func__, session);
/* * Check that the session is valid and clear the session * usage bit
*/
mutex_lock(&session_list_mutex);
sess = find_session(ctxdata, session); if (sess) {
ta_handle = get_ta_handle(session);
i = get_session_index(session);
session_info = sess->session_info[i];
spin_lock(&sess->lock);
clear_bit(i, sess->sess_mask);
spin_unlock(&sess->lock);
}
mutex_unlock(&session_list_mutex);
if (!sess) return -EINVAL;
/* Close the session */
handle_close_session(ta_handle, session_info);
handle_unload_ta(ta_handle);
/* * Send a MAP command to TEE and get the corresponding * buffer Id
*/
rc = handle_map_shmem(count, &shmem, &buf_id); if (rc) {
pr_err("map_shmem failed: ret = %d\n", rc);
kfree(shmnode); return rc;
}
/* Check that the session is valid */
mutex_lock(&session_list_mutex);
sess = find_session(ctxdata, arg->session); if (sess) {
i = get_session_index(arg->session);
session_info = sess->session_info[i];
}
mutex_unlock(&session_list_mutex);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.25Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.