Skip to contentSkip to conversation

vhost: rcu annotation fixup

PATCH Superseded Michael S. Tsirkin 3 participants 8 messages Jan 18, 2011 – Jan 19, 2011

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vhost: rcu annotation fixup

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

---
 drivers/vhost/vhost.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/vhost/vhost.h +1 -3
index 2af44b7..2d03a31 100644
@@ -173,9 +173,7 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 {
 	unsigned acked_features;
 
-	acked_features =
-		rcu_dereference_index_check(dev->acked_features,
-					    lockdep_is_held(&dev->mutex));
+	acked_features = rcu_dereference_index_check(dev->acked_features, 1);
 	return acked_features & (1 << bit);
 }
 
Signature · 1 line
1.7.3.2.91.g446ac
#1 lore raw
Quoted 17 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

---
 drivers/vhost/vhost.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/vhost/vhost.h +0 -0
index 2af44b7..2d03a31 100644

drivers/vhost/vhost.h static inline int vhost_has_feature(struct vhost_dev *dev, int bit) · line 176

Quoted 7 lines
drivers/vhost/vhost.h +1 -3
@@ -173,9 +173,7 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 {
 	unsigned acked_features;
 
-	acked_features =
-		rcu_dereference_index_check(dev->acked_features,
-					    lockdep_is_held(&dev->mutex));
+	acked_features = rcu_dereference_index_check(dev->acked_features, 1);

Ouch!!!

Could you please at least add a comment?

Alternatively, pass in the lock that is held and check for that? Given that this is a static inline, the compiler should be able to optimize the argument away when !PROVE_RCU, correct?

Thanx, Paul

Quoted 10 lines
drivers/vhost/vhost.h +0 -0
 	return acked_features & (1 << bit);
 }
 
Signature · 6 lines
1.7.3.2.91.g446ac
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
author maintainer
#2 lore raw
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

---
 drivers/vhost/vhost.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/vhost/vhost.h +0 -0
index 2af44b7..2d03a31 100644
@@ -173,9 +173,7 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 {
 	unsigned acked_features;
 
Quoted 8 lines

drivers/vhost/vhost.h static inline int vhost_has_feature(struct vhost_dev *dev, int bit) · line 176

Quoted 4 lines
drivers/vhost/vhost.h +1 -3
-	acked_features =
-		rcu_dereference_index_check(dev->acked_features,
-					    lockdep_is_held(&dev->mutex));
+	acked_features = rcu_dereference_index_check(dev->acked_features, 1);

Ouch!!!

Could you please at least add a comment?

Yes, OK.

Quoted 5 lines

Alternatively, pass in the lock that is held and check for that? Given that this is a static inline, the compiler should be able to optimize the argument away when !PROVE_RCU, correct?

Thanx, Paul

Hopefully, yes. We don't always have a lock: the idea was to create a lockdep for these cases. But we can't pass the pointer to that ...

Quoted 10 lines
Quoted 10 lines
drivers/vhost/vhost.h +0 -0
 	return acked_features & (1 << bit);
 }
 
Signature · 6 lines
1.7.3.2.91.g446ac
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#3 lore raw
Quoted 37 lines · Michael S. Tsirkin
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

---
 drivers/vhost/vhost.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/vhost/vhost.h +0 -0
index 2af44b7..2d03a31 100644
@@ -173,9 +173,7 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 {
 	unsigned acked_features;
 
Quoted 8 lines

drivers/vhost/vhost.h static inline int vhost_has_feature(struct vhost_dev *dev, int bit) · line 176

Quoted 4 lines
drivers/vhost/vhost.h +1 -3
-	acked_features =
-		rcu_dereference_index_check(dev->acked_features,
-					    lockdep_is_held(&dev->mutex));
+	acked_features = rcu_dereference_index_check(dev->acked_features, 1);

Ouch!!!

Could you please at least add a comment?

Yes, OK.

Quoted 4 lines

Alternatively, pass in the lock that is held and check for that? Given that this is a static inline, the compiler should be able to optimize the argument away when !PROVE_RCU, correct?

Quoted 5 lines
Quoted 1 line

Thanx, Paul

Hopefully, yes. We don't always have a lock: the idea was to create a lockdep for these cases. But we can't pass the pointer to that ...

I suppose you could pass a pointer to the lockdep map structure. Not sure if this makes sense, but it would handle the situation.

Alternatively, create a helper function that checks the possibilities and screams if none of them are in effect.

Thanx, Paul

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/vhost/vhost.h +0 -0
 	return acked_features & (1 << bit);
 }
 
Signature · 6 lines
1.7.3.2.91.g446ac
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
author maintainer
#4 lore raw
Quoted 38 lines · Paul E. McKenney
Quoted 37 lines · Michael S. Tsirkin
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

---
 drivers/vhost/vhost.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/vhost/vhost.h +0 -0
index 2af44b7..2d03a31 100644
@@ -173,9 +173,7 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 {
 	unsigned acked_features;
 
Quoted 8 lines

drivers/vhost/vhost.h static inline int vhost_has_feature(struct vhost_dev *dev, int bit) · line 176

Quoted 4 lines
drivers/vhost/vhost.h +1 -3
-	acked_features =
-		rcu_dereference_index_check(dev->acked_features,
-					    lockdep_is_held(&dev->mutex));
+	acked_features = rcu_dereference_index_check(dev->acked_features, 1);

Ouch!!!

Could you please at least add a comment?

Yes, OK.

Quoted 4 lines

Alternatively, pass in the lock that is held and check for that? Given that this is a static inline, the compiler should be able to optimize the argument away when !PROVE_RCU, correct?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanx, Paul

Hopefully, yes. We don't always have a lock: the idea was to create a lockdep for these cases. But we can't pass the pointer to that ...

I suppose you could pass a pointer to the lockdep map structure. Not sure if this makes sense, but it would handle the situation.

Will it compile with lockdep disabled too? What will the pointer be?

Quoted 4 lines

Alternatively, create a helper function that checks the possibilities and screams if none of them are in effect.

Thanx, Paul

The problem here is the callee needs to know about all callers.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/vhost/vhost.h +0 -0
 	return acked_features & (1 << bit);
 }
 
Signature · 6 lines
1.7.3.2.91.g446ac
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#5 lore raw
Quoted 41 lines · Michael S. Tsirkin
Quoted 40 lines · Paul E. McKenney
Quoted 39 lines · Michael S. Tsirkin
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

---
 drivers/vhost/vhost.h |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/vhost/vhost.h +0 -0
index 2af44b7..2d03a31 100644
@@ -173,9 +173,7 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
 {
 	unsigned acked_features;
 
Quoted 8 lines

drivers/vhost/vhost.h static inline int vhost_has_feature(struct vhost_dev *dev, int bit) · line 176

Quoted 4 lines
drivers/vhost/vhost.h +1 -3
-	acked_features =
-		rcu_dereference_index_check(dev->acked_features,
-					    lockdep_is_held(&dev->mutex));
+	acked_features = rcu_dereference_index_check(dev->acked_features, 1);

Ouch!!!

Could you please at least add a comment?

Yes, OK.

Quoted 5 lines

Alternatively, pass in the lock that is held and check for that? Given that this is a static inline, the compiler should be able to optimize the argument away when !PROVE_RCU, correct?

Thanx, Paul

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Hopefully, yes. We don't always have a lock: the idea was to create a lockdep for these cases. But we can't pass the pointer to that ...

I suppose you could pass a pointer to the lockdep map structure. Not sure if this makes sense, but it would handle the situation.

Will it compile with lockdep disabled too? What will the pointer be?

One (crude) approach would be to make the pointer void* if lockdep is disabled.

Quoted 6 lines
Quoted 4 lines

Alternatively, create a helper function that checks the possibilities and screams if none of them are in effect.

Thanx, Paul

The problem here is the callee needs to know about all callers.

As does the guy reading the code. ;-)

Thanx, Paul

Quoted 15 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/vhost/vhost.h +0 -0
 	return acked_features & (1 << bit);
 }
 
Signature · 6 lines
1.7.3.2.91.g446ac
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#6 lore raw
In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

What is the harm in leaving the bogus warnings until the difficult fix happens? RCU checks enabled does not seem like something that is enabled in production. If this patch is applied, there is always the risk that it'll be simply forgotten about.

Signature · 3 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab
author maintainer
#7 lore raw
Quoted 9 lines · Mel Gorman
Quoted 7 lines · Michael S. Tsirkin

When built with rcu checks enabled, vhost triggers bogus warnings as vhost features are read without dev->mutex sometimes.
Fixing it properly is not trivial as vhost.h does not know which lockdep classes it will be used under. Disable the warning by stubbing out the check for now.

Quoted 3 lines

What is the harm in leaving the bogus warnings until the difficult fix happens? RCU checks enabled does not seem like something that is enabled in production.

I would like to run with rcu checks enabled sometimes to debug kvm, which has an elaborate rcu strategy. Bogus warnings in the log make it easy to overlook the real ones. Further, the rcu macros used are a form of documentation. If we have
- rcu_dereference_index_check(dev->acked_features,
- lockdep_is_held(&dev->mutex));
this means 'taken in rcu read side critical section or under mutex',

+ acked_features = rcu_dereference_index_check(dev->acked_features, 1);
means 'not checked'.

Quoted 2 lines

If this patch is applied, there is always the risk that it'll be simply forgotten about.

Well, that's why I put in a TODO.
If there's a demand for that, I can add a Kconfig option to trigger a warning at each unchecked rcu call in vhost-net but I doubt it'll get a lof of use :)

Quoted 4 lines
Signature · 3 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab