From patchwork Fri Jul 10 06:59:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarosh Arif X-Patchwork-Id: 73683 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D4D59A0526; Fri, 10 Jul 2020 09:01:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 157351DB11; Fri, 10 Jul 2020 09:01:39 +0200 (CEST) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by dpdk.org (Postfix) with ESMTP id 1203D1DAF6 for ; Fri, 10 Jul 2020 09:01:38 +0200 (CEST) Received: by mail-wm1-f65.google.com with SMTP id g75so4798842wme.5 for ; Fri, 10 Jul 2020 00:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+bq0+am2PmuY0f1Htu54NjqEVD1fJomIB5FI/6fsnk4=; b=mT5ugCNOMknw1ggtI5bfj9PqhLLFickF/4rHlCIpoPy0MwzYXOd9bqXN9SVyKMyie2 ubC/wKHjls+fXIS5txr1VhVR9V5gqYjgwr1crOcNCsLnlnZ+4GmzjMf1qf0+LgOlw4wV KMHphLwqfZdHst0BtqNZSuObAkmyTOIOu5a1dMYkD/yQ6/q3YPMcgTvZZsJNMZNi4q8F LPdahkE9SBBrSHAMSyu0zICfkdytWvdFKLp04DQw/L4FRoWdCY7Rrs5USGVRaZKC0gaP Md2lp5fROOhag8AbEQeiMAUejiUbziwLT5b1mVlhDXFeQrfcAB9H3dr3kZTTWNnbfsK3 r1tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+bq0+am2PmuY0f1Htu54NjqEVD1fJomIB5FI/6fsnk4=; b=tF8cIBQE0HBpYmGplFM1mCQ8S2m71f9QvTezLTVBNDPfQpvsmoQYVHhL0Ld7cNZ9AJ A5/NLEK9w7anT52r86bihh1DX3kzPVUBW2ReJeR2Dl04hVsaOdmB+mWIJBJkrhtwIkZx vfVtKT13mm4XvvA0ESLVFGJCTGTdyFNFHzADZil8vuBCBjbVWhYnREro3HDqcK+brEcG siRoVEHSD3Ys1zlinYEnub5NRB6DC1GEiWK4cPGZOLFh36WTlej9qYz6KJmv8cyKS859 HqF4fjBnMi5imCeYfMyxEYOnUWRRnH+pWPCWIW72Q2NYkckIdewTFJGAeWTnFfkVKuJ6 kxWw== X-Gm-Message-State: AOAM530Y8SrKKW0Yra0GGC6FEGfOlCPvD/SVtJj4OjVm0ULOSXv5hZig FPr2kRfbbOqJKr10DUhzDwpjLQ== X-Google-Smtp-Source: ABdhPJxXaK9j2VdglRCz6sS3PkCYh8oLOpOZ6EQyuDQ4sNU/GUPFFQsC0lQfQma9azlkY7EovtF+BA== X-Received: by 2002:a7b:c208:: with SMTP id x8mr3697669wmi.49.1594364497699; Fri, 10 Jul 2020 00:01:37 -0700 (PDT) Received: from localhost.localdomain ([39.40.87.182]) by smtp.gmail.com with ESMTPSA id 133sm8498045wme.5.2020.07.10.00.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 00:01:37 -0700 (PDT) From: Sarosh Arif To: rsanford@akamai.com, erik.g.carrillo@intel.com, dev@dpdk.org Cc: stable@dpdk.org, Sarosh Arif , h.mikita89@gmail.com Date: Fri, 10 Jul 2020 11:59:54 +0500 Message-Id: <20200710065954.4937-1-sarosh.arif@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200707090320.2463-1-sarosh.arif@emumba.com> References: <20200707090320.2463-1-sarosh.arif@emumba.com> Subject: [dpdk-dev] [PATCH v3] lib/librte_timer:fix corruption with reset X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If the user tries to reset/stop some other timer in it's callback function, which is also about to expire, using rte_timer_reset_sync/rte_timer_stop_sync the application goes into an infinite loop. This happens because rte_timer_reset_sync/rte_timer_stop_sync loop until the timer resets/stops and there is check inside timer_set_config_state which prevents a running timer from being reset/stopped by not it's own timer_cb. Therefore timer_set_config_state returns -1 due to which rte_timer_reset returns -1 and rte_timer_reset_sync goes into an infinite loop. The soloution to this problem is to return -1 from rte_timer_reset_sync/rte_timer_stop_sync in case the user tries to reset/stop some other timer in it's callback function. Bugzilla ID: 491 Fixes: 20d159f20543 ("timer: fix corruption with reset") Cc: h.mikita89@gmail.com Signed-off-by: Sarosh Arif --- v2: remove line continuations v3: separate code and declarations --- lib/librte_timer/rte_timer.c | 26 ++++++++++++++++++++++++-- lib/librte_timer/rte_timer.h | 4 ++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index 6d19ce469..0cd3e2c86 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -576,14 +576,24 @@ rte_timer_alt_reset(uint32_t timer_data_id, struct rte_timer *tim, } /* loop until rte_timer_reset() succeed */ -void +int rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks, enum rte_timer_type type, unsigned tim_lcore, rte_timer_cb_t fct, void *arg) { + struct rte_timer_data *timer_data; + TIMER_DATA_VALID_GET_OR_ERR_RET(default_data_id, timer_data, -EINVAL); + + if (tim->status.state == RTE_TIMER_RUNNING && + (tim->status.owner != (uint16_t)tim_lcore || + tim != timer_data->priv_timer[tim_lcore].running_tim)) + return -1; + while (rte_timer_reset(tim, ticks, type, tim_lcore, fct, arg) != 0) rte_pause(); + + return 0; } static int @@ -642,11 +652,23 @@ rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim) } /* loop until rte_timer_stop() succeed */ -void +int rte_timer_stop_sync(struct rte_timer *tim) { + struct rte_timer_data *timer_data; + unsigned int lcore_id = rte_lcore_id(); + + TIMER_DATA_VALID_GET_OR_ERR_RET(default_data_id, timer_data, -EINVAL); + + if (tim->status.state == RTE_TIMER_RUNNING && + (tim->status.owner != (uint16_t)lcore_id || + tim != timer_data->priv_timer[lcore_id].running_tim)) + return -1; + while (rte_timer_stop(tim) != 0) rte_pause(); + + return 0; } /* Test the PENDING status of the timer handle tim */ diff --git a/lib/librte_timer/rte_timer.h b/lib/librte_timer/rte_timer.h index c6b3d450d..392ca423d 100644 --- a/lib/librte_timer/rte_timer.h +++ b/lib/librte_timer/rte_timer.h @@ -275,7 +275,7 @@ int rte_timer_reset(struct rte_timer *tim, uint64_t ticks, * @param arg * The user argument of the callback function. */ -void +int rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks, enum rte_timer_type type, unsigned tim_lcore, rte_timer_cb_t fct, void *arg); @@ -314,7 +314,7 @@ int rte_timer_stop(struct rte_timer *tim); * @param tim * The timer handle. */ -void rte_timer_stop_sync(struct rte_timer *tim); +int rte_timer_stop_sync(struct rte_timer *tim); /** * Test if a timer is pending.