Fix race in dGPU event page setup
events_page is unprotected from multiple allocation. The first event creation ioctl is unprotected from a race with args.event_page_offset being set (for page setup) and null (all subsequent invocations). Change-Id: I40ba712a17e9eff257785f90c553a74ad09c661d Signed-off-by: Yair Shachar <Yair.Shachar@amd.com>
Этот коммит содержится в:
коммит произвёл
Gerrit Code Review
родитель
006f3ee41b
Коммит
3a662ac712
+8
-1
@@ -74,10 +74,13 @@ hsaKmtCreateEvent(
|
||||
args.auto_reset = !ManualReset;
|
||||
|
||||
/* dGPU code */
|
||||
pthread_mutex_lock(&hsakmt_mutex);
|
||||
|
||||
if (is_dgpu && events_page == NULL) {
|
||||
events_page = allocate_exec_aligned_memory_gpu(
|
||||
KFD_SIGNAL_EVENT_LIMIT * 8, PAGE_SIZE, 0);
|
||||
if (!events_page) {
|
||||
pthread_mutex_unlock(&hsakmt_mutex);
|
||||
return HSAKMT_STATUS_ERROR;
|
||||
}
|
||||
fmm_get_handle(events_page, &args.event_page_offset);
|
||||
@@ -86,6 +89,7 @@ hsaKmtCreateEvent(
|
||||
if (kmtIoctl(kfd_fd, AMDKFD_IOC_CREATE_EVENT, &args) != 0) {
|
||||
free(e);
|
||||
*Event = NULL;
|
||||
pthread_mutex_unlock(&hsakmt_mutex);
|
||||
return HSAKMT_STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -93,12 +97,15 @@ hsaKmtCreateEvent(
|
||||
events_page = mmap(NULL, KFD_SIGNAL_EVENT_LIMIT * 8, PROT_WRITE | PROT_READ,
|
||||
MAP_SHARED, kfd_fd, args.event_page_offset);
|
||||
if (events_page == MAP_FAILED) {
|
||||
hsaKmtDestroyEvent(e);
|
||||
events_page = NULL;
|
||||
pthread_mutex_unlock(&hsakmt_mutex);
|
||||
hsaKmtDestroyEvent(e);
|
||||
return HSAKMT_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&hsakmt_mutex);
|
||||
|
||||
if (args.event_page_offset > 0 && args.event_slot_index < KFD_SIGNAL_EVENT_LIMIT)
|
||||
e->EventData.HWData2 = (HSAuint64)&events_page[args.event_slot_index];
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user