From: Paul Mundt <lethal@linux-sh.org>
To: linux-sh@vger.kernel.org
Subject: Re: [PATCH] sh-sci: fix a race of DMA submit_tx on transfer
Date: Thu, 15 Mar 2012 06:09:39 +0000 [thread overview]
Message-ID: <20120315060938.GB10046@linux-sh.org> (raw)
In-Reply-To: <4F5DC485.8020607@renesas.com>
On Wed, Mar 14, 2012 at 04:14:43PM +0900, Takashi Yoshii wrote:
> serial: sh-sci: fix a race of DMA submit_tx on transfer
>
> When DMA is enabled, sh-sci transfer begins with
> uart_start()
> sci_start_tx()
> if (cookie_tx < 0) schedule_work()
> Then, starts DMA when wq scheduled, -- (A)
> process_one_work()
> work_fn_rx()
> cookie_tx = desc->submit_tx()
> And finishes when DMA transfer ends, -- (B)
> sci_dma_tx_complete()
> async_tx_ack()
> cookie_tx = -EINVAL
> (possible another schedule_work())
>
> This A to B sequence is not reentrant, since controlling variables
> (for example, cookie_tx above) are not queues nor lists. So, they
> must be invoked as A B A B..., otherwise results in kernel crash.
>
> To ensure the sequence, sci_start_tx() seems to test if cookie_tx < 0
> (represents "not used") to call schedule_work().
> But cookie_tx will not be set (to a cookie, also means "used") until
> in the middle of work queue scheduled function work_fn_tx().
>
> This gap between the test and set allows the breakage of the sequence
> under the very frequently call of uart_start().
> Another gap between async_tx_ack() and another schedule_work() results
> in the same issue, too.
>
> This patch introduces a new condition "cookie_tx = 0" just to mark
> it is "busy" and assign it within spin-locked region to fill the gaps.
>
> Signed-off-by: Takashi Yoshii <takashi.yoshii.zj@renesas.com>
> Reviewed-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Looks good to me. I'll apply it unless Guennadi has any other concerns.
next prev parent reply other threads:[~2012-03-15 6:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-12 9:40 [PATCH] sh-sci: fix a race of DMA submit_tx on transfer Yoshii Takashi
2012-03-12 13:36 ` Guennadi Liakhovetski
2012-03-13 11:08 ` Takashi Yoshii
2012-03-13 11:47 ` Guennadi Liakhovetski
2012-03-14 7:14 ` Takashi Yoshii
2012-03-15 6:09 ` Paul Mundt [this message]
2012-03-15 10:50 ` Guennadi Liakhovetski
2012-03-28 6:11 ` Paul Mundt
2012-03-15 9:54 ` Takashi Yoshii
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=20120315060938.GB10046@linux-sh.org \
--to=lethal@linux-sh.org \
--cc=linux-sh@vger.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).