Skip to content

Commit 246e991

Browse files
committed
net-shapers: implement NL get operation
JIRA: https://issues.redhat.com/browse/RHEL-89973 Conflicts: - include/linux/netdevice.h Context diff because KABI reservation. Context diff because f858cc9 and 13cabc4 were not applied. commit 4b623f9 Author: Paolo Abeni <pabeni@redhat.com> Date: Wed Oct 9 10:09:49 2024 +0200 net-shapers: implement NL get operation Introduce the basic infrastructure to implement the net-shaper core functionality. Each network devices carries a net-shaper cache, the NL get() operation fetches the data from such cache. The cache is initially empty, will be fill by the set()/group() operation implemented later and is destroyed at device cleanup time. The net_shaper_fill_handle(), net_shaper_ctx_init(), and net_shaper_generic_pre() implementations handle generic index type attributes, despite the current caller always pass a constant value to avoid more noise in later patches using them with different attributes. Reviewed-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Link: https://patch.msgid.link/ddd10fd645a9367803ad02fca4a5664ea5ace170.1728460186.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
1 parent 689be2f commit 246e991

File tree

6 files changed

+485
-7
lines changed

6 files changed

+485
-7
lines changed

Documentation/networking/kapi.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ Driver Support
104104
.. kernel-doc:: include/linux/netdevice.h
105105
:internal:
106106

107+
.. kernel-doc:: include/net/net_shaper.h
108+
:internal:
109+
107110
PHY Support
108111
-----------
109112

include/linux/netdevice.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,14 @@ struct net_device_ops {
16151615
struct kernel_hwtstamp_config *kernel_config,
16161616
struct netlink_ext_ack *extack);
16171617

1618+
#if IS_ENABLED(CONFIG_NET_SHAPER)
1619+
/**
1620+
* @net_shaper_ops: Device shaping offload operations
1621+
* see include/net/net_shapers.h
1622+
*/
1623+
const struct net_shaper_ops *net_shaper_ops;
1624+
#endif
1625+
16181626
RH_KABI_RESERVE(1)
16191627
RH_KABI_RESERVE(2)
16201628
RH_KABI_RESERVE(3)
@@ -2491,6 +2499,20 @@ struct net_device {
24912499
unsigned long gro_flush_timeout;
24922500
u32 napi_defer_hard_irqs;
24932501

2502+
/**
2503+
* @lock: protects @net_shaper_hierarchy, feel free to use for other
2504+
* netdev-scope protection. Ordering: take after rtnl_lock.
2505+
*/
2506+
struct mutex lock;
2507+
2508+
#if IS_ENABLED(CONFIG_NET_SHAPER)
2509+
/**
2510+
* @net_shaper_hierarchy: data tracking the current shaper status
2511+
* see include/net/net_shapers.h
2512+
*/
2513+
struct net_shaper_hierarchy *net_shaper_hierarchy;
2514+
#endif
2515+
24942516
RH_KABI_RESERVE(1)
24952517
RH_KABI_RESERVE(2)
24962518
RH_KABI_RESERVE(3)

include/net/net_shaper.h

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
3+
#ifndef _NET_SHAPER_H_
4+
#define _NET_SHAPER_H_
5+
6+
#include <linux/types.h>
7+
8+
#include <uapi/linux/net_shaper.h>
9+
10+
struct net_device;
11+
struct devlink;
12+
struct netlink_ext_ack;
13+
14+
enum net_shaper_binding_type {
15+
NET_SHAPER_BINDING_TYPE_NETDEV,
16+
/* NET_SHAPER_BINDING_TYPE_DEVLINK_PORT */
17+
};
18+
19+
struct net_shaper_binding {
20+
enum net_shaper_binding_type type;
21+
union {
22+
struct net_device *netdev;
23+
struct devlink *devlink;
24+
};
25+
};
26+
27+
struct net_shaper_handle {
28+
enum net_shaper_scope scope;
29+
u32 id;
30+
};
31+
32+
/**
33+
* struct net_shaper - represents a shaping node on the NIC H/W
34+
* zeroed field are considered not set.
35+
* @parent: Unique identifier for the shaper parent, usually implied
36+
* @handle: Unique identifier for this shaper
37+
* @metric: Specify if the rate limits refers to PPS or BPS
38+
* @bw_min: Minimum guaranteed rate for this shaper
39+
* @bw_max: Maximum peak rate allowed for this shaper
40+
* @burst: Maximum burst for the peek rate of this shaper
41+
* @priority: Scheduling priority for this shaper
42+
* @weight: Scheduling weight for this shaper
43+
*/
44+
struct net_shaper {
45+
struct net_shaper_handle parent;
46+
struct net_shaper_handle handle;
47+
enum net_shaper_metric metric;
48+
u64 bw_min;
49+
u64 bw_max;
50+
u64 burst;
51+
u32 priority;
52+
u32 weight;
53+
54+
/* private: */
55+
u32 leaves; /* accounted only for NODE scope */
56+
struct rcu_head rcu;
57+
};
58+
59+
/**
60+
* struct net_shaper_ops - Operations on device H/W shapers
61+
*
62+
* The operations applies to either net_device and devlink objects.
63+
* The initial shaping configuration at device initialization is empty:
64+
* does not constraint the rate in any way.
65+
* The network core keeps track of the applied user-configuration in
66+
* the net_device or devlink structure.
67+
* The operations are serialized via a per device lock.
68+
*
69+
* Device not supporting any kind of nesting should not provide the
70+
* group operation.
71+
*
72+
* Each shaper is uniquely identified within the device with a 'handle'
73+
* comprising the shaper scope and a scope-specific id.
74+
*/
75+
struct net_shaper_ops {
76+
/**
77+
* @group: create the specified shapers scheduling group
78+
*
79+
* Nest the @leaves shapers identified under the * @node shaper.
80+
* All the shapers belong to the device specified by @binding.
81+
* The @leaves arrays size is specified by @leaves_count.
82+
* Create either the @leaves and the @node shaper; or if they already
83+
* exists, links them together in the desired way.
84+
* @leaves scope must be NET_SHAPER_SCOPE_QUEUE.
85+
*/
86+
int (*group)(struct net_shaper_binding *binding, int leaves_count,
87+
const struct net_shaper *leaves,
88+
const struct net_shaper *node,
89+
struct netlink_ext_ack *extack);
90+
91+
/**
92+
* @set: Updates the specified shaper
93+
*
94+
* Updates or creates the @shaper on the device specified by @binding.
95+
*/
96+
int (*set)(struct net_shaper_binding *binding,
97+
const struct net_shaper *shaper,
98+
struct netlink_ext_ack *extack);
99+
100+
/**
101+
* @delete: Removes the specified shaper
102+
*
103+
* Removes the shaper configuration as identified by the given @handle
104+
* on the device specified by @binding, restoring the default behavior.
105+
*/
106+
int (*delete)(struct net_shaper_binding *binding,
107+
const struct net_shaper_handle *handle,
108+
struct netlink_ext_ack *extack);
109+
110+
/**
111+
* @capabilities: get the shaper features supported by the device
112+
*
113+
* Fills the bitmask @cap with the supported capabilities for the
114+
* specified @scope and device specified by @binding.
115+
*/
116+
void (*capabilities)(struct net_shaper_binding *binding,
117+
enum net_shaper_scope scope, unsigned long *cap);
118+
};
119+
120+
#endif

net/core/dev.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11067,6 +11067,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
1106711067
hash_init(dev->qdisc_hash);
1106811068
#endif
1106911069

11070+
mutex_init(&dev->lock);
11071+
1107011072
dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
1107111073
setup(dev);
1107211074

@@ -11142,6 +11144,8 @@ void free_netdev(struct net_device *dev)
1114211144
return;
1114311145
}
1114411146

11147+
mutex_destroy(&dev->lock);
11148+
1114511149
kfree(dev->ethtool);
1114611150
netif_free_tx_queues(dev);
1114711151
netif_free_rx_queues(dev);
@@ -11352,6 +11356,8 @@ void unregister_netdevice_many_notify(struct list_head *head,
1135211356

1135311357
mutex_destroy(&dev->ethtool->rss_lock);
1135411358

11359+
net_shaper_flush_netdev(dev);
11360+
1135511361
if (skb)
1135611362
rtmsg_ifinfo_send(skb, dev, GFP_KERNEL, portid, nlh);
1135711363

net/core/dev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ void linkwatch_run_queue(void);
3939
void dev_addr_flush(struct net_device *dev);
4040
int dev_addr_init(struct net_device *dev);
4141

42+
#if IS_ENABLED(CONFIG_NET_SHAPER)
43+
void net_shaper_flush_netdev(struct net_device *dev);
44+
#else
45+
static inline void net_shaper_flush_netdev(struct net_device *dev) {}
46+
#endif
47+
4248
/* sysctls not referred to from outside net/core/ */
4349
extern int netdev_budget;
4450
extern unsigned int netdev_budget_usecs;

0 commit comments

Comments
 (0)