[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 3/9] vhost-user-gpu: fix vugbm_device_init fallback
From: |
Gerd Hoffmann |
Subject: |
[PULL 3/9] vhost-user-gpu: fix vugbm_device_init fallback |
Date: |
Fri, 26 Mar 2021 13:49:26 +0100 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
vugbm implements GBM device wrapping, udmabuf and memory fallback.
However, the fallback/detection logic is flawed, as if "/dev/udmabuf"
failed to be opened, it will not initialize vugbm and crash later.
Rework the vugbm_device_init() logic to initialize correctly in all
cases.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20210312100108.2706195-4-marcandre.lureau@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
contrib/vhost-user-gpu/vugbm.h | 2 +-
contrib/vhost-user-gpu/vhost-user-gpu.c | 6 +---
contrib/vhost-user-gpu/vugbm.c | 44 +++++++++++--------------
3 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/contrib/vhost-user-gpu/vugbm.h b/contrib/vhost-user-gpu/vugbm.h
index 66f1520764a6..82bc4934e1ba 100644
--- a/contrib/vhost-user-gpu/vugbm.h
+++ b/contrib/vhost-user-gpu/vugbm.h
@@ -54,7 +54,7 @@ struct vugbm_buffer {
uint32_t format;
};
-bool vugbm_device_init(struct vugbm_device *dev, int fd);
+void vugbm_device_init(struct vugbm_device *dev, int fd);
void vugbm_device_destroy(struct vugbm_device *dev);
bool vugbm_buffer_create(struct vugbm_buffer *buffer, struct vugbm_device *dev,
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c
b/contrib/vhost-user-gpu/vhost-user-gpu.c
index b27990ffdbc0..ef40fbccbbd9 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -1186,11 +1186,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (g.drm_rnode_fd >= 0) {
- if (!vugbm_device_init(&g.gdev, g.drm_rnode_fd)) {
- g_warning("Failed to init DRM device, using fallback path");
- }
- }
+ vugbm_device_init(&g.gdev, g.drm_rnode_fd);
if ((!!opt_socket_path + (opt_fdnum != -1)) != 1) {
g_printerr("Please specify either --fd or --socket-path\n");
diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c
index f5304ada2f1b..fb15d0372c25 100644
--- a/contrib/vhost-user-gpu/vugbm.c
+++ b/contrib/vhost-user-gpu/vugbm.c
@@ -199,55 +199,51 @@ vugbm_device_destroy(struct vugbm_device *dev)
dev->device_destroy(dev);
}
-bool
+void
vugbm_device_init(struct vugbm_device *dev, int fd)
{
- dev->fd = fd;
+ assert(!dev->inited);
#ifdef CONFIG_GBM
- dev->dev = gbm_create_device(fd);
-#endif
-
- if (0) {
- /* nothing */
+ if (fd >= 0) {
+ dev->dev = gbm_create_device(fd);
}
-#ifdef CONFIG_GBM
- else if (dev->dev != NULL) {
+ if (dev->dev != NULL) {
+ dev->fd = fd;
dev->alloc_bo = alloc_bo;
dev->free_bo = free_bo;
dev->get_fd = get_fd;
dev->map_bo = map_bo;
dev->unmap_bo = unmap_bo;
dev->device_destroy = device_destroy;
+ dev->inited = true;
}
#endif
#ifdef CONFIG_MEMFD
- else if (g_file_test("/dev/udmabuf", G_FILE_TEST_EXISTS)) {
+ if (!dev->inited && g_file_test("/dev/udmabuf", G_FILE_TEST_EXISTS)) {
dev->fd = open("/dev/udmabuf", O_RDWR);
- if (dev->fd < 0) {
- return false;
+ if (dev->fd >= 0) {
+ g_debug("Using experimental udmabuf backend");
+ dev->alloc_bo = udmabuf_alloc_bo;
+ dev->free_bo = udmabuf_free_bo;
+ dev->get_fd = udmabuf_get_fd;
+ dev->map_bo = udmabuf_map_bo;
+ dev->unmap_bo = udmabuf_unmap_bo;
+ dev->device_destroy = udmabuf_device_destroy;
+ dev->inited = true;
}
- g_debug("Using experimental udmabuf backend");
- dev->alloc_bo = udmabuf_alloc_bo;
- dev->free_bo = udmabuf_free_bo;
- dev->get_fd = udmabuf_get_fd;
- dev->map_bo = udmabuf_map_bo;
- dev->unmap_bo = udmabuf_unmap_bo;
- dev->device_destroy = udmabuf_device_destroy;
}
#endif
- else {
+ if (!dev->inited) {
g_debug("Using mem fallback");
dev->alloc_bo = mem_alloc_bo;
dev->free_bo = mem_free_bo;
dev->map_bo = mem_map_bo;
dev->unmap_bo = mem_unmap_bo;
dev->device_destroy = mem_device_destroy;
- return false;
+ dev->inited = true;
}
-
- dev->inited = true;
- return true;
+ assert(dev->inited);
}
static bool
--
2.30.2
- [PULL 0/9] Fixes 20210326 patches, Gerd Hoffmann, 2021/03/26
- [PULL 1/9] usb: Remove "-usbdevice ccid", Gerd Hoffmann, 2021/03/26
- [PULL 3/9] vhost-user-gpu: fix vugbm_device_init fallback,
Gerd Hoffmann <=
- [PULL 2/9] vhost-user-gpu: glFlush before notifying clients, Gerd Hoffmann, 2021/03/26
- [PULL 6/9] s390x: move S390_ADAPTER_SUPPRESSIBLE, Gerd Hoffmann, 2021/03/26
- [PULL 4/9] vhost-user-gpu: fix cursor move/update, Gerd Hoffmann, 2021/03/26
- [PULL 5/9] hw/usb/hcd-ehci-sysbus: Free USBPacket on instance finalize(), Gerd Hoffmann, 2021/03/26
- [PULL 7/9] s390x: add have_virtio_ccw, Gerd Hoffmann, 2021/03/26
- [PULL 8/9] s390x: modularize virtio-gpu-ccw, Gerd Hoffmann, 2021/03/26
- [PULL 9/9] hw/usb/hcd-ehci: Fix crash when showing help of EHCI devices, Gerd Hoffmann, 2021/03/26
- Re: [PULL 0/9] Fixes 20210326 patches, Peter Maydell, 2021/03/26