From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C6BCC2D0A8 for ; Wed, 23 Sep 2020 16:21:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DAD072065E for ; Wed, 23 Sep 2020 16:21:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="i2Z2yy+c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAD072065E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baikalelectronics.ru Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=HCUpkETI2WlEQU49Nql5UMwAHJXH3yRyG8fwrkWMY98=; b=i2Z2yy+cJvl2kaFN8yatGB6dpK ZX5+xjBm9Q4FYTmxVO3zaPqA9s2QvJMXM+nPwnyMAomwKRrKhPeO2bCEpW7wNphnUvWWS73YGr1rs gMlumgzTtARve+7413dBDcggweZQ3eR1tpSxdYR+fD/GWO4H6qUotR1KBV7k4f3Oxpqtr0Kizrw9n NfY3nJ2nry7wav4hUaT3GI5on1iREx30ijTI/A11iTtynqoO+kBlMcO6AqSKH1C116ISTrwhOCQ3G Wjmr56oAbs4T+3bNMcddi0kaC2Yu0pYp1xHS1UmzaVqYZPe0AcqKebgf78dwjYZpGvd6VgcLNlxbk 6PbM3HMg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL7VK-0003Lv-Hb; Wed, 23 Sep 2020 16:20:26 +0000 Received: from mail.baikalelectronics.com ([87.245.175.226] helo=mail.baikalelectronics.ru) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL7Ux-0003E8-I4 for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 16:20:06 +0000 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 9AC68803073C; Wed, 23 Sep 2020 16:19:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Je9HNbMWeOV5; Wed, 23 Sep 2020 19:19:54 +0300 (MSK) From: Serge Semin To: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko Subject: [PATCH 0/3] serial: 8250_dw: Fix clk-notifier/port suspend deadlock Date: Wed, 23 Sep 2020 19:19:47 +0300 Message-ID: <20200923161950.6237-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200923_122003_904411_CEE1B7C4 X-CRM114-Status: GOOD ( 11.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , linux-kernel@vger.kernel.org, Russell King , Serge Semin , Alexey Malahov , Serge Semin , Hans de Goede , Andy Shevchenko , Pavel Parkhomenko , linux-serial@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hans has discovered that there is a potential deadlock between the ref clock change notifier and the port suspension procedures {see the link at the bottom of the letter}. Indeed the deadlock is possible if the port suspension is initiated during the ref clock rate change: CPU0 (suspend CPU/UART) CPU1 (update clock) ---- ---- lock(&port->mutex); lock((work_completion)(&data->clk_work)); lock(&port->mutex); lock((work_completion)(&data->clk_work)); *** DEADLOCK *** So the CPU performing the UART port shutdown procedure will wait until the ref clock change notifier is finished (worker is flushed), while the later will wait for a port mutex being released. A possible solution to bypass the deadlock is to move the worker flush out of the critical section protected by the TTY port mutex. For instance we can register and de-register the clock change notifier in the port probe and remove methods instead of having them called from the port startup/shutdown callbacks. But in order to do that we need to make sure that the serial8250_update_uartclk() method is safe to be used while the port is shutted down. Alas the current implementation doesn't provide that safety. The solution described above is introduced in the framework of this patchset. See individual patches for details. Link: https://lore.kernel.org/linux-serial/f1cd5c75-9cda-6896-a4e2-42c5bfc3f5c3@redhat.com Hans, could you test the patchset out on your Cherry Trail (x86)-based devices? After that we can merge it in into the kernels 5.8 and 5.9 if there is no objections against the fix. Note, in order to have the fix working for the older kernel all of patches need to be backported. Fixes: cc816969d7b5 ("serial: 8250_dw: Fix common clocks usage race condition") Fixes: 868f3ee6e452 ("serial: 8250: Add 8250 port clock update method") Reported-by: Hans de Goede Signed-off-by: Serge Semin Cc: Alexey Malahov Cc: Pavel Parkhomenko Cc: Andy Shevchenko Cc: Maxime Ripard Cc: Will Deacon Cc: Russell King Cc: linux-arm-kernel@lists.infradead.org Cc: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org Serge Semin (3): serial: 8250: Discard RTS/DTS setting from clock update method serial: 8250: Skip uninitialized TTY port baud rate update serial: 8250_dw: Fix clk-notifier/port suspend deadlock drivers/tty/serial/8250/8250_dw.c | 54 ++++++++++------------------- drivers/tty/serial/8250/8250_port.c | 5 ++- 2 files changed, 23 insertions(+), 36 deletions(-) -- 2.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel