All of lore.kernel.org
 help / color / mirror / Atom feed
From: mwilck@suse.com
To: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [dm-devel] [PATCH v2] multipathd: fix compilation issue with liburcu < 0.8
Date: Thu, 13 May 2021 21:53:58 +0200	[thread overview]
Message-ID: <20210513195358.11638-1-mwilck@suse.com> (raw)

From: Martin Wilck <mwilck@suse.com>

To avoid race conditions with pending RCU callbacks on exit, it's
necessary to call rcu_barrier() in cleanup_rcu() (see
https://lists.lttng.org/pipermail/lttng-dev/2021-May/029958.html and
follow-ups).

rcu_barrier() is only available in User-space RCU v0.8 and newer.
Fix it by reverting 5d0dae6 ("multipathd: Fix liburcu memory leak")
if an older version of liburcu is detected.

Fixes: 5d0dae6 ("multipathd: Fix liburcu memory leak")
Signed-off-by: Martin Wilck <mwilck@suse.com>

---
v2: Use $(PKGCONFIG) (Ben Marzinski); remove "\n" in awk.

---
 multipathd/Makefile |  2 ++
 multipathd/main.c   | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/multipathd/Makefile b/multipathd/Makefile
index d053c1e..393b6cb 100644
--- a/multipathd/Makefile
+++ b/multipathd/Makefile
@@ -16,6 +16,8 @@ LDFLAGS += $(BIN_LDFLAGS)
 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist \
 	   -L$(mpathcmddir) -lmpathcmd -ludev -ldl -lurcu -lpthread \
 	   -ldevmapper -lreadline
+CFLAGS += $(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
+	awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
 
 ifdef SYSTEMD
 	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
diff --git a/multipathd/main.c b/multipathd/main.c
index 102946b..c34fd9c 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -3031,6 +3031,10 @@ static void cleanup_threads(void)
 	pthread_attr_destroy(&waiter_attr);
 }
 
+#ifndef URCU_VERSION
+#  define URCU_VERSION 0
+#endif
+#if (URCU_VERSION >= 0x000800)
 /*
  * Use a non-default call_rcu_data for child().
  *
@@ -3040,6 +3044,9 @@ static void cleanup_threads(void)
  * can't be joined with pthread_join(), leaving a memory leak.
  *
  * Therefore we create our own, which can be destroyed and joined.
+ * The cleanup handler needs to call rcu_barrier(), which is only
+ * available in user-space RCU v0.8 and newer. See
+ * https://lists.lttng.org/pipermail/lttng-dev/2021-May/029958.html
  */
 static struct call_rcu_data *setup_rcu(void)
 {
@@ -3072,6 +3079,7 @@ static void cleanup_rcu(void)
 	}
 	rcu_unregister_thread();
 }
+#endif /* URCU_VERSION */
 
 static void cleanup_child(void)
 {
@@ -3116,9 +3124,14 @@ child (__attribute__((unused)) void *param)
 	init_unwinder();
 	mlockall(MCL_CURRENT | MCL_FUTURE);
 	signal_init();
+#if (URCU_VERSION >= 0x000800)
 	mp_rcu_data = setup_rcu();
-
-	if (atexit(cleanup_rcu) || atexit(cleanup_child))
+	if (atexit(cleanup_rcu))
+		fprintf(stderr, "failed to register RCU cleanup handler\n");
+#else
+	rcu_init();
+#endif
+	if (atexit(cleanup_child))
 		fprintf(stderr, "failed to register cleanup handlers\n");
 
 	setup_thread_attr(&misc_attr, 64 * 1024, 0);
-- 
2.31.1


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


             reply	other threads:[~2021-05-13 19:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13 19:53 mwilck [this message]
2021-05-14 19:00 ` [dm-devel] [PATCH v2] multipathd: fix compilation issue with liburcu < 0.8 Benjamin Marzinski

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=20210513195358.11638-1-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.