* [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode @ 2023-06-14 11:47 Ravi Gunasekaran 2023-06-16 5:37 ` Jakub Kicinski 2023-06-22 0:00 ` patchwork-bot+netdevbpf 0 siblings, 2 replies; 6+ messages in thread From: Ravi Gunasekaran @ 2023-06-14 11:47 UTC (permalink / raw) To: davem, edumazet, kuba, pabeni, bigeasy, simon.horman Cc: netdev, linux-kernel, rogerq, r-gunasekaran When port-to-port forwarding for interfaces in HSR node is enabled, disable promiscuous mode since L2 frame forward happens at the offloaded hardware. Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> --- Changes from v1: =============== * Changed the data type of "fwd_offloaded" from "unsigned int" to "bool" and moved it below "net_id" struct member as per Paolo's comment. * Collected Reviewed-by tag from v1 patch. v1: https://lore.kernel.org/all/20230612093933.13267-1-r-gunasekaran@ti.com/ net/hsr/hsr_device.c | 5 +++++ net/hsr/hsr_main.h | 1 + net/hsr/hsr_slave.c | 15 +++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c index 5a236aae2366..306f942c3b28 100644 --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -531,6 +531,11 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], if (res) goto err_add_master; + /* HSR forwarding offload supported in lower device? */ + if ((slave[0]->features & NETIF_F_HW_HSR_FWD) && + (slave[1]->features & NETIF_F_HW_HSR_FWD)) + hsr->fwd_offloaded = true; + res = register_netdevice(hsr_dev); if (res) goto err_unregister; diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h index 5584c80a5c79..6851e33df7d1 100644 --- a/net/hsr/hsr_main.h +++ b/net/hsr/hsr_main.h @@ -208,6 +208,7 @@ struct hsr_priv { u8 net_id; /* for PRP, it occupies most significant 3 bits * of lan_id */ + bool fwd_offloaded; /* Forwarding offloaded to HW */ unsigned char sup_multicast_addr[ETH_ALEN] __aligned(sizeof(u16)); /* Align to u16 boundary to avoid unaligned access * in ether_addr_equal diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c index b70e6bbf6021..e5742f2a2d52 100644 --- a/net/hsr/hsr_slave.c +++ b/net/hsr/hsr_slave.c @@ -131,9 +131,14 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, struct hsr_port *master; int res; - res = dev_set_promiscuity(dev, 1); - if (res) - return res; + /* Don't use promiscuous mode for offload since L2 frame forward + * happens at the offloaded hardware. + */ + if (!port->hsr->fwd_offloaded) { + res = dev_set_promiscuity(dev, 1); + if (res) + return res; + } master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); hsr_dev = master->dev; @@ -152,7 +157,9 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, fail_rx_handler: netdev_upper_dev_unlink(dev, hsr_dev); fail_upper_dev_link: - dev_set_promiscuity(dev, -1); + if (!port->hsr->fwd_offloaded) + dev_set_promiscuity(dev, -1); + return res; } -- 2.17.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode 2023-06-14 11:47 [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode Ravi Gunasekaran @ 2023-06-16 5:37 ` Jakub Kicinski 2023-06-19 11:14 ` Ido Schimmel 2023-06-22 0:00 ` patchwork-bot+netdevbpf 1 sibling, 1 reply; 6+ messages in thread From: Jakub Kicinski @ 2023-06-16 5:37 UTC (permalink / raw) To: Ido Schimmel, Nikolay Aleksandrov, Vladimir Oltean Cc: Ravi Gunasekaran, davem, edumazet, pabeni, bigeasy, simon.horman, netdev, linux-kernel, rogerq On Wed, 14 Jun 2023 17:17:10 +0530 Ravi Gunasekaran wrote: > When port-to-port forwarding for interfaces in HSR node is enabled, > disable promiscuous mode since L2 frame forward happens at the > offloaded hardware. > > Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > Reviewed-by: Simon Horman <simon.horman@corigine.com> Bridge folks any thoughts on this? Is this the behavior bridge has and if not should we try to align the two? > Changes from v1: > =============== > * Changed the data type of "fwd_offloaded" from "unsigned int" to "bool" > and moved it below "net_id" struct member as per Paolo's comment. > * Collected Reviewed-by tag from v1 patch. > > v1: https://lore.kernel.org/all/20230612093933.13267-1-r-gunasekaran@ti.com/ > > net/hsr/hsr_device.c | 5 +++++ > net/hsr/hsr_main.h | 1 + > net/hsr/hsr_slave.c | 15 +++++++++++---- > 3 files changed, 17 insertions(+), 4 deletions(-) > > diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c > index 5a236aae2366..306f942c3b28 100644 > --- a/net/hsr/hsr_device.c > +++ b/net/hsr/hsr_device.c > @@ -531,6 +531,11 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], > if (res) > goto err_add_master; > > + /* HSR forwarding offload supported in lower device? */ > + if ((slave[0]->features & NETIF_F_HW_HSR_FWD) && > + (slave[1]->features & NETIF_F_HW_HSR_FWD)) > + hsr->fwd_offloaded = true; > + > res = register_netdevice(hsr_dev); > if (res) > goto err_unregister; > diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h > index 5584c80a5c79..6851e33df7d1 100644 > --- a/net/hsr/hsr_main.h > +++ b/net/hsr/hsr_main.h > @@ -208,6 +208,7 @@ struct hsr_priv { > u8 net_id; /* for PRP, it occupies most significant 3 bits > * of lan_id > */ > + bool fwd_offloaded; /* Forwarding offloaded to HW */ > unsigned char sup_multicast_addr[ETH_ALEN] __aligned(sizeof(u16)); > /* Align to u16 boundary to avoid unaligned access > * in ether_addr_equal > diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c > index b70e6bbf6021..e5742f2a2d52 100644 > --- a/net/hsr/hsr_slave.c > +++ b/net/hsr/hsr_slave.c > @@ -131,9 +131,14 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, > struct hsr_port *master; > int res; > > - res = dev_set_promiscuity(dev, 1); > - if (res) > - return res; > + /* Don't use promiscuous mode for offload since L2 frame forward > + * happens at the offloaded hardware. > + */ > + if (!port->hsr->fwd_offloaded) { > + res = dev_set_promiscuity(dev, 1); > + if (res) > + return res; > + } > > master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); > hsr_dev = master->dev; > @@ -152,7 +157,9 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, > fail_rx_handler: > netdev_upper_dev_unlink(dev, hsr_dev); > fail_upper_dev_link: > - dev_set_promiscuity(dev, -1); > + if (!port->hsr->fwd_offloaded) > + dev_set_promiscuity(dev, -1); > + > return res; > } > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode 2023-06-16 5:37 ` Jakub Kicinski @ 2023-06-19 11:14 ` Ido Schimmel 2023-06-19 12:07 ` Ravi Gunasekaran 0 siblings, 1 reply; 6+ messages in thread From: Ido Schimmel @ 2023-06-19 11:14 UTC (permalink / raw) To: r-gunasekaran Cc: kuba, Nikolay Aleksandrov, Vladimir Oltean, Ravi Gunasekaran, davem, edumazet, pabeni, bigeasy, simon.horman, netdev, linux-kernel, rogerq On Thu, Jun 15, 2023 at 10:37:36PM -0700, Jakub Kicinski wrote: > On Wed, 14 Jun 2023 17:17:10 +0530 Ravi Gunasekaran wrote: > > When port-to-port forwarding for interfaces in HSR node is enabled, > > disable promiscuous mode since L2 frame forward happens at the > > offloaded hardware. It's not clear to me why you want to disable promiscuous mode. I'm not familiar with HSR, but I assume you want the hardware to forward all the packets between the two ports and not only specific DMACs. How does the underlying device implement "promiscuous mode" that you benefit from disabling it? Thanks > > > > Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > > Reviewed-by: Simon Horman <simon.horman@corigine.com> > > Bridge folks any thoughts on this? Is this the behavior bridge has > and if not should we try to align the two? > > > Changes from v1: > > =============== > > * Changed the data type of "fwd_offloaded" from "unsigned int" to "bool" > > and moved it below "net_id" struct member as per Paolo's comment. > > * Collected Reviewed-by tag from v1 patch. > > > > v1: https://lore.kernel.org/all/20230612093933.13267-1-r-gunasekaran@ti.com/ > > > > net/hsr/hsr_device.c | 5 +++++ > > net/hsr/hsr_main.h | 1 + > > net/hsr/hsr_slave.c | 15 +++++++++++---- > > 3 files changed, 17 insertions(+), 4 deletions(-) > > > > diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c > > index 5a236aae2366..306f942c3b28 100644 > > --- a/net/hsr/hsr_device.c > > +++ b/net/hsr/hsr_device.c > > @@ -531,6 +531,11 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], > > if (res) > > goto err_add_master; > > > > + /* HSR forwarding offload supported in lower device? */ > > + if ((slave[0]->features & NETIF_F_HW_HSR_FWD) && > > + (slave[1]->features & NETIF_F_HW_HSR_FWD)) > > + hsr->fwd_offloaded = true; > > + > > res = register_netdevice(hsr_dev); > > if (res) > > goto err_unregister; > > diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h > > index 5584c80a5c79..6851e33df7d1 100644 > > --- a/net/hsr/hsr_main.h > > +++ b/net/hsr/hsr_main.h > > @@ -208,6 +208,7 @@ struct hsr_priv { > > u8 net_id; /* for PRP, it occupies most significant 3 bits > > * of lan_id > > */ > > + bool fwd_offloaded; /* Forwarding offloaded to HW */ > > unsigned char sup_multicast_addr[ETH_ALEN] __aligned(sizeof(u16)); > > /* Align to u16 boundary to avoid unaligned access > > * in ether_addr_equal > > diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c > > index b70e6bbf6021..e5742f2a2d52 100644 > > --- a/net/hsr/hsr_slave.c > > +++ b/net/hsr/hsr_slave.c > > @@ -131,9 +131,14 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, > > struct hsr_port *master; > > int res; > > > > - res = dev_set_promiscuity(dev, 1); > > - if (res) > > - return res; > > + /* Don't use promiscuous mode for offload since L2 frame forward > > + * happens at the offloaded hardware. > > + */ > > + if (!port->hsr->fwd_offloaded) { > > + res = dev_set_promiscuity(dev, 1); > > + if (res) > > + return res; > > + } > > > > master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); > > hsr_dev = master->dev; > > @@ -152,7 +157,9 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, > > fail_rx_handler: > > netdev_upper_dev_unlink(dev, hsr_dev); > > fail_upper_dev_link: > > - dev_set_promiscuity(dev, -1); > > + if (!port->hsr->fwd_offloaded) > > + dev_set_promiscuity(dev, -1); > > + > > return res; > > } > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode 2023-06-19 11:14 ` Ido Schimmel @ 2023-06-19 12:07 ` Ravi Gunasekaran 2023-06-27 12:19 ` Vladimir Oltean 0 siblings, 1 reply; 6+ messages in thread From: Ravi Gunasekaran @ 2023-06-19 12:07 UTC (permalink / raw) To: Ido Schimmel Cc: kuba, Nikolay Aleksandrov, Vladimir Oltean, davem, edumazet, pabeni, bigeasy, simon.horman, netdev, linux-kernel, rogerq On 6/19/23 4:44 PM, Ido Schimmel wrote: > On Thu, Jun 15, 2023 at 10:37:36PM -0700, Jakub Kicinski wrote: >> On Wed, 14 Jun 2023 17:17:10 +0530 Ravi Gunasekaran wrote: >>> When port-to-port forwarding for interfaces in HSR node is enabled, >>> disable promiscuous mode since L2 frame forward happens at the >>> offloaded hardware. > > It's not clear to me why you want to disable promiscuous mode. I'm not > familiar with HSR, but I assume you want the hardware to forward all the > packets between the two ports and not only specific DMACs. > > How does the underlying device implement "promiscuous mode" that you > benefit from disabling it? While creating an HSR interface using two slave nodes, the promiscuous mode is set via dev_set_promiscuity() in hsr_portdev_setup() for both the ports. And then in the HSR driver, a packet is forwarded to the other slave port (physical port) and also the HSR master if it is intended for it. Before forwarding, a check is done in static void hsr_forward_do(struct hsr_frame_info *frame) { ... if (hsr->proto_ops->drop_frame && hsr->proto_ops->drop_frame(frame, port)) continue; ... } And the drop_frame callback is as below bool hsr_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port) { if (port->dev->features & NETIF_F_HW_HSR_FWD) return prp_drop_frame(frame, port); return false; } The driver drops these packets and does not forward to any port at all. But since promiscuous mode is enabled, CPU cycles are consumed. So benefit of disabling promiscuous mode is saving CPU cycles. So in this patch, I check for NETIF_F_HW_HSR_FWD and then take a call to enable/disable the promiscuous mode during HSR interface creation. > > Thanks > >>> >>> Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com> >>> Reviewed-by: Simon Horman <simon.horman@corigine.com> >> >> Bridge folks any thoughts on this? Is this the behavior bridge has >> and if not should we try to align the two? >> >>> Changes from v1: >>> =============== >>> * Changed the data type of "fwd_offloaded" from "unsigned int" to "bool" >>> and moved it below "net_id" struct member as per Paolo's comment. >>> * Collected Reviewed-by tag from v1 patch. >>> >>> v1: https://lore.kernel.org/all/20230612093933.13267-1-r-gunasekaran@ti.com/ >>> >>> net/hsr/hsr_device.c | 5 +++++ >>> net/hsr/hsr_main.h | 1 + >>> net/hsr/hsr_slave.c | 15 +++++++++++---- >>> 3 files changed, 17 insertions(+), 4 deletions(-) >>> >>> diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c >>> index 5a236aae2366..306f942c3b28 100644 >>> --- a/net/hsr/hsr_device.c >>> +++ b/net/hsr/hsr_device.c >>> @@ -531,6 +531,11 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], >>> if (res) >>> goto err_add_master; >>> >>> + /* HSR forwarding offload supported in lower device? */ >>> + if ((slave[0]->features & NETIF_F_HW_HSR_FWD) && >>> + (slave[1]->features & NETIF_F_HW_HSR_FWD)) >>> + hsr->fwd_offloaded = true; >>> + >>> res = register_netdevice(hsr_dev); >>> if (res) >>> goto err_unregister; >>> diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h >>> index 5584c80a5c79..6851e33df7d1 100644 >>> --- a/net/hsr/hsr_main.h >>> +++ b/net/hsr/hsr_main.h >>> @@ -208,6 +208,7 @@ struct hsr_priv { >>> u8 net_id; /* for PRP, it occupies most significant 3 bits >>> * of lan_id >>> */ >>> + bool fwd_offloaded; /* Forwarding offloaded to HW */ >>> unsigned char sup_multicast_addr[ETH_ALEN] __aligned(sizeof(u16)); >>> /* Align to u16 boundary to avoid unaligned access >>> * in ether_addr_equal >>> diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c >>> index b70e6bbf6021..e5742f2a2d52 100644 >>> --- a/net/hsr/hsr_slave.c >>> +++ b/net/hsr/hsr_slave.c >>> @@ -131,9 +131,14 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, >>> struct hsr_port *master; >>> int res; >>> >>> - res = dev_set_promiscuity(dev, 1); >>> - if (res) >>> - return res; >>> + /* Don't use promiscuous mode for offload since L2 frame forward >>> + * happens at the offloaded hardware. >>> + */ >>> + if (!port->hsr->fwd_offloaded) { >>> + res = dev_set_promiscuity(dev, 1); >>> + if (res) >>> + return res; >>> + } >>> >>> master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); >>> hsr_dev = master->dev; >>> @@ -152,7 +157,9 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, >>> fail_rx_handler: >>> netdev_upper_dev_unlink(dev, hsr_dev); >>> fail_upper_dev_link: >>> - dev_set_promiscuity(dev, -1); >>> + if (!port->hsr->fwd_offloaded) >>> + dev_set_promiscuity(dev, -1); >>> + >>> return res; >>> } >>> >> -- Regards, Ravi ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode 2023-06-19 12:07 ` Ravi Gunasekaran @ 2023-06-27 12:19 ` Vladimir Oltean 0 siblings, 0 replies; 6+ messages in thread From: Vladimir Oltean @ 2023-06-27 12:19 UTC (permalink / raw) To: Ravi Gunasekaran Cc: Ido Schimmel, kuba, Nikolay Aleksandrov, davem, edumazet, pabeni, bigeasy, simon.horman, netdev, linux-kernel, rogerq On Mon, Jun 19, 2023 at 05:37:16PM +0530, Ravi Gunasekaran wrote: > > It's not clear to me why you want to disable promiscuous mode. I'm not > > familiar with HSR, but I assume you want the hardware to forward all the > > packets between the two ports and not only specific DMACs. > > > > How does the underlying device implement "promiscuous mode" that you > > benefit from disabling it? > > While creating an HSR interface using two slave nodes, the promiscuous mode > is set via dev_set_promiscuity() in hsr_portdev_setup() for both the ports. > And then in the HSR driver, a packet is forwarded to the other > slave port (physical port) and also the HSR master if it is intended for it. > > Before forwarding, a check is done in > > static void hsr_forward_do(struct hsr_frame_info *frame) > { > ... > > if (hsr->proto_ops->drop_frame && > hsr->proto_ops->drop_frame(frame, port)) > continue; > > ... > } > > And the drop_frame callback is as below > > bool hsr_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port) > { > if (port->dev->features & NETIF_F_HW_HSR_FWD) > return prp_drop_frame(frame, port); > > return false; > } > > > The driver drops these packets and does not forward to any port at all. > But since promiscuous mode is enabled, CPU cycles are consumed. So benefit > of disabling promiscuous mode is saving CPU cycles. > > So in this patch, I check for NETIF_F_HW_HSR_FWD and then take a > call to enable/disable the promiscuous mode during HSR interface creation. Can the hardware be configured to not send to the CPU packets that the CPU is going to drop anyway? IFF_PROMISC is about receiving packets with any MAC DA, not about sending all packets to the CPU. With offloading drivers, there is a difference between the 2, because the RX path of a port is not necessarily the same as the CPU receive path - the destination of a packet can simply be another port. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode 2023-06-14 11:47 [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode Ravi Gunasekaran 2023-06-16 5:37 ` Jakub Kicinski @ 2023-06-22 0:00 ` patchwork-bot+netdevbpf 1 sibling, 0 replies; 6+ messages in thread From: patchwork-bot+netdevbpf @ 2023-06-22 0:00 UTC (permalink / raw) To: Ravi Gunasekaran Cc: davem, edumazet, kuba, pabeni, bigeasy, simon.horman, netdev, linux-kernel, rogerq Hello: This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <kuba@kernel.org>: On Wed, 14 Jun 2023 17:17:10 +0530 you wrote: > When port-to-port forwarding for interfaces in HSR node is enabled, > disable promiscuous mode since L2 frame forward happens at the > offloaded hardware. > > Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com> > Reviewed-by: Simon Horman <simon.horman@corigine.com> > > [...] Here is the summary with links: - [v2,net-next] net: hsr: Disable promiscuous mode in offload mode https://git.kernel.org/netdev/net-next/c/e748d0fd66ab 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] 6+ messages in thread
end of thread, other threads:[~2023-06-27 12:20 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-06-14 11:47 [PATCH v2 net-next] net: hsr: Disable promiscuous mode in offload mode Ravi Gunasekaran 2023-06-16 5:37 ` Jakub Kicinski 2023-06-19 11:14 ` Ido Schimmel 2023-06-19 12:07 ` Ravi Gunasekaran 2023-06-27 12:19 ` Vladimir Oltean 2023-06-22 0: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).