Skip to content

Commit

Permalink
dpif-netdev: Fix unsafe access to pmd polling lists.
Browse files Browse the repository at this point in the history
All accesses to 'pmd->poll_list' should be guarded by
'pmd->port_mutex'. Additionally fixed inappropriate usage
of 'HMAP_FOR_EACH_SAFE' (hmap doesn't change in a loop)
and dropped not needed local variable 'proc_cycles'.

CC: Nitin Katiyar <nitin.katiyar@ericsson.com>
Fixes: 5bf8428 ("Adding support for PMD auto load balancing")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Kevin Traynor <ktraynor@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
  • Loading branch information
igsilya committed May 29, 2019
1 parent 7095b90 commit eef8538
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/dpif-netdev.c
Expand Up @@ -5098,7 +5098,7 @@ pmd_rebalance_dry_run(struct dp_netdev *dp)
uint64_t improvement = 0;
uint32_t num_pmds;
uint32_t *pmd_corelist;
struct rxq_poll *poll, *poll_next;
struct rxq_poll *poll;
bool ret;

num_pmds = cmap_count(&dp->poll_threads);
Expand All @@ -5124,13 +5124,14 @@ pmd_rebalance_dry_run(struct dp_netdev *dp)
/* Estimate the cycles to cover all intervals. */
total_cycles *= PMD_RXQ_INTERVAL_MAX;

HMAP_FOR_EACH_SAFE (poll, poll_next, node, &pmd->poll_list) {
uint64_t proc_cycles = 0;
ovs_mutex_lock(&pmd->port_mutex);
HMAP_FOR_EACH (poll, node, &pmd->poll_list) {
for (unsigned i = 0; i < PMD_RXQ_INTERVAL_MAX; i++) {
proc_cycles += dp_netdev_rxq_get_intrvl_cycles(poll->rxq, i);
total_proc += dp_netdev_rxq_get_intrvl_cycles(poll->rxq, i);
}
total_proc += proc_cycles;
}
ovs_mutex_unlock(&pmd->port_mutex);

if (total_proc) {
curr_pmd_usage[num_pmds] = (total_proc * 100) / total_cycles;
}
Expand Down

0 comments on commit eef8538

Please sign in to comment.