From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, Gaetan Rivet <gaetan.rivet@6wind.com>,
Thomas Monjalon <thomas@monjalon.net>
Subject: [dpdk-stable] [PATCH v1 7/9] ethdev: fix shallow copy of flow API RSS action
Date: Fri, 23 Mar 2018 13:58:14 +0100 [thread overview]
Message-ID: <20180323124725.15806-8-adrien.mazarguil@6wind.com> (raw)
In-Reply-To: <20180323124725.15806-1-adrien.mazarguil@6wind.com>
The rss_conf field is defined as a pointer to struct rte_eth_rss_conf.
Even assuming it is permanently allocated and a pointer copy is safe,
pointed data may change and not reflect an applied flow rule anymore.
This patch aligns with testpmd by making a deep copy instead.
Fixes: 18da437b5f63 ("ethdev: add flow rule copy function")
Cc: stable@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Cc: Thomas Monjalon <thomas@monjalon.net>
---
lib/librte_ether/rte_flow.c | 145 +++++++++++++++++++++++++++------------
1 file changed, 102 insertions(+), 43 deletions(-)
diff --git a/lib/librte_ether/rte_flow.c b/lib/librte_ether/rte_flow.c
index 38f2d27be..ba6feddee 100644
--- a/lib/librte_ether/rte_flow.c
+++ b/lib/librte_ether/rte_flow.c
@@ -255,60 +255,119 @@ rte_flow_error_set(struct rte_flow_error *error,
return -code;
}
-/** Compute storage space needed by item specification. */
-static void
-flow_item_spec_size(const struct rte_flow_item *item,
- size_t *size, size_t *pad)
+/** Pattern item specification types. */
+enum item_spec_type {
+ ITEM_SPEC,
+ ITEM_LAST,
+ ITEM_MASK,
+};
+
+/** Compute storage space needed by item specification and copy it. */
+static size_t
+flow_item_spec_copy(void *buf, const struct rte_flow_item *item,
+ enum item_spec_type type)
{
- if (!item->spec) {
- *size = 0;
+ size_t size = 0;
+ const void *item_spec =
+ type == ITEM_SPEC ? item->spec :
+ type == ITEM_LAST ? item->last :
+ type == ITEM_MASK ? item->mask :
+ NULL;
+
+ if (!item_spec)
goto empty;
- }
switch (item->type) {
union {
const struct rte_flow_item_raw *raw;
- } spec;
+ } src;
+ union {
+ struct rte_flow_item_raw *raw;
+ } dst;
- /* Not a fall-through */
case RTE_FLOW_ITEM_TYPE_RAW:
- spec.raw = item->spec;
- *size = offsetof(struct rte_flow_item_raw, pattern) +
- spec.raw->length * sizeof(*spec.raw->pattern);
+ src.raw = item_spec;
+ dst.raw = buf;
+ size = offsetof(struct rte_flow_item_raw, pattern) +
+ src.raw->length * sizeof(*src.raw->pattern);
+ if (dst.raw)
+ memcpy(dst.raw, src.raw, size);
break;
default:
- *size = rte_flow_desc_item[item->type].size;
+ size = rte_flow_desc_item[item->type].size;
+ if (buf)
+ memcpy(buf, item_spec, size);
break;
}
empty:
- *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
+ return RTE_ALIGN_CEIL(size, sizeof(double));
}
-/** Compute storage space needed by action configuration. */
-static void
-flow_action_conf_size(const struct rte_flow_action *action,
- size_t *size, size_t *pad)
+/** Compute storage space needed by action configuration and copy it. */
+static size_t
+flow_action_conf_copy(void *buf, const struct rte_flow_action *action)
{
- if (!action->conf) {
- *size = 0;
+ size_t size = 0;
+
+ if (!action->conf)
goto empty;
- }
switch (action->type) {
union {
const struct rte_flow_action_rss *rss;
- } conf;
+ } src;
+ union {
+ struct rte_flow_action_rss *rss;
+ } dst;
+ size_t off;
- /* Not a fall-through. */
case RTE_FLOW_ACTION_TYPE_RSS:
- conf.rss = action->conf;
- *size = offsetof(struct rte_flow_action_rss, queue) +
- conf.rss->num * sizeof(*conf.rss->queue);
+ src.rss = action->conf;
+ dst.rss = buf;
+ off = 0;
+ if (dst.rss)
+ *dst.rss = (struct rte_flow_action_rss){
+ .num = src.rss->num,
+ };
+ off += offsetof(struct rte_flow_action_rss, queue);
+ if (src.rss->num) {
+ size = sizeof(*src.rss->queue) * src.rss->num;
+ if (dst.rss)
+ memcpy(dst.rss->queue, src.rss->queue, size);
+ off += size;
+ }
+ off = RTE_ALIGN_CEIL(off, sizeof(double));
+ if (dst.rss) {
+ dst.rss->rss_conf = (void *)((uintptr_t)dst.rss + off);
+ *(struct rte_eth_rss_conf *)(uintptr_t)
+ dst.rss->rss_conf = (struct rte_eth_rss_conf){
+ .rss_key_len = src.rss->rss_conf->rss_key_len,
+ .rss_hf = src.rss->rss_conf->rss_hf,
+ };
+ }
+ off += sizeof(*src.rss->rss_conf);
+ if (src.rss->rss_conf->rss_key_len) {
+ off = RTE_ALIGN_CEIL(off, sizeof(double));
+ size = sizeof(*src.rss->rss_conf->rss_key) *
+ src.rss->rss_conf->rss_key_len;
+ if (dst.rss) {
+ ((struct rte_eth_rss_conf *)(uintptr_t)
+ dst.rss->rss_conf)->rss_key =
+ (void *)((uintptr_t)dst.rss + off);
+ memcpy(dst.rss->rss_conf->rss_key,
+ src.rss->rss_conf->rss_key,
+ size);
+ }
+ off += size;
+ }
+ size = off;
break;
default:
- *size = rte_flow_desc_action[action->type].size;
+ size = rte_flow_desc_action[action->type].size;
+ if (buf)
+ memcpy(buf, action->conf, size);
break;
}
empty:
- *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size;
+ return RTE_ALIGN_CEIL(size, sizeof(double));
}
/** Store a full rte_flow description. */
@@ -320,7 +379,6 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len,
{
struct rte_flow_desc *fd = NULL;
size_t tmp;
- size_t pad;
size_t off1 = 0;
size_t off2 = 0;
size_t size = 0;
@@ -345,24 +403,26 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len,
dst = memcpy(fd->data + off1, item,
sizeof(*item));
off1 += sizeof(*item);
- flow_item_spec_size(item, &tmp, &pad);
if (item->spec) {
if (fd)
- dst->spec = memcpy(fd->data + off2,
- item->spec, tmp);
- off2 += tmp + pad;
+ dst->spec = fd->data + off2;
+ off2 += flow_item_spec_copy
+ (fd ? fd->data + off2 : NULL, item,
+ ITEM_SPEC);
}
if (item->last) {
if (fd)
- dst->last = memcpy(fd->data + off2,
- item->last, tmp);
- off2 += tmp + pad;
+ dst->last = fd->data + off2;
+ off2 += flow_item_spec_copy
+ (fd ? fd->data + off2 : NULL, item,
+ ITEM_LAST);
}
if (item->mask) {
if (fd)
- dst->mask = memcpy(fd->data + off2,
- item->mask, tmp);
- off2 += tmp + pad;
+ dst->mask = fd->data + off2;
+ off2 += flow_item_spec_copy
+ (fd ? fd->data + off2 : NULL, item,
+ ITEM_MASK);
}
off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
} while ((item++)->type != RTE_FLOW_ITEM_TYPE_END);
@@ -387,12 +447,11 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len,
dst = memcpy(fd->data + off1, action,
sizeof(*action));
off1 += sizeof(*action);
- flow_action_conf_size(action, &tmp, &pad);
if (action->conf) {
if (fd)
- dst->conf = memcpy(fd->data + off2,
- action->conf, tmp);
- off2 += tmp + pad;
+ dst->conf = fd->data + off2;
+ off2 += flow_action_conf_copy
+ (fd ? fd->data + off2 : NULL, action);
}
off2 = RTE_ALIGN_CEIL(off2, sizeof(double));
} while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
--
2.11.0
next prev parent reply other threads:[~2018-03-23 12:58 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20180323124725.15806-1-adrien.mazarguil@6wind.com>
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 1/9] net/mlx4: fix RSS resource leak in case of error Adrien Mazarguil
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 2/9] net/mlx4: fix ignored RSS hash types Adrien Mazarguil
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 3/9] app/testpmd: fix flow completion for RSS queues Adrien Mazarguil
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 4/9] app/testpmd: fix lack of flow action configuration Adrien Mazarguil
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 5/9] app/testpmd: fix RSS " Adrien Mazarguil
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 6/9] app/testpmd: fix missing RSS fields in flow action Adrien Mazarguil
2018-03-23 12:58 ` Adrien Mazarguil [this message]
2018-03-23 12:58 ` [dpdk-stable] [PATCH v1 8/9] ethdev: fix missing boolean values in flow command Adrien Mazarguil
[not found] ` <20180404144805.11966-1-adrien.mazarguil@6wind.com>
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 01/13] net/mlx4: fix RSS resource leak in case of error Adrien Mazarguil
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 02/13] net/mlx4: fix ignored RSS hash types Adrien Mazarguil
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 03/13] net/mlx5: fix RSS flow action bounds check Adrien Mazarguil
2018-04-05 6:57 ` Nélio Laranjeiro
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 04/13] net/bnxt: fix matching of flow API item masks Adrien Mazarguil
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 05/13] net/sfc: fix endian conversions in flow API Adrien Mazarguil
2018-04-04 15:30 ` Andrew Rybchenko
2018-04-04 16:08 ` Adrien Mazarguil
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 06/13] app/testpmd: fix flow completion for RSS queues Adrien Mazarguil
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 07/13] app/testpmd: fix lack of flow action configuration Adrien Mazarguil
2018-04-05 6:59 ` Nélio Laranjeiro
2018-04-04 14:57 ` [dpdk-stable] [PATCH v2 08/13] app/testpmd: fix RSS " Adrien Mazarguil
2018-04-05 7:39 ` Nélio Laranjeiro
2018-04-04 14:58 ` [dpdk-stable] [PATCH v2 09/13] app/testpmd: fix missing RSS fields in flow action Adrien Mazarguil
2018-04-05 8:15 ` Nélio Laranjeiro
2018-04-04 14:58 ` [dpdk-stable] [PATCH v2 10/13] ethdev: fix shallow copy of flow API RSS action Adrien Mazarguil
2018-04-04 14:58 ` [dpdk-stable] [PATCH v2 11/13] ethdev: fix missing boolean values in flow command Adrien Mazarguil
2018-04-05 8:17 ` Nélio Laranjeiro
2018-04-04 14:58 ` [dpdk-stable] [PATCH v2 13/13] ethdev: fix missing include in flow API Adrien Mazarguil
2018-04-05 8:18 ` Nélio Laranjeiro
[not found] ` <20180406131243.19037-1-adrien.mazarguil@6wind.com>
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 01/11] net/mlx4: fix RSS resource leak in case of error Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 02/11] net/mlx4: fix ignored RSS hash types Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 03/11] net/mlx5: fix RSS flow action bounds check Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 04/11] net/bnxt: fix matching of flow API item masks Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 05/11] app/testpmd: fix flow completion for RSS queues Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 06/11] app/testpmd: fix lack of flow action configuration Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 07/11] app/testpmd: fix RSS " Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 08/11] app/testpmd: fix missing RSS fields in flow action Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 09/11] ethdev: fix shallow copy of flow API RSS action Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 10/11] ethdev: fix missing boolean values in flow command Adrien Mazarguil
2018-04-06 13:22 ` [dpdk-stable] [PATCH v3 11/11] ethdev: fix missing include in flow API Adrien Mazarguil
[not found] ` <20180410161132.8776-1-adrien.mazarguil@6wind.com>
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 01/11] net/mlx4: fix RSS resource leak in case of error Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 02/11] net/mlx4: fix ignored RSS hash types Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 03/11] net/mlx5: fix RSS flow action bounds check Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 04/11] net/bnxt: fix matching of flow API item masks Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 05/11] app/testpmd: fix flow completion for RSS queues Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 06/11] app/testpmd: fix lack of flow action configuration Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 07/11] app/testpmd: fix RSS " Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 08/11] app/testpmd: fix missing RSS fields in flow action Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 09/11] ethdev: fix shallow copy of flow API RSS action Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 10/11] ethdev: fix missing boolean values in flow command Adrien Mazarguil
2018-04-10 16:34 ` [dpdk-stable] [PATCH v4 11/11] ethdev: fix missing include in flow API Adrien Mazarguil
[not found] ` <20180416150058.2620-1-adrien.mazarguil@6wind.com>
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 01/11] net/mlx4: fix RSS resource leak in case of error Adrien Mazarguil
2018-04-17 9:19 ` [dpdk-stable] [dpdk-dev] " Nélio Laranjeiro
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 02/11] net/mlx4: fix ignored RSS hash types Adrien Mazarguil
2018-04-17 9:20 ` [dpdk-stable] [dpdk-dev] " Nélio Laranjeiro
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 03/11] net/mlx5: fix RSS flow action bounds check Adrien Mazarguil
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 04/11] net/bnxt: fix matching of flow API item masks Adrien Mazarguil
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 05/11] app/testpmd: fix flow completion for RSS queues Adrien Mazarguil
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 06/11] app/testpmd: fix lack of flow action configuration Adrien Mazarguil
2018-04-16 16:21 ` [dpdk-stable] [PATCH v5 07/11] app/testpmd: fix RSS " Adrien Mazarguil
2018-04-16 16:22 ` [dpdk-stable] [PATCH v5 08/11] app/testpmd: fix missing RSS fields in flow action Adrien Mazarguil
2018-04-16 16:22 ` [dpdk-stable] [PATCH v5 09/11] ethdev: fix shallow copy of flow API RSS action Adrien Mazarguil
2018-04-17 9:18 ` Nélio Laranjeiro
2018-04-16 16:22 ` [dpdk-stable] [PATCH v5 10/11] ethdev: fix missing boolean values in flow command Adrien Mazarguil
2018-04-16 19:17 ` [dpdk-stable] [dpdk-dev] " Matan Azrad
2018-04-17 8:25 ` Adrien Mazarguil
2018-04-18 17:16 ` Ferruh Yigit
2018-04-19 10:18 ` Adrien Mazarguil
2018-04-16 16:22 ` [dpdk-stable] [PATCH v5 11/11] ethdev: fix missing include in flow API Adrien Mazarguil
[not found] ` <20180419100204.5728-1-adrien.mazarguil@6wind.com>
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 01/11] net/mlx4: fix RSS resource leak in case of error Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 02/11] net/mlx4: fix ignored RSS hash types Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 03/11] net/mlx5: fix RSS flow action bounds check Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 04/11] net/bnxt: fix matching of flow API item masks Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 05/11] app/testpmd: fix flow completion for RSS queues Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 06/11] app/testpmd: fix lack of flow action configuration Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 07/11] app/testpmd: fix RSS " Adrien Mazarguil
2018-05-07 5:23 ` [dpdk-stable] [dpdk-dev] " Peng, Yuan
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 08/11] app/testpmd: fix missing RSS fields in flow action Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 09/11] app/testpmd: fix missing boolean values in flow command Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 10/11] ethdev: fix shallow copy of flow API RSS action Adrien Mazarguil
2018-04-19 10:07 ` [dpdk-stable] [PATCH v6 11/11] ethdev: fix missing include in flow API Adrien Mazarguil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180323124725.15806-8-adrien.mazarguil@6wind.com \
--to=adrien.mazarguil@6wind.com \
--cc=dev@dpdk.org \
--cc=gaetan.rivet@6wind.com \
--cc=stable@dpdk.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).