From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Thomas Huth" <thuth@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PULL 3/9] vhost-user-gpu: fix vugbm_device_init fallback
Date: Fri, 26 Mar 2021 13:49:26 +0100 [thread overview]
Message-ID: <20210326124932.481942-4-kraxel@redhat.com> (raw)
In-Reply-To: <20210326124932.481942-1-kraxel@redhat.com>
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
next prev parent reply other threads:[~2021-03-26 12:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-26 12:49 [PULL 0/9] Fixes 20210326 patches Gerd Hoffmann
2021-03-26 12:49 ` [PULL 1/9] usb: Remove "-usbdevice ccid" Gerd Hoffmann
2021-03-26 12:49 ` [PULL 2/9] vhost-user-gpu: glFlush before notifying clients Gerd Hoffmann
2021-03-26 12:49 ` Gerd Hoffmann [this message]
2021-03-26 12:49 ` [PULL 4/9] vhost-user-gpu: fix cursor move/update Gerd Hoffmann
2021-03-26 12:49 ` [PULL 5/9] hw/usb/hcd-ehci-sysbus: Free USBPacket on instance finalize() Gerd Hoffmann
2021-03-26 12:49 ` [PULL 6/9] s390x: move S390_ADAPTER_SUPPRESSIBLE Gerd Hoffmann
2021-03-26 12:49 ` [PULL 7/9] s390x: add have_virtio_ccw Gerd Hoffmann
2021-03-26 12:49 ` [PULL 8/9] s390x: modularize virtio-gpu-ccw Gerd Hoffmann
2021-03-26 12:49 ` [PULL 9/9] hw/usb/hcd-ehci: Fix crash when showing help of EHCI devices Gerd Hoffmann
2021-03-26 17:50 ` [PULL 0/9] Fixes 20210326 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210326124932.481942-4-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).