Skip to content

Commit

Permalink
netdev-offload: Fix Clang's static analyzer 'Division by zero' warnings.
Browse files Browse the repository at this point in the history
When enabling DPDK with the configure the below, ovs-vswitchd will crash.

  ovs-vsctl set Open_vSwitch . other_config:n-offload-threads=0
  ovs-vsctl set Open_vSwitch . other_config:hw-offload=true

This issue arises because setting the 'n-offload-threads' value to zero
is not a supported configuration. This fix addresses this by implementing
a check to ensure a valid 'n-offload-threads' value, both during
configuration and statistics gathering.

Fixes: 62c2d8a ("netdev-offload: Add multi-thread API.")
Signed-off-by: Eelco Chaudron <[email protected]>
Acked-by: Ilya Maximets <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
chaudron authored and Simon Horman committed Oct 30, 2023
1 parent 3919e61 commit 1b0c753
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,10 @@ dpif_netdev_offload_stats_get(struct dpif *dpif,
}

nb_thread = netdev_offload_thread_nb();
if (!nb_thread) {
return EINVAL;
}

/* nb_thread counters for the overall total as well. */
stats->size = ARRAY_SIZE(hwol_stats) * (nb_thread + 1);
stats->counters = xcalloc(stats->size, sizeof *stats->counters);
Expand Down
3 changes: 2 additions & 1 deletion lib/netdev-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ netdev_set_flow_api_enabled(const struct smap *ovs_other_config)
offload_thread_nb = smap_get_ullong(ovs_other_config,
"n-offload-threads",
DEFAULT_OFFLOAD_THREAD_NB);
if (offload_thread_nb > MAX_OFFLOAD_THREAD_NB) {
if (offload_thread_nb == 0 ||
offload_thread_nb > MAX_OFFLOAD_THREAD_NB) {
VLOG_WARN("netdev: Invalid number of threads requested: %u",
offload_thread_nb);
offload_thread_nb = DEFAULT_OFFLOAD_THREAD_NB;
Expand Down
2 changes: 1 addition & 1 deletion tests/test-id-fpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ print_result(const char *prefix)
for (i = 0; i < n_threads; i++) {
avg += thread_working_ms[i];
}
avg /= n_threads;
avg /= n_threads ? n_threads : 1;
printf("%s: ", prefix);
for (i = 0; i < n_threads; i++) {
if (thread_working_ms[i] >= TIMEOUT_MS) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test-mpsc-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ print_result(const char *prefix, int reader_elapsed)
for (i = 0; i < n_threads; i++) {
avg += thread_working_ms[i];
}
avg /= n_threads;
avg /= n_threads ? n_threads : 1;
printf("%s: %6d", prefix, reader_elapsed);
for (i = 0; i < n_threads; i++) {
printf(" %6" PRIu64, thread_working_ms[i]);
Expand Down

0 comments on commit 1b0c753

Please sign in to comment.