On Thu, May 07, 2020 at 02:31:31AM +0300, Serge Semin wrote:
> 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 it's no good. 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 few fixes we discovered when were
> working the issue. First one concerns the maximum baud rate setting used
> to determine a serial port baud based on the current UART port clock rate.
> Another one simplifies the ref clock rate setting procedure a bit.
>
> This patchset is rebased and tested on the mainline Linux kernel 5.7-rc4:
> 0e698dfa2822 ("Linux 5.7-rc4")
> tag: v5.7-rc4
Thanks!
I will look at them later, but first impression that the first approach narrowed
to the certain SoC (by matching compatible string) looks better solution for
time being.
> Changelog v3:
> - Refactor the original patch to adjust the UART port divisor instead of
> requesting an exclusive ref clock utilization.
>
> Signed-off-by: Serge Semin <[email protected]>
> Cc: Alexey Malahov <[email protected]>
> Cc: Maxim Kaurkin <[email protected]>
> Cc: Pavel Parkhomenko <[email protected]>
> Cc: Alexey Kolotnikov <[email protected]>
> Cc: Ramil Zaripov <[email protected]>
> Cc: Ekaterina Skachko <[email protected]>
> Cc: Vadim Vlasov <[email protected]>
> Cc: Alexey Kolotnikov <[email protected]>
> Cc: Paul Burton <[email protected]>
> Cc: Ralf Baechle <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Long Cheng <[email protected]>
> Cc: Andy Shevchenko <[email protected]>
> Cc: Maxime Ripard <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Cc: Russell King <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
>
> Serge Semin (4):
> serial: 8250: Fix max baud limit in generic 8250 port
> serial: 8250: Add 8250 port clock update method
> serial: 8250_dw: Simplify the ref clock rate setting procedure
> serial: 8250_dw: Fix common clocks usage race condition
>
> drivers/tty/serial/8250/8250_dw.c | 125 +++++++++++++++++++++++++---
> drivers/tty/serial/8250/8250_port.c | 42 +++++++++-
> include/linux/serial_8250.h | 2 +
> 3 files changed, 156 insertions(+), 13 deletions(-)
>
> --
> 2.25.1
>
--
With Best Regards,
Andy Shevchenko