From patchwork Mon Dec 2 08:41:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Britstein X-Patchwork-Id: 1202998 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47RJXG49ZGz9sP3 for ; Mon, 2 Dec 2019 19:42:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0D64B86302; Mon, 2 Dec 2019 08:42:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ioQfYWd4f7Nv; Mon, 2 Dec 2019 08:42:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 40EBF862AC; Mon, 2 Dec 2019 08:42:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0ADD9C1DE6; Mon, 2 Dec 2019 08:42:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id E59B3C087F for ; Mon, 2 Dec 2019 08:42:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id A57D588167 for ; Mon, 2 Dec 2019 08:42:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IU3KlZC5q9+J for ; Mon, 2 Dec 2019 08:42:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by hemlock.osuosl.org (Postfix) with ESMTP id 15DA987E63 for ; Mon, 2 Dec 2019 08:42:07 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from elibr@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Dec 2019 10:42:02 +0200 Received: from dev-r-vrt-215.mtr.labs.mlnx. (dev-r-vrt-215.mtr.labs.mlnx [10.212.215.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id xB28g0Pf007800; Mon, 2 Dec 2019 10:42:02 +0200 From: Eli Britstein To: dev@openvswitch.org, Ilya Maximets , Ian Stokes Date: Mon, 2 Dec 2019 08:41:50 +0000 Message-Id: <20191202084153.14412-17-elibr@mellanox.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20191202084153.14412-1-elibr@mellanox.com> References: <20191202084153.14412-1-elibr@mellanox.com> Cc: Oz Shlomo , Majd Dibbiny , Eli Britstein , Ameer Mahagneh Subject: [ovs-dev] [PATCH V2 16/19] netdev-offload-dpdk-flow: Support offload of set MAC actions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Signed-off-by: Eli Britstein Reviewed-by: Oz Shlomo --- NEWS | 3 +- lib/netdev-offload-dpdk-flow.c | 122 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 45eef591f..b372e703a 100644 --- a/NEWS +++ b/NEWS @@ -26,7 +26,8 @@ Post-v2.12.0 releases. * OVS validated with DPDK 18.11.5, due to the inclusion of a fix for CVE-2019-14818, this DPDK version is strongly recommended to be used. - * Add hardware offload support for output and drop actions (experimental). + * Add hardware offload support for output, drop and set MAC actions + (experimental). v2.12.0 - 03 Sep 2019 --------------------- diff --git a/lib/netdev-offload-dpdk-flow.c b/lib/netdev-offload-dpdk-flow.c index a73d9522d..b9ceb1aaf 100644 --- a/lib/netdev-offload-dpdk-flow.c +++ b/lib/netdev-offload-dpdk-flow.c @@ -298,6 +298,21 @@ ds_put_flow_action(struct ds *s, const struct rte_flow_action *actions) } } else if (actions->type == RTE_FLOW_ACTION_TYPE_DROP) { ds_put_cstr(s, "rte flow drop action\n"); + } else if (actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC || + actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_DST) { + const struct rte_flow_action_set_mac *set_mac = actions->conf; + + char *dirstr = actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_DST + ? "dst" : "src"; + + ds_put_format(s, "rte flow set-mac-%s action:\n", dirstr); + if (set_mac) { + ds_put_format(s, + " Set-mac-%s: "ETH_ADDR_FMT"\n", + dirstr, ETH_ADDR_BYTES_ARGS(set_mac->mac_addr)); + } else { + ds_put_format(s, " Set-mac-%s = null\n", dirstr); + } } else { ds_put_format(s, "unknown rte flow action (%d)\n", actions->type); } @@ -608,6 +623,103 @@ netdev_dpdk_flow_add_output_action(struct flow_actions *actions, return ret; } +struct set_action_info { + const uint8_t *value, *mask; + const uint8_t size; + uint8_t *spec; + const int attr; +}; + +static int +add_set_flow_action(struct flow_actions *actions, + struct set_action_info *sa_info_arr, + size_t sa_info_arr_size) +{ + int field, i; + + for (field = 0; field < sa_info_arr_size; field++) { + if (sa_info_arr[field].mask) { + /* DPDK does not support partially masked set actions. In such + * case, fail the offload. + */ + if (sa_info_arr[field].mask[0] != 0x00 && + sa_info_arr[field].mask[0] != 0xFF) { + VLOG_DBG_RL(&error_rl, + "Partial mask is not supported"); + return -1; + } + + for (i = 1; i < sa_info_arr[field].size; i++) { + if (sa_info_arr[field].mask[i] != + sa_info_arr[field].mask[i - 1]) { + VLOG_DBG_RL(&error_rl, + "Partial mask is not supported"); + return -1; + } + } + + if (sa_info_arr[field].mask[0] == 0x00) { + /* mask bytes are all 0 - no rewrite action required */ + continue; + } + } + + memcpy(sa_info_arr[field].spec, sa_info_arr[field].value, + sa_info_arr[field].size); + add_flow_action(actions, sa_info_arr[field].attr, + sa_info_arr[field].spec); + } + + return 0; +} + +/* Mask is at the midpoint of the data. */ +#define get_mask(a, type) ((const type *)(const void *)(a + 1) + 1) + +#define SA_INFO(_field, _spec, _attr) { \ + .value = (uint8_t *)&key->_field, \ + .mask = (masked) ? (uint8_t *)&mask->_field : NULL, \ + .size = sizeof key->_field, \ + .spec = (uint8_t *)&_spec, \ + .attr = _attr } + +static int +netdev_dpdk_flow_add_set_actions(struct flow_actions *actions, + const struct nlattr *set_actions, + const size_t set_actions_len, + bool masked) +{ + const struct nlattr *sa; + unsigned int sleft; + + NL_ATTR_FOR_EACH_UNSAFE (sa, sleft, set_actions, set_actions_len) { + if (nl_attr_type(sa) == OVS_KEY_ATTR_ETHERNET) { + const struct ovs_key_ethernet *key = nl_attr_get(sa); + const struct ovs_key_ethernet *mask = masked ? + get_mask(sa, struct ovs_key_ethernet) : NULL; + struct rte_flow_action_set_mac *src = xzalloc(sizeof *src); + struct rte_flow_action_set_mac *dst = xzalloc(sizeof *dst); + struct set_action_info sa_info_arr[] = { + SA_INFO(eth_src, src->mac_addr[0], + RTE_FLOW_ACTION_TYPE_SET_MAC_SRC), + SA_INFO(eth_dst, dst->mac_addr[0], + RTE_FLOW_ACTION_TYPE_SET_MAC_DST), + }; + + if (add_set_flow_action(actions, sa_info_arr, + ARRAY_SIZE(sa_info_arr))) { + return -1; + } + } else { + VLOG_DBG_RL(&error_rl, + "Unsupported set action type=%d", nl_attr_type(sa)); + return -1; + } + } + + return 0; +} + int netdev_dpdk_flow_actions_add(struct flow_actions *actions, struct nlattr *nl_actions, @@ -624,6 +736,16 @@ netdev_dpdk_flow_actions_add(struct flow_actions *actions, netdev_dpdk_flow_add_output_action(actions, nla, info )) { return -1; } + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SET || + nl_attr_type(nla) == OVS_ACTION_ATTR_SET_MASKED) { + const struct nlattr *set_actions = nl_attr_get(nla); + const size_t set_actions_len = nl_attr_get_size(nla); + bool masked = nl_attr_type(nla) == OVS_ACTION_ATTR_SET_MASKED; + + if (netdev_dpdk_flow_add_set_actions(actions, set_actions, + set_actions_len, masked)) { + return -1; + } } else { VLOG_DBG_RL(&error_rl, "Unsupported action type %d", nl_attr_type(nla));