diff mbox series

dmaengine: qcom: bam_dma: fix runtime PM underflow

Message ID 20220609195043.1544625-1-caleb.connolly@linaro.org
State New
Headers show
Series dmaengine: qcom: bam_dma: fix runtime PM underflow | expand

Commit Message

Caleb Connolly June 9, 2022, 7:50 p.m. UTC
When PM runtime is disabled, pm_runtime_get() isn't called, but
pm_runtime_put() still is. Fix this by creating a matching wrapper
on pm_runtime_put_autosuspend().

Fixes: dbad41e7bb5f ("dmaengine: qcom: bam_dma: check if the runtime pm enabled")
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/dma/qcom/bam_dma.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Steev Klimaszewski June 11, 2022, 6:19 p.m. UTC | #1
Hi Caleb,

On 6/9/22 2:50 PM, Caleb Connolly wrote:
> When PM runtime is disabled, pm_runtime_get() isn't called, but
> pm_runtime_put() still is. Fix this by creating a matching wrapper
> on pm_runtime_put_autosuspend().
>
> Fixes: dbad41e7bb5f ("dmaengine: qcom: bam_dma: check if the runtime pm enabled")
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>   drivers/dma/qcom/bam_dma.c | 18 +++++++++++++-----
>   1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index 87f6ca1541cf..a36dedee262e 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -566,6 +566,14 @@ static int bam_pm_runtime_get_sync(struct device *dev)
>   	return 0;
>   }
>   
> +static int bam_pm_runtime_put_autosuspend(struct device *dev)
> +{
> +	if (pm_runtime_enabled(dev))
> +		return pm_runtime_put_autosuspend(dev);
> +
> +	return 0;
> +}
> +
>   /**
>    * bam_free_chan - Frees dma resources associated with specific channel
>    * @chan: specified channel
> @@ -617,7 +625,7 @@ static void bam_free_chan(struct dma_chan *chan)
>   
>   err:
>   	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>   }
>   
>   /**
> @@ -793,7 +801,7 @@ static int bam_pause(struct dma_chan *chan)
>   	bchan->paused = 1;
>   	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>   	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>   
>   	return 0;
>   }
> @@ -819,7 +827,7 @@ static int bam_resume(struct dma_chan *chan)
>   	bchan->paused = 0;
>   	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>   	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>   
>   	return 0;
>   }
> @@ -936,7 +944,7 @@ static irqreturn_t bam_dma_irq(int irq, void *data)
>   	}
>   
>   	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>   
>   	return IRQ_HANDLED;
>   }
> @@ -1111,7 +1119,7 @@ static void bam_start_dma(struct bam_chan *bchan)
>   			bam_addr(bdev, bchan->id, BAM_P_EVNT_REG));
>   
>   	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>   }
>   
>   /**

I've tested this patch here and no longer see the logs filling up with 
messages about Runtime PM underflows.  Tested on the Lenovo Yoga C630.


Tested-by: Steev Klimaszewski <steev@kali.org>
Vinod Koul June 16, 2022, 2 p.m. UTC | #2
On 09-06-22, 20:50, Caleb Connolly wrote:
> When PM runtime is disabled, pm_runtime_get() isn't called, but
> pm_runtime_put() still is. Fix this by creating a matching wrapper
> on pm_runtime_put_autosuspend().
> 
> Fixes: dbad41e7bb5f ("dmaengine: qcom: bam_dma: check if the runtime pm enabled")
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>  drivers/dma/qcom/bam_dma.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index 87f6ca1541cf..a36dedee262e 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -566,6 +566,14 @@ static int bam_pm_runtime_get_sync(struct device *dev)
>  	return 0;
>  }
>  
> +static int bam_pm_runtime_put_autosuspend(struct device *dev)
> +{
> +	if (pm_runtime_enabled(dev))
> +		return pm_runtime_put_autosuspend(dev);
> +
> +	return 0;
> +}

should we really do a wrapper to fix this ;-) I would think dropping the
get wrapper and calling pm_runtime_get() unconditionally would be
better..?

> +
>  /**
>   * bam_free_chan - Frees dma resources associated with specific channel
>   * @chan: specified channel
> @@ -617,7 +625,7 @@ static void bam_free_chan(struct dma_chan *chan)
>  
>  err:
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  }
>  
>  /**
> @@ -793,7 +801,7 @@ static int bam_pause(struct dma_chan *chan)
>  	bchan->paused = 1;
>  	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  
>  	return 0;
>  }
> @@ -819,7 +827,7 @@ static int bam_resume(struct dma_chan *chan)
>  	bchan->paused = 0;
>  	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  
>  	return 0;
>  }
> @@ -936,7 +944,7 @@ static irqreturn_t bam_dma_irq(int irq, void *data)
>  	}
>  
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -1111,7 +1119,7 @@ static void bam_start_dma(struct bam_chan *bchan)
>  			bam_addr(bdev, bchan->id, BAM_P_EVNT_REG));
>  
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  }
>  
>  /**
> -- 
> 2.36.1
Caleb Connolly June 28, 2022, 12:08 p.m. UTC | #3
On 16/06/2022 15:00, Vinod Koul wrote:
> On 09-06-22, 20:50, Caleb Connolly wrote:
>> When PM runtime is disabled, pm_runtime_get() isn't called, but
>> pm_runtime_put() still is. Fix this by creating a matching wrapper
>> on pm_runtime_put_autosuspend().
>>
>> Fixes: dbad41e7bb5f ("dmaengine: qcom: bam_dma: check if the runtime pm enabled")
>> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
>> ---
>>   drivers/dma/qcom/bam_dma.c | 18 +++++++++++++-----
>>   1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
>> index 87f6ca1541cf..a36dedee262e 100644
>> --- a/drivers/dma/qcom/bam_dma.c
>> +++ b/drivers/dma/qcom/bam_dma.c
>> @@ -566,6 +566,14 @@ static int bam_pm_runtime_get_sync(struct device *dev)
>>   	return 0;
>>   }
>>   
>> +static int bam_pm_runtime_put_autosuspend(struct device *dev)
>> +{
>> +	if (pm_runtime_enabled(dev))
>> +		return pm_runtime_put_autosuspend(dev);
>> +
>> +	return 0;
>> +}
> 
> should we really do a wrapper to fix this ;-) I would think dropping the
> get wrapper and calling pm_runtime_get() unconditionally would be
> better..?
The original pm_runtime_get() wrapper was added because _get() returns -EACCES 
if PM is disabled for the device, I've read through some of the pm_runtime docs 
and I don't see any way to handle this nicely in the framework. I think the real 
fix will have to be in pm_runtime.

I can rework this to explicitly check for -EACCES on every _get() call, but we 
still need to check if pm_runtime is enabled before calling _put().
> 
>> +
>>   /**
>>    * bam_free_chan - Frees dma resources associated with specific channel
>>    * @chan: specified channel
>> @@ -617,7 +625,7 @@ static void bam_free_chan(struct dma_chan *chan)
>>   
>>   err:
>>   	pm_runtime_mark_last_busy(bdev->dev);
>> -	pm_runtime_put_autosuspend(bdev->dev);
>> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>>   }
>>   
>>   /**
>> @@ -793,7 +801,7 @@ static int bam_pause(struct dma_chan *chan)
>>   	bchan->paused = 1;
>>   	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>>   	pm_runtime_mark_last_busy(bdev->dev);
>> -	pm_runtime_put_autosuspend(bdev->dev);
>> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>>   
>>   	return 0;
>>   }
>> @@ -819,7 +827,7 @@ static int bam_resume(struct dma_chan *chan)
>>   	bchan->paused = 0;
>>   	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>>   	pm_runtime_mark_last_busy(bdev->dev);
>> -	pm_runtime_put_autosuspend(bdev->dev);
>> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>>   
>>   	return 0;
>>   }
>> @@ -936,7 +944,7 @@ static irqreturn_t bam_dma_irq(int irq, void *data)
>>   	}
>>   
>>   	pm_runtime_mark_last_busy(bdev->dev);
>> -	pm_runtime_put_autosuspend(bdev->dev);
>> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>>   
>>   	return IRQ_HANDLED;
>>   }
>> @@ -1111,7 +1119,7 @@ static void bam_start_dma(struct bam_chan *bchan)
>>   			bam_addr(bdev, bchan->id, BAM_P_EVNT_REG));
>>   
>>   	pm_runtime_mark_last_busy(bdev->dev);
>> -	pm_runtime_put_autosuspend(bdev->dev);
>> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>>   }
>>   
>>   /**
>> -- 
>> 2.36.1
>
Yassine Oudjana July 2, 2022, 8:48 a.m. UTC | #4
From: Yassine Oudjana <yassine.oudjana@gmail.com>

From: Yassine Oudjana <y.oudjana@protonmail.com>

On Thu,  9 Jun 2022 20:50:43 +0100, Caleb Connolly <caleb.connolly@linaro.org> wrote:
> 
> When PM runtime is disabled, pm_runtime_get() isn't called, but
> pm_runtime_put() still is. Fix this by creating a matching wrapper
> on pm_runtime_put_autosuspend().
> 
> Fixes: dbad41e7bb5f ("dmaengine: qcom: bam_dma: check if the runtime pm enabled")
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>  drivers/dma/qcom/bam_dma.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
> index 87f6ca1541cf..a36dedee262e 100644
> --- a/drivers/dma/qcom/bam_dma.c
> +++ b/drivers/dma/qcom/bam_dma.c
> @@ -566,6 +566,14 @@ static int bam_pm_runtime_get_sync(struct device *dev)
>  	return 0;
>  }
>  
> +static int bam_pm_runtime_put_autosuspend(struct device *dev)
> +{
> +	if (pm_runtime_enabled(dev))
> +		return pm_runtime_put_autosuspend(dev);
> +
> +	return 0;
> +}
> +
>  /**
>   * bam_free_chan - Frees dma resources associated with specific channel
>   * @chan: specified channel
> @@ -617,7 +625,7 @@ static void bam_free_chan(struct dma_chan *chan)
>  
>  err:
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  }
>  
>  /**
> @@ -793,7 +801,7 @@ static int bam_pause(struct dma_chan *chan)
>  	bchan->paused = 1;
>  	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  
>  	return 0;
>  }
> @@ -819,7 +827,7 @@ static int bam_resume(struct dma_chan *chan)
>  	bchan->paused = 0;
>  	spin_unlock_irqrestore(&bchan->vc.lock, flag);
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  
>  	return 0;
>  }
> @@ -936,7 +944,7 @@ static irqreturn_t bam_dma_irq(int irq, void *data)
>  	}
>  
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -1111,7 +1119,7 @@ static void bam_start_dma(struct bam_chan *bchan)
>  			bam_addr(bdev, bchan->id, BAM_P_EVNT_REG));
>  
>  	pm_runtime_mark_last_busy(bdev->dev);
> -	pm_runtime_put_autosuspend(bdev->dev);
> +	bam_pm_runtime_put_autosuspend(bdev->dev);
>  }
>  
>  /**
> -- 
> 2.36.1
> 

Thanks for the fix!

On the Xiaomi Mi Note 2:

Tested-by: Yassine Oudjana <y.oudjana@protonmail.com>
diff mbox series

Patch

diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c
index 87f6ca1541cf..a36dedee262e 100644
--- a/drivers/dma/qcom/bam_dma.c
+++ b/drivers/dma/qcom/bam_dma.c
@@ -566,6 +566,14 @@  static int bam_pm_runtime_get_sync(struct device *dev)
 	return 0;
 }
 
+static int bam_pm_runtime_put_autosuspend(struct device *dev)
+{
+	if (pm_runtime_enabled(dev))
+		return pm_runtime_put_autosuspend(dev);
+
+	return 0;
+}
+
 /**
  * bam_free_chan - Frees dma resources associated with specific channel
  * @chan: specified channel
@@ -617,7 +625,7 @@  static void bam_free_chan(struct dma_chan *chan)
 
 err:
 	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
+	bam_pm_runtime_put_autosuspend(bdev->dev);
 }
 
 /**
@@ -793,7 +801,7 @@  static int bam_pause(struct dma_chan *chan)
 	bchan->paused = 1;
 	spin_unlock_irqrestore(&bchan->vc.lock, flag);
 	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
+	bam_pm_runtime_put_autosuspend(bdev->dev);
 
 	return 0;
 }
@@ -819,7 +827,7 @@  static int bam_resume(struct dma_chan *chan)
 	bchan->paused = 0;
 	spin_unlock_irqrestore(&bchan->vc.lock, flag);
 	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
+	bam_pm_runtime_put_autosuspend(bdev->dev);
 
 	return 0;
 }
@@ -936,7 +944,7 @@  static irqreturn_t bam_dma_irq(int irq, void *data)
 	}
 
 	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
+	bam_pm_runtime_put_autosuspend(bdev->dev);
 
 	return IRQ_HANDLED;
 }
@@ -1111,7 +1119,7 @@  static void bam_start_dma(struct bam_chan *bchan)
 			bam_addr(bdev, bchan->id, BAM_P_EVNT_REG));
 
 	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
+	bam_pm_runtime_put_autosuspend(bdev->dev);
 }
 
 /**