diff mbox series

[v6,8/8] bus: mhi: core: Do not clear channel context more than once

Message ID 1612470486-10440-9-git-send-email-bbhatt@codeaurora.org (mailing list archive)
State Superseded
Headers show
Series Updates to MHI channel handling | expand

Commit Message

Bhaumik Bhatt Feb. 4, 2021, 8:28 p.m. UTC
Clearing a channel context can happen twice if the client driver
unprepares and reset the channels from the remove() callback from
a controller requested MHI power down sequence. If there are
multiple attempts at calling the mhi_free_coherent() API, we see
kernel warnings such as "trying to free invalid coherent area".
Example for one such client is the QRTR MHI driver. Avoid these
warnings by skipping mhi_deinit_chan_ctxt() API call and prevent
extra work from MHI as the channels are already disabled.

Signed-off-by: Bhaumik Bhatt <bbhatt@codeaurora.org>
---
 drivers/bus/mhi/core/init.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Hemant Kumar Feb. 5, 2021, 10:46 p.m. UTC | #1
On 2/4/21 12:28 PM, Bhaumik Bhatt wrote:
> Clearing a channel context can happen twice if the client driver
> unprepares and reset the channels from the remove() callback from
> a controller requested MHI power down sequence. If there are
> multiple attempts at calling the mhi_free_coherent() API, we see
> kernel warnings such as "trying to free invalid coherent area".
> Example for one such client is the QRTR MHI driver. Avoid these
> warnings by skipping mhi_deinit_chan_ctxt() API call and prevent
> extra work from MHI as the channels are already disabled.
> 
> Signed-off-by: Bhaumik Bhatt <bbhatt@codeaurora.org>

Reviewed-by: Hemant Kumar <hemantk@codeaurora.org>
Manivannan Sadhasivam Feb. 24, 2021, 10:10 a.m. UTC | #2
On Thu, Feb 04, 2021 at 12:28:06PM -0800, Bhaumik Bhatt wrote:
> Clearing a channel context can happen twice if the client driver
> unprepares and reset the channels from the remove() callback from
> a controller requested MHI power down sequence. If there are
> multiple attempts at calling the mhi_free_coherent() API, we see
> kernel warnings such as "trying to free invalid coherent area".
> Example for one such client is the QRTR MHI driver. Avoid these
> warnings by skipping mhi_deinit_chan_ctxt() API call and prevent
> extra work from MHI as the channels are already disabled.
> 
> Signed-off-by: Bhaumik Bhatt <bbhatt@codeaurora.org>

Is this patch still valid? We merged a similar fix from Loic for v5.11.

Thanks,
Mani

> ---
>  drivers/bus/mhi/core/init.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c
> index 30eef19..272f350 100644
> --- a/drivers/bus/mhi/core/init.c
> +++ b/drivers/bus/mhi/core/init.c
> @@ -1314,6 +1314,7 @@ static int mhi_driver_remove(struct device *dev)
>  
>  		if ((ch_state[dir] == MHI_CH_STATE_ENABLED ||
>  		     ch_state[dir] == MHI_CH_STATE_STOP) &&
> +		    mhi_chan->ch_state != MHI_CH_STATE_DISABLED &&
>  		    !mhi_chan->offload_ch)
>  			mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);
>  
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
Bhaumik Bhatt Feb. 24, 2021, 6:55 p.m. UTC | #3
On 2021-02-24 02:10 AM, Manivannan Sadhasivam wrote:
> On Thu, Feb 04, 2021 at 12:28:06PM -0800, Bhaumik Bhatt wrote:
>> Clearing a channel context can happen twice if the client driver
>> unprepares and reset the channels from the remove() callback from
>> a controller requested MHI power down sequence. If there are
>> multiple attempts at calling the mhi_free_coherent() API, we see
>> kernel warnings such as "trying to free invalid coherent area".
>> Example for one such client is the QRTR MHI driver. Avoid these
>> warnings by skipping mhi_deinit_chan_ctxt() API call and prevent
>> extra work from MHI as the channels are already disabled.
>> 
>> Signed-off-by: Bhaumik Bhatt <bbhatt@codeaurora.org>
> 
> Is this patch still valid? We merged a similar fix from Loic for v5.11.
> 
Yes, both the patches work to solve the same problem. This one just does 
it
sooner and relies on internal state variable rather than context being 
NULL.
> Thanks,
> Mani
> 
>> ---
>>  drivers/bus/mhi/core/init.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c
>> index 30eef19..272f350 100644
>> --- a/drivers/bus/mhi/core/init.c
>> +++ b/drivers/bus/mhi/core/init.c
>> @@ -1314,6 +1314,7 @@ static int mhi_driver_remove(struct device *dev)
>> 
>>  		if ((ch_state[dir] == MHI_CH_STATE_ENABLED ||
>>  		     ch_state[dir] == MHI_CH_STATE_STOP) &&
>> +		    mhi_chan->ch_state != MHI_CH_STATE_DISABLED &&
>>  		    !mhi_chan->offload_ch)
>>  			mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);
>> 
>> --
>> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
>> Forum,
>> a Linux Foundation Collaborative Project
>> 

Thanks,
Bhaumik
---
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
Forum,
a Linux Foundation Collaborative Project
diff mbox series

Patch

diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c
index 30eef19..272f350 100644
--- a/drivers/bus/mhi/core/init.c
+++ b/drivers/bus/mhi/core/init.c
@@ -1314,6 +1314,7 @@  static int mhi_driver_remove(struct device *dev)
 
 		if ((ch_state[dir] == MHI_CH_STATE_ENABLED ||
 		     ch_state[dir] == MHI_CH_STATE_STOP) &&
+		    mhi_chan->ch_state != MHI_CH_STATE_DISABLED &&
 		    !mhi_chan->offload_ch)
 			mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);