libhsakmt: Improve error handling in child process

Check for errno == EBADF in kmtIoctl to detect misuse of the kfd_fd
in a forked child process.

Detect being in a forked child process pro-actively by implementing
a pthread_atfork callback.

Make sure all mutexes get reinitialized in the child process to avoid
deadlocks.

Check for being in a forked child process in CHECK_KFD_OPENED so that
all hsaKmt functions will return the appropriate status
HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED.

Update InvalidKFDHandleTest to expect that error code.

Change-Id: I0238e5fba344dcaa454e97a35db2e2dcc8d1f607
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
This commit is contained in:
Felix Kuehling
2019-12-04 23:06:00 -05:00
parent fe97612800
commit 87e10cd0b4
5 ha cambiato i file con 60 aggiunte e 4 eliminazioni
+9
Vedi File
@@ -1,3 +1,4 @@
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
@@ -12,5 +13,13 @@ int kmtIoctl(int fd, unsigned long request, void *arg)
ret = ioctl(fd, request, arg);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
if (errno == EBADF) {
/* In case pthread_atfork didn't catch it, this will
* make any subsequent hsaKmt calls fail in CHECK_KFD_OPEN.
*/
pr_err("KFD file descriptor not valid in this process\n");
hsakmt_forked = true;
}
return ret;
}