[dpdk-dev] [BUG-REPORT] Need to add mutex on vhost_devices[] in virtio-net.c in DPDK-2.2?

Sam batmanustc at gmail.com
Thu Oct 12 08:29:45 CEST 2017

Hi all,

I'm running vhostuser part code of dpdk, and I found a crash, which is
caused by call NULL pointer. Then I debug code and I found I use NULL
pointer which is got from vhost_devices[].

I read code of virtio-net.c, and I found there is no lock on
vhost_devices[] !!! vhost_devices[] is used
by vhost_destroy_device, get_device, vhost_new_device. If one thread use
get_device to get the dev pointer, and another thread use
vhost_destroy_device to destroy it, then crash will happen.

Also I know that, if one thread to call get_device or other functions, it
must supply vid, which means thread must hold vid itself, this mechanism
could solve the problem above. But now there is a requirement to dump all
info of dev in vhost_devices[] which is not NULL, so if there is no lock on
this array, crash will happens.

So how to fix this? And if this bug has already fixed in new version?

More information about the dev mailing list