[ovs-dev,V5,07/18] netdev-offload-dpdk: Framework for actions offload
diff mbox series

Message ID 20191218144110.18653-8-elibr@mellanox.com
State Changes Requested
Delegated to: Ilya Maximets
Headers show
Series
  • netdev datapath actions offload
Related show

Commit Message

Eli Britstein Dec. 18, 2019, 2:40 p.m. UTC
Currently HW offload is accelerating only the rule matching sequence.
Introduce a framework for offloading rule actions as a pre-step for
processing the rule actions in HW. In case of a failure, fallback to the
legacy partial offload scheme.

Note: a flow will be fully offloaded only if it can process all its
actions in HW.

Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
---
 lib/netdev-offload-dpdk.c | 101 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 86 insertions(+), 15 deletions(-)

Comments

0-day Robot Dec. 18, 2019, 3:16 p.m. UTC | #1
Bleep bloop.  Greetings Eli Britstein, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line is 80 characters long (recommended limit is 79)
#160 FILE: lib/netdev-offload-dpdk.c:794:
        flow = netdev_offload_dpdk_mark_rss(&patterns, netdev, info->flow_mark);

Lines checked: 181, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot

Patch
diff mbox series

diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
index e95db821e..905cf7f50 100644
--- a/lib/netdev-offload-dpdk.c
+++ b/lib/netdev-offload-dpdk.c
@@ -56,6 +56,7 @@  struct ufid_to_rte_flow_data {
     struct cmap_node node;
     ovs_u128 ufid;
     struct rte_flow *rte_flow;
+    bool actions_offloaded;
 };
 
 /* Find rte_flow with @ufid. */
@@ -76,7 +77,7 @@  ufid_to_rte_flow_data_find(const ovs_u128 *ufid)
 
 static inline void
 ufid_to_rte_flow_associate(const ovs_u128 *ufid,
-                           struct rte_flow *rte_flow)
+                           struct rte_flow *rte_flow, bool actions_offloaded)
 {
     size_t hash = hash_bytes(ufid, sizeof *ufid, 0);
     struct ufid_to_rte_flow_data *data = xzalloc(sizeof *data);
@@ -95,6 +96,7 @@  ufid_to_rte_flow_associate(const ovs_u128 *ufid,
 
     data->ufid = *ufid;
     data->rte_flow = rte_flow;
+    data->actions_offloaded = actions_offloaded;
 
     cmap_insert(&ufid_to_rte_flow,
                 CONST_CAST(struct cmap_node *, &data->node), hash);
@@ -692,6 +694,78 @@  add_flow_mark_rss_actions(struct flow_actions *actions,
     add_flow_action(actions, RTE_FLOW_ACTION_TYPE_END, NULL);
 }
 
+static struct rte_flow *
+netdev_offload_dpdk_mark_rss(struct flow_patterns *patterns,
+                             struct netdev *netdev,
+                             uint32_t flow_mark)
+{
+    struct flow_actions actions = { .actions = NULL, .cnt = 0 };
+    const struct rte_flow_attr flow_attr = {
+        .group = 0,
+        .priority = 0,
+        .ingress = 1,
+        .egress = 0
+    };
+    struct rte_flow_error error;
+    struct rte_flow *flow;
+
+    add_flow_mark_rss_actions(&actions, flow_mark, netdev);
+
+    flow = netdev_offload_dpdk_flow_create(netdev, &flow_attr, patterns->items,
+                                           actions.actions, &error);
+
+    free_flow_actions(&actions);
+    return flow;
+}
+
+static int
+parse_flow_actions(struct netdev *netdev OVS_UNUSED,
+                   struct flow_actions *actions,
+                   struct nlattr *nl_actions,
+                   size_t nl_actions_len,
+                   struct offload_info *info OVS_UNUSED)
+{
+    struct nlattr *nla;
+    size_t left;
+
+    NL_ATTR_FOR_EACH_UNSAFE (nla, left, nl_actions, nl_actions_len) {
+        VLOG_DBG_RL(&rl, "Unsupported action type %d", nl_attr_type(nla));
+        return -1;
+    }
+
+    if (nl_actions_len == 0) {
+        VLOG_DBG_RL(&rl, "Unsupported action type drop");
+        return -1;
+    }
+
+    add_flow_action(actions, RTE_FLOW_ACTION_TYPE_END, NULL);
+    return 0;
+}
+
+static struct rte_flow *
+netdev_offload_dpdk_actions(struct netdev *netdev,
+                            struct flow_patterns *patterns,
+                            struct nlattr *nl_actions,
+                            size_t actions_len,
+                            struct offload_info *info)
+{
+    const struct rte_flow_attr flow_attr = { .ingress = 1, .transfer = 1 };
+    struct flow_actions actions = { .actions = NULL, .cnt = 0 };
+    struct rte_flow *flow = NULL;
+    struct rte_flow_error error;
+    int ret;
+
+    ret = parse_flow_actions(netdev, &actions, nl_actions, actions_len, info);
+    if (ret) {
+        goto out;
+    }
+    flow = netdev_offload_dpdk_flow_create(netdev, &flow_attr, patterns->items,
+                                           actions.actions, &error);
+out:
+    free_flow_actions(&actions);
+    return flow;
+}
+
 static int
 netdev_offload_dpdk_add_flow(struct netdev *netdev,
                              const struct match *match,
@@ -700,16 +774,9 @@  netdev_offload_dpdk_add_flow(struct netdev *netdev,
                              const ovs_u128 *ufid,
                              struct offload_info *info)
 {
-    const struct rte_flow_attr flow_attr = {
-        .group = 0,
-        .priority = 0,
-        .ingress = 1,
-        .egress = 0
-    };
     struct flow_patterns patterns = { .items = NULL, .cnt = 0 };
-    struct flow_actions actions = { .actions = NULL, .cnt = 0 };
+    bool actions_offloaded = true;
     struct rte_flow *flow;
-    struct rte_flow_error error;
     int ret = 0;
 
     ret = parse_flow_match(&patterns, match);
@@ -717,22 +784,26 @@  netdev_offload_dpdk_add_flow(struct netdev *netdev,
         goto out;
     }
 
-    add_flow_mark_rss_actions(&actions, info->flow_mark, netdev);
-
-    flow = netdev_offload_dpdk_flow_create(netdev, &flow_attr, patterns.items,
-                                           actions.actions, &error);
+    flow = netdev_offload_dpdk_actions(netdev, &patterns, nl_actions,
+                                       actions_len, info);
+    if (!flow) {
+        /* if we failed to offload the rule actions fallback to mark rss
+         * actions.
+         */
+        flow = netdev_offload_dpdk_mark_rss(&patterns, netdev, info->flow_mark);
+        actions_offloaded = false;
+    }
 
     if (!flow) {
         ret = -1;
         goto out;
     }
-    ufid_to_rte_flow_associate(ufid, flow);
+    ufid_to_rte_flow_associate(ufid, flow, actions_offloaded);
     VLOG_DBG("%s: installed flow %p by ufid "UUID_FMT"\n",
              netdev_get_name(netdev), flow, UUID_ARGS((struct uuid *)ufid));
 
 out:
     free_flow_patterns(&patterns);
-    free_flow_actions(&actions);
     return ret;
 }