Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp928722ybh; Wed, 22 Jul 2020 17:34:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwB0eVf8SKtsx/AEYphJ8d1pJQfNRvwugBL4WIlg2ofGoyxdy7g4rrpEZT2oK7tgQgqFPeO X-Received: by 2002:aa7:cf82:: with SMTP id z2mr1796942edx.15.1595464482583; Wed, 22 Jul 2020 17:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595464482; cv=none; d=google.com; s=arc-20160816; b=rvISkrqgwOVFupZKv9mM0p61UzARMQ15OJ/CrkfP6lc8vZZNs9G+svZtHxXbHv6y7l NhyLmL7zcLSyRLvEuhImeJEY6yBZu0YlN7zNrkPHPRxmnzRPg55YZaxUi4KmEE3Ni6Ic 2KRPI+BSumAxpszTYNyck4f7R/F3XuXC1Ris1Z2C/blSjXsuycDc7fR6vSd21lfoKkXB qdV+cIkTZqntrYm9284oD5Lu+vLVgxeYnbndEm1Z7BuN7/CXSacRV4UMW8AH87m6eXC+ pqSU9+qRT+G2JicJzanWBylPQx/oF2jxLiHxKkGGY/8mGUAUNAhZ04R57jFs7lOEf9go pU4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KrYHyHQcyJ6j5ygeHmajYHaHeG1ApyfHrP8ZLX5Ig5g=; b=Hh+k2xNESQpP3yz5NT5FYdS65bHzSsjZ4wiD+i4Z/pvPpyX761Q45vGKsMRypGEp3I yiQ0Jtr0OXjLGokj8OWj2/rMkbCVpcdDXwmQ3HN3GgR8iK1zmt8m6Q/mychKubBwrVjQ KryLt7C28ophnOfsjPlt5Pwk3F8rsZ7g0JXCgDK68AwrVzrhegrOBi04OyJL7J6+g+S+ mnWBWvXLLOhaELHmyj3FMFY9gvHXaUh7AON7Nc8xPBNlngFGnH4vUGC2O77V4AAjE3lt EOobPAYFinVrZN56A1VfXw9Xag+PtAficm7PJHrYZMgPWPFQQWdja3lCtqJvjhvovSIS bpsg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f1si945193edm.601.2020.07.22.17.34.19; Wed, 22 Jul 2020 17:34:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733267AbgGWAeM (ORCPT + 99 others); Wed, 22 Jul 2020 20:34:12 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:60720 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729423AbgGWAeJ (ORCPT ); Wed, 22 Jul 2020 20:34:09 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id 521218040A6A; Thu, 23 Jul 2020 00:34:01 +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 dmfSIOayfHoF; Thu, 23 Jul 2020 03:34:00 +0300 (MSK) From: Serge Semin To: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Andy Shevchenko , Maxime Ripard , Will Deacon , Russell King , , , Subject: [PATCH v9 0/4] serial: 8250_dw: Fix ref clock usage Date: Thu, 23 Jul 2020 03:33:53 +0300 Message-ID: <20200723003357.26897-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Greg, Jiri, Andy. We've missed the last merge window. It would be pity to miss the next one. Please review/merge in the series. Regarding the patchset. It might be dangerous if an UART port reference clock rate is suddenly changed. In particular the 8250 port drivers (and AFAICS most of the tty drivers using common clock framework clocks) rely either on the exclusive reference clock utilization or on the ref clock rate being always constant. Needless to say that it turns out not true and if some other service suddenly changes the clock rate behind an UART port driver back no good can happen. So the port might not only end up with an invalid uartclk value saved, but may also experience a distorted output/input data since such action will effectively update the programmed baud-clock. We discovered such problem on Baikal-T1 SoC where two DW 8250 ports have got a shared reference clock. Allwinner SoC is equipped with an UART, which clock is derived from the CPU PLL clock source, so the CPU frequency change might be propagated down up to the serial port reference clock. This patchset provides a way to fix the problem to the 8250 serial port controllers and mostly fixes it for the DW 8250-compatible UART. I say mostly because due to not having a facility to pause/stop and resume/restart on-going transfers we implemented the UART clock rate update procedure executed post factum of the actual reference clock rate change. In addition the patchset includes a small optimization patch. It simplifies the DW APB UART ref clock rate setting procedure a bit. This patchset is rebased and tested on the mainline Linux kernel 5.8-rc5: base-commit: 11ba468877bb ("Linux 5.8-rc5") tag: v5.8-rc5 Changelog v3: - Refactor the original patch to adjust the UART port divisor instead of requesting an exclusive ref clock utilization. Changelog v4: - Discard commit b426bf0fb085 ("serial: 8250: Fix max baud limit in generic 8250 port") since Greg has already merged it into the tty-next branch. - Use EXPORT_SYMBOL_GPL() for the serial8250_update_uartclk() method. Changelog v5: - Refactor dw8250_clk_work_cb() function cheking the clk_get_rate() return value for being erroneous and exit if it is. - Don't update p->uartclk in the port startup. It will be updated later in the same procedure at the set_termios() function being invoked by the serial_core anyway. Changelog v6: - Resend Link: https://lore.kernel.org/linux-serial/20200617224813.23853-1-Sergey.Semin@baikalelectronics.ru Changelog v7: - Wake the device up on the serial port divider update. Link: https://lore.kernel.org/linux-serial/20200619200251.9066-1-Sergey.Semin@baikalelectronics.ru Changelog v8: - Add a new patch: "serial: 8250_dw: Pass the same rate to the clk round and set rate methods" Link: https://lore.kernel.org/linux-serial/20200714124808.21493-1-Sergey.Semin@baikalelectronics.ru Changelog v9: - Resend 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 (4): serial: 8250: Add 8250 port clock update method serial: 8250_dw: Simplify the ref clock rate setting procedure serial: 8250_dw: Pass the same rate to the clk round and set rate methods serial: 8250_dw: Fix common clocks usage race condition drivers/tty/serial/8250/8250_dw.c | 120 ++++++++++++++++++++++++---- drivers/tty/serial/8250/8250_port.c | 40 ++++++++++ include/linux/serial_8250.h | 2 + 3 files changed, 148 insertions(+), 14 deletions(-) -- 2.26.2