Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp637154iog; Mon, 13 Jun 2022 09:37:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzN7IpuiLdj78H91HOtNxiDMekci2RG0AwVjy3x5ggTIxKkRTreRaLrvUiaXArVhFhkz8RE X-Received: by 2002:a17:906:656:b0:6f4:ebc2:da81 with SMTP id t22-20020a170906065600b006f4ebc2da81mr555973ejb.757.1655138237534; Mon, 13 Jun 2022 09:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138237; cv=none; d=google.com; s=arc-20160816; b=AQcbSxbqjRXjJtUXjtP535f12ukuaJwK9OPudHA0gYWfIBG8ytbaZXkjI1DuLSOuTW RK8sXX4moUXSH47Qs4o2wohSdMiofMeGvvYlrWXnsnpJNU6R9puLHZCRswZj+yGtazR+ Dnb1BTBhabT/AzIFLHLEx0ENTKzoNOM5omp2QJJg6Kq0OVdyZF7d1DU+NTCBOZSy6liD /DLvn5QHD486wb5k66VW8jIrFrOYglkI4Q088FOQORMjCLd+cgCYFey42aBm0KWmtMOT fVefRWHFzgEzPgj+zIxXeLAxQYMvyv3v+3h9MeW5oA1NHYr4hvDo36gR+8jyg3Ni/fhk o6JA== 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=Yz/VbYZHNh677Oyl9RSC+E3WeF0tSXzhVZlUHDTnUM4=; b=IHF8GJnDrLGAv45mp/F3gQjM3z3qLxWh5jKhkS5WaA05Mc2kJnfoWE7v/cOi1uwDc9 m3wonguWfKvuN6k2bXtaPzHwwA64VQiC0l1RlRMcDMRd2Gri0vzQaD2KcP1Y0z0CzKOq MfmSYT+RjCfRH+tMtcf69+XvTDMqSCsP7HmX5ypE+1H/Y+nGfHTWwhWTlrZw25caSaOk B40+LL4+wiGhIvx+KTUj61Z7RjChC05bPPkVQ1wkcHml7cECfpRagsCNLzIvfmhdUdYP ckTFp+WXwmfIynMIEsiNcetbJ8Dqjj+/lm2vlfIyAeZmxxnuoQwzFS+PD2LGROctVxPg hzSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zhy8OVpi; 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 ji21-20020a170907981500b00717f2a08a2csi4578232ejc.169.2022.06.13.09.36.52; Mon, 13 Jun 2022 09:37:17 -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=Zhy8OVpi; 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 S1379874AbiFMN7s (ORCPT + 99 others); Mon, 13 Jun 2022 09:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380258AbiFMNx6 (ORCPT ); Mon, 13 Jun 2022 09:53:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 904D27DE1D; Mon, 13 Jun 2022 04:34:20 -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 2BDE7612D0; Mon, 13 Jun 2022 11:34:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3898AC34114; Mon, 13 Jun 2022 11:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655120059; bh=FW/I7BVkoeE8In3t2dtd44ke8+0eARmdPhzZXUroxaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zhy8OVpiJjt5Uy7+J+hqv/f472BEzXwRoztJsoB2e/Zf07xGD051ncBsukVaoBapx BOGECYHsMSmpqUN+lpvXhXQFwJt6rSVCo29KgIgb0VFwp6rD1jAZypxxhvS1Ajn61o ALk6JjiTFJ25FFYfy7FypJHgBKecA79im9ZkdGdk= 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.18 236/339] drivers: tty: serial: Fix deadlock in sa1100_set_termios() Date: Mon, 13 Jun 2022 12:11:01 +0200 Message-Id: <20220613094933.815191697@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094926.497929857@linuxfoundation.org> References: <20220613094926.497929857@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 5fe6cccfc1ae..e64e42a19d1a 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