Skip to contentSkip to conversation

clvmd: fix _allocate_memory to avoid segfault on ppc64.

PATCH New Liuhua Wang 2 participants 3 messages Jun 6, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clvmd: fix _allocate_memory to avoid segfault on ppc64.

From: lhwang <[email protected]>

Under some LIBPTHREAD_VERSION, for example 2.11, when allocates 64K and thread stacksize is 128K, starting clvmd causes a segfault.

---
 lib/mm/memlock.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
lib/mm/memlock.c +17 -6
index 84b93db..be92a7b 100644
@@ -19,6 +19,7 @@
 #include "config.h"
 #include "toolcontext.h"
 
+#include <pthread.h>
 #include <limits.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -128,16 +129,26 @@ static void _touch_memory(void *mem, size_t size)
 	}
 }
 
-static void _allocate_memory(void)
+static void _allocate_memory(struct cmd_context *cmd)
 {
 	void *stack_mem, *temp_malloc_mem;
 	struct rlimit limit;
+        pthread_attr_t thread_attr;
+        size_t thread_stacksize;
 
 	/* Check if we could preallocate requested stack */
-	if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
-	    ((_size_stack * 2) < limit.rlim_cur) &&
-	    ((stack_mem = alloca(_size_stack))))
-		_touch_memory(stack_mem, _size_stack);
+	if (cmd->threaded) {
+		if ((pthread_attr_init(&thread_attr) == 0) &&
+		    (pthread_attr_getstacksize(&thread_attr, &thread_stacksize) == 0) &&
+        	    ((_size_stack * 2) < thread_stacksize) && 
+		    ((stack_mem = alloca(_size_stack))))
+			_touch_memory(stack_mem, _size_stack);        		
+        } else {
+		if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
+		    ((_size_stack * 2) < limit.rlim_cur) &&
+		    ((stack_mem = alloca(_size_stack))))
+			_touch_memory(stack_mem, _size_stack);
+	}
 	/* FIXME else warn user setting got ignored */
 
 	if ((temp_malloc_mem = malloc(_size_malloc_tmp)))
@@ -317,7 +328,7 @@ static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats
 /* Stop memory getting swapped out */
 static void _lock_mem(struct cmd_context *cmd)
 {
-	_allocate_memory();
+	_allocate_memory(cmd);
 
 	/*
 	 * For daemon we need to use mlockall()
Signature · 1 line
1.9.0
#1 lore raw

PATCH 1/1 clvmd: fix _allocate_memory to avoid segfault on ppc64.

Dne 6.6.2014 08:49, Liuhua Wang napsal(a):

Quoted 6 lines

From: lhwang <[email protected]>

Under some LIBPTHREAD_VERSION, for example 2.11, when allocates 64K and thread stacksize is 128K, starting clvmd causes a segfault.

Do you have any stack backtrace for this situation.

It'd be rather serious problem in clvmd code path to allocate even 32K on stack.

Thanks

Zdenek

#2 lore raw

PATCH 1/1 clvmd: fix _allocate_memory to avoid segfault on ppc64.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On 6/6/2014 at 03:03 PM, in message <[email protected]>, Zdenek

Quoted 8 lines · Kabelac

Dne 6.6.2014 08:49, Liuhua Wang napsal(a):

Quoted 6 lines

From: lhwang <[email protected]>

Under some LIBPTHREAD_VERSION, for example 2.11, when allocates 64K and thread stacksize is 128K, starting clvmd causes a segfault.

Quoted 9 lines

Do you have any stack backtrace for this situation.

It'd be rather serious problem in clvmd code path to allocate even 32K on stack.

Thanks

Zdenek

version: 2.02.98-0.25.4

from the core file:

#p $pc
$1 = (void (*)()) 0x10070c18
#bt

#0  0x0000000010070c18 in _allocate_memory () at mm/memlock.c:130
#1  0x0000000010070d38 in _lock_mem (cmd=<optimized out>) at mm/memlock.c:310
#2  _lock_mem_if_needed (cmd=0x10104f40) at mm/memlock.c:387
#3  0x0000000010011358 in init_clvm (excl_uuid=<optimized out>) at
lvm-functions.c:919
#4  0x000000001000f47c in lvm_thread_fn (arg=0xfffcaf4e530) at clvmd.c:2020
#5  0x00000fff9df6c67c in .start_thread () from /lib64/power6/libpthread.so.0
#6  0x00000fff9de7643c in .__clone () from /lib64/power6/libc.so.6

Thanks for your reply.

Best regards
Liuhua

Quoted 1 line