* [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up
@ 2021-11-08 17:41 Manivannan Sadhasivam
2021-11-08 18:04 ` Loic Poulain
2021-11-08 18:33 ` Hemant Kumar
0 siblings, 2 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2021-11-08 17:41 UTC (permalink / raw)
To: mhi
Cc: aleksander, loic.poulain, thomas.perrot, hemantk, bbhatt,
quic_jhugo, linux-arm-msm, Manivannan Sadhasivam, stable
Some devices tend to trigger SYS_ERR interrupt while the host handling
SYS_ERR state of the device during power up. This creates a race
condition and causes a failure in booting up the device.
The issue is seen on the Sierra Wireless EM9191 modem during SYS_ERR
handling in mhi_async_power_up(). Once the host detects that the device
is in SYS_ERR state, it issues MHI_RESET and waits for the device to
process the reset request. During this time, the device triggers SYS_ERR
interrupt to the host and host starts handling SYS_ERR execution.
So by the time the device has completed reset, host starts SYS_ERR
handling. This causes the race condition and the modem fails to boot.
Hence, register the IRQ handler only after handling the SYS_ERR check
to avoid getting spurious IRQs from the device.
Cc: stable@vger.kernel.org
Fixes: e18d4e9fa79b ("bus: mhi: core: Handle syserr during power_up")
Reported-by: Aleksander Morgado <aleksander@aleksander.es>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/bus/mhi/core/pm.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c
index fb99e3727155..ec5f11166820 100644
--- a/drivers/bus/mhi/core/pm.c
+++ b/drivers/bus/mhi/core/pm.c
@@ -1055,10 +1055,6 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
mutex_lock(&mhi_cntrl->pm_mutex);
mhi_cntrl->pm_state = MHI_PM_DISABLE;
- ret = mhi_init_irq_setup(mhi_cntrl);
- if (ret)
- goto error_setup_irq;
-
/* Setup BHI INTVEC */
write_lock_irq(&mhi_cntrl->pm_lock);
mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0);
@@ -1072,7 +1068,7 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
dev_err(dev, "%s is not a valid EE for power on\n",
TO_MHI_EXEC_STR(current_ee));
ret = -EIO;
- goto error_async_power_up;
+ goto error_setup_irq;
}
state = mhi_get_mhi_state(mhi_cntrl);
@@ -1082,19 +1078,18 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
if (state == MHI_STATE_SYS_ERR) {
mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
ret = wait_event_timeout(mhi_cntrl->state_event,
- MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state) ||
- mhi_read_reg_field(mhi_cntrl,
- mhi_cntrl->regs,
- MHICTRL,
- MHICTRL_RESET_MASK,
- MHICTRL_RESET_SHIFT,
+ mhi_read_reg_field(mhi_cntrl,
+ mhi_cntrl->regs,
+ MHICTRL,
+ MHICTRL_RESET_MASK,
+ MHICTRL_RESET_SHIFT,
&val) ||
!val,
msecs_to_jiffies(mhi_cntrl->timeout_ms));
if (!ret) {
ret = -EIO;
dev_info(dev, "Failed to reset MHI due to syserr state\n");
- goto error_async_power_up;
+ goto error_setup_irq;
}
/*
@@ -1104,6 +1099,10 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0);
}
+ ret = mhi_init_irq_setup(mhi_cntrl);
+ if (ret)
+ goto error_setup_irq;
+
/* Transition to next state */
next_state = MHI_IN_PBL(current_ee) ?
DEV_ST_TRANSITION_PBL : DEV_ST_TRANSITION_READY;
@@ -1116,9 +1115,6 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
return 0;
-error_async_power_up:
- mhi_deinit_free_irq(mhi_cntrl);
-
error_setup_irq:
mhi_cntrl->pm_state = MHI_PM_DISABLE;
mutex_unlock(&mhi_cntrl->pm_mutex);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up
2021-11-08 18:04 ` Loic Poulain
@ 2021-11-08 17:59 ` Manivannan Sadhasivam
0 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2021-11-08 17:59 UTC (permalink / raw)
To: Loic Poulain
Cc: mhi, aleksander, thomas.perrot, hemantk, bbhatt, quic_jhugo,
linux-arm-msm, stable
Hey Loic,
On Mon, Nov 08, 2021 at 07:04:56PM +0100, Loic Poulain wrote:
> Hi Mani,
>
> On Mon, 8 Nov 2021 at 18:42, Manivannan Sadhasivam
> <manivannan.sadhasivam@linaro.org> wrote:
> >
> > Some devices tend to trigger SYS_ERR interrupt while the host handling
> > SYS_ERR state of the device during power up. This creates a race
> > condition and causes a failure in booting up the device.
> >
> > The issue is seen on the Sierra Wireless EM9191 modem during SYS_ERR
> > handling in mhi_async_power_up(). Once the host detects that the device
> > is in SYS_ERR state, it issues MHI_RESET and waits for the device to
> > process the reset request. During this time, the device triggers SYS_ERR
> > interrupt to the host and host starts handling SYS_ERR execution.
> >
> > So by the time the device has completed reset, host starts SYS_ERR
> > handling. This causes the race condition and the modem fails to boot.
> >
> > Hence, register the IRQ handler only after handling the SYS_ERR check
> > to avoid getting spurious IRQs from the device.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: e18d4e9fa79b ("bus: mhi: core: Handle syserr during power_up")
> > Reported-by: Aleksander Morgado <aleksander@aleksander.es>
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> > drivers/bus/mhi/core/pm.c | 26 +++++++++++---------------
> > 1 file changed, 11 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c
> > index fb99e3727155..ec5f11166820 100644
> > --- a/drivers/bus/mhi/core/pm.c
> > +++ b/drivers/bus/mhi/core/pm.c
> > @@ -1055,10 +1055,6 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
> > mutex_lock(&mhi_cntrl->pm_mutex);
> > mhi_cntrl->pm_state = MHI_PM_DISABLE;
> >
> > - ret = mhi_init_irq_setup(mhi_cntrl);
> > - if (ret)
> > - goto error_setup_irq;
> > -
> > /* Setup BHI INTVEC */
> > write_lock_irq(&mhi_cntrl->pm_lock);
> > mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0);
> > @@ -1072,7 +1068,7 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
> > dev_err(dev, "%s is not a valid EE for power on\n",
> > TO_MHI_EXEC_STR(current_ee));
> > ret = -EIO;
> > - goto error_async_power_up;
> > + goto error_setup_irq;
> > }
> >
> > state = mhi_get_mhi_state(mhi_cntrl);
> > @@ -1082,19 +1078,18 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
> > if (state == MHI_STATE_SYS_ERR) {
> > mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
> > ret = wait_event_timeout(mhi_cntrl->state_event,
>
> Shouldn't we use a polling variant such as mhi_poll_reg_field() given
> the interrupts are not yet enabled?
>
Realised _just_ after sending the patch and already submitted v2. Please take a
look.
Thanks,
Mani
> > - MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state) ||
> > - mhi_read_reg_field(mhi_cntrl,
> > - mhi_cntrl->regs,
> > - MHICTRL,
> > - MHICTRL_RESET_MASK,
> > - MHICTRL_RESET_SHIFT,
> > + mhi_read_reg_field(mhi_cntrl,
> > + mhi_cntrl->regs,
> > + MHICTRL,
> > + MHICTRL_RESET_MASK,
> > + MHICTRL_RESET_SHIFT,
> > &val) ||
> > !val,
> > msecs_to_jiffies(mhi_cntrl->timeout_ms));
> > if (!ret) {
> > ret = -EIO;
> > dev_info(dev, "Failed to reset MHI due to syserr state\n");
> > - goto error_async_power_up;
> > + goto error_setup_irq;
> > }
>
> Regards,
> Loic
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up
2021-11-08 17:41 [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up Manivannan Sadhasivam
@ 2021-11-08 18:04 ` Loic Poulain
2021-11-08 17:59 ` Manivannan Sadhasivam
2021-11-08 18:33 ` Hemant Kumar
1 sibling, 1 reply; 4+ messages in thread
From: Loic Poulain @ 2021-11-08 18:04 UTC (permalink / raw)
To: Manivannan Sadhasivam
Cc: mhi, aleksander, thomas.perrot, hemantk, bbhatt, quic_jhugo,
linux-arm-msm, stable
Hi Mani,
On Mon, 8 Nov 2021 at 18:42, Manivannan Sadhasivam
<manivannan.sadhasivam@linaro.org> wrote:
>
> Some devices tend to trigger SYS_ERR interrupt while the host handling
> SYS_ERR state of the device during power up. This creates a race
> condition and causes a failure in booting up the device.
>
> The issue is seen on the Sierra Wireless EM9191 modem during SYS_ERR
> handling in mhi_async_power_up(). Once the host detects that the device
> is in SYS_ERR state, it issues MHI_RESET and waits for the device to
> process the reset request. During this time, the device triggers SYS_ERR
> interrupt to the host and host starts handling SYS_ERR execution.
>
> So by the time the device has completed reset, host starts SYS_ERR
> handling. This causes the race condition and the modem fails to boot.
>
> Hence, register the IRQ handler only after handling the SYS_ERR check
> to avoid getting spurious IRQs from the device.
>
> Cc: stable@vger.kernel.org
> Fixes: e18d4e9fa79b ("bus: mhi: core: Handle syserr during power_up")
> Reported-by: Aleksander Morgado <aleksander@aleksander.es>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> drivers/bus/mhi/core/pm.c | 26 +++++++++++---------------
> 1 file changed, 11 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c
> index fb99e3727155..ec5f11166820 100644
> --- a/drivers/bus/mhi/core/pm.c
> +++ b/drivers/bus/mhi/core/pm.c
> @@ -1055,10 +1055,6 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
> mutex_lock(&mhi_cntrl->pm_mutex);
> mhi_cntrl->pm_state = MHI_PM_DISABLE;
>
> - ret = mhi_init_irq_setup(mhi_cntrl);
> - if (ret)
> - goto error_setup_irq;
> -
> /* Setup BHI INTVEC */
> write_lock_irq(&mhi_cntrl->pm_lock);
> mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0);
> @@ -1072,7 +1068,7 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
> dev_err(dev, "%s is not a valid EE for power on\n",
> TO_MHI_EXEC_STR(current_ee));
> ret = -EIO;
> - goto error_async_power_up;
> + goto error_setup_irq;
> }
>
> state = mhi_get_mhi_state(mhi_cntrl);
> @@ -1082,19 +1078,18 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl)
> if (state == MHI_STATE_SYS_ERR) {
> mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET);
> ret = wait_event_timeout(mhi_cntrl->state_event,
Shouldn't we use a polling variant such as mhi_poll_reg_field() given
the interrupts are not yet enabled?
> - MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state) ||
> - mhi_read_reg_field(mhi_cntrl,
> - mhi_cntrl->regs,
> - MHICTRL,
> - MHICTRL_RESET_MASK,
> - MHICTRL_RESET_SHIFT,
> + mhi_read_reg_field(mhi_cntrl,
> + mhi_cntrl->regs,
> + MHICTRL,
> + MHICTRL_RESET_MASK,
> + MHICTRL_RESET_SHIFT,
> &val) ||
> !val,
> msecs_to_jiffies(mhi_cntrl->timeout_ms));
> if (!ret) {
> ret = -EIO;
> dev_info(dev, "Failed to reset MHI due to syserr state\n");
> - goto error_async_power_up;
> + goto error_setup_irq;
> }
Regards,
Loic
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up
2021-11-08 17:41 [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up Manivannan Sadhasivam
2021-11-08 18:04 ` Loic Poulain
@ 2021-11-08 18:33 ` Hemant Kumar
1 sibling, 0 replies; 4+ messages in thread
From: Hemant Kumar @ 2021-11-08 18:33 UTC (permalink / raw)
To: Manivannan Sadhasivam, mhi
Cc: aleksander, loic.poulain, thomas.perrot, bbhatt, quic_jhugo,
linux-arm-msm, stable
On 11/8/2021 9:41 AM, Manivannan Sadhasivam wrote:
> Some devices tend to trigger SYS_ERR interrupt while the host handling
> SYS_ERR state of the device during power up. This creates a race
> condition and causes a failure in booting up the device.
>
> The issue is seen on the Sierra Wireless EM9191 modem during SYS_ERR
> handling in mhi_async_power_up(). Once the host detects that the device
> is in SYS_ERR state, it issues MHI_RESET and waits for the device to
> process the reset request. During this time, the device triggers SYS_ERR
Device is not triggering the SYS_ERR interrupt, interrupt was triggered
due to MHI RESET was getting cleared by device.
> interrupt to the host and host starts handling SYS_ERR execution.
"As interrupts are setup, MHI reset results in device clearing the reset
and it sends incoming BHI interrupt with state still seen as SYS_ERROR
instead of READY."
>
> So by the time the device has completed reset, host starts SYS_ERR
> handling. This causes the race condition and the modem fails to boot.
>
> Hence, register the IRQ handler only after handling the SYS_ERR check
> to avoid getting spurious IRQs from the device.
>
> Cc: stable@vger.kernel.org
> Fixes: e18d4e9fa79b ("bus: mhi: core: Handle syserr during power_up")
> Reported-by: Aleksander Morgado <aleksander@aleksander.es>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[..]
Thanks,
Hemant
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
Forum, a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-08 18:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08 17:41 [PATCH] bus: mhi: Fix race while handling SYS_ERR at power up Manivannan Sadhasivam
2021-11-08 18:04 ` Loic Poulain
2021-11-08 17:59 ` Manivannan Sadhasivam
2021-11-08 18:33 ` Hemant Kumar
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).