dpif-netdev: Introduce port_try_ref() to prevent a race.
authorAlex Wang <alexw@nicira.com>
Thu, 21 Aug 2014 22:54:07 +0000 (15:54 -0700)
committerAlex Wang <alexw@nicira.com>
Wed, 3 Sep 2014 20:29:03 +0000 (13:29 -0700)
commita1fdee136b278e575d84aeeac06374a44a530300
treeacba542f157ba1aabdb9b1697919994878231f84
parent16ee1400bbff0f001c2075f413da4bee9f9190e8
dpif-netdev: Introduce port_try_ref() to prevent a race.

When pmd thread interates through all ports for queue loading,
the main thread may unreference and 'rcu-free' a port before
pmd thread take new reference of it.  This could cause pmd
thread fail the reference and access freed memory later.

This commit fixes this race by introducing port_try_ref()
which uses ovs_refcount_try_ref_rcu().  And the pmd thread
will only load the port's queue, if port_try_ref() returns
true.

Found by inspection.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
lib/dpif-netdev.c