* [PATCH net] linux/dim: Do nothing if no time delta between samples
@ 2023-05-07 13:57 Tariq Toukan
2023-05-08 6:13 ` Leon Romanovsky
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Tariq Toukan @ 2023-05-07 13:57 UTC (permalink / raw)
To: linux-kernel, netdev
Cc: David S. Miller, John Fastabend, Jakub Kicinski, Eric Dumazet,
Paolo Abeni, Saeed Mahameed, Gal Pressman, Tal Gilboa,
Leon Romanovsky, Roy Novich, Aya Levin, Tariq Toukan
From: Roy Novich <royno@nvidia.com>
Add return value for dim_calc_stats. This is an indication for the
caller if curr_stats was assigned by the function. Avoid using
curr_stats uninitialized over {rdma/net}_dim, when no time delta between
samples. Coverity reported this potential use of an uninitialized
variable.
Fixes: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
Fixes: cb3c7fd4f839 ("net/mlx5e: Support adaptive RX coalescing")
Signed-off-by: Roy Novich <royno@nvidia.com>
Reviewed-by: Aya Levin <ayal@nvidia.com>
Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
include/linux/dim.h | 3 ++-
lib/dim/dim.c | 5 +++--
lib/dim/net_dim.c | 3 ++-
lib/dim/rdma_dim.c | 3 ++-
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/include/linux/dim.h b/include/linux/dim.h
index 6c5733981563..f343bc9aa2ec 100644
--- a/include/linux/dim.h
+++ b/include/linux/dim.h
@@ -236,8 +236,9 @@ void dim_park_tired(struct dim *dim);
*
* Calculate the delta between two samples (in data rates).
* Takes into consideration counter wrap-around.
+ * Returned boolean indicates whether curr_stats are reliable.
*/
-void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
+bool dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
struct dim_stats *curr_stats);
/**
diff --git a/lib/dim/dim.c b/lib/dim/dim.c
index 38045d6d0538..e89aaf07bde5 100644
--- a/lib/dim/dim.c
+++ b/lib/dim/dim.c
@@ -54,7 +54,7 @@ void dim_park_tired(struct dim *dim)
}
EXPORT_SYMBOL(dim_park_tired);
-void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
+bool dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
struct dim_stats *curr_stats)
{
/* u32 holds up to 71 minutes, should be enough */
@@ -66,7 +66,7 @@ void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
start->comp_ctr);
if (!delta_us)
- return;
+ return false;
curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
@@ -79,5 +79,6 @@ void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
else
curr_stats->cpe_ratio = 0;
+ return true;
}
EXPORT_SYMBOL(dim_calc_stats);
diff --git a/lib/dim/net_dim.c b/lib/dim/net_dim.c
index 53f6b9c6e936..4e32f7aaac86 100644
--- a/lib/dim/net_dim.c
+++ b/lib/dim/net_dim.c
@@ -227,7 +227,8 @@ void net_dim(struct dim *dim, struct dim_sample end_sample)
dim->start_sample.event_ctr);
if (nevents < DIM_NEVENTS)
break;
- dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats);
+ if (!dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats))
+ break;
if (net_dim_decision(&curr_stats, dim)) {
dim->state = DIM_APPLY_NEW_PROFILE;
schedule_work(&dim->work);
diff --git a/lib/dim/rdma_dim.c b/lib/dim/rdma_dim.c
index 15462d54758d..88f779486707 100644
--- a/lib/dim/rdma_dim.c
+++ b/lib/dim/rdma_dim.c
@@ -88,7 +88,8 @@ void rdma_dim(struct dim *dim, u64 completions)
nevents = curr_sample->event_ctr - dim->start_sample.event_ctr;
if (nevents < DIM_NEVENTS)
break;
- dim_calc_stats(&dim->start_sample, curr_sample, &curr_stats);
+ if (!dim_calc_stats(&dim->start_sample, curr_sample, &curr_stats))
+ break;
if (rdma_dim_decision(&curr_stats, dim)) {
dim->state = DIM_APPLY_NEW_PROFILE;
schedule_work(&dim->work);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] linux/dim: Do nothing if no time delta between samples
2023-05-07 13:57 [PATCH net] linux/dim: Do nothing if no time delta between samples Tariq Toukan
@ 2023-05-08 6:13 ` Leon Romanovsky
2023-05-08 12:34 ` Michal Kubiak
2023-05-09 9:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2023-05-08 6:13 UTC (permalink / raw)
To: Tariq Toukan
Cc: linux-kernel, netdev, David S. Miller, John Fastabend,
Jakub Kicinski, Eric Dumazet, Paolo Abeni, Saeed Mahameed,
Gal Pressman, Tal Gilboa, Roy Novich, Aya Levin
On Sun, May 07, 2023 at 04:57:43PM +0300, Tariq Toukan wrote:
> From: Roy Novich <royno@nvidia.com>
>
> Add return value for dim_calc_stats. This is an indication for the
> caller if curr_stats was assigned by the function. Avoid using
> curr_stats uninitialized over {rdma/net}_dim, when no time delta between
> samples. Coverity reported this potential use of an uninitialized
> variable.
>
> Fixes: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
> Fixes: cb3c7fd4f839 ("net/mlx5e: Support adaptive RX coalescing")
> Signed-off-by: Roy Novich <royno@nvidia.com>
> Reviewed-by: Aya Levin <ayal@nvidia.com>
> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> ---
> include/linux/dim.h | 3 ++-
> lib/dim/dim.c | 5 +++--
> lib/dim/net_dim.c | 3 ++-
> lib/dim/rdma_dim.c | 3 ++-
> 4 files changed, 9 insertions(+), 5 deletions(-)
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] linux/dim: Do nothing if no time delta between samples
2023-05-07 13:57 [PATCH net] linux/dim: Do nothing if no time delta between samples Tariq Toukan
2023-05-08 6:13 ` Leon Romanovsky
@ 2023-05-08 12:34 ` Michal Kubiak
2023-05-09 9:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Michal Kubiak @ 2023-05-08 12:34 UTC (permalink / raw)
To: Tariq Toukan
Cc: linux-kernel, netdev, David S. Miller, John Fastabend,
Jakub Kicinski, Eric Dumazet, Paolo Abeni, Saeed Mahameed,
Gal Pressman, Tal Gilboa, Leon Romanovsky, Roy Novich, Aya Levin
On Sun, May 07, 2023 at 04:57:43PM +0300, Tariq Toukan wrote:
> From: Roy Novich <royno@nvidia.com>
>
> Add return value for dim_calc_stats. This is an indication for the
> caller if curr_stats was assigned by the function. Avoid using
> curr_stats uninitialized over {rdma/net}_dim, when no time delta between
> samples. Coverity reported this potential use of an uninitialized
> variable.
>
> Fixes: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
> Fixes: cb3c7fd4f839 ("net/mlx5e: Support adaptive RX coalescing")
> Signed-off-by: Roy Novich <royno@nvidia.com>
> Reviewed-by: Aya Levin <ayal@nvidia.com>
> Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> ---
Looks good to me.
Thanks,
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] linux/dim: Do nothing if no time delta between samples
2023-05-07 13:57 [PATCH net] linux/dim: Do nothing if no time delta between samples Tariq Toukan
2023-05-08 6:13 ` Leon Romanovsky
2023-05-08 12:34 ` Michal Kubiak
@ 2023-05-09 9:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-09 9:20 UTC (permalink / raw)
To: Tariq Toukan
Cc: linux-kernel, netdev, davem, john.fastabend, kuba, edumazet,
pabeni, saeedm, gal, talgi, leonro, royno, ayal
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Sun, 7 May 2023 16:57:43 +0300 you wrote:
> From: Roy Novich <royno@nvidia.com>
>
> Add return value for dim_calc_stats. This is an indication for the
> caller if curr_stats was assigned by the function. Avoid using
> curr_stats uninitialized over {rdma/net}_dim, when no time delta between
> samples. Coverity reported this potential use of an uninitialized
> variable.
>
> [...]
Here is the summary with links:
- [net] linux/dim: Do nothing if no time delta between samples
https://git.kernel.org/netdev/net/c/162bd18eb55a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-09 9:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-07 13:57 [PATCH net] linux/dim: Do nothing if no time delta between samples Tariq Toukan
2023-05-08 6:13 ` Leon Romanovsky
2023-05-08 12:34 ` Michal Kubiak
2023-05-09 9:20 ` patchwork-bot+netdevbpf
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).