2024-03-01 13:44:26

by Breno Leitao

[permalink] [raw]
Subject: [PATCH net-next 1/2] net: nlmon: Remove init and uninit functions

With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
convert veth & vrf"), stats allocation could be done on net core
instead of this driver.

With this new approach, the driver doesn't have to bother with error
handling (allocation failure checking, making sure free happens in the
right spot, etc). This is core responsibility now.

Remove the allocation in the nlmon driver and leverage the network
core allocation.

Signed-off-by: Breno Leitao <[email protected]>
---
drivers/net/nlmon.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
index 5e19a6839dea..e026bfc83757 100644
--- a/drivers/net/nlmon.c
+++ b/drivers/net/nlmon.c
@@ -17,17 +17,6 @@ static netdev_tx_t nlmon_xmit(struct sk_buff *skb, struct net_device *dev)
return NETDEV_TX_OK;
}

-static int nlmon_dev_init(struct net_device *dev)
-{
- dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
- return dev->lstats == NULL ? -ENOMEM : 0;
-}
-
-static void nlmon_dev_uninit(struct net_device *dev)
-{
- free_percpu(dev->lstats);
-}
-
struct nlmon {
struct netlink_tap nt;
};
@@ -72,8 +61,6 @@ static const struct ethtool_ops nlmon_ethtool_ops = {
};

static const struct net_device_ops nlmon_ops = {
- .ndo_init = nlmon_dev_init,
- .ndo_uninit = nlmon_dev_uninit,
.ndo_open = nlmon_open,
.ndo_stop = nlmon_close,
.ndo_start_xmit = nlmon_xmit,
@@ -92,6 +79,7 @@ static void nlmon_setup(struct net_device *dev)
dev->features = NETIF_F_SG | NETIF_F_FRAGLIST |
NETIF_F_HIGHDMA | NETIF_F_LLTX;
dev->flags = IFF_NOARP;
+ dev->pcpu_stat_type = NETDEV_PCPU_STAT_LSTATS;

/* That's rather a softlimit here, which, of course,
* can be altered. Not a real MTU, but what is to be
--
2.43.0



2024-03-01 13:44:44

by Breno Leitao

[permalink] [raw]
Subject: [PATCH net-next 2/2] net: nlmon: Simplify nlmon_get_stats64

Do not set rtnl_link_stats64 fields to zero, since they are zeroed
before ops->ndo_get_stats64 is called in core dev_get_stats() function.

Also, simplify the data collection by removing the temporary variable.

Signed-off-by: Breno Leitao <[email protected]>
---
drivers/net/nlmon.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
index e026bfc83757..e5a0987a263e 100644
--- a/drivers/net/nlmon.c
+++ b/drivers/net/nlmon.c
@@ -40,15 +40,7 @@ static int nlmon_close(struct net_device *dev)
static void
nlmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
{
- u64 packets, bytes;
-
- dev_lstats_read(dev, &packets, &bytes);
-
- stats->rx_packets = packets;
- stats->tx_packets = 0;
-
- stats->rx_bytes = bytes;
- stats->tx_bytes = 0;
+ dev_lstats_read(dev, &stats->rx_packets, &stats->rx_bytes);
}

static u32 always_on(struct net_device *dev)
--
2.43.0


2024-03-01 14:09:45

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH net-next 1/2] net: nlmon: Remove init and uninit functions

On 3/1/24 2:42 PM, Breno Leitao wrote:
> With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
> convert veth & vrf"), stats allocation could be done on net core
> instead of this driver.
>
> With this new approach, the driver doesn't have to bother with error
> handling (allocation failure checking, making sure free happens in the
> right spot, etc). This is core responsibility now.
>
> Remove the allocation in the nlmon driver and leverage the network
> core allocation.
>
> Signed-off-by: Breno Leitao <[email protected]>

Acked-by: Daniel Borkmann <[email protected]>

2024-03-01 14:10:25

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH net-next 2/2] net: nlmon: Simplify nlmon_get_stats64

On 3/1/24 2:42 PM, Breno Leitao wrote:
> Do not set rtnl_link_stats64 fields to zero, since they are zeroed
> before ops->ndo_get_stats64 is called in core dev_get_stats() function.
>
> Also, simplify the data collection by removing the temporary variable.
>
> Signed-off-by: Breno Leitao <[email protected]>

Acked-by: Daniel Borkmann <[email protected]>

2024-03-04 10:23:06

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net-next 1/2] net: nlmon: Remove init and uninit functions

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <[email protected]>:

On Fri, 1 Mar 2024 05:42:13 -0800 you wrote:
> With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and
> convert veth & vrf"), stats allocation could be done on net core
> instead of this driver.
>
> With this new approach, the driver doesn't have to bother with error
> handling (allocation failure checking, making sure free happens in the
> right spot, etc). This is core responsibility now.
>
> [...]

Here is the summary with links:
- [net-next,1/2] net: nlmon: Remove init and uninit functions
https://git.kernel.org/netdev/net-next/c/4f41ce81a919
- [net-next,2/2] net: nlmon: Simplify nlmon_get_stats64
https://git.kernel.org/netdev/net-next/c/26b5df99bf60

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