Skip to contentSkip to conversation

multipathd: fix compilation issue with liburcu < 0.8

PATCH Superseded [email protected] 2 participants 3 messages May 12, 2021 – May 13, 2021 Device mapper

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multipathd: fix compilation issue with liburcu < 0.8

From: Martin Wilck <[email protected]>

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")
---
 multipathd/Makefile |  2 ++
 multipathd/main.c   | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
multipathd/Makefile +2 -0
index d053c1e..dc7eb32 100644
@@ -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 pkg-config --modversion liburcu 2>/dev/null | \
+	awk -F. '{ printf("-DURCU_VERSION=0x%06x\n", 256 * ( 256 * $$1 + $$2) + $$3); }')
 
 ifdef SYSTEMD
 	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
multipathd/main.c +15 -2
index 102946b..c34fd9c 100644
@@ -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);
Signature · 7 lines
2.31.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw
Quoted 23 lines · On Wed, May 12, 2021 at 11:17:05PM +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

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")
---
 multipathd/Makefile |  2 ++
 multipathd/main.c   | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
multipathd/Makefile +0 -0
index d053c1e..dc7eb32 100644

multipathd/Makefile LDFLAGS += $(BIN_LDFLAGS) · line 20

Quoted 5 lines
multipathd/Makefile +2 -0
@@ -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 pkg-config --modversion liburcu 2>/dev/null | \
+	awk -F. '{ printf("-DURCU_VERSION=0x%06x\n", 256 * ( 256 * $$1 + $$2) + $$3); }')

Shouldn't this be

$(shell $(PKGCONFIG) --modversion ...

-Ben

Quoted 55 lines
multipathd/Makefile +0 -0
 ifdef SYSTEMD
 	CFLAGS += -DUSE_SYSTEMD=$(SYSTEMD)
multipathd/main.c +15 -2
index 102946b..c34fd9c 100644
@@ -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);
Signature · 1 line
2.31.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#2 lore raw
Quoted 17 lines · Benjamin Marzinski
Quoted 6 lines
multipathd/Makefile +0 -0
index d053c1e..dc7eb32 100644
@@ -16,6 +16,8 @@ LDFLAGS += $(BIN_LDFLAGS)
Quoted 8 lines

 LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathpersistdir) - lmpathpersist \
           -L$(mpathcmddir) -lmpathcmd -ludev -ldl -lurcu -lpthread \
           -ldevmapper -lreadline
+CFLAGS += $(shell pkg-config --modversion liburcu 2>/dev/null | \
+       awk -F. '{ printf("-DURCU_VERSION=0x%06x\n", 256 * ( 256 * $$1 + $$2) + $$3); }')

Shouldn't this be

Quoted 1 line

$(shell $(PKGCONFIG) --modversion ...

Thanks for spotting that.

Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel