Skip to contentSkip to conversation

switchdev: fix BUG when port driver doesn't support set attr op

PATCH Superseded [email protected] 5 participants 10 messages Jun 10, 2015 – Jun 11, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 switchdev: fix BUG when port driver doesn't support set attr op

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
 net/switchdev/switchdev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
index e008057..99bced4 100644
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct work_struct *work)
 
 	rtnl_lock();
 	err = switchdev_port_attr_set(asw->dev, &asw->attr);
-	BUG_ON(err);
+	BUG_ON(err && err != -EOPNOTSUPP);
 	rtnl_unlock();
 
 	dev_put(asw->dev);
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Wed, Jun 10, 2015 at 01:56:02PM -0700, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

Looks good since -EOPNOTSUPP seems to be the safe failure case when switchdev is enabled or not.

#2 lore raw
In reply to [email protected]
Quoted 18 lines · On 6/10/15 2:56 PM, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
  net/switchdev/switchdev.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +0 -0
index e008057..99bced4 100644

net/switchdev/switchdev.c static void switchdev_port_attr_set_work(struct work_struct *work) · line 109

Quoted 8 lines
net/switchdev/switchdev.c +1 -1
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct work_struct *work)
 
  	rtnl_lock();
  	err = switchdev_port_attr_set(asw->dev, &asw->attr);
-	BUG_ON(err);
+	BUG_ON(err && err != -EOPNOTSUPP);
  	rtnl_unlock();
 
  	dev_put(asw->dev);

Should that be WARN_ON instead of BUG_ON?

#3 lore raw
Quoted 27 lines · David Ahern
Quoted 26 lines · On 6/10/15 2:56 PM, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
  net/switchdev/switchdev.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
index e008057..99bced4 100644
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct
 work_struct *work)
 
        rtnl_lock();
        err = switchdev_port_attr_set(asw->dev, &asw->attr);
-       BUG_ON(err);
+       BUG_ON(err && err != -EOPNOTSUPP);
        rtnl_unlock();
 
Quoted 4 lines
Quoted 2 lines
        dev_put(asw->dev);

Should that be WARN_ON instead of BUG_ON?

I think I had it as WARN when we were working on the initial patches, but we changed it to BUG_ON because we should only get an error here if the driver screwed something up between PREPARE phase and COMMIT phase, so it should be considered a driver bug which needs fixing.

#4 lore raw
Quoted 7 lines · Scott Feldman
Quoted 1 line

Should that be WARN_ON instead of BUG_ON?

I think I had it as WARN when we were working on the initial patches, but we changed it to BUG_ON because we should only get an error here if the driver screwed something up between PREPARE phase and COMMIT phase, so it should be considered a driver bug which needs fixing.

Linus rants from time to time about the prolific use of BUG_ON. e.g.,

    https://lkml.org/lkml/2015/4/28/528

'BUG_ON() is for things where our internal data structures are so corrupted that we don't know what to do, and there's no way to continue. Not for "I want to sprinkle these things around and this should not happen".'

David

#5 lore raw
In reply to Scott Feldman
Quoted 33 lines · Scott Feldman
Quoted 27 lines · David Ahern
Quoted 26 lines · On 6/10/15 2:56 PM, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
  net/switchdev/switchdev.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
index e008057..99bced4 100644
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct
 work_struct *work)
 
        rtnl_lock();
        err = switchdev_port_attr_set(asw->dev, &asw->attr);
-       BUG_ON(err);
+       BUG_ON(err && err != -EOPNOTSUPP);
        rtnl_unlock();
 
Quoted 4 lines
Quoted 2 lines
        dev_put(asw->dev);

Should that be WARN_ON instead of BUG_ON?

Quoted 4 lines

I think I had it as WARN when we were working on the initial patches, but we changed it to BUG_ON because we should only get an error here if the driver screwed something up between PREPARE phase and COMMIT phase, so it should be considered a driver bug which needs fixing.

Actually, ignore what I said above. I was confusing this BUG_ON with the one in switchdev_port_attr_set(). Perhaps this BUG_ON() you're commenting on should be WARN(). A driver could return an err in PREPARE phase and that shouldn't be a BUG_ON situation; seems WARN
would be better. It the case where the driver returns an err in
COMMIT phase but didn't return an err in PREPARE phase we want to BUG_ON(). Maybe that case doesn't justify BUG_ON either, based on the link you posted.

Jiri, IIRC, you suggested the BUG_ON(). Does it still sound right based on the point David is raising?

-scott

maintainer
#6 lore raw
Quoted 48 lines · Thu, Jun 11, 2015 at 12:00:47AM CEST, [email protected] wrote:
Quoted 33 lines · Scott Feldman
Quoted 27 lines · David Ahern
Quoted 26 lines · On 6/10/15 2:56 PM, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
  net/switchdev/switchdev.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
index e008057..99bced4 100644
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct
 work_struct *work)
 
        rtnl_lock();
        err = switchdev_port_attr_set(asw->dev, &asw->attr);
-       BUG_ON(err);
+       BUG_ON(err && err != -EOPNOTSUPP);
        rtnl_unlock();
 
Quoted 4 lines
Quoted 2 lines
        dev_put(asw->dev);

Should that be WARN_ON instead of BUG_ON?

Quoted 4 lines

I think I had it as WARN when we were working on the initial patches, but we changed it to BUG_ON because we should only get an error here if the driver screwed something up between PREPARE phase and COMMIT phase, so it should be considered a driver bug which needs fixing.

Actually, ignore what I said above. I was confusing this BUG_ON with the one in switchdev_port_attr_set(). Perhaps this BUG_ON() you're commenting on should be WARN(). A driver could return an err in PREPARE phase and that shouldn't be a BUG_ON situation; seems WARN
would be better. It the case where the driver returns an err in
COMMIT phase but didn't return an err in PREPARE phase we want to BUG_ON(). Maybe that case doesn't justify BUG_ON either, based on the link you posted.

Quoted 2 lines

Jiri, IIRC, you suggested the BUG_ON(). Does it still sound right based on the point David is raising?

Hmm, looking at code of switchdev_port_attr_set. In case that fails in prepare state (which can easily happen for example due to -ENOMEM) this BUG_ON is hit as well. That is not right. I think we should change it just to warning. Also I think that prink (or a flavour) is more suitable here than WARN.

Btw, why switchdev_port_obj_add has WARN and not BUG ?

maintainer
#9 lore raw
In reply to [email protected]

From: [email protected]
Date: Wed, 10 Jun 2015 13:56:02 -0700

Quoted 17 lines

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
 net/switchdev/switchdev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +0 -0
index e008057..99bced4 100644

net/switchdev/switchdev.c static void switchdev_port_attr_set_work(struct work_struct *work) · line 109

Quoted 8 lines
net/switchdev/switchdev.c +1 -1
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct work_struct *work)
 
 	rtnl_lock();
 	err = switchdev_port_attr_set(asw->dev, &asw->attr);
-	BUG_ON(err);
+	BUG_ON(err && err != -EOPNOTSUPP);
 	rtnl_unlock();
 
 	dev_put(asw->dev);

I agree with other feedback, in that this function can return other "normal" errors like -ENOMEM and that's not absolutely not BUG_ON() material.

#7 lore raw
In reply to Jiri Pirko
Quoted 49 lines · Jiri Pirko
Quoted 48 lines · Thu, Jun 11, 2015 at 12:00:47AM CEST, [email protected] wrote:
Quoted 33 lines · Scott Feldman
Quoted 27 lines · David Ahern
Quoted 26 lines · On 6/10/15 2:56 PM, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
  net/switchdev/switchdev.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
index e008057..99bced4 100644
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct
 work_struct *work)
 
        rtnl_lock();
        err = switchdev_port_attr_set(asw->dev, &asw->attr);
-       BUG_ON(err);
+       BUG_ON(err && err != -EOPNOTSUPP);
        rtnl_unlock();
 
Quoted 4 lines
Quoted 2 lines
        dev_put(asw->dev);

Should that be WARN_ON instead of BUG_ON?

Quoted 4 lines

I think I had it as WARN when we were working on the initial patches, but we changed it to BUG_ON because we should only get an error here if the driver screwed something up between PREPARE phase and COMMIT phase, so it should be considered a driver bug which needs fixing.

Actually, ignore what I said above. I was confusing this BUG_ON with the one in switchdev_port_attr_set(). Perhaps this BUG_ON() you're commenting on should be WARN(). A driver could return an err in PREPARE phase and that shouldn't be a BUG_ON situation; seems WARN
would be better. It the case where the driver returns an err in
COMMIT phase but didn't return an err in PREPARE phase we want to BUG_ON(). Maybe that case doesn't justify BUG_ON either, based on the link you posted.

Quoted 8 lines
Quoted 2 lines

Jiri, IIRC, you suggested the BUG_ON(). Does it still sound right based on the point David is raising?

Hmm, looking at code of switchdev_port_attr_set. In case that fails in prepare state (which can easily happen for example due to -ENOMEM) this BUG_ON is hit as well. That is not right. I think we should change it just to warning. Also I think that prink (or a flavour) is more suitable here than WARN.

Thanks, I'll change it to netdev_err.

Quoted 1 line

Btw, why switchdev_port_obj_add has WARN and not BUG ?

Not sure. We should be consistent. WARN seems better for both obj_add/attr_set than BUG, given the link David Ahern posted. Do you agree?

maintainer
#8 lore raw
Quoted 59 lines · Thu, Jun 11, 2015 at 05:03:21PM CEST, [email protected] wrote:
Quoted 49 lines · Jiri Pirko
Quoted 48 lines · Thu, Jun 11, 2015 at 12:00:47AM CEST, [email protected] wrote:
Quoted 33 lines · Scott Feldman
Quoted 27 lines · David Ahern
Quoted 26 lines · On 6/10/15 2:56 PM, [email protected] wrote:

From: Scott Feldman <[email protected]>

Fix a BUG() where CONFIG_NET_SWITCHDEV is set but the driver for a bridged port does not support switchdec_port_attr_set op. Don't BUG() if -EOPNOTSUPP is returned.

---
  net/switchdev/switchdev.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
index e008057..99bced4 100644
@@ -103,7 +103,7 @@ static void switchdev_port_attr_set_work(struct
 work_struct *work)
 
        rtnl_lock();
        err = switchdev_port_attr_set(asw->dev, &asw->attr);
-       BUG_ON(err);
+       BUG_ON(err && err != -EOPNOTSUPP);
        rtnl_unlock();
 
Quoted 4 lines
Quoted 2 lines
        dev_put(asw->dev);

Should that be WARN_ON instead of BUG_ON?

Quoted 4 lines

I think I had it as WARN when we were working on the initial patches, but we changed it to BUG_ON because we should only get an error here if the driver screwed something up between PREPARE phase and COMMIT phase, so it should be considered a driver bug which needs fixing.

Actually, ignore what I said above. I was confusing this BUG_ON with the one in switchdev_port_attr_set(). Perhaps this BUG_ON() you're commenting on should be WARN(). A driver could return an err in PREPARE phase and that shouldn't be a BUG_ON situation; seems WARN
would be better. It the case where the driver returns an err in
COMMIT phase but didn't return an err in PREPARE phase we want to BUG_ON(). Maybe that case doesn't justify BUG_ON either, based on the link you posted.

Quoted 8 lines
Quoted 2 lines

Jiri, IIRC, you suggested the BUG_ON(). Does it still sound right based on the point David is raising?

Hmm, looking at code of switchdev_port_attr_set. In case that fails in prepare state (which can easily happen for example due to -ENOMEM) this BUG_ON is hit as well. That is not right. I think we should change it just to warning. Also I think that prink (or a flavour) is more suitable here than WARN.

Quoted 7 lines

Thanks, I'll change it to netdev_err.

Quoted 1 line

Btw, why switchdev_port_obj_add has WARN and not BUG ?

Not sure. We should be consistent. WARN seems better for both obj_add/attr_set than BUG, given the link David Ahern posted. Do you agree?

Okay. Sounds reasonable.