Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp491046pxj; Thu, 20 May 2021 14:18:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw706TZ8AzsI/3iTVCIlIiHoqUsiRBMp6pY4CdPCVyjgeVQebUU0EY7Hq5ek1jWTYSw8gx+ X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr7125545edu.268.1621545504918; Thu, 20 May 2021 14:18:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621545504; cv=none; d=google.com; s=arc-20160816; b=nI9rWl4NseK4JK9YHRtFZ/muZHS/WEF1+DuYVPUZILKbA8fpbFQEgZfLe/QcEI1VCY jGNbpNhIMuv9GDXD13BEeemG1XvWa73bQA1Y+0e7X3pdl5EjxtF+XAuz3VE5dvWXFix7 gd/a1bj4UxpfeKL5z4NDVLU64qsrRnb7pVAkWBO6WPLmAdHlCywPy03BWwzyQ0GUhezX iSLqHp3lmTx9zY9+7Mdt2WCB0b4TK6UprD37KF8/7/f5Eq3j0zuqjq+yUFRp1vVp9u3O WSYa65rUsSkusEe53fUTmyzOHDm6kvwPhNjGP8sNMHvVWXPhfKtHIAvOAxa+bXvjQimh 0Q3Q== 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=ZU0RutWuz0JIt5goiou6x6wijSzSbHMo/K85XklXz4o=; b=qirQ84isfGcslhM8aGjnyVkfqsDmOolxsFqOJF882eKaswMZNlZdl1hY/bZUhMUSms GA9V7038VJFZsRGxMPE2VANKn0m05x1zwW2oeQvErscJ63M1d5aFckQ1IBiZn+P+7R+m YuhR9vUTjWZAtcjYQfvZ7B4T5gzKlIq6q2Zwac48oHm9PV1RuwIIEmJvnh3eld6vZKIU HwuRjHw+DtulPLBxUcWMSLJt/TgHYA3ZZCF18xGQSgLHXTPrOH3W79jao8kNjSL0WA4l 6rX3gGF8g8y7Bic3W7MCJYl8n3+mzV2iVl6c56YWPlAz98L/wVIRhtqTH/0EHYJVbuol 1s1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o7mrqCjG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr2si3830121ejc.274.2021.05.20.14.18.01; Thu, 20 May 2021 14:18:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o7mrqCjG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239205AbhETLC1 (ORCPT + 99 others); Thu, 20 May 2021 07:02:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:44958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237912AbhETKoG (ORCPT ); Thu, 20 May 2021 06:44:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB96861C90; Thu, 20 May 2021 09:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504620; bh=97YbxEaPhkNbzZCJI9dvPq3/hKx5CAZlYlzMlxBP67o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o7mrqCjG6wuaB8LXV7g+TPVkNQMwFbEQm2evhnWLhrSZMnBxgilVSDd0CQ1+mx0Ih cBYKnM9ESA/EmhXIoFpsz15pW4IDH/x+Hdb3vpxxmQTz+mfkMEP33qYOGHy7RNOxx9 rmcTSPCqZ6v7+QqHuJzpXQgXWnmwyrSVsIg18fGQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tomas Melin , Sasha Levin Subject: [PATCH 4.14 319/323] serial: 8250: fix potential deadlock in rs485-mode Date: Thu, 20 May 2021 11:23:31 +0200 Message-Id: <20210520092131.177575205@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tomas Melin [ Upstream commit b86f86e8e7c5264bb8f5835d60f9ec840d9f5a7a ] Canceling hrtimer when holding uart spinlock can deadlock. CPU0: syscall write -> get uart port spinlock -> write uart -> start_tx_rs485 -> hrtimer_cancel -> wait for hrtimer callback to finish CPU1: hrtimer IRQ -> run hrtimer -> em485_handle_stop_tx -> get uart port spinlock CPU0 is waiting for the hrtimer callback to finish, but the hrtimer callback running on CPU1 is waiting to get the uart port spinlock. This deadlock can be avoided by not canceling the hrtimers in these paths. Setting active_timer=NULL can be done without accessing hrtimer, and that will effectively cancel operations that would otherwise have been performed by the hrtimer callback. Signed-off-by: Tomas Melin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_port.c | 3 --- 1 file changed, 3 deletions(-) --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1527,7 +1527,6 @@ static inline void __stop_tx(struct uart return; em485->active_timer = NULL; - hrtimer_cancel(&em485->start_tx_timer); __stop_tx_rs485(p); } @@ -1591,8 +1590,6 @@ static inline void start_tx_rs485(struct serial8250_stop_rx(&up->port); em485->active_timer = NULL; - if (hrtimer_is_queued(&em485->stop_tx_timer)) - hrtimer_cancel(&em485->stop_tx_timer); mcr = serial8250_in_MCR(up); if (!!(up->port.rs485.flags & SER_RS485_RTS_ON_SEND) !=