Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp288228pxb; Thu, 7 Apr 2022 05:51:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHXMVKZFUponW2+onPgCrScKTsrtfx3F2yJHu7Iu2DP6E4YHpUu9FPg9wsDmRnGpJQ5RMk X-Received: by 2002:a17:902:7247:b0:156:9d3d:756d with SMTP id c7-20020a170902724700b001569d3d756dmr14030405pll.6.1649335884057; Thu, 07 Apr 2022 05:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649335884; cv=none; d=google.com; s=arc-20160816; b=ZmWOQmpNWMZorqGvX05UsyDDDA0x6gqY4LJgQ52Vz3EabNEB4SD1lUBCqjnnyogjLj rjx5M6gB9K4eVhFV7UsWcphxc0qgHxbmuCw8/tthA6ASdrrCBlkdqBEoZPRWjFr3rUoy Au6yhpzrIK6WhEc1f/5u3wVPz/vDaS36r4k+wCz3BhS3jAi9dC2GSG75OUZxsSsNFtNh O0e3KH4ed7Lrz3d7m9a5TFBX/GsxUcXaeXvXN6B5g4GW7w5EYUfmbVMVciBRQngaCtx2 Qv/Er3f3qia19D2t5QGacUx2gj8FFm9vaUDZh4CUuJyeDnTJaoYSu4NhHxPTuL+w8cF3 Oiig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=Kk2DPEL4F1gvqGcguJHKrj/htSD2+T+nh9Fr0VvOMh4=; b=dKCbo/Lyq5Q6S25latWPuHUzhNOzJ0RhCUcACJ+vyB2G+9ngJVzRL33o7obMvODyfw IeI3wr0GYuDABo2ceL+y1kTDTVANl8SCvMiJFLj4eHkj8w/OWCutbjiSA+UtU/GHX1/P lua240QD9IqaDpBusUptjM1qPrY5OJBgVZFjVuScqBxKQHQlCpN/gacWlYhNQTBpf0JZ 6TiKnyzUcdOjnVpv97C0IP/6kHE20zVl570L2j00zN8vAqPtiN4fnaICVmaw649RUK+m 9lc4Gqs0rjFbw8eakHuqIh7UFx+oTTJNwJBUAe4GVPe1ltdZMYkoYl0tI+77nbq6Y9HY sW0w== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a63f943000000b00398ecc4479dsi16414945pgk.139.2022.04.07.05.51.10; Thu, 07 Apr 2022 05:51:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241409AbiDGGkn (ORCPT + 99 others); Thu, 7 Apr 2022 02:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241361AbiDGGkI (ORCPT ); Thu, 7 Apr 2022 02:40:08 -0400 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 73BA55A0B5; Wed, 6 Apr 2022 23:38:06 -0700 (PDT) Received: from ubuntu.localdomain (unknown [10.15.192.164]) by mail-app4 (Coremail) with SMTP id cS_KCgA3rqW8hk5ipp_iAA--.33196S2; Thu, 07 Apr 2022 14:37:52 +0800 (CST) From: Duoming Zhou To: linux-kernel@vger.kernel.org Cc: chris@zankel.net, jcmvbkbc@gmail.com, mustafa.ismail@intel.com, shiraz.saleem@intel.com, jgg@ziepe.ca, wg@grandegger.com, mkl@pengutronix.de, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jes@trained-monkey.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, alexander.deucher@amd.com, linux-xtensa@linux-xtensa.org, linux-rdma@vger.kernel.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-hippi@sunsite.dk, linux-staging@lists.linux.dev, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, Duoming Zhou Subject: [PATCH 11/11] arch: xtensa: platforms: Fix deadlock in rs_close() Date: Thu, 7 Apr 2022 14:37:48 +0800 Message-Id: <9ca3ab0b40c875b6019f32f031c68a1ae80dd73a.1649310812.git.duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CM-TRANSID: cS_KCgA3rqW8hk5ipp_iAA--.33196S2 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1kWFy8CFW7KrWfAr4DXFb_yoW8Jw4xpF WUKrnxGF4DWrWjg3WDta1DWryUZa1kKF1UJr98K3yUZ3Z5XryagF1xtw4rXFW7tFs7Wanx ZF1vqry5AFsrZr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvG1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW0oVCq3wA2z4x0Y4vEx4A2 jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52 x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWU twAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY 0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26r4fKr1UJr1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa 73UjIFyTuYvjfU5JPEDUUUU X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAggNAVZdtZEcMgANsK X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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); } -- 2.17.1