diff mbox series

[v2] drm/msm/dp: fix event thread stuck in wait_event after kthread_stop()

Message ID 1651532668-18873-1-git-send-email-quic_khsieh@quicinc.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/msm/dp: fix event thread stuck in wait_event after kthread_stop() | expand

Commit Message

Kuogee Hsieh May 2, 2022, 11:04 p.m. UTC
Event thread supposed to exit from its while loop after kthread_stop().
However there may has possibility that event thread is pending in the
middle of wait_event due to condition checking never become true.
To make sure event thread exit its loop after kthread_stop(), this
patch OR kthread_should_stop() into wait_event's condition checking
so that event thread will exit its loop after kernal_stop().

Changes in v2:
--  correct spelling error at commit title

Reported-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Fixes: 570d3e5d28db ("drm/msm/dp: stop event kernel thread when DP unbind")
Signed-off-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
---
 drivers/gpu/drm/msm/dp/dp_display.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Stephen Boyd May 3, 2022, 1:13 a.m. UTC | #1
Quoting Kuogee Hsieh (2022-05-02 16:04:28)
> Event thread supposed to exit from its while loop after kthread_stop().
> However there may has possibility that event thread is pending in the
> middle of wait_event due to condition checking never become true.
> To make sure event thread exit its loop after kthread_stop(), this
> patch OR kthread_should_stop() into wait_event's condition checking
> so that event thread will exit its loop after kernal_stop().
>
> Changes in v2:
> --  correct spelling error at commit title
>
> Reported-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Fixes: 570d3e5d28db ("drm/msm/dp: stop event kernel thread when DP unbind")
> Signed-off-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
> ---
>  drivers/gpu/drm/msm/dp/dp_display.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
> index c388323..5200a58 100644
> --- a/drivers/gpu/drm/msm/dp/dp_display.c
> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
> @@ -1106,12 +1106,17 @@ static int hpd_event_thread(void *data)
>         while (!kthread_should_stop()) {
>                 if (timeout_mode) {
>                         wait_event_timeout(dp_priv->event_q,
> -                               (dp_priv->event_pndx == dp_priv->event_gndx),
> -                                               EVENT_TIMEOUT);
> +                               ((dp_priv->event_pndx == dp_priv->event_gndx) ||

Why the parenthesis (before and after)?

> +                                       kthread_should_stop()), EVENT_TIMEOUT);
>                 } else {
>                         wait_event_interruptible(dp_priv->event_q,
> -                               (dp_priv->event_pndx != dp_priv->event_gndx));
> +                               ((dp_priv->event_pndx != dp_priv->event_gndx) ||

Why the parenthesis (before and after)?

> +                                       kthread_should_stop()));
>                 }
> +
> +               if(kthread_should_stop())

Missing space after if

> +                       break;

Is it possible to move the wait_event to the end of the loop and always
run the loop initially? That way we don't have to check for
kthread_should_stop() again.
Kuogee Hsieh May 3, 2022, 4:13 p.m. UTC | #2
On 5/2/2022 6:13 PM, Stephen Boyd wrote:
> Quoting Kuogee Hsieh (2022-05-02 16:04:28)
>> Event thread supposed to exit from its while loop after kthread_stop().
>> However there may has possibility that event thread is pending in the
>> middle of wait_event due to condition checking never become true.
>> To make sure event thread exit its loop after kthread_stop(), this
>> patch OR kthread_should_stop() into wait_event's condition checking
>> so that event thread will exit its loop after kernal_stop().
>>
>> Changes in v2:
>> --  correct spelling error at commit title
>>
>> Reported-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>> Fixes: 570d3e5d28db ("drm/msm/dp: stop event kernel thread when DP unbind")
>> Signed-off-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
>> ---
>>   drivers/gpu/drm/msm/dp/dp_display.c | 11 ++++++++---
>>   1 file changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
>> index c388323..5200a58 100644
>> --- a/drivers/gpu/drm/msm/dp/dp_display.c
>> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
>> @@ -1106,12 +1106,17 @@ static int hpd_event_thread(void *data)
>>          while (!kthread_should_stop()) {
>>                  if (timeout_mode) {
>>                          wait_event_timeout(dp_priv->event_q,
>> -                               (dp_priv->event_pndx == dp_priv->event_gndx),
>> -                                               EVENT_TIMEOUT);
>> +                               ((dp_priv->event_pndx == dp_priv->event_gndx) ||
> Why the parenthesis (before and after)?
>
>> +                                       kthread_should_stop()), EVENT_TIMEOUT);
>>                  } else {
>>                          wait_event_interruptible(dp_priv->event_q,
>> -                               (dp_priv->event_pndx != dp_priv->event_gndx));
>> +                               ((dp_priv->event_pndx != dp_priv->event_gndx) ||
> Why the parenthesis (before and after)?
>
>> +                                       kthread_should_stop()));
>>                  }
>> +
>> +               if(kthread_should_stop())
> Missing space after if
>
>> +                       break;
> Is it possible to move the wait_event to the end of the loop and always
> run the loop initially? That way we don't have to check for
> kthread_should_stop() again.

no, since we have to make sure q is not empty so that we can proceed to 
service events.

bu ti thin we can use while (1) instead of while 
(!kthread_should_stop()) since we have add kthread_should_stop() into 
wait_event condition checking.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index c388323..5200a58 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -1106,12 +1106,17 @@  static int hpd_event_thread(void *data)
 	while (!kthread_should_stop()) {
 		if (timeout_mode) {
 			wait_event_timeout(dp_priv->event_q,
-				(dp_priv->event_pndx == dp_priv->event_gndx),
-						EVENT_TIMEOUT);
+				((dp_priv->event_pndx == dp_priv->event_gndx) ||
+					kthread_should_stop()), EVENT_TIMEOUT);
 		} else {
 			wait_event_interruptible(dp_priv->event_q,
-				(dp_priv->event_pndx != dp_priv->event_gndx));
+				((dp_priv->event_pndx != dp_priv->event_gndx) ||
+					kthread_should_stop()));
 		}
+
+		if(kthread_should_stop())
+			break;
+
 		spin_lock_irqsave(&dp_priv->event_lock, flag);
 		todo = &dp_priv->event_list[dp_priv->event_gndx];
 		if (todo->delay) {