Skip to contentSkip to conversation

compressdev: fix end of comp PMD list macro conflict

PATCH Superseded Michael Baum 2 participants 11 messages Jan 1, 2023 – Feb 5, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compressdev: fix end of comp PMD list macro conflict

The "rte_compressdev_info_get()" function retrieves the contextual information of a device.
The output structure "dev_info" contains a list of devices supported capabilities for each supported algorithm.

In this function description, it says the element after the last valid element has op field set to "RTE_COMP_ALGO_LIST_END".
On the other hand, when this function used by "rte_compressdev_capability_get()" function, it uses "RTE_COMP_ALGO_UNSPECIFIED" as end of list as same as the "RTE_COMP_END_OF_CAPABILITIES_LIST()".

The mlx5 and qat PMDs use "RTE_COMP_ALGO_LIST_END" as the end of capabilities list. When "rte_compressdev_capability_get()" function is called with unsupported algorithm, it might read memory out of bound.

This patch change the "rte_compressdev_info_get()" function description to say using "RTE_COMP_ALGO_UNSPECIFIED" as the end of capabilities list.
In addition, it moves both mlx5 and qat PMDs to use "RTE_COMP_ALGO_UNSPECIFIED" through "RTE_COMP_END_OF_CAPABILITIES_LIST()" macro.

Fixes 5d432f364078 ("compressdev: add device capabilities")
Fixes 2d148597ce76 ("compress/qat: add gen-specific implementation")
Fixes 384bac8d6555 ("compress/mlx5: add supported capabilities")

---

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

 drivers/compress/mlx5/mlx5_compress.c        | 4 +---
 drivers/compress/qat/dev/qat_comp_pmd_gen1.c | 2 +-
 drivers/compress/qat/dev/qat_comp_pmd_gen4.c | 2 +-
 lib/compressdev/rte_compressdev.h            | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/compress/mlx5/mlx5_compress.c +1 -3
index fb2bda9745..459e4b5e8a 100644
@@ -96,9 +96,7 @@ static const struct rte_compressdev_capabilities mlx5_caps[] = {
 				      RTE_COMP_FF_HUFFMAN_DYNAMIC,
 		.window_size = {.min = 10, .max = 15, .increment = 1},
 	},
-	{
-		.algo = RTE_COMP_ALGO_LIST_END,
-	}
+	RTE_COMP_END_OF_CAPABILITIES_LIST()
 };
 
 static void
drivers/compress/qat/dev/qat_comp_pmd_gen1.c +1 -1
index 12d9d89072..3a8484eef1 100644
@@ -26,7 +26,7 @@ const struct rte_compressdev_capabilities qat_gen1_comp_capabilities[] = {
 				RTE_COMP_FF_OOP_LB_IN_SGL_OUT |
 				RTE_COMP_FF_STATEFUL_DECOMPRESSION,
 	 .window_size = {.min = 15, .max = 15, .increment = 0} },
-	{RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+	 RTE_COMP_END_OF_CAPABILITIES_LIST() };
 
 static int
 qat_comp_dev_config_gen1(struct rte_compressdev *dev,
drivers/compress/qat/dev/qat_comp_pmd_gen4.c +1 -1
index 79b2ceb414..05906f13e0 100644
@@ -25,7 +25,7 @@ qat_gen4_comp_capabilities[] = {
 				RTE_COMP_FF_OOP_SGL_IN_LB_OUT |
 				RTE_COMP_FF_OOP_LB_IN_SGL_OUT,
 	 .window_size = {.min = 15, .max = 15, .increment = 0} },
-	{RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+	 RTE_COMP_END_OF_CAPABILITIES_LIST() };
 
 static int
 qat_comp_dev_config_gen4(struct rte_compressdev *dev,
lib/compressdev/rte_compressdev.h +1 -1
index 42bda9fc79..7eb5c58798 100644
@@ -353,7 +353,7 @@ rte_compressdev_stats_reset(uint8_t dev_id);
  * @note The capabilities field of dev_info is set to point to the first
  * element of an array of struct rte_compressdev_capabilities.
  * The element after the last valid element has it's op field set to
- * RTE_COMP_ALGO_LIST_END.
+ * RTE_COMP_ALGO_UNSPECIFIED.
  */
 __rte_experimental
 void
Signature · 1 line
2.25.1
#1 lore raw

Hi All, any comments?

From: Michael Baum <[email protected]>

Quoted 112 lines

The "rte_compressdev_info_get()" function retrieves the contextual information of a device.
The output structure "dev_info" contains a list of devices supported capabilities for each supported algorithm.

In this function description, it says the element after the last valid element has op field set to "RTE_COMP_ALGO_LIST_END".
On the other hand, when this function used by "rte_compressdev_capability_get()" function, it uses "RTE_COMP_ALGO_UNSPECIFIED" as end of list as same as the "RTE_COMP_END_OF_CAPABILITIES_LIST()".

The mlx5 and qat PMDs use "RTE_COMP_ALGO_LIST_END" as the end of capabilities list. When "rte_compressdev_capability_get()" function is called with unsupported algorithm, it might read memory out of bound.

This patch change the "rte_compressdev_info_get()" function description to say using "RTE_COMP_ALGO_UNSPECIFIED" as the end of capabilities list. In addition, it moves both mlx5 and qat PMDs to use "RTE_COMP_ALGO_UNSPECIFIED" through "RTE_COMP_END_OF_CAPABILITIES_LIST()" macro.

Fixes 5d432f364078 ("compressdev: add device capabilities")
Fixes 2d148597ce76 ("compress/qat: add gen-specific implementation")
Fixes 384bac8d6555 ("compress/mlx5: add supported capabilities")

---

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

 drivers/compress/mlx5/mlx5_compress.c        | 4 +---
 drivers/compress/qat/dev/qat_comp_pmd_gen1.c | 2 +-
drivers/compress/qat/dev/qat_comp_pmd_gen4.c | 2 +-
 lib/compressdev/rte_compressdev.h            | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/compress/mlx5/mlx5_compress.c +1 -3
index fb2bda9745..459e4b5e8a 100644
@@ -96,9 +96,7 @@ static const struct rte_compressdev_capabilities
 mlx5_caps[] = {
                                      RTE_COMP_FF_HUFFMAN_DYNAMIC,
                .window_size = {.min = 10, .max = 15, .increment = 1},
        },
-       {
-               .algo = RTE_COMP_ALGO_LIST_END,
-       }
+       RTE_COMP_END_OF_CAPABILITIES_LIST()
 };
 

static void

drivers/compress/qat/dev/qat_comp_pmd_gen1.c +1 -1
index 12d9d89072..3a8484eef1 100644
@@ -26,7 +26,7 @@ const struct rte_compressdev_capabilities
 qat_gen1_comp_capabilities[] = {
                                RTE_COMP_FF_OOP_LB_IN_SGL_OUT |
                                RTE_COMP_FF_STATEFUL_DECOMPRESSION,
         .window_size = {.min = 15, .max = 15, .increment = 0} },
-       {RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+        RTE_COMP_END_OF_CAPABILITIES_LIST() };
 
 static int

qat_comp_dev_config_gen1(struct rte_compressdev *dev, diff --git
a/drivers/compress/qat/dev/qat_comp_pmd_gen4.c b/drivers/compress/qat/dev/qat_comp_pmd_gen4.c
index 79b2ceb414..05906f13e0 100644

drivers/compress/qat/dev/qat_comp_pmd_gen4.c +1 -1
@@ -25,7 +25,7 @@ qat_gen4_comp_capabilities[] = {
                                RTE_COMP_FF_OOP_SGL_IN_LB_OUT |
                                RTE_COMP_FF_OOP_LB_IN_SGL_OUT,
         .window_size = {.min = 15, .max = 15, .increment = 0} },
-       {RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+        RTE_COMP_END_OF_CAPABILITIES_LIST() };
 
 static int
 qat_comp_dev_config_gen4(struct rte_compressdev *dev, diff --git

a/lib/compressdev/rte_compressdev.h b/lib/compressdev/rte_compressdev.h index 42bda9fc79..7eb5c58798 100644

lib/compressdev/rte_compressdev.h +1 -2
@@ -353,7 +353,7 @@ rte_compressdev_stats_reset(uint8_t dev_id);
  * @note The capabilities field of dev_info is set to point to the first
  * element of an array of struct rte_compressdev_capabilities.
  * The element after the last valid element has it's op field set to
- * RTE_COMP_ALGO_LIST_END.
+ * RTE_COMP_ALGO_UNSPECIFIED.
  */
 __rte_experimental
 void
--

2.25.1

#2 lore raw
In reply to Michael Baum
Quoted 35 lines

The "rte_compressdev_info_get()" function retrieves the contextual information of a device.
The output structure "dev_info" contains a list of devices supported capabilities for each supported algorithm.

In this function description, it says the element after the last valid element has op field set to "RTE_COMP_ALGO_LIST_END".
On the other hand, when this function used by "rte_compressdev_capability_get()" function, it uses "RTE_COMP_ALGO_UNSPECIFIED" as end of list as same as the "RTE_COMP_END_OF_CAPABILITIES_LIST()".

The mlx5 and qat PMDs use "RTE_COMP_ALGO_LIST_END" as the end of capabilities list. When "rte_compressdev_capability_get()" function is called with unsupported algorithm, it might read memory out of bound.

This patch change the "rte_compressdev_info_get()" function description to say using "RTE_COMP_ALGO_UNSPECIFIED" as the end of capabilities list.
In addition, it moves both mlx5 and qat PMDs to use "RTE_COMP_ALGO_UNSPECIFIED" through "RTE_COMP_END_OF_CAPABILITIES_LIST()" macro.

Fixes 5d432f364078 ("compressdev: add device capabilities")
Fixes 2d148597ce76 ("compress/qat: add gen-specific implementation")
Fixes 384bac8d6555 ("compress/mlx5: add supported capabilities")

---

Quoted 9 lines

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

+1 to remove the list end enums. This will also help in avoiding ABI breakage When we make this lib as stable.

#3 lore raw
Quoted 44 lines

Subject: RE: [EXT] [PATCH] compressdev: fix end of comp PMD list macro conflict

Quoted 41 lines

The "rte_compressdev_info_get()" function retrieves the contextual information of a device.
The output structure "dev_info" contains a list of devices supported capabilities for each supported algorithm.

In this function description, it says the element after the last valid element has op field set to "RTE_COMP_ALGO_LIST_END".
On the other hand, when this function used by "rte_compressdev_capability_get()" function, it uses "RTE_COMP_ALGO_UNSPECIFIED" as end of list as same as the "RTE_COMP_END_OF_CAPABILITIES_LIST()".

The mlx5 and qat PMDs use "RTE_COMP_ALGO_LIST_END" as the end of capabilities list. When "rte_compressdev_capability_get()" function is called with unsupported algorithm, it might read memory out of bound.

This patch change the "rte_compressdev_info_get()" function description to say using "RTE_COMP_ALGO_UNSPECIFIED" as the end of capabilities list.
In addition, it moves both mlx5 and qat PMDs to use "RTE_COMP_ALGO_UNSPECIFIED" through "RTE_COMP_END_OF_CAPABILITIES_LIST()" macro.

Fixes 5d432f364078 ("compressdev: add device capabilities")
Fixes 2d148597ce76 ("compress/qat: add gen-specific implementation")
Fixes 384bac8d6555 ("compress/mlx5: add supported capabilities")

---

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Quoted 5 lines
Quoted 3 lines

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

+1 to remove the list end enums. This will also help in avoiding ABI breakage When we make this lib as stable.

Even RTE_COMP_HASH_ALGO_LIST_END can also be removed. It is not used anywhere.

#4 lore raw

Hi,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

+1 to remove the list end enums. This will also help in avoiding ABI breakage When we make this lib as stable.

Even RTE_COMP_HASH_ALGO_LIST_END can also be removed. It is not used anywhere.

Can you send a patch to remove these list end enums along with this patch?

-Akhil

#5 lore raw

Hi,

Quoted 13 lines

Hi,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+1 to remove the list end enums. This will also help in avoiding ABI +breakage
When we make this lib as stable.

Even RTE_COMP_HASH_ALGO_LIST_END can also be removed. It is not used anywhere.

Can you send a patch to remove these list end enums along with this patch?

In the same patch? Or add one?

Quoted 2 lines

-Akhil

#6 lore raw
Quoted 15 lines
Quoted 15 lines

Hi,

Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

After this change, I'm not sure about the purpose of "RTE_COMP_ALGO_LIST_END".
There is no any other use of it in DPDK code, and it isn't represent the number of algorithms supported by the API since the "RTE_COMP_ALGO_UNSPECIFIED" is part of the enum.

Due to the compress API is experimental I think the "RTE_COMP_ALGO_LIST_END" can be removed.

+1 to remove the list end enums. This will also help in avoiding ABI +breakage
When we make this lib as stable.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Even RTE_COMP_HASH_ALGO_LIST_END can also be removed. It is not used anywhere.

Can you send a patch to remove these list end enums along with this patch?

In the same patch? Or add one?

Separate patch would be better as the current patch is talking about a conflict. Removing the enums need not be backported, but this patch is required to be backported.

#7 lore raw

v2 cover compressdev: fix end of list enums conflict

In reply to Michael Baum

Handle the conflict about which enum value is used as end of list.

v2: add patch to remove useless list end enums.

Michael Baum (2):
compressdev: fix end of comp PMD list macro conflict
compressdev: remove useless list end enums

 drivers/compress/mlx5/mlx5_compress.c        | 4 +---
 drivers/compress/qat/dev/qat_comp_pmd_gen1.c | 2 +-
 drivers/compress/qat/dev/qat_comp_pmd_gen4.c | 2 +-
 lib/compressdev/rte_comp.h                   | 2 --
 lib/compressdev/rte_compressdev.h            | 2 +-
 5 files changed, 4 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 1/2 compressdev: fix end of comp PMD list macro conflict

The "rte_compressdev_info_get()" function retrieves the contextual information of a device.
The output structure "dev_info" contains a list of devices supported capabilities for each supported algorithm.

In this function description, it says the element after the last valid element has op field set to "RTE_COMP_ALGO_LIST_END".
On the other hand, when this function used by "rte_compressdev_capability_get()" function, it uses "RTE_COMP_ALGO_UNSPECIFIED" as end of list as same as the "RTE_COMP_END_OF_CAPABILITIES_LIST()".

The mlx5 and qat PMDs use "RTE_COMP_ALGO_LIST_END" as the end of capabilities list. When "rte_compressdev_capability_get()" function is called with unsupported algorithm, it might read memory out of bound.

This patch change the "rte_compressdev_info_get()" function description to say using "RTE_COMP_ALGO_UNSPECIFIED" as the end of capabilities list.
In addition, it moves both mlx5 and qat PMDs to use "RTE_COMP_ALGO_UNSPECIFIED" through "RTE_COMP_END_OF_CAPABILITIES_LIST()" macro.

Fixes 5d432f364078 ("compressdev: add device capabilities")
Fixes 2d148597ce76 ("compress/qat: add gen-specific implementation")
Fixes 384bac8d6555 ("compress/mlx5: add supported capabilities")
---
 drivers/compress/mlx5/mlx5_compress.c        | 4 +---
 drivers/compress/qat/dev/qat_comp_pmd_gen1.c | 2 +-
 drivers/compress/qat/dev/qat_comp_pmd_gen4.c | 2 +-
 lib/compressdev/rte_compressdev.h            | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/compress/mlx5/mlx5_compress.c +1 -3
index fb2bda9745..459e4b5e8a 100644
@@ -96,9 +96,7 @@ static const struct rte_compressdev_capabilities mlx5_caps[] = {
 				      RTE_COMP_FF_HUFFMAN_DYNAMIC,
 		.window_size = {.min = 10, .max = 15, .increment = 1},
 	},
-	{
-		.algo = RTE_COMP_ALGO_LIST_END,
-	}
+	RTE_COMP_END_OF_CAPABILITIES_LIST()
 };
 
 static void
drivers/compress/qat/dev/qat_comp_pmd_gen1.c +1 -1
index 12d9d89072..3a8484eef1 100644
@@ -26,7 +26,7 @@ const struct rte_compressdev_capabilities qat_gen1_comp_capabilities[] = {
 				RTE_COMP_FF_OOP_LB_IN_SGL_OUT |
 				RTE_COMP_FF_STATEFUL_DECOMPRESSION,
 	 .window_size = {.min = 15, .max = 15, .increment = 0} },
-	{RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+	 RTE_COMP_END_OF_CAPABILITIES_LIST() };
 
 static int
 qat_comp_dev_config_gen1(struct rte_compressdev *dev,
drivers/compress/qat/dev/qat_comp_pmd_gen4.c +1 -1
index 79b2ceb414..05906f13e0 100644
@@ -25,7 +25,7 @@ qat_gen4_comp_capabilities[] = {
 				RTE_COMP_FF_OOP_SGL_IN_LB_OUT |
 				RTE_COMP_FF_OOP_LB_IN_SGL_OUT,
 	 .window_size = {.min = 15, .max = 15, .increment = 0} },
-	{RTE_COMP_ALGO_LIST_END, 0, {0, 0, 0} } };
+	 RTE_COMP_END_OF_CAPABILITIES_LIST() };
 
 static int
 qat_comp_dev_config_gen4(struct rte_compressdev *dev,
lib/compressdev/rte_compressdev.h +1 -1
index 42bda9fc79..7eb5c58798 100644
@@ -353,7 +353,7 @@ rte_compressdev_stats_reset(uint8_t dev_id);
  * @note The capabilities field of dev_info is set to point to the first
  * element of an array of struct rte_compressdev_capabilities.
  * The element after the last valid element has it's op field set to
- * RTE_COMP_ALGO_LIST_END.
+ * RTE_COMP_ALGO_UNSPECIFIED.
  */
 __rte_experimental
 void
Signature · 1 line
2.25.1
#9 lore raw

PATCH v2 2/2 compressdev: remove useless list end enums

In reply to Michael Baum

The both "RTE_COMP_ALGO_LIST_END" and "RTE_COMP_HASH_ALGO_LIST_END" are useless. This patch removes them from the library.

---
 lib/compressdev/rte_comp.h | 2 --
 1 file changed, 2 deletions(-)
lib/compressdev/rte_comp.h +0 -2
index a8f398b57b..5bd711fda1 100644
@@ -109,7 +109,6 @@ enum rte_comp_algorithm {
 	/**< LZS compression algorithm
 	 * https://tools.ietf.org/html/rfc2395
 	 */
-	RTE_COMP_ALGO_LIST_END
 };
 
 /** Compression Hash Algorithms */
@@ -120,7 +119,6 @@ enum rte_comp_hash_algorithm {
 	/**< SHA1 hash algorithm */
 	RTE_COMP_HASH_ALGO_SHA2_256,
 	/**< SHA256 hash algorithm of SHA2 family */
-	RTE_COMP_HASH_ALGO_LIST_END
 };
 
 /**< Compression Level.
Signature · 1 line
2.25.1
#10 lore raw

RE: [EXT] [PATCH v2 0/2] compressdev: fix end of list enums conflict

In reply to Michael Baum
Quoted 8 lines

Handle the conflict about which enum value is used as end of list.

v2: add patch to remove useless list end enums.

Michael Baum (2):
compressdev: fix end of comp PMD list macro conflict
compressdev: remove useless list end enums

Quoted 7 lines
 drivers/compress/mlx5/mlx5_compress.c        | 4 +---
 drivers/compress/qat/dev/qat_comp_pmd_gen1.c | 2 +-
 drivers/compress/qat/dev/qat_comp_pmd_gen4.c | 2 +-
 lib/compressdev/rte_comp.h                   | 2 --
 lib/compressdev/rte_compressdev.h            | 2 +-
 5 files changed, 4 insertions(+), 8 deletions(-)

Series Acked-by: Akhil Goyal <[email protected]>
Applied to dpdk-next-crypto

Thanks.