File bug-1025630_mem-add-extra-mem-pages-for-pthread-stack.patch of Package lvm2.3893

From 362611f9380453ab759d9bae1aba426feb0417df Mon Sep 17 00:00:00 2001
From: Eric Ren <zren@suse.com>
Date: Wed, 1 Mar 2017 19:32:05 +0800
Subject: [PATCH] mem: add extra mem pages for pthread stack

Some archs can use even 64K pages and then lvm2 runs into trouble if
the stack is 'too small' to fit extra page capturing stack overwrite.

So when lvm2 limits stack - add extra mem page - be it 4K or 64K.

Relates to ppc64le bug: https://bugzilla.redhat.com/1387279

Upstream commit: 2a9eda1229c9d5d7150acdd3d8dd4908fbc784a8
Backported-by: Eric Ren <zren@suse.com>
---
 daemons/clvmd/clvmd.c            | 2 +-
 daemons/dmeventd/dmeventd.c      | 2 +-
 libdaemon/server/daemon-server.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 11de50d..5fbcbd7 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -516,7 +516,7 @@ int main(int argc, char *argv[])
 	/* Initialise the LVM thread variables */
 	dm_list_init(&lvm_cmd_head);
 	if (pthread_attr_init(&stack_attr) ||
-	    pthread_attr_setstacksize(&stack_attr, STACK_SIZE)) {
+	    pthread_attr_setstacksize(&stack_attr, STACK_SIZE + getpagesize())) {
 		log_sys_error("pthread_attr_init", "");
 		exit(1);
 	}
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 3b1952c..67512a7 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -352,7 +352,7 @@ static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *
 	/*
 	 * We use a smaller stack since it gets preallocated in its entirety
 	 */
-	pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE);
+	pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE + getpagesize());
 
 	/*
 	 * If no-one will be waiting, we need to detach.
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index bedd3b2..c2230d2 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -38,7 +38,7 @@ static int _pthread_create(pthread_t *t, void *(*fun)(void *), void *arg, int st
 	/*
 	 * We use a smaller stack since it gets preallocated in its entirety
 	 */
-	pthread_attr_setstacksize(&attr, stacksize);
+	pthread_attr_setstacksize(&attr, stacksize + getpagesize());
 	return pthread_create(t, &attr, fun, arg);
 }
 #endif
-- 
2.10.2
openSUSE Build Service is sponsored by