Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Hemant Kumar <hemantk@codeaurora.org>
To: manivannan.sadhasivam@linaro.org
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	jhugo@codeaurora.org, bbhatt@codeaurora.org,
	Hemant Kumar <hemantk@codeaurora.org>
Subject: [PATCH v1 2/5] bus: mhi: core: Handle disable transitions in state worker
Date: Mon, 11 May 2020 19:03:06 -0700	[thread overview]
Message-ID: <1589248989-23824-3-git-send-email-hemantk@codeaurora.org> (raw)
In-Reply-To: <1589248989-23824-1-git-send-email-hemantk@codeaurora.org>

Mission mode transition is handled by state worker thread but
power off is not. There is a possibility while mission mode
transition is in progress which calls MHI client driver probe,
power off is issued by MHI controller. This results into client
driver probe and remove running in parallel and causes use after
free situation. By queuing disable transition work when mission
mode is in progress prevents the race condition.

Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Reviewed-by: Jeffrey Hugo <jhugo@codeaurora.org>
---
 drivers/bus/mhi/core/init.c     |  1 +
 drivers/bus/mhi/core/internal.h |  1 +
 drivers/bus/mhi/core/pm.c       | 11 ++++++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c
index 3a853c5..12207cc 100644
--- a/drivers/bus/mhi/core/init.c
+++ b/drivers/bus/mhi/core/init.c
@@ -35,6 +35,7 @@
 	[DEV_ST_TRANSITION_SBL] = "SBL",
 	[DEV_ST_TRANSITION_MISSION_MODE] = "MISSION_MODE",
 	[DEV_ST_TRANSITION_SYS_ERR] = "SYS_ERR",
+	[DEV_ST_TRANSITION_DISABLE] = "DISABLE",
 };
 
 const char * const mhi_state_str[MHI_STATE_MAX] = {
diff --git a/drivers/bus/mhi/core/internal.h b/drivers/bus/mhi/core/internal.h
index f01283b..b1f640b 100644
--- a/drivers/bus/mhi/core/internal.h
+++ b/drivers/bus/mhi/core/internal.h
@@ -387,6 +387,7 @@ enum dev_st_transition {
 	DEV_ST_TRANSITION_SBL,
 	DEV_ST_TRANSITION_MISSION_MODE,
 	DEV_ST_TRANSITION_SYS_ERR,
+	DEV_ST_TRANSITION_DISABLE,
 	DEV_ST_TRANSITION_MAX,
 };
 
diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c
index d9964d4..345f197 100644
--- a/drivers/bus/mhi/core/pm.c
+++ b/drivers/bus/mhi/core/pm.c
@@ -657,6 +657,10 @@ void mhi_pm_st_worker(struct work_struct *work)
 			mhi_pm_disable_transition
 				(mhi_cntrl, MHI_PM_SYS_ERR_PROCESS);
 			break;
+		case DEV_ST_TRANSITION_DISABLE:
+			mhi_pm_disable_transition
+				(mhi_cntrl, MHI_PM_SHUTDOWN_PROCESS);
+			break;
 		default:
 			break;
 		}
@@ -1011,7 +1015,12 @@ void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful)
 				to_mhi_pm_state_str(MHI_PM_LD_ERR_FATAL_DETECT),
 				to_mhi_pm_state_str(mhi_cntrl->pm_state));
 	}
-	mhi_pm_disable_transition(mhi_cntrl, MHI_PM_SHUTDOWN_PROCESS);
+
+	mhi_queue_state_transition(mhi_cntrl, DEV_ST_TRANSITION_DISABLE);
+
+	/* Wait for shutdown to complete */
+	flush_work(&mhi_cntrl->st_worker);
+
 	mhi_deinit_free_irq(mhi_cntrl);
 
 	if (!mhi_cntrl->pre_init) {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

  parent reply	other threads:[~2020-05-12  2:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12  2:03 [PATCH v1 0/5] MHI Misc Fixes Hemant Kumar
2020-05-12  2:03 ` [PATCH v1 1/5] bus: mhi: core: Remove the system error worker thread Hemant Kumar
2020-05-12  6:46   ` Manivannan Sadhasivam
2020-05-12  2:03 ` Hemant Kumar [this message]
2020-05-12  6:47   ` [PATCH v1 2/5] bus: mhi: core: Handle disable transitions in state worker Manivannan Sadhasivam
2020-05-12  2:03 ` [PATCH v1 3/5] bus: mhi: core: Skip handling BHI irq if MHI reg access is not allowed Hemant Kumar
2020-05-12  6:53   ` Manivannan Sadhasivam
2020-05-13  0:28     ` Hemant Kumar
2020-05-13  7:04       ` Manivannan Sadhasivam
2020-05-13 18:39         ` Hemant Kumar
2020-05-13  7:58   ` Manivannan Sadhasivam
2020-05-12  2:03 ` [PATCH v1 4/5] bus: mhi: core: Do not process SYS_ERROR if RDDM is supported Hemant Kumar
2020-05-12  6:55   ` Manivannan Sadhasivam
2020-05-12  2:03 ` [PATCH v1 5/5] bus: mhi: core: Handle write lock properly in mhi_pm_m0_transition Hemant Kumar
2020-05-12  6:57   ` Manivannan Sadhasivam
2020-05-12  7:04 ` [PATCH v1 0/5] MHI Misc Fixes Manivannan Sadhasivam
2020-05-13 10:35 ` Manivannan Sadhasivam

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=1589248989-23824-3-git-send-email-hemantk@codeaurora.org \
    --to=hemantk@codeaurora.org \
    --cc=bbhatt@codeaurora.org \
    --cc=jhugo@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.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