From patchwork Tue Feb 25 10:45:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243990 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=ObZf8Ops; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbDw4qQMz9sRQ for ; Tue, 25 Feb 2020 21:45:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730376AbgBYKpe (ORCPT ); Tue, 25 Feb 2020 05:45:34 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50202 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730242AbgBYKpd (ORCPT ); Tue, 25 Feb 2020 05:45:33 -0500 Received: by mail-wm1-f66.google.com with SMTP id a5so2479570wmb.0 for ; Tue, 25 Feb 2020 02:45:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SS2QFyZIJelZ/sd9XZ/hXTMvynBDfSWHspJ07fvITKs=; b=ObZf8Ops+4fX3VHrL9eMT7u3vdo93FAd7vYGcWkkBDsDaPJm59VbwFaBPFMdZ8VQ6B 1ZiOv5QwUVFidzDuu8c9DrN0jlwNK3qZ2w39hp+lu+wLiBtsVb27t8D/lsrV+1nP0IIE Oxh12cO6C38y42U0fVWDp4D0R7VPFKmgqd6nE+0mXrlMfDV8IrZWjqAfQQ7M6JYHEnCE bIUNGQF165XYsaOv2ZiFDTInndnhUY5VKB6d7WjCnPfxVqF2qbykNQX0vej7D4EjddTF aI/KPuAplxHfnK0WM3aIM5ju7nt7rGMhDO3baZquENVz2kBk9omxxVO6Jdbk3TZeiP7e G1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SS2QFyZIJelZ/sd9XZ/hXTMvynBDfSWHspJ07fvITKs=; b=LU/TAiQS3z4HrkyPisR5XKVSnJ1twGfSOHAKLiRTeF0twF58uYTiolO6Dt1F1eb54I +sFxiRDEHTibJyUc/eioGbXX7UfrNWYXQ1UJmV2MVIOXp9xG09b46+LDOuklQa7p4iEW NQwlXjSIFZSz0YUVqn5L9wNMrksY6D03PhaLoGrea6fKw32rq2iydAM7X4gsSKZRGjAM F+XzY1zgJzHlVJfJQRuDznHzb3oJ2tMj8wET4yfI/QEhYOprNl+WsWgWcsWSjthaJWmG TCiOm7tvLnJlQYqCgt0HaPXcA9PgzlFmk5LQooEOppaFrRwqwiqSZ318qd8BqoG7hA/V FSLg== X-Gm-Message-State: APjAAAX1lcI9ynQv81Jk3Qs2QS3mfmjDifp8GO5PdfcndcTD+57kXdmi pOeFhCJj3imC3mJPECcl6q8no2wiGmY= X-Google-Smtp-Source: APXvYqzi/dpk/oHxWYBqu2wz4K0A0A2tDMGToLAPfkg76OXoyx1Vs8okixcm1nxGda9m3YQT829+AA== X-Received: by 2002:a1c:8156:: with SMTP id c83mr4502096wmd.164.1582627529897; Tue, 25 Feb 2020 02:45:29 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id f207sm3842343wme.9.2020.02.25.02.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:29 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 01/10] flow_offload: pass action cookie through offload structures Date: Tue, 25 Feb 2020 11:45:18 +0100 Message-Id: <20200225104527.2849-2-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Extend struct flow_action_entry in order to hold TC action cookie specified by user inserting the action. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel Reviewed-by: Jakub Kicinski --- v1->v2: - s/[0]/[]/ - used u8* instead of unsigned long* for cookie - used u32 for cookie_len --- include/net/flow_offload.h | 11 +++++++++++ net/core/flow_offload.c | 21 +++++++++++++++++++++ net/sched/cls_api.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h index c6f7bd22db60..4e864c34a1b0 100644 --- a/include/net/flow_offload.h +++ b/include/net/flow_offload.h @@ -156,6 +156,16 @@ enum flow_action_mangle_base { typedef void (*action_destr)(void *priv); +struct flow_action_cookie { + u32 cookie_len; + u8 cookie[]; +}; + +struct flow_action_cookie *flow_action_cookie_create(void *data, + unsigned int len, + gfp_t gfp); +void flow_action_cookie_destroy(struct flow_action_cookie *cookie); + struct flow_action_entry { enum flow_action_id id; action_destr destructor; @@ -214,6 +224,7 @@ struct flow_action_entry { u8 ttl; } mpls_mangle; }; + struct flow_action_cookie *cookie; /* user defined action cookie */ }; struct flow_action { diff --git a/net/core/flow_offload.c b/net/core/flow_offload.c index 45b6a59ac124..d21348202ba6 100644 --- a/net/core/flow_offload.c +++ b/net/core/flow_offload.c @@ -167,6 +167,27 @@ void flow_rule_match_enc_opts(const struct flow_rule *rule, } EXPORT_SYMBOL(flow_rule_match_enc_opts); +struct flow_action_cookie *flow_action_cookie_create(void *data, + unsigned int len, + gfp_t gfp) +{ + struct flow_action_cookie *cookie; + + cookie = kmalloc(sizeof(*cookie) + len, gfp); + if (!cookie) + return NULL; + cookie->cookie_len = len; + memcpy(cookie->cookie, data, len); + return cookie; +} +EXPORT_SYMBOL(flow_action_cookie_create); + +void flow_action_cookie_destroy(struct flow_action_cookie *cookie) +{ + kfree(cookie); +} +EXPORT_SYMBOL(flow_action_cookie_destroy); + struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb, void *cb_ident, void *cb_priv, void (*release)(void *cb_priv)) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 13c33eaf1ca1..4e766c5ab77a 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -3382,14 +3382,40 @@ int tc_setup_cb_reoffload(struct tcf_block *block, struct tcf_proto *tp, } EXPORT_SYMBOL(tc_setup_cb_reoffload); +static int tcf_act_get_cookie(struct flow_action_entry *entry, + const struct tc_action *act) +{ + struct tc_cookie *cookie; + int err = 0; + + rcu_read_lock(); + cookie = rcu_dereference(act->act_cookie); + if (cookie) { + entry->cookie = flow_action_cookie_create(cookie->data, + cookie->len, + GFP_ATOMIC); + if (!entry->cookie) + err = -ENOMEM; + } + rcu_read_unlock(); + return err; +} + +static void tcf_act_put_cookie(struct flow_action_entry *entry) +{ + flow_action_cookie_destroy(entry->cookie); +} + void tc_cleanup_flow_action(struct flow_action *flow_action) { struct flow_action_entry *entry; int i; - flow_action_for_each(i, entry, flow_action) + flow_action_for_each(i, entry, flow_action) { + tcf_act_put_cookie(entry); if (entry->destructor) entry->destructor(entry->destructor_priv); + } } EXPORT_SYMBOL(tc_cleanup_flow_action); @@ -3447,6 +3473,9 @@ int tc_setup_flow_action(struct flow_action *flow_action, entry = &flow_action->entries[j]; spin_lock_bh(&act->tcfa_lock); + err = tcf_act_get_cookie(entry, act); + if (err) + goto err_out_locked; if (is_tcf_gact_ok(act)) { entry->id = FLOW_ACTION_ACCEPT; } else if (is_tcf_gact_shot(act)) { From patchwork Tue Feb 25 10:45:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243989 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=sgao1DAR; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbDw1Vynz9sPk for ; Tue, 25 Feb 2020 21:45:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730372AbgBYKpd (ORCPT ); Tue, 25 Feb 2020 05:45:33 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33062 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730276AbgBYKpc (ORCPT ); Tue, 25 Feb 2020 05:45:32 -0500 Received: by mail-wm1-f66.google.com with SMTP id m10so1930153wmc.0 for ; Tue, 25 Feb 2020 02:45:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=alyiJMVEHZZVcF9qcZtRupgd4PPc6iD37iF33muKNRQ=; b=sgao1DARZA9M5ZFX76uOu3nbPY8PmuG6OpTnPrDdHpTVWMC76BjPL+UVk4fEfB1poN KScwZqbihBoNHK/bKL7INUgtYH8MHzdUh869+5l3FaoGsPULsUNlHCslDj8YK8kC9PXy EhYPsbb7U0FRPlv31w7yPq/TCANS1TdwF16oRPh01JFlE3TlhRhhzrN8tfzUIYk2z5J/ dPCWxpbVm6q22tum/va44j+Au3+Opk2VrpNY0YKBmHtdNEOWaseGAllCoXYANpH3g9qC zgbDenk/+KJGNgitcMebQ889f+50SO6cNTFtLr/pPPzzhB7FtmOA0lbet59UbFq20eUV 1Jgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=alyiJMVEHZZVcF9qcZtRupgd4PPc6iD37iF33muKNRQ=; b=S+YRBXUZkedt1vn8HroSDkDdgKkTHgrISobL/+SajjuPTjjPAjCh9CmAeyfhMrvNAq 6ozX0BERdrp4WOjOOwhxfnlILqJs8+CWePa7LLAHnvaxEyU2BOlwnaUPCDKJf5zBVy7C 7puZN1ayMdolyarwyutjyeS8mhDxTazey8CVRHxqfzuPmgv4PuF3DRFJY2n6ypDN75fc yUvvnGM1yq21FvUKQJOM7NwzCLCNvdDiG6WEirJO6Wei2AIvHc9OrlJeh8QGBvMBoKBq +LPWEsYlleCJN3JjnGWjwq8O6mOjl/qEQ4jsfRsKlbrs/QfBAohhp4kF6aVaApYa8Oo2 ZWaw== X-Gm-Message-State: APjAAAXRUEbJHNEEKDWBPQBQwYznYjeFZDhNd8Uje8yFHLUTMuKjPm14 yneMxWs9MkRGFlsabetdMklcs29hWPM= X-Google-Smtp-Source: APXvYqxwleEItucyf26dGz03wJW5jIy7WPvWW04fIJEL327Op5v8ltLs/QbNEzspJ0w/Wv7wgN6ELw== X-Received: by 2002:a05:600c:24d2:: with SMTP id 18mr4627436wmu.149.1582627531321; Tue, 25 Feb 2020 02:45:31 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id e18sm22787535wrw.70.2020.02.25.02.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:30 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 02/10] devlink: add trap metadata type for cookie Date: Tue, 25 Feb 2020 11:45:19 +0100 Message-Id: <20200225104527.2849-3-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Allow driver to indicate cookie metadata for registered traps. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel Reviewed-by: Jakub Kicinski --- include/net/devlink.h | 1 + include/uapi/linux/devlink.h | 2 ++ net/core/devlink.c | 3 +++ 3 files changed, 6 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 07923e619206..014a8b3d1499 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -541,6 +541,7 @@ struct devlink_trap_group { }; #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0) +#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1) /** * struct devlink_trap - Immutable packet trap attributes. diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index ae37fd4d194a..be2a2948f452 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -252,6 +252,8 @@ enum devlink_trap_type { enum { /* Trap can report input port as metadata */ DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT, + /* Trap can report flow action cookie as metadata */ + DEVLINK_ATTR_TRAP_METADATA_TYPE_FA_COOKIE, }; enum devlink_attr { diff --git a/net/core/devlink.c b/net/core/devlink.c index 0d7c5d3443d2..12e6ef749b8a 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5540,6 +5540,9 @@ static int devlink_trap_metadata_put(struct sk_buff *msg, if ((trap->metadata_cap & DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT) && nla_put_flag(msg, DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT)) goto nla_put_failure; + if ((trap->metadata_cap & DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE) && + nla_put_flag(msg, DEVLINK_ATTR_TRAP_METADATA_TYPE_FA_COOKIE)) + goto nla_put_failure; nla_nest_end(msg, attr); From patchwork Tue Feb 25 10:45:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243991 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Jx9GCh9I; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbDx4rjYz9sP7 for ; Tue, 25 Feb 2020 21:45:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730383AbgBYKph (ORCPT ); Tue, 25 Feb 2020 05:45:37 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53214 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730377AbgBYKpg (ORCPT ); Tue, 25 Feb 2020 05:45:36 -0500 Received: by mail-wm1-f67.google.com with SMTP id p9so2474597wmc.2 for ; Tue, 25 Feb 2020 02:45:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4ai++lULxg0ZN5Kl7gxhRIYJlzkBlKymDyg0FU+/UHQ=; b=Jx9GCh9IpAXRVxkXBwHcyPRURq3p/92lUY0b2C2zW1FX4ENctJkIx4dfXK6Mt/fiS8 mxNAgqRX+RFLbuYto/J3asBnMFS9H8QSTq8RYRlsD+ge9EXjmZ4AcXztgbbxDbR3w4an iJDUviU/cOxnO8q0+VV+SvqJUHav8Exif1sHx74X2k9JJ1fUHHOPr5zpLH1q9HplftQZ WfBCVy7IfWJAEIqiCpe/eKpFmmK0T4SiFXYJhVEy3WxYjiQtvJBSAOqqbkSTVFHThDrK 0U99gH9Rl3X06OquX3xmo/8C6xHaNzJnJtdgzlkEK/o0cxtA8uukCA53w06Q8pVREP+E KtJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4ai++lULxg0ZN5Kl7gxhRIYJlzkBlKymDyg0FU+/UHQ=; b=Zw8nlCmVn1oYvrdjO6ULF3mHrRlD70mNFqIAoZi9tsqnzpHjnbLjxSld1G5onbB+OK /pz4rxxT6amHtc0E2gdEp1LgoCV9GFZbeWYKhIa0xBo0MJ0EXk1+5ojQW2ZWfF++/YQh FVtMAbS6Z5eUO3sw04OO3BySCXLSL06XdawB5seP5iqVioJlIeKR6rwtpW0jpU4lONHF KG+9bDTRGouJZvlXZ4crRI3mfxkgIpvrgQpSwSMdMxfDo8E9VK1plWUQtrV//3nXu5rO K+gSpoGQMMNOF5atuICy9y4VQPj1pCx9A0ekOaRpDbSn9z5vWN5d2aD0MNHtvFZvMb39 Sz0w== X-Gm-Message-State: APjAAAXVzntV40QNXHq1MVSPEb8fjwemWGX/PKEH2TYV/w0N46c1vG/K WKx6ukOrmY49hj3PALpazZTWIRjW4l4= X-Google-Smtp-Source: APXvYqwhq5u+kuOs4ISUscu8bDTRwUQERKXbbaV7OVG9VADjvn3OgUsy2zwSAO+azVq/Gk3GTtvciQ== X-Received: by 2002:a1c:f21a:: with SMTP id s26mr4637633wmc.39.1582627532619; Tue, 25 Feb 2020 02:45:32 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id m68sm3558606wme.48.2020.02.25.02.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:32 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 03/10] drop_monitor: extend by passing cookie from driver Date: Tue, 25 Feb 2020 11:45:20 +0100 Message-Id: <20200225104527.2849-4-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko If driver passed along the cookie, push it through Netlink. Signed-off-by: Jiri Pirko --- v1->v2: - removed __GFP_ZERO --- include/net/drop_monitor.h | 3 +++ include/uapi/linux/net_dropmon.h | 1 + net/core/drop_monitor.c | 33 +++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/net/drop_monitor.h b/include/net/drop_monitor.h index 2ab668461463..ddd441a60e03 100644 --- a/include/net/drop_monitor.h +++ b/include/net/drop_monitor.h @@ -6,17 +6,20 @@ #include #include #include +#include /** * struct net_dm_hw_metadata - Hardware-supplied packet metadata. * @trap_group_name: Hardware trap group name. * @trap_name: Hardware trap name. * @input_dev: Input netdevice. + * @fa_cookie: Flow action user cookie. */ struct net_dm_hw_metadata { const char *trap_group_name; const char *trap_name; struct net_device *input_dev; + const struct flow_action_cookie *fa_cookie; }; #if IS_ENABLED(CONFIG_NET_DROP_MONITOR) diff --git a/include/uapi/linux/net_dropmon.h b/include/uapi/linux/net_dropmon.h index 8bf79a9eb234..66048cc5d7b3 100644 --- a/include/uapi/linux/net_dropmon.h +++ b/include/uapi/linux/net_dropmon.h @@ -92,6 +92,7 @@ enum net_dm_attr { NET_DM_ATTR_HW_TRAP_COUNT, /* u32 */ NET_DM_ATTR_SW_DROPS, /* flag */ NET_DM_ATTR_HW_DROPS, /* flag */ + NET_DM_ATTR_FLOW_ACTION_COOKIE, /* binary */ __NET_DM_ATTR_MAX, NET_DM_ATTR_MAX = __NET_DM_ATTR_MAX - 1 diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index 31700e0c3928..d58c1c45a895 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -700,6 +701,13 @@ static void net_dm_packet_work(struct work_struct *work) net_dm_packet_report(skb); } +static size_t +net_dm_flow_action_cookie_size(const struct net_dm_hw_metadata *hw_metadata) +{ + return hw_metadata->fa_cookie ? + nla_total_size(hw_metadata->fa_cookie->cookie_len) : 0; +} + static size_t net_dm_hw_packet_report_size(size_t payload_len, const struct net_dm_hw_metadata *hw_metadata) @@ -717,6 +725,8 @@ net_dm_hw_packet_report_size(size_t payload_len, nla_total_size(strlen(hw_metadata->trap_name) + 1) + /* NET_DM_ATTR_IN_PORT */ net_dm_in_port_size() + + /* NET_DM_ATTR_FLOW_ACTION_COOKIE */ + net_dm_flow_action_cookie_size(hw_metadata) + /* NET_DM_ATTR_TIMESTAMP */ nla_total_size(sizeof(u64)) + /* NET_DM_ATTR_ORIG_LEN */ @@ -762,6 +772,12 @@ static int net_dm_hw_packet_report_fill(struct sk_buff *msg, goto nla_put_failure; } + if (hw_metadata->fa_cookie && + nla_put(msg, NET_DM_ATTR_FLOW_ACTION_COOKIE, + hw_metadata->fa_cookie->cookie_len, + hw_metadata->fa_cookie->cookie)) + goto nla_put_failure; + if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP, ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD)) goto nla_put_failure; @@ -794,11 +810,12 @@ static int net_dm_hw_packet_report_fill(struct sk_buff *msg, static struct net_dm_hw_metadata * net_dm_hw_metadata_clone(const struct net_dm_hw_metadata *hw_metadata) { + const struct flow_action_cookie *fa_cookie; struct net_dm_hw_metadata *n_hw_metadata; const char *trap_group_name; const char *trap_name; - n_hw_metadata = kmalloc(sizeof(*hw_metadata), GFP_ATOMIC); + n_hw_metadata = kzalloc(sizeof(*hw_metadata), GFP_ATOMIC); if (!n_hw_metadata) return NULL; @@ -812,12 +829,25 @@ net_dm_hw_metadata_clone(const struct net_dm_hw_metadata *hw_metadata) goto free_trap_group; n_hw_metadata->trap_name = trap_name; + if (hw_metadata->fa_cookie) { + size_t cookie_size = sizeof(*fa_cookie) + + hw_metadata->fa_cookie->cookie_len; + + fa_cookie = kmemdup(hw_metadata->fa_cookie, cookie_size, + GFP_ATOMIC); + if (!fa_cookie) + goto free_trap_name; + n_hw_metadata->fa_cookie = fa_cookie; + } + n_hw_metadata->input_dev = hw_metadata->input_dev; if (n_hw_metadata->input_dev) dev_hold(n_hw_metadata->input_dev); return n_hw_metadata; +free_trap_name: + kfree(trap_name); free_trap_group: kfree(trap_group_name); free_hw_metadata: @@ -830,6 +860,7 @@ net_dm_hw_metadata_free(const struct net_dm_hw_metadata *hw_metadata) { if (hw_metadata->input_dev) dev_put(hw_metadata->input_dev); + kfree(hw_metadata->fa_cookie); kfree(hw_metadata->trap_name); kfree(hw_metadata->trap_group_name); kfree(hw_metadata); From patchwork Tue Feb 25 10:45:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243997 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=DvfuWQC3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbF92s3Vz9sP7 for ; Tue, 25 Feb 2020 21:45:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730394AbgBYKpk (ORCPT ); Tue, 25 Feb 2020 05:45:40 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34949 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730242AbgBYKpg (ORCPT ); Tue, 25 Feb 2020 05:45:36 -0500 Received: by mail-wr1-f66.google.com with SMTP id w12so14136040wrt.2 for ; Tue, 25 Feb 2020 02:45:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PyaQoZ7A0Cg5Z+OnyhMczSB3es9d6Va4hi/dGp7bQaU=; b=DvfuWQC39oS7JGIgkNCfN0gjpsdAaDI+V/FmuB+tKprk7thsZWFfkWlFnIMN/cCUBY gVVYCQmag8MPXuLmg4PNFcv7V4VqxhtIDwS2BU16+wknJ9N7MvWHA7ldzeMhB7uKEBK3 OFkoHmh9sYtzbqJQw4x1HVzRpSaSwpkgwg/Mjo0KxtrH1kwc2e4NK8zNW34w3jxGaIhi wlSi9KED0483dstO2aJk+zhgviDe4gdFb0271xEePgTxZWIBVfQIH2WpMKi/vbZCfxq2 +PqMK9lqAEIF2p2Kvqatfdt0AM6fb08ApJdyxh8mM0yTHzOOL5fMDf1I3es+KNfPtlSV L4tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PyaQoZ7A0Cg5Z+OnyhMczSB3es9d6Va4hi/dGp7bQaU=; b=RxcMh0tAZO7HYTCs+7HZqvGF/ogfRc1k7cj+Zkm+oJ828F/5XsTb+JDPnmQkSPTwSx TxoFVozjX96ZMGhCA07jKuwKtXoq7s/E9U0kU7m2QjHtkg/PdjjyDjLtLfALJqnEW4wO F3gBfnCB5BgBPWvuHCKgt7dGbNWCw+5YCDFvqWAluuRTsv3yCKXYWN9gMgwGQKWTx6j/ 2VvVRIj8qKFTOIeHdM9eUlWwTdDOgcd8hRgdlUt9iVhD2ynNTnIRCj8xGsBp6jMQ8EK+ oJOBJfxpJOQ5NBaXOTybvGT6L7nvZSqPu5Uy+/hTd+ULHqVNRxYVPAGfuZ5IqH/8y48+ KTUA== X-Gm-Message-State: APjAAAWkSEpID52CoiaNpiXkj7FEPzWDv6mdTqAXAoERpYtQz+FaVwFB s3QMq8l4PaVVBAZzWqgobnAx17/zC5o= X-Google-Smtp-Source: APXvYqyc7KbxE7w5Y52EbllxCj6UsucNvoDhQOiRu9gBl6wvQd769fOqSpRfqLA8j0yVkRZ4qVC3SA== X-Received: by 2002:adf:f787:: with SMTP id q7mr72465694wrp.297.1582627533882; Tue, 25 Feb 2020 02:45:33 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id t131sm3679707wmb.13.2020.02.25.02.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:33 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 04/10] devlink: extend devlink_trap_report() to accept cookie and pass Date: Tue, 25 Feb 2020 11:45:21 +0100 Message-Id: <20200225104527.2849-5-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Add cookie argument to devlink_trap_report() allowing driver to pass in the user cookie. Pass on the cookie down to drop monitor code. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel Reviewed-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 4 ++-- drivers/net/netdevsim/dev.c | 2 +- include/net/devlink.h | 7 ++++--- net/core/devlink.c | 11 ++++++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c index 04f2445f6d43..a55577a50e90 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c @@ -71,7 +71,7 @@ static void mlxsw_sp_rx_drop_listener(struct sk_buff *skb, u8 local_port, in_devlink_port = mlxsw_core_port_devlink_port_get(mlxsw_sp->core, local_port); skb_push(skb, ETH_HLEN); - devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port); + devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port, NULL); consume_skb(skb); } @@ -95,7 +95,7 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port, in_devlink_port = mlxsw_core_port_devlink_port_get(mlxsw_sp->core, local_port); skb_push(skb, ETH_HLEN); - devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port); + devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port, NULL); skb_pull(skb, ETH_HLEN); skb->offload_fwd_mark = 1; netif_receive_skb(skb); diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index d7706a0346f2..aa17533c06e1 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -385,7 +385,7 @@ static void nsim_dev_trap_report(struct nsim_dev_port *nsim_dev_port) */ local_bh_disable(); devlink_trap_report(devlink, skb, nsim_trap_item->trap_ctx, - &nsim_dev_port->devlink_port); + &nsim_dev_port->devlink_port, NULL); local_bh_enable(); consume_skb(skb); } diff --git a/include/net/devlink.h b/include/net/devlink.h index 014a8b3d1499..c9ca86b054bc 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -16,6 +16,7 @@ #include #include #include +#include #include struct devlink_ops; @@ -1050,9 +1051,9 @@ int devlink_traps_register(struct devlink *devlink, void devlink_traps_unregister(struct devlink *devlink, const struct devlink_trap *traps, size_t traps_count); -void devlink_trap_report(struct devlink *devlink, - struct sk_buff *skb, void *trap_ctx, - struct devlink_port *in_devlink_port); +void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, + void *trap_ctx, struct devlink_port *in_devlink_port, + const struct flow_action_cookie *fa_cookie); void *devlink_trap_ctx_priv(void *trap_ctx); #if IS_ENABLED(CONFIG_NET_DEVLINK) diff --git a/net/core/devlink.c b/net/core/devlink.c index 12e6ef749b8a..49706031ab45 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -8205,12 +8205,14 @@ devlink_trap_stats_update(struct devlink_stats __percpu *trap_stats, static void devlink_trap_report_metadata_fill(struct net_dm_hw_metadata *hw_metadata, const struct devlink_trap_item *trap_item, - struct devlink_port *in_devlink_port) + struct devlink_port *in_devlink_port, + const struct flow_action_cookie *fa_cookie) { struct devlink_trap_group_item *group_item = trap_item->group_item; hw_metadata->trap_group_name = group_item->group->name; hw_metadata->trap_name = trap_item->trap->name; + hw_metadata->fa_cookie = fa_cookie; spin_lock(&in_devlink_port->type_lock); if (in_devlink_port->type == DEVLINK_PORT_TYPE_ETH) @@ -8224,9 +8226,12 @@ devlink_trap_report_metadata_fill(struct net_dm_hw_metadata *hw_metadata, * @skb: Trapped packet. * @trap_ctx: Trap context. * @in_devlink_port: Input devlink port. + * @fa_cookie: Flow action cookie. Could be NULL. */ void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, - void *trap_ctx, struct devlink_port *in_devlink_port) + void *trap_ctx, struct devlink_port *in_devlink_port, + const struct flow_action_cookie *fa_cookie) + { struct devlink_trap_item *trap_item = trap_ctx; struct net_dm_hw_metadata hw_metadata = {}; @@ -8235,7 +8240,7 @@ void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, devlink_trap_stats_update(trap_item->group_item->stats, skb->len); devlink_trap_report_metadata_fill(&hw_metadata, trap_item, - in_devlink_port); + in_devlink_port, fa_cookie); net_dm_hw_report(skb, &hw_metadata); } EXPORT_SYMBOL_GPL(devlink_trap_report); From patchwork Tue Feb 25 10:45:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243992 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=xW8RloKA; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbF06kyxz9sP7 for ; Tue, 25 Feb 2020 21:45:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730390AbgBYKpk (ORCPT ); Tue, 25 Feb 2020 05:45:40 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33186 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730378AbgBYKpg (ORCPT ); Tue, 25 Feb 2020 05:45:36 -0500 Received: by mail-wr1-f65.google.com with SMTP id u6so14157648wrt.0 for ; Tue, 25 Feb 2020 02:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zHMa5uRfXauRxVZHxXo1hn0OuQImAgMVG7rq6bvn8lE=; b=xW8RloKA5icTHVx4p7Un1LETk8CG8nSsX9ySaRneq4P/1jXmtk4awTPYkrtJj1WWkJ mVlTqOLxtM70KXdqnGQFLSNGcMgVO++mEA/Wxt85Sbp1yO43W6PvMQoj5VOoyqbD7+CN qkniuUYAsm/S0QzunfZMya5VDrtYbHeLzeXPNpyJhp+TsTrwg7K+0LHhc9bbFVEUW2Xh e8k29+JUCB7OcUE7LyH2y1owrAeFCcWQuULJeHQaniAQ/a2mXD4jY/859OO1oOEiTdWr 68z2eIAtJ2p+gCUTx7QUnNRBBiPM+rUwA6nzjOKP9+Q+Pz/9/QmGsVKkerkzpFdCZq8N I3eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zHMa5uRfXauRxVZHxXo1hn0OuQImAgMVG7rq6bvn8lE=; b=HZ5/5NZGccG+Xhp/jWxozdE+D4Ecvk2TRbGS1ZSqm539w8dhEoDVluLWJ2llokBMFU 9DY71/OpuPUyuojc9T0PIv8viDEXR7uX2DiBztURZToMVlOeKXKyHpHl7M8FeGs+hwHe EYxQjlG/1uUGv1GtKIOnzqrkY+B/lBz8sd0pcOClhD+9JAQ+zu6V3HK8nx2u4wBjUg4j e7/jfraN3gFWE6iDcP8uoWI21dRzLZU8stNBmlx8nRPwTAGMKyANlofltlU9c+uNMguq P5xy4OimsnMXNECRDOA8xxUEG1R+dawhaASq/pBVOJVRSRehqF3j6tj7PWwHb8PXipE7 iCrQ== X-Gm-Message-State: APjAAAX6FLMRECTjJkYHvk47aBQnO+eOukPWRmeohO2uawAX30zlMEgg 0Cy+TicGZnnV9xjUT60vUmFnpXFt7Kk= X-Google-Smtp-Source: APXvYqzIbEpUUx7MYono2jb+XvEPAsoUBTLxIVbdCcHfgW2snhFlowMbK36AM06ZQ7Im/Y1KN+gVGg== X-Received: by 2002:a5d:6344:: with SMTP id b4mr21120186wrw.224.1582627534967; Tue, 25 Feb 2020 02:45:34 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id v16sm3528583wml.11.2020.02.25.02.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:34 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 05/10] mlxsw: core_acl_flex_actions: Add trap with userdef action Date: Tue, 25 Feb 2020 11:45:22 +0100 Message-Id: <20200225104527.2849-6-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Expose "Trap action with userdef". It is the same as already defined "Trap action" with a difference that it would ask the policy engine to pass arbitrary value (userdef) alongside with received packets. This would be later on used to carry cookie index. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../mellanox/mlxsw/core_acl_flex_actions.c | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c index 424ef26e6cca..b7a846dd8f32 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c @@ -747,18 +747,25 @@ int mlxsw_afa_block_append_vlan_modify(struct mlxsw_afa_block *block, } EXPORT_SYMBOL(mlxsw_afa_block_append_vlan_modify); -/* Trap Action - * ----------- +/* Trap Action / Trap With Userdef Action + * -------------------------------------- * The Trap action enables trapping / mirroring packets to the CPU * as well as discarding packets. * The ACL Trap / Discard separates the forward/discard control from CPU * trap control. In addition, the Trap / Discard action enables activating * SPAN (port mirroring). + * + * The Trap with userdef action action has the same functionality as + * the Trap action with addition of user defined value that can be set + * and used by higher layer applications. */ #define MLXSW_AFA_TRAP_CODE 0x03 #define MLXSW_AFA_TRAP_SIZE 1 +#define MLXSW_AFA_TRAPWU_CODE 0x04 +#define MLXSW_AFA_TRAPWU_SIZE 2 + enum mlxsw_afa_trap_trap_action { MLXSW_AFA_TRAP_TRAP_ACTION_NOP = 0, MLXSW_AFA_TRAP_TRAP_ACTION_TRAP = 2, @@ -794,6 +801,15 @@ MLXSW_ITEM32(afa, trap, mirror_agent, 0x08, 29, 3); */ MLXSW_ITEM32(afa, trap, mirror_enable, 0x08, 24, 1); +/* user_def_val + * Value for the SW usage. Can be used to pass information of which + * rule has caused a trap. This may be overwritten by later traps. + * This field does a set on the packet's user_def_val only if this + * is the first trap_id or if the trap_id has replaced the previous + * packet's trap_id. + */ +MLXSW_ITEM32(afa, trap, user_def_val, 0x0C, 0, 20); + static inline void mlxsw_afa_trap_pack(char *payload, enum mlxsw_afa_trap_trap_action trap_action, @@ -805,6 +821,16 @@ mlxsw_afa_trap_pack(char *payload, mlxsw_afa_trap_trap_id_set(payload, trap_id); } +static inline void +mlxsw_afa_trapwu_pack(char *payload, + enum mlxsw_afa_trap_trap_action trap_action, + enum mlxsw_afa_trap_forward_action forward_action, + u16 trap_id, u32 user_def_val) +{ + mlxsw_afa_trap_pack(payload, trap_action, forward_action, trap_id); + mlxsw_afa_trap_user_def_val_set(payload, user_def_val); +} + static inline void mlxsw_afa_trap_mirror_pack(char *payload, bool mirror_enable, u8 mirror_agent) From patchwork Tue Feb 25 10:45:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243998 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=V5Hxh/in; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbFB4Sxmz9sP7 for ; Tue, 25 Feb 2020 21:45:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730418AbgBYKpu (ORCPT ); Tue, 25 Feb 2020 05:45:50 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42431 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730384AbgBYKpk (ORCPT ); Tue, 25 Feb 2020 05:45:40 -0500 Received: by mail-wr1-f68.google.com with SMTP id p18so10475244wre.9 for ; Tue, 25 Feb 2020 02:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xV/Wbla3nNgRAb+Jc51sd0Ib/rZAFU0ywyteSJt+8EM=; b=V5Hxh/inrngD8EvWE0RigDWhUgiPFXdttdiy9LgO3Feq2ql8cHm07nmTFLIm+iwwPX wfA0dzjmbyMbRSDZrQigc3sivCPws2Hfw0tyzgjilUGVGYwGI2+BkWtz1D74/sCGreyj T9d4h4V4sRJDqfiv0vziWTMB7rwj6K+aBM4dkZk6UmDpLSmdiK3FbfGWaSraBeaHQJD2 vsc9kq1o52MHrXttzAkTPxQfY6Ai1/I9OLxjT5xTzf+NZ6m/qj0AHovwVCvAeXcq0OK7 6Isnwo5/z5sesoxNQk1lxAtNz6CBflV11u3hwFmJ9dq8w5WX2n8aXAgxXkLcsE4/32oU 8vWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xV/Wbla3nNgRAb+Jc51sd0Ib/rZAFU0ywyteSJt+8EM=; b=sodGJ/IeyHTp62LJ54RFtInxUnLu1Tjx6jGzOAoMU05iTXNkMEX79uSxPtbvYnmHrD wq6cQA81qvBKErW1VlnnTk0r8D7JhkMV18QTvoQOif88Ah11VIA5vSA8U6+xYK/uMGn9 /zQsU9RjWQqsLh0Tspdfkstix7AHL2e2ti0Fix3RITSlaGrLNmAT7RAUKIbi2Fgu/5RC DC1gd/t0VhtxnRZjvzXuV9TQVZDOWkvCyOHZZJyPma94lxPk3A86r+MiDe5LkCMRfd0d pDNVuq24NvNkGLIbvd0KZaF69KmPE9IDmk2tr5/Ll3O0eD1oYdKWceJqx0TZfa2QOZn+ ZFEA== X-Gm-Message-State: APjAAAWpIaKA1la0wpSMsmmEMPrKAYODVEGLoSbOs9mNR1ycHN92njrO tfUl/L/68ZGixphb8HLh9rtaFZOrKtE= X-Google-Smtp-Source: APXvYqy4cdif0TgsHWqD7KqhFZJXwCunXkLkGGHOWNJeqHfu7ruMrtwpMFY1XwBZvdTWdwLF1XsT2A== X-Received: by 2002:adf:ed8c:: with SMTP id c12mr69794181wro.231.1582627536265; Tue, 25 Feb 2020 02:45:36 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id p12sm23595775wrx.10.2020.02.25.02.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:35 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 06/10] mlxsw: core_acl_flex_actions: Implement flow_offload action cookie offload Date: Tue, 25 Feb 2020 11:45:23 +0100 Message-Id: <20200225104527.2849-7-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Track cookies coming down to driver by flow_offload. Assign a cookie_index to each unique cookie binary. Use previously defined "Trap with userdef" flex action to ask HW to pass cookie_index alongside with the dropped packets. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../mellanox/mlxsw/core_acl_flex_actions.c | 243 +++++++++++++++++- .../mellanox/mlxsw/core_acl_flex_actions.h | 5 +- .../net/ethernet/mellanox/mlxsw/spectrum.h | 5 +- .../ethernet/mellanox/mlxsw/spectrum_acl.c | 7 +- .../ethernet/mellanox/mlxsw/spectrum_flower.c | 3 +- 5 files changed, 257 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c index b7a846dd8f32..9fad56df8303 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "item.h" #include "trap.h" @@ -63,6 +66,8 @@ struct mlxsw_afa { void *ops_priv; struct rhashtable set_ht; struct rhashtable fwd_entry_ht; + struct rhashtable cookie_ht; + struct idr cookie_idr; }; #define MLXSW_AFA_SET_LEN 0xA8 @@ -121,6 +126,55 @@ static const struct rhashtable_params mlxsw_afa_fwd_entry_ht_params = { .automatic_shrinking = true, }; +struct mlxsw_afa_cookie { + struct rhash_head ht_node; + refcount_t ref_count; + struct rcu_head rcu; + u32 cookie_index; + struct flow_action_cookie fa_cookie; +}; + +static u32 mlxsw_afa_cookie_hash(const struct flow_action_cookie *fa_cookie, + u32 seed) +{ + return jhash2((u32 *) fa_cookie->cookie, + fa_cookie->cookie_len / sizeof(u32), seed); +} + +static u32 mlxsw_afa_cookie_key_hashfn(const void *data, u32 len, u32 seed) +{ + const struct flow_action_cookie *fa_cookie = data; + + return mlxsw_afa_cookie_hash(fa_cookie, seed); +} + +static u32 mlxsw_afa_cookie_obj_hashfn(const void *data, u32 len, u32 seed) +{ + const struct mlxsw_afa_cookie *cookie = data; + + return mlxsw_afa_cookie_hash(&cookie->fa_cookie, seed); +} + +static int mlxsw_afa_cookie_obj_cmpfn(struct rhashtable_compare_arg *arg, + const void *obj) +{ + const struct flow_action_cookie *fa_cookie = arg->key; + const struct mlxsw_afa_cookie *cookie = obj; + + if (cookie->fa_cookie.cookie_len == fa_cookie->cookie_len) + return memcmp(cookie->fa_cookie.cookie, fa_cookie->cookie, + fa_cookie->cookie_len); + return 1; +} + +static const struct rhashtable_params mlxsw_afa_cookie_ht_params = { + .head_offset = offsetof(struct mlxsw_afa_cookie, ht_node), + .hashfn = mlxsw_afa_cookie_key_hashfn, + .obj_hashfn = mlxsw_afa_cookie_obj_hashfn, + .obj_cmpfn = mlxsw_afa_cookie_obj_cmpfn, + .automatic_shrinking = true, +}; + struct mlxsw_afa *mlxsw_afa_create(unsigned int max_acts_per_set, const struct mlxsw_afa_ops *ops, void *ops_priv) @@ -138,11 +192,18 @@ struct mlxsw_afa *mlxsw_afa_create(unsigned int max_acts_per_set, &mlxsw_afa_fwd_entry_ht_params); if (err) goto err_fwd_entry_rhashtable_init; + err = rhashtable_init(&mlxsw_afa->cookie_ht, + &mlxsw_afa_cookie_ht_params); + if (err) + goto err_cookie_rhashtable_init; + idr_init(&mlxsw_afa->cookie_idr); mlxsw_afa->max_acts_per_set = max_acts_per_set; mlxsw_afa->ops = ops; mlxsw_afa->ops_priv = ops_priv; return mlxsw_afa; +err_cookie_rhashtable_init: + rhashtable_destroy(&mlxsw_afa->fwd_entry_ht); err_fwd_entry_rhashtable_init: rhashtable_destroy(&mlxsw_afa->set_ht); err_set_rhashtable_init: @@ -153,6 +214,9 @@ EXPORT_SYMBOL(mlxsw_afa_create); void mlxsw_afa_destroy(struct mlxsw_afa *mlxsw_afa) { + WARN_ON(!idr_is_empty(&mlxsw_afa->cookie_idr)); + idr_destroy(&mlxsw_afa->cookie_idr); + rhashtable_destroy(&mlxsw_afa->cookie_ht); rhashtable_destroy(&mlxsw_afa->fwd_entry_ht); rhashtable_destroy(&mlxsw_afa->set_ht); kfree(mlxsw_afa); @@ -627,6 +691,135 @@ mlxsw_afa_counter_create(struct mlxsw_afa_block *block) return ERR_PTR(err); } +/* 20 bits is a maximum that hardware can handle in trap with userdef action + * and carry along with the trapped packet. + */ +#define MLXSW_AFA_COOKIE_INDEX_BITS 20 +#define MLXSW_AFA_COOKIE_INDEX_MAX ((1 << MLXSW_AFA_COOKIE_INDEX_BITS) - 1) + +static struct mlxsw_afa_cookie * +mlxsw_afa_cookie_create(struct mlxsw_afa *mlxsw_afa, + const struct flow_action_cookie *fa_cookie) +{ + struct mlxsw_afa_cookie *cookie; + u32 cookie_index; + int err; + + cookie = kzalloc(sizeof(*cookie) + fa_cookie->cookie_len, GFP_KERNEL); + if (!cookie) + return ERR_PTR(-ENOMEM); + refcount_set(&cookie->ref_count, 1); + memcpy(&cookie->fa_cookie, fa_cookie, + sizeof(*fa_cookie) + fa_cookie->cookie_len); + + err = rhashtable_insert_fast(&mlxsw_afa->cookie_ht, &cookie->ht_node, + mlxsw_afa_cookie_ht_params); + if (err) + goto err_rhashtable_insert; + + /* Start cookie indexes with 1. Leave the 0 index unused. Packets + * that come from the HW which are not dropped by drop-with-cookie + * action are going to pass cookie_index 0 to lookup. + */ + cookie_index = 1; + err = idr_alloc_u32(&mlxsw_afa->cookie_idr, cookie, &cookie_index, + MLXSW_AFA_COOKIE_INDEX_MAX, GFP_KERNEL); + if (err) + goto err_idr_alloc; + cookie->cookie_index = cookie_index; + return cookie; + +err_idr_alloc: + rhashtable_remove_fast(&mlxsw_afa->cookie_ht, &cookie->ht_node, + mlxsw_afa_cookie_ht_params); +err_rhashtable_insert: + kfree(cookie); + return ERR_PTR(err); +} + +static void mlxsw_afa_cookie_destroy(struct mlxsw_afa *mlxsw_afa, + struct mlxsw_afa_cookie *cookie) +{ + idr_remove(&mlxsw_afa->cookie_idr, cookie->cookie_index); + rhashtable_remove_fast(&mlxsw_afa->cookie_ht, &cookie->ht_node, + mlxsw_afa_cookie_ht_params); + kfree_rcu(cookie, rcu); +} + +static struct mlxsw_afa_cookie * +mlxsw_afa_cookie_get(struct mlxsw_afa *mlxsw_afa, + const struct flow_action_cookie *fa_cookie) +{ + struct mlxsw_afa_cookie *cookie; + + cookie = rhashtable_lookup_fast(&mlxsw_afa->cookie_ht, fa_cookie, + mlxsw_afa_cookie_ht_params); + if (cookie) { + refcount_inc(&cookie->ref_count); + return cookie; + } + return mlxsw_afa_cookie_create(mlxsw_afa, fa_cookie); +} + +static void mlxsw_afa_cookie_put(struct mlxsw_afa *mlxsw_afa, + struct mlxsw_afa_cookie *cookie) +{ + if (!refcount_dec_and_test(&cookie->ref_count)) + return; + mlxsw_afa_cookie_destroy(mlxsw_afa, cookie); +} + +struct mlxsw_afa_cookie_ref { + struct mlxsw_afa_resource resource; + struct mlxsw_afa_cookie *cookie; +}; + +static void +mlxsw_afa_cookie_ref_destroy(struct mlxsw_afa_block *block, + struct mlxsw_afa_cookie_ref *cookie_ref) +{ + mlxsw_afa_resource_del(&cookie_ref->resource); + mlxsw_afa_cookie_put(block->afa, cookie_ref->cookie); + kfree(cookie_ref); +} + +static void +mlxsw_afa_cookie_ref_destructor(struct mlxsw_afa_block *block, + struct mlxsw_afa_resource *resource) +{ + struct mlxsw_afa_cookie_ref *cookie_ref; + + cookie_ref = container_of(resource, struct mlxsw_afa_cookie_ref, + resource); + mlxsw_afa_cookie_ref_destroy(block, cookie_ref); +} + +static struct mlxsw_afa_cookie_ref * +mlxsw_afa_cookie_ref_create(struct mlxsw_afa_block *block, + const struct flow_action_cookie *fa_cookie) +{ + struct mlxsw_afa_cookie_ref *cookie_ref; + struct mlxsw_afa_cookie *cookie; + int err; + + cookie_ref = kzalloc(sizeof(*cookie_ref), GFP_KERNEL); + if (!cookie_ref) + return ERR_PTR(-ENOMEM); + cookie = mlxsw_afa_cookie_get(block->afa, fa_cookie); + if (IS_ERR(cookie)) { + err = PTR_ERR(cookie); + goto err_cookie_get; + } + cookie_ref->cookie = cookie; + cookie_ref->resource.destructor = mlxsw_afa_cookie_ref_destructor; + mlxsw_afa_resource_add(block, &cookie_ref->resource); + return cookie_ref; + +err_cookie_get: + kfree(cookie_ref); + return ERR_PTR(err); +} + #define MLXSW_AFA_ONE_ACTION_LEN 32 #define MLXSW_AFA_PAYLOAD_OFFSET 4 @@ -839,7 +1032,8 @@ mlxsw_afa_trap_mirror_pack(char *payload, bool mirror_enable, mlxsw_afa_trap_mirror_agent_set(payload, mirror_agent); } -int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress) +static int mlxsw_afa_block_append_drop_plain(struct mlxsw_afa_block *block, + bool ingress) { char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_TRAP_CODE, MLXSW_AFA_TRAP_SIZE); @@ -852,6 +1046,53 @@ int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress) MLXSW_TRAP_ID_DISCARD_EGRESS_ACL); return 0; } + +static int +mlxsw_afa_block_append_drop_with_cookie(struct mlxsw_afa_block *block, + bool ingress, + const struct flow_action_cookie *fa_cookie, + struct netlink_ext_ack *extack) +{ + struct mlxsw_afa_cookie_ref *cookie_ref; + u32 cookie_index; + char *act; + int err; + + cookie_ref = mlxsw_afa_cookie_ref_create(block, fa_cookie); + if (IS_ERR(cookie_ref)) { + NL_SET_ERR_MSG_MOD(extack, "Cannot create cookie for drop action"); + return PTR_ERR(cookie_ref); + } + cookie_index = cookie_ref->cookie->cookie_index; + + act = mlxsw_afa_block_append_action(block, MLXSW_AFA_TRAPWU_CODE, + MLXSW_AFA_TRAPWU_SIZE); + if (IS_ERR(act)) { + NL_SET_ERR_MSG_MOD(extack, "Cannot append drop with cookie action"); + err = PTR_ERR(act); + goto err_append_action; + } + mlxsw_afa_trapwu_pack(act, MLXSW_AFA_TRAP_TRAP_ACTION_TRAP, + MLXSW_AFA_TRAP_FORWARD_ACTION_DISCARD, + ingress ? MLXSW_TRAP_ID_DISCARD_INGRESS_ACL : + MLXSW_TRAP_ID_DISCARD_EGRESS_ACL, + cookie_index); + return 0; + +err_append_action: + mlxsw_afa_cookie_ref_destroy(block, cookie_ref); + return err; +} + +int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress, + const struct flow_action_cookie *fa_cookie, + struct netlink_ext_ack *extack) +{ + return fa_cookie ? + mlxsw_afa_block_append_drop_with_cookie(block, ingress, + fa_cookie, extack) : + mlxsw_afa_block_append_drop_plain(block, ingress); +} EXPORT_SYMBOL(mlxsw_afa_block_append_drop); int mlxsw_afa_block_append_trap(struct mlxsw_afa_block *block, u16 trap_id) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h index 28b2576ea272..67473f8bd12b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h @@ -6,6 +6,7 @@ #include #include +#include struct mlxsw_afa; struct mlxsw_afa_block; @@ -42,7 +43,9 @@ int mlxsw_afa_block_activity_get(struct mlxsw_afa_block *block, bool *activity); int mlxsw_afa_block_continue(struct mlxsw_afa_block *block); int mlxsw_afa_block_jump(struct mlxsw_afa_block *block, u16 group_id); int mlxsw_afa_block_terminate(struct mlxsw_afa_block *block); -int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress); +int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress, + const struct flow_action_cookie *fa_cookie, + struct netlink_ext_ack *extack); int mlxsw_afa_block_append_trap(struct mlxsw_afa_block *block, u16 trap_id); int mlxsw_afa_block_append_trap_and_forward(struct mlxsw_afa_block *block, u16 trap_id); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index cb3ff8d021a4..c88f00b293a1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "port.h" #include "core.h" @@ -726,7 +727,9 @@ int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei, u16 group_id); int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei); int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei, - bool ingress); + bool ingress, + const struct flow_action_cookie *fa_cookie, + struct netlink_ext_ack *extack); int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei); int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei, diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c index abd749adb0f5..36b264798f04 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c @@ -536,9 +536,12 @@ int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei) } int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei, - bool ingress) + bool ingress, + const struct flow_action_cookie *fa_cookie, + struct netlink_ext_ack *extack) { - return mlxsw_afa_block_append_drop(rulei->act_block, ingress); + return mlxsw_afa_block_append_drop(rulei->act_block, ingress, + fa_cookie, extack); } int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c index 17368ef8cee0..0011a71114e3 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c @@ -49,7 +49,8 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp, return -EOPNOTSUPP; } ingress = mlxsw_sp_acl_block_is_ingress_bound(block); - err = mlxsw_sp_acl_rulei_act_drop(rulei, ingress); + err = mlxsw_sp_acl_rulei_act_drop(rulei, ingress, + act->cookie, extack); if (err) { NL_SET_ERR_MSG_MOD(extack, "Cannot append drop action"); return err; From patchwork Tue Feb 25 10:45:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243993 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=DPp65AjR; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbF41PpJz9sP7 for ; Tue, 25 Feb 2020 21:45:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730400AbgBYKpm (ORCPT ); Tue, 25 Feb 2020 05:45:42 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39664 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730377AbgBYKpj (ORCPT ); Tue, 25 Feb 2020 05:45:39 -0500 Received: by mail-wm1-f65.google.com with SMTP id c84so2612423wme.4 for ; Tue, 25 Feb 2020 02:45:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hYgO2RdAljNfebakfE8lpmrMYi77WS78Xd/fXA6uUKs=; b=DPp65AjRxonyBSdrqf6fxRhhDcudCWvnh9kjn039c5h198Wn0BMVk9slZbTIm5kqMD Bsj9txm8Ji1DsQP0IFx+NPJnK5+0Mc6XuDCwhaDpntW9dkXn7Q9tm1xdhbnK/eExsnNB QxSjLTjpRUCYtAe7p4f80o7HUOlStIgLuOKFT++iBfFLeuDwm1d90G6X39pSO1M8mTky olOjL89JAjw5zcdW7aJ4hj6114SDy1nlYjD2SNZoD5/eG/xPcN6nfohQPIXBlVpT3WOG 7nYlNxarJgJUgrJ02560Khe34Hmp1Fuu/AJ71KNQXxftWDUTZ7OMOOnI1pUshM7VTD+c 4/fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hYgO2RdAljNfebakfE8lpmrMYi77WS78Xd/fXA6uUKs=; b=D4nrgt9sy+Hi9nttbj+X0KZFXmHz0oJ9bQjlsy+F7N0iJWt3X/xzZDfY5JfbLgU0hp F82vZshuVrfPMi9DK0Vy577LGjtlksvGqhw3t0xW+CBXs+TcjKBdNjaIteSvGreuYZLR n5OWfeI4+Je3A4sig8LEC4ZBpjzk6K3UL7vKA+K8Uvd+1Ax83ie7Nqt4iwEtq3rd5BGO Ik6R1uCmFxTBj7MloOfOjlYzSlOtNX9PcQXdUXXlqUiEkERaVnTQnuvziX+ncBng2DRw AYCBPa0wXj+y6tvznz4+BYEvVkmk1R3lYg24FaPWV7B/63QxD7SImDPyPZd5FD0bLkyx Kwdw== X-Gm-Message-State: APjAAAUphQanuIRiJnWUGvOVt9LF0BQfyFiySKNentD74UMMDB1jEGj+ IFXrugZIyC3xPGvmNfvzcWfoCxyx2UY= X-Google-Smtp-Source: APXvYqyHXsKtflVhdaZ3+FLVK3N1drtNeMDZS1XOimgm3lYe64mGxXfBSwgLm8pfGlQ0kpmMxVn88Q== X-Received: by 2002:a05:600c:34d:: with SMTP id u13mr4705106wmd.77.1582627537443; Tue, 25 Feb 2020 02:45:37 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id q14sm23642307wrj.81.2020.02.25.02.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:37 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 07/10] mlxsw: pci: Extract cookie index for ACL discard trap packets Date: Tue, 25 Feb 2020 11:45:24 +0100 Message-Id: <20200225104527.2849-8-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko In case the received packet comes in due to one of ACL discard traps, take the user_def_val_orig_pkt_len field from CQE and store it in skb->cb as ACL cookie index. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core.h | 5 ++++- drivers/net/ethernet/mellanox/mlxsw/pci.c | 9 +++++++++ drivers/net/ethernet/mellanox/mlxsw/pci_hw.h | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 00e44e778aca..46226823c7a6 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h @@ -473,7 +473,10 @@ enum mlxsw_devlink_param_id { }; struct mlxsw_skb_cb { - struct mlxsw_tx_info tx_info; + union { + struct mlxsw_tx_info tx_info; + u32 cookie_index; /* Only used during receive */ + }; }; static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb) diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c index 914c33e46fb4..67ee0da75af2 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci.c +++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c @@ -575,6 +575,15 @@ static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci, rx_info.trap_id = mlxsw_pci_cqe_trap_id_get(cqe); + if (rx_info.trap_id == MLXSW_TRAP_ID_DISCARD_INGRESS_ACL || + rx_info.trap_id == MLXSW_TRAP_ID_DISCARD_EGRESS_ACL) { + u32 cookie_index = 0; + + if (mlxsw_pci->max_cqe_ver >= MLXSW_PCI_CQE_V2) + cookie_index = mlxsw_pci_cqe2_user_def_val_orig_pkt_len_get(cqe); + mlxsw_skb_cb(skb)->cookie_index = cookie_index; + } + byte_count = mlxsw_pci_cqe_byte_count_get(cqe); if (mlxsw_pci_cqe_crc_get(cqe_v, cqe)) byte_count -= ETH_FCS_LEN; diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h b/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h index c5ceb0bb6485..32c7cabfb261 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h +++ b/drivers/net/ethernet/mellanox/mlxsw/pci_hw.h @@ -208,6 +208,11 @@ MLXSW_ITEM32(pci, cqe0, dqn, 0x0C, 1, 5); MLXSW_ITEM32(pci, cqe12, dqn, 0x0C, 1, 6); mlxsw_pci_cqe_item_helpers(dqn, 0, 12, 12); +/* pci_cqe_user_def_val_orig_pkt_len + * When trap_id is an ACL: User defined value from policy engine action. + */ +MLXSW_ITEM32(pci, cqe2, user_def_val_orig_pkt_len, 0x14, 0, 20); + /* pci_cqe_owner * Ownership bit. */ From patchwork Tue Feb 25 10:45:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243994 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=kfnkPqVq; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbF44RZwz9sPk for ; Tue, 25 Feb 2020 21:45:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730405AbgBYKpn (ORCPT ); Tue, 25 Feb 2020 05:45:43 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34962 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730388AbgBYKpl (ORCPT ); Tue, 25 Feb 2020 05:45:41 -0500 Received: by mail-wr1-f68.google.com with SMTP id w12so14136346wrt.2 for ; Tue, 25 Feb 2020 02:45:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JK/rUEreguATu4C2P2UYrDcycytDmgIhXvcFWDU0at0=; b=kfnkPqVqxXXT8EJaZygbvvuTf9dIt3YS7OPiiLxbvuv0l7dMz592ACPGxVIcf/biuB aGHlVFMA/TkuUd0rPibQBlKkLf2m4wandrnJuWI4lmh8OrfJBZjJQB8BDw7pNGxyjpDw GIBIruB1P0VBH9UVKwHBE5tWs8VvCxnL+W4xO0InOUK4toopw2hpAjEu7Hz4pK2UxaGF t+jS0sr+/vOFMkyPRfD+ayFQnH/UxvvHAcBsqPIFdFt9qphzk0sjvLoO4iXx9qfFacO0 6ZNyztd6YcO+fkvvs+/75wP7GD2j7qw1lIPkY1csC8SADRlNsprGnj6FRb/Fr/nma1BI 6E8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JK/rUEreguATu4C2P2UYrDcycytDmgIhXvcFWDU0at0=; b=Eiq0kcU4fP6jDzQDsoXxNm11JloqWfLkuXEdFxSqUAKwoS12xYYEpqDSoJ4VlUPn2K bduNNYq1T+QK904PC59m37yaEUIDKuL9aM3ePm46wbnAHqri+3g7f6naKSFZO40k6mU1 gcULqGdX+L4r9iXo9RIxJPo8ly9HaBjeuiA39oXud/PfZ4ZlD2XIcJl1/m3PWSn5zD5K XYLGVzZpS5va7Y0V/fVMiT/xKH4YnGyv1fS19olRv5B1e6zgo/CX9IT65xgpq0iyfJ/X BXuR19g2VJDYfUyvlNiBEJiFhL7ndm+AOdOTbjET8Lv+piM9SLqDW6S4uFKApwmx2dPW DNQA== X-Gm-Message-State: APjAAAVO485JVsWa2BMq0GJK1r9MTjSW+cZbkzQrMvq+xgq3XoipBXBc +utcAyAryjug8ZiEDeBDknmF+5b5zgE= X-Google-Smtp-Source: APXvYqxmFWP/OZxOxL0nBjxntNNOsUQpPwzdCNHLuRW0pa4r6adI7BIFOf8PtHP6V5ARQqQ5j/Z9fg== X-Received: by 2002:a5d:4d0a:: with SMTP id z10mr22790685wrt.253.1582627538635; Tue, 25 Feb 2020 02:45:38 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id h13sm22433147wrw.54.2020.02.25.02.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:38 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 08/10] mlxsw: spectrum_trap: Lookup and pass cookie down to devlink_trap_report() Date: Tue, 25 Feb 2020 11:45:25 +0100 Message-Id: <20200225104527.2849-9-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Use the cookie index received along with the packet to lookup original flow_offload cookie binary and pass it down to devlink_trap_report(). Add "fa_cookie" metadata to the ACL trap. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../mellanox/mlxsw/core_acl_flex_actions.c | 16 +++++++ .../mellanox/mlxsw/core_acl_flex_actions.h | 2 + .../net/ethernet/mellanox/mlxsw/spectrum.h | 6 +++ .../ethernet/mellanox/mlxsw/spectrum_trap.c | 42 +++++++++++++++++-- 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c index 9fad56df8303..1f2e6db743e1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c @@ -769,6 +769,22 @@ static void mlxsw_afa_cookie_put(struct mlxsw_afa *mlxsw_afa, mlxsw_afa_cookie_destroy(mlxsw_afa, cookie); } +/* RCU read lock must be held */ +const struct flow_action_cookie * +mlxsw_afa_cookie_lookup(struct mlxsw_afa *mlxsw_afa, u32 cookie_index) +{ + struct mlxsw_afa_cookie *cookie; + + /* 0 index means no cookie */ + if (!cookie_index) + return NULL; + cookie = idr_find(&mlxsw_afa->cookie_idr, cookie_index); + if (!cookie) + return NULL; + return &cookie->fa_cookie; +} +EXPORT_SYMBOL(mlxsw_afa_cookie_lookup); + struct mlxsw_afa_cookie_ref { struct mlxsw_afa_resource resource; struct mlxsw_afa_cookie *cookie; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h index 67473f8bd12b..5f4c1e505136 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h @@ -43,6 +43,8 @@ int mlxsw_afa_block_activity_get(struct mlxsw_afa_block *block, bool *activity); int mlxsw_afa_block_continue(struct mlxsw_afa_block *block); int mlxsw_afa_block_jump(struct mlxsw_afa_block *block, u16 group_id); int mlxsw_afa_block_terminate(struct mlxsw_afa_block *block); +const struct flow_action_cookie * +mlxsw_afa_cookie_lookup(struct mlxsw_afa *mlxsw_afa, u32 cookie_index); int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress, const struct flow_action_cookie *fa_cookie, struct netlink_ext_ack *extack); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index c88f00b293a1..3522f9674577 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -780,6 +780,12 @@ int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp); +static inline const struct flow_action_cookie * +mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index) +{ + return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index); +} + int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp); void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp); u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c index a55577a50e90..9c300d625e04 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c @@ -75,6 +75,35 @@ static void mlxsw_sp_rx_drop_listener(struct sk_buff *skb, u8 local_port, consume_skb(skb); } +static void mlxsw_sp_rx_acl_drop_listener(struct sk_buff *skb, u8 local_port, + void *trap_ctx) +{ + u32 cookie_index = mlxsw_skb_cb(skb)->cookie_index; + const struct flow_action_cookie *fa_cookie; + struct devlink_port *in_devlink_port; + struct mlxsw_sp_port *mlxsw_sp_port; + struct mlxsw_sp *mlxsw_sp; + struct devlink *devlink; + int err; + + mlxsw_sp = devlink_trap_ctx_priv(trap_ctx); + mlxsw_sp_port = mlxsw_sp->ports[local_port]; + + err = mlxsw_sp_rx_listener(mlxsw_sp, skb, local_port, mlxsw_sp_port); + if (err) + return; + + devlink = priv_to_devlink(mlxsw_sp->core); + in_devlink_port = mlxsw_core_port_devlink_port_get(mlxsw_sp->core, + local_port); + skb_push(skb, ETH_HLEN); + rcu_read_lock(); + fa_cookie = mlxsw_sp_acl_act_cookie_lookup(mlxsw_sp, cookie_index); + devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port, fa_cookie); + rcu_read_unlock(); + consume_skb(skb); +} + static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port, void *trap_ctx) { @@ -106,6 +135,11 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port, DEVLINK_TRAP_GROUP_GENERIC(_group_id), \ MLXSW_SP_TRAP_METADATA) +#define MLXSW_SP_TRAP_DROP_EXT(_id, _group_id, _metadata) \ + DEVLINK_TRAP_GENERIC(DROP, DROP, _id, \ + DEVLINK_TRAP_GROUP_GENERIC(_group_id), \ + MLXSW_SP_TRAP_METADATA | (_metadata)) + #define MLXSW_SP_TRAP_DRIVER_DROP(_id, _group_id) \ DEVLINK_TRAP_DRIVER(DROP, DROP, DEVLINK_MLXSW_TRAP_ID_##_id, \ DEVLINK_MLXSW_TRAP_NAME_##_id, \ @@ -123,7 +157,7 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port, SET_FW_DEFAULT, SP_##_group_id) #define MLXSW_SP_RXL_ACL_DISCARD(_id, _en_group_id, _dis_group_id) \ - MLXSW_RXL_DIS(mlxsw_sp_rx_drop_listener, DISCARD_##_id, \ + MLXSW_RXL_DIS(mlxsw_sp_rx_acl_drop_listener, DISCARD_##_id, \ TRAP_EXCEPTION_TO_CPU, false, SP_##_en_group_id, \ SET_FW_DEFAULT, SP_##_dis_group_id) @@ -160,8 +194,10 @@ static const struct devlink_trap mlxsw_sp_traps_arr[] = { MLXSW_SP_TRAP_DROP(NON_ROUTABLE, L3_DROPS), MLXSW_SP_TRAP_EXCEPTION(DECAP_ERROR, TUNNEL_DROPS), MLXSW_SP_TRAP_DROP(OVERLAY_SMAC_MC, TUNNEL_DROPS), - MLXSW_SP_TRAP_DROP(INGRESS_FLOW_ACTION_DROP, ACL_DROPS), - MLXSW_SP_TRAP_DROP(EGRESS_FLOW_ACTION_DROP, ACL_DROPS), + MLXSW_SP_TRAP_DROP_EXT(INGRESS_FLOW_ACTION_DROP, ACL_DROPS, + DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE), + MLXSW_SP_TRAP_DROP_EXT(EGRESS_FLOW_ACTION_DROP, ACL_DROPS, + DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE), }; static const struct mlxsw_listener mlxsw_sp_listeners_arr[] = { From patchwork Tue Feb 25 10:45:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243995 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=dP5atwxh; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbF55snXz9sP7 for ; Tue, 25 Feb 2020 21:45:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730409AbgBYKpo (ORCPT ); Tue, 25 Feb 2020 05:45:44 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45177 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730395AbgBYKpl (ORCPT ); Tue, 25 Feb 2020 05:45:41 -0500 Received: by mail-wr1-f67.google.com with SMTP id g3so14078777wrs.12 for ; Tue, 25 Feb 2020 02:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xEVbBsf2xl+NdwgFKpECjZSEK5xH+edT+7ckGVaAWxI=; b=dP5atwxhUp+We4p7jJH5C2+H03hfJ46lDfrAnKhgugujArWJgJKBh6S9QJ+dWeacX4 BnCVfBy2Il2wrv+uinlhh9BNihvpn3gWIfodqXK+9BlZI9LP9to3pv35+71Zf8uB8N/s /58rZv9NmLiCECmNnh/QBq3MeBy8LnTkOswtaUn3lSEWokJqg92DJDBFWWiEF8j6FBCh MoO3YPZ0ZyROtCSnVHo317rq/x+N78Z7cLzppBF3C/HBtLf1U7FUUSyHHNBjRunsH9np MhwQ6KnJchSvi7AHLWHmnEwwS3/dCLSgfxUKI6rdfeEdFvc90u4eizL20lDbEG2iEYrr cKig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xEVbBsf2xl+NdwgFKpECjZSEK5xH+edT+7ckGVaAWxI=; b=MsyPL9Qx5EYCsj8fdAXVzWrTnpg2ekkcg47lQrUSVgMpLvVEkeH4Odp+14r8pZZ+Yc XMBHAtpelFTGmIL5p1r1nlxCiLTakBs4ZB/KuAQq11VvRWrc7Q8moXwxAJr1LdcuVunO VcTzaH/+C5oZSrqmh5CJWS2GfEu7Xi+nh73Ubz1FM7sEiTUM6u3bms40Gvv5Nys7PLwq oOVg8rBanbvWQCSb25YgXozBTZZXxVgAGu2dXAM9Sh9Re+mFNVJCOyMsNq0RP3lbCztq YwjsuxCybWRapMxXhndpn7BNYSzBmM2Vgc22S3W3ttFeWyA1fmbgtVqbnqwSDcyd4+Y0 lmOw== X-Gm-Message-State: APjAAAXdisMXBAkF/lmzkH+ilBs/+08WeZDah11o3iSOyEHQEMBQEdPx f75EaU/9GBMuizemKrIy5FiJNSy1gws= X-Google-Smtp-Source: APXvYqxiLG3dK/KtNOrZ97iAXRPK9Q0iJCCwQ8GgbVkgA+uq68etmLkkigWH+sJgrn8R239t3FCkEw== X-Received: by 2002:a5d:4bcf:: with SMTP id l15mr10253472wrt.0.1582627539766; Tue, 25 Feb 2020 02:45:39 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id a184sm3677619wmf.29.2020.02.25.02.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:39 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 09/10] netdevsim: add ACL trap reporting cookie as a metadata Date: Tue, 25 Feb 2020 11:45:26 +0100 Message-Id: <20200225104527.2849-10-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Add new trap ACL which reports flow action cookie in a metadata. Allow used to setup the cookie using debugfs file. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel Reviewed-by: Jakub Kicinski --- v1->v2: - remove cookie_len initialization - return -EINVAL if (*ppos != 0) - added __GFP_NOWARN flag to buf malloc - removed u8 * cast in hex2bin call which is no longer needed - changed names of error path labels --- drivers/net/netdevsim/dev.c | 117 +++++++++++++++++++++++++++++- drivers/net/netdevsim/netdevsim.h | 2 + 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index aa17533c06e1..f81c47377f32 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,98 @@ static const struct file_operations nsim_dev_take_snapshot_fops = { .llseek = generic_file_llseek, }; +static ssize_t nsim_dev_trap_fa_cookie_read(struct file *file, + char __user *data, + size_t count, loff_t *ppos) +{ + struct nsim_dev *nsim_dev = file->private_data; + struct flow_action_cookie *fa_cookie; + unsigned int buf_len; + ssize_t ret; + char *buf; + + spin_lock(&nsim_dev->fa_cookie_lock); + fa_cookie = nsim_dev->fa_cookie; + if (!fa_cookie) { + ret = -EINVAL; + goto errout; + } + buf_len = fa_cookie->cookie_len * 2; + buf = kmalloc(buf_len, GFP_ATOMIC); + if (!buf) { + ret = -ENOMEM; + goto errout; + } + bin2hex(buf, fa_cookie->cookie, fa_cookie->cookie_len); + spin_unlock(&nsim_dev->fa_cookie_lock); + + ret = simple_read_from_buffer(data, count, ppos, buf, buf_len); + + kfree(buf); + return ret; + +errout: + spin_unlock(&nsim_dev->fa_cookie_lock); + return ret; +} + +static ssize_t nsim_dev_trap_fa_cookie_write(struct file *file, + const char __user *data, + size_t count, loff_t *ppos) +{ + struct nsim_dev *nsim_dev = file->private_data; + struct flow_action_cookie *fa_cookie; + size_t cookie_len; + ssize_t ret; + char *buf; + + if (*ppos != 0) + return -EINVAL; + cookie_len = (count - 1) / 2; + if ((count - 1) % 2) + return -EINVAL; + buf = kmalloc(count, GFP_KERNEL | __GFP_NOWARN); + if (!buf) + return -ENOMEM; + + ret = simple_write_to_buffer(buf, count, ppos, data, count); + if (ret < 0) + goto free_buf; + + fa_cookie = kmalloc(sizeof(*fa_cookie) + cookie_len, + GFP_KERNEL | __GFP_NOWARN); + if (!fa_cookie) { + ret = -ENOMEM; + goto free_buf; + } + + fa_cookie->cookie_len = cookie_len; + ret = hex2bin(fa_cookie->cookie, buf, cookie_len); + if (ret) + goto free_fa_cookie; + kfree(buf); + + spin_lock(&nsim_dev->fa_cookie_lock); + kfree(nsim_dev->fa_cookie); + nsim_dev->fa_cookie = fa_cookie; + spin_unlock(&nsim_dev->fa_cookie_lock); + + return count; + +free_fa_cookie: + kfree(fa_cookie); +free_buf: + kfree(buf); + return ret; +} + +static const struct file_operations nsim_dev_trap_fa_cookie_fops = { + .open = simple_open, + .read = nsim_dev_trap_fa_cookie_read, + .write = nsim_dev_trap_fa_cookie_write, + .llseek = generic_file_llseek, +}; + static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) { char dev_ddir_name[sizeof(DRV_NAME) + 10]; @@ -97,6 +190,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) &nsim_dev->dont_allow_reload); debugfs_create_bool("fail_reload", 0600, nsim_dev->ddir, &nsim_dev->fail_reload); + debugfs_create_file("trap_flow_action_cookie", 0600, nsim_dev->ddir, + nsim_dev, &nsim_dev_trap_fa_cookie_fops); return 0; } @@ -288,6 +383,10 @@ enum { DEVLINK_TRAP_GENERIC(DROP, DROP, _id, \ DEVLINK_TRAP_GROUP_GENERIC(_group_id), \ NSIM_TRAP_METADATA) +#define NSIM_TRAP_DROP_EXT(_id, _group_id, _metadata) \ + DEVLINK_TRAP_GENERIC(DROP, DROP, _id, \ + DEVLINK_TRAP_GROUP_GENERIC(_group_id), \ + NSIM_TRAP_METADATA | (_metadata)) #define NSIM_TRAP_EXCEPTION(_id, _group_id) \ DEVLINK_TRAP_GENERIC(EXCEPTION, TRAP, _id, \ DEVLINK_TRAP_GROUP_GENERIC(_group_id), \ @@ -309,6 +408,10 @@ static const struct devlink_trap nsim_traps_arr[] = { NSIM_TRAP_DROP(BLACKHOLE_ROUTE, L3_DROPS), NSIM_TRAP_EXCEPTION(TTL_ERROR, L3_DROPS), NSIM_TRAP_DROP(TAIL_DROP, BUFFER_DROPS), + NSIM_TRAP_DROP_EXT(INGRESS_FLOW_ACTION_DROP, ACL_DROPS, + DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE), + NSIM_TRAP_DROP_EXT(EGRESS_FLOW_ACTION_DROP, ACL_DROPS, + DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE), }; #define NSIM_TRAP_L4_DATA_LEN 100 @@ -366,8 +469,13 @@ static void nsim_dev_trap_report(struct nsim_dev_port *nsim_dev_port) spin_lock(&nsim_trap_data->trap_lock); for (i = 0; i < ARRAY_SIZE(nsim_traps_arr); i++) { + struct flow_action_cookie *fa_cookie = NULL; struct nsim_trap_item *nsim_trap_item; struct sk_buff *skb; + bool has_fa_cookie; + + has_fa_cookie = nsim_traps_arr[i].metadata_cap & + DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE; nsim_trap_item = &nsim_trap_data->trap_items_arr[i]; if (nsim_trap_item->action == DEVLINK_TRAP_ACTION_DROP) @@ -383,10 +491,12 @@ static void nsim_dev_trap_report(struct nsim_dev_port *nsim_dev_port) * softIRQs to prevent lockdep from complaining about * "incosistent lock state". */ - local_bh_disable(); + + spin_lock_bh(&nsim_dev->fa_cookie_lock); + fa_cookie = has_fa_cookie ? nsim_dev->fa_cookie : NULL; devlink_trap_report(devlink, skb, nsim_trap_item->trap_ctx, - &nsim_dev_port->devlink_port, NULL); - local_bh_enable(); + &nsim_dev_port->devlink_port, fa_cookie); + spin_unlock_bh(&nsim_dev->fa_cookie_lock); consume_skb(skb); } spin_unlock(&nsim_trap_data->trap_lock); @@ -780,6 +890,7 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) nsim_dev->fw_update_status = true; nsim_dev->max_macs = NSIM_DEV_MAX_MACS_DEFAULT; nsim_dev->test1 = NSIM_DEV_TEST1_DEFAULT; + spin_lock_init(&nsim_dev->fa_cookie_lock); dev_set_drvdata(&nsim_bus_dev->dev, nsim_dev); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 2eb7b0dc1594..e46fc565b981 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -178,6 +178,8 @@ struct nsim_dev { bool fail_reload; struct devlink_region *dummy_region; struct nsim_dev_health health; + struct flow_action_cookie *fa_cookie; + spinlock_t fa_cookie_lock; /* protects fa_cookie */ }; static inline struct net *nsim_dev_net(struct nsim_dev *nsim_dev) From patchwork Tue Feb 25 10:45:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 1243996 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=keL0dAhG; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48RbF72BJzz9sP7 for ; Tue, 25 Feb 2020 21:45:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730414AbgBYKpq (ORCPT ); Tue, 25 Feb 2020 05:45:46 -0500 Received: from mail-wr1-f43.google.com ([209.85.221.43]:33405 "EHLO mail-wr1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbgBYKpo (ORCPT ); Tue, 25 Feb 2020 05:45:44 -0500 Received: by mail-wr1-f43.google.com with SMTP id u6so14157998wrt.0 for ; Tue, 25 Feb 2020 02:45:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q0ltq8yr54w4WYzWfLMscM8M4JgXlp34YJicpyse3M0=; b=keL0dAhGhvaFPmuecJoMkV8JuMudr7IYk1VLrIEJNpWhxiHnKD8bxQ7PR8y16Nqxo/ a4JaIdR+f8OAioe/RupLBioi+ygk+i0wgEutahLg0xQLIJdx82BQuElqnbuNwrpItDeg gt2HbzBz8sPf23tdzc0QlX2GrEdX9Spru97GPbrOXIjOLnSaDrUtgEbwg2YDyFB/cxQi oZD2GxL4PsE2jTdHoqEeiAyS4tPPJ5mcBBCo3puOuz/5N4uGN1o1llXxcHjneHogA8+i 2/MfNjhCSHNAP5ga331KfUxNDUM/EybEKH1gju9r7Go+iJRQHRl+MkeIqijNjWf3bH9v RidA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q0ltq8yr54w4WYzWfLMscM8M4JgXlp34YJicpyse3M0=; b=MxFfUAS5ZbCXmLW8AT0o5FK5Ot5lbHeN6iPjv1qgS4iJgw0og7hLTHLvx8aJAiswMl N2kgTvIKUTFSzandqVcvjABZK6As8NKQZWYxWz1IC9UtRl/SAqVRaF9JnaahYRBuLNMU Fo7PjQileTUqyE37Flojp05dtet6JgjPfDxJYjafQfoimWCOsKuiq0e28HFQk3U/TI3k t+GSGL8ci/QCmsSqoeEHl/5NUcgTLkm0oQoElh8sftn2qN7Qtlhi12ZJ5iuZ1dCv+RCC XaK10lMagiuQsR5DadxTzW0WLXrs+Ce20fqyAvn/0++Fy7mx+J81xOl16nPmUMoZTrAy 5wFg== X-Gm-Message-State: APjAAAXjaAYQvZoZfnzrRC3o6Mt/M/X8N0/NFiDe8Z/FIxzBntW6a5Ox gXsOFZlmohQms9SfilGumz1cDQs08L8= X-Google-Smtp-Source: APXvYqykPO8SSvSrcakRfYa9/nqbgWE/ArZdAWAJA+s45/VOReoTbuH+oEv5FXS+wq3GmUn/0D0lgQ== X-Received: by 2002:adf:b60f:: with SMTP id f15mr75503806wre.372.1582627540880; Tue, 25 Feb 2020 02:45:40 -0800 (PST) Received: from localhost (ip-89-177-130-96.net.upcbroadband.cz. [89.177.130.96]) by smtp.gmail.com with ESMTPSA id n3sm6606334wrw.52.2020.02.25.02.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 02:45:40 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, nhorman@tuxdriver.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, idosch@mellanox.com, mlxsw@mellanox.com Subject: [patch net-next v2 10/10] selftests: netdevsim: Extend devlink trap test to include flow action cookie Date: Tue, 25 Feb 2020 11:45:27 +0100 Message-Id: <20200225104527.2849-11-jiri@resnulli.us> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225104527.2849-1-jiri@resnulli.us> References: <20200225104527.2849-1-jiri@resnulli.us> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Extend existing devlink trap test to include metadata type for flow action cookie. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../testing/selftests/drivers/net/netdevsim/devlink_trap.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh index f101ab9441e2..437d32bd4cfd 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh @@ -103,6 +103,11 @@ trap_metadata_test() for trap_name in $(devlink_traps_get); do devlink_trap_metadata_test $trap_name "input_port" check_err $? "Input port not reported as metadata of trap $trap_name" + if [ $trap_name == "ingress_flow_action_drop" ] || + [ $trap_name == "egress_flow_action_drop" ]; then + devlink_trap_metadata_test $trap_name "flow_action_cookie" + check_err $? "Flow action cookie not reported as metadata of trap $trap_name" + fi done log_test "Trap metadata"