Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp582917iog; Mon, 13 Jun 2022 08:34:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqruO9a/h62Me+0wzr1DmRjODfkOpP9jEo+Ywk6hAkAkBVVRzpcw80zjCtM2UDmyy3g+JQ X-Received: by 2002:a17:90b:4acb:b0:1e8:67df:6c61 with SMTP id mh11-20020a17090b4acb00b001e867df6c61mr16474581pjb.224.1655134449701; Mon, 13 Jun 2022 08:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134449; cv=none; d=google.com; s=arc-20160816; b=Nt4EgXPhxxinA24bK+NcxMWVdcGxQdeiawie+PMq8ojYIVRFaUVoeyIR0L/H9HVXTU TJZAsCTdyIU/rilHicKh49BDqE47nD2zJNf/jnX62uZOCWO0MWBgQg8UB2wBBRUd2CCD xjZp7GIiSKEn5s2fMAhknyH3d7IS59VL+o2+lrnRvqD4PI/bQ7jy4yZ5EUg2aHA0eMaI iu4hOx9EP9Fpi4XWpYrWnohgv+NseMHqW9sBFYYJxtDOLcshyOd9CnTLTzSiVBYvlcpw a5RK3lrXlC8cNUj8Io4JV35XflBeThzUOFDDTJZbueWTPyDntm00mdK7OrGSXDpb0ok8 oBoQ== 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=Z2jKZCiyuP7N2//wzL84nudYZom7P5rlMdKc4/NOQAU=; b=Isb40v/EWi33o1KBnrcck9EpQH5mOhC9ZdftkZprjr8nakl7eMvqnSP+g8pdMG9h1V xTlNvMLIuFtke2Lj17GCaCffe6RFlaJXfY8zCU6Uzrd6Xr78/mgmJdp6Y6wxMXVuE2RQ h5dAYpGafU6aFjE7JaBLX84tfot7OJS0jjy+oCco7GfXYrWVKVbnKgWKXhMYRcwmsP/U wX/LCYGDWkIQfzZaEsTTgMndos3OzChIWLHpCysswlCgkopdPvnaSpbgTIZfznvQQLVf 48Us+shDyQqZ0O0PKkzeYdQYnF1LmDTqXCgvOn4mYLjOCW8eCLIJb+SiQTuhPU1bRhkV a1yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IhQdUgDN; 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 t16-20020a170902e85000b00166496b7274si10677254plg.186.2022.06.13.08.33.55; Mon, 13 Jun 2022 08:34:09 -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=IhQdUgDN; 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 S1352060AbiFMLKZ (ORCPT + 99 others); Mon, 13 Jun 2022 07:10:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351885AbiFMLFL (ORCPT ); Mon, 13 Jun 2022 07:05:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51CBDE7; Mon, 13 Jun 2022 03:34:35 -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 ams.source.kernel.org (Postfix) with ESMTPS id 10AD4B80E93; Mon, 13 Jun 2022 10:34:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DB20C34114; Mon, 13 Jun 2022 10:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116472; bh=x3KhVWC0ll/qL0hqYrVnjfMXp95Ww5ZMIt+AkkTdFUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IhQdUgDNf4vYE7E/m2Iz1JaohBrIFYG8db7LD/Inffk0TUtiYtOSRdE4weI47tf7s LdvN87roJjowIhGk0foBKLKeyqgKf6MxUcny30LPkkbBV7Yp4QWW4c6k2KurjUuaoN kJvMJfg0KlhDqR6PIWBT/JM8/RisJ/AAtOe/UjbE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Sasha Levin Subject: [PATCH 4.14 187/218] drivers: tty: serial: Fix deadlock in sa1100_set_termios() Date: Mon, 13 Jun 2022 12:10:45 +0200 Message-Id: <20220613094926.286902618@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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=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 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 fd3d1329d48c..68eb1c9faa29 100644 --- a/drivers/tty/serial/sa1100.c +++ b/drivers/tty/serial/sa1100.c @@ -452,6 +452,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); @@ -482,8 +484,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