netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net PATCH v2] hsr: Simplify code for announcing HSR nodes timer setup
@ 2024-05-07 11:12 Lukasz Majewski
  2024-05-08 10:14 ` Simon Horman
  2024-05-09  2:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Lukasz Majewski @ 2024-05-07 11:12 UTC (permalink / raw)
  To: Jakub Kicinski, netdev, Paolo Abeni
  Cc: Eric Dumazet, Vladimir Oltean, David S. Miller, Oleksij Rempel,
	Tristram.Ha, Sebastian Andrzej Siewior, Ravi Gunasekaran,
	Simon Horman, Nikita Zhandarovich, Murali Karicheri, Arvid Brodin,
	Dan Carpenter, Ricardo B. Marliere, Casper Andersson,
	linux-kernel, Lukasz Majewski

Up till now the code to start HSR announce timer, which triggers sending
supervisory frames, was assuming that hsr_netdev_notify() would be called
at least twice for hsrX interface. This was required to have different
values for old and current values of network device's operstate.

This is problematic for a case where hsrX interface is already in the
operational state when hsr_netdev_notify() is called, so timer is not
configured to trigger and as a result the hsrX is not sending supervisory
frames to HSR ring.

This error has been discovered when hsr_ping.sh script was run. To be
more specific - for the hsr1 and hsr2 the hsr_netdev_notify() was
called at least twice with different IF_OPER_{LOWERDOWN|DOWN|UP} states
assigned in hsr_check_carrier_and_operstate(hsr). As a result there was
no issue with sending supervisory frames.
However, with hsr3, the notify function was called only once with
operstate set to IF_OPER_UP and timer responsible for triggering
supervisory frames was not fired.

The solution is to use netif_oper_up() and netif_running() helper
functions to assess if network hsrX device is up.
Only then, when the timer is not already pending, it is started.
Otherwise it is deactivated.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

Fixes: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
---
Changes for v2:

- Add extra condition to check if the hsr network device is running
  (not only up).

- Only start announce timer when it is not pending (to avoid period
  shortening/violation)
---
 net/hsr/hsr_device.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index e9d45133d641..5afc450d0855 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -61,39 +61,36 @@ static bool hsr_check_carrier(struct hsr_port *master)
 	return false;
 }
 
-static void hsr_check_announce(struct net_device *hsr_dev,
-			       unsigned char old_operstate)
+static void hsr_check_announce(struct net_device *hsr_dev)
 {
 	struct hsr_priv *hsr;
 
 	hsr = netdev_priv(hsr_dev);
-
-	if (READ_ONCE(hsr_dev->operstate) == IF_OPER_UP && old_operstate != IF_OPER_UP) {
-		/* Went up */
-		hsr->announce_count = 0;
-		mod_timer(&hsr->announce_timer,
-			  jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
+	if (netif_running(hsr_dev) && netif_oper_up(hsr_dev)) {
+		/* Enable announce timer and start sending supervisory frames */
+		if (!timer_pending(&hsr->announce_timer)) {
+			hsr->announce_count = 0;
+			mod_timer(&hsr->announce_timer, jiffies +
+				  msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
+		}
+	} else {
+		/* Deactivate the announce timer  */
+		timer_delete(&hsr->announce_timer);
 	}
-
-	if (READ_ONCE(hsr_dev->operstate) != IF_OPER_UP && old_operstate == IF_OPER_UP)
-		/* Went down */
-		del_timer(&hsr->announce_timer);
 }
 
 void hsr_check_carrier_and_operstate(struct hsr_priv *hsr)
 {
 	struct hsr_port *master;
-	unsigned char old_operstate;
 	bool has_carrier;
 
 	master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
 	/* netif_stacked_transfer_operstate() cannot be used here since
 	 * it doesn't set IF_OPER_LOWERLAYERDOWN (?)
 	 */
-	old_operstate = READ_ONCE(master->dev->operstate);
 	has_carrier = hsr_check_carrier(master);
 	hsr_set_operstate(master, has_carrier);
-	hsr_check_announce(master->dev, old_operstate);
+	hsr_check_announce(master->dev);
 }
 
 int hsr_get_max_mtu(struct hsr_priv *hsr)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net PATCH v2] hsr: Simplify code for announcing HSR nodes timer setup
  2024-05-07 11:12 [net PATCH v2] hsr: Simplify code for announcing HSR nodes timer setup Lukasz Majewski
@ 2024-05-08 10:14 ` Simon Horman
  2024-05-09  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-05-08 10:14 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Jakub Kicinski, netdev, Paolo Abeni, Eric Dumazet,
	Vladimir Oltean, David S. Miller, Oleksij Rempel, Tristram.Ha,
	Sebastian Andrzej Siewior, Ravi Gunasekaran, Nikita Zhandarovich,
	Murali Karicheri, Arvid Brodin, Dan Carpenter,
	Ricardo B. Marliere, Casper Andersson, linux-kernel

On Tue, May 07, 2024 at 01:12:14PM +0200, Lukasz Majewski wrote:
> Up till now the code to start HSR announce timer, which triggers sending
> supervisory frames, was assuming that hsr_netdev_notify() would be called
> at least twice for hsrX interface. This was required to have different
> values for old and current values of network device's operstate.
> 
> This is problematic for a case where hsrX interface is already in the
> operational state when hsr_netdev_notify() is called, so timer is not
> configured to trigger and as a result the hsrX is not sending supervisory
> frames to HSR ring.
> 
> This error has been discovered when hsr_ping.sh script was run. To be
> more specific - for the hsr1 and hsr2 the hsr_netdev_notify() was
> called at least twice with different IF_OPER_{LOWERDOWN|DOWN|UP} states
> assigned in hsr_check_carrier_and_operstate(hsr). As a result there was
> no issue with sending supervisory frames.
> However, with hsr3, the notify function was called only once with
> operstate set to IF_OPER_UP and timer responsible for triggering
> supervisory frames was not fired.
> 
> The solution is to use netif_oper_up() and netif_running() helper
> functions to assess if network hsrX device is up.
> Only then, when the timer is not already pending, it is started.
> Otherwise it is deactivated.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> 
> Fixes: f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
> ---
> Changes for v2:
> 
> - Add extra condition to check if the hsr network device is running
>   (not only up).
> 
> - Only start announce timer when it is not pending (to avoid period
>   shortening/violation)

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net PATCH v2] hsr: Simplify code for announcing HSR nodes timer setup
  2024-05-07 11:12 [net PATCH v2] hsr: Simplify code for announcing HSR nodes timer setup Lukasz Majewski
  2024-05-08 10:14 ` Simon Horman
@ 2024-05-09  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-09  2:00 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: kuba, netdev, pabeni, edumazet, olteanv, davem, o.rempel,
	Tristram.Ha, bigeasy, r-gunasekaran, horms, n.zhandarovich,
	m-karicheri2, Arvid.Brodin, dan.carpenter, ricardo, casper.casan,
	linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  7 May 2024 13:12:14 +0200 you wrote:
> Up till now the code to start HSR announce timer, which triggers sending
> supervisory frames, was assuming that hsr_netdev_notify() would be called
> at least twice for hsrX interface. This was required to have different
> values for old and current values of network device's operstate.
> 
> This is problematic for a case where hsrX interface is already in the
> operational state when hsr_netdev_notify() is called, so timer is not
> configured to trigger and as a result the hsrX is not sending supervisory
> frames to HSR ring.
> 
> [...]

Here is the summary with links:
  - [net,v2] hsr: Simplify code for announcing HSR nodes timer setup
    https://git.kernel.org/netdev/net/c/4893b8b3ef8d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-09  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-07 11:12 [net PATCH v2] hsr: Simplify code for announcing HSR nodes timer setup Lukasz Majewski
2024-05-08 10:14 ` Simon Horman
2024-05-09  2:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).