bonding: avoid repeated display of same link status change
Subsystems (3)
PATCH 1/1 bonding: avoid repeated display of same link status change
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't be taken, avoid redisplay of same link status change message.
--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +4 -2
@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(struct bonding *bond)bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n", (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) ?
@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(struct bonding *bond) commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status up for interface %s, enabling it in %d ms\n", slave->dev->name, ignore_updelay ? 0 :
@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct work_struct *work)if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; + bond->rtnl_needed = true; goto re_arm; } + bond->rtnl_needed = false;bond_for_each_slave (bond, slave, iter) {bond_commit_link_state (slave,BOND_SLAVE_NOTIFY_LATER ); }
include/net/bonding.h +1 -0
@@ -234,6 +234,7 @@ struct bonding {struct dentry *debug_dir;#endif /* CONFIG_DEBUG_FS */ struct rtnl_link_stats64 bond_stats; +bool rtnl_needed; };#define bond_slave_get_rcu (dev) \
Signature · 1 line
2.14.1
Quoted 34 lines · On 09/17/2018 12:20 AM, [email protected] wrote:
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't be taken, avoid redisplay of same link status change message.
Signed-off-by Manish Kumar Singh <[email protected]>--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +2
-2@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(struct bonding *bond)bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n", (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) ?@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(struct bonding *bond) commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status up for interface %s, enabling it in %d ms\n", slave->dev->name, ignore_updelay ? 0 :
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work) · line 2304
Quoted 4 lines
drivers/net/bonding/bond_main.c +1
-0@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct work_struct *work)if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; + bond->rtnl_needed = true;
How can you set a shared variable with no synchronization ?
A bool is particularly dangerous here, at least on some arches.
Quoted 20 lines
drivers/net/bonding/bond_main.c +1
-0goto re_arm; } + bond->rtnl_needed = false;bond_for_each_slave (bond, slave, iter) {bond_commit_link_state (slave,BOND_SLAVE_NOTIFY_LATER ); }include/net/bonding.h +1
-0@@ -234,6 +234,7 @@ struct bonding {struct dentry *debug_dir;#endif /* CONFIG_DEBUG_FS */ struct rtnl_link_stats64 bond_stats; +bool rtnl_needed; };#define bond_slave_get_rcu (dev) \
Quoted 54 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: 17 सितम्बर 2018 20:08
To: Manish Kumar Singh; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller; linux- [email protected]
Subject: Re: [PATCH] bonding: avoid repeated display of same link status changeQuoted 5 lines · On 09/17/2018 12:20 AM, [email protected] wrote:
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't be taken, avoid redisplay of same link status change message.
Review
Quoted 7 lines
Signed-off-by Manish Kumar Singh <[email protected]>--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/net/bonding/bond_main.cdrivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding
Quoted 4 lines
index
217b790d22ed..fb4e3aff1677100644drivers/net/bonding/bond_main.c +0
-0@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(struct bonding*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding *bond)
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status down for%sinterface %s, disabling it in %d ms\n",
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0(BOND_MODE (bond) == BOND_MODE_ACTIVEBACKUP) ?@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(struct bonding*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding *bond)
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status up forinterface %s, enabling it in %d ms\n",
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0slave->dev->name, ignore_updelay ? 0 :@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct
work_struct*work)
Quoted 6 lines
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work) · line 2304
Quoted 4 lines
drivers/net/bonding/bond_main.c +1
-0if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; + bond->rtnl_needed = true;How can you set a shared variable with no synchronization ?
Thanks Eric for reviewing the patch. rtnl_needed is not a shared variable, it is part of bonding structure, that is one per bonding driver instance. There can't be two parallel instances of bond_miimon_inspect for a single bonding driver instance at any given point of time. and only bond_miimon_inspect updates it. That’s why I think there is no need of any synchronization here.
Quoted 2 lines
A bool is particularly dangerous here, at least on some arches.
Thank you for cautioning us on bool usage. even a u8 can meet our requirement. we will change it. but; if time permits can you share more on "particularly dangerous here, at least on some arches".
F
Quoted 22 lines
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work)
Quoted 7 lines
drivers/net/bonding/bond_main.c +1
-0goto re_arm; } + bond->rtnl_needed = false;bond_for_each_slave (bond, slave, iter) { bond_commit_link_state(slave,
BOND_SLAVE_NOTIFY_LATER);Quoted 14 lines
drivers/net/bonding/bond_main.c +0
-0}include/net/bonding.h +1
-0@@ -234,6 +234,7 @@ struct bonding {struct dentry *debug_dir;#endif /* CONFIG_DEBUG_FS */ struct rtnl_link_stats64 bond_stats; +bool rtnl_needed; };#define bond_slave_get_rcu (dev) \
Quoted 54 lines · Manish Kumar Singh
Quoted 54 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: 17 सितम्बर 2018 20:08
To: Manish Kumar Singh; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller; linux- [email protected]
Subject: Re: [PATCH] bonding: avoid repeated display of same link status changeQuoted 5 lines · On 09/17/2018 12:20 AM, [email protected] wrote:
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't be taken, avoid redisplay of same link status change message.
Review
Quoted 7 lines
Signed-off-by Manish Kumar Singh <[email protected]>--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/net/bonding/bond_main.cdrivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding
Quoted 4 lines
index
217b790d22ed..fb4e3aff1677100644drivers/net/bonding/bond_main.c +0
-0@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(struct bonding*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding *bond)
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status down for%sinterface %s, disabling it in %d ms\n",
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0(BOND_MODE (bond) == BOND_MODE_ACTIVEBACKUP) ?@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(struct bonding*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding *bond)
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status up forinterface %s, enabling it in %d ms\n",
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0slave->dev->name, ignore_updelay ? 0 :@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct
work_struct*work)
Quoted 9 lines
Quoted 6 lines
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work) · line 2304
Quoted 4 lines
drivers/net/bonding/bond_main.c +1
-0if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; + bond->rtnl_needed = true;How can you set a shared variable with no synchronization ?
Thanks Eric for reviewing the patch.
rtnl_neededis not a shared variable, it is part of bonding structure, that is one per bonding driver instance. There can't be two parallel instances ofbond_miimon_inspectfor a single bonding driver instance at any given point of time. and onlybond_miimon_inspectupdates it. That’s why I think there is no need of any synchronization here.
If rtnl_trylock() can not grab RTNL,
there is no way the current thread can set the variable without a race, if the word including rtnl_needed is shared by other fields in the structure.
Your patch adds a subtle possibility of future bugs, even if it runs fine today.
Do not pave the way for future bugs, make your code robust, please.
Quoted 84 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: 18 सितम्बर 2018 19:30
To: Manish Kumar Singh; Eric Dumazet; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller; linux- [email protected]
Subject: Re: [PATCH] bonding: avoid repeated display of same link status changeQuoted 7 lines · Manish Kumar Singh
Quoted 7 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: 17 सितम्बर 2018 20:08
To: Manish Kumar Singh; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller;linux-
Quoted 25 lines
Quoted 25 lines
[email protected]
Subject: Re: [PATCH] bonding: avoid repeated display of same link status changeQuoted 5 lines · On 09/17/2018 12:20 AM, [email protected] wrote:
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't be taken, avoid redisplay of same link status change message.
Review
Quoted 7 lines
Signed-off-by Manish Kumar Singh <[email protected]>--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/net/bonding/bond_main.cdrivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding
Quoted 4 lines
index
217b790d22ed..fb4e3aff1677100644drivers/net/bonding/bond_main.c +0
-0@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(struct bonding*bond)
Quoted 6 lines
Quoted 6 lines
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding *bond)
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status downfor
Quoted 16 lines
Quoted 16 lines
%sinterface %s, disabling it in %d ms\n",
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0(BOND_MODE (bond) == BOND_MODE_ACTIVEBACKUP) ?@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(struct bonding*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct bonding *bond)
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status up forinterface %s, enabling it in %d ms\n",
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0slave->dev->name, ignore_updelay ? 0 :@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct
work_struct*work)Quoted 7 lines
Quoted 6 lines
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct work_struct *work) · line 2304
Quoted 4 lines
drivers/net/bonding/bond_main.c +1
-0if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; + bond->rtnl_needed = true;How can you set a shared variable with no synchronization ?
Thanks Eric for reviewing the patch.
rtnl_neededis not a shared variable, itis part of bonding structure, that is one per bonding driver instance. There can't be two parallel instances of
bond_miimon_inspectfor a single bonding driver instance at any given point of time. and onlybond_miimon_inspectupdates it. That’s why I think there is no need of any synchronization here.Quoted 2 lines
Quoted 7 lines
If
rtnl_trylock()can not grab RTNL,
there is no way the current thread can set the variable without a race, if the word includingrtnl_neededis shared by other fields in the structure.Your patch adds a subtle possibility of future bugs, even if it runs fine today.
Do not pave the way for future bugs, make your code robust, please.
Thankyou Eric, we are making the changes and will repost the patch after testing it. -Manish
Quoted 7 lines
Quoted 105 lines
-----Original Message-----
From: Manish Kumar Singh
Sent: 24 सितम्बर 2018 12:36
To: Eric Dumazet; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller; linux- [email protected]
Subject: RE: [PATCH] bonding: avoid repeated display of same link status changeQuoted 14 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: 18 सितम्बर 2018 19:30
To: Manish Kumar Singh; Eric Dumazet; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller; linux- [email protected]
Subject: Re: [PATCH] bonding: avoid repeated display of same link status changeQuoted 2 lines · Manish Kumar Singh
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: 17 सितम्बर 2018 20:08
To: Manish Kumar Singh; [email protected]
Cc: Jay Vosburgh; Veaceslav Falico; Andy Gospodarek; David S. Miller;linux-
Quoted 10 lines
Quoted 10 lines
[email protected]
Subject: Re: [PATCH] bonding: avoid repeated display of same link status changeQuoted 3 lines · On 09/17/2018 12:20 AM, [email protected] wrote:
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't
be
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
taken, avoid redisplay of same link status change message.
Signed-off-by Manish Kumar Singh <[email protected]>--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/net/bonding/bond_main.cdrivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct
Quoted 4 lines
index
217b790d22ed..fb4e3aff1677100644drivers/net/bonding/bond_main.c +0
-0@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(structbonding
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct · line 2091
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status downfor
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
%sinterface %s, disabling it in %d ms\n",
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0(BOND_MODE (bond) == BOND_MODE_ACTIVEBACKUP) ?@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(structbonding
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
*bond)
drivers/net/bonding/bond_main.c static int bond_miimon_inspect(struct · line 2131
Quoted 6 lines
drivers/net/bonding/bond_main.c +1
-1commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !bond->rtnl_needed) { netdev_info(bond->dev, "link status up forinterface %s, enabling it in %d ms\n",
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct
Quoted 3 lines
drivers/net/bonding/bond_main.c +0
-0slave->dev->name, ignore_updelay ? 0 :@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct
work_struct*work)Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/net/bonding/bond_main.c static void bond_mii_monitor(struct · line 2304
Quoted 4 lines
drivers/net/bonding/bond_main.c +1
-0if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; + bond->rtnl_needed = true;How can you set a shared variable with no synchronization ?
Thanks Eric for reviewing the patch.
rtnl_neededis not a shared variable,it
Quoted 2 lines
is part of bonding structure, that is one per bonding driver instance. There can't be two parallel instances of
bond_miimon_inspectfor asingle bonding
Quoted 7 lines
driver instance at any given point of time. and only
bond_miimon_inspectupdates it. That’s why I think there is no need of any synchronization here.Quoted 2 lines
If
rtnl_trylock()can not grab RTNL,
there is no way the current thread can set the variable without a race, ifthe
Quoted 2 lines
word including
rtnl_neededis shared by other fields in the structure.
Quoted 8 lines
Quoted 1 line
Your patch adds a subtle possibility of future bugs, even if it runs fine
today.
Quoted 2 lines
Do not pave the way for future bugs, make your code robust, please.
Thankyou Eric, we are making the changes and will repost the patch after testing it.
-Manish
Please review the updated patch, I have changed the rtnl_needed to an atomic variable, to avoid any race condition:
From: Manish Kumar Singh <[email protected]>
When link status change needs to be committed and rtnl lock couldn't be taken, avoid redisplay of same link status change message.
--- drivers/net/bonding/bond_main.c | 6 ++++-- include/net/bonding.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +4 -2
@@ -2087,7 +2087,7 @@ static int bond_miimon_inspect(struct bonding *bond)bond_propose_link_state (slave,BOND_LINK_FAIL ); commit++; slave->delay = bond->params.downdelay; -if (slave->delay) { +if (slave->delay && !atomic_read (&bond->rtnl_needed)) { netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n", (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) ?
@@ -2127,7 +2127,7 @@ static int bond_miimon_inspect(struct bonding *bond) commit++; slave->delay = bond->params.updelay; -if (slave->delay) { +if (slave->delay && !atomic_read (&bond->rtnl_needed)) { netdev_info(bond->dev, "link status up for interface %s, enabling it in %d ms\n", slave->dev->name, ignore_updelay ? 0 :
@@ -2301,9 +2301,11 @@ static void bond_mii_monitor(struct work_struct *work)if (!rtnl_trylock ()) { delay =1 ; should_notify_peers = false; +atomic_set (&bond->rtnl_needed,1 ); goto re_arm; } +atomic_set (&bond->rtnl_needed,0 );bond_for_each_slave (bond, slave, iter) {bond_commit_link_state (slave,BOND_SLAVE_NOTIFY_LATER ); }
include/net/bonding.h +1 -0
@@ -234,6 +234,7 @@ struct bonding {struct dentry *debug_dir;#endif /* CONFIG_DEBUG_FS */ struct rtnl_link_stats64 bond_stats; +atomic_t rtnl_needed; };#define bond_slave_get_rcu (dev) \
--
2.14.1
Thanks,
Manish
Quoted 7 lines
Quoted 7 lines