Skip to contentSkip to conversation

examples/ipsec-secgw: fix cryptodev to SA mapping

PATCH Superseded Radu Nicolau 7 participants 15 messages Dec 11, 2023 – Mar 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/ipsec-secgw: fix cryptodev to SA mapping

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")
---
 examples/ipsec-secgw/ipsec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c +8 -5
index f5cec4a928..593eab4e73 100644
@@ -288,10 +288,9 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			RTE_LOG(WARNING, IPSEC,
+				"SA mapped to multiple cryptodevs for SPI %d\n",
+				sa->spi);
 		}
 
 		/* Store per core queue pair information */
@@ -908,7 +907,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
 			continue;
 		}
 
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (sa->cqp[ipsec_ctx->lcore_id])
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);
 	}
 }
 
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw
Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")
---
 examples/ipsec-secgw/ipsec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c +3 -4
@@ -288,10 +288,9 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			RTE_LOG(WARNING, IPSEC,
+				"SA mapped to multiple cryptodevs for SPI %d\n",
+				sa->spi);
 		}
 
 		/* Store per core queue pair information */ @@ -908,7 +907,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,

continue;
}

- enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+ if (sa->cqp[ipsec_ctx->lcore_id])
+ enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+ else
+ RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+ ipsec_ctx->lcore_id);
}
}

--
2.25.1

-----Original Message-----
From: Nicolau, Radu <[email protected]>
Sent: Monday, December 11, 2023 5:54 PM
To: Nicolau, Radu <[email protected]>; Akhil Goyal <[email protected]>
Cc: [email protected]; Power, Ciara <[email protected]>; Ku, Ting-Kai <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] examples/ipsec-secgw: fix cryptodev to SA mapping

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function.
Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")
---
 examples/ipsec-secgw/ipsec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c +3 -4
@@ -288,10 +288,9 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			RTE_LOG(WARNING, IPSEC,
+				"SA mapped to multiple cryptodevs for SPI %d\n",
+				sa->spi);
 		}
 
 		/* Store per core queue pair information */ @@ -908,7 +907,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,

continue;
}

- enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+ if (sa->cqp[ipsec_ctx->lcore_id])
+ enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+ else
+ RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+ ipsec_ctx->lcore_id);
}
}

--
2.25.1

Acked-by on v1 1/1
#2 lore raw
In reply to Radu Nicolau

Hi Radu,

Quoted 16 lines

-----Original Message-----
From: Nicolau, Radu <[email protected]>
Sent: Monday, December 11, 2023 9:54 AM
To: Nicolau, Radu <[email protected]>; Akhil Goyal <[email protected]>
Cc: [email protected]; Power, Ciara <[email protected]>; Ku, Ting-Kai <ting- [email protected]>; [email protected]; [email protected]
Subject: [PATCH] examples/ipsec-secgw: fix cryptodev to SA mapping

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function.
Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at
Quoted 8 lines

init")
Cc: [email protected]
Cc: [email protected]

---
 examples/ipsec-secgw/ipsec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
Acked-by on v1 1/1
#3 lore raw
In reply to Radu Nicolau

________________________________
From: Radu Nicolau <[email protected]>
Sent: 11 December 2023 09:53
To: Nicolau, Radu <[email protected]>; Akhil Goyal <[email protected]>
Cc: [email protected] <[email protected]>; Power, Ciara <[email protected]>; Ku, Ting-Kai <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: [PATCH] examples/ipsec-secgw: fix cryptodev to SA mapping

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---

--
2.25.1

#4 lore raw
In reply to Radu Nicolau

examples/ipsec-secgw/ipsec.c ipsec_enqueue(ipsec_xform_fn xform_func, struct · line 915

Quoted 11 lines
examples/ipsec-secgw/ipsec.c +5 -1
@@ -908,7 +907,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct
 ipsec_ctx *ipsec_ctx,
 			continue;
 		}
 
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (sa->cqp[ipsec_ctx->lcore_id])
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);

Can we add likely here?

#5 lore raw

PATCH v2 1/1 examples/ipsec-secgw: fix cryptodev to SA mapping

In reply to Radu Nicolau

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---
v2: add likely to CQP available branch

 examples/ipsec-secgw/ipsec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c +8 -5
index f5cec4a928..7bb9646736 100644
@@ -288,10 +288,9 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			RTE_LOG(WARNING, IPSEC,
+				"SA mapped to multiple cryptodevs for SPI %d\n",
+				sa->spi);
 		}
 
 		/* Store per core queue pair information */
@@ -908,7 +907,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
 			continue;
 		}
 
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);
 	}
 }
 
Signature · 1 line
2.34.1
#6 lore raw

Hi Radu,

Using same session across multiple devices would only work if the device instances are same. For example, if you use QAT device 0 & QAT device 1, then the sharing is okay. But if we have QAT and some SW crypto PMD, then the same session will not work. Is it possible to throw a warning when the crypto devices are not of same type?

Thanks,
Anoob

Quoted 69 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Friday, February 23, 2024 4:31 PM
To: [email protected]
Cc: Radu Nicolau <[email protected]>; [email protected]; Volodymyr Fialko <[email protected]>; Ting-Kai Ku <[email protected]>; Ciara Power <[email protected]>; Kai Ji <[email protected]>; Akhil Goyal <[email protected]>
Subject: [EXT] [PATCH v2] examples/ipsec-secgw: fix cryptodev to SA mapping

External Email

----------------------------------------------------------------------
There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---
v2: add likely to CQP available branch

 examples/ipsec-secgw/ipsec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c index renamed from examples/ipsec-secgw/ipsec.c +0 -0

f5cec4a928..7bb9646736 100644

examples/ipsec-secgw/ipsec.c +3 -4
@@ -288,10 +288,9 @@ create_lookaside_session(struct ipsec_ctx
 *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			RTE_LOG(WARNING, IPSEC,
+				"SA mapped to multiple cryptodevs for SPI
 %d\n",
+				sa->spi);
 		}

/* Store per core queue pair information */ @@ -908,7 +907,11
@@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,

examples/ipsec-secgw/ipsec.c +5 -2
 			continue;
 		}
 
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);
 	}
 }
 
--

2.34.1

#7 lore raw

PATCH v3 1/1 examples/ipsec-secgw: fix cryptodev to SA mapping

In reply to Radu Nicolau

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---
v3: check if the cryptodev are not of the same type

 examples/ipsec-secgw/ipsec.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c +20 -5
index f5cec4a928..b59576c049 100644
@@ -288,10 +288,21 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			struct rte_cryptodev_info dev_info_1, dev_info_2;
+			rte_cryptodev_info_get(cdev_id, &dev_info_1);
+			rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
+					&dev_info_2);
+			if (dev_info_1.driver_id == dev_info_2.driver_id) {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs for SPI %d\n",
+					sa->spi);
+
+			} else {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs of different types for SPI %d\n",
+					sa->spi);
+
+			}
 		}
 
 		/* Store per core queue pair information */
@@ -908,7 +919,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
 			continue;
 		}
 
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);
 	}
 }
 
Signature · 1 line
2.34.1
#8 lore raw

Recheck-request: iol-broadcom-Performance

This patch should not fail a performance test in CI - checking with a rerun now.

Quoted 78 lines · Radu Nicolau

There are use cases where a SA should be able to use different cryptodevs on
different lcores, for example there can be cryptodevs with just 1 qp per VF.
For this purpose this patch relaxes the check in create lookaside session function.
Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at

init")
Cc: [email protected]
Cc: [email protected]

---
v3: check if the cryptodev are not of the same type

 examples/ipsec-secgw/ipsec.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c +0 -2
index f5cec4a928..b59576c049 100644
@@ -288,10 +288,21 @@ create_lookaside_session(struct ipsec_ctx
 *ipsec_ctx_lcore[],
                if (cdev_id == RTE_CRYPTO_MAX_DEVS)
                        cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
                else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-                       RTE_LOG(ERR, IPSEC,
-                                       "SA mapping to multiple cryptodevs

is "

examples/ipsec-secgw/ipsec.c +7 -2
-                                       "not supported!");
-                       return -EINVAL;
+                       struct rte_cryptodev_info dev_info_1, dev_info_2;
+                       rte_cryptodev_info_get(cdev_id, &dev_info_1);
+
 rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
+                                       &dev_info_2);
+                       if (dev_info_1.driver_id == dev_info_2.driver_id) {
+                               RTE_LOG(WARNING, IPSEC,
+                                       "SA mapped to multiple cryptodevs

for SPI %d\n",

examples/ipsec-secgw/ipsec.c +5 -0
+                                       sa->spi);
+
+                       } else {
+                               RTE_LOG(WARNING, IPSEC,
+                                       "SA mapped to multiple cryptodevs

of different types for SPI %d\n",

examples/ipsec-secgw/ipsec.c +8 -1
+                                       sa->spi);
+
+                       }
                }
 
                /* Store per core queue pair information */
@@ -908,7 +919,11 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct
 ipsec_ctx *ipsec_ctx,
                        continue;
                }
 
-               enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+               if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+                       enqueue_cop(sa->cqp[ipsec_ctx->lcore_id],
 &priv->cop);
+               else
+                       RTE_LOG(ERR, IPSEC, "No CQP available for lcore
 %d\n",
+                                       ipsec_ctx->lcore_id);
        }

}

--
2.34.1

#9 lore raw
In reply to Radu Nicolau

Hi Radu,

Thanks for making the changes. I've one more question. Please see inline.

Thanks,
Anoob

Quoted 67 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Monday, February 26, 2024 3:56 PM
To: [email protected]
Cc: Anoob Joseph <[email protected]>; Radu Nicolau <[email protected]>; [email protected]; Volodymyr Fialko <[email protected]>; Ting-Kai Ku <[email protected]>; Ciara Power <[email protected]>; Kai Ji <[email protected]>; Akhil Goyal <[email protected]>
Subject: [EXT] [PATCH v3] examples/ipsec-secgw: fix cryptodev to SA mapping

External Email

----------------------------------------------------------------------
There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---
v3: check if the cryptodev are not of the same type

 examples/ipsec-secgw/ipsec.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c index renamed from examples/ipsec-secgw/ipsec.c +0 -0

f5cec4a928..b59576c049 100644

examples/ipsec-secgw/ipsec.c +15 -4
@@ -288,10 +288,21 @@ create_lookaside_session(struct ipsec_ctx
 *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			struct rte_cryptodev_info dev_info_1, dev_info_2;
+			rte_cryptodev_info_get(cdev_id, &dev_info_1);
+			rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
+					&dev_info_2);
+			if (dev_info_1.driver_id == dev_info_2.driver_id) {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs for
 SPI %d\n",
+					sa->spi);
+
+			} else {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs of
 different types for SPI %d\n",
+					sa->spi);
+
+			}
examples/ipsec-secgw/ipsec.c +0 -0
 		}
 
 		/* Store per core queue pair information */ @@ -908,7 +919,11

@@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,

examples/ipsec-secgw/ipsec.c ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx, · line 926

Quoted 9 lines
examples/ipsec-secgw/ipsec.c +5 -1
 			continue;
 		}
 
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);

[Anoob] Throwing an error won't be good enough, right? Won't this lead to packet leaks? Since it is datapath, can't we assume that the configuration would be done correctly in control path?

I would suggest drop this specific change and we can enable multiple cryptodevs with lookaside SAs with the changes proposed.

Quoted 5 lines

}
}

--
2.34.1

#10 lore raw

Hi Anoob, reply inline.

Regards,

Radu

Quoted 85 lines · Anoob Joseph

Hi Radu,

Thanks for making the changes. I've one more question. Please see inline.

Thanks,
Anoob

Quoted 70 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Monday, February 26, 2024 3:56 PM
To: [email protected]
Cc: Anoob Joseph <[email protected]>; Radu Nicolau <[email protected]>; [email protected]; Volodymyr Fialko <[email protected]>; Ting-Kai Ku <[email protected]>; Ciara Power <[email protected]>; Kai Ji <[email protected]>; Akhil Goyal <[email protected]>
Subject: [EXT] [PATCH v3] examples/ipsec-secgw: fix cryptodev to SA mapping

External Email

----------------------------------------------------------------------
There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---
v3: check if the cryptodev are not of the same type

  examples/ipsec-secgw/ipsec.c | 25 ++++++++++++++++++++-----
  1 file changed, 20 insertions(+), 5 deletions(-)
examples/ipsec-secgw/ipsec.c index renamed from examples/ipsec-secgw/ipsec.c +0 -0

f5cec4a928..b59576c049 100644

examples/ipsec-secgw/ipsec.c +15 -4
@@ -288,10 +288,21 @@ create_lookaside_session(struct ipsec_ctx
 *ipsec_ctx_lcore[],
  		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
  			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
  		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			struct rte_cryptodev_info dev_info_1, dev_info_2;
+			rte_cryptodev_info_get(cdev_id, &dev_info_1);
+			rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
+					&dev_info_2);
+			if (dev_info_1.driver_id == dev_info_2.driver_id) {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs for
 SPI %d\n",
+					sa->spi);
+
+			} else {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs of
 different types for SPI %d\n",
+					sa->spi);
+
+			}
  		}

/* Store per core queue pair information */ @@ -908,7 +919,11
@@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
continue;
}

examples/ipsec-secgw/ipsec.c ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx, · line 926

Quoted 6 lines
examples/ipsec-secgw/ipsec.c +5 -1
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore %d\n",
+					ipsec_ctx->lcore_id);

[Anoob] Throwing an error won't be good enough, right? Won't this lead to packet leaks? Since it is datapath, can't we assume that the configuration would be done correctly in control path?

Quoted 1 line

I would suggest drop this specific change and we can enable multiple cryptodevs with lookaside SAs with the changes proposed.

With the change that removed the lazy initialization of SAs ("examples/ipsec-secgw: create lookaside sessions at init") we can't assume anymore that a worker core has the proper CQP assigned, that is the reason I added the check here, the control path had no errors but there was no CQP assigned to a lcore. Indeed there will be dropped packets but at least there will be no segfault and the user will have an indication on what needs to be done - assign more cryptodevs.

Quoted 5 lines
Quoted 5 lines
  	}
  }

--
2.34.1

#11 lore raw

Hi Radu,

Please see inline.

Thanks,
Anoob

Quoted 115 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Tuesday, February 27, 2024 3:41 PM
To: Anoob Joseph <[email protected]>
Cc: [email protected]; Volodymyr Fialko <[email protected]>; Ting-Kai Ku <[email protected]>; Ciara Power <[email protected]>; Kai Ji <[email protected]>; Akhil Goyal <[email protected]>; [email protected]
Subject: Re: [EXT] [PATCH v3] examples/ipsec-secgw: fix cryptodev to SA mapping

Hi Anoob, reply inline.

Regards,

Radu

Quoted 26 lines · Anoob Joseph

Hi Radu,

Thanks for making the changes. I've one more question. Please see inline.

Thanks,
Anoob

Quoted 19 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Monday, February 26, 2024 3:56 PM
To: [email protected]
Cc: Anoob Joseph <[email protected]>; Radu Nicolau <[email protected]>; [email protected]; Volodymyr Fialko <[email protected]>; Ting-Kai Ku <[email protected]>; Ciara Power <[email protected]>; Kai Ji <[email protected]>; Akhil Goyal <[email protected]>
Subject: [EXT] [PATCH v3] examples/ipsec-secgw: fix cryptodev to SA mapping

External Email

---------------------------------------------------------------------
- There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF.
For this purpose this patch relaxes the check in create lookaside session

function.

Quoted 17 lines
Quoted 17 lines

Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions

at init")
Cc: [email protected]
Cc: [email protected]

---
v3: check if the cryptodev are not of the same type

  examples/ipsec-secgw/ipsec.c | 25 ++++++++++++++++++++-----
  1 file changed, 20 insertions(+), 5 deletions(-)
Quoted 12 lines

examples/ipsec-secgw/ipsec.c create_lookaside_session(struct ipsec_ctx · line 293

Quoted 12 lines
(quoted diff) +0 -0

b/examples/ipsec-secgw/ipsec.c index
f5cec4a928..b59576c049 100644

examples/ipsec-secgw/ipsec.c +0 -2
@@ -288,10 +288,21 @@ create_lookaside_session(struct ipsec_ctx
 *ipsec_ctx_lcore[],
  		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
  			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
  		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is

"

Quoted 9 lines

examples/ipsec-secgw/ipsec.c create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],

Quoted 9 lines
examples/ipsec-secgw/ipsec.c +7 -2
-					"not supported!");
-			return -EINVAL;
+			struct rte_cryptodev_info dev_info_1, dev_info_2;
+			rte_cryptodev_info_get(cdev_id, &dev_info_1);
+			rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
+					&dev_info_2);
+			if (dev_info_1.driver_id == dev_info_2.driver_id) {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs

for

Quoted 12 lines
Quoted 12 lines
examples/ipsec-secgw/ipsec.c +8 -0
 SPI %d\n",
+					sa->spi);
+
+			} else {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs of
 different types for SPI %d\n",
+					sa->spi);
+
+			}
  		}
Quoted 1 line
Quoted 1 line

/* Store per core queue pair information */ @@ -908,7

+919,11 @@

Quoted 10 lines

examples/ipsec-secgw/ipsec.c ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,

Quoted 7 lines

ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
continue;
}

examples/ipsec-secgw/ipsec.c +2 -1
-		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
+		if (likely(sa->cqp[ipsec_ctx->lcore_id]))
+			enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv-

cop);

examples/ipsec-secgw/ipsec.c

Quoted 2 lines
examples/ipsec-secgw/ipsec.c +2 -0
+		else
+			RTE_LOG(ERR, IPSEC, "No CQP available for lcore

%d\n",

Quoted 2 lines

examples/ipsec-secgw/ipsec.c ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx, · line 926

Quoted 1 line
examples/ipsec-secgw/ipsec.c +1 -0
+					ipsec_ctx->lcore_id);

[Anoob] Throwing an error won't be good enough, right? Won't this lead to

packet leaks? Since it is datapath, can't we assume that the configuration would be done correctly in control path?

Quoted 2 lines

I would suggest drop this specific change and we can enable multiple

Quoted 8 lines

cryptodevs with lookaside SAs with the changes proposed.
With the change that removed the lazy initialization of SAs ("examples/ipsec-secgw: create lookaside sessions at init") we can't assume anymore that a worker core has the proper CQP assigned, that is the reason I added the check here, the control path had no errors but there was no CQP assigned to a lcore. Indeed there will be dropped packets but at least there will be no segfault and the user will have an indication on what needs to be done - assign more cryptodevs.

[Anoob] I understand your concern. I was just worried about an extra check coming in data path which can impact performance benchmarks with valid configuration. Can we keep the check under a debug flag? Is that okay?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
  	}
  }

--
2.34.1

#12 lore raw

PATCH v4 1/1 examples/ipsec-secgw: fix cryptodev to SA mapping

In reply to Radu Nicolau

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function. Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at init")

---
v4: replaced plain if with RTE_ASSERT

 examples/ipsec-secgw/ipsec.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
examples/ipsec-secgw/ipsec.c +16 -4
index f5cec4a928..c321108119 100644
@@ -288,10 +288,21 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[],
 		if (cdev_id == RTE_CRYPTO_MAX_DEVS)
 			cdev_id = ipsec_ctx->tbl[cdev_id_qp].id;
 		else if (cdev_id != ipsec_ctx->tbl[cdev_id_qp].id) {
-			RTE_LOG(ERR, IPSEC,
-					"SA mapping to multiple cryptodevs is "
-					"not supported!");
-			return -EINVAL;
+			struct rte_cryptodev_info dev_info_1, dev_info_2;
+			rte_cryptodev_info_get(cdev_id, &dev_info_1);
+			rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
+					&dev_info_2);
+			if (dev_info_1.driver_id == dev_info_2.driver_id) {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs for SPI %d\n",
+					sa->spi);
+
+			} else {
+				RTE_LOG(WARNING, IPSEC,
+					"SA mapped to multiple cryptodevs of different types for SPI %d\n",
+					sa->spi);
+
+			}
 		}
 
 		/* Store per core queue pair information */
@@ -908,6 +919,7 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
 			continue;
 		}
 
+		RTE_ASSERT(sa->cqp[ipsec_ctx->lcore_id] != NULL);
 		enqueue_cop(sa->cqp[ipsec_ctx->lcore_id], &priv->cop);
 	}
 }
Signature · 1 line
2.34.1
Acked-by on v4 1/1
#13 lore raw
Quoted 9 lines

----------------------------------------------------------------------
There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function.
Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at
Quoted 8 lines

init")
Cc: [email protected]
Cc: [email protected]

Applied
#14 lore raw
Quoted 11 lines
Quoted 11 lines

There are use cases where a SA should be able to use different cryptodevs on different lcores, for example there can be cryptodevs with just 1 qp per VF. For this purpose this patch relaxes the check in create lookaside session function.
Also add a check to verify that a CQP is available for the current lcore.

Fixes a8ade12123c3 ("examples/ipsec-secgw: create lookaside sessions at

init")
Cc: [email protected]
Cc: [email protected]

Quoted 7 lines
Quoted 4 lines

Applied to dpdk-next-crypto
Thanks.