Skip to contentSkip to conversation

mmc: meson: Fix usage of meson_mmc_post_req()

PATCH In review Rong Chen 3 participants 3 messages Feb 16, 2022 – Feb 28, 2022

Subsystems (2)
lore
Share & tools
lore

Rong Chen

author
#0 lore raw

PATCH v2 1/1 mmc: meson: Fix usage of meson_mmc_post_req()

Currently meson_mmc_post_req() is called in meson_mmc_request() right after meson_mmc_start_cmd(). This could lead to DMA unmapping before the request is actually finished.

To fix, don't call meson_mmc_post_req() until meson_mmc_request_done().

---
 drivers/mmc/host/meson-gx-mmc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +8 -7
index 8f36536cb1b6..58ab9d90bc8b 100644
@@ -173,6 +173,8 @@ struct meson_host {
 	int irq;
 
 	bool vqmmc_enabled;
+	bool needs_pre_post_req;
+
 };
 
 #define CMD_CFG_LENGTH_MASK GENMASK(8, 0)
@@ -663,6 +665,8 @@ static void meson_mmc_request_done(struct mmc_host *mmc,
 	struct meson_host *host = mmc_priv(mmc);
 
 	host->cmd = NULL;
+	if (host->needs_pre_post_req)
+		meson_mmc_post_req(mmc, mrq, 0);
 	mmc_request_done(host->mmc, mrq);
 }
 
@@ -880,7 +884,7 @@ static int meson_mmc_validate_dram_access(struct mmc_host *mmc, struct mmc_data
 static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
 {
 	struct meson_host *host = mmc_priv(mmc);
-	bool needs_pre_post_req = mrq->data &&
+	host->needs_pre_post_req = mrq->data &&
 			!(mrq->data->host_cookie & SD_EMMC_PRE_REQ_DONE);
 
 	/*
@@ -896,22 +900,19 @@ static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
 		}
 	}
 
-	if (needs_pre_post_req) {
+	if (host->needs_pre_post_req) {
 		meson_mmc_get_transfer_mode(mmc, mrq);
 		if (!meson_mmc_desc_chain_mode(mrq->data))
-			needs_pre_post_req = false;
+			host->needs_pre_post_req = false;
 	}
 
-	if (needs_pre_post_req)
+	if (host->needs_pre_post_req)
 		meson_mmc_pre_req(mmc, mrq);
 
 	/* Stop execution */
 	writel(0, host->regs + SD_EMMC_START);
 
 	meson_mmc_start_cmd(mmc, mrq->sbc ?: mrq->cmd);
-
-	if (needs_pre_post_req)
-		meson_mmc_post_req(mmc, mrq, 0);
 }
 
 static void meson_mmc_read_resp(struct mmc_host *mmc, struct mmc_command *cmd)
Signature · 7 lines
2.25.1


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Rong Chen

Currently meson_mmc_post_req() is called in meson_mmc_request() right after meson_mmc_start_cmd(). This could lead to DMA unmapping before the request is actually finished.

To fix, don't call meson_mmc_post_req() until meson_mmc_request_done().

#2 lore raw
In reply to Rong Chen

+ Hainer

Quoted 8 lines · Rong Chen

Currently meson_mmc_post_req() is called in meson_mmc_request() right after meson_mmc_start_cmd(). This could lead to DMA unmapping before the request is actually finished.

To fix, don't call meson_mmc_post_req() until meson_mmc_request_done().

We should probably add a fixes tag to this, right?

Fixes 79ed05e329c3 ("mmc: meson-gx: add support for descriptor chain mode")

Moreover, you want this tagged for stable kernels too, right?

I have applied it for fixes and added the above tags, please tell if you want me to change it.

Kind regards
Uffe

Quoted 64 lines
---
 drivers/mmc/host/meson-gx-mmc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +8 -8
index 8f36536cb1b6..58ab9d90bc8b 100644
@@ -173,6 +173,8 @@ struct meson_host {
        int irq;
 
        bool vqmmc_enabled;
+       bool needs_pre_post_req;
+
 };
 
 #define CMD_CFG_LENGTH_MASK GENMASK(8, 0)
@@ -663,6 +665,8 @@ static void meson_mmc_request_done(struct mmc_host *mmc,
        struct meson_host *host = mmc_priv(mmc);
 
        host->cmd = NULL;
+       if (host->needs_pre_post_req)
+               meson_mmc_post_req(mmc, mrq, 0);
        mmc_request_done(host->mmc, mrq);
 }
 
@@ -880,7 +884,7 @@ static int meson_mmc_validate_dram_access(struct mmc_host *mmc, struct mmc_data
 static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
 {
        struct meson_host *host = mmc_priv(mmc);
-       bool needs_pre_post_req = mrq->data &&
+       host->needs_pre_post_req = mrq->data &&
                        !(mrq->data->host_cookie & SD_EMMC_PRE_REQ_DONE);
 
        /*
@@ -896,22 +900,19 @@ static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
                }
        }
 
-       if (needs_pre_post_req) {
+       if (host->needs_pre_post_req) {
                meson_mmc_get_transfer_mode(mmc, mrq);
                if (!meson_mmc_desc_chain_mode(mrq->data))
-                       needs_pre_post_req = false;
+                       host->needs_pre_post_req = false;
        }
 
-       if (needs_pre_post_req)
+       if (host->needs_pre_post_req)
                meson_mmc_pre_req(mmc, mrq);
 
        /* Stop execution */
        writel(0, host->regs + SD_EMMC_START);
 
        meson_mmc_start_cmd(mmc, mrq->sbc ?: mrq->cmd);
-
-       if (needs_pre_post_req)
-               meson_mmc_post_req(mmc, mrq, 0);
 }
 
 static void meson_mmc_read_resp(struct mmc_host *mmc, struct mmc_command *cmd)
--

2.25.1