From: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
To: dev@dpdk.org, Adrien Mazarguil <adrien.mazarguil@6wind.com>,
Yongseok Koh <yskoh@mellanox.com>
Cc: stable@dpdk.org
Subject: [dpdk-dev] [PATCH v2] net/mlx5: fix flow validation
Date: Thu, 3 May 2018 11:31:38 +0200 [thread overview]
Message-ID: <1adabe63b3dfc733aaad6e9b6e149da73e95c5db.1525339843.git.nelio.laranjeiro@6wind.com> (raw)
In-Reply-To: <efb6008e678ae09f6e899479296e8d1156d409e3.1525272061.git.nelio.laranjeiro@6wind.com>
Item spec and last are wrongly compared to the NIC capability causing a
validation failure when the mask is null.
This validation function should only verify the user is not configuring
unsupported matching fields.
Fixes: 2097d0d1e2cc ("net/mlx5: support basic flow items and actions")
Cc: stable@dpdk.org
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
Changes in v2:
- Simplify verification by testing only item->mask and item->last.
- add a comment to explain the loop verification.
---
drivers/net/mlx5/mlx5_flow.c | 77 ++++++++++++------------------------
1 file changed, 25 insertions(+), 52 deletions(-)
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 129311d50..38811bbce 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -538,7 +538,7 @@ struct ibv_spec_header {
};
/**
- * Check support for a given item.
+ * Check item is fully supported by the NIC matching capability.
*
* @param item[in]
* Item specification.
@@ -555,60 +555,33 @@ static int
mlx5_flow_item_validate(const struct rte_flow_item *item,
const uint8_t *mask, unsigned int size)
{
- if (!item->spec && (item->mask || item->last)) {
- rte_errno = EINVAL;
- return -rte_errno;
- }
- if (item->spec && !item->mask) {
- unsigned int i;
- const uint8_t *spec = item->spec;
-
- for (i = 0; i < size; ++i)
- if ((spec[i] | mask[i]) != mask[i]) {
- rte_errno = EINVAL;
- return -rte_errno;
- }
- }
- if (item->last && !item->mask) {
- unsigned int i;
- const uint8_t *spec = item->last;
-
- for (i = 0; i < size; ++i)
- if ((spec[i] | mask[i]) != mask[i]) {
- rte_errno = EINVAL;
- return -rte_errno;
- }
- }
- if (item->mask) {
- unsigned int i;
- const uint8_t *spec = item->spec;
-
- for (i = 0; i < size; ++i)
- if ((spec[i] | mask[i]) != mask[i]) {
- rte_errno = EINVAL;
- return -rte_errno;
- }
- }
- if (item->spec && item->last) {
- uint8_t spec[size];
- uint8_t last[size];
- const uint8_t *apply = mask;
- unsigned int i;
- int ret;
+ unsigned int i;
+ const uint8_t *spec = item->spec;
+ const uint8_t *last = item->last;
+ const uint8_t *m = item->mask ? item->mask : mask;
- if (item->mask)
- apply = item->mask;
- for (i = 0; i < size; ++i) {
- spec[i] = ((const uint8_t *)item->spec)[i] & apply[i];
- last[i] = ((const uint8_t *)item->last)[i] & apply[i];
- }
- ret = memcmp(spec, last, size);
- if (ret != 0) {
- rte_errno = EINVAL;
- return -rte_errno;
- }
+ if (!spec && (item->mask || last))
+ goto error;
+ if (!spec)
+ return 0;
+ /*
+ * Single-pass check to make sure that:
+ * - item->mask is supported, no bits are set outside mask.
+ * - Both masked item->spec and item->last are equal (no range
+ * supported).
+ */
+ for (i = 0; i < size; i++) {
+ if (!m[i])
+ continue;
+ if ((m[i] | mask[i]) != mask[i])
+ goto error;
+ if (last && ((spec[i] & m[i]) != (last[i] & m[i])))
+ goto error;
}
return 0;
+error:
+ rte_errno = ENOTSUP;
+ return -rte_errno;
}
/**
--
2.17.0
next prev parent reply other threads:[~2018-05-03 9:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 14:42 [dpdk-dev] [PATCH] net/mlx5: fix: " Nelio Laranjeiro
2018-05-03 7:07 ` [dpdk-dev] [dpdk-stable] " Shahaf Shuler
2018-05-03 9:23 ` Nélio Laranjeiro
2018-05-03 9:31 ` Nelio Laranjeiro [this message]
2018-05-03 10:40 ` [dpdk-dev] [dpdk-stable] [PATCH v2] net/mlx5: fix " Shahaf Shuler
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=1adabe63b3dfc733aaad6e9b6e149da73e95c5db.1525339843.git.nelio.laranjeiro@6wind.com \
--to=nelio.laranjeiro@6wind.com \
--cc=adrien.mazarguil@6wind.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=yskoh@mellanox.com \
/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).