Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp401475pxb; Thu, 21 Apr 2022 02:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0SnTmbCcN1ZiMDkVDqDWBX17fBPQFqaxtm8w/0WilPsuozI1CevM+uQQnFNLTxeYYOIwJ X-Received: by 2002:a17:907:9485:b0:6db:331:591e with SMTP id dm5-20020a170907948500b006db0331591emr21948821ejc.478.1650531862813; Thu, 21 Apr 2022 02:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650531862; cv=none; d=google.com; s=arc-20160816; b=r4gnbJNp9vz1BAWJ1+iNCsiBftZFQoa3VTG+5uJgw/YerNofGUv8i1/qmBzSfBgpS7 j4YMRiUPBHbSCXOOojROiwEEUgtuUbaqAQBvBt1+7LITgDZn2lrZ+ZgzCb/3vwBPDMhS ZgKhIYL4cnyAS0xxk9ZwROn3qO6+7RPyDtMzzTVy3rchh/I6VafgQA4tGQPXQlbEw4nM xPQi/wFfBqBMVN0wq7E+IzdB5Pqf8IsnFpjSOazSfVD3k3mkyeVSm2u8Ae3Fm1Fv0mWz RHsxff5XDXZcJkDaQiynH8gWNqAQeIuntqVYtifT3cvP9cHU1r31LLInvpwXZN+dlxZD jEhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nrmZN1YGOXwt96xOgDckyKdEp0sX0UQnyV38Md8fDGs=; b=ixwbItzbt54I6o3D06VB7BWYHWXdP7e6Yd3tNgxm/WKe5xnYnBHHnyJOHbLBTExq8+ tvF7HKnm05SqDNEmr82EyO7mfgGNvuXiFmiGiU5jf1/z4V2HmGKuVJQ7xWzubyylokhm QN3lv94RxwZnycn6allG7PdTkqiFsQQjV7X0Y7RIhFfiDw4XTRGFA96GUQZym9DMVpr5 LRwWp8EPPulVYPgsx4Vrcav9sshtiyoXVNLpHc4+O4NXC7nAwiTbpRjFiZZG/6MdVZv6 wdY8EqzGkmxmUUdey+ocm60VvFY4osjAkYuwUyGdHCGA7dTNK43EjJ1y3rqdGT7INH70 nMww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bHBqeh+C; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b25-20020a170906491900b006e7f47d22a9si3722058ejq.434.2022.04.21.02.03.58; Thu, 21 Apr 2022 02:04:22 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bHBqeh+C; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239177AbiDTGTN (ORCPT + 99 others); Wed, 20 Apr 2022 02:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359480AbiDTGTI (ORCPT ); Wed, 20 Apr 2022 02:19:08 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4870393DB for ; Tue, 19 Apr 2022 23:16:23 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id s14so900970plk.8 for ; Tue, 19 Apr 2022 23:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nrmZN1YGOXwt96xOgDckyKdEp0sX0UQnyV38Md8fDGs=; b=bHBqeh+CrW9h20RGBZXkWpQvf8YwJDwRfjQbGqhVknLEACTwHhEFaqmd+4l3Ptfxza EH+vqfFNLManK+QQZpss9gjUc5sa4qLUw58mojbTvaS0INZipA6XoRm/Ya7F4FtG7Wit Uyf2UqDky9RIWj9xOQdq/xcxbvdoPRvCbyR6D81bsw9ihcmPykjPgTGlB3UpVh7UYSXO L0KtEzQD8e3StZ862FvNcchsX569ksD90vwg3fFJCQk/TdPVzP8SnmiTfHqcoTE5+8n8 574kbXlWpTmaISmD9nVClw4EETxiiNS1Gn++gl0sF7IFhWKNnxDA/FJYeilTaX2VXWAp ThDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nrmZN1YGOXwt96xOgDckyKdEp0sX0UQnyV38Md8fDGs=; b=GZeemRLiQZo7i4zfiDaxB4bdvR9X1iSNOHwTaqE7xqrtPS2CHRg8IJMFbGFcLupztm rE8p+U+uwywdLow6LoObK7d1G4VcCz2PBHx0S5a3gOY0wDzHKi8+w4gEVJ+wEWDs8wBd 5HFgQidLNQ/KyUWn3ecYMLVDzoE0YlagdNrmXfD2Gxbf3RZK+vxg4hjhV6mCLS+BX93b Glxyo3mjAXrCJpduTvKqy/gsA2a+iW1aUYKWcoFa6Jm9l6lPFqr4VPY/madXkk0pSIX8 8dpBRXc+4CfyXk4DhCjxIwrsEB3Yc89AwVxGhxAwPeO+YTor1KQQ916M7d1R+qkd4EET hd9g== X-Gm-Message-State: AOAM53331hKhhtk0Ix1mnww30F7RsSmFMMfCmmvIw2Qal9P8SPdH6nU7 LVavA02pjcnHYUany/DLTTc= X-Received: by 2002:a17:90b:4d86:b0:1d2:cd59:d275 with SMTP id oj6-20020a17090b4d8600b001d2cd59d275mr2589745pjb.119.1650435383187; Tue, 19 Apr 2022 23:16:23 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net ([2601:641:401:1d20:daec:60d:88f6:798a]) by smtp.gmail.com with ESMTPSA id k22-20020aa790d6000000b0050a765d5d48sm9798778pfk.160.2022.04.19.23.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:16:22 -0700 (PDT) From: Max Filippov To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, linux-xtensa@linux-xtensa.org, Chris Zankel , Duoming Zhou , Max Filippov Subject: [PATCH 2/3] arch: xtensa: platforms: Fix deadlock in rs_close() Date: Tue, 19 Apr 2022 23:16:10 -0700 Message-Id: <20220420061611.4103443-3-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220420061611.4103443-1-jcmvbkbc@gmail.com> References: <20220420061611.4103443-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Duoming Zhou 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 deletes the redundant timer_lock in order to prevent the deadlock. Because there is no race condition between rs_close, rs_open and rs_poll. Signed-off-by: Duoming Zhou Message-Id: <20220407154430.22387-1-duoming@zju.edu.cn> Signed-off-by: Max Filippov --- arch/xtensa/platforms/iss/console.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c index 81d7c7e8f7e9..10b79d3c74e0 100644 --- a/arch/xtensa/platforms/iss/console.c +++ b/arch/xtensa/platforms/iss/console.c @@ -36,24 +36,19 @@ static void rs_poll(struct timer_list *); static struct tty_driver *serial_driver; static struct tty_port serial_port; static DEFINE_TIMER(serial_timer, rs_poll); -static DEFINE_SPINLOCK(timer_lock); static int rs_open(struct tty_struct *tty, struct file * filp) { - spin_lock_bh(&timer_lock); if (tty->count == 1) mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE); - spin_unlock_bh(&timer_lock); return 0; } static void rs_close(struct tty_struct *tty, struct file * filp) { - spin_lock_bh(&timer_lock); if (tty->count == 1) del_timer_sync(&serial_timer); - spin_unlock_bh(&timer_lock); } @@ -73,8 +68,6 @@ static void rs_poll(struct timer_list *unused) int rd = 1; unsigned char c; - spin_lock(&timer_lock); - while (simc_poll(0)) { rd = simc_read(0, &c, 1); if (rd <= 0) @@ -87,7 +80,6 @@ static void rs_poll(struct timer_list *unused) tty_flip_buffer_push(port); if (rd) mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE); - spin_unlock(&timer_lock); } -- 2.30.2