Skip to content

Commit

Permalink
core: arm: fix lock in virt_add_cookie_to_current_guest()
Browse files Browse the repository at this point in the history
Prior to this patch was virt_add_cookie_to_current_guest() only masking
interrupts while adding a shared memory cookie to the list of cookies.
Proper locking is needed to serialize access to the cookie list, replace
the interrupt masking with a cpu_spin_lock_xsave().

Fixes: a65dd3a ("core: spmc: support virtualization with SPMC at S-EL1")
Signed-off-by: Jens Wiklander <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
  • Loading branch information
jenswi-linaro authored and jforissier committed Feb 13, 2024
1 parent 8985300 commit a7400fc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core/arch/arm/kernel/virtualization.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ TEE_Result virt_add_cookie_to_current_guest(uint64_t cookie)
{
TEE_Result res = TEE_ERROR_ACCESS_DENIED;
struct guest_partition *prtn = NULL;
uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR);
uint32_t exceptions = 0;

exceptions = cpu_spin_lock_xsave(&prtn_list_lock);
if (find_prtn_cookie(cookie, NULL))
goto out;

Expand All @@ -479,37 +480,39 @@ TEE_Result virt_add_cookie_to_current_guest(uint64_t cookie)
res = TEE_SUCCESS;
}
out:
thread_unmask_exceptions(exceptions);
cpu_spin_unlock_xrestore(&prtn_list_lock, exceptions);

return res;
}

void virt_remove_cookie(uint64_t cookie)
{
uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR);
struct guest_partition *prtn = NULL;
uint32_t exceptions = 0;
int i = 0;

exceptions = cpu_spin_lock_xsave(&prtn_list_lock);
prtn = find_prtn_cookie(cookie, &i);
if (prtn) {
memmove(prtn->cookies + i, prtn->cookies + i + 1,
sizeof(uint64_t) * (prtn->cookie_count - i - 1));
prtn->cookie_count--;
}
thread_unmask_exceptions(exceptions);
cpu_spin_unlock_xrestore(&prtn_list_lock, exceptions);
}

uint16_t virt_find_guest_by_cookie(uint64_t cookie)
{
uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR);
struct guest_partition *prtn = NULL;
uint32_t exceptions = 0;
uint16_t ret = 0;

exceptions = cpu_spin_lock_xsave(&prtn_list_lock);
prtn = find_prtn_cookie(cookie, NULL);
if (prtn)
ret = prtn->id;

thread_unmask_exceptions(exceptions);
cpu_spin_unlock_xrestore(&prtn_list_lock, exceptions);

return ret;
}
Expand Down

0 comments on commit a7400fc

Please sign in to comment.