Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp585391iog; Mon, 13 Jun 2022 08:36:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1trJZ3BGCxFFcgCvXUk/jVpHGcOpMWsorLY2n4a4jHy6tTtKMzqZLBhNG6/9HjOVC+HNRGh X-Received: by 2002:a17:902:cec5:b0:163:fa31:9438 with SMTP id d5-20020a170902cec500b00163fa319438mr345503plg.85.1655134614604; Mon, 13 Jun 2022 08:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134614; cv=none; d=google.com; s=arc-20160816; b=T8AQB98ZGZTxEdw5ZFIUaAdEkRJvp5CaFyOuNUienNiaBXkW/peFkpUxq3O2xt42i7 PRHa+u98HoU3idCD5l548/vtG4G4JS6F2wiINueUVrwceOKGT/Hm58zLud31D6eQMEY7 c7Eo712VkrzyT+7QtvWW6IktWtiw+Yc8GlEUql4vlxMMODxwNNOTkle2a/0ykCpmSaXS JMUIb5nT2lCb4bSjyfGpuUlkTRZkP2vJUKYSzaCRudhSxTRxx+x61NCUoKqTdedXZe44 fLgpaLFXAdmcv0a5rHhcKQk21cWDFwe17Masla5eoCADu3i2SZO48n70PCOBcnKhCZQe IyEw== 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=yqTbnyt6jO40wL5aaSm3q0UxuI/HAS0vG91pwbp+sN8=; b=ExWW4dYziKEp1/yKr1CV7RLop1h6CnBzmy8u3s7SSXojn+1VkzRdGipPdTlGY9qqrh +HZD6sFBUSTLWZvf9FSlHXmjmzjpSZmk5aWs2rye+a2DXzz711+MZCOB+94rJemCr8Re AdFee/MB7g4nIg0EJCFngwL36jUmHdJoSERUACMInWTLwQhmbro9fiBYNH5YFQ6bOTDA 4hxYYG4MtNcuCilly6umy80b1NZEUxNumfP0QZEYBUJ2xesPuWrLTlucfR8fOGI84Smc yyjvmnThErm69zBZS+mDxiWYgrunil/kgEsSVhutOKpnhORysQ58NkeuWNvOlAQ4pvgB HC3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e6Gsg2pD; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i62-20020a626d41000000b0051c3dcbe8ffsi9035515pfc.373.2022.06.13.08.36.42; Mon, 13 Jun 2022 08:36:54 -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=@linuxfoundation.org header.s=korg header.b=e6Gsg2pD; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359669AbiFMNQR (ORCPT + 99 others); Mon, 13 Jun 2022 09:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359292AbiFMNJq (ORCPT ); Mon, 13 Jun 2022 09:09:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FEB81FCFC; Mon, 13 Jun 2022 04:20:01 -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 0A90860F2B; Mon, 13 Jun 2022 11:20:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16BE4C3411C; Mon, 13 Jun 2022 11:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119200; bh=KPi+PDnXetNqe8k0T50PiyVPHdsSkTnx9m4diIFuL3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e6Gsg2pDc/0ChDZ3E+zaOVStERshRlPcW4MM7xHQTKsWIRKV084SXsZ7nNXolSihc I1UO/HaWGpMhSS2+5rvJLapQOlqt7DaiWVwaVJF7hCfcumjr+SC3gSR8X7h7Xa9vrY T5fp7CsaSstA0aRYxM8uIUeBkeT9zyFoHAg9fRhg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Sasha Levin Subject: [PATCH 5.15 177/247] drivers: tty: serial: Fix deadlock in sa1100_set_termios() Date: Mon, 13 Jun 2022 12:11:19 +0200 Message-Id: <20220613094928.323142816@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@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=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 62b2caef400c1738b6d22f636c628d9f85cd4c4c ] There is a deadlock in sa1100_set_termios(), which is shown below: (Thread 1) | (Thread 2) | sa1100_enable_ms() sa1100_set_termios() | mod_timer() spin_lock_irqsave() //(1) | (wait a time) ... | sa1100_timeout() del_timer_sync() | spin_lock_irqsave() //(2) (wait timer to stop) | ... We hold sport->port.lock in position (1) of thread 1 and use del_timer_sync() to wait timer to stop, but timer handler also need sport->port.lock in position (2) of thread 2. As a result, sa1100_set_termios() will block forever. This patch moves del_timer_sync() before spin_lock_irqsave() in order to prevent the deadlock. Signed-off-by: Duoming Zhou Link: https://lore.kernel.org/r/20220417111626.7802-1-duoming@zju.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/sa1100.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/sa1100.c b/drivers/tty/serial/sa1100.c index 697b6a002a16..4ddcc985621a 100644 --- a/drivers/tty/serial/sa1100.c +++ b/drivers/tty/serial/sa1100.c @@ -446,6 +446,8 @@ sa1100_set_termios(struct uart_port *port, struct ktermios *termios, baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); quot = uart_get_divisor(port, baud); + del_timer_sync(&sport->timer); + spin_lock_irqsave(&sport->port.lock, flags); sport->port.read_status_mask &= UTSR0_TO_SM(UTSR0_TFS); @@ -476,8 +478,6 @@ sa1100_set_termios(struct uart_port *port, struct ktermios *termios, UTSR1_TO_SM(UTSR1_ROR); } - del_timer_sync(&sport->timer); - /* * Update the per-port timeout. */ -- 2.35.1