From patchwork Tue Nov 18 15:27:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robbie King X-Patchwork-Id: 41044 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 66D2B241C9 for ; Tue, 18 Nov 2014 15:27:58 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf13085137lbj.11 for ; Tue, 18 Nov 2014 07:27:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:thread-topic:thread-index :date:message-id:references:in-reply-to:accept-language :content-language:mime-version:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :content-type:content-transfer-encoding:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=/ttIjih9dtD9qK7nAABEvxYaqhJkxEsI5YGu8/DB2PI=; b=kWkI4y4mpVAG9WyElJSoJ+WTYiHwh30+38CSqRHSAJlpp/z1BIhPgl7bMvlvPqPO0o VPh8vtfsyw906x2e2s3R3rBA4AFyaaca+Mmd4LDvSoun5e0GKD0+vThjj3n7pdEKK7Wc Q8595Emf2O4GRtLE8CwoYWUfP6cgZv9OqlrDhIp1RRssF0Jfcn7M5eBfUNyz9z9J0abQ +AIuI+3SmWn0hJexviqWvGTCPvIgGtEx+BSAnzSAkNajapbs4l/yw7+DAW21mqv1Lg9p AsaQpigApqmj3DEw2w7e+teYSS7mlZfyZX29/1elDGVWtUZ8VylGPBePJzlVdHKLrJT2 smFw== X-Gm-Message-State: ALoCoQl109Cr9mlnjkPL+JLJCIqQ8f2JaI3v93sAFLPGK7refpmGt9on2IrO2N0l1aXGvx0oK+wd X-Received: by 10.180.106.67 with SMTP id gs3mr5822380wib.3.1416324477396; Tue, 18 Nov 2014 07:27:57 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.23.101 with SMTP id l5ls1008703wif.8.canary; Tue, 18 Nov 2014 07:27:57 -0800 (PST) X-Received: by 10.194.5.227 with SMTP id v3mr49825689wjv.63.1416324477284; Tue, 18 Nov 2014 07:27:57 -0800 (PST) Received: from mail-wi0-x235.google.com (mail-wi0-x235.google.com. [2a00:1450:400c:c05::235]) by mx.google.com with ESMTPS id ge4si62542413wjd.134.2014.11.18.07.27.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 07:27:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:400c:c05::235 as permitted sender) client-ip=2a00:1450:400c:c05::235; Received: by mail-wi0-f181.google.com with SMTP id r20so6648879wiv.2 for ; Tue, 18 Nov 2014 07:27:57 -0800 (PST) X-Received: by 10.194.209.180 with SMTP id mn20mr48932570wjc.49.1416324476983; Tue, 18 Nov 2014 07:27:56 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp1345567lbc; Tue, 18 Nov 2014 07:27:56 -0800 (PST) X-Received: by 10.224.68.73 with SMTP id u9mr44642968qai.75.1416324475478; Tue, 18 Nov 2014 07:27:55 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id w81si53333750qge.81.2014.11.18.07.27.52 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Nov 2014 07:27:54 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xqkh4-0005cH-UX; Tue, 18 Nov 2014 15:27:50 +0000 Received: from alln-iport-3.cisco.com ([173.37.142.90]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xqkgz-0005cA-K2 for lng-odp@lists.linaro.org; Tue, 18 Nov 2014 15:27:45 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgQHANZka1StJA2D/2dsb2JhbABbgw5VWQSDAskRCodJAhxxFgEBAQEBfYQCAQEBBAEBASAEDToXBAIBCBEEAQEDAgYdAwICAiUBChQBCAgCBAESCIg5Dbl8lmIBAQEBAQEBAQEBAQEBAQEBAQEBAQEXgS2PKhYiBoJxNoEeBZAngiiEXYJLgVOEPz2NTIc9g3ttgUiBAwEBAQ X-IronPort-AV: E=Sophos;i="5.07,410,1413244800"; d="scan'208";a="97743025" Received: from alln-core-1.cisco.com ([173.36.13.131]) by alln-iport-3.cisco.com with ESMTP; 18 Nov 2014 15:27:40 +0000 Received: from xhc-aln-x15.cisco.com (xhc-aln-x15.cisco.com [173.36.12.89]) by alln-core-1.cisco.com (8.14.5/8.14.5) with ESMTP id sAIFRews018456 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 18 Nov 2014 15:27:40 GMT Received: from xmb-rcd-x01.cisco.com ([169.254.1.182]) by xhc-aln-x15.cisco.com ([173.36.12.89]) with mapi id 14.03.0195.001; Tue, 18 Nov 2014 09:27:39 -0600 From: "Robbie King (robking)" To: Jerin Jacob , "lng-odp@lists.linaro.org" Thread-Topic: [lng-odp] [PATCH] ipsec: Fix ctx->state update race Thread-Index: AQHP//6kpdmoE13oC0CHD4go2Nx6MJxmhz5Q Date: Tue, 18 Nov 2014 15:27:38 +0000 Message-ID: References: <1415964666-18661-1-git-send-email-jerin.jacob@caviumnetworks.com> In-Reply-To: <1415964666-18661-1-git-send-email-jerin.jacob@caviumnetworks.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.150.216.116] MIME-Version: 1.0 X-Topics: patch Subject: Re: [lng-odp] [PATCH] ipsec: Fix ctx->state update race X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Original-Sender: robking@cisco.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:400c:c05::235 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@ Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Oops! Good catch. I looked and I don't see any other manifestations. Reviewed-by: Robert King 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 --- 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, ¶ms, 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: