Add devlink traps in
Subsystems (5)
v2 cover Add devlink traps in
Implement support for devlink traps on per-port basis. Dropped packets in the RX flow are related to the Ethernet port and thus should be in port context. Traps per device should trap global configuration which may cause drops. Devlink traps is regard as a debug mode. Using traps per port enable debug which doesn't effect other ports on a device.
Patchset:
Patch 1: Refactors devlink trap for easier code re-use in the coming patches
Patch 2: Adds devlink traps under devlink port context ports context. In a nutshell it allows enable/disable of a trap on all related ports which registered this trap.
Patch 3: Display a use in devlink traps in port context in mlx5 ethernet driver.
Changelog:
Minor changes in cover letterv1->v2:
Patch 1:
-Gather only the traps lists for future code reuse. Don't
try to reuse the traps ops.
Ptach 2:
-Add traps lock in devlink_port
-Add devlink_port ops and in it, add the trap ops -Add support onlty for traps and exclude groups and policy -Add separate netlink commands for port trap get and set -Allow trap registration without a corresponding group Patch 3: removed
Ptach 4:
-Is now patch 3
-Minor changes in trap's definition
-Adjustments to trap API and ops
Aya Levin (3):
devlink: Wrap trap related lists a trap_lists struct
devlink: Add devlink traps under devlink_ports context net/mlx5e: Add devlink trap to catch oversize packets
drivers/net/ethernet/mellanox/mlx5/core/Makefile | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 + drivers/net/ethernet/mellanox/mlx5/core/en/traps.c | 38 ++ drivers/net/ethernet/mellanox/mlx5/core/en/traps.h | 14 + drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 48 +++ drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 11 +- include/net/devlink.h | 54 ++- include/uapi/linux/devlink.h | 5 + net/core/devlink.c | 453 ++++++++++++++++++--- 9 files changed, 556 insertions(+), 71 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/traps.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/traps.h
Signature · 1 line
2.14.1
RFC PATCH v2 1/3 devlink: Wrap trap related
Bundle the trap related lists: trap_list, trap_group_list and trap_policer_list in a dedicated struct. This will be handy in the coming patches in the set introducing traps in devlink port context. With trap_lists, code reuse is much simpler.
---
Changelog:v1->v2:
Patch 1: Encapsulate only the traps lists for future code reuse. Don't try to reuse the traps ops.
include/net/devlink.h | 10 +++-- net/core/devlink.c | 109 ++++++++++++++++++++++++++------------------------ 2 files changed, 63 insertions(+), 56 deletions(-)
include/net/devlink.h +7 -3
@@ -22,6 +22,12 @@struct devlink_ops ; +struct devlink_trap_lists { +struct list_head trap_list; +struct list_head trap_group_list; +struct list_head trap_policer_list; +}; +struct devlink {struct list_head list;struct list_head port_list;
@@ -33,9 +39,7 @@ struct devlink {struct list_head reporter_list;struct mutex reporters_lock;/* protects reporter_list */ struct devlink_dpipe_headers *dpipe_headers; -struct list_head trap_list; -struct list_head trap_group_list; -struct list_head trap_policer_list; +struct devlink_trap_lists trap_lists;const struct devlink_ops *ops;struct xarray snapshot_ids;struct device *dev;
net/core/devlink.c +56 -53
378 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH v2 2/3 devlink: Add devlink traps
In reply to Aya LevinThere are some cases where we would like to trap dropped packets only for a single port on a device without affecting the others. For that purpose:
- Add trap lists and trap ops to devlink_port
- Add corresponding trap API to manage traps
- Add matching netlink commands
---
Changelog:v1->v2:
Add traps lock in devlink_port
Add devlink_port ops and in it, add the trap ops Add support onlty for traps and exclude groups and policer Add seperate netlink commands foor port trap get and set Allow trap registration without a corresponding group
include/net/devlink.h | 44 ++++++ include/uapi/linux/devlink.h | 5 + net/core/devlink.c | 346 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 382 insertions(+), 13 deletions(-)
include/net/devlink.h +44 -0
@@ -21,6 +21,8 @@#include <linux/xarray.h> struct devlink_ops ; +struct devlink_port_ops ; +struct devlink_trap_lists {struct list_head trap_list;
@@ -129,6 +131,9 @@ struct devlink_port {struct delayed_work type_warn_dw;struct list_head reporter_list;struct mutex reporters_lock;/* Protects reporter_list */ +struct mutex trap_lists_lock; +struct devlink_trap_lists trap_lists; +const struct devlink_port_ops *ops; };struct devlink_sb_pool_info {
@@ -1177,6 +1182,35 @@ struct devlink_ops { struct netlink_ext_ack *extack); }; +struct devlink_port_ops { +/** +* @trap_init: Trap initialization function. +* +* Should be used by device drivers to initialize the trap in the +* underlying device. Drivers should also store the provided trap +* context, so that they could efficiently pass it to +* devlink_trap_report() when the trap is triggered. +*/ +int (*trap_init)(struct devlink_port *devlink, +const struct devlink_trap *trap,void *trap_ctx); +/** +* @trap_fini: Trap de-initialization function. +* +* Should be used by device drivers to de-initialize the trap in the +* underlying device. +*/ + +void (*trap_fini)(struct devlink_port *devlink_port, +const struct devlink_trap *trap,void *trap_ctx); +/** +* @trap_action_set: Trap action set function. +*/ +int (*trap_action_set)(struct devlink_port *devlink_port, +const struct devlink_trap *trap, +enum devlink_trap_action action, +struct netlink_ext_ack *extack); +}; +static inline void *devlink_priv (struct devlink *devlink) {BUG_ON (!devlink);
@@ -1220,6 +1254,8 @@ int devlink_port_register(struct devlink *devlink,struct devlink_port *devlink_port, unsigned int port_index);void devlink_port_unregister (struct devlink_port *devlink_port); +void devlink_port_set_ops (struct devlink_port *devlink_port, +const struct devlink_port_ops *ops);void devlink_port_type_eth_set (struct devlink_port *devlink_port,struct net_device *netdev); void devlink_port_type_ib_set(struct devlink_port *devlink_port,
@@ -1429,6 +1465,14 @@ void devlink_trap_policers_unregister(struct devlink *devlink, const struct devlink_trap_policer *policers, size_t policers_count); +int devlink_port_traps_register (struct devlink_port *devlink_port, +const struct devlink_trap *traps, +size_t traps_count,void *priv); +void devlink_port_traps_unregister (struct devlink_port *devlink_port, +const struct devlink_trap *traps, +size_t traps_count); +void devlink_port_trap_report (struct devlink_port *devlink_port,struct sk_buff *skb, +void *trap_ctx,const struct flow_action_cookie *fa_cookie);#if IS_ENABLED (CONFIG_NET_DEVLINK )
include/uapi/linux/devlink.h +5 -0
@@ -122,6 +122,11 @@ enum devlink_command {DEVLINK_CMD_TRAP_POLICER_NEW ,DEVLINK_CMD_TRAP_POLICER_DEL , +DEVLINK_CMD_PORT_TRAP_GET ,/* can dump */ +DEVLINK_CMD_PORT_TRAP_SET , +DEVLINK_CMD_PORT_TRAP_NEW , +DEVLINK_CMD_PORT_TRAP_DEL , +/* add new commands above here */ __DEVLINK_CMD_MAX,DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX -1
net/core/devlink.c +333 -13
435 lines not on this page · raw message
Signature · 1 line
2.14.1
RFC PATCH v2 3/3 net/mlx5e: Add devlink
In reply to Aya LevinFrom: Aya Levin <[email protected]>
Register MTU error trap to allow visibility of oversize packets. Display a naive use of devlink trap in devlink port context.
---
Changelog:v1->v2:
-Minor changes in trap's definition
-Adjustments to trap API and ops
drivers/net/ethernet/mellanox/mlx5/core/Makefile | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 + drivers/net/ethernet/mellanox/mlx5/core/en/traps.c | 38 +++++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en/traps.h | 14 +++++++ drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 48 ++++++++++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 11 ++++- 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/traps.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/traps.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -25,7 +25,7 @@ mlx5_core-$(CONFIG_MLX5_CORE_EN) += en_main.o en_common.o en_fs.o en_ethtool.o \ en_tx.o en_rx.o en_dim.o en_txrx.o en/xdp.o en_stats.o \ en_selftest.o en/port.o en/monitor_stats.o en/health.o \ en/reporter_tx.o en/reporter_rx.o en/params.o en/xsk/pool.o \ - en/xsk/setup.o en/xsk/rx.o en/xsk/tx.o en/devlink.o + en/xsk/setup.o en/xsk/rx.o en/xsk/tx.o en/devlink.o en/traps.o # # Netdev extra
drivers/net/ethernet/mellanox/mlx5/core/en.h +2 -0
@@ -824,6 +824,8 @@ struct mlx5e_priv {struct mlx5e_hv_vhca_stats_agent stats_agent;#endif struct mlx5e_scratchpad scratchpad; +bool trap_oversize; +void *trap_mtu; };struct mlx5e_rx_handlers {
drivers/net/ethernet/mellanox/mlx5/core/en/traps.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Mellanox Technologies. +#include "traps.h" + +#define MLX5E_TRAP (_id, _type, _group_id) \ + DEVLINK_TRAP_GENERIC(_type, DROP, _id, \ + DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id, \ + DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT) +static struct devlink_trap mlx5e_traps_arr[] = { +MLX5E_TRAP (MTU_ERROR ,EXCEPTION ,L2_DROPS ), +}; + +int mlx5e_devlink_traps_create (struct mlx5e_priv *priv) +{ +struct devlink_port *dl_port = &priv->dl_port; + +return devlink_port_traps_register (dl_port, mlx5e_traps_arr, +ARRAY_SIZE (mlx5e_traps_arr), + priv); +} + +void mlx5e_devlink_traps_destroy (struct mlx5e_priv *priv) +{ +struct devlink_port *dl_port = &priv->dl_port; + +devlink_port_traps_unregister (dl_port, mlx5e_traps_arr, +ARRAY_SIZE (mlx5e_traps_arr)); +} + +struct devlink_trap *mlx5e_trap_lookup (u16 id) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (mlx5e_traps_arr); i++) +if (mlx5e_traps_arr[i].id == id) +return &mlx5e_traps_arr[i]; +return NULL ; +}
drivers/net/ethernet/mellanox/mlx5/core/en/traps.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2020 Mellanox Technologies.*/ + +#ifndef __MLX5E_EN_TRAPS_H +#define __MLX5E_EN_TRAPS_H + +#include "en.h" + +int mlx5e_devlink_traps_create (struct mlx5e_priv *priv); +void mlx5e_devlink_traps_destroy (struct mlx5e_priv *priv); +struct devlink_trap *mlx5e_trap_lookup (u16 id); + +#endif +
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +48 -0
72 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +9 -2
@@ -1445,6 +1445,7 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, u16 cqe_bcnt, u32 head_offset, u32 page_idx) { struct mlx5e_dma_info *di = &wi->umr.dma_info[page_idx]; +struct mlx5e_priv *priv = rq->channel->priv;u16 rx_headroom = rq->buff.headroom;u32 cqe_bcnt32 = cqe_bcnt;struct xdp_buff xdp;
@@ -1452,11 +1453,14 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,void *va, *data;u32 frag_size;bool consumed; +bool trap;/* Check packet size. Note LRO doesn't use linear SKB */ if (unlikely (cqe_bcnt > rq->hw_mtu)) { rq->stats->oversize_pkts_sw_drop++; -return NULL ; +if (!priv->trap_oversize) +return NULL ; + trap = true; } va =page_address (di->page) + head_offset;
@@ -1483,7 +1487,10 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, skb =mlx5e_build_linear_skb (rq, va, frag_size, rx_headroom, cqe_bcnt32);if (unlikely (!skb))return NULL ; - +if (trap) { +devlink_port_trap_report (&priv->dl_port, skb, priv->trap_mtu,NULL ); +return NULL ; + }/* queue up for recycling/reuse */ page_ref_inc (di->page);
Signature · 1 line
2.14.1