drm/udl: Fix stray URBs and cleanup
Subsystems (3)
cover drm/udl: Fix stray URBs and cleanup
Hi,
this is a series of fixes for UDL driver to address the leftover URBs at suspend/resume. It begins with the simplification of FIFO control code with the standard wait queue, followed by the handling of pending URBs, and replace BUG_ON() with WARN_ON() as a cleanup.
Takashi
===
Takashi Iwai (4):
drm/udl: Replace semaphore with a simple wait queue drm/udl: Sync pending URBs at suspend / disconnect drm/udl: Kill pending URBs at suspend and disconnect drm/udl: Replace BUG_ON() with WARN_ON()
drivers/gpu/drm/udl/udl_drv.h | 14 +++- drivers/gpu/drm/udl/udl_main.c | 125 ++++++++++++++--------------- drivers/gpu/drm/udl/udl_modeset.c | 4 + drivers/gpu/drm/udl/udl_transfer.c | 3 +- 4 files changed, 79 insertions(+), 67 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/4 drm/udl: Replace semaphore with a simple wait queue
UDL driver uses a semaphore for controlling the emptiness of FIFO in a slightly funky way. This patch replaces it with a wait queue and controls the emptiness with the standard wait_event*() macro instead, which is a more straightforward implementation.
While we are at it, drop the dead code for delayed semaphore down, too.
--- drivers/gpu/drm/udl/udl_drv.h | 11 +++-- drivers/gpu/drm/udl/udl_main.c | 84 ++++++++++------------------------ 2 files changed, 31 insertions(+), 64 deletions(-)
drivers/gpu/drm/udl/udl_drv.h +8 -3
@@ -34,14 +34,13 @@ struct udl_device;struct urb_node {struct list_head entry;struct udl_device *dev; -struct delayed_work release_urb_work;struct urb *urb; };struct urb_list {struct list_head list;spinlock_t lock; -struct semaphore limit_sem; +wait_queue_head_t sleep;int available;int count;size_t size;
@@ -75,7 +74,13 @@ static inline struct usb_device *udl_to_usb_device(struct udl_device *udl)int udl_modeset_init (struct drm_device *dev);struct drm_connector *udl_connector_init (struct drm_device *dev); -struct urb *udl_get_urb (struct drm_device *dev); +struct urb *udl_get_urb_timeout (struct drm_device *dev,long timeout); + +#define GET_URB_TIMEOUT HZ +static inline struct urb *udl_get_urb (struct drm_device *dev) +{ +return udl_get_urb_timeout (dev,GET_URB_TIMEOUT ); +}int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);void udl_urb_completion (struct urb *urb);
drivers/gpu/drm/udl/udl_main.c +23 -61
151 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH 2/4 drm/udl: Sync pending URBs at suspend / disconnect
In reply to Takashi IwaiWe need to wait for finishing to process the all URBs after disabling the pipe; otherwise pending URBs may stray at suspend/resume, leading to a possible memory corruption in a worst case.
--- drivers/gpu/drm/udl/udl_drv.h | 1 + drivers/gpu/drm/udl/udl_main.c | 17 +++++++++++++++++ drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 20 insertions(+)
drivers/gpu/drm/udl/udl_drv.h +1 -0
@@ -83,6 +83,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev) }int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len); +int udl_sync_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);
drivers/gpu/drm/udl/udl_main.c +17 -0
@@ -270,6 +270,23 @@ int udl_submit_urb(struct drm_device *dev, struct urb *urb, size_t len)return ret; } +/* wait until all pending URBs have been processed */ +int udl_sync_pending_urbs (struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +int ret =0 ; + +spin_lock_irq (&udl->urbs.lock); +/* 2 seconds as a sane timeout */ +if (!wait_event_lock_irq_timeout (udl->urbs.sleep, + udl->urbs.available == udl->urbs.count, + udl->urbs.lock, +msecs_to_jiffies (2000 ))) + ret = -ETIMEDOUT ; +spin_unlock_irq (&udl->urbs.lock); +return ret; +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;
drivers/gpu/drm/udl/udl_modeset.c +2 -0
@@ -408,6 +408,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) buf =udl_dummy_render (buf);udl_submit_urb (dev, urb, buf - (char *)urb->transfer_buffer); + +udl_sync_pending_urbs (dev); } static void
Signature · 1 line
2.35.3
PATCH 3/4 drm/udl: Kill pending URBs at suspend and disconnect
In reply to Takashi IwaiAt both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)
drivers/gpu/drm/udl/udl_drv.h +2 -0
@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;
@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);
drivers/gpu/drm/udl/udl_main.c +22 -3
@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags);
@@ -180,6 +180,7 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) retry: udl->urbs.size = size;INIT_LIST_HEAD (&udl->urbs.list); +INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;
@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:
@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;
@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs (struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;
@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;
drivers/gpu/drm/udl/udl_modeset.c +2 -0
@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); + urb =udl_get_urb (dev);if (!urb)return ;
Signature · 1 line
2.35.3
Thomas Zimmermann
maintainerRe: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 110 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +22
-3@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags);@@ -180,6 +180,7 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) retry: udl->urbs.size = size;INIT_LIST_HEAD (&udl->urbs.list); +INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs (struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0
drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 401
Quoted 5 lines
drivers/gpu/drm/udl/udl_modeset.c +2
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +
I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Best regards
Thomas
Quoted 3 lines
drivers/gpu/drm/udl/udl_modeset.c +0
-0urb =udl_get_urb (dev);if (!urb)return ;
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Re: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Quoted 116 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
Quoted 3 lines
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
Takashi
Thomas Zimmermann
maintainerRe: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 118 lines
Quoted 116 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
Quoted 6 lines
Quoted 3 lines
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable() only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.
Best regards
Thomas
Quoted 3 lines
Takashi
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Re: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Quoted 126 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 122 lines
Quoted 119 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Quoted 7 lines
Quoted 2 lines
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable()only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.
But udl_simple_display_pipe_disable() invokes UDL_BLANK_MODE_POWERDOWN command right after the place I've put udl_kill_pending_urbs(). So it shall blank / turn off the power (of the device, as it has a single output). And the URB completion doesn't do any error handling but just re-links URB chain and wakes up the queue. So killing a pending URB would nothing but canceling the in-flight URBs, and there should be no disturbance to the modeset operation itself, as the screen will be blanked immediately.
Of course, it's all theory, and if this breaks anything, it should be corrected :)
thanks,
Takashi
Thomas Zimmermann
maintainerRe: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Hi
Am 09.08.22 um 11:03 schrieb Takashi Iwai:
Quoted 136 lines
Quoted 126 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 122 lines
Quoted 119 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Quoted 7 lines
Quoted 2 lines
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable()only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.
Quoted 8 lines
But
udl_simple_display_pipe_disable()invokesUDL_BLANK_MODE_POWERDOWNcommand right after the place I've putudl_kill_pending_urbs(). So it shall blank / turn off the power (of the device, as it has a single output). And the URB completion doesn't do any error handling but just re-links URB chain and wakes up the queue. So killing a pending URB would nothing but canceling the in-flight URBs, and there should be no disturbance to the modeset operation itself, as the screen will be blanked immediately.
The blank mode is essentially DPMS. It's unrelated to the device's display mode.
Best regards
Thomas
Quoted 8 lines
Of course, it's all theory, and if this breaks anything, it should be corrected :)
thanks,
Takashi
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Re: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Quoted 149 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 11:03 schrieb Takashi Iwai:
Quoted 136 lines
Quoted 126 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 122 lines
Quoted 119 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Quoted 7 lines
Quoted 2 lines
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable()only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.Quoted 8 lines
But
udl_simple_display_pipe_disable()invokesUDL_BLANK_MODE_POWERDOWNcommand right after the place I've putudl_kill_pending_urbs(). So it shall blank / turn off the power (of the device, as it has a single output). And the URB completion doesn't do any error handling but just re-links URB chain and wakes up the queue. So killing a pending URB would nothing but canceling the in-flight URBs, and there should be no disturbance to the modeset operation itself, as the screen will be blanked immediately.
Quoted 2 lines
The blank mode is essentially DPMS. It's unrelated to the device's display mode.
The function invokes the UDL_BLANK_MODE_POWERDOWN command; that will discard the whole rendered picture. And, the counterpart, udl_simple_display_pipe_enable(), re-initializes the mode fully from the scratch again.
So what's the point to continue rendering that is immediately cleared (from the screen and from the device state)? Killing pending URBs doesn't influence on the internal (modeset) state of the driver.
Takashi
Re: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Quoted 155 lines · Takashi Iwai
Quoted 149 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 11:03 schrieb Takashi Iwai:
Quoted 136 lines
Quoted 126 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 122 lines
Quoted 119 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Quoted 7 lines
Quoted 2 lines
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable()only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.Quoted 8 lines
But
udl_simple_display_pipe_disable()invokesUDL_BLANK_MODE_POWERDOWNcommand right after the place I've putudl_kill_pending_urbs(). So it shall blank / turn off the power (of the device, as it has a single output). And the URB completion doesn't do any error handling but just re-links URB chain and wakes up the queue. So killing a pending URB would nothing but canceling the in-flight URBs, and there should be no disturbance to the modeset operation itself, as the screen will be blanked immediately.Quoted 2 lines
The blank mode is essentially DPMS. It's unrelated to the device's display mode.
Quoted 7 lines
The function invokes the
UDL_BLANK_MODE_POWERDOWNcommand; that will discard the whole rendered picture. And, the counterpart,udl_simple_display_pipe_enable(), re-initializes the mode fully from the scratch again.
So what's the point to continue rendering that is immediately cleared (from the screen and from the device state)? Killing pending URBs doesn't influence on the internal (modeset) state of the driver.
In anyway, this patchset seems problematic around the disconnection, and maybe this particular one is no much improvement, better to drop for now.
I'll resubmit the v2 patch set including your resume fixes later.
thanks,
Takashi
Thomas Zimmermann
maintainerRe: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Hi Takashi
Am 16.08.22 um 15:55 schrieb Takashi Iwai:
Quoted 165 lines
Quoted 155 lines · Takashi Iwai
Quoted 149 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 11:03 schrieb Takashi Iwai:
Quoted 136 lines
Quoted 126 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 122 lines
Quoted 119 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Quoted 7 lines
Quoted 2 lines
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable()only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.Quoted 8 lines
But
udl_simple_display_pipe_disable()invokesUDL_BLANK_MODE_POWERDOWNcommand right after the place I've putudl_kill_pending_urbs(). So it shall blank / turn off the power (of the device, as it has a single output). And the URB completion doesn't do any error handling but just re-links URB chain and wakes up the queue. So killing a pending URB would nothing but canceling the in-flight URBs, and there should be no disturbance to the modeset operation itself, as the screen will be blanked immediately.Quoted 2 lines
The blank mode is essentially DPMS. It's unrelated to the device's display mode.
Quoted 7 lines
The function invokes the
UDL_BLANK_MODE_POWERDOWNcommand; that will discard the whole rendered picture. And, the counterpart,udl_simple_display_pipe_enable(), re-initializes the mode fully from the scratch again.
So what's the point to continue rendering that is immediately cleared (from the screen and from the device state)? Killing pending URBs doesn't influence on the internal (modeset) state of the driver.
Quoted 5 lines
In anyway, this patchset seems problematic around the disconnection, and maybe this particular one is no much improvement, better to drop for now.
I'll resubmit the v2 patch set including your resume fixes later.
I already merged the patches before seeing the discussion on the rsp bug report. If you submit an update, maybe you can do so with Fixes tags?
Best regards
Thomas
Quoted 5 lines
thanks,
Takashi
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Re: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect
Quoted 173 lines · Thomas Zimmermann
Hi Takashi
Am 16.08.22 um 15:55 schrieb Takashi Iwai:
Quoted 169 lines
Quoted 155 lines · Takashi Iwai
Quoted 149 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 11:03 schrieb Takashi Iwai:
Quoted 136 lines
Quoted 126 lines · Thomas Zimmermann
Hi
Am 09.08.22 um 09:15 schrieb Takashi Iwai:
Quoted 122 lines
Quoted 119 lines · Thomas Zimmermann
Hi
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 103 lines
At both suspend and disconnect, we should rather cancel the pending URBs immediately. For the suspend case, the display will be turned off, so it makes no sense to process the rendering. And for the disconnect case, the device may be no longer accessible, hence we shouldn't do any submission.
Tested-by Thomas Zimmermann <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/gpu/drm/udl/udl_drv.h | 2 ++ drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- drivers/gpu/drm/udl/udl_modeset.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-)drivers/gpu/drm/udl/udl_drv.h +2
-0@@ -39,6 +39,7 @@ struct urb_node {struct urb_list {struct list_head list; +struct list_head in_flight;spinlock_t lock;wait_queue_head_t sleep;int available;@@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev)int udl_submit_urb (struct drm_device *dev,struct urb *urb,size_t len);int udl_sync_pending_urbs (struct drm_device *dev); +void udl_kill_pending_urbs (struct drm_device *dev);void udl_urb_completion (struct urb *urb);int udl_init (struct udl_device *udl);drivers/gpu/drm/udl/udl_main.c +1
-1@@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) urb->transfer_buffer_length = udl->urbs.size;/* reset to actual */ spin_lock_irqsave (&udl->urbs.lock, flags); -list_add_tail (&unode->entry, &udl->urbs.list); +list_move (&unode->entry, &udl->urbs.list); udl->urbs.available++;spin_unlock_irqrestore (&udl->urbs.lock, flags); @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(structdrm_device *dev,int count,size_t size)retry: udl->urbs.size = size; INIT_LIST_HEAD(&udl->urbs.list);drivers/gpu/drm/udl/udl_main.c +19
-2+INIT_LIST_HEAD (&udl->urbs.in_flight);init_waitqueue_head (&udl->urbs.sleep); udl->urbs.count =0 ;@@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) } unode = list_first_entry(&udl->urbs.list, struct urb_node, entry); -list_del_init (&unode->entry); +list_move (&unode->entry, &udl->urbs.in_flight); udl->urbs.available--; unlock:@@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev)spin_lock_irq (&udl->urbs.lock);/* 2 seconds as a sane timeout */ if (!wait_event_lock_irq_timeout (udl->urbs.sleep, - udl->urbs.available == udl->urbs.count, +list_empty (&udl->urbs.in_flight), udl->urbs.lock,msecs_to_jiffies (2000 ))) ret = -ETIMEDOUT ;@@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev)return ret; } +/* kill pending URBs */ +void udl_kill_pending_urbs(struct drm_device *dev) +{ +struct udl_device *udl =to_udl (dev); +struct urb_node *unode; + +spin_lock_irq (&udl->urbs.lock); +while (!list_empty (&udl->urbs.in_flight)) { + unode =list_first_entry (&udl->urbs.in_flight, + struct urb_node, entry); +spin_unlock_irq (&udl->urbs.lock); +usb_kill_urb (unode->urb); +spin_lock_irq (&udl->urbs.lock); + } +spin_unlock_irq (&udl->urbs.lock); +} +int udl_init (struct udl_device *udl) {struct drm_device *dev = &udl->drm;@@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) {struct udl_device *udl =to_udl (dev); +udl_kill_pending_urbs (dev);udl_free_urb_list (dev);put_device (udl->dmadev); udl->dmadev =NULL ;drivers/gpu/drm/udl/udl_modeset.c +0
-0drivers/gpu/drm/udl/udl_modeset.c udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) · line 400
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +1
-0@@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)struct urb *urb;char *buf; +udl_kill_pending_urbs (dev); +I already reviewed the patchset, but I have another comment. I think we should only kill urbs from within the suspend handler. Same for the call to the URB-sync function in patch 2.
This disable function is part of the regular modeset path. It's probably not appropriate to outright remove pending URBs here. This can lead to failed modesets, which would have succeeded otherwise.
Quoted 7 lines
Quoted 2 lines
Well, the device shall be turned off right after that point, so the all pending rendering makes little sense, no?
udl_simple_display_pipe_disable()only disables the display, but not the device. The kill operation here could potentially kill some valid modeset operation that was still going on. And who knows what the device state is after that.Quoted 8 lines
But
udl_simple_display_pipe_disable()invokesUDL_BLANK_MODE_POWERDOWNcommand right after the place I've putudl_kill_pending_urbs(). So it shall blank / turn off the power (of the device, as it has a single output). And the URB completion doesn't do any error handling but just re-links URB chain and wakes up the queue. So killing a pending URB would nothing but canceling the in-flight URBs, and there should be no disturbance to the modeset operation itself, as the screen will be blanked immediately.Quoted 2 lines
The blank mode is essentially DPMS. It's unrelated to the device's display mode.
Quoted 7 lines
The function invokes the
UDL_BLANK_MODE_POWERDOWNcommand; that will discard the whole rendered picture. And, the counterpart,udl_simple_display_pipe_enable(), re-initializes the mode fully from the scratch again.
So what's the point to continue rendering that is immediately cleared (from the screen and from the device state)? Killing pending URBs doesn't influence on the internal (modeset) state of the driver.In anyway, this patchset seems problematic around the disconnection, and maybe this particular one is no much improvement, better to drop for now.
Quoted 5 lines
Quoted 1 line
I'll resubmit the v2 patch set including your resume fixes later.
I already merged the patches before seeing the discussion on the rsp bug report. If you submit an update, maybe you can do so with Fixes tags?
Oh sure, will check then.
Takashi
PATCH 4/4 drm/udl: Replace BUG_ON() with WARN_ON()
In reply to Takashi IwaiBUG_ON() is a tasteless choice as a sanity check for a driver like UDL that isn't really a core code. Replace with WARN_ON() and proper error handling instead.
--- drivers/gpu/drm/udl/udl_main.c | 3 ++- drivers/gpu/drm/udl/udl_transfer.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/udl/udl_main.c +2 -1
@@ -260,7 +260,8 @@ int udl_submit_urb(struct drm_device *dev, struct urb *urb, size_t len)struct udl_device *udl =to_udl (dev);int ret; -BUG_ON (len > udl->urbs.size); +if (WARN_ON (len > udl->urbs.size)) +return -EINVAL ; urb->transfer_buffer_length = len;/* set to actual payload len */ ret =usb_submit_urb (urb,GFP_ATOMIC );
drivers/gpu/drm/udl/udl_transfer.c +2 -1
@@ -220,7 +220,8 @@ int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr,u8 *cmd = *urb_buf_ptr;u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length; -BUG_ON (!(log_bpp ==1 || log_bpp ==2 )); +if (WARN_ON (!(log_bpp ==1 || log_bpp ==2 ))) +return -EINVAL ; line_start = (u8 *) (front + byte_offset); next_pixel = line_start;
Signature · 1 line
2.35.3
Hi Takashi,
Am 04.08.22 um 09:58 schrieb Takashi Iwai:
Quoted 6 lines
Hi,
this is a series of fixes for UDL driver to address the leftover URBs at suspend/resume. It begins with the simplification of FIFO control code with the standard wait queue, followed by the handling of pending URBs, and replace
BUG_ON()withWARN_ON()as a cleanup.
That's a lot better than what's currently there. If no other reviews come in, I'll add the patches next week.
Best regards
Thomas
Quoted 18 lines
Takashi
===
Takashi Iwai (4):
drm/udl: Replace semaphore with a simple wait queue drm/udl: Sync pending URBs at suspend / disconnect drm/udl: Kill pending URBs at suspend and disconnect drm/udl: ReplaceBUG_ON()withWARN_ON()drivers/gpu/drm/udl/udl_drv.h | 14 +++- drivers/gpu/drm/udl/udl_main.c | 125 ++++++++++++++--------------- drivers/gpu/drm/udl/udl_modeset.c | 4 + drivers/gpu/drm/udl/udl_transfer.c | 3 +- 4 files changed, 79 insertions(+), 67 deletions(-)
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev