All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clvmd: fix _allocate_memory to avoid segfault on ppc64.
@ 2014-06-06  6:49 Liuhua Wang
  2014-06-06  7:03 ` Zdenek Kabelac
  0 siblings, 1 reply; 3+ messages in thread
From: Liuhua Wang @ 2014-06-06  6:49 UTC (permalink / raw)
  To: lvm-devel

From: lhwang <lwang@suse.com>

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

Signed-off-by: Liuhua Wang <lwang@suse.com>
---
 lib/mm/memlock.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 84b93db..be92a7b 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -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()
-- 
1.9.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] clvmd: fix _allocate_memory to avoid segfault on ppc64.
  2014-06-06  6:49 [PATCH] clvmd: fix _allocate_memory to avoid segfault on ppc64 Liuhua Wang
@ 2014-06-06  7:03 ` Zdenek Kabelac
  2014-06-06  7:26   ` Liuhua Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Zdenek Kabelac @ 2014-06-06  7:03 UTC (permalink / raw)
  To: lvm-devel

Dne 6.6.2014 08:49, Liuhua Wang napsal(a):
> From: lhwang <lwang@suse.com>
>
> Under some LIBPTHREAD_VERSION, for example 2.11, when allocates 64K
> and thread stacksize is 128K, starting clvmd causes a segfault.
>
> Signed-off-by: Liuhua Wang <lwang@suse.com>

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] clvmd: fix _allocate_memory to avoid segfault on ppc64.
  2014-06-06  7:03 ` Zdenek Kabelac
@ 2014-06-06  7:26   ` Liuhua Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Liuhua Wang @ 2014-06-06  7:26 UTC (permalink / raw)
  To: lvm-devel


>>> On 6/6/2014 at 03:03 PM, in message <539167C2.2060604@redhat.com>, Zdenek
Kabelac <zkabelac@redhat.com> wrote: 
> Dne 6.6.2014 08:49, Liuhua Wang napsal(a):
> > From: lhwang <lwang@suse.com>
> >
> > Under some LIBPTHREAD_VERSION, for example 2.11, when allocates 64K
> > and thread stacksize is 128K, starting clvmd causes a segfault.
> >
> > Signed-off-by: Liuhua Wang <lwang@suse.com>
> 
> 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




> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-06  7:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-06  6:49 [PATCH] clvmd: fix _allocate_memory to avoid segfault on ppc64 Liuhua Wang
2014-06-06  7:03 ` Zdenek Kabelac
2014-06-06  7:26   ` Liuhua Wang

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.