Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp66709pxh; Thu, 7 Apr 2022 14:09:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtt6lNcDdE3zD/ROrPQpS4lfcIWQmRY0HRCHQij24E0fAw8cXNkl1xeveigiz7XN6f19CL X-Received: by 2002:a05:6a00:26ea:b0:4fb:358f:fe93 with SMTP id p42-20020a056a0026ea00b004fb358ffe93mr16182890pfw.78.1649365777421; Thu, 07 Apr 2022 14:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649365777; cv=none; d=google.com; s=arc-20160816; b=Stgb4RNoxIKUhOvU7RQ8aKjqf6hcntRj5uj3crpYtBzDCfU2kvUSZX2HhwOiSXHZea gHuG6BP+DiT922lMNr376ZbK0kiFNGJbYPI4kvRW0RUCYTrcREjsySX704w8pWWaxmjF csXwKhogJZLUgsgUOy+PLo7BzQvH45kijFKKK4cUuJMs//V9JaMaLpFePxOrmyfGJOCG 8MgjKVcIHP2xojLKMgWmFCP/3nX7eYulcODEfIVdYWHbAMLBrM9wX6AyLY5i70Ols11J wWgo6kuI2WWlH+SLUAHiBmTBzaJxXnGVE95wGTpui0XYUrQjKpHXaUhIrIrX/k808NgF fyhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-filter; bh=VIpddvV6P5OFhrrZnW0kspUd1MWvmCXatDW5RgsSO2M=; b=I/QkHaFBrx4Vb3ieZ1NDavYVZ6ycDD0fSLRchtIK/v7mbhy4k0z0aQqBEYwW1O33NP 4VB5jOqZ5LqnQGBDkKiS4wtnZpTNT5RR4N6g4WMAtAHguIkIbnQu2D3tjDRt58ieyClP uh18Q1vvrup+ik4Y0OpYwLyH/fhuRjYFhXvkKA/89rkPcQTLdIUZlxAyTpK0aLXzGcws IRHO0EnsREd7fDd30PVDuPPyCG4+1Hwfb+SxH2wV4ObYxfomrmE8AB5alW3kN6k9PRNb U9mllSljyNdxVz5qfQbeGk/rcIqR//efs8xL04GAlLzuG1ekWctpugU2R4V/KtbtAk0h gP3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g15-20020a056a001a0f00b004fa3a8e0013si21845360pfv.202.2022.04.07.14.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 14:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 65D55421336; Thu, 7 Apr 2022 13:02:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242883AbiDGJop (ORCPT + 99 others); Thu, 7 Apr 2022 05:44:45 -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) X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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