Commit cfbd09d6 authored by Chris Wilson's avatar Chris Wilson

igt/vgem: Add a basic test for handling of module unload

We found a bug where a dmabuf did not keep the module alive (and so when
i915 tried to use it later, it exploded).
Signed-off-by: Chris Wilson's avatarChris Wilson <chris@chris-wilson.co.uk>
parent 1dd7ce87
......@@ -188,6 +188,7 @@ static void test_dmabuf_fence(int fd)
igt_assert(!prime_busy(dmabuf, false));
igt_assert(!prime_busy(dmabuf, true));
close(dmabuf);
gem_close(fd, bo.handle);
}
......@@ -212,7 +213,9 @@ static void test_dmabuf_fence_before(int fd)
igt_assert(!prime_busy(dmabuf, false));
igt_assert(!prime_busy(dmabuf, true));
close(dmabuf);
gem_close(fd, bo.handle);
vgem_create(fd, &bo);
fence = vgem_fence_attach(fd, &bo, VGEM_FENCE_WRITE);
......@@ -224,6 +227,7 @@ static void test_dmabuf_fence_before(int fd)
igt_assert(!prime_busy(dmabuf, false));
igt_assert(!prime_busy(dmabuf, true));
close(dmabuf);
gem_close(fd, bo.handle);
}
......@@ -284,6 +288,79 @@ static void test_debugfs_read(int fd)
close(dir);
}
static int module_unload(void)
{
return system("/sbin/modprobe -s -r vgem");
}
static void test_unload(void)
{
struct vgem_bo bo;
int vgem, dmabuf;
uint32_t *ptr;
igt_require(module_unload() == 0);
vgem = __drm_open_driver(DRIVER_VGEM);
igt_assert(vgem != -1);
/* The driver should stop the module from unloading */
igt_assert_f(module_unload() != 0,
"open(//dev/vgem) should keep the module alive\n");
bo.width = 1024;
bo.height = 1;
bo.bpp = 32;
vgem_create(vgem, &bo);
close(vgem);
/* Closing the driver should clear all normal references */
igt_assert_f(module_unload() == 0,
"No open(/dev/vgem), should be able to unload\n");
vgem = __drm_open_driver(DRIVER_VGEM);
igt_assert(vgem != -1);
bo.width = 1024;
bo.height = 1;
bo.bpp = 32;
vgem_create(vgem, &bo);
dmabuf = prime_handle_to_fd(vgem, bo.handle);
close(vgem);
/* A dmabuf should prevent module unload. */
igt_assert_f(module_unload() != 0,
"A dmabuf should keep the module alive\n");
close(dmabuf);
igt_assert_f(module_unload() == 0,
"No open dmabuf, should be able to unload\n");
vgem = __drm_open_driver(DRIVER_VGEM);
igt_assert(vgem != -1);
bo.width = 1024;
bo.height = 1;
bo.bpp = 32;
vgem_create(vgem, &bo);
dmabuf = prime_handle_to_fd_for_mmap(vgem, bo.handle);
close(vgem);
ptr = mmap(NULL, bo.size, PROT_WRITE, MAP_SHARED, dmabuf, 0);
igt_assert(ptr != MAP_FAILED);
close(dmabuf);
/* Although closed, the mmap should keep the dmabuf/module alive */
igt_assert_f(module_unload() != 0,
"A mmap should keep the module alive\n");
for (int page = 0; page < bo.size >> 12; page++)
ptr[1024*page + page%1024] = page;
/* And finally we should have no more uses on the module. */
munmap(ptr, bo.size);
igt_assert_f(module_unload() == 0,
"No open mmap, should be able to unload\n");
}
static bool has_prime_export(int fd)
{
uint64_t value;
......@@ -298,6 +375,9 @@ igt_main
{
int fd = -1;
igt_subtest("unload")
test_unload();
igt_fixture {
fd = drm_open_driver(DRIVER_VGEM);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment