From patchwork Wed Sep 2 15:32:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aya Levin X-Patchwork-Id: 261621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43ABBC433E7 for ; Wed, 2 Sep 2020 15:33:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AA2220767 for ; Wed, 2 Sep 2020 15:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728431AbgIBPdW (ORCPT ); Wed, 2 Sep 2020 11:33:22 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52318 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728376AbgIBPcg (ORCPT ); Wed, 2 Sep 2020 11:32:36 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ayal@mellanox.com) with SMTP; 2 Sep 2020 18:32:29 +0300 Received: from dev-l-vrt-210.mtl.labs.mlnx (dev-l-vrt-210.mtl.labs.mlnx [10.234.210.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 082FWTDB014704; Wed, 2 Sep 2020 18:32:29 +0300 Received: from dev-l-vrt-210.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Debian-8ubuntu1) with ESMTP id 082FWTUU026693; Wed, 2 Sep 2020 18:32:29 +0300 Received: (from ayal@localhost) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id 082FWTiR026692; Wed, 2 Sep 2020 18:32:29 +0300 From: Aya Levin To: "David S. Miller" , Jakub Kicinski , Jiri Pirko , netdev@vger.kernel.org Cc: Moshe Shemesh , Eran Ben Elisha , Ido Schimmel , linux-kernel@vger.kernel.org, Aya Levin Subject: [PATCH net-next RFC v1 3/4] devlink: Add hierarchy between traps in device level and port level Date: Wed, 2 Sep 2020 18:32:13 +0300 Message-Id: <1599060734-26617-4-git-send-email-ayal@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1599060734-26617-1-git-send-email-ayal@mellanox.com> References: <1599060734-26617-1-git-send-email-ayal@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Managing large scale port's traps may be complicated. This patch introduces a shortcut: when setting a trap on a device and this trap is not registered on this device, the action will take place on all related ports that did register this trap. Signed-off-by: Aya Levin --- net/core/devlink.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index b13e1b40bf1c..dea5482b2517 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -6501,23 +6501,46 @@ static int devlink_nl_cmd_trap_set_doit(struct sk_buff *skb, struct devlink *devlink = info->user_ptr[0]; struct devlink_trap_mngr *trap_mngr; struct devlink_trap_item *trap_item; + struct devlink_port *devlink_port; int err; - trap_mngr = devlink_trap_get_trap_mngr_from_info(devlink, info); - if (list_empty(&trap_mngr->trap_list)) - return -EOPNOTSUPP; + devlink_port = devlink_port_get_from_attrs(devlink, info->attrs); + if (IS_ERR(devlink_port)) { + trap_mngr = &devlink->trap_mngr; + if (list_empty(&trap_mngr->trap_list)) + goto loop_over_ports; - trap_item = devlink_trap_item_get_from_info(trap_mngr, info); - if (!trap_item) { - NL_SET_ERR_MSG_MOD(extack, "Device did not register this trap"); - return -ENOENT; + trap_item = devlink_trap_item_get_from_info(trap_mngr, info); + if (!trap_item) + goto loop_over_ports; + } else { + trap_mngr = &devlink_port->trap_mngr; + if (list_empty(&trap_mngr->trap_list)) + return -EOPNOTSUPP; + + trap_item = devlink_trap_item_get_from_info(trap_mngr, info); + if (!trap_item) { + NL_SET_ERR_MSG_MOD(extack, "Port did not register this trap"); + return -ENOENT; + } } return devlink_trap_action_set(devlink, trap_mngr, trap_item, info); - err = devlink_trap_action_set(devlink, trap_mngr, trap_item, info); - if (err) - return err; +loop_over_ports: + if (list_empty(&devlink->port_list)) + return -EOPNOTSUPP; + list_for_each_entry(devlink_port, &devlink->port_list, list) { + trap_mngr = &devlink_port->trap_mngr; + if (list_empty(&trap_mngr->trap_list)) + continue; + trap_item = devlink_trap_item_get_from_info(trap_mngr, info); + if (!trap_item) + continue; + err = devlink_trap_action_set(devlink, trap_mngr, trap_item, info); + if (err) + return err; + } return 0; } From patchwork Wed Sep 2 15:32:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aya Levin X-Patchwork-Id: 261622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CE76C433E2 for ; Wed, 2 Sep 2020 15:33:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7652A207EA for ; Wed, 2 Sep 2020 15:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728407AbgIBPdI (ORCPT ); Wed, 2 Sep 2020 11:33:08 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52313 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728378AbgIBPch (ORCPT ); Wed, 2 Sep 2020 11:32:37 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ayal@mellanox.com) with SMTP; 2 Sep 2020 18:32:29 +0300 Received: from dev-l-vrt-210.mtl.labs.mlnx (dev-l-vrt-210.mtl.labs.mlnx [10.234.210.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 082FWTlq014707; Wed, 2 Sep 2020 18:32:29 +0300 Received: from dev-l-vrt-210.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Debian-8ubuntu1) with ESMTP id 082FWTDo026695; Wed, 2 Sep 2020 18:32:29 +0300 Received: (from ayal@localhost) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id 082FWTjE026694; Wed, 2 Sep 2020 18:32:29 +0300 From: Aya Levin To: "David S. Miller" , Jakub Kicinski , Jiri Pirko , netdev@vger.kernel.org Cc: Moshe Shemesh , Eran Ben Elisha , Ido Schimmel , linux-kernel@vger.kernel.org, Aya Levin Subject: [PATCH net-next RFC v1 4/4] net/mlx5e: Add devlink trap to catch oversize packets Date: Wed, 2 Sep 2020 18:32:14 +0300 Message-Id: <1599060734-26617-5-git-send-email-ayal@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1599060734-26617-1-git-send-email-ayal@mellanox.com> References: <1599060734-26617-1-git-send-email-ayal@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Register MTU error trap to allow visibility of oversize packets. Display a naive use of devlink trap in devlink port context. Signed-off-by: Aya Levin --- 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 | 32 +++++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en/traps.h | 13 +++++++ drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 41 ++++++++++++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 11 ++++-- 6 files changed, 98 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 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile index 94268a697e1c..78e2e9107986 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile @@ -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/umem.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 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 0cc2080fd847..7e5581ed9311 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -814,6 +814,8 @@ struct mlx5e_priv { struct mlx5e_hv_vhca_stats_agent stats_agent; #endif struct mlx5e_scratchpad scratchpad; + void *trap_mtu; + bool trap_oversize; }; struct mlx5e_rx_handlers { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/traps.c b/drivers/net/ethernet/mellanox/mlx5/core/en/traps.c new file mode 100644 index 000000000000..e365e8dbd6ff --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/traps.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Mellanox Technologies. +#include "en.h" +#include "traps.h" +#include +#include + +#define MLX5E_TRAP(_id, _group_id) \ + DEVLINK_TRAP_GENERIC(DROP, 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, 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)); +} + diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/traps.h b/drivers/net/ethernet/mellanox/mlx5/core/en/traps.h new file mode 100644 index 000000000000..14a32b6968ee --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/traps.h @@ -0,0 +1,13 @@ +/* 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); + +#endif + diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index aebcf73f8546..056f34326b3d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -64,6 +64,7 @@ #include "en/hv_vhca_stats.h" #include "en/devlink.h" #include "lib/mlx5.h" +#include "en/traps.h" bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev) { @@ -4976,6 +4977,43 @@ void mlx5e_destroy_q_counters(struct mlx5e_priv *priv) } } +static int mlx5e_devlink_trap_init(struct devlink *devlink, + const struct devlink_trap *trap, + void *trap_ctx) +{ + struct mlx5e_priv *priv = (struct mlx5e_priv *)devlink_trap_ctx_priv(trap_ctx); + + priv->trap_mtu = trap_ctx; + return 0; +} + +static void mlx5e_devlink_trap_fini(struct devlink *devlink, + const struct devlink_trap *trap, + void *trap_ctx) +{ + struct mlx5e_priv *priv = (struct mlx5e_priv *)devlink_trap_ctx_priv(trap_ctx); + + priv->trap_mtu = NULL; +} + +static int mlx5e_devlink_trap_action_set(struct devlink *devlink, + const struct devlink_trap *trap, + enum devlink_trap_action action, + void *trap_ctx, + struct netlink_ext_ack *extack) +{ + struct mlx5e_priv *priv = (struct mlx5e_priv *)devlink_trap_ctx_priv(trap_ctx); + + priv->trap_oversize = !!action; + return 0; +} + +static const struct devlink_trap_ops mlx5e_devlink_traps_ops = { + .trap_init = mlx5e_devlink_trap_init, + .trap_fini = mlx5e_devlink_trap_fini, + .trap_action_set = mlx5e_devlink_trap_action_set, +}; + static int mlx5e_nic_init(struct mlx5_core_dev *mdev, struct net_device *netdev, const struct mlx5e_profile *profile, @@ -5005,12 +5043,15 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev, if (err) mlx5_core_err(mdev, "mlx5e_devlink_port_register failed, %d\n", err); mlx5e_health_create_reporters(priv); + devlink_port_traps_ops(&priv->dl_port, &mlx5e_devlink_traps_ops); + mlx5e_devlink_traps_create(priv); return 0; } static void mlx5e_nic_cleanup(struct mlx5e_priv *priv) { + mlx5e_devlink_traps_destroy(priv); mlx5e_health_destroy_reporters(priv); mlx5e_devlink_port_unregister(priv); mlx5e_tls_cleanup(priv); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index 1e42e27eae26..4fe20a6e6d6d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -1437,6 +1437,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; @@ -1444,11 +1445,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; @@ -1475,7 +1479,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);