drm/virtio: Add drm_panic support
Subsystems (4)
PATCH v4 1/1 drm/virtio: Add drm_panic support
From: Jocelyn Falempe <[email protected]>
Virtio gpu supports the drm_panic module, which displays a message to the screen when a kernel panic occurs.
---
v4:
- As per Dmitry's comment, make virtio_panic_buffer private to virtio_gpu_device.
v3:
https://lkml.org/lkml/2024/11/8/155
- As per Jocelyn's comment, add a finite timeout 500usec in virtio_gpu_panic_put_vbuf() to avoid infinite loop
v2:
https://lkml.org/lkml/2024/11/6/668
- Remove unnecessary virtio_gpu_vbuffer_inline
- Remove reclaim_list and just call drm_gem_object_put() if there is an obj
- Don't wait for an event in virtio_gpu_panic_queue_ctrl_sgs and just return -ENOMEM. Also add error handlers for this error.
- Use virtio_gpu_panic_queue_fenced_ctrl_buffer() in virtio_gpu_panic_cmd_resource_flush
- Remove fence and objs arguments because these are always NULL in panic handler.
- Rename virtio_gpu_panic_queue_fenced_ctrl_buffer to ..._queue_ctrl_buffer
- Rename virtio_gpu_panic_alloc_cmd to ..._panic_init_cmd
v1:
https://lkml.org/lkml/2024/10/31/154
drivers/gpu/drm/virtio/virtgpu_drv.h | 19 +++ drivers/gpu/drm/virtio/virtgpu_plane.c | 171 +++++++++++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_vq.c | 148 ++++++++++++++++++++- 3 files changed, 332 insertions(+), 6 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +19 -0
@@ -125,6 +125,12 @@ struct virtio_gpu_object_array { struct drm_gem_object *objs[] __counted_by(total); }; +#define MAX_INLINE_CMD_SIZE 96 +#define MAX_INLINE_RESP_SIZE 24 +#define VBUFFER_SIZE (sizeof(struct virtio_gpu_vbuffer) \ + + MAX_INLINE_CMD_SIZE \ + + MAX_INLINE_RESP_SIZE) +struct virtio_gpu_vbuffer ;struct virtio_gpu_device ;
@@ -267,6 +273,7 @@ struct virtio_gpu_device {spinlock_t resource_export_lock;/* protects map state and host_visible_mm */ spinlock_t host_visible_lock; +void *virtio_panic_buffer; };struct virtio_gpu_fpriv {
@@ -329,12 +336,23 @@ void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev, struct virtio_gpu_fence *fence);void virtio_gpu_cmd_unref_resource (struct virtio_gpu_device *vgdev,struct virtio_gpu_object *bo); +int virtio_gpu_panic_cmd_transfer_to_host_2d (struct virtio_gpu_device *vgdev, +uint64_t offset, +uint32_t width,uint32_t height, +uint32_t x,uint32_t y, +struct virtio_gpu_object_array *objs, +struct virtio_gpu_vbuffer *vbuf);void virtio_gpu_cmd_transfer_to_host_2d (struct virtio_gpu_device *vgdev,uint64_t offset,uint32_t width,uint32_t height,uint32_t x,uint32_t y,struct virtio_gpu_object_array *objs,struct virtio_gpu_fence *fence); +int virtio_gpu_panic_cmd_resource_flush (struct virtio_gpu_device *vgdev, +struct virtio_gpu_vbuffer *vbuf, +uint32_t resource_id, +uint32_t x,uint32_t y, +uint32_t width,uint32_t height); void virtio_gpu_cmd_resource_flush(struct virtio_gpu_device *vgdev, uint32_t resource_id, uint32_t x, uint32_t y,
@@ -399,6 +417,7 @@ void virtio_gpu_ctrl_ack(struct virtqueue *vq);void virtio_gpu_cursor_ack (struct virtqueue *vq);void virtio_gpu_dequeue_ctrl_func (struct work_struct *work);void virtio_gpu_dequeue_cursor_func (struct work_struct *work); +void virtio_gpu_panic_notify (struct virtio_gpu_device *vgdev);void virtio_gpu_notify (struct virtio_gpu_device *vgdev);int
drivers/gpu/drm/virtio/virtgpu_plane.c +171 -0
206 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +142 -6
184 lines not on this page · raw message
Signature · 1 line
2.47.0
Dmitry Osipenko
maintainerQuoted 8 lines · Ryosuke Yasuoka
From: Jocelyn Falempe <[email protected]>
Virtio gpu supports the
drm_panicmodule, which displays a message to the screen when a kernel panic occurs.Signed-off-by Ryosuke Yasuoka <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>---
I'll apply this patch tomorrow with a shortened virtio_panic_buffer variable name if nobody will have more comments to add.
Signature · 2 lines
Best regards, Dmitry
Dmitry Osipenko
maintainerQuoted 8 lines · Ryosuke Yasuoka
From: Jocelyn Falempe <[email protected]>
Virtio gpu supports the
drm_panicmodule, which displays a message to the screen when a kernel panic occurs.Signed-off-by Ryosuke Yasuoka <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>---
On a second look, I spotted few problems, see them below:
...
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +8
-0+/* For drm_panic */ +static int virtio_gpu_panic_resource_flush (struct drm_plane *plane, +struct virtio_gpu_vbuffer *vbuf, +uint32_t x,uint32_t y, +uint32_t width,uint32_t height) +{ +int ret; +struct drm_device *dev = plane->dev;
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_update_dumb_bo(struct virtio_gpu_device *vgdev, · line 178
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+struct virtio_gpu_device *vgdev = dev->dev_private; +struct virtio_gpu_framebuffer *vgfb; +struct virtio_gpu_object *bo; + + vgfb =to_virtio_gpu_framebuffer (plane->state->fb); + bo =gem_to_virtio_gpu_obj (vgfb->base.obj[0 ]); + + ret =virtio_gpu_panic_cmd_resource_flush (vgdev, vbuf, bo->hw_res_handle, x, y, + width, height); +return ret;
Nit: return directly directly in such cases, dummy ret variable not needed
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +2
-0+} +static void virtio_gpu_resource_flush (struct drm_plane *plane,uint32_t x,uint32_t y,uint32_t width,uint32_t height)@@ -359,11 +406,128 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,virtio_gpu_cursor_ping (vgdev, output); }
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 417
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +9
-0+static int virtio_drm_get_scanout_buffer (struct drm_plane *plane, +struct drm_scanout_buffer *sb) +{ +struct virtio_gpu_object *bo; + +if (!plane->state || !plane->state->fb || !plane->state->visible) +return -ENODEV ; + + bo =gem_to_virtio_gpu_obj (plane->state->fb->obj[0 ]);
VRAM BOs aren't vmappable and should be rejected.
In the virtio_panic_flush() below, virtio_gpu_panic_cmd_transfer_to_host_2d() is invoked only for dumb BOs. Thus, only dumb BO supports panic output and should be accepted by get_scanout_buffer(), other should be rejected with ENODEV here, AFAICT. Correct?
Quoted 14 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +14
-0+/* try to vmap it if possible */ +if (!bo->base.vaddr) { +int ret; + + ret =drm_gem_shmem_vmap (&bo->base, &sb->map[0 ]); +if (ret) +return ret; + }else { +iosys_map_set_vaddr (&sb->map[0 ], bo->base.vaddr); + } + + sb->format = plane->state->fb->format; + sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width;
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 442
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+ sb->pitch[0 ] = plane->state->fb->pitches[0 ]; +return 0 ; +} + +struct virtio_gpu_panic_object_array { +struct ww_acquire_ctx ticket; +struct list_head next; +u32 nents, total; +struct drm_gem_object *objs; +};
This virtio_gpu_panic_object_array struct is a hack, use virtio_gpu_array_alloc(). Maybe add atomic variant of the array_alloc().
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 454
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+static void virtio_gpu_panic_put_vbuf (struct virtqueue *vq, +struct virtio_gpu_vbuffer *vbuf, +struct virtio_gpu_object_array *objs) +{ +unsigned int len; +int i; + +/* waiting vbuf to be used */ +for (i =0 ; i <500 ; i++) { +if (vbuf ==virtqueue_get_buf (vq, &len)) {
Is it guaranteed that virtio_gpu_dequeue_ctrl_func() never runs in parallel here?
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 456
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +2
-0+if (objs !=NULL && vbuf->objs) +drm_gem_object_put (objs->objs[0 ]);
This drm_gem_object_put(objs->objs) is difficult to follow. Why vbuf->objs can't be used directly?
Better to remove all error handlings for simplicity. It's not important if a bit of memory leaked on panic.
Quoted 21 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +21
-0+break ; + } +udelay (1 ); + } +} + +static void virtio_panic_flush (struct drm_plane *plane) +{ +int ret; +struct virtio_gpu_object *bo; +struct drm_device *dev = plane->dev; +struct virtio_gpu_device *vgdev = dev->dev_private; +struct drm_rect rect; +void *vp_buf = vgdev->virtio_panic_buffer; +struct virtio_gpu_vbuffer *vbuf_dumb_bo = vp_buf; +struct virtio_gpu_vbuffer *vbuf_resource_flush = vp_buf +VBUFFER_SIZE ; + + rect.x1 =0 ; + rect.y1 =0 ; + rect.x2 = plane->state->fb->width; + rect.y2 = plane->state->fb->height;
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 487
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+ + bo =gem_to_virtio_gpu_obj (plane->state->fb->obj[0 ]); + +struct drm_gem_object obj; +struct virtio_gpu_panic_object_array objs = { + .next = {NULL ,NULL }, + .nents =0 , + .total =1 , + .objs = &obj + };
This &obj is unitialized stack data. The .objs points to an array of obj pointers and you pointing it to object. Like I suggested above, let's remove this hack and use proper virtio_gpu_array_alloc().
Quoted 12 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +12
-0+if (bo->dumb) { + ret =virtio_gpu_panic_update_dumb_bo (vgdev, + plane->state, + &rect, + (struct virtio_gpu_object_array *)&objs, + vbuf_dumb_bo); +if (ret) { +if (vbuf_dumb_bo->objs) +drm_gem_object_put (&objs.objs[0 ]); +return ; + } + }
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 510
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+ + ret =virtio_gpu_panic_resource_flush (plane, vbuf_resource_flush, + plane->state->src_x >>16 , + plane->state->src_y >>16 , + plane->state->src_w >>16 , + plane->state->src_h >>16 ); +if (ret) { +virtio_gpu_panic_put_vbuf (vgdev->ctrlq.vq, + vbuf_dumb_bo, + (struct virtio_gpu_object_array *)&objs);
The virtio_gpu_panic_notify() hasn't been invoked here, thus this put_vbuf should always time out because vq hasn't been kicked. Again, best to leak resources on error than to have broken/untested error handling code paths.
Quoted 24 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +15
-0+return ; + } + +virtio_gpu_panic_notify (vgdev); + +virtio_gpu_panic_put_vbuf (vgdev->ctrlq.vq, + vbuf_dumb_bo, + (struct virtio_gpu_object_array *)&objs); +virtio_gpu_panic_put_vbuf (vgdev->ctrlq.vq, + vbuf_resource_flush, +NULL ); +} +static const struct drm_plane_helper_funcs virtio_gpu_primary_helper_funcs = { .prepare_fb = virtio_gpu_plane_prepare_fb, .cleanup_fb = virtio_gpu_plane_cleanup_fb, .atomic_check = virtio_gpu_plane_atomic_check, .atomic_update = virtio_gpu_primary_plane_update, + .get_scanout_buffer = virtio_drm_get_scanout_buffer, + .panic_flush = virtio_panic_flush, };static const struct drm_plane_helper_funcs virtio_gpu_cursor_helper_funcs = {
drivers/gpu/drm/virtio/virtgpu_plane.c struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev, · line 555
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +6
-0@@ -383,6 +547,13 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,const uint32_t *formats;int nformats; +/* allocate panic buffers */ +if (index ==0 && type ==DRM_PLANE_TYPE_PRIMARY ) { + vgdev->virtio_panic_buffer =drmm_kzalloc (dev,2 *VBUFFER_SIZE ,GFP_KERNEL ); +if (!vgdev->virtio_panic_buffer) +return ERR_PTR (-ENOMEM ); + }
If there is more than one virtio-gpu display, then this panic buffer is reused by other displays. It seems to work okay, but potential implications are unclear. Won't it be more robust to have a panic buffer per CRTC?
Also, please rename vgdev->virtio_panic_buffer to vgdev->panic_vbuf for brevity.
Signature · 2 lines
Best regards, Dmitry
Quoted 55 lines · Dmitry Osipenko
Quoted 8 lines · Ryosuke Yasuoka
From: Jocelyn Falempe <[email protected]>
Virtio gpu supports the
drm_panicmodule, which displays a message to the screen when a kernel panic occurs.Signed-off-by Ryosuke Yasuoka <[email protected]>Signed-off-by Jocelyn Falempe <[email protected]>---
On a second look, I spotted few problems, see them below:
...
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +8
-0+/* For drm_panic */ +static int virtio_gpu_panic_resource_flush (struct drm_plane *plane, +struct virtio_gpu_vbuffer *vbuf, +uint32_t x,uint32_t y, +uint32_t width,uint32_t height) +{ +int ret; +struct drm_device *dev = plane->dev;drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_update_dumb_bo(struct virtio_gpu_device *vgdev, · line 178
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+struct virtio_gpu_device *vgdev = dev->dev_private; +struct virtio_gpu_framebuffer *vgfb; +struct virtio_gpu_object *bo; + + vgfb =to_virtio_gpu_framebuffer (plane->state->fb); + bo =gem_to_virtio_gpu_obj (vgfb->base.obj[0 ]); + + ret =virtio_gpu_panic_cmd_resource_flush (vgdev, vbuf, bo->hw_res_handle, x, y, + width, height); +return ret;Nit: return directly directly in such cases, dummy ret variable not needed
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +2
-0+} +static void virtio_gpu_resource_flush (struct drm_plane *plane,uint32_t x,uint32_t y,uint32_t width,uint32_t height)@@ -359,11 +406,128 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,virtio_gpu_cursor_ping (vgdev, output); }drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 417
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +9
-0+static int virtio_drm_get_scanout_buffer (struct drm_plane *plane, +struct drm_scanout_buffer *sb) +{ +struct virtio_gpu_object *bo; + +if (!plane->state || !plane->state->fb || !plane->state->visible) +return -ENODEV ; + + bo =gem_to_virtio_gpu_obj (plane->state->fb->obj[0 ]);VRAM BOs aren't vmappable and should be rejected.
Quoted 5 lines
In the
virtio_panic_flush()below,virtio_gpu_panic_cmd_transfer_to_host_2d()is invoked only for dumb BOs. Thus, only dumb BO supports panic output and should be accepted byget_scanout_buffer(), other should be rejected with ENODEV here, AFAICT. Correct?
Yes, it's correct
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +19
-0+/* try to vmap it if possible */ +if (!bo->base.vaddr) { +int ret; + + ret =drm_gem_shmem_vmap (&bo->base, &sb->map[0 ]); +if (ret) +return ret; + }else { +iosys_map_set_vaddr (&sb->map[0 ], bo->base.vaddr); + } + + sb->format = plane->state->fb->format; + sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width; + sb->pitch[0 ] = plane->state->fb->pitches[0 ]; +return 0 ; +} + +struct virtio_gpu_panic_object_array {
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 442
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +5
-0+struct ww_acquire_ctx ticket; +struct list_head next; +u32 nents, total; +struct drm_gem_object *objs; +};This
virtio_gpu_panic_object_arraystruct is a hack, usevirtio_gpu_array_alloc(). Maybe add atomic variant of thearray_alloc().
We can't allocate memory in the panic handler, but maybe it can be pre-allocated, like the virtio_panic_buffer ?
Quoted 14 lines
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 454
Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+static void virtio_gpu_panic_put_vbuf (struct virtqueue *vq, +struct virtio_gpu_vbuffer *vbuf, +struct virtio_gpu_object_array *objs) +{ +unsigned int len; +int i; + +/* waiting vbuf to be used */ +for (i =0 ; i <500 ; i++) { +if (vbuf ==virtqueue_get_buf (vq, &len)) {Is it guaranteed that
virtio_gpu_dequeue_ctrl_func()never runs in parallel here?
Yes, in the panic handler, only one CPU remains active, and no other task can be scheduled.
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 456
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +2
-0+if (objs !=NULL && vbuf->objs) +drm_gem_object_put (objs->objs[0 ]);This
drm_gem_object_put(objs->objs)is difficult to follow. Whyvbuf->objscan't be used directly?Better to remove all error handlings for simplicity. It's not important if a bit of memory leaked on panic.
We try to reclaim, to make it easier to test with the debugfs interface. But this is a bit racy anyway, because it's not the real panic context.
Quoted 56 lines
Quoted 22 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +21
-0+break ; + } +udelay (1 ); + } +} + +static void virtio_panic_flush (struct drm_plane *plane) +{ +int ret; +struct virtio_gpu_object *bo; +struct drm_device *dev = plane->dev; +struct virtio_gpu_device *vgdev = dev->dev_private; +struct drm_rect rect; +void *vp_buf = vgdev->virtio_panic_buffer; +struct virtio_gpu_vbuffer *vbuf_dumb_bo = vp_buf; +struct virtio_gpu_vbuffer *vbuf_resource_flush = vp_buf +VBUFFER_SIZE ; + + rect.x1 =0 ; + rect.y1 =0 ; + rect.x2 = plane->state->fb->width; + rect.y2 = plane->state->fb->height;drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 487
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +10
-0+ + bo =gem_to_virtio_gpu_obj (plane->state->fb->obj[0 ]); + +struct drm_gem_object obj; +struct virtio_gpu_panic_object_array objs = { + .next = {NULL ,NULL }, + .nents =0 , + .total =1 , + .objs = &obj + };This &obj is unitialized stack data. The .objs points to an array of obj pointers and you pointing it to object. Like I suggested above, let's remove this hack and use proper
virtio_gpu_array_alloc().Quoted 19 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +19
-0+if (bo->dumb) { + ret =virtio_gpu_panic_update_dumb_bo (vgdev, + plane->state, + &rect, + (struct virtio_gpu_object_array *)&objs, + vbuf_dumb_bo); +if (ret) { +if (vbuf_dumb_bo->objs) +drm_gem_object_put (&objs.objs[0 ]); +return ; + } + } + + ret =virtio_gpu_panic_resource_flush (plane, vbuf_resource_flush, + plane->state->src_x >>16 , + plane->state->src_y >>16 , + plane->state->src_w >>16 , + plane->state->src_h >>16 ); +if (ret) {
Quoted 8 lines
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 510
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +3
-0+virtio_gpu_panic_put_vbuf (vgdev->ctrlq.vq, + vbuf_dumb_bo, + (struct virtio_gpu_object_array *)&objs);The
virtio_gpu_panic_notify()hasn't been invoked here, thus thisput_vbufshould always time out because vq hasn't been kicked. Again, best to leak resources on error than to have broken/untested error handling code paths.
agreed
Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +15
-0+return ; + } + +virtio_gpu_panic_notify (vgdev); + +virtio_gpu_panic_put_vbuf (vgdev->ctrlq.vq, + vbuf_dumb_bo, + (struct virtio_gpu_object_array *)&objs); +virtio_gpu_panic_put_vbuf (vgdev->ctrlq.vq, + vbuf_resource_flush, +NULL ); +} +static const struct drm_plane_helper_funcs virtio_gpu_primary_helper_funcs = { .prepare_fb = virtio_gpu_plane_prepare_fb, .cleanup_fb = virtio_gpu_plane_cleanup_fb, .atomic_check = virtio_gpu_plane_atomic_check, .atomic_update = virtio_gpu_primary_plane_update, + .get_scanout_buffer = virtio_drm_get_scanout_buffer, + .panic_flush = virtio_panic_flush, };static const struct drm_plane_helper_funcs virtio_gpu_cursor_helper_funcs = {@@ -383,6 +547,13 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,const uint32_t *formats;int nformats;
Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_plane.c struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev, · line 555
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +6
-0+/* allocate panic buffers */ +if (index ==0 && type ==DRM_PLANE_TYPE_PRIMARY ) { + vgdev->virtio_panic_buffer =drmm_kzalloc (dev,2 *VBUFFER_SIZE ,GFP_KERNEL ); +if (!vgdev->virtio_panic_buffer) +return ERR_PTR (-ENOMEM ); + }If there is more than one virtio-gpu display, then this panic buffer is reused by other displays. It seems to work okay, but potential implications are unclear. Won't it be more robust to have a panic buffer per CRTC?
The drm panic handler call each plane sequentially, so it's not a problem. Having one buffer per CRTC would just add more complexity.
Quoted 4 lines
Also, please rename
vgdev->virtio_panic_buffertovgdev->panic_vbuffor brevity.
Thanks for the review.
Signature · 1 line
Jocelyn
Dmitry Osipenko
maintainerOn 11/19/24 13:21, Jocelyn Falempe wrote:
...
Quoted 7 lines
Quoted 5 lines
In the
virtio_panic_flush()below,virtio_gpu_panic_cmd_transfer_to_host_2d()is invoked only for dumb BOs. Thus, only dumb BO supports panic output and should be accepted byget_scanout_buffer(), other should be rejected with ENODEV here, AFAICT. Correct?Yes, it's correct
Please fix in v5.
...
Quoted 10 lines
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_plane.c static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, · line 442
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +6
-0+struct virtio_gpu_panic_object_array { + struct ww_acquire_ctx ticket; + struct list_head next; + u32 nents, total; + struct drm_gem_object *objs; +};This
virtio_gpu_panic_object_arraystruct is a hack, usevirtio_gpu_array_alloc(). Maybe add atomic variant of thearray_alloc().
Quoted 2 lines
We can't allocate memory in the panic handler, but maybe it can be pre- allocated, like the
virtio_panic_buffer?
We certainly can allocate memory from any context using GFP_ATOMIC flag for the allocation. You already doing that in virtio_gpu_panic_queue_ctrl_sgs().
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +5
-0+static void virtio_gpu_panic_put_vbuf (struct virtqueue *vq, + struct virtio_gpu_vbuffer *vbuf, + struct virtio_gpu_object_array *objs) +{ + unsigned int len;Quoted 8 lines
Quoted 5 lines
+ int i;
+
+ /* waiting vbuf to be used */
+ for (i = 0; i < 500; i++) {
+ if (vbuf ==virtqueue_get_buf(vq, &len)) {Is it guaranteed that
virtio_gpu_dequeue_ctrl_func()never runs in parallel here?
Quoted 2 lines
Yes, in the panic handler, only one CPU remains active, and no other task can be scheduled.
Awesome. thanks for the clarification.
...
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
+ ret = virtio_gpu_panic_resource_flush(plane,
vbuf_resource_flush, +plane->state->src_x>> 16,
+plane->state->src_y>> 16,
+plane->state->src_w>> 16,
+plane->state->src_h>> 16);
+ if (ret) {
+ virtio_gpu_panic_put_vbuf(vgdev->ctrlq.vq,
+vbuf_dumb_bo,
+ (structvirtio_gpu_object_array*)&objs);
Quoted 6 lines
Quoted 4 lines
The
virtio_gpu_panic_notify()hasn't been invoked here, thus thisput_vbufshould always time out because vq hasn't been kicked. Again, best to leak resources on error than to have broken/untested error handling code paths.agreed
Please change it in v5.
...
Quoted 7 lines
Quoted 4 lines
If there is more than one virtio-gpu display, then this panic buffer is reused by other displays. It seems to work okay, but potential implications are unclear. Won't it be more robust to have a panic buffer per CRTC?
The drm panic handler call each plane sequentially, so it's not a problem. Having one buffer per CRTC would just add more complexity.
Please add a clarifying comment for that to the code.
Signature · 2 lines
Best regards, Dmitry