Commit 4b623f9f authored by Paolo Abeni's avatar Paolo Abeni Committed by Jakub Kicinski
Browse files

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: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Link: https://patch.msgid.link/ddd10fd645a9367803ad02fca4a5664ea5ace170.1728460186.git.pabeni@redhat.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 04e65df9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -104,6 +104,9 @@ Driver Support
.. kernel-doc:: include/linux/netdevice.h
   :internal:

.. kernel-doc:: include/net/net_shaper.h
   :internal:

PHY Support
-----------

+21 −0
Original line number Diff line number Diff line
@@ -1603,6 +1603,14 @@ struct net_device_ops {
	int			(*ndo_hwtstamp_set)(struct net_device *dev,
						    struct kernel_hwtstamp_config *kernel_config,
						    struct netlink_ext_ack *extack);

#if IS_ENABLED(CONFIG_NET_SHAPER)
	/**
	 * @net_shaper_ops: Device shaping offload operations
	 * see include/net/net_shapers.h
	 */
	const struct net_shaper_ops *net_shaper_ops;
#endif
};

/**
@@ -2406,6 +2414,19 @@ struct net_device {

	u64			max_pacing_offload_horizon;

	/**
	 * @lock: protects @net_shaper_hierarchy, feel free to use for other
	 * netdev-scope protection. Ordering: take after rtnl_lock.
	 */
	struct mutex		lock;

#if IS_ENABLED(CONFIG_NET_SHAPER)
	/**
	 * @net_shaper_hierarchy: data tracking the current shaper status
	 *  see include/net/net_shapers.h
	 */
	struct net_shaper_hierarchy *net_shaper_hierarchy;
#endif
	u8			priv[] ____cacheline_aligned
				       __counted_by(priv_len);
} ____cacheline_aligned;
+120 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-or-later */

#ifndef _NET_SHAPER_H_
#define _NET_SHAPER_H_

#include <linux/types.h>

#include <uapi/linux/net_shaper.h>

struct net_device;
struct devlink;
struct netlink_ext_ack;

enum net_shaper_binding_type {
	NET_SHAPER_BINDING_TYPE_NETDEV,
	/* NET_SHAPER_BINDING_TYPE_DEVLINK_PORT */
};

struct net_shaper_binding {
	enum net_shaper_binding_type type;
	union {
		struct net_device *netdev;
		struct devlink *devlink;
	};
};

struct net_shaper_handle {
	enum net_shaper_scope scope;
	u32 id;
};

/**
 * struct net_shaper - represents a shaping node on the NIC H/W
 * zeroed field are considered not set.
 * @parent: Unique identifier for the shaper parent, usually implied
 * @handle: Unique identifier for this shaper
 * @metric: Specify if the rate limits refers to PPS or BPS
 * @bw_min: Minimum guaranteed rate for this shaper
 * @bw_max: Maximum peak rate allowed for this shaper
 * @burst: Maximum burst for the peek rate of this shaper
 * @priority: Scheduling priority for this shaper
 * @weight: Scheduling weight for this shaper
 */
struct net_shaper {
	struct net_shaper_handle parent;
	struct net_shaper_handle handle;
	enum net_shaper_metric metric;
	u64 bw_min;
	u64 bw_max;
	u64 burst;
	u32 priority;
	u32 weight;

	/* private: */
	u32 leaves; /* accounted only for NODE scope */
	struct rcu_head rcu;
};

/**
 * struct net_shaper_ops - Operations on device H/W shapers
 *
 * The operations applies to either net_device and devlink objects.
 * The initial shaping configuration at device initialization is empty:
 * does not constraint the rate in any way.
 * The network core keeps track of the applied user-configuration in
 * the net_device or devlink structure.
 * The operations are serialized via a per device lock.
 *
 * Device not supporting any kind of nesting should not provide the
 * group operation.
 *
 * Each shaper is uniquely identified within the device with a 'handle'
 * comprising the shaper scope and a scope-specific id.
 */
struct net_shaper_ops {
	/**
	 * @group: create the specified shapers scheduling group
	 *
	 * Nest the @leaves shapers identified under the * @node shaper.
	 * All the shapers belong to the device specified by @binding.
	 * The @leaves arrays size is specified by @leaves_count.
	 * Create either the @leaves and the @node shaper; or if they already
	 * exists, links them together in the desired way.
	 * @leaves scope must be NET_SHAPER_SCOPE_QUEUE.
	 */
	int (*group)(struct net_shaper_binding *binding, int leaves_count,
		     const struct net_shaper *leaves,
		     const struct net_shaper *node,
		     struct netlink_ext_ack *extack);

	/**
	 * @set: Updates the specified shaper
	 *
	 * Updates or creates the @shaper on the device specified by @binding.
	 */
	int (*set)(struct net_shaper_binding *binding,
		   const struct net_shaper *shaper,
		   struct netlink_ext_ack *extack);

	/**
	 * @delete: Removes the specified shaper
	 *
	 * Removes the shaper configuration as identified by the given @handle
	 * on the device specified by @binding, restoring the default behavior.
	 */
	int (*delete)(struct net_shaper_binding *binding,
		      const struct net_shaper_handle *handle,
		      struct netlink_ext_ack *extack);

	/**
	 * @capabilities: get the shaper features supported by the device
	 *
	 * Fills the bitmask @cap with the supported capabilities for the
	 * specified @scope and device specified by @binding.
	 */
	void (*capabilities)(struct net_shaper_binding *binding,
			     enum net_shaper_scope scope, unsigned long *cap);
};

#endif
+6 −0
Original line number Diff line number Diff line
@@ -11147,6 +11147,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
	hash_init(dev->qdisc_hash);
#endif

	mutex_init(&dev->lock);

	dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
	setup(dev);

@@ -11217,6 +11219,8 @@ void free_netdev(struct net_device *dev)
		return;
	}

	mutex_destroy(&dev->lock);

	kfree(dev->ethtool);
	netif_free_tx_queues(dev);
	netif_free_rx_queues(dev);
@@ -11426,6 +11430,8 @@ void unregister_netdevice_many_notify(struct list_head *head,

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

		net_shaper_flush_netdev(dev);

		if (skb)
			rtmsg_ifinfo_send(skb, dev, GFP_KERNEL, portid, nlh);

+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ void dev_addr_flush(struct net_device *dev);
int dev_addr_init(struct net_device *dev);
void dev_addr_check(struct net_device *dev);

#if IS_ENABLED(CONFIG_NET_SHAPER)
void net_shaper_flush_netdev(struct net_device *dev);
#else
static inline void net_shaper_flush_netdev(struct net_device *dev) {}
#endif

/* sysctls not referred to from outside net/core/ */
extern int		netdev_unregister_timeout_secs;
extern int		weight_p;
Loading