# Re: \[net PATCH v4 2/6\] virtio\_net: wrap rtnl\_lock in test for calling with lock already held

- From: David Miller \<davem@davemloft.net\>
- Date: 2017-01-17 17:06:56 
- List: netdev
- Page: https://ratatoskr.run/netdev/2017/01/11041124
- Thread: https://ratatoskr.run/netdev/2017/01/11040916/t.md

```text
From: John Fastabend <john.fastabend@gmail.com>
Date: Sun, 15 Jan 2017 15:59:47 -0800

> @@ -2358,7 +2371,10 @@ static void remove_vq_common(struct virtnet_info *vi)
>  	/* Free unused buffers in both send and recv, if any. */
>  	free_unused_bufs(vi);
>  
> -	free_receive_bufs(vi);
> +	if (rtnl_is_locked())
> +		_free_receive_bufs(vi);
> +	else
> +		free_receive_bufs(vi);
>  
>  	free_receive_page_frags(vi);
>  

This doesn't work.  rtnl_is_locked() doesn't tell if _you_ own the mutex, it
just says that someone does.

So if we now execute this code without taking the RTNL lock just because some
other thread of control holds it, we introduce a race.
```
