Add vfio dma-buf based display reset handling
v3 cover Add vfio dma-buf based display reset handling
vfio display needs to release the invalid display resource and disable the scanout mode during guest OS reboot, otherwise bugs come out.
Thanks [email protected] for helping root cause the issue.
v2->v3:
- Limit vfio_display_reset to dma-buf based vfio display. (Gerd)
v1->v2:
- remove dpy_gfx_switch_surface. (Gerd)
- add dpy_gfx_update_full. (Gerd)
Tina Zhang (2):
console: introduce dpy_gfx_update_full
ui: introduce vfio_display_reset
hw/vfio/display.c | 10 ++++++++++ hw/vfio/pci.c | 7 +++++++ hw/vfio/pci.h | 1 + include/ui/console.h | 1 + ui/console.c | 10 ++++++++++ 5 files changed, 29 insertions(+)
Signature · 1 line
2.7.4
PATCH v3 1/2 console: introduce dpy_gfx_update_full
dpy_gfx_update_full is used to do the whole display surface update.
This function is proposed by Gerd Hoffmann.
--- include/ui/console.h | 1 + ui/console.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
include/ui/console.h +1 -0
@@ -291,6 +291,7 @@ bool dpy_ui_info_supported(QemuConsole *con);int dpy_set_ui_info (QemuConsole *con,QemuUIInfo *info);void dpy_gfx_update (QemuConsole *con,int x,int y,int w,int h); +void dpy_gfx_update_full (QemuConsole *con);void dpy_gfx_replace_surface (QemuConsole *con,DisplaySurface *surface);void dpy_text_cursor (QemuConsole *con,int x,int y);
ui/console.c +10 -0
@@ -1574,6 +1574,16 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h) } } +void dpy_gfx_update_full (QemuConsole *con) +{ +if (!con->surface) { +return ; + } +dpy_gfx_update (con,0 ,0 , +surface_width (con->surface), +surface_height (con->surface)); +} +void dpy_gfx_replace_surface (QemuConsole *con,DisplaySurface *surface) {
Signature · 1 line
2.7.4
PATCH v3 2/2 ui: introduce vfio_display_reset
In reply to Tina ZhangDuring guest OS reboot, guest framebuffer is invalid. It will cause bugs, if the invalid guest framebuffer is still used by host.
This patch is to introduce vfio_display_reset which is invoked during vfio display reset. This vfio_display_reset function is used to release the invalid display resource, disable scanout mode and replace the invalid surface with QemuConsole's DisplaySurafce.
This patch can fix the GPU hang issue caused by gd_egl_draw during guest OS reboot.
Changes v2->v3:
- Limit vfio_display_reset to dma-buf based vfio display. (Gerd)
Changes v1->v2:
- Use dpy_gfx_update_full() update screen after reset. (Gerd)
- Remove dpy_gfx_switch_surface(). (Gerd)
--- hw/vfio/display.c | 10 ++++++++++ hw/vfio/pci.c | 7 +++++++ hw/vfio/pci.h | 1 + 3 files changed, 18 insertions(+)
hw/vfio/display.c +10 -0
@@ -198,6 +198,16 @@ static void vfio_display_dmabuf_exit(VFIODisplay *dpy) }/* ---------------------------------------------------------------------- */ +void vfio_display_reset (VFIOPCIDevice *vdev) +{ +if (!vdev || !vdev->dpy || !vdev->dpy->con) { +return ; + } + +dpy_gl_scanout_disable (vdev->dpy->con); +vfio_display_dmabuf_exit (vdev->dpy); +dpy_gfx_update_full (vdev->dpy->con); +}static void vfio_display_region_update (void *opaque) {
hw/vfio/pci.c +7 -0
@@ -3098,11 +3098,18 @@ static void vfio_pci_reset(DeviceState *dev) {PCIDevice *pdev =DO_UPCAST (PCIDevice, qdev, dev);VFIOPCIDevice *vdev =DO_UPCAST (VFIOPCIDevice, pdev, pdev); +VFIODisplay *dpy = vdev->dpy;trace_vfio_pci_reset (vdev->vbasedev.name);vfio_pci_pre_reset (vdev); +/* vfio_display_reset is needed by dma-buf based vfio display */ +if (vdev->display !=ON_OFF_AUTO_OFF && dpy && + dpy->dmabuf.primary) { +vfio_display_reset (vdev); + } +if (vdev->resetfn && !vdev->resetfn (vdev)) { goto post_reset; }
hw/vfio/pci.h +1 -0
@@ -176,6 +176,7 @@ int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,struct vfio_region_info *info, Error **errp); +void vfio_display_reset (VFIOPCIDevice *vdev);int vfio_display_probe (VFIOPCIDevice *vdev,Error **errp);void vfio_display_finalize (VFIOPCIDevice *vdev);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v3 2/2] ui: introduce vfio_display_reset
Quoted 5 lines
/* ---------------------------------------------------------------------- */
hw/vfio/display.c +4
-0+void vfio_display_reset (VFIOPCIDevice *vdev) +{ +if (!vdev || !vdev->dpy || !vdev->dpy->con) { +return ;
hw/vfio/display.c static void vfio_display_dmabuf_exit(VFIODisplay *dpy)
Quoted 10 lines
hw/vfio/display.c +9
-0+ } + +dpy_gl_scanout_disable (vdev->dpy->con); +vfio_display_dmabuf_exit (vdev->dpy); +dpy_gfx_update_full (vdev->dpy->con); +} +/* vfio_display_reset is needed by dma-buf based vfio display */ +if (vdev->display !=ON_OFF_AUTO_OFF && dpy && + dpy->dmabuf.primary) {
Well, the check should be inside the vfio_display_reset() function, so the display specific code is contained to display.c.
cheers,
Gerd