get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1528344/
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1528344,
    "url": "http://patchwork.ozlabs.org/api/patches/1528344/",
    "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/20210915124319.1683219-5-cmi@nvidia.com/",
    "project": {
        "id": 47,
        "url": "http://patchwork.ozlabs.org/api/projects/47/",
        "name": "Open vSwitch",
        "link_name": "openvswitch",
        "list_id": "ovs-dev.openvswitch.org",
        "list_email": "ovs-dev@openvswitch.org",
        "web_url": "http://openvswitch.org/",
        "scm_url": "git@github.com:openvswitch/ovs.git",
        "webscm_url": "https://github.com/openvswitch/ovs",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20210915124319.1683219-5-cmi@nvidia.com>",
    "list_archive_url": null,
    "date": "2021-09-15T12:43:16",
    "name": "[ovs-dev,v15,4/7] netdev-offload-tc: Introduce group ID management API",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "31556427ed294f93e61e97d84d089ced85648919",
    "submitter": {
        "id": 80086,
        "url": "http://patchwork.ozlabs.org/api/people/80086/",
        "name": "Chris Mi",
        "email": "cmi@nvidia.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/openvswitch/patch/20210915124319.1683219-5-cmi@nvidia.com/mbox/",
    "series": [
        {
            "id": 262447,
            "url": "http://patchwork.ozlabs.org/api/series/262447/",
            "web_url": "http://patchwork.ozlabs.org/project/openvswitch/list/?series=262447",
            "date": "2021-09-15T12:43:12",
            "name": "Add offload support for sFlow",
            "version": 15,
            "mbox": "http://patchwork.ozlabs.org/series/262447/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1528344/comments/",
    "check": "success",
    "checks": "http://patchwork.ozlabs.org/api/patches/1528344/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<ovs-dev-bounces@openvswitch.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "dev@openvswitch.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@ozlabs.org",
            "ovs-dev@lists.linuxfoundation.org"
        ],
        "Authentication-Results": "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org\n (client-ip=140.211.166.138; helo=smtp1.osuosl.org;\n envelope-from=ovs-dev-bounces@openvswitch.org; receiver=<UNKNOWN>)",
        "Received": [
            "from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 4H8fzJ3Jz0z9sjJ\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Sep 2021 22:43:56 +1000 (AEST)",
            "from localhost (localhost [127.0.0.1])\n\tby smtp1.osuosl.org (Postfix) with ESMTP id 3422F82CC7;\n\tWed, 15 Sep 2021 12:43:53 +0000 (UTC)",
            "from smtp1.osuosl.org ([127.0.0.1])\n\tby localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id DBuHctzuj0ui; Wed, 15 Sep 2021 12:43:44 +0000 (UTC)",
            "from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56])\n\tby smtp1.osuosl.org (Postfix) with ESMTPS id 3064F82BE7;\n\tWed, 15 Sep 2021 12:43:41 +0000 (UTC)",
            "from lf-lists.osuosl.org (localhost [127.0.0.1])\n\tby lists.linuxfoundation.org (Postfix) with ESMTP id 8BF3DC0039;\n\tWed, 15 Sep 2021 12:43:36 +0000 (UTC)",
            "from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136])\n by lists.linuxfoundation.org (Postfix) with ESMTP id 4493BC0027\n for <dev@openvswitch.org>; Wed, 15 Sep 2021 12:43:32 +0000 (UTC)",
            "from localhost (localhost [127.0.0.1])\n by smtp3.osuosl.org (Postfix) with ESMTP id DF76060B89\n for <dev@openvswitch.org>; Wed, 15 Sep 2021 12:43:29 +0000 (UTC)",
            "from smtp3.osuosl.org ([127.0.0.1])\n by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n with ESMTP id uD2t2DbC-2ua for <dev@openvswitch.org>;\n Wed, 15 Sep 2021 12:43:29 +0000 (UTC)",
            "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n by smtp3.osuosl.org (Postfix) with ESMTP id 5A4D460B90\n for <dev@openvswitch.org>; Wed, 15 Sep 2021 12:43:28 +0000 (UTC)",
            "from Internal Mail-Server by MTLPINE1 (envelope-from cmi@nvidia.com)\n with SMTP; 15 Sep 2021 15:43:21 +0300",
            "from c-141-46-1-010.mtl.labs.mlnx (c-141-46-1-010.mtl.labs.mlnx\n [10.141.46.10])\n by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 18FChLbY010242;\n Wed, 15 Sep 2021 15:43:21 +0300"
        ],
        "X-Virus-Scanned": [
            "amavisd-new at osuosl.org",
            "amavisd-new at osuosl.org"
        ],
        "X-Greylist": "domain auto-whitelisted by SQLgrey-1.8.0",
        "To": "dev@openvswitch.org",
        "Date": "Wed, 15 Sep 2021 15:43:16 +0300",
        "Message-Id": "<20210915124319.1683219-5-cmi@nvidia.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20210915124319.1683219-1-cmi@nvidia.com>",
        "References": "<20210915124319.1683219-1-cmi@nvidia.com>",
        "MIME-Version": "1.0",
        "Cc": "elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com,\n i.maximets@ovn.org",
        "Subject": "[ovs-dev] [PATCH v15 4/7] netdev-offload-tc: Introduce group ID\n\tmanagement API",
        "X-BeenThere": "ovs-dev@openvswitch.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "<ovs-dev.openvswitch.org>",
        "List-Unsubscribe": "<https://mail.openvswitch.org/mailman/options/ovs-dev>,\n <mailto:ovs-dev-request@openvswitch.org?subject=unsubscribe>",
        "List-Archive": "<http://mail.openvswitch.org/pipermail/ovs-dev/>",
        "List-Post": "<mailto:ovs-dev@openvswitch.org>",
        "List-Help": "<mailto:ovs-dev-request@openvswitch.org?subject=help>",
        "List-Subscribe": "<https://mail.openvswitch.org/mailman/listinfo/ovs-dev>,\n <mailto:ovs-dev-request@openvswitch.org?subject=subscribe>",
        "From": "Chris Mi via dev <ovs-dev@openvswitch.org>",
        "Reply-To": "Chris Mi <cmi@nvidia.com>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "ovs-dev-bounces@openvswitch.org",
        "Sender": "\"dev\" <ovs-dev-bounces@openvswitch.org>"
    },
    "content": "When offloading sample action to TC, userspace creates a unique ID\nto map sFlow action and tunnel info and passes this ID to kernel instead\nof the sFlow info. psample will send this ID and sampled packet to\nuserspace. Using the ID, userspace can recover the sFlow info and send\nsampled packet to the right sFlow monitoring host.\n\nSigned-off-by: Chris Mi <cmi@nvidia.com>\nReviewed-by: Eli Britstein <elibr@nvidia.com>\n---\n lib/dpif-offload-provider.h |  17 +++\n lib/netdev-offload-tc.c     | 247 +++++++++++++++++++++++++++++++++++-\n lib/netdev-offload.h        |   1 +\n lib/tc.h                    |   1 +\n 4 files changed, 260 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h\nindex 75238c4cb..95c29c0d8 100644\n--- a/lib/dpif-offload-provider.h\n+++ b/lib/dpif-offload-provider.h\n@@ -17,9 +17,26 @@\n #ifndef DPIF_OFFLOAD_PROVIDER_H\n #define DPIF_OFFLOAD_PROVIDER_H\n \n+#include \"netlink-protocol.h\"\n+#include \"openvswitch/packets.h\"\n+#include \"openvswitch/types.h\"\n+\n struct dpif;\n struct dpif_offload_sflow;\n \n+/* When offloading sample action, userspace creates a unique ID to map\n+ * sFlow action and tunnel info and passes this ID to datapath instead\n+ * of the sFlow info. Datapath will send this ID and sampled packet to\n+ * userspace. Using the ID, userspace can recover the sFlow info and send\n+ * sampled packet to the right sFlow monitoring host.\n+ */\n+struct dpif_sflow_attr {\n+    const struct nlattr *action;    /* SFlow action. */\n+    const struct nlattr *userdata;  /* Struct user_action_cookie. */\n+    struct flow_tnl *tunnel;        /* Tunnel info. */\n+    ovs_u128 ufid;                  /* Flow ufid. */\n+};\n+\n /* Datapath interface offload structure, to be defined by each implementation\n  * of a datapath interface.\n  */\ndiff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c\nindex 9845e8d3f..5d817b6cf 100644\n--- a/lib/netdev-offload-tc.c\n+++ b/lib/netdev-offload-tc.c\n@@ -40,6 +40,7 @@\n #include \"unaligned.h\"\n #include \"util.h\"\n #include \"dpif-provider.h\"\n+#include \"cmap.h\"\n \n VLOG_DEFINE_THIS_MODULE(netdev_offload_tc);\n \n@@ -62,6 +63,234 @@ struct chain_node {\n     uint32_t chain;\n };\n \n+/* This maps a psample group ID to struct dpif_sflow_attr for sFlow */\n+struct sgid_node {\n+    struct ovs_list exp_node OVS_GUARDED;\n+    struct cmap_node metadata_node;\n+    struct cmap_node id_node;\n+    struct ovs_refcount refcount;\n+    uint32_t hash;\n+    uint32_t id;\n+    const struct dpif_sflow_attr sflow;\n+};\n+\n+static struct ovs_rwlock sgid_rwlock = OVS_RWLOCK_INITIALIZER;\n+static struct cmap sgid_map = CMAP_INITIALIZER;\n+static struct cmap sgid_metadata_map = CMAP_INITIALIZER;\n+static struct ovs_list sgid_expiring OVS_GUARDED_BY(sgid_rwlock)\n+    = OVS_LIST_INITIALIZER(&sgid_expiring);\n+static uint32_t next_sample_group_id OVS_GUARDED_BY(sgid_rwlock) = 1;\n+\n+static void\n+sgid_node_free(struct sgid_node *node)\n+{\n+    free(node->sflow.tunnel);\n+    free(CONST_CAST(void *, node->sflow.action));\n+    free(CONST_CAST(void *, node->sflow.userdata));\n+    free(node);\n+}\n+\n+/* Lockless RCU protected lookup.  If node is needed accross RCU quiescent\n+ * state, caller should copy the contents. */\n+static const struct sgid_node *\n+sgid_find(uint32_t id)\n+{\n+    const struct cmap_node *node = cmap_find(&sgid_map, id);\n+\n+    return node ? CONTAINER_OF(node, const struct sgid_node, id_node) : NULL;\n+}\n+\n+const struct dpif_sflow_attr *\n+dpif_offload_sflow_attr_find(uint32_t id)\n+{\n+    const struct sgid_node *node;\n+\n+    node = sgid_find(id);\n+    if (!node) {\n+        return NULL;\n+    }\n+\n+    return &node->sflow;\n+}\n+\n+static uint32_t\n+dpif_sflow_attr_hash(const struct dpif_sflow_attr *sflow)\n+{\n+    return hash_bytes(&sflow->ufid, sizeof sflow->ufid, 0);\n+}\n+\n+static bool\n+dpif_sflow_attr_equal(const struct dpif_sflow_attr *a,\n+                      const struct dpif_sflow_attr *b)\n+{\n+    if (!ovs_u128_equals(a->ufid, b->ufid)) {\n+        return false;\n+    }\n+    if (!a->action || !b->action) {\n+        return false;\n+    }\n+    if (a->action->nla_len != b->action->nla_len\n+        || memcmp(a->action, b->action, a->action->nla_len)) {\n+        return false;\n+    }\n+    if (!a->tunnel && !b->tunnel) {\n+        return true;\n+    }\n+    if (!a->tunnel || !b->tunnel) {\n+        return false;\n+    }\n+\n+    return !memcmp(a->tunnel, b->tunnel, sizeof *a->tunnel);\n+}\n+\n+/* Lockless RCU protected lookup.  If node is needed accross RCU quiescent\n+ * state, caller should take a reference. */\n+static struct sgid_node *\n+sgid_find_equal(const struct dpif_sflow_attr *target, uint32_t hash)\n+{\n+    struct sgid_node *node;\n+\n+    CMAP_FOR_EACH_WITH_HASH (node, metadata_node, hash, &sgid_metadata_map) {\n+        if (dpif_sflow_attr_equal(&node->sflow, target)) {\n+            return node;\n+        }\n+    }\n+    return NULL;\n+}\n+\n+static struct sgid_node *\n+sgid_ref_equal(const struct dpif_sflow_attr *target, uint32_t hash)\n+{\n+    struct sgid_node *node;\n+\n+    do {\n+        node = sgid_find_equal(target, hash);\n+        /* Try again if the node was released before we get the reference. */\n+    } while (node && !ovs_refcount_try_ref_rcu(&node->refcount));\n+\n+    return node;\n+}\n+\n+static void\n+dpif_sflow_attr_clone(struct dpif_sflow_attr *new,\n+                      const struct dpif_sflow_attr *old)\n+{\n+    new->action = xmemdup(old->action, old->action->nla_len);\n+    new->userdata = xmemdup(old->userdata, old->userdata->nla_len);\n+    new->tunnel = old->tunnel\n+                  ? xmemdup(old->tunnel, sizeof *old->tunnel)\n+                  : NULL;\n+    new->ufid = old->ufid;\n+}\n+\n+/* We use the id as the hash value, which works due to cmap internal rehashing.\n+ * We also only insert nodes with unique IDs, so all possible hash collisions\n+ * remain internal to the cmap. */\n+static struct sgid_node *\n+sgid_find__(uint32_t id)\n+    OVS_REQUIRES(sgid_rwlock)\n+{\n+    struct cmap_node *node = cmap_find_protected(&sgid_map, id);\n+\n+    return node ? CONTAINER_OF(node, struct sgid_node, id_node) : NULL;\n+}\n+\n+/* Allocate a unique group id for the given set of flow metadata. The id\n+ * space is 2^^32, but if looping too many times, we still can't find a\n+ * free one, that means something is wrong, return NULL.\n+ */\n+#define SGID_ALLOC_RETRY_MAX 8192\n+static struct sgid_node *\n+sgid_alloc__(const struct dpif_sflow_attr *sflow, uint32_t hash)\n+{\n+    struct sgid_node *node = xzalloc(sizeof *node);\n+    int i = 0;\n+\n+    node->hash = hash;\n+    ovs_refcount_init(&node->refcount);\n+    dpif_sflow_attr_clone(CONST_CAST(struct dpif_sflow_attr *,\n+                                     &node->sflow), sflow);\n+\n+    ovs_rwlock_wrlock(&sgid_rwlock);\n+    for (;;) {\n+        node->id = next_sample_group_id++;\n+        if (OVS_UNLIKELY(!node->id)) {\n+            next_sample_group_id = 1;\n+            node->id = next_sample_group_id++;\n+        }\n+        /* Find if the id is free. */\n+        if (OVS_LIKELY(!sgid_find__(node->id))) {\n+            break;\n+        }\n+        if (++i == SGID_ALLOC_RETRY_MAX) {\n+            VLOG_ERR(\"%s: Can't find a free group ID after %d retries\",\n+                     __func__, i);\n+            ovs_rwlock_unlock(&sgid_rwlock);\n+            sgid_node_free(node);\n+            return NULL;\n+        }\n+    }\n+    cmap_insert(&sgid_map, &node->id_node, node->id);\n+    cmap_insert(&sgid_metadata_map, &node->metadata_node, node->hash);\n+    ovs_rwlock_unlock(&sgid_rwlock);\n+    return node;\n+}\n+\n+/* Allocate a unique group id for the given set of flow metadata and\n+   optional actions. */\n+static uint32_t\n+sgid_alloc_ctx(const struct dpif_sflow_attr *sflow)\n+{\n+    uint32_t hash = dpif_sflow_attr_hash(sflow);\n+    struct sgid_node *node = sgid_ref_equal(sflow, hash);\n+\n+    if (!node) {\n+        node = sgid_alloc__(sflow, hash);\n+    }\n+\n+    return node ? node->id : 0;\n+}\n+\n+static void\n+sgid_node_unref(const struct sgid_node *node_)\n+    OVS_EXCLUDED(sgid_rwlock)\n+{\n+    struct sgid_node *node = CONST_CAST(struct sgid_node *, node_);\n+\n+    ovs_rwlock_wrlock(&sgid_rwlock);\n+    if (node && ovs_refcount_unref(&node->refcount) == 1) {\n+        cmap_remove(&sgid_metadata_map, &node->metadata_node, node->hash);\n+        cmap_remove(&sgid_map, &node->id_node, node->id);\n+        ovsrcu_postpone(sgid_node_free, node);\n+    }\n+    ovs_rwlock_unlock(&sgid_rwlock);\n+}\n+\n+static void\n+sgid_free(uint32_t id)\n+{\n+    const struct sgid_node *node;\n+\n+    if (!id) {\n+        return;\n+    }\n+\n+    node = sgid_find(id);\n+    if (node) {\n+        sgid_node_unref(node);\n+    } else {\n+        VLOG_ERR(\"%s: Freeing nonexistent group ID: %\"PRIu32, __func__, id);\n+    }\n+}\n+\n+static int\n+del_filter_and_sgid(struct tcf_id *id)\n+{\n+    sgid_free(id->sample_group_id);\n+    id->sample_group_id = 0;\n+    return tc_del_filter(id);\n+}\n+\n static bool\n is_internal_port(const char *type)\n {\n@@ -198,13 +427,13 @@ del_ufid_tc_mapping(const ovs_u128 *ufid)\n     ovs_mutex_unlock(&ufid_lock);\n }\n \n-/* Wrapper function to delete filter and ufid tc mapping */\n+/* Wrapper function to delete filter, sgid and ufid tc mapping */\n static int\n-del_filter_and_ufid_mapping(struct tcf_id *id, const ovs_u128 *ufid)\n+del_filter_sgid_ufid_mapping(struct tcf_id *id, const ovs_u128 *ufid)\n {\n     int err;\n \n-    err = tc_del_filter(id);\n+    err = del_filter_and_sgid(id);\n     if (!err) {\n         del_ufid_tc_mapping(ufid);\n     }\n@@ -426,7 +655,7 @@ netdev_tc_flow_flush(struct netdev *netdev)\n             continue;\n         }\n \n-        err = tc_del_filter(&data->id);\n+        err = del_filter_and_sgid(&data->id);\n         if (!err) {\n             del_ufid_tc_mapping_unlocked(&data->ufid);\n         }\n@@ -1917,6 +2146,11 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n             action->type = TC_ACT_GOTO;\n             action->chain = 0;  /* 0 is reserved and not used by recirc. */\n             flower.action_count++;\n+        } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) {\n+            struct dpif_sflow_attr sflow_attr;\n+\n+            memset(&sflow_attr, 0, sizeof sflow_attr);\n+            sgid_alloc_ctx(&sflow_attr);\n         } else {\n             VLOG_DBG_RL(&rl, \"unsupported put action type: %d\",\n                         nl_attr_type(nla));\n@@ -1932,7 +2166,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n     if (get_ufid_tc_mapping(ufid, &id) == 0) {\n         VLOG_DBG_RL(&rl, \"updating old handle: %d prio: %d\",\n                     id.handle, id.prio);\n-        info->tc_modify_flow_deleted = !del_filter_and_ufid_mapping(&id, ufid);\n+        info->tc_modify_flow_deleted = !del_filter_sgid_ufid_mapping(&id,\n+                                                                     ufid);\n     }\n \n     prio = get_prio_for_tc_flower(&flower);\n@@ -2021,7 +2256,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED,\n         }\n     }\n \n-    error = del_filter_and_ufid_mapping(&id, ufid);\n+    error = del_filter_sgid_ufid_mapping(&id, ufid);\n \n     return error;\n }\ndiff --git a/lib/netdev-offload.h b/lib/netdev-offload.h\nindex e7fcedae9..d57d70470 100644\n--- a/lib/netdev-offload.h\n+++ b/lib/netdev-offload.h\n@@ -138,6 +138,7 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match,\n int netdev_ports_get_n_flows(const char *dpif_type,\n                              odp_port_t port_no, uint64_t *n_flows);\n \n+const struct dpif_sflow_attr *dpif_offload_sflow_attr_find(uint32_t id);\n #ifdef  __cplusplus\n }\n #endif\ndiff --git a/lib/tc.h b/lib/tc.h\nindex a147ca461..2e4084f48 100644\n--- a/lib/tc.h\n+++ b/lib/tc.h\n@@ -276,6 +276,7 @@ struct tcf_id {\n     uint32_t chain;\n     uint16_t prio;\n     uint32_t handle;\n+    uint32_t sample_group_id;\n };\n \n static inline struct tcf_id\n",
    "prefixes": [
        "ovs-dev",
        "v15",
        "4/7"
    ]
}