Support bandwidth clamping in mana using net shapers
Subsystems (5)
cover Support bandwidth clamping in mana using net shapers
This patchset introduces hardware-backed bandwidth rate limiting for MANA NICs via the net_shaper_ops interface, enabling efficient and fine-grained traffic shaping directly on the device.
Previously, MANA lacked a mechanism for user-configurable bandwidth control. With this addition, users can now configure shaping parameters, allowing better traffic management and performance isolation.
The implementation includes the net_shaper_ops callbacks in the MANA driver and supports one shaper per vport. Add shaping support via mana_set_bw_clamp(), allowing the configuration of bandwidth rates in 100 Mbps increments (minimum 100 Mbps). The driver validates input and rejects unsupported values. On failure, it restores the previous configuration which is queried using mana_query_link_cfg() or retains the current state.
To prevent potential deadlocks introduced by net_shaper_ops, switch to _locked variants of NAPI APIs when netdevops_lock is held during VF setup and teardown.
Also, Add support for ethtool get_link_ksettings to report the maximum link speed supported by the SKU in mbps.
These APIs when invoked on hardware that are older or that do not support these APIs, the speed would be reported as UNKNOWN and the net-shaper calls to set speed would fail.
Erni Sri Satya Vennela (4):
net: mana: Fix potential deadlocks in mana napi ops
net: mana: Add support for net_shaper_ops
net: mana: Add speed support in mana_get_link_ksettings
net: mana: Handle unsupported HWC commands
.../net/ethernet/microsoft/mana/hw_channel.c | 4 + drivers/net/ethernet/microsoft/mana/mana_en.c | 206 +++++++++++++++++- .../ethernet/microsoft/mana/mana_ethtool.c | 6 + include/net/mana/mana.h | 42 ++++ 4 files changed, 249 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 net: mana: Fix potential deadlocks in mana napi ops
When net_shaper_ops are enabled for MANA, netdev_ops_lock becomes active.
The netvsc sets up MANA VF via following call chain:
netvsc_vf_setup()
dev_change_flags()
...
__dev_open() OR __dev_close()dev_change_flags() holds the netdev mutex via netdev_lock_ops.
During this process, mana_create_txq() and mana_create_rxq() invoke netif_napi_add_tx(), netif_napi_add_weight(), and napi_enable(), all of which attempt to acquire the same lock,
leading to a potential deadlock.
Similarly, mana_destroy_txq() and mana_destroy_rxq() call netif_napi_disable() and netif_napi_del(), which also contend for the same lock.
Switch to the _locked variants of these APIs to avoid deadlocks when the netdev_ops_lock is held.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +30 -9
@@ -1911,8 +1911,13 @@ static void mana_destroy_txq(struct mana_port_context *apc) napi = &apc->tx_qp[i].tx_cq.napi;if (apc->tx_qp[i].txq.napi_initialized) {napi_synchronize (napi); -napi_disable (napi); -netif_napi_del (napi); +if (netdev_need_ops_lock (napi->dev)) { +napi_disable_locked (napi); +netif_napi_del_locked (napi); + }else { +napi_disable (napi); +netif_napi_del (napi); + } apc->tx_qp[i].txq.napi_initialized = false; }mana_destroy_wq_obj (apc,GDMA_SQ , apc->tx_qp[i].tx_object);
@@ -2064,8 +2069,14 @@ static int mana_create_txq(struct mana_port_context *apc,mana_create_txq_debugfs (apc, i); -netif_napi_add_tx (net, &cq->napi, mana_poll); -napi_enable (&cq->napi); +if (netdev_need_ops_lock (net)) { +set_bit (NAPI_STATE_NO_BUSY_POLL , &cq->napi.state); +netif_napi_add_locked (net, &cq->napi, mana_poll); +napi_enable_locked (&cq->napi); + }else { +netif_napi_add_tx (net, &cq->napi, mana_poll); +napi_enable (&cq->napi); + } txq->napi_initialized = true;mana_gd_ring_cq (cq->gdma_cq,SET_ARM_BIT );
@@ -2101,9 +2112,13 @@ static void mana_destroy_rxq(struct mana_port_context *apc,if (napi_initialized) {napi_synchronize (napi); -napi_disable (napi); - -netif_napi_del (napi); +if (netdev_need_ops_lock (napi->dev)) { +napi_disable_locked (napi); +netif_napi_del_locked (napi); + }else { +napi_disable (napi); +netif_napi_del (napi); + } }xdp_rxq_info_unreg (&rxq->xdp_rxq);
@@ -2354,14 +2369,20 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc, gc->cq_table[cq->gdma_id] = cq->gdma_cq; -netif_napi_add_weight (ndev, &cq->napi, mana_poll,1 ); +if (netdev_need_ops_lock (ndev)) +netif_napi_add_weight_locked (ndev, &cq->napi, mana_poll,1 ); +else +netif_napi_add_weight (ndev, &cq->napi, mana_poll,1 );WARN_ON (xdp_rxq_info_reg (&rxq->xdp_rxq, ndev, rxq_idx, cq->napi.napi_id));WARN_ON (xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , rxq->page_pool)); -napi_enable (&cq->napi); +if (netdev_need_ops_lock (ndev)) +napi_enable_locked (&cq->napi); +else +napi_enable (&cq->napi);mana_gd_ring_cq (cq->gdma_cq,SET_ARM_BIT ); out:
Signature · 1 line
2.34.1
PATCH 2/4 net: mana: Add support for net_shaper_ops
In reply to Erni Sri Satya VennelaIntroduce support for net_shaper_ops in the MANA driver, enabling configuration of rate limiting on the MANA NIC.
To apply rate limiting, the driver issues a HWC command via mana_set_bw_clamp() and updates the corresponding shaper object in the net_shaper cache. If an error occurs during this process, the driver restores the previous speed by querying the current link configuration using mana_query_link_cfg().
The minimum supported bandwidth is 100 Mbps, and only values that are exact multiples of 100 Mbps are allowed. Any other values are rejected.
To remove a shaper, the driver resets the bandwidth to the maximum supported by the SKU using mana_set_bw_clamp() and clears the associated cache entry. If an error occurs during this process, the shaper details are retained.
On the hardware that does not support these APIs, the net-shaper calls to set speed would fail.
Set the speed:./tools/net/ynl/pyynl/cli.py \
--spec Documentation/netlink/specs/net_shaper.yaml \
--do set --json '{"ifindex":'$IFINDEX',
"handle":{"scope": "netdev", "id":'$ID' },
"bw-max": 200000000 }'Get the shaper details:./tools/net/ynl/pyynl/cli.py \
--spec Documentation/netlink/specs/net_shaper.yaml \
--do get --json '{"ifindex":'$IFINDEX',
"handle":{"scope": "netdev", "id":'$ID' }}'Quoted 4 lines
{'bw-max': 200000000,
'handle': {'scope': 'netdev'},
'ifindex': $IFINDEX,
'metric': 'bps'}
Delete the shaper object:./tools/net/ynl/pyynl/cli.py \
--spec Documentation/netlink/specs/net_shaper.yaml \
--do delete --json '{"ifindex":'$IFINDEX',
"handle":{"scope": "netdev","id":'$ID' }}'--- drivers/net/ethernet/microsoft/mana/mana_en.c | 155 ++++++++++++++++++ include/net/mana/mana.h | 40 +++++ 2 files changed, 195 insertions(+)
drivers/net/ethernet/microsoft/mana/mana_en.c +155 -0
@@ -719,6 +719,78 @@ static int mana_change_mtu(struct net_device *ndev, int new_mtu)return err; } +static int mana_shaper_set (struct net_shaper_binding *binding, +const struct net_shaper *shaper, +struct netlink_ext_ack *extack) +{ +struct mana_port_context *apc =netdev_priv (binding->netdev); +u32 old_speed, rate; +int err; + +if (shaper->handle.scope !=NET_SHAPER_SCOPE_NETDEV ) { +NL_SET_ERR_MSG_MOD (extack,"net shaper scope should be netdev" ); +return -EINVAL ; + } + +if (apc->handle.id && shaper->handle.id != apc->handle.id) { +NL_SET_ERR_MSG_MOD (extack,"Cannot create multiple shapers" ); +return -EOPNOTSUPP ; + } + +if (!shaper->bw_max || (shaper->bw_max %100000000 )) { +NL_SET_ERR_MSG_MOD (extack,"Please use multiples of 100Mbps for bandwidth" ); +return -EINVAL ; + } + + rate =div_u64 (shaper->bw_max,1000 );/* Convert bps to Kbps */ + rate =div_u64 (rate,1000 );/* Convert Kbps to Mbps */ + +/* Get current speed */ + err =mana_query_link_cfg (apc); + old_speed = (err) ?SPEED_UNKNOWN : apc->speed; + +if (!err) { + err =mana_set_bw_clamp (apc, rate,TRI_STATE_TRUE ); + apc->speed = (err) ? old_speed : rate; + apc->handle = (err) ? apc->handle : shaper->handle; + } + +return err; +} + +static int mana_shaper_del (struct net_shaper_binding *binding, +const struct net_shaper_handle *handle, +struct netlink_ext_ack *extack) +{ +struct mana_port_context *apc =netdev_priv (binding->netdev); +int err; + + err =mana_set_bw_clamp (apc,0 ,TRI_STATE_FALSE ); + +if (!err) { +/* Reset mana port context parameters */ + apc->handle.id =0 ; + apc->handle.scope =NET_SHAPER_SCOPE_UNSPEC ; + apc->speed =0 ; + } + +return err; +} + +static void mana_shaper_cap (struct net_shaper_binding *binding, +enum net_shaper_scope scope, +unsigned long *flags) +{ + *flags =BIT (NET_SHAPER_A_CAPS_SUPPORT_BW_MAX ) | +BIT (NET_SHAPER_A_CAPS_SUPPORT_METRIC_BPS ); +} + +static const struct net_shaper_ops mana_shaper_ops = { + .set = mana_shaper_set, + .delete = mana_shaper_del, + .capabilities = mana_shaper_cap, +}; +static const struct net_device_ops mana_devops = { .ndo_open = mana_open, .ndo_stop = mana_close,
@@ -729,6 +801,7 @@ static const struct net_device_ops mana_devops = { .ndo_bpf = mana_bpf, .ndo_xdp_xmit = mana_xdp_xmit, .ndo_change_mtu = mana_change_mtu, + .net_shaper_ops = &mana_shaper_ops, };static void mana_cleanup_port_context (struct mana_port_context *apc)
@@ -1161,6 +1234,86 @@ static int mana_cfg_vport_steering(struct mana_port_context *apc,return err; } +int mana_query_link_cfg (struct mana_port_context *apc) +{ +struct net_device *ndev = apc->ndev; +struct mana_query_link_config_resp resp = {}; +struct mana_query_link_config_req req = {}; +int err; + +mana_gd_init_req_hdr (&req.hdr,MANA_QUERY_LINK_CONFIG , +sizeof (req),sizeof (resp)); + + req.vport = apc->port_handle; + req.hdr.resp.msg_version =GDMA_MESSAGE_V2 ; + + err =mana_send_request (apc->ac, &req,sizeof (req), &resp, +sizeof (resp)); + +if (err) { +netdev_err (ndev,"Failed to query link config: %d\n" , err); +return err; + } + + err =mana_verify_resp_hdr (&resp.hdr,MANA_QUERY_LINK_CONFIG , +sizeof (resp)); + +if (err || resp.hdr.status) { +netdev_err (ndev,"Failed to query link config: %d, 0x%x\n" , err, + resp.hdr.status); +if (!err) + err = -EOPNOTSUPP ; +return err; + } + +if (resp.qos_unconfigured) { + err = -EINVAL ; +return err; + } + apc->speed = resp.link_speed_mbps; +return 0 ; +} + +int mana_set_bw_clamp (struct mana_port_context *apc,u32 speed, +int enable_clamping) +{ +struct mana_set_bw_clamp_resp resp = {}; +struct mana_set_bw_clamp_req req = {}; +struct net_device *ndev = apc->ndev; +int err; + +mana_gd_init_req_hdr (&req.hdr,MANA_SET_BW_CLAMP , +sizeof (req),sizeof (resp)); + req.vport = apc->port_handle; + req.link_speed_mbps = speed; + req.enable_clamping = enable_clamping; + + err =mana_send_request (apc->ac, &req,sizeof (req), &resp, +sizeof (resp)); + +if (err) { +netdev_err (ndev,"Failed to set bandwidth clamp for speed %u, err = %d" , + speed, err); +return err; + } + + err =mana_verify_resp_hdr (&resp.hdr,MANA_SET_BW_CLAMP , +sizeof (resp)); + +if (err || resp.hdr.status) { +netdev_err (ndev,"Failed to set bandwidth clamp: %d, 0x%x\n" , err, + resp.hdr.status); +if (!err) + err = -EOPNOTSUPP ; +return err; + } + +if (resp.qos_unconfigured) { +netdev_err (ndev,"QoS is unconfigured\n" ); +return -EINVAL ; + } + +return 0 ; +} + int mana_create_wq_obj(struct mana_port_context *apc,
mana_handle_t vport,
u32 wq_type, struct mana_obj_spec *wq_spec,
@@ -2939,6 +3092,8 @@ static int mana_probe_port(struct mana_context *ac, int port_idx,
goto free_indir;
}
+ debugfs_create_u32("current_speed", 0400, apc->mana_port_debugfs, &apc->speed);
+
return 0;
free_indir:
include/net/mana/mana.h +40 -0
@@ -5,6 +5,7 @@#define _MANA_H#include <net/xdp.h> +#include <net/net_shaper.h> #include "gdma.h" #include "hw_channel.h"
@@ -467,7 +468,12 @@ struct mana_port_context {struct mutex vport_mutex;int vport_use_count; +/* Net shaper handle*/ +struct net_shaper_handle handle; +u16 port_idx; +/* Currently configured speed (mbps) */ +u32 speed;bool port_is_up;bool port_st_save;/* Saved port state */
@@ -501,6 +507,9 @@ struct bpf_prog *mana_xdp_get(struct mana_port_context *apc);void mana_chn_setxdp (struct mana_port_context *apc,struct bpf_prog *prog);int mana_bpf (struct net_device *ndev,struct netdev_bpf *bpf);void mana_query_gf_stats (struct mana_port_context *apc); +int mana_query_link_cfg (struct mana_port_context *apc); +int mana_set_bw_clamp (struct mana_port_context *apc,u32 speed, +int enable_clamping);int mana_pre_alloc_rxbufs (struct mana_port_context *apc,int mtu,int num_queues);void mana_pre_dealloc_rxbufs (struct mana_port_context *apc);
@@ -527,6 +536,8 @@ enum mana_command_code {MANA_FENCE_RQ =0x20006 ,MANA_CONFIG_VPORT_RX =0x20007 ,MANA_QUERY_VPORT_CONFIG =0x20008 , +MANA_QUERY_LINK_CONFIG =0x2000A , +MANA_SET_BW_CLAMP =0x2000B ,/* Privileged commands for the PF mode */ MANA_REGISTER_FILTER = 0x28000,
@@ -535,6 +546,35 @@ enum mana_command_code { MANA_DEREGISTER_HW_PORT = 0x28004, }; +/* Query Link Configuration*/ +struct mana_query_link_config_req { +struct gdma_req_hdr hdr; +mana_handle_t vport; +};/* HW DATA */ + +struct mana_query_link_config_resp { +struct gdma_resp_hdr hdr; +u32 qos_speed_mbps; +u8 qos_unconfigured; +u8 reserved1[3 ]; +u32 link_speed_mbps; +u8 reserved2[4 ]; +};/* HW DATA */ + +/* Set Bandwidth Clamp*/ +struct mana_set_bw_clamp_req { +struct gdma_req_hdr hdr; +mana_handle_t vport; +enum TRI_STATE enable_clamping; +u32 link_speed_mbps; +};/* HW DATA */ + +struct mana_set_bw_clamp_resp { +struct gdma_resp_hdr hdr; +u8 qos_unconfigured; +u8 reserved[7 ]; +};/* HW DATA */ +/* Query Device Configuration */ struct mana_query_device_cfg_req {struct gdma_req_hdr hdr;
Signature · 1 line
2.34.1
PATCH 3/4 net: mana: Add speed support in mana_get_link_ksettings
In reply to Erni Sri Satya VennelaAllow mana ethtool get_link_ksettings operation to report the maximum speed supported by the SKU in mbps.
The driver retrieves this information by issuing a HWC command to the hardware via mana_query_link_cfg(), which retrieves the SKU's maximum supported speed.
These APIs when invoked on hardware that are older ot that do not support these APIs, the speed would be reported as UNKNOWN.
Before:
$ethtool enP30832s1
Quoted 1 line
Settings for enP30832s1:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: Unknown!
Duplex: Full
Auto-negotiation: off
Port: Other
PHYAD: 0
Transceiver: internal
Link detected: yes
After:
$ethtool enP30832s1
Quoted 1 line
Settings for enP30832s1:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: 16000Mb/s
Duplex: Full
Auto-negotiation: off
Port: Other
PHYAD: 0
Transceiver: internal
Link detected: yes
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + drivers/net/ethernet/microsoft/mana/mana_ethtool.c | 6 ++++++ include/net/mana/mana.h | 2 ++ 3 files changed, 9 insertions(+)
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
@@ -1271,6 +1271,7 @@ int mana_query_link_cfg(struct mana_port_context *apc)return err; } apc->speed = resp.link_speed_mbps; + apc->max_speed = resp.qos_speed_mbps;return 0 ; }
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +6 -0
@@ -427,6 +427,12 @@ static int mana_set_ringparam(struct net_device *ndev,static int mana_get_link_ksettings (struct net_device *ndev,struct ethtool_link_ksettings *cmd) { +struct mana_port_context *apc =netdev_priv (ndev); +int err; + + err =mana_query_link_cfg (apc); + cmd->base.speed = (err) ?SPEED_UNKNOWN : apc->max_speed; + cmd->base.duplex =DUPLEX_FULL ; cmd->base.port =PORT_OTHER ;
include/net/mana/mana.h +2 -0
@@ -474,6 +474,8 @@ struct mana_port_context {u16 port_idx;/* Currently configured speed (mbps) */ u32 speed; +/* Maximum speed supported by the SKU (mbps) */ +u32 max_speed;bool port_is_up;bool port_st_save;/* Saved port state */
Signature · 1 line
2.34.1
PATCH 4/4 net: mana: Handle unsupported HWC commands
In reply to Erni Sri Satya VennelaIf any of the HWC commands are not recognized by the underlying hardware, the hardware returns the response header status of -1. Log the information using netdev_info_once to avoid multiple error logs in dmesg.
--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 11 +++++++++++ 2 files changed, 15 insertions(+)
drivers/net/ethernet/microsoft/mana/hw_channel.c +4 -0
@@ -890,6 +890,10 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, }if (ctx->status_code && ctx->status_code !=GDMA_STATUS_MORE_ENTRIES ) { +if (ctx->status_code ==-1 ) { + err = -EOPNOTSUPP ; + goto out; + }dev_err (hwc->dev,"HWC: Failed hw_channel req: 0x%x\n" , ctx->status_code); err = -EPROTO ;
drivers/net/ethernet/microsoft/mana/mana_en.c +11 -0
@@ -847,6 +847,9 @@ static int mana_send_request(struct mana_context *ac, void *in_buf, err =mana_gd_send_request (gc, in_len, in_buf, out_len, out_buf);if (err || resp->status) { +if (err == -EOPNOTSUPP ) +return err; +dev_err (dev,"Failed to send mana message: %d, 0x%x\n" , err, resp->status);return err ? err : -EPROTO ;
@@ -1251,6 +1254,10 @@ int mana_query_link_cfg(struct mana_port_context *apc) sizeof(resp));if (err) { +if (err == -EOPNOTSUPP ) { +netdev_info_once (ndev,"MANA_QUERY_LINK_CONFIG not supported\n" ); +return err; + }netdev_err (ndev,"Failed to query link config: %d\n" , err);return err; }
@@ -1293,6 +1300,10 @@ int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, sizeof(resp));if (err) { +if (err == -EOPNOTSUPP ) { +netdev_info_once (ndev,"MANA_SET_BW_CLAMP not supported\n" ); +return err; + }netdev_err (ndev,"Failed to set bandwidth clamp for speed %u, err = %d" , speed, err);return err;
Signature · 1 line
2.34.1
Re: [PATCH net-next 1/4] net: mana: Fix potential deadlocks in mana napi ops
In reply to Erni Sri Satya VennelaQuoted 10 lines · Erni Sri Satya Vennela
When
net_shaper_opsare enabled for MANA,netdev_ops_lockbecomes active.The netvsc sets up MANA VF via following call chain:
netvsc_vf_setup()dev_change_flags() ... __dev_open() OR __dev_close()
Quoted 6 lines
dev_change_flags()holds the netdev mutex vianetdev_lock_ops.During this process,
mana_create_txq()andmana_create_rxq()invokenetif_napi_add_tx(),netif_napi_add_weight(), andnapi_enable(), all of which attempt to acquire the same lock,
leading to a potential deadlock.
commit message could be better oriented.
Quoted 23 lines
Similarly,
mana_destroy_txq()andmana_destroy_rxq()callnetif_napi_disable()andnetif_napi_del(), which also contend for the same lock.Switch to the
_lockedvariants of these APIs to avoid deadlocks when thenetdev_ops_lockis held.Fixes d4c22ec680c8 ("net: hold netdev instance lock during ndo_open/ndo_stop")Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>Reviewed-by Shradha Gupta <[email protected]>--- drivers/net/ethernet/microsoft/mana/mana_en.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-)drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -1911,8 +1911,13 @@ static void mana_destroy_txq(struct mana_port_context *apc) napi = &apc->tx_qp[i].tx_cq.napi;if (apc->tx_qp[i].txq.napi_initialized) {
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct mana_port_context *apc) · line 1920
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7
-2napi_synchronize (napi); -napi_disable (napi); -netif_napi_del (napi); +if (netdev_need_ops_lock (napi->dev)) { +napi_disable_locked (napi); +netif_napi_del_locked (napi); + }else { +napi_disable (napi); +netif_napi_del (napi); + }
Instead of using if-else, we can used netdev_lock_ops(), followed by *_locked api-s. Same for rest of the patch.
- Saurabh
Re: [PATCH net-next 4/4] net: mana: Handle unsupported HWC commands
In reply to Erni Sri Satya VennelaQuoted 18 lines · Erni Sri Satya Vennela
If any of the HWC commands are not recognized by the underlying hardware, the hardware returns the response header status of -1. Log the information using
netdev_info_onceto avoid multiple error logs in dmesg.Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>Reviewed-by Shradha Gupta <[email protected]>--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 11 +++++++++++ 2 files changed, 15 insertions(+)drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0
drivers/net/ethernet/microsoft/mana/hw_channel.c int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, · line 893
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-0@@ -890,6 +890,10 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, }if (ctx->status_code && ctx->status_code !=GDMA_STATUS_MORE_ENTRIES ) { +if (ctx->status_code ==-1 ) {
Minor comment: instead of == -1 could use some macro like GDMA_STATUS_CMD_UNSUPPORTED, rest LGTM.
Quoted 45 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +3
-0+ err = -EOPNOTSUPP ; + goto out; + }dev_err (hwc->dev,"HWC: Failed hw_channel req: 0x%x\n" , ctx->status_code); err = -EPROTO ;drivers/net/ethernet/microsoft/mana/mana_en.c +11
-0@@ -847,6 +847,9 @@ static int mana_send_request(struct mana_context *ac, void *in_buf, err =mana_gd_send_request (gc, in_len, in_buf, out_len, out_buf);if (err || resp->status) { +if (err == -EOPNOTSUPP ) +return err; +dev_err (dev,"Failed to send mana message: %d, 0x%x\n" , err, resp->status);return err ? err : -EPROTO ;@@ -1251,6 +1254,10 @@ int mana_query_link_cfg(struct mana_port_context *apc) sizeof(resp));if (err) { +if (err == -EOPNOTSUPP ) { +netdev_info_once (ndev,"MANA_QUERY_LINK_CONFIG not supported\n" ); +return err; + }netdev_err (ndev,"Failed to query link config: %d\n" , err);return err; }@@ -1293,6 +1300,10 @@ int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, sizeof(resp));if (err) { +if (err == -EOPNOTSUPP ) { +netdev_info_once (ndev,"MANA_SET_BW_CLAMP not supported\n" ); +return err; + }netdev_err (ndev,"Failed to set bandwidth clamp for speed %u, err = %d" , speed, err);return err;Signature · 1 line
2.34.1
Re: [PATCH net-next 1/4] net: mana: Fix potential deadlocks in mana napi ops
In reply to Saurabh Singh SengarQuoted 48 lines · Saurabh Singh Sengar
Quoted 10 lines · Erni Sri Satya Vennela
When
net_shaper_opsare enabled for MANA,netdev_ops_lockbecomes active.The netvsc sets up MANA VF via following call chain:
netvsc_vf_setup()dev_change_flags() ... __dev_open() OR __dev_close()Quoted 6 lines
dev_change_flags()holds the netdev mutex vianetdev_lock_ops.During this process,
mana_create_txq()andmana_create_rxq()invokenetif_napi_add_tx(),netif_napi_add_weight(), andnapi_enable(), all of which attempt to acquire the same lock,
leading to a potential deadlock.commit message could be better oriented.
Quoted 28 lines
Similarly,
mana_destroy_txq()andmana_destroy_rxq()callnetif_napi_disable()andnetif_napi_del(), which also contend for the same lock.Switch to the
_lockedvariants of these APIs to avoid deadlocks when thenetdev_ops_lockis held.Fixes d4c22ec680c8 ("net: hold netdev instance lock during ndo_open/ndo_stop")Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>Reviewed-by Shradha Gupta <[email protected]>--- drivers/net/ethernet/microsoft/mana/mana_en.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-)drivers/net/ethernet/microsoft/mana/mana_en.c +2
-2@@ -1911,8 +1911,13 @@ static void mana_destroy_txq(struct mana_port_context *apc) napi = &apc->tx_qp[i].tx_cq.napi;if (apc->tx_qp[i].txq.napi_initialized) {napi_synchronize (napi); -napi_disable (napi); -netif_napi_del (napi); +if (netdev_need_ops_lock (napi->dev)) { +napi_disable_locked (napi);
Quoted 9 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct mana_port_context *apc) · line 1920
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +5
-0+netif_napi_del_locked (napi); + }else { +napi_disable (napi); +netif_napi_del (napi); + }Instead of using if-else, we can used
netdev_lock_ops(), followed by*_lockedapi-s. Same for rest of the patch.
I later realized that what we actually need is:
if (!netdev_need_ops_lock(napi->dev))
netdev_lock(dev);
not
if (netdev_need_ops_lock(napi->dev))
netdev_lock(dev);Hence, netdev_lock_ops() is not appropriate. Instead, netdev_lock_ops_to_full() seems to be a better choice.
Quoted 4 lines
Reviewed-by Saurabh Sengar <[email protected]>- Saurabh
RE: [PATCH net-next 1/4] net: mana: Fix potential deadlocks in mana napi ops
Quoted 72 lines
Subject: Re: [PATCH net-next 1/4] net: mana: Fix potential deadlocks in mana napi ops
Quoted 38 lines · Saurabh Singh Sengar
Quoted 10 lines · Erni Sri Satya Vennela
When
net_shaper_opsare enabled for MANA,netdev_ops_lockbecomes active.The netvsc sets up MANA VF via following call chain:
netvsc_vf_setup()dev_change_flags() ... __dev_open() OR __dev_close()Quoted 6 lines
dev_change_flags()holds the netdev mutex vianetdev_lock_ops.During this process,
mana_create_txq()andmana_create_rxq()invokenetif_napi_add_tx(),netif_napi_add_weight(), andnapi_enable(), all of which attempt to acquire the same lock, leading to a potential deadlock.commit message could be better oriented.
Quoted 18 lines
Similarly,
mana_destroy_txq()andmana_destroy_rxq()callnetif_napi_disable()andnetif_napi_del(), which also contend for the same lock.Switch to the
_lockedvariants of these APIs to avoid deadlocks when thenetdev_ops_lockis held.Fixes d4c22ec680c8 ("net: hold netdev instance lock duringndo_open/ndo_stop")
Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>Reviewed-by Shradha Gupta <[email protected]>--- drivers/net/ethernet/microsoft/mana/mana_en.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-)Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -1911,8 +1911,13 @@ static void mana_destroy_txq(struct
mana_port_context*apc)Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +1
-2napi = &apc->tx_qp[i].tx_cq.napi;if (apc->tx_qp[i].txq.napi_initialized) {napi_synchronize (napi); -napi_disable (napi); -netif_napi_del (napi); +if (netdev_need_ops_lock (napi->dev)) {Quoted 8 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct mana_port_context *apc) · line 1920
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6
-0+napi_disable_locked (napi); +netif_napi_del_locked (napi); + }else { +napi_disable (napi); +netif_napi_del (napi); + }Instead of using if-else, we can used
netdev_lock_ops(), followed by*_lockedapi-s.
Quoted 2 lines
Same for rest of the patch.
I later realized that what we actually need is:
if (!netdev_need_ops_lock(napi->dev))
netdev_lock(dev);
Quoted 7 lines
not
if (netdev_need_ops_lock(napi->dev)) netdev_lock(dev);Hence,
netdev_lock_ops()is not appropriate. Instead,netdev_lock_ops_to_full()seems to be a better choice.
Yes, netdev_lock_ops_to_full() seems better.
Long
Re: [PATCH net-next 1/4] net: mana: Fix potential deadlocks in mana napi ops
Quoted 74 lines · Long Li
Quoted 74 lines
Subject: Re: [PATCH net-next 1/4] net: mana: Fix potential deadlocks in mana napi ops
Quoted 38 lines · Saurabh Singh Sengar
Quoted 10 lines · Erni Sri Satya Vennela
When
net_shaper_opsare enabled for MANA,netdev_ops_lockbecomes active.The netvsc sets up MANA VF via following call chain:
netvsc_vf_setup()dev_change_flags() ... __dev_open() OR __dev_close()Quoted 6 lines
dev_change_flags()holds the netdev mutex vianetdev_lock_ops.During this process,
mana_create_txq()andmana_create_rxq()invokenetif_napi_add_tx(),netif_napi_add_weight(), andnapi_enable(), all of which attempt to acquire the same lock, leading to a potential deadlock.commit message could be better oriented.
Quoted 18 lines
Similarly,
mana_destroy_txq()andmana_destroy_rxq()callnetif_napi_disable()andnetif_napi_del(), which also contend for the same lock.Switch to the
_lockedvariants of these APIs to avoid deadlocks when thenetdev_ops_lockis held.Fixes d4c22ec680c8 ("net: hold netdev instance lock duringndo_open/ndo_stop")
Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>Reviewed-by Shradha Gupta <[email protected]>--- drivers/net/ethernet/microsoft/mana/mana_en.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-)Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -1911,8 +1911,13 @@ static void mana_destroy_txq(struct
mana_port_context*apc)Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +1
-2napi = &apc->tx_qp[i].tx_cq.napi;if (apc->tx_qp[i].txq.napi_initialized) {napi_synchronize (napi); -napi_disable (napi); -netif_napi_del (napi); +if (netdev_need_ops_lock (napi->dev)) {Quoted 8 lines
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_destroy_txq(struct mana_port_context *apc) · line 1920
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6
-0+napi_disable_locked (napi); +netif_napi_del_locked (napi); + }else { +napi_disable (napi); +netif_napi_del (napi); + }Instead of using if-else, we can used
netdev_lock_ops(), followed by*_lockedapi-s.
Quoted 2 lines
Same for rest of the patch.
I later realized that what we actually need is:
if (!netdev_need_ops_lock(napi->dev))
netdev_lock(dev);not
Quoted 7 lines
Quoted 5 lines
if (netdev_need_ops_lock(napi->dev)) netdev_lock(dev);Hence,
netdev_lock_ops()is not appropriate. Instead,netdev_lock_ops_to_full()seems to be a better choice.Yes,
netdev_lock_ops_to_full()seems better
Thankyou, Saurabh and Long, for the suggestion. I'll make sure to incorporate this API in my next version.
Quoted 1 line
Long
Re: [PATCH net-next 4/4] net: mana: Handle unsupported HWC commands
In reply to Dipayaan RoyQuoted 21 lines · Dipayaan Roy
Quoted 20 lines · Erni Sri Satya Vennela
If any of the HWC commands are not recognized by the underlying hardware, the hardware returns the response header status of -1. Log the information using
netdev_info_onceto avoid multiple error logs in dmesg.Signed-off-by Erni Sri Satya Vennela <[email protected]>Reviewed-by Haiyang Zhang <[email protected]>Reviewed-by Shradha Gupta <[email protected]>--- drivers/net/ethernet/microsoft/mana/hw_channel.c | 4 ++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 11 +++++++++++ 2 files changed, 15 insertions(+)drivers/net/ethernet/microsoft/mana/hw_channel.c +0
-0@@ -890,6 +890,10 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, }
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len, · line 893
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/hw_channel.c +1
-0if (ctx->status_code && ctx->status_code !=GDMA_STATUS_MORE_ENTRIES ) { +if (ctx->status_code ==-1 ) {Minor comment: instead of == -1 could use some macro like
GDMA_STATUS_CMD_UNSUPPORTED, rest LGTM.
Thankyou Dipayaan.
I'll define this macro and us it for the next version.
Quoted 2 lines
Reviewed-by Dipayaan Roy <[email protected]>