run-elf_cntl_gelf_getshdr.sh: Resource deadlock avoided.

Mark Wielaard mjw at redhat.com
Wed Nov 6 11:55:42 UTC 2013


On Sun, 2013-11-03 at 15:40 +0100, Kurt Roeckx wrote:
> When running the test suite with --enable-thread-safety I get the
> following error in the FDREAD case:
> test-elf_cntl_gelf_getshdr: elf_readall.c:73: __libelf_readall: Unexpected error: Resource deadlock avoided.
> Aborted

Hmmm. We keep getting people trying out that configure option. But since
nobody is really testing or using it we really should discourage people
from using it. I added the following warning:

configure: WARNING: thread-safety is EXPERIMENTAL tests might fail.

People might still ignore it, but at least we did warn them.

> (gdb) frame 4
> #4  0x00007ffff7bcb072 in __libelf_readall (elf=elf at entry=0x603010) at elf_readall.c:73
> 73        rwlock_wrlock (elf->lock);
> 
> elf_cntl() also already did a rwlock_wrlock (elf->lock); at elf_cntl.c:55
> 
> The only other caller of __libelf_readall() seems to be elf_rawfile()
> which takes a lock just after the __libelf_readall() call.

elf_rawfile takes a rwlock_rdlock, __libelf_readall uses a
rwlock_wrlock.

As far as I understand rdlocks may nest, but wrlock that nest might
cause deadlocks (even when "upgrading" an rdlock to a wrlock).

I think the correct solution is to change to scope of the rwlock_wrlock
in elf_cntl to just the ELF_C_FDDONE case. But I might be missing which
field are protected by the lock. Does the following look sane and work
for you?

diff --git a/libelf/elf_cntl.c b/libelf/elf_cntl.c
index a3c5805..3b29571 100644
--- a/libelf/elf_cntl.c
+++ b/libelf/elf_cntl.c
@@ -52,8 +52,6 @@ elf_cntl (elf, cmd)
       return -1;
     }
 
-  rwlock_wrlock (elf->lock);
-
   switch (cmd)
     {
     case ELF_C_FDREAD:
@@ -68,7 +66,9 @@ elf_cntl (elf, cmd)
 
     case ELF_C_FDDONE:
       /* Mark the file descriptor as not usable.  */
+      rwlock_wrlock (elf->lock);
       elf->fildes = -1;
+      rwlock_unlock (elf->lock);
       break;
 
     default:
@@ -77,7 +77,5 @@ elf_cntl (elf, cmd)
       break;
     }
 
-  rwlock_unlock (elf->lock);
-
   return result;
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-configure.ac-Add-warning-that-enable-thread-safety-i.patch
Type: text/x-patch
Size: 1638 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/elfutils-devel/attachments/20131106/6b80288d/attachment-0001.bin>


More information about the elfutils-devel mailing list