DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, stephen@networkplumber.org,
	Stephen Hemminger <sthemmin@microsoft.com>
Subject: [dpdk-dev] [PATCH v2] eal/mp: remove rte_panic and profanity
Date: Tue, 13 Nov 2018 18:03:52 +0000	[thread overview]
Message-ID: <8fb8fa187d7f5843904129b22383a2a6fe404797.1542132003.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <7632620e2d7fbf772965b2d15b8187df6648a375.1540565496.git.anatoly.burakov@intel.com>

EAL should not crash when setting alarm fails. Also, remove the
profanity in error message.

Fixes: daf9bfca717e ("ipc: remove thread for async requests")

Cc: stable@dpdk.org
Cc: stephen@networkplumber.org

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---

Notes:
    v2: fix uninitialized variable

 lib/librte_eal/common/eal_common_proc.c | 31 ++++++++++++++++++-------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
index 97663d3ba..f65ef56c0 100644
--- a/lib/librte_eal/common/eal_common_proc.c
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -800,7 +800,7 @@ mp_request_async(const char *dst, struct rte_mp_msg *req,
 {
 	struct rte_mp_msg *reply_msg;
 	struct pending_request *pending_req, *exist;
-	int ret;
+	int ret = -1;
 
 	pending_req = calloc(1, sizeof(*pending_req));
 	reply_msg = calloc(1, sizeof(*reply_msg));
@@ -827,6 +827,28 @@ mp_request_async(const char *dst, struct rte_mp_msg *req,
 		goto fail;
 	}
 
+	/*
+	 * set the alarm before sending message. there are two possible error
+	 * scenarios to consider here:
+	 *
+	 * - if the alarm set fails, we free the memory right there
+	 * - if the alarm set succeeds but sending message fails, then the alarm
+	 *   will trigger and clean up the memory
+	 *
+	 * Even if the alarm triggers too early (i.e. immediately), we're still
+	 * holding the lock to pending requests queue, so the interrupt thread
+	 * will just spin until we release the lock, and either release the
+	 * memory, or doesn't find any pending requests in the queue because we
+	 * never added any due to send message failure.
+	 */
+	if (rte_eal_alarm_set(ts->tv_sec * 1000000 + ts->tv_nsec / 1000,
+			      async_reply_handle, pending_req) < 0) {
+		RTE_LOG(ERR, EAL, "Fail to set alarm for request %s:%s\n",
+			dst, req->name);
+		ret = -1;
+		goto fail;
+	}
+
 	ret = send_msg(dst, req, MP_REQ);
 	if (ret < 0) {
 		RTE_LOG(ERR, EAL, "Fail to send request %s:%s\n",
@@ -841,13 +863,6 @@ mp_request_async(const char *dst, struct rte_mp_msg *req,
 
 	param->user_reply.nb_sent++;
 
-	if (rte_eal_alarm_set(ts->tv_sec * 1000000 + ts->tv_nsec / 1000,
-			      async_reply_handle, pending_req) < 0) {
-		RTE_LOG(ERR, EAL, "Fail to set alarm for request %s:%s\n",
-			dst, req->name);
-		rte_panic("Fix the above shit to properly free all memory\n");
-	}
-
 	return 0;
 fail:
 	free(pending_req);
-- 
2.17.1

  parent reply	other threads:[~2018-11-13 18:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-25 18:20 [dpdk-dev] [PATCH 0/4] small cleanups Stephen Hemminger
2018-07-25 18:20 ` [dpdk-dev] [PATCH 1/4] arm: remove profanity in comment Stephen Hemminger
2018-10-24 23:50   ` Thomas Monjalon
2018-07-25 18:20 ` [dpdk-dev] [PATCH 2/4] bnx2x: remove profanity Stephen Hemminger
2018-09-18  9:40   ` Thomas Monjalon
2018-09-18 15:07     ` Stephen Hemminger
2018-09-19 16:40       ` Mody, Rasesh
2018-10-16 14:45         ` Ferruh Yigit
2018-10-16 14:52           ` Ferruh Yigit
2018-10-26 14:56   ` Burakov, Anatoly
2018-07-25 18:20 ` [dpdk-dev] [PATCH 3/4] eal: don't crash if alarm set fails Stephen Hemminger
2018-07-26  9:34   ` Burakov, Anatoly
2018-07-26  9:41   ` Burakov, Anatoly
2018-09-18  9:43     ` Thomas Monjalon
2018-09-18 10:16       ` Burakov, Anatoly
2018-10-24 23:51         ` Thomas Monjalon
2018-10-25 14:04           ` Burakov, Anatoly
2018-10-26 14:55   ` [dpdk-dev] [PATCH] eal/mp: remove rte_panic and profanity Anatoly Burakov
2018-10-26 20:41     ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2018-10-30 10:31       ` Burakov, Anatoly
2018-11-13 18:03     ` Anatoly Burakov [this message]
2018-11-13 23:03       ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
2018-07-25 18:20 ` [dpdk-dev] [PATCH 4/4] ixgbe: remove mild profanity Stephen Hemminger
2018-10-16 15:00   ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fb8fa187d7f5843904129b22383a2a6fe404797.1542132003.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.org \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).