* [PATCH] mmc: mediatek: fix race condition between msdc_request_timeout and irq
@ 2020-12-18 7:16 Chaotian Jing
2021-01-13 11:24 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Chaotian Jing @ 2020-12-18 7:16 UTC (permalink / raw)
To: Ulf Hansson
Cc: srv_heupstream, linux-mmc, linux-kernel, linux-mediatek,
Chaotian Jing, Matthias Brugger, linux-arm-kernel
when get request SW timeout, if CMD/DAT xfer done irq coming right now,
then there is race between the msdc_request_timeout work and irq handler,
and the host->cmd and host->data may set to NULL in irq handler. also,
current flow ensure that only one path can go to msdc_request_done(), so
no need check the return value of cancel_delayed_work().
Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
---
drivers/mmc/host/mtk-sd.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index de09c6347524..898ed1b023df 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -1127,13 +1127,13 @@ static void msdc_track_cmd_data(struct msdc_host *host,
static void msdc_request_done(struct msdc_host *host, struct mmc_request *mrq)
{
unsigned long flags;
- bool ret;
- ret = cancel_delayed_work(&host->req_timeout);
- if (!ret) {
- /* delay work already running */
- return;
- }
+ /*
+ * No need check the return value of cancel_delayed_work, as only ONE
+ * path will go here!
+ */
+ cancel_delayed_work(&host->req_timeout);
+
spin_lock_irqsave(&host->lock, flags);
host->mrq = NULL;
spin_unlock_irqrestore(&host->lock, flags);
@@ -1155,7 +1155,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events,
bool done = false;
bool sbc_error;
unsigned long flags;
- u32 *rsp = cmd->resp;
+ u32 *rsp;
if (mrq->sbc && cmd == mrq->cmd &&
(events & (MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR
@@ -1176,6 +1176,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events,
if (done)
return true;
+ rsp = cmd->resp;
sdr_clr_bits(host->base + MSDC_INTEN, cmd_ints_mask);
@@ -1363,7 +1364,7 @@ static void msdc_data_xfer_next(struct msdc_host *host,
static bool msdc_data_xfer_done(struct msdc_host *host, u32 events,
struct mmc_request *mrq, struct mmc_data *data)
{
- struct mmc_command *stop = data->stop;
+ struct mmc_command *stop;
unsigned long flags;
bool done;
unsigned int check_data = events &
@@ -1379,6 +1380,7 @@ static bool msdc_data_xfer_done(struct msdc_host *host, u32 events,
if (done)
return true;
+ stop = data->stop;
if (check_data || (stop && stop->error)) {
dev_dbg(host->dev, "DMA status: 0x%8X\n",
--
2.18.0
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mmc: mediatek: fix race condition between msdc_request_timeout and irq
2020-12-18 7:16 [PATCH] mmc: mediatek: fix race condition between msdc_request_timeout and irq Chaotian Jing
@ 2021-01-13 11:24 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2021-01-13 11:24 UTC (permalink / raw)
To: Chaotian Jing
Cc: srv_heupstream, linux-mmc, Linux Kernel Mailing List,
moderated list:ARM/Mediatek SoC support, Matthias Brugger,
Linux ARM
On Fri, 18 Dec 2020 at 08:16, Chaotian Jing <chaotian.jing@mediatek.com> wrote:
>
> when get request SW timeout, if CMD/DAT xfer done irq coming right now,
> then there is race between the msdc_request_timeout work and irq handler,
> and the host->cmd and host->data may set to NULL in irq handler. also,
> current flow ensure that only one path can go to msdc_request_done(), so
> no need check the return value of cancel_delayed_work().
>
> Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/host/mtk-sd.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
> index de09c6347524..898ed1b023df 100644
> --- a/drivers/mmc/host/mtk-sd.c
> +++ b/drivers/mmc/host/mtk-sd.c
> @@ -1127,13 +1127,13 @@ static void msdc_track_cmd_data(struct msdc_host *host,
> static void msdc_request_done(struct msdc_host *host, struct mmc_request *mrq)
> {
> unsigned long flags;
> - bool ret;
>
> - ret = cancel_delayed_work(&host->req_timeout);
> - if (!ret) {
> - /* delay work already running */
> - return;
> - }
> + /*
> + * No need check the return value of cancel_delayed_work, as only ONE
> + * path will go here!
> + */
> + cancel_delayed_work(&host->req_timeout);
> +
> spin_lock_irqsave(&host->lock, flags);
> host->mrq = NULL;
> spin_unlock_irqrestore(&host->lock, flags);
> @@ -1155,7 +1155,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events,
> bool done = false;
> bool sbc_error;
> unsigned long flags;
> - u32 *rsp = cmd->resp;
> + u32 *rsp;
>
> if (mrq->sbc && cmd == mrq->cmd &&
> (events & (MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR
> @@ -1176,6 +1176,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events,
>
> if (done)
> return true;
> + rsp = cmd->resp;
>
> sdr_clr_bits(host->base + MSDC_INTEN, cmd_ints_mask);
>
> @@ -1363,7 +1364,7 @@ static void msdc_data_xfer_next(struct msdc_host *host,
> static bool msdc_data_xfer_done(struct msdc_host *host, u32 events,
> struct mmc_request *mrq, struct mmc_data *data)
> {
> - struct mmc_command *stop = data->stop;
> + struct mmc_command *stop;
> unsigned long flags;
> bool done;
> unsigned int check_data = events &
> @@ -1379,6 +1380,7 @@ static bool msdc_data_xfer_done(struct msdc_host *host, u32 events,
>
> if (done)
> return true;
> + stop = data->stop;
>
> if (check_data || (stop && stop->error)) {
> dev_dbg(host->dev, "DMA status: 0x%8X\n",
> --
> 2.18.0
>
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-13 11:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 7:16 [PATCH] mmc: mediatek: fix race condition between msdc_request_timeout and irq Chaotian Jing
2021-01-13 11:24 ` Ulf Hansson
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).