From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Douglas Anderson <dianders@chromium.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
linux-arm-msm@vger.kernel.org,
"John Ogness" <john.ogness@linutronix.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Tony Lindgren" <tony@atomide.com>,
"Stephen Boyd" <swboyd@chromium.org>,
linux-serial@vger.kernel.org,
"Yicong Yang" <yangyicong@hisilicon.com>,
"Johan Hovold" <johan+linaro@kernel.org>,
linux-kernel@vger.kernel.org,
"Bjorn Andersson" <andersson@kernel.org>,
"Konrad Dybcio" <konrad.dybcio@linaro.org>,
"Vijaya Krishna Nivarthi" <quic_vnivarth@quicinc.com>
Subject: Re: [PATCH v2 6/7] serial: qcom-geni: Fix suspend while active UART xfer
Date: Fri, 31 May 2024 11:36:36 +0300 [thread overview]
Message-ID: <ZlmMFBxkMlINr2JO@smile.fi.intel.com> (raw)
In-Reply-To: <20240530154553.v2.6.I0f81a5baa37d368f291c96ee4830abca337e3c87@changeid>
On Thu, May 30, 2024 at 03:45:58PM -0700, Douglas Anderson wrote:
> On devices using Qualcomm's GENI UART it is possible to get the UART
> stuck such that it no longer outputs data. Specifically, I could
> reproduce this problem by logging in via an agetty on the debug serial
> port (which was _not_ used for kernel console) and running:
> cat /var/log/messages
> ...and then (via an SSH session) forcing a few suspend/resume cycles.
>
> Digging into this showed a number of problems that are all related.
>
> The root of the problems was with qcom_geni_serial_stop_tx_fifo()
> which is called as part of the suspend process. Specific problems with
> that function:
> - When we cancel an in-progress "tx" command it doesn't appear to
> fully drain the FIFO. That meant qcom_geni_serial_tx_empty()
> continued to report that the FIFO wasn't empty. The
> qcom_geni_serial_start_tx_fifo() function didn't re-enable
> interrupts in this case so we'd never start transferring again.
> - We cancelled the current "tx" command but we forgot to zero out
> "tx_remaining". This confused logic elsewhere in the driver
> - From experimentation, it appears that cancelling the "tx" command
> could drop some of the queued up bytes. While maybe not the end of
> the world, it doesn't seem like we should be dropping bytes when
> stopping the FIFO, which is defined more of a "pause".
>
> One idea to fix the above would be to add FIFO draining to
> qcom_geni_serial_stop_tx_fifo(). However, digging into the
> documentation in serial_core.h for stop_tx() makes this seem like the
> wrong choice. Specifically stop_tx() is called with local interrupts
> disabled. Waiting for a FIFO (which might be 64 bytes big) to drain at
> 115.2 kbps doesn't seem like a wise move.
>
> Ideally qcom_geni_serial_stop_tx_fifo() would be able to pause the
> transmitter, but nothing in the documentation for the GENI UART makes
> me believe that is possible.
>
> Given the lack of better choices, we'll change
> qcom_geni_serial_stop_tx_fifo() to simply disable the
> TX_FIFO_WATERMARK interrupt and call it a day. This seems OK as per
> the serial core docs since stop_tx() is supposed to stop transferring
> bytes "as soon as possible" and there doesn't seem to be any possible
> way to stop transferring sooner. As part of this, get rid of some of
> the extra conditions on qcom_geni_serial_start_tx_fifo() which simply
> weren't needed and are now getting in the way. It's always fine to
> turn the interrupts on if we want to receive and it'll be up to the
> IRQ handler to turn them back off if somehow they're not needed. This
> works fine.
>
> Unfortunately, doing just the above change causes new/different
> problems with suspend/resume. Now if you suspend while an active
> transfer is happening you can find that after resume time you're no
> longer receiving UART interrupts at all. It appears to be important to
> drain the FIFO and send a "cancel" command if the UART is active to
> avoid this. Since we've already decided that
> qcom_geni_serial_stop_tx_fifo() shouldn't be doing this, let's add the
> draining / cancelling logic to the shutdown() call where it should be
> OK to delay a bit. This is called as part of the suspend process via
> uart_suspend_port().
>
> Finally, with all of the above, the test case where we're spamming the
> UART with data and going through suspend/resume cycles doesn't kill
> the UART and doesn't drop bytes.
>
> NOTE: though I haven't gone back and validated on ancient code, it
> appears from code inspection that many of these problems have existed
> since the start of the driver. In the very least, I could reproduce
> the problems on vanilla v5.15. The problems don't seem to reproduce
> when using the serial port for kernel console output and also don't
> seem to reproduce if nothing is being printed to the console at
> suspend time, so this is presumably why they were not noticed until
> now.
...
> + qcom_geni_serial_poll_bitfield(uport, SE_GENI_M_GP_LENGTH, 0xffffffff,
It's easy to miscount f:s, GENMASK()?
> + port->tx_total - port->tx_remaining);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2024-05-31 8:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 22:45 [PATCH v2 0/7] serial: qcom-geni: Overhaul TX handling to fix crashes/hangs Douglas Anderson
2024-05-30 22:45 ` [PATCH v2 1/7] soc: qcom: geni-se: Add GP_LENGTH/IRQ_EN_SET/IRQ_EN_CLEAR registers Douglas Anderson
2024-06-02 4:23 ` Bjorn Andersson
2024-05-30 22:45 ` [PATCH v2 2/7] serial: qcom-geni: Fix the timeout in qcom_geni_serial_poll_bit() Douglas Anderson
2024-05-31 8:34 ` Andy Shevchenko
2024-05-31 14:57 ` Ilpo Järvinen
2024-05-30 22:45 ` [PATCH v2 3/7] serial: qcom-geni: Fix arg types for qcom_geni_serial_poll_bit() Douglas Anderson
2024-05-30 22:45 ` [PATCH v2 4/7] serial: qcom-geni: Introduce qcom_geni_serial_poll_bitfield() Douglas Anderson
2024-05-30 22:45 ` [PATCH v2 5/7] serial: qcom-geni: Just set the watermark level once Douglas Anderson
2024-05-30 22:45 ` [PATCH v2 6/7] serial: qcom-geni: Fix suspend while active UART xfer Douglas Anderson
2024-05-31 8:36 ` Andy Shevchenko [this message]
2024-05-31 15:13 ` Ilpo Järvinen
2024-06-04 16:03 ` Doug Anderson
2024-05-30 22:45 ` [PATCH v2 7/7] serial: qcom-geni: Rework TX in FIFO mode to fix hangs/lockups Douglas Anderson
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=ZlmMFBxkMlINr2JO@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=andersson@kernel.org \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=johan+linaro@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=quic_vnivarth@quicinc.com \
--cc=swboyd@chromium.org \
--cc=tony@atomide.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=yangyicong@hisilicon.com \
/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