diff mbox

ipsec: Fix ctx->state update race

Message ID C1BBCB674C57E643932FC661E0B0D46628B1EC2B@xmb-rcd-x01.cisco.com
State Accepted
Commit 8f03c614c3fa04273242721c6f847fa52d000262
Headers show

Commit Message

Robbie King Nov. 18, 2014, 3:27 p.m. UTC
Oops!  Good catch.  I looked and I don't see any other
manifestations. 

Reviewed-by: Robert King <robking@cisco.com>

Robbie.

-----Original Message-----
From: lng-odp-bounces@lists.linaro.org [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of Jerin Jacob
Sent: Friday, November 14, 2014 6:31 AM
To: lng-odp@lists.linaro.org
Subject: [lng-odp] [PATCH] ipsec: Fix ctx->state update race


In existing code, ctx->state of packet which received from ORDERED queue
has been updated after sending the packet to ATOMIC queue.
This creates a race  between "updating ctx->state from core x(ORDERED)" and
"reading stale ctx->state from core y(ATOMIC)"
In order to avoid the race, core x(ORDERED) should
update the ctx->state value before sending to ATOMIC queue.


Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
 example/ipsec/odp_ipsec.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Maxim Uvarov Nov. 18, 2014, 3:52 p.m. UTC | #1
Thanks! Merged!

Maxim.

On 11/18/2014 06:27 PM, Robbie King (robking) wrote:
> Oops!  Good catch.  I looked and I don't see any other
> manifestations.
>
> Reviewed-by: Robert King <robking@cisco.com>
>
> Robbie.
>
> -----Original Message-----
> From: lng-odp-bounces@lists.linaro.org [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of Jerin Jacob
> Sent: Friday, November 14, 2014 6:31 AM
> To: lng-odp@lists.linaro.org
> Subject: [lng-odp] [PATCH] ipsec: Fix ctx->state update race
>
>
> In existing code, ctx->state of packet which received from ORDERED queue
> has been updated after sending the packet to ATOMIC queue.
> This creates a race  between "updating ctx->state from core x(ORDERED)" and
> "reading stale ctx->state from core y(ATOMIC)"
> In order to avoid the race, core x(ORDERED) should
> update the ctx->state value before sending to ATOMIC queue.
>
>
> Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> ---
>   example/ipsec/odp_ipsec.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
> index da6c48e..37ad34d 100644
> --- a/example/ipsec/odp_ipsec.c
> +++ b/example/ipsec/odp_ipsec.c
> @@ -932,9 +932,7 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt,
>   	ctx->ipsec.esp_seq = &entry->state.esp_seq;
>   	memcpy(&ctx->ipsec.params, &params, sizeof(params));
>   
> -	/* Send packet to the atmoic queue to assign sequence numbers */
>   	*skip = FALSE;
> -	odp_queue_enq(seqnumq, odp_packet_to_buffer(pkt));
>   
>   	return PKT_POSTED;
>   }
> @@ -1108,9 +1106,12 @@ void *pktio_thread(void *arg ODP_UNUSED)
>   			case PKT_STATE_IPSEC_OUT_CLASSIFY:
>   
>   				rc = do_ipsec_out_classify(pkt, ctx, &skip);
> -				ctx->state = (skip) ?
> -					PKT_STATE_TRANSMIT :
> -					PKT_STATE_IPSEC_OUT_SEQ;
> +				if (odp_unlikely(skip)) {
> +					ctx->state = PKT_STATE_TRANSMIT;
> +				} else {
> +					ctx->state = PKT_STATE_IPSEC_OUT_SEQ;
> +					odp_queue_enq(seqnumq, buf);
> +				}
>   				break;
>   
>   			case PKT_STATE_IPSEC_OUT_SEQ:
diff mbox

Patch

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index da6c48e..37ad34d 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -932,9 +932,7 @@  pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt,
 	ctx->ipsec.esp_seq = &entry->state.esp_seq;
 	memcpy(&ctx->ipsec.params, &params, sizeof(params));
 
-	/* Send packet to the atmoic queue to assign sequence numbers */
 	*skip = FALSE;
-	odp_queue_enq(seqnumq, odp_packet_to_buffer(pkt));
 
 	return PKT_POSTED;
 }
@@ -1108,9 +1106,12 @@  void *pktio_thread(void *arg ODP_UNUSED)
 			case PKT_STATE_IPSEC_OUT_CLASSIFY:
 
 				rc = do_ipsec_out_classify(pkt, ctx, &skip);
-				ctx->state = (skip) ?
-					PKT_STATE_TRANSMIT :
-					PKT_STATE_IPSEC_OUT_SEQ;
+				if (odp_unlikely(skip)) {
+					ctx->state = PKT_STATE_TRANSMIT;
+				} else {
+					ctx->state = PKT_STATE_IPSEC_OUT_SEQ;
+					odp_queue_enq(seqnumq, buf);
+				}
 				break;
 
 			case PKT_STATE_IPSEC_OUT_SEQ: