Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4836816iob; Mon, 9 May 2022 02:49:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjnO5kWQz6mfytCSJnQnwLvPIj4HUEDtrOT5inkP/+8gTahoL5k7ocz9UIacT4uOm8837X X-Received: by 2002:a05:6a00:1808:b0:50e:eee:d78 with SMTP id y8-20020a056a00180800b0050e0eee0d78mr15437470pfa.81.1652089765829; Mon, 09 May 2022 02:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652089765; cv=none; d=google.com; s=arc-20160816; b=JqP1MJUl8NRECtnd06Y/hCEetJKraVSGkxI0/GE0wyat0UHnANBiFjU30pURJ+LZAB aM5l1kHM1JCuJlGMNWLRm1Hwr7FmzbGUWsweSvEgbpZs2rcpw5vnEfyXCI7JMthdEKZw MPw39v8cUB8JEJYj3ILwfMpH+bFec4COAUOeqPJYrK/G+m+LKQyx56tiGBgwmT/B1r1p 6mjbLi1I5nLf26nYwAfM38fHwYl349vSk7+hqS6L4m98ZV6D3LltRg4G1XuxOcHKR7l6 K5rTDzUZIMwb7undAdkWT6Hczz+7XdH0JPbwm+tUno2HGOiG1PPeBEhHq57DQny3JbbT 4Lxg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D+6J1tM/KX+B1Dixkhn39VO+ZubUPv35zshBkeB6sjA=; b=ZVPu0F9+jobFIy4ynkOgUnVvwmKnPMhjoRUp/GrgJicZIX5/6Ef2CnCeUzpEjWzQpT fFGxZuDEsfm/vD1wnI9Jf2KzgIhEiR7wDcLQJ5b4oQUtVVXAQHa5tcVmj/z3Gw+lSpjN y0dFpZbzsS8v8hjwv+5apRJTMR+Pg0UxcDRgQzZUDIB3r93ukLGLwvYT0XZO/E6LBdEh YrVoExhHKhXPWcUotHKpT1klon2FUvD7L6ccjNyAntWnVKFR6CpCMCgoX2rsRLW5QFaz +/PSpdHBwOsnWAo51BRF4h8wo2IZWVGRBKycDzMoKnpee+sBD5pUH3xBtQz949Ml5Om1 XBlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lavSqlHe; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m1-20020a1709026bc100b00153b2d16537si10397245plt.319.2022.05.09.02.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:49:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lavSqlHe; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 059C9227CE2; Mon, 9 May 2022 02:34:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358560AbiEDRel (ORCPT + 99 others); Wed, 4 May 2022 13:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355853AbiEDRIx (ORCPT ); Wed, 4 May 2022 13:08:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FAED49FA5; Wed, 4 May 2022 09:54:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6284061899; Wed, 4 May 2022 16:54:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7C09C385A5; Wed, 4 May 2022 16:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683277; bh=U7F8eZYEpVTSmb/J39TUf2NGEuMLVkqIGrd2moRZY9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lavSqlHe99BIe9cu1Gz+Ba0Tup3OL4UCtCmNDE6zrXFlTAvye4RkwcOOf1tCysYQZ GKVshGeF3FhwK/1ZLQMJMbnrZHlslC0HxsvZVZ+J/PanndhPgvIuN5O3qcf61labS1 HP3Xd0k8pSF1r3mYkkdBMkeNxbbKen1Zcxxem8D0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Max Filippov , Sasha Levin Subject: [PATCH 5.15 130/177] arch: xtensa: platforms: Fix deadlock in rs_close() Date: Wed, 4 May 2022 18:45:23 +0200 Message-Id: <20220504153104.791464567@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Duoming Zhou [ Upstream commit eb5adc70754d26a260f8b42d39db42da0d0af500 ] 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 Signed-off-by: Sasha Levin --- 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.35.1