Denis Efremov | 11 Aug 2012 12:05
Picon

[PATCH] macvtap: rcu_dereference outside read-lock section

In this case it is not an error. rcu_dereference
occurs in update section. Replacement by
rcu_dereference_protected (with spinlock) in order to
prevent lockdep complaint.

Found by Linux Driver Verification project (linuxtesting.org)

Signed-off-by: Denis Efremov <yefremov.denis <at> gmail.com>
---
 drivers/net/macvtap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 0737bd4..8ef11a8 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
 <at>  <at>  -94,7 +94,8  <at>  <at>  static int get_slot(struct macvlan_dev *vlan, struct macvtap_queue *q)
 	int i;

 	for (i = 0; i < MAX_MACVTAP_QUEUES; i++) {
-		if (rcu_dereference(vlan->taps[i]) == q)
+		if (rcu_dereference_protected(vlan->taps[i],
+				lockdep_is_held(&macvtap_lock)) == q)
 			return i;
 	}

--

-- 
1.7.7

(Continue reading)

David Miller | 12 Aug 2012 03:16
Favicon

Re: [PATCH] macvtap: rcu_dereference outside read-lock section

From: Denis Efremov <yefremov.denis <at> gmail.com>
Date: Sat, 11 Aug 2012 14:05:27 +0400

> -		if (rcu_dereference(vlan->taps[i]) == q)
> +		if (rcu_dereference_protected(vlan->taps[i],
> +				lockdep_is_held(&macvtap_lock)) == q)

You must use the proper combination of TAB character and spaces
to line up the lockdep_is_held() argument with the first column
after openning "(" on the previous line.

Never be lazy and use only TABs.
Denis Efremov | 12 Aug 2012 08:26
Picon

[PATCH v2] macvtap: rcu_dereference outside read-lock section

rcu_dereference occurs in update section. Replacement by
rcu_dereference_protected in order to prevent lockdep
complaint.

Found by Linux Driver Verification project (linuxtesting.org)

Signed-off-by: Denis Efremov <yefremov.denis <at> gmail.com>
---
 drivers/net/macvtap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 0737bd4..0f0f9ce 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
 <at>  <at>  -94,7 +94,8  <at>  <at>  static int get_slot(struct macvlan_dev *vlan, struct macvtap_queue *q)
 	int i;

 	for (i = 0; i < MAX_MACVTAP_QUEUES; i++) {
-		if (rcu_dereference(vlan->taps[i]) == q)
+		if (rcu_dereference_protected(vlan->taps[i],
+					      lockdep_is_held(&macvtap_lock)) == q)
 			return i;
 	}

--

-- 
1.7.7

Michael S. Tsirkin | 12 Aug 2012 10:49
Picon
Favicon

Re: [PATCH v2] macvtap: rcu_dereference outside read-lock section

On Sun, Aug 12, 2012 at 10:26:31AM +0400, Denis Efremov wrote:
> rcu_dereference occurs in update section. Replacement by
> rcu_dereference_protected in order to prevent lockdep
> complaint.
> 
> Found by Linux Driver Verification project (linuxtesting.org)
> 
> Signed-off-by: Denis Efremov <yefremov.denis <at> gmail.com>
> ---
>  drivers/net/macvtap.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
> index 0737bd4..0f0f9ce 100644
> --- a/drivers/net/macvtap.c
> +++ b/drivers/net/macvtap.c
>  <at>  <at>  -94,7 +94,8  <at>  <at>  static int get_slot(struct macvlan_dev *vlan, struct macvtap_queue *q)
>  	int i;
>  
>  	for (i = 0; i < MAX_MACVTAP_QUEUES; i++) {
> -		if (rcu_dereference(vlan->taps[i]) == q)
> +		if (rcu_dereference_protected(vlan->taps[i],
> +					      lockdep_is_held(&macvtap_lock)) == q)

And now it's too long.  Maybe a temporary would be better?

		struct macvtap_queue *t;
		t = rcu_dereference_protected(vlan->taps[i],
					      lockdep_is_held(&macvtap_lock));
		if (t == q)
(Continue reading)

David Miller | 12 Aug 2012 22:41
Favicon

Re: [PATCH v2] macvtap: rcu_dereference outside read-lock section

From: "Michael S. Tsirkin" <mst <at> redhat.com>
Date: Sun, 12 Aug 2012 11:49:29 +0300

> On Sun, Aug 12, 2012 at 10:26:31AM +0400, Denis Efremov wrote:
>> rcu_dereference occurs in update section. Replacement by
>> rcu_dereference_protected in order to prevent lockdep
>> complaint.
>> 
>> Found by Linux Driver Verification project (linuxtesting.org)
>> 
>> Signed-off-by: Denis Efremov <yefremov.denis <at> gmail.com>
...
> Acked-by: Michael S. Tsirkin <mst <at> redhat.com>

Applied, thanks everyone.

Gmane