From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Serge Semin <Sergey.Semin@baikalelectronics.ru>,
Tony Lindgren <tony@atomide.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Serge Semin <fancer.lancer@gmail.com>,
Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>,
Arnd Bergmann <arnd@arndb.de>, Maxime Ripard <mripard@kernel.org>,
Will Deacon <will@kernel.org>,
Russell King <linux@armlinux.org.uk>,
linux-mips@vger.kernel.org,
linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
"open list:SERIAL DRIVERS" <linux-serial@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 3/3] serial: 8250_dw: Fix common clocks usage race condition
Date: Thu, 18 Jun 2020 11:29:36 +0300 [thread overview]
Message-ID: <CAHp75VcoV+aC9H5TYAxQX2O9HLz==xnts9bcKKQBcdtvohpi6g@mail.gmail.com> (raw)
In-Reply-To: <20200617224813.23853-4-Sergey.Semin@baikalelectronics.ru>
On Thu, Jun 18, 2020 at 1:50 AM Serge Semin
<Sergey.Semin@baikalelectronics.ru> wrote:
>
> The race condition may happen if the UART reference clock is shared with
> some other device (on Baikal-T1 SoC it's another DW UART port). In this
> case if that device changes the clock rate while serial console is using
> it the DW 8250 UART port might not only end up with an invalid uartclk
> value saved, but may also experience a distorted output data since
> baud-clock could have been changed. In order to fix this lets at least
> try to adjust the 8250 port setting like UART clock rate in case if the
> reference clock rate change is discovered. The driver will call the new
> method to update 8250 UART port clock rate settings. It's done by means of
> the clock event notifier registered at the port startup and unregistered
> in the shutdown callback method.
>
> Note 1. In order to avoid deadlocks we had to execute the UART port update
> method in a dedicated deferred work. This is due to (in my opinion
> redundant) the clock update implemented in the dw8250_set_termios()
> method.
> Note 2. Before the ref clock is manually changed by the custom
> set_termios() function we swap the port uartclk value with new rate
> adjusted to be suitable for the requested baud. It is necessary in
> order to effectively disable a functionality of the ref clock events
> handler for the current UART port, since uartclk update will be done
> a bit further in the generic serial8250_do_set_termios() function.
So, regarding runtime PM...
> +static void dw8250_clk_work_cb(struct work_struct *work)
> +{
> + struct dw8250_data *d = work_to_dw8250_data(work);
> + struct uart_8250_port *up;
> + unsigned long rate;
> +
> + rate = clk_get_rate(d->clk);
> + if (rate <= 0)
> + return;
> +
> + up = serial8250_get_port(d->data.line);
(Btw, this can be done directly in the definition block above.)
> + serial8250_update_uartclk(&up->port, rate);
This I think should require a device to be powered on. What in your
opinion is a better place to have it done?
To me it looks like serial8250_update_uartclk() misses it.
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2020-06-18 8:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-17 22:48 [PATCH RESEND v6 0/3] serial: 8250_dw: Fix ref clock usage Serge Semin
2020-06-17 22:48 ` [PATCH v6 1/3] serial: 8250: Add 8250 port clock update method Serge Semin
2020-06-17 22:48 ` [PATCH v6 2/3] serial: 8250_dw: Simplify the ref clock rate setting procedure Serge Semin
2020-06-17 22:48 ` [PATCH v6 3/3] serial: 8250_dw: Fix common clocks usage race condition Serge Semin
2020-06-18 8:29 ` Andy Shevchenko [this message]
2020-06-19 17:47 ` Serge Semin
2020-06-18 8:17 ` [PATCH RESEND v6 0/3] serial: 8250_dw: Fix ref clock usage Andy Shevchenko
2020-06-18 8:31 ` Andy Shevchenko
2020-06-19 17:21 ` Serge Semin
2020-06-19 17:16 ` Serge Semin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHp75VcoV+aC9H5TYAxQX2O9HLz==xnts9bcKKQBcdtvohpi6g@mail.gmail.com' \
--to=andy.shevchenko@gmail.com \
--cc=Alexey.Malahov@baikalelectronics.ru \
--cc=Sergey.Semin@baikalelectronics.ru \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=fancer.lancer@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mripard@kernel.org \
--cc=tony@atomide.com \
--cc=tsbogend@alpha.franken.de \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).