From patchwork Thu Sep 3 15:16:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 53035 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id F256B22E23 for ; Thu, 3 Sep 2015 15:21:38 +0000 (UTC) Received: by wisv5 with SMTP id v5sf3957440wis.0 for ; Thu, 03 Sep 2015 08:21:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=FAAEUwN54Vdlnrptv/dloE+XsLmc1/UpuDpn5dDqgFI=; b=FQvDJqjL7ZwTy7h/uIw7JZxDa/UqR9vcXq0uAPZrNHc2NLd2uCUB/OGjGpf4JEh8+F wJRAc3333+d03+l6gSj4tvMnsHP1v15V4bM8X8HUAISTC7FrasO9CpK3phJCmf/HwOf1 9/w5I0LCMgKPSdqRBPkpRROaOQrpairgTqiDjdH9y8N6WbdA0473lcaYmUOn4jOM72+/ kMx3Mgn5YHxc33N3uXZuaIXXdB6kfSPKWFsLzgUyZMEegCeWMGykNZk6p1G4FmpBXTwM VuaXDpqtgrb8ZbgPYn1178sVPcWnHSnQYWUkc2CoX1JXAJWxiySVGErDh463wu+vxZoi RckA== X-Gm-Message-State: ALoCoQlwzU+yq21PsrUL3qGhEZnSlzAmNSCoAsOMMKZTpBHcyIZyOA0pir0loOLnaJT8DGGK++OZ X-Received: by 10.112.57.194 with SMTP id k2mr403830lbq.10.1441293697834; Thu, 03 Sep 2015 08:21:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.196 with SMTP id a4ls182272lak.27.gmail; Thu, 03 Sep 2015 08:21:37 -0700 (PDT) X-Received: by 10.112.129.72 with SMTP id nu8mr17765714lbb.81.1441293697607; Thu, 03 Sep 2015 08:21:37 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id pp10si23392922lbc.132.2015.09.03.08.21.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Sep 2015 08:21:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbcao8 with SMTP id ao8so26363961lbc.3 for ; Thu, 03 Sep 2015 08:21:37 -0700 (PDT) X-Received: by 10.152.26.163 with SMTP id m3mr22406305lag.86.1441293697495; Thu, 03 Sep 2015 08:21:37 -0700 (PDT) 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.164.42 with SMTP id yn10csp1344937lbb; Thu, 3 Sep 2015 08:21:35 -0700 (PDT) X-Received: by 10.140.88.148 with SMTP id t20mr7092272qgd.44.1441293695660; Thu, 03 Sep 2015 08:21:35 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 10si30224878qhy.85.2015.09.03.08.21.34; Thu, 03 Sep 2015 08:21:35 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id B350761A1B; Thu, 3 Sep 2015 15:21:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id BA17961A2F; Thu, 3 Sep 2015 15:17:34 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B563861A29; Thu, 3 Sep 2015 15:17:27 +0000 (UTC) Received: from mail-oi0-f51.google.com (mail-oi0-f51.google.com [209.85.218.51]) by lists.linaro.org (Postfix) with ESMTPS id 0CAA361A2B for ; Thu, 3 Sep 2015 15:16:52 +0000 (UTC) Received: by oiww128 with SMTP id w128so29438553oiw.2 for ; Thu, 03 Sep 2015 08:16:51 -0700 (PDT) X-Received: by 10.202.224.195 with SMTP id x186mr2307002oig.8.1441293411467; Thu, 03 Sep 2015 08:16:51 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by smtp.gmail.com with ESMTPSA id e73sm1525294oib.3.2015.09.03.08.16.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Sep 2015 08:16:50 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org, maxim.uvarov@linaro.org Date: Thu, 3 Sep 2015 10:16:39 -0500 Message-Id: <1441293400-28777-8-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441293400-28777-1-git-send-email-bill.fischofer@linaro.org> References: <1441293400-28777-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 7/8] linux-generic: schedule: fix race condition in ordered locks X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bill.fischofer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Correct race condition that arises due to attempt to permit ordered locks to be reusable. For now, ordered locks can only be used once per scheduled event. Signed-off-by: Bill Fischofer --- platform/linux-generic/include/odp_queue_internal.h | 6 +++++- platform/linux-generic/odp_queue.c | 8 +------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h index 48576bc..0f30965 100644 --- a/platform/linux-generic/include/odp_queue_internal.h +++ b/platform/linux-generic/include/odp_queue_internal.h @@ -193,8 +193,12 @@ static inline void reorder_enq(queue_entry_t *queue, static inline void order_release(queue_entry_t *origin_qe, int count) { + uint64_t sync = odp_atomic_load_u64(&origin_qe->s.sync_out); + origin_qe->s.order_out += count; - odp_atomic_fetch_add_u64(&origin_qe->s.sync_out, count); + if (sync < origin_qe->s.order_out) + odp_atomic_fetch_add_u64(&origin_qe->s.sync_out, + origin_qe->s.order_out - sync); } static inline int reorder_deq(queue_entry_t *queue, diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 15abd93..ac933da 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -999,12 +999,6 @@ void odp_schedule_order_unlock(odp_schedule_order_lock_t *lock ODP_UNUSED) if (!origin_qe) return; - /* Get a new sync order for reusability, and release the lock. Note - * that this must be done in this sequence to prevent race conditions - * where the next waiter could lock and unlock before we're able to - * get a new sync order since that would cause order inversion on - * subsequent locks we may perform in this ordered context. - */ - *sync = odp_atomic_fetch_inc_u64(&origin_qe->s.sync_in); + /* Release the ordered lock */ odp_atomic_fetch_inc_u64(&origin_qe->s.sync_out); }