All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: fix: flow validation
@ 2018-05-02 14:42 Nelio Laranjeiro
  2018-05-03  7:07 ` [dpdk-stable] " Shahaf Shuler
  2018-05-03  9:31 ` [PATCH v2] net/mlx5: fix " Nelio Laranjeiro
  0 siblings, 2 replies; 5+ messages in thread
From: Nelio Laranjeiro @ 2018-05-02 14:42 UTC (permalink / raw)
  To: dev, Adrien Mazarguil, Yongseok Koh; +Cc: stable

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>
---
 drivers/net/mlx5/mlx5_flow.c | 73 +++++++++++-------------------------
 1 file changed, 22 insertions(+), 51 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 129311d50..5d4995783 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -555,60 +555,31 @@ 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;
+	for (i = 0; i < size; i++) {
+		if (spec)
+			if (((spec[i] & m[i]) | mask[i]) != mask[i])
+				goto error;
+		if (last)
+			if ((((last[i] & m[i]) | mask[i]) != mask[i]) ||
+			    ((spec[i] & m[i]) != (last[i] & m[i])))
+				goto error;
+		if (m)
+			if ((m[i] | mask[i]) != mask[i])
+				goto error;
 	}
 	return 0;
+error:
+	rte_errno = ENOTSUP;
+	return -rte_errno;
 }
 
 /**
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH] net/mlx5: fix: flow validation
  2018-05-02 14:42 [PATCH] net/mlx5: fix: flow validation Nelio Laranjeiro
@ 2018-05-03  7:07 ` Shahaf Shuler
  2018-05-03  9:23   ` Nélio Laranjeiro
  2018-05-03  9:31 ` [PATCH v2] net/mlx5: fix " Nelio Laranjeiro
  1 sibling, 1 reply; 5+ messages in thread
From: Shahaf Shuler @ 2018-05-03  7:07 UTC (permalink / raw)
  To: Nélio Laranjeiro, dev, Adrien Mazarguil, Yongseok Koh; +Cc: stable

Hi Nelio,

Wednesday, May 2, 2018 5:43 PM, Nelio Laranjeiro:
> Subject: [dpdk-stable] [PATCH] net/mlx5: fix: flow validation

The title is wrong the : after the fix should be removed. 

> 
> 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>
> ---
>  drivers/net/mlx5/mlx5_flow.c | 73 +++++++++++-------------------------
>  1 file changed, 22 insertions(+), 51 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
> index 129311d50..5d4995783 100644
> --- a/drivers/net/mlx5/mlx5_flow.c
> +++ b/drivers/net/mlx5/mlx5_flow.c
> @@ -555,60 +555,31 @@ 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;
> +	for (i = 0; i < size; i++) {


I think inline comment which explains what each code section below verifies would much help.

> +		if (spec)
> +			if (((spec[i] & m[i]) | mask[i]) != mask[i])
> +				goto error;

Am wondering. 
Which the below check of m ...

> +		if (last)
> +			if ((((last[i] & m[i]) | mask[i]) != mask[i]) ||
> +			    ((spec[i] & m[i]) != (last[i] & m[i])))
> +				goto error;
> +		if (m)
> +			if ((m[i] | mask[i]) != mask[i])
> +				goto error;

Do we really need to spec check? 
Meaning if above one passes it is guarantee m is contained in mask. And if so, then the spec check will always succeed. 


>  	}
>  	return 0;
> +error:
> +	rte_errno = ENOTSUP;
> +	return -rte_errno;
>  }
> 
>  /**
> --
> 2.17.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH] net/mlx5: fix: flow validation
  2018-05-03  7:07 ` [dpdk-stable] " Shahaf Shuler
@ 2018-05-03  9:23   ` Nélio Laranjeiro
  0 siblings, 0 replies; 5+ messages in thread
From: Nélio Laranjeiro @ 2018-05-03  9:23 UTC (permalink / raw)
  To: Shahaf Shuler; +Cc: dev, Adrien Mazarguil, Yongseok Koh, stable

On Thu, May 03, 2018 at 07:07:54AM +0000, Shahaf Shuler wrote:
> Hi Nelio,
> 
> Wednesday, May 2, 2018 5:43 PM, Nelio Laranjeiro:
> > Subject: [dpdk-stable] [PATCH] net/mlx5: fix: flow validation
> 
> The title is wrong the : after the fix should be removed. 

Right,

> > 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>
> > ---
>[...]
> > -			rte_errno = EINVAL;
> > -			return -rte_errno;
> > -		}
> > +	if (!spec && (item->mask || last))
> > +		goto error;
> > +	if (!spec)
> > +		return 0;
> > +	for (i = 0; i < size; i++) {
> 
> 
> I think inline comment which explains what each code section below
> verifies would much help.

Adding it,

> > +		if (spec)
> > +			if (((spec[i] & m[i]) | mask[i]) != mask[i])
> > +				goto error;
> 
> Am wondering. 
> Which the below check of m ...
> 
> > +		if (last)
> > +			if ((((last[i] & m[i]) | mask[i]) != mask[i]) ||
> > +			    ((spec[i] & m[i]) != (last[i] & m[i])))
> > +				goto error;
> > +		if (m)
> > +			if ((m[i] | mask[i]) != mask[i])
> > +				goto error;
> 
> Do we really need to spec check? 
> Meaning if above one passes it is guarantee m is contained in mask.
> And if so, then the spec check will always succeed. 

Indeed,

> >  	}
> >  	return 0;
> > +error:
> > +	rte_errno = ENOTSUP;
> > +	return -rte_errno;
> >  }
> > 
> >  /**
> > --
> > 2.17.0

I am making a v2 accordingly.
 
Thanks,

-- 
Nélio Laranjeiro
6WIND

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] net/mlx5: fix flow validation
  2018-05-02 14:42 [PATCH] net/mlx5: fix: flow validation Nelio Laranjeiro
  2018-05-03  7:07 ` [dpdk-stable] " Shahaf Shuler
@ 2018-05-03  9:31 ` Nelio Laranjeiro
  2018-05-03 10:40   ` [dpdk-stable] " Shahaf Shuler
  1 sibling, 1 reply; 5+ messages in thread
From: Nelio Laranjeiro @ 2018-05-03  9:31 UTC (permalink / raw)
  To: dev, Adrien Mazarguil, Yongseok Koh; +Cc: stable

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [PATCH v2] net/mlx5: fix flow validation
  2018-05-03  9:31 ` [PATCH v2] net/mlx5: fix " Nelio Laranjeiro
@ 2018-05-03 10:40   ` Shahaf Shuler
  0 siblings, 0 replies; 5+ messages in thread
From: Shahaf Shuler @ 2018-05-03 10:40 UTC (permalink / raw)
  To: Nélio Laranjeiro, dev, Adrien Mazarguil, Yongseok Koh; +Cc: stable

Thursday, May 3, 2018 12:32 PM, Nelio Laranjeiro:
> Subject: [dpdk-stable] [PATCH v2] net/mlx5: fix flow validation
> 
> 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>
> 

Applied to next-net-mlx. Thanks. 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-03 10:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-02 14:42 [PATCH] net/mlx5: fix: flow validation Nelio Laranjeiro
2018-05-03  7:07 ` [dpdk-stable] " Shahaf Shuler
2018-05-03  9:23   ` Nélio Laranjeiro
2018-05-03  9:31 ` [PATCH v2] net/mlx5: fix " Nelio Laranjeiro
2018-05-03 10:40   ` [dpdk-stable] " Shahaf Shuler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.