From: Thierry Reding <thierry.reding@gmail.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: Dmitry Osipenko <digetx@gmail.com>,
Jon Hunter <jonathanh@nvidia.com>,
linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: [PATCH 4/5] i2c: tegra: Better handle case where CPU0 is busy for a long time
Date: Wed, 6 May 2020 21:33:57 +0200 [thread overview]
Message-ID: <20200506193358.2807244-5-thierry.reding@gmail.com> (raw)
In-Reply-To: <20200506193358.2807244-1-thierry.reding@gmail.com>
From: Dmitry Osipenko <digetx@gmail.com>
Boot CPU0 always handle I2C interrupt and under some rare circumstances
(like running KASAN + NFS root) it may stuck in uninterruptible state for
a significant time. In this case we will get timeout if I2C transfer is
running on a sibling CPU, despite of IRQ being raised. In order to handle
this rare condition, the IRQ status needs to be checked after completion
timeout.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/i2c/busses/i2c-tegra.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 8d2a212db733..d504e272d9fa 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -996,14 +996,13 @@ tegra_i2c_poll_completion_timeout(struct tegra_i2c_dev *i2c_dev,
do {
u32 status = i2c_readl(i2c_dev, I2C_INT_STATUS);
- if (status) {
+ if (status)
tegra_i2c_isr(i2c_dev->irq, i2c_dev);
- if (completion_done(complete)) {
- s64 delta = ktime_ms_delta(ktimeout, ktime);
+ if (completion_done(complete)) {
+ s64 delta = ktime_ms_delta(ktimeout, ktime);
- return msecs_to_jiffies(delta) ?: 1;
- }
+ return msecs_to_jiffies(delta) ?: 1;
}
ktime = ktime_get();
@@ -1030,14 +1029,18 @@ tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev,
disable_irq(i2c_dev->irq);
/*
- * There is a chance that completion may happen after IRQ
- * synchronization, which is done by disable_irq().
+ * Under some rare circumstances (like running KASAN +
+ * NFS root) CPU, which handles interrupt, may stuck in
+ * uninterruptible state for a significant time. In this
+ * case we will get timeout if I2C transfer is running on
+ * a sibling CPU, despite of IRQ being raised.
+ *
+ * In order to handle this rare condition, the IRQ status
+ * needs to be checked after timeout.
*/
- if (ret == 0 && completion_done(complete)) {
- dev_warn(i2c_dev->dev,
- "completion done after timeout\n");
- ret = 1;
- }
+ if (ret == 0)
+ ret = tegra_i2c_poll_completion_timeout(i2c_dev,
+ complete, 0);
}
return ret;
--
2.24.1
next prev parent reply other threads:[~2020-05-06 19:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-06 19:33 [PATCH 0/5] i2c: tegra: Various fixes and improvements Thierry Reding
2020-05-06 19:33 ` [PATCH 1/5] Revert "i2c: tegra: Fix suspending in active runtime PM state" Thierry Reding
2020-05-06 19:33 ` [PATCH 2/5] i2c: tegra: Restore pinmux on system resume Thierry Reding
2020-05-06 22:43 ` mirq-test
2020-05-07 10:03 ` Thierry Reding
2020-05-07 12:20 ` Michał Mirosław
2020-05-07 21:50 ` Dmitry Osipenko
2020-05-08 10:31 ` Thierry Reding
2020-05-08 15:00 ` Dmitry Osipenko
2020-05-09 15:35 ` Dmitry Osipenko
2020-05-19 16:07 ` Thierry Reding
2020-05-19 15:57 ` Thierry Reding
2020-05-08 15:05 ` Dmitry Osipenko
2020-05-06 19:33 ` [PATCH 3/5] i2c: tegra: Keep IRQs enabled during suspend/resume Thierry Reding
2020-05-06 19:33 ` Thierry Reding [this message]
2020-05-06 19:33 ` [PATCH 5/5] i2c: tegra: Synchronize DMA before termination Thierry Reding
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=20200506193358.2807244-5-thierry.reding@gmail.com \
--to=thierry.reding@gmail.com \
--cc=digetx@gmail.com \
--cc=jonathanh@nvidia.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=wsa@the-dreams.de \
/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).