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 53D6EC433F5 for ; Thu, 7 Apr 2022 09:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243880AbiDGJor (ORCPT ); Thu, 7 Apr 2022 05:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237161AbiDGJok (ORCPT ); Thu, 7 Apr 2022 05:44:40 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F38718D9AD; Thu, 7 Apr 2022 02:42:37 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru C1ADB20CD431 Received: from LanCloud Received: from LanCloud Received: from LanCloud Subject: Re: [PATCH 11/11] arch: xtensa: platforms: Fix deadlock in rs_close() To: Duoming Zhou , CC: , , , , , , , , , , , , , , , , , , , , , References: <9ca3ab0b40c875b6019f32f031c68a1ae80dd73a.1649310812.git.duoming@zju.edu.cn> From: Sergey Shtylyov Organization: Open Mobile Platform Message-ID: <1195e776-328d-12fe-d1f8-22085dc77b44@omp.ru> Date: Thu, 7 Apr 2022 12:42:31 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <9ca3ab0b40c875b6019f32f031c68a1ae80dd73a.1649310812.git.duoming@zju.edu.cn> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT01.lancloud.ru (fd00:f066::141) To LFEX1907.lancloud.ru (fd00:f066::207) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello! On 4/7/22 9:37 AM, Duoming Zhou wrote: > There is a deadlock in rs_close(), which is shown > below: > > (Thread 1) | (Thread 2) > | rs_open() > rs_close() | mod_timer() > spin_lock_bh() //(1) | (wait a time) > ... | rs_poll() > del_timer_sync() | spin_lock() //(2) > (wait timer to stop) | ... > > We hold timer_lock in position (1) of thread 1 and > use del_timer_sync() to wait timer to stop, but timer handler > also need timer_lock in position (2) of thread 2. > As a result, rs_close() will block forever. > > This patch extracts del_timer_sync() from the protection of > spin_lock_bh(), which could let timer handler to obtain > the needed lock. > > Signed-off-by: Duoming Zhou > --- > arch/xtensa/platforms/iss/console.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c > index 81d7c7e8f7e..d431b61ae3c 100644 > --- a/arch/xtensa/platforms/iss/console.c > +++ b/arch/xtensa/platforms/iss/console.c > @@ -51,8 +51,10 @@ static int rs_open(struct tty_struct *tty, struct file * filp) > static void rs_close(struct tty_struct *tty, struct file * filp) > { > spin_lock_bh(&timer_lock); > - if (tty->count == 1) > + if (tty->count == 1) { > + spin_unlock_bh(&timer_lock); > del_timer_sync(&serial_timer); > + } > spin_unlock_bh(&timer_lock); Double unlock iff tty->count == 1? [...] MBR, Sergey