linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: Douglas Anderson <dianders@chromium.org>,
	Mark Brown <broonie@kernel.org>
Cc: Alok Chauhan <alokc@codeaurora.org>,
	skakit@codeaurora.org, Douglas Anderson <dianders@chromium.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Dilip Kota <dkota@codeaurora.org>,
	Girish Mahadevan <girishm@codeaurora.org>,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-spi@vger.kernel.org
Subject: Re: [PATCH v4 2/5] spi: spi-geni-qcom: Mo' betta locking
Date: Thu, 18 Jun 2020 10:52:25 -0700	[thread overview]
Message-ID: <159250274581.62212.7220017192299709142@swboyd.mtv.corp.google.com> (raw)
In-Reply-To: <20200618080459.v4.2.I752ebdcfd5e8bf0de06d66e767b8974932b3620e@changeid>

Quoting Douglas Anderson (2020-06-18 08:06:23)
> If you added a bit of a delay (like a trace_printk) into the ISR for
> the spi-geni-qcom driver, you would suddenly start seeing some errors
> spit out.  The problem was that, though the ISR itself held a lock,
> other parts of the driver didn't always grab the lock.
> 
> One example race was this:
>   CPU0                                         CPU1
>   ----                                         ----
>   spi_geni_set_cs()
>    mas->cur_mcmd = CMD_CS;
>    geni_se_setup_m_cmd(...)
>    wait_for_completion_timeout(&xfer_done);
>                                               <INTERRUPT>
>                                                geni_spi_isr()
>                                                 complete(&xfer_done);
>    <wakeup>
>    pm_runtime_put(mas->dev);
>   ... // back to SPI core
>   spi_geni_transfer_one()
>    setup_fifo_xfer()
>     mas->cur_mcmd = CMD_XFER;
>                                                 mas->cur_cmd = CMD_NONE; // bad!
>                                                 return IRQ_HANDLED;
> 
> Let's fix this.  Before we start messing with hardware, we'll grab the
> lock to make sure that the IRQ handler from some previous command has
> really finished.  We don't need to hold the lock unless we're in a
> state where more interrupts can come in, but we at least need to make
> sure the previous IRQ is done.  This lock is used exclusively to
> prevent the IRQ handler and non-IRQ from stomping on each other.  The
> SPI core handles all other mutual exclusion.
> 
> As part of this, we change the way that the IRQ handler detects
> spurious interrupts.  Previously we checked for our state variable
> being set to IRQ_NONE, but that was done outside the spinlock.  We
> could move it into the spinlock, but instead let's just change it to
> look for the lack of any IRQ status bits being set.  This can be done
> outside the lock--the hardware certainly isn't grabbing or looking at
> the spinlock when it updates its status register.
> 
> It's possible that this will fix real (but very rare) errors seen in
> the field that look like:
>   irq ...: nobody cared (try booting with the "irqpoll" option)
> 
> NOTE: an alternate strategy considered here was to always make the
> complete() / spi_finalize_current_transfer() the very last thing in
> our IRQ handler.  With such a change you could consider that we could
> be "lockless".  In that case, though, we'd have to be very careful w/
> memory barriers so we made sure we didn't have any bugs with weakly
> ordered memory.  Using spinlocks makes the driver much easier to
> understand.
> 
> Fixes: 561de45f72bd ("spi: spi-geni-qcom: Add SPI driver support for GENI based QUP")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---

Reviewed-by: Stephen Boyd <swboyd@chromium.org>

  reply	other threads:[~2020-06-18 17:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-18 15:06 [PATCH v4 0/5] spi: spi-geni-qcom: Fixes / perf improvements Douglas Anderson
2020-06-18 15:06 ` [PATCH v4 1/5] spi: spi-geni-qcom: No need for irqsave variant of spinlock calls Douglas Anderson
2020-06-18 15:15   ` Mark Brown
2020-06-18 15:06 ` [PATCH v4 2/5] spi: spi-geni-qcom: Mo' betta locking Douglas Anderson
2020-06-18 17:52   ` Stephen Boyd [this message]
2020-06-18 15:06 ` [PATCH v4 3/5] spi: spi-geni-qcom: Check for error IRQs Douglas Anderson
2020-06-18 15:06 ` [PATCH v4 4/5] spi: spi-geni-qcom: Actually use our FIFO Douglas Anderson
2020-06-18 15:06 ` [PATCH v4 5/5] spi: spi-geni-qcom: Don't keep a local state variable Douglas Anderson
2020-06-18 17:53   ` Stephen Boyd
2020-06-18 18:05   ` Stephen Boyd
2020-06-18 20:09     ` Doug Anderson
2020-06-18 21:52       ` Stephen Boyd
2020-06-18 22:00         ` Doug Anderson
2020-06-18 23:37           ` Stephen Boyd
2020-06-19  0:34             ` Doug Anderson
2020-06-18 23:39 ` [PATCH 6/5] spi: spi-geni-qcom: Simplify setup_fifo_xfer() Stephen Boyd
2020-06-19  0:40   ` Doug Anderson
2020-06-20  2:16     ` Stephen Boyd
2020-06-19  9:54   ` Mark Brown
2020-06-18 23:39 ` [PATCH 7/5] spi: spi-geni-qcom: Don't set {tx,rx}_rem_bytes unnecessarily Stephen Boyd
2020-06-19  0:40   ` Doug Anderson
2020-06-19 15:24   ` Mark Brown
2020-06-19 13:28 ` [PATCH v4 0/5] spi: spi-geni-qcom: Fixes / perf improvements Mark Brown
2020-06-22 14:59 ` Mark Brown

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=159250274581.62212.7220017192299709142@swboyd.mtv.corp.google.com \
    --to=swboyd@chromium.org \
    --cc=agross@kernel.org \
    --cc=alokc@codeaurora.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=broonie@kernel.org \
    --cc=dianders@chromium.org \
    --cc=dkota@codeaurora.org \
    --cc=girishm@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=skakit@codeaurora.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).