From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BB90C433FE for ; Tue, 3 May 2022 16:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239221AbiECQQm (ORCPT ); Tue, 3 May 2022 12:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239216AbiECQQi (ORCPT ); Tue, 3 May 2022 12:16:38 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A895327164; Tue, 3 May 2022 09:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1651594384; x=1683130384; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=9FGMVgF8GLGaAcGv/yGifqNyiG6ez9qf2269SDYd8Uc=; b=D331LDeqrGr8UuZKYQcxcTDV272NmmudzC3lKV+OGrAlOWrOHd6mLrHy zDqM8XMZsnIyzkmoNLtXghUJa4AFAoTHtR9oqKauDFa67Yx8qJwop00mm Qvf4R0HmrVZnwG617m/ZHrBgsk2Gif9VwoAqeb6adh0PW0lNATJvTH/Qk k=; Received: from ironmsg07-lv.qualcomm.com ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 03 May 2022 09:13:04 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg07-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 May 2022 09:13:03 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 3 May 2022 09:13:03 -0700 Received: from [10.134.70.75] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 3 May 2022 09:13:02 -0700 Message-ID: Date: Tue, 3 May 2022 09:13:02 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v2] drm/msm/dp: fix event thread stuck in wait_event after kthread_stop() Content-Language: en-US To: Stephen Boyd , , , , , , , , , CC: , , , , , , References: <1651532668-18873-1-git-send-email-quic_khsieh@quicinc.com> From: Kuogee Hsieh In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> Fixes: 570d3e5d28db ("drm/msm/dp: stop event kernel thread when DP unbind") >> Signed-off-by: Kuogee Hsieh >> --- >> 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.