Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: core: sysfs: Prevent div by zero
@ 2024-11-20  6:25 Gwendal Grignou
  2024-11-21 20:24 ` Bart Van Assche
  2024-11-22  2:09 ` Can Guo
  0 siblings, 2 replies; 5+ messages in thread
From: Gwendal Grignou @ 2024-11-20  6:25 UTC (permalink / raw)
  To: alim.akhtar, avri.altman, quic_cang, daejun7.park
  Cc: linux-scsi, Gwendal Grignou, stable

Prevent a division by 0 when monitoring is not enabled.

Fixes: 1d8613a23f3c ("scsi: ufs: core: Introduce HBA performance monitor sysfs nodes")

Cc: stable@vger.kernel.org
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
 drivers/ufs/core/ufs-sysfs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index c95906443d5f9..3692b39b35e78 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -485,6 +485,9 @@ static ssize_t read_req_latency_avg_show(struct device *dev,
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 	struct ufs_hba_monitor *m = &hba->monitor;
 
+	if (!m->nr_req[READ])
+		return sysfs_emit(buf, "0\n");
+
 	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
 						 m->nr_req[READ]));
 }
@@ -552,6 +555,9 @@ static ssize_t write_req_latency_avg_show(struct device *dev,
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 	struct ufs_hba_monitor *m = &hba->monitor;
 
+	if (!m->nr_req[WRITE])
+		return sysfs_emit(buf, "0\n");
+
 	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
 						 m->nr_req[WRITE]));
 }
-- 
2.47.0.338.g60cca15819-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: core: sysfs: Prevent div by zero
  2024-11-20  6:25 [PATCH] scsi: ufs: core: sysfs: Prevent div by zero Gwendal Grignou
@ 2024-11-21 20:24 ` Bart Van Assche
  2024-11-22  2:12   ` Can Guo
  2024-11-22  2:09 ` Can Guo
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2024-11-21 20:24 UTC (permalink / raw)
  To: Gwendal Grignou, alim.akhtar, avri.altman, quic_cang,
	daejun7.park
  Cc: linux-scsi, stable

On 11/19/24 10:25 PM, Gwendal Grignou wrote:
> Prevent a division by 0 when monitoring is not enabled.
> 
> Fixes: 1d8613a23f3c ("scsi: ufs: core: Introduce HBA performance monitor sysfs nodes")
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> ---
>   drivers/ufs/core/ufs-sysfs.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
> index c95906443d5f9..3692b39b35e78 100644
> --- a/drivers/ufs/core/ufs-sysfs.c
> +++ b/drivers/ufs/core/ufs-sysfs.c
> @@ -485,6 +485,9 @@ static ssize_t read_req_latency_avg_show(struct device *dev,
>   	struct ufs_hba *hba = dev_get_drvdata(dev);
>   	struct ufs_hba_monitor *m = &hba->monitor;
>   
> +	if (!m->nr_req[READ])
> +		return sysfs_emit(buf, "0\n");
> +
>   	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
>   						 m->nr_req[READ]));
>   }
> @@ -552,6 +555,9 @@ static ssize_t write_req_latency_avg_show(struct device *dev,
>   	struct ufs_hba *hba = dev_get_drvdata(dev);
>   	struct ufs_hba_monitor *m = &hba->monitor;
>   
> +	if (!m->nr_req[WRITE])
> +		return sysfs_emit(buf, "0\n");
> +
>   	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
>   						 m->nr_req[WRITE]));
>   }

Is anyone using the UFS monitor infrastructure or can it perhaps be
removed?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: core: sysfs: Prevent div by zero
  2024-11-20  6:25 [PATCH] scsi: ufs: core: sysfs: Prevent div by zero Gwendal Grignou
  2024-11-21 20:24 ` Bart Van Assche
@ 2024-11-22  2:09 ` Can Guo
  1 sibling, 0 replies; 5+ messages in thread
From: Can Guo @ 2024-11-22  2:09 UTC (permalink / raw)
  To: Gwendal Grignou, alim.akhtar, avri.altman, daejun7.park
  Cc: linux-scsi, stable


On 11/20/2024 2:25 PM, Gwendal Grignou wrote:
> Prevent a division by 0 when monitoring is not enabled.
>
> Fixes: 1d8613a23f3c ("scsi: ufs: core: Introduce HBA performance monitor sysfs nodes")
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> ---
>   drivers/ufs/core/ufs-sysfs.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
> index c95906443d5f9..3692b39b35e78 100644
> --- a/drivers/ufs/core/ufs-sysfs.c
> +++ b/drivers/ufs/core/ufs-sysfs.c
> @@ -485,6 +485,9 @@ static ssize_t read_req_latency_avg_show(struct device *dev,
>   	struct ufs_hba *hba = dev_get_drvdata(dev);
>   	struct ufs_hba_monitor *m = &hba->monitor;
>   
> +	if (!m->nr_req[READ])
> +		return sysfs_emit(buf, "0\n");
> +
>   	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
>   						 m->nr_req[READ]));
>   }
> @@ -552,6 +555,9 @@ static ssize_t write_req_latency_avg_show(struct device *dev,
>   	struct ufs_hba *hba = dev_get_drvdata(dev);
>   	struct ufs_hba_monitor *m = &hba->monitor;
>   
> +	if (!m->nr_req[WRITE])
> +		return sysfs_emit(buf, "0\n");
> +
>   	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
>   						 m->nr_req[WRITE]));
>   }
Thanks for the fix!

Reviewed-by: Can Guo <quic_cang@quicinc.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: core: sysfs: Prevent div by zero
  2024-11-21 20:24 ` Bart Van Assche
@ 2024-11-22  2:12   ` Can Guo
  2024-11-25 23:08     ` Bart Van Assche
  0 siblings, 1 reply; 5+ messages in thread
From: Can Guo @ 2024-11-22  2:12 UTC (permalink / raw)
  To: Bart Van Assche, Gwendal Grignou, alim.akhtar, avri.altman,
	daejun7.park
  Cc: linux-scsi, stable

Hi Bart,

On 11/22/2024 4:24 AM, Bart Van Assche wrote:
> On 11/19/24 10:25 PM, Gwendal Grignou wrote:
>> Prevent a division by 0 when monitoring is not enabled.
>>
>> Fixes: 1d8613a23f3c ("scsi: ufs: core: Introduce HBA performance 
>> monitor sysfs nodes")
>>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
>> ---
>>   drivers/ufs/core/ufs-sysfs.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
>> index c95906443d5f9..3692b39b35e78 100644
>> --- a/drivers/ufs/core/ufs-sysfs.c
>> +++ b/drivers/ufs/core/ufs-sysfs.c
>> @@ -485,6 +485,9 @@ static ssize_t read_req_latency_avg_show(struct 
>> device *dev,
>>       struct ufs_hba *hba = dev_get_drvdata(dev);
>>       struct ufs_hba_monitor *m = &hba->monitor;
>>   +    if (!m->nr_req[READ])
>> +        return sysfs_emit(buf, "0\n");
>> +
>>       return sysfs_emit(buf, "%llu\n", 
>> div_u64(ktime_to_us(m->lat_sum[READ]),
>>                            m->nr_req[READ]));
>>   }
>> @@ -552,6 +555,9 @@ static ssize_t write_req_latency_avg_show(struct 
>> device *dev,
>>       struct ufs_hba *hba = dev_get_drvdata(dev);
>>       struct ufs_hba_monitor *m = &hba->monitor;
>>   +    if (!m->nr_req[WRITE])
>> +        return sysfs_emit(buf, "0\n");
>> +
>>       return sysfs_emit(buf, "%llu\n", 
>> div_u64(ktime_to_us(m->lat_sum[WRITE]),
>>                            m->nr_req[WRITE]));
>>   }
>
> Is anyone using the UFS monitor infrastructure or can it perhaps be
> removed?

We are the user of the UFS monitor. And we are about to integrate UFS 
queue depth monitoring in it.


Thanks,

Can Guo.

>
> Thanks,
>
> Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: core: sysfs: Prevent div by zero
  2024-11-22  2:12   ` Can Guo
@ 2024-11-25 23:08     ` Bart Van Assche
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2024-11-25 23:08 UTC (permalink / raw)
  To: Can Guo, Gwendal Grignou, alim.akhtar, avri.altman, daejun7.park
  Cc: linux-scsi, stable

On 11/21/24 6:12 PM, Can Guo wrote:
> We are the user of the UFS monitor. And we are about to integrate UFS 
> queue depth monitoring in it.

Shouldn't such functionality be integrated in the block layer or SCSI 
core instead of in the UFS driver such that this functionality becomes
available to all block drivers?

Thanks,

Bart.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-25 23:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-20  6:25 [PATCH] scsi: ufs: core: sysfs: Prevent div by zero Gwendal Grignou
2024-11-21 20:24 ` Bart Van Assche
2024-11-22  2:12   ` Can Guo
2024-11-25 23:08     ` Bart Van Assche
2024-11-22  2:09 ` Can Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox