devlink and mlx5: Support cross-function rate scheduling
Status from this message: This series was applied to netdev/net-next.git (main)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v10 Latest14 patches 0 repliesApplied 14/14
- v914 patches 14 repliesSuperseded
- v814 patches 3 repliesSuperseded
Earlier versions · 7
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v7 | 14 patches | 17 replies | Superseded | |
| v6 | 14 patches | 4 replies | Superseded | |
| v5 | 15 patches | 10 replies | Superseded | |
| v4 | 14 patches | 15 replies | Superseded | |
| v3 | 14 patches | 1 reply | Superseded | |
| v2 | 14 patches | 2 replies | Superseded | |
| v1 | 14 patches | 7 replies | Superseded |
Changes in v10 from the cover letter
- Added a comment in devl_rate_nodes_destroy clarifying locking.
- Expanded 'supported_cross_device_rate_nodes' comment with locking expectations.
- Simplified rate locking by only keeping the common ancestor locked.
- Removed devlink_nested_in_get_locked and devlink_nested_in_put_unlock.
- devlink_nl_rate_parent_node_set iterates over the proper rate list.
- Refactored mlx5 locking given dev->shd is now optional (after [3]).
- Fixed a bug in pruning introduced by the root node patch.
- Fixed a bug on failure when detaching a node from parent.
- Clarified expectations for shared devlink rate storage.
- Fixed incorrect net namespace when listing shared instances.
Patches in v10 All 14 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/14 | devlink: Update nested instance locking commentDocumentation/ | +4 | 0 replies | Applied |
| 2/14 | devlink: Add a helper for getting a nested-in instancenet/ net/ | +20 | 0 replies | Applied |
| 3/14 | devlink: Migrate from info->user_ptr to info->ctxnet/ net/ net/ +10 more | +84 | 0 replies | Applied |
| 4/14 | devlink: Decouple rate storage from associated devlink objectnet/ | +177 | 0 replies | Applied |
| 5/14 | devlink: Add parent dev to devlink APIDocumentation/ include/ net/ +1 more | +56 | 0 replies | Applied |
| 6/14 | devlink: Allow parent dev for rate-set and rate-newDocumentation/ net/ net/ +2 more | +72 | 0 replies | Applied |
| 7/14 | devlink: Allow rate node parents from other devlinksDocumentation/ include/ net/ +1 more | +92 | 0 replies | Applied |
| 8/14 | net/mlx5: qos: Use mlx5_lag_query_bond_speed to query LAG speeddrivers/ | +6 | 0 replies | Applied |
| 9/14 | net/mlx5: qos: Refactor vport QoS cleanupdrivers/ drivers/ drivers/ +1 more | +14 | 0 replies | Applied |
| 10/14 | net/mlx5: qos: Model the root node in the scheduling hierarchydrivers/ drivers/ | +89 | 0 replies | Applied |
| 11/14 | net/mlx5: qos: Remove qos domains and use shddrivers/ drivers/ drivers/ +2 more | +120 | 0 replies | Applied |
| 12/14 | net/mlx5: qos: Support cross-device tx schedulingdrivers/ | +85 | 0 replies | Applied |
| 13/14 | selftests: drv-net: Add test for cross-esw rate schedulingtools/ tools/ | +297 | 0 replies | Applied |
| 14/14 | net/mlx5: Document devlink ratesDocumentation/ | +33 | 0 replies | Applied |
Reviews trailers per patch
All 14 patches have a Reviewed-by or Acked-by.
| Patch | Carolina Jubran | Jiri Pirko |
|---|---|---|
| 1/14 | R-b | R-b |
| 2/14 | R-b | R-b |
| 3/14 | R-b | |
| 4/14 | R-b | R-b |
| 5/14 | R-b | R-b |
| 6/14 | R-b | R-b |
| 7/14 | R-b | R-b |
| 8/14 | R-b | |
| 9/14 | R-b | |
| 10/14 | R-b | |
| 11/14 | R-b | |
| 12/14 | R-b | |
| 13/14 | R-b | |
| 14/14 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH net-next V10 00/14] devlink and mlx5: Support cross-function rate scheduling
Hi,
This series by Cosmin adds support for cross-function rate scheduling in devlink and mlx5.
See detailed explanation by Cosmin below [0].
Regards,
Tariq
[0]
devlink objects support rate management for TX scheduling, which involves maintaining a tree of rate nodes that corresponds to TX schedulers in hardware. 'man devlink-rate' has the full details.
The tree of rate nodes is maintained per devlink object, protected by the devlink lock.
There exists hardware capable of instantiating TX scheduling trees spanning multiple functions of the same physical device (and thus devlink objects) and therefore the current API and locking scheme is insufficient.
This patch series changes the devlink rate implementation and API to allow supporting such hardware and managing TX scheduling trees across multiple functions of a physical device.
Modeling this requires having devlink rate nodes with parents in other devlink objects. A naive approach that relies on the current one-lock-per-devlink model is impossible, as it would require in some cases acquiring multiple devlink locks in the correct order.
The solution proposed in this patch series makes use of the recently introduced shared devlink instance [1] to manage rate hierarchy changes across multiple functions.
V1 of this patch series was sent a long time ago [2], using a different approach of storing rates in a shared rate domain with special locking rules. This new approach uses standard devlink instances and nesting.
The first part of the series adds support to devlink rates for maintaining the rate tree across multiple functions.
The second part changes the mlx5 implementation to make use of this (and cleans up remnants of the previous approach, involving rate domains).
The neat part about using the shared devlink object is that it works for SFs as well, which are already nested in their parent PF instances. So with this series, complex scheduling trees spanning multiple SFs across multiple PFs of the same NIC can now be supported.
---
[1] https://lore.kernel.org/all/[email protected]/T/#u
[2] https://lore.kernel.org/netdev/[email protected]/
[3] https://lore.kernel.org/netdev/[email protected]/
Comments from internal Sashiko review:
Quoted 7 lines
When a rate node is linked to a parent on a different devlink device, should the rate-get reply and dump operations also include the parent's device information?
Currently, parent-dev is only added to the request attributes for rate-set and rate-new, but it appears to be omitted from the serialization logic and the rate-get reply definition. Does this render the cross-device relationship invisible to user space monitoring tools?
[CR] Preexisting problem with devlink rate API, the rate-get command specifies only a subset of output attributes. May be fixed separately.
Quoted 14 lines
net/devlink/rate.c int devlink_nl_rate_set_doit(struct sk_buff *skb, struct genl_info *info) · line 664
Quoted 11 lines
net/devlink/rate.c +2
-1@@ -660,9 +660,11 @@ int devlink_nl_rate_set_doit(struct sk_buff *skb, struct genl_info *info)int devlink_nl_rate_new_doit (struct sk_buff *skb,struct genl_info *info) { -struct devlink *rate_devlink, *devlink =devlink_nl_ctx (info)->devlink; +struct devlink_nl_ctx *ctx =devlink_nl_ctx (info); +struct devlink *devlink = ctx->devlink;While ctx is now retrieved, does the rest of the function ignore
ctx->parent_devlink?
Quoted 4 lines
It looks like the command handlers never retrieve or use the parent devlink, and unconditionally use the child's devlink for lookups and assignments. Will this cause cross-device parent assignments to silently fail or return
-ENODEVsince they search for the parent node exclusively on the child's device?
[CR] False positive, it's used in devlink_nl_rate_parent_node_set().
Quoted 13 lines
Additionally, looking at how the parent devlink is prepared in
__devlink_nl_pre_doit()(which is called viaDEVLINK_NL_FLAG_OPTIONAL_PARENT_DEV):__devlink_nl_pre_doit()if (parent_dev && attrs[DEVLINK_ATTR_PARENT_DEV]) { parent_devlink = devlink_get_parent_from_attrs_lock(net, attrs); ... devlink_nl_ctx(info)->parent_devlink = parent_devlink; /* Drop the parent devlink lock but don't release the reference. * This will keep it alive until the end of the request. */ devl_unlock(parent_devlink); }
Quoted 4 lines
To actually implement the cross-device feature in the command handlers, the parent's rate list would need to be accessed. Since the parent devlink lock is explicitly dropped here, wouldn't accessing the parent's rate list without its lock violate devlink locking rules and lead to data races?
[CR] Locking changes are intentional. All rate changes for anything in the rate group now acquire the root devlink lock, where rates are stored.
Quoted 26 lines
Quoted 26 lines
net/devlink/rate.c +9
-5* devl_rate_nodes_destroy - destroy all devlink rate nodes on device * @devlink: devlink instance * -* Unset parent for all rate objects and destroy all rate nodes -* on specified device. +* Unset parent for all rate objects involving this device and destroy all rate +* nodes on it. */ void devl_rate_nodes_destroy (struct devlink *devlink) { -const struct devlink_ops *ops = devlink->ops;struct devlink_rate *devlink_rate, *tmp; +const struct devlink_ops *ops; +struct devlink *rate_devlink;devl_assert_locked (devlink); + rate_devlink =devl_rate_lock (devlink); -list_for_each_entry (devlink_rate, &devlink->rate_list, list) { -if (!devlink_rate->parent) +list_for_each_entry (devlink_rate, &rate_devlink->rate_list, list) { +if (!devlink_rate->parent || + (devlink_rate->devlink != devlink && + devlink_rate->parent->devlink != devlink))continue ;
Quoted 16 lines
net/devlink/rate.c
Quoted 6 lines
net/devlink/rate.c +6
-0+/* This could destroy rate objects on other devlinks in the +* same hierarchy under 'rate_devlink'. This is safe because +* the shared common ancestor is locked so there can be no +* other concurrent rate operations on devlink_rate->devlink. +*/ + ops = devlink_rate->devlink->ops;Does this code invoke
devlink_opscallbacks on other devlink instances without holding their instance lock?
While the comment indicates the shared common ancestor lock prevents concurrent rate operations, the child device's instance lock (devlink_rate->devlink) is not held.
Could this violate the devlink locking contract if the driver is executing concurrent non-rate operations on the child instance? Because devlink drivers rely on the instance lock to serialize access to their internal structures, could invoking these callbacks unlocked cause data corruption or trigger lockdep splats if the driver assertsdevl_assert_locked()?
[CR] As mentioned in the comment, concurrent ops which touch rates _will_ eventually acquire the shared devlink lock, so they're safe. We don't care about other ops, since we only touching rates here.
Quoted 4 lines
Quoted 4 lines
net/devlink/rate.c +0
-0@@ -321,22 +307,19 @@ static int esw_qos_create_rate_limit_element(struct mlx5_esw_sched_node *node,return esw_qos_node_create_sched_element (node, sched_ctx, extack); }
Quoted 16 lines
net/devlink/rate.c static int esw_qos_create_rate_limit_element(struct mlx5_esw_sched_node *node, · line 313
Quoted 8 lines
net/devlink/rate.c +3
-4-static u32 esw_qos_calculate_min_rate_divider (struct mlx5_eswitch *esw, -struct mlx5_esw_sched_node *parent) +static u32 +esw_qos_calculate_min_rate_divider (struct mlx5_esw_sched_node *parent) { -struct list_head *nodes = parent ? &parent->children : &esw->qos.domain->nodes; -u32 fw_max_bw_share =MLX5_CAP_QOS (esw->dev, max_tsar_bw_share); +u32 fw_max_bw_share =MLX5_CAP_QOS (parent->esw->dev, max_tsar_bw_share);This is a pre-existing issue, but does this division risk a divide-by-zero panic regression?
If the hardware does not support bandwidth sharing,max_tsar_bw_sharecould be 0. If a user subsequently sets a non-zerotx_share(minimum rate guarantee),max_guaranteebecomes greater than 0, resulting inmax_guarantee/fw_max_bw_share.
Should we validate whetherfw_max_bw_shareis non-zero before performing the division?
[CR] Preexisting, also not really possible for fw to give a value of 0 for the divisor.
Quoted 7 lines
net/devlink/rate.c static int esw_qos_create_tc_arbiter_sched_elem( · line 634
Quoted 6 lines
net/devlink/rate.c +0
-1@@ -665,7 +631,6 @@ static int esw_qos_create_tc_arbiter_sched_elem( struct netlink_ext_ack *extack) {u32 tsar_ctx[MLX5_ST_SZ_DW (scheduling_context)] = {}; -u32 tsar_parent_ix;void *attr;This is a pre-existing issue, but is there a hardware scheduling element
Quoted 8 lines
leak when transitioning a node to a TC arbiter?
Whenesw_qos_tc_arbiter_scheduling_setup()callsesw_qos_create_tc_arbiter_sched_elem(node, extack), it provisions a new hardware element and immediately overwritesnode->ixwith its ID. If the subsequent stepesw_qos_create_vports_tc_nodes(node, extack)fails, it jumps toerr_tc_node_createand restoresnode->ix=curr_ix, but it doesn't appear to tear down the newly created scheduling element. Does this permanently leak the newly provisioned hardware element in the firmware?
[CR] False alarm, the call to esw_qos_node_destroy_sched_element() destroys the new temporary scheduling element on failure.
Quoted 9 lines
net/devlink/rate.c static int esw_qos_switch_tc_arbiter_node_to_vports( · line 1290
Quoted 4 lines
net/devlink/rate.c +0
-0@@ -1319,11 +1288,9 @@ static int esw_qos_switch_tc_arbiter_node_to_vports(struct mlx5_esw_sched_node *node, struct netlink_ext_ack *extack) {This is a pre-existing issue, but what happens if the rollback path fails during vport migration in
esw_qos_switch_vports_node_to_tc_arbiter()? If an error occurs, it attempts to rollback by callingesw_qos_switch_vport_tcs_to_vport(). If this rollback fails internally (e.g. due to ENOMEM inesw_qos_vport_update()), the vport is
Quoted 8 lines
successfully restored to the doomed TC arbiter node, and the error is silently ignored.
Then, the calleresw_qos_node_enable_tc_arbitration()executesesw_qos_tc_arbiter_scheduling_teardown(), which frees the TC arbiter'sVPORTS_TC_TSARnodes without freeing the attached vportVPORT_TCnodes. Does this leak the vport TC nodes and leave them holding use-after-free pointers to their freed parents, leading to memory corruption when the vport is later disabled?
[CR] Preexisting, also hard to hit. Requires a failure mid-way when switching nodes to TC arbitration AND a failure during rollback. Fixing it outside the scope of this series.
Quoted 13 lines
net/devlink/rate.c mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, · line 1860
Quoted 8 lines
net/devlink/rate.c +3
-1@@ -1888,7 +1855,9 @@ mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, err =mlx5_esw_qos_vport_enable (vport, type, parent,0 ,0 , extack); }else if (vport->qos.sched_node) { - err =esw_qos_vport_update_parent (vport, parent, extack); + err =esw_qos_vport_update_parent (vport, + parent ? : esw->qos.root, + extack);Can this sequence cause a use-after-free regression on
esw->qos.rootwhen updating a vport's QoS configuration?
If a vport is the only QoS user in the E-Switch,esw->qos.refcntis 1. If its QoS configuration is updated,esw_qos_vport_update()is called with the parent argument pointing toesw->qos.root(since this patch
Quoted 8 lines
changes the default parent from NULL to
esw->qos.root).
Insideesw_qos_vport_update(),mlx5_esw_qos_vport_disable_locked()drops the vport's QoS reference, decrementingesw->qos.refcntto 0. This triggersesw_qos_destroy(), freeingesw->qos.root.
The function then callsmlx5_esw_qos_vport_enable(..., parent, ...)passing the stale parent pointer. Because parent is no longer NULL, it doesn't fetch the newly re-allocated root node, and instead passes the freed pointer to__esw_qos_alloc_node(), resulting in a use-after-free.
[CR] False alarm. The finding confuses esw_qos_vport_disable() and mlx5_esw_qos_vport_disable_locked(). esw_qos_vport_disable() doesn't touch the refcnt.
Quoted 20 lines
Quoted 4 lines
net/devlink/rate.c +0
-1@@ -1859,13 +1840,15 @@ mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, extack); } -esw_qos_unlock (esw);net/devlink/rate.c mlx5_esw_qos_vport_update_parent(struct mlx5_vport *vport, · line 1851
Quoted 10 lines
net/devlink/rate.c +3
-0+return err; }void mlx5_esw_qos_vport_clear_parent (struct mlx5_vport *vport) { +esw_qos_lock (vport->dev);mlx5_esw_qos_vport_update_parent (vport,NULL ,NULL ); +esw_qos_unlock (vport->dev); }Could this lead to a recursive mutex deadlock during VF teardown on older hardware where shd is NULL?
In the teardown path,mlx5_eswitch_unload_pf_vf_vport()already acquiresesw->state_lock. It then proceeds to call:mlx5_eswitch_unload_pf_vf_vport()
mlx5_eswitch_unload_vport()
Quoted 8 lines
mlx5_esw_offloads_unload_rep()
mlx5_esw_offloads_devlink_port_unregister()
mlx5_esw_qos_vport_clear_parent()
Since this patch changesmlx5_esw_qos_vport_clear_parent()to unconditionally callesw_qos_lock(), which falls back to acquiringesw->state_lockwhendev->shdis NULL, won't this result in an attempt to re-acquire the non-recursivestate_lockthat is already held by the teardown process?
[CR] False alarm. state_lock isn't held during VF teardown.
Quoted 11 lines
net/devlink/rate.c void devl_rate_nodes_destroy(struct devlink *devlink) · line 941
Quoted 3 lines
net/devlink/rate.c +0
-0@@ -839,13 +940,17 @@ void devl_rate_nodes_destroy(struct devlink *devlink)refcount_dec (&devlink_rate->parent->refcnt); devlink_rate->parent =NULL ;When unsetting the parent of a rate object in
devl_rate_nodes_destroy(), this patch allows it to happen to cross-device child nodes (wheredevlink_rate->devlink!= devlink). Since the child's devlink instance is still active, shouldn't its state change (losing its parent) be communicated to user space?
Omittingdevlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_NEW)here might leave user space monitors out of sync, incorrectly believing the active child is still attached to the deleted parent node.
[CR] Preexisting, devl_rate_nodes_destroy() didn't send notifications.
Quoted 23 lines
net/devlink/rate.c void devl_rate_nodes_destroy(struct devlink *devlink) · line 952
Quoted 12 lines
net/devlink/rate.c +10
-1+static struct devlink *devl_rate_lock (struct devlink *devlink) { -return devlink; +struct devlink *rate_devlink = devlink, *parent; + +devl_assert_locked (devlink); + +while (rate_devlink->ops && + rate_devlink->ops->supported_cross_device_rate_nodes) { + parent =devlink_nested_in_get_lock (rate_devlink); +if (!parent) +break ;Can this lead to list corruption if the parent devlink is unregistered? If the parent is unregistered concurrently (for example, a PF is unregistered before VF teardown),
devlink_nested_in_get_lock()will return NULL because of this internal check:devlink_nested_in_get_lock() { ... if (devl_is_registered(devlink)) return devlink; ... return NULL; }
Quoted 5 lines
Since parent is NULL, this loop breaks and returns the child devlink lock instead of the parent's lock. Later, in functions like
devl_rate_leaf_destroy(),list_del(&devlink_rate->list)is called on the rate node.
Because the rate node is chained into the parent'srate_list, does this modify the parent's list concurrently without holding its lock?
[CR] This misunderstands the nesting hierarchy. VFs are not nested in PFs, PFs are nested in shd, which is reference counted (=> outlives all PFs) and keeps all rate nodes for all PFs.
Quoted 14 lines
This is a pre-existing issue, but does
devlink_nl_rate_del_doit()unconditionally free rate nodes even if the driver rejects the deletion? Looking atdevlink_nl_rate_del_doit()innet/devlink/rate.c:devlink_nl_rate_del_doit() { ... err = devlink->ops->rate_node_del(rate_node, rate_node->priv, info->extack); if (rate_node->parent) refcount_dec(&rate_node->parent->refcnt); list_del(&rate_node->list); kfree(rate_node->name); kfree(rate_node); ... }
Quoted 5 lines
If the hardware or driver cannot fulfill the request and
ops->rate_node_del()returns an error like-EBUSY, the function ignores the error regarding memory management and proceeds tokfree()the rate node.
Could this leave the driver with a dangling pointer to the freed rate node, triggering a use-after-free later?
[CR] Preexisting, it is intentional that the node is removed no matter what the rate_node_del op manages to do.
Quoted 4 lines
net/devlink/rate.c devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, · line 244
Quoted 3 lines
net/devlink/rate.c +2
-0@@ -243,7 +243,29 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, + err =nla_parse_nested (tb, maxtype, attrs[DEVLINK_ATTR_PARENT_DEV ], + devlink_dl_parent_dev_nl_policy,NULL );Could this
nla_parse_nested()call pass down an extended ACK pointer instead
Quoted 8 lines
of NULL?
When passing NULL for the extack parameter, if the nested attribute is malformed (such as a missingNLA_F_NESTEDflag), userspace will receive a silent-EINVALwithout a descriptive error message.
Becausedevlink_get_parent_from_attrs_lock()is called by__devlink_nl_pre_doit()which has access to thegenl_infostructure and its extack pointer, passing it down to this function would allow for reporting accurate validation errors to userspace.
[CR] Valid, but quite a lot of plumbing is necessary for extack to be used here. Out of scope of the series.
Quoted 7 lines
This is a pre-existing issue, but does the error path in
devlink_nl_rate_new_doit()leak the parent's reference count? Ifdevlink_nl_rate_set()successfully sets the parent (which incrementsparent->refcnt) but fails on a subsequent attribute validation liketc_bw, it returns an error.
The cleanup path indevlink_nl_rate_new_doit()handles the error:err_rate_set:
Quoted 8 lines
ops->rate_node_del(rate_node, rate_node->priv, info->extack); err_node_new: kfree(rate_node->name); err_strdup: kfree(rate_node);Because this path frees the node but never decrements the parent's refcnt, does this permanently elevate the parent's refcount, falsely indicating it has children and preventing it from ever being deleted?
[CR] Preexisting, will be fixed separately with a net patch.
Quoted 43 lines
Quoted 21 lines
net/devlink/rate.c +14
-1@@ -30,14 +30,42 @@ devlink_rate_leaf_get_from_info(struct devlink *devlink, struct genl_info *info)return devlink_rate ?:ERR_PTR (-ENODEV ); } +/* Repeatedly walks the nested devlink chain while cross device rate nodes are +* supported and finds the topmost instance where rates should be stored. +* That instance is locked, referenced and returned. +* When cross device rate nodes aren't supported the original devlink instance +* is returned. +*/ static struct devlink *devl_rate_lock (struct devlink *devlink) { -return devlink; +struct devlink *rate_devlink = devlink, *parent; + +devl_assert_locked (devlink); + +while (rate_devlink->ops && + rate_devlink->ops->supported_cross_device_rate_nodes) { + parent =devlink_nested_in_get_lock (rate_devlink); +if (!parent)net/devlink/rate.c devlink_rate_leaf_get_from_info(struct devlink *devlink, struct genl_info *info) · line 58
Quoted 10 lines
net/devlink/rate.c +9
-0+break ; +if (rate_devlink != devlink) { +/* Unlock intermediate instances. */ +devl_unlock (rate_devlink); +devlink_put (rate_devlink); + } + rate_devlink = parent; + } +return rate_devlink; }Now that
devl_rate_lock()returns the shared ancestor, does this causedevlink_rates_check()to skip child rate nodes?
In net/devlink/rate.c:devlink_rates_check(), the loop filters nodes by the devlink pointer:rate_devlink = devl_rate_lock(devlink); list_for_each_entry(devlink_rate, &rate_devlink->rate_list, list) if (devlink_rate->devlink == devlink && (!rate_filter || rate_filter(devlink_rate))) { ... err = -EBUSY; break; }
Quoted 10 lines
Because of this check, if a user creates an SF rate node and then triggers an eswitch mode change to legacy on the PF devlink,
devlink_rates_check()skips the SF node and returns 0 instead of-EBUSY.
Could this allowmlx5_devlink_eswitch_mode_set()to proceed and unconditionally free the QoS domain inmlx5_esw_qos_cleanup(), while the child SF devlink and its software rate node remain active?
If so, a subsequent operation on the active child SF rate node (likeDEVLINK_CMD_RATE_DEL) would invokemlx5_esw_devlink_rate_node_del()and callesw_qos_lock(), leading to a NULL pointer dereference when accessingesw->qos.domain->lock.
[CR] False alarm, no driver uses supported_cross_device_rate_nodes yet so this code path isn't taken. QoS domains are removed in a later patch in the series before the cross device flag is enabled, so this finding is moot.
Quoted 20 lines
net/devlink/rate.c devlink_rate_leaf_get_from_info(struct devlink *devlink, struct genl_info *info) · line 65
Quoted 9 lines
net/devlink/rate.c +2
-2static int mlx5_esw_qos_max_link_speed_get (struct mlx5_core_dev *mdev,u32 *link_speed_max, -bool take_rtnl,struct netlink_ext_ack *extack) {int err; -if (!mlx5_lag_is_active (mdev)) + if (!mlx5_lag_is_active(mdev) || + mlx5_lag_query_bond_speed(mdev, link_speed_max) < 0 ||^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^This is a pre-existing issue, but does
mlx5_lag_query_bond_speed()have a race condition when accessing theldev->trackerstructure?
Themlx5_lag_query_bond_speed()function readsldev->tracker.bond_speed_mbpswhile holdinglag_lock. However,mlx5_lag_netdev_event()modifiesldev->trackerholding onlyrtnl_lock, without holdinglag_lock:drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_netdev_event() { ... ldev->tracker = tracker; ... }
Quoted 6 lines
Concurrently,
mlx5_ldev_add_netdev()modifies fields inside it underlag_lock, meaning its updates can be overwritten and lost by the read-modify-write inmlx5_lag_netdev_event().
Since this patch now heavily relies onmlx5_lag_query_bond_speed()for QoS max link speed, could this expose readers to observing torn or inconsistent tracker states?
[CR] Preexisting, no impact. Either a value of 0 is read, or the correct one.
Quoted 7 lines
Quoted 7 lines
net/devlink/rate.c +4
-0@@ -458,10 +461,17 @@ esw_qos_vport_create_sched_element(struct mlx5_esw_sched_node *vport_node,MLX5_SET (scheduling_context, sched_ctx, max_average_bw, vport_node->max_rate); +if (vport->dev != dev) { +/* The port is assigned to a node on another eswitch. */ +MLX5_SET (vport_element, attr, eswitch_owner_vhca_id_valid, + true);
Quoted 8 lines
net/devlink/rate.c esw_qos_vport_create_sched_element(struct mlx5_esw_sched_node *vport_node, · line 468
Quoted 2 lines
net/devlink/rate.c +2
-0+MLX5_SET (vport_element, attr, eswitch_owner_vhca_id, +MLX5_CAP_GEN (vport->dev, vhca_id));Does this code silently truncate the
vhca_idif it is >= 2048? The hardware structuremlx5_ifc_vport_element_bitsdefineseswitch_owner_vhca_idas an 11-bit field, butMLX5_CAP_GEN(..., vhca_id)returns a 16-bit identifier. TheMLX5_SETmacro will silently apply a mask of0x7ff. Should there be a bounds check returning an error like-EOVERFLOWhere, or does the hardware actually support a 16-bit field?
[CR] vhca_id >= 2048 would imply a NIC with that many physical ports, which is only possible in theory. Not worth addressing.
Quoted 4 lines
Quoted 4 lines
net/devlink/rate.c +0
-0@@ -1221,8 +1260,15 @@ static int esw_qos_vport_update(struct mlx5_vport *vport,if (err)return err;
Quoted 16 lines
net/devlink/rate.c static int esw_qos_vport_update(struct mlx5_vport *vport, · line 1264
Quoted 3 lines
net/devlink/rate.c +1
-1-if (curr_type ==SCHED_NODE_TYPE_TC_ARBITER_TSAR && curr_type == type) +if (curr_type ==SCHED_NODE_TYPE_TC_ARBITER_TSAR && curr_type == type) {esw_qos_tc_arbiter_get_bw_shares (vport_node, curr_tc_bw);Does this condition skip the preservation and restoration of TC bandwidth shares when transitioning between different node types?
When a vport transitions away fromSCHED_NODE_TYPE_TC_ARBITER_TSAR(e.g., to a regularSCHED_NODE_TYPE_VPORT),curr_type!= type evaluates to true, causing the function to skip saving the currenttc_bwshares.esw_qos_vport_disable()then unconditionally clearsvport_node->tc_bwto zero.
If the subsequentesw_qos_vport_enable()fails, the rollback path attempts to restore the oldTC_ARBITER_TSARstate.
However, becausecurr_type!= type, the code skips restoring the bandwidth shares viaesw_qos_set_tc_arbiter_bw_shares().
Are the vport's bandwidth guarantees permanently erased in this failure scenario?
[CR] Pre-existing, unlikely and low-impact: If tc-bw settings fail, there will be an error and an opportunity for the user to retry.
Quoted 20 lines
net/devlink/rate.c void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf) · line 1991
Quoted 3 lines
net/devlink/rate.c +0
-0@@ -1990,6 +1990,13 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf) esw->esw_funcs.num_vfs, esw->esw_funcs.num_ec_vfs, esw->enabled_vports);
mlx5_eswitch_invalidate_wq(esw);net/devlink/rate.c void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf) · line 1998
Quoted 7 lines
net/devlink/rate.c +7
-0+ +if (esw->mode ==MLX5_ESWITCH_OFFLOADS ) { +struct devlink *devlink =priv_to_devlink (esw->dev); + +devl_rate_nodes_destroy (devlink); + } +Can this reordering cause a use-after-free if leaf unparenting fails? Devlink's
devl_rate_nodes_destroy()callsops->rate_leaf_parent_set(..., NULL)which maps tomlx5_esw_qos_vport_update_parent(). Devlink ignores the return value of this callback.
If the hardware operation fails (e.g., due to a firmware timeout), the driver leavesvport->qos.sched_node->parentpointing to the original parent node. Devlink then unconditionally proceeds to destroy and free the rate node. Later, whenmlx5_eswitch_unload_vf_vports()executes, it callsmlx5_esw_qos_vport_disable(), which reachesesw_qos_vport_disable():
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c:esw_qos_vport_disable() { ... list_del_init(&vport_node->entry); esw_qos_normalize_min_rate(vport_node->esw, vport_node->parent, extack); ... }Will this dereference the freed
vport_node->parent, resulting in list corruption or a use-after-free?
[CR] This is a preexisting problem, brought to light by the reordering of group destruction before leaf destruction. It's extremely unlikely, requiring the firmware command to reparent a vport to its root to fail. Fixing this properly requires multiple patches and will be pursued after this series.
Quoted 9 lines
net/devlink/rate.c void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw) · line 2045
Quoted 7 lines
net/devlink/rate.c +3
-0@@ -2039,6 +2040,9 @@ void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw) esw->mode ==MLX5_ESWITCH_LEGACY ?"LEGACY" :"OFFLOADS" , esw->esw_funcs.num_vfs, esw->esw_funcs.num_ec_vfs, esw->enabled_vports); +if (esw->mode ==MLX5_ESWITCH_OFFLOADS ) +devl_rate_nodes_destroy (devlink); +Does this identical reordering in the locked disable path suffer from the same unparenting failure use-after-free described above?
[CR] Same comment as above. QoS improvements for the error paths will follow.
V10:
- Added a comment in devl_rate_nodes_destroy clarifying locking.
- Expanded 'supported_cross_device_rate_nodes' comment with locking expectations.
- Simplified rate locking by only keeping the common ancestor locked.
- Removed devlink_nested_in_get_locked and devlink_nested_in_put_unlock.
- devlink_nl_rate_parent_node_set iterates over the proper rate list.
- Refactored mlx5 locking given dev->shd is now optional (after [3]).
- Fixed a bug in pruning introduced by the root node patch.
- Fixed a bug on failure when detaching a node from parent.
- Clarified expectations for shared devlink rate storage.
- Fixed incorrect net namespace when listing shared instances.
V9:
https://lore.kernel.org/netdev/[email protected]/
Cosmin Ratiu (14):
devlink: Update nested instance locking comment
devlink: Add a helper for getting a nested-in instance
devlink: Migrate from info->user_ptr to info->ctx
devlink: Decouple rate storage from associated devlink object
devlink: Add parent dev to devlink API
devlink: Allow parent dev for rate-set and rate-new
devlink: Allow rate node parents from other devlinks net/mlx5: qos: Use mlx5_lag_query_bond_speed to query LAG speed net/mlx5: qos: Refactor vport QoS cleanup
net/mlx5: qos: Model the root node in the scheduling hierarchy net/mlx5: qos: Remove qos domains and use shd net/mlx5: qos: Support cross-device tx scheduling
selftests: drv-net: Add test for cross-esw rate scheduling net/mlx5: Document devlink rates
Documentation/netlink/specs/devlink.yaml | 30 +- .../networking/devlink/devlink-port.rst | 2 + Documentation/networking/devlink/index.rst | 8 +- Documentation/networking/devlink/mlx5.rst | 33 + .../net/ethernet/mellanox/mlx5/core/devlink.c | 1 + .../mellanox/mlx5/core/esw/devlink_port.c | 1 - .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 605 +++++++++--------- .../net/ethernet/mellanox/mlx5/core/esw/qos.h | 3 - .../net/ethernet/mellanox/mlx5/core/eswitch.c | 27 +- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 18 +- include/net/devlink.h | 9 + include/uapi/linux/devlink.h | 2 + net/devlink/core.c | 20 +- net/devlink/dev.c | 16 +- net/devlink/devl_internal.h | 20 + net/devlink/dpipe.c | 14 +- net/devlink/health.c | 12 +- net/devlink/linecard.c | 4 +- net/devlink/netlink.c | 82 ++- net/devlink/netlink_gen.c | 24 +- net/devlink/netlink_gen.h | 8 + net/devlink/param.c | 4 +- net/devlink/port.c | 18 +- net/devlink/rate.c | 331 +++++++--- net/devlink/region.c | 6 +- net/devlink/resource.c | 14 +- net/devlink/sb.c | 22 +- net/devlink/trap.c | 12 +- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../drivers/net/hw/devlink_rate_cross_esw.py | 296 +++++++++ 30 files changed, 1132 insertions(+), 511 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/hw/devlink_rate_cross_esw.py
base-commit: 1c664ec4b9ea827b609d296921ed5bad8a40a158
Signature · 1 line
2.44.0