Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1591087

Summary: glibc: SIGABRT when qemu-kvm calls sem_timedwait()
Product: Red Hat Enterprise Linux 7 Reporter: Han Han <hhan>
Component: glibcAssignee: glibc team <glibc-bugzilla>
Status: CLOSED DUPLICATE QA Contact: qe-baseos-tools-bugs
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.6CC: ashankar, chwen, codonell, dj, dyuan, fweimer, hannsj_uhl, juzhang, mnewsome, pfrankli, xuzhang
Target Milestone: rcKeywords: Regression, TestBlocker
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: glibc-2.17-258 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-06-14 19:45:01 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
All threads backtrace none

Description Han Han 2018-06-14 03:51:07 UTC
Created attachment 1451098 [details]
All threads backtrace

Description of problem:
As subject

Version-Release number of selected component (if applicable):
glibc-2.17-257.el7.x86_64
qemu-kvm-rhev-2.12.0-3.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Install glibc-2.17-257.el7.x86_64 qemu-kvm-rhev-2.12.0-3.el7.x86_64
2. Download compressed image https://avocado-project.org/data/assets/jeos/27/jeos-27-64.qcow2.xz and extract it with xz.
3. Start a VM and wait a minute:
# /usr/libexec/qemu-kvm -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 jeos-27-64.qcow2.qcow2
VNC server running on ::1:5900
Aborted (core dumped)

the coredump backtrace:
#0  0x00007f2520a6e207 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
#1  0x00007f2520a6f8f8 in __GI_abort () at abort.c:90
#2  0x00007f2520e12d12 in do_futex_wait (cancel=true, private=<optimized out>, abstime=0x7f24c3abd5a0, expected=0, futex=0x55a3d8a92bd8)
    at ../nptl/sysdeps/unix/sysv/linux/sem_waitcommon.c:107
#3  0x00007f2520e12d12 in do_futex_wait (sem=sem@entry=0x55a3d8a92bd8, abstime=abstime@entry=0x7f24c3abd5a0) at ../nptl/sysdeps/unix/sysv/linux/sem_waitcommon.c:223
#4  0x00007f2520e12da7 in __new_sem_wait_slow (sem=0x55a3d8a92bd8, abstime=0x7f24c3abd5a0) at ../nptl/sysdeps/unix/sysv/linux/sem_waitcommon.c:292
#5  0x00007f2520e12e45 in sem_timedwait (sem=sem@entry=0x55a3d8a92bd8, abstime=abstime@entry=0x7f24c3abd5a0) at ../nptl/sysdeps/unix/sysv/linux/sem_timedwait.c:37
#6  0x000055a3d6b97a27 in qemu_sem_timedwait (sem=sem@entry=0x55a3d8a92bd8, ms=ms@entry=10000) at util/qemu-thread-posix.c:292
#7  0x000055a3d6b93268 in worker_thread (opaque=0x55a3d8a92b60) at util/thread-pool.c:92
#8  0x00007f2520e0cdd5 in start_thread (arg=0x7f24c3ac0700) at pthread_create.c:307
#9  0x00007f2520b35ead in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Actual results:
As above

Expected results:
No SIGABRT

Additional info:
It works well on glibc-2.17-252.el7.x86_64

Comment 3 Han Han 2018-06-14 04:03:31 UTC
This bug will cause VM start failure. Please fix it ASAP.

Comment 4 Florian Weimer 2018-06-14 08:05:18 UTC
Thanks, and sorry.  I can reproduce it, and even after fixing strncmp in rtld, so it's another issue.  Will investigate further.

Comment 5 Florian Weimer 2018-06-14 09:55:53 UTC
Note for debugging: This reproduces only when building with --enable-kernel=2.6.32, which triggers the definition of __ASSUME_FUTEX_CLOCK_REALTIME, among other things.

Comment 6 Florian Weimer 2018-06-14 12:34:59 UTC
git bisect blames this on this backport:

    2738: glibc-rh1401665-1.patch
    
    Includes generic lll_futex_timed_wait_bitset for x86_64, to use
    standard code paths from upstream.
    
    commit 35df5a77f3ad2a35761631928440d2994a9e4bc5
    Author: Carlos O'Donell <carlos>
    Date:   Tue Jun 12 16:17:05 2018 -0400
    
        Fix fallback path in __pthread_mutex_timedlock ().
    
        Fix the typo in the fallback path in __pthread_mutex_timedlock ()
        whic hcalls lll_futex_timed_wait ().  This is only useful for cases
        where the patch is being backported to older distributions where
        only lll_futex_timed_wait () is available.
    
    commit 65810f0ef05e8c9e333f17a44e77808b163ca298
    Author: Torvald Riegel <triegel>
    Date:   Thu Dec 22 10:20:43 2016 +0100
    
        robust mutexes: Fix broken x86 assembly by removing it
    
        lll_robust_unlock on i386 and x86_64 first sets the futex word to
        FUTEX_WAITERS|0 before calling __lll_unlock_wake, which will set the
        futex word to 0.  If the thread is killed between these steps, then the
        futex word will be FUTEX_WAITERS|0, and the kernel (at least current
        upstream) will not set it to FUTEX_OWNER_DIED|FUTEX_WAITERS because 0 is
        not equal to the TID of the crashed thread.
    
        The lll_robust_lock assembly code on i386 and x86_64 is not prepared to
        deal with this case because the fastpath tries to only CAS 0 to TID and
        not FUTEX_WAITERS|0 to TID; the slowpath simply waits until it can CAS 0
        to TID or the futex_word has the FUTEX_OWNER_DIED bit set.
    
        This issue is fixed by removing the custom x86 assembly code and using
        the generic C code instead.  However, instead of adding more duplicate
        code to the custom x86 lowlevellock.h, the code of the lll_robust* functions
        is inlined into the single call sites that exist for each of these functions
        in the pthread_mutex_* functions.  The robust mutex paths in the latter
        have been slightly reorganized to make them simpler.
    
        This patch is meant to be easy to backport, so C11-style atomics are not
        used.

Comment 7 Carlos O'Donell 2018-06-14 12:56:07 UTC
(In reply to Han Han from comment #3)
> This bug will cause VM start failure. Please fix it ASAP.

The glibc -257 build went out with 2 defects in it which were not caught in early testing, the -257 build had been untagged, and the working -254  build should be used again (back on the errata).

Sorry for the problems the build caused.

Comment 8 Carlos O'Donell 2018-06-14 12:57:56 UTC
(In reply to Florian Weimer from comment #6)
> git bisect blames this on this backport:
> 
>     2738: glibc-rh1401665-1.patch

That's what I expected.

See: https://bugzilla.redhat.com/show_bug.cgi?id=1401665#c36

I'm going to drop this patch because it does cause two regressions, already seen in tst-sem5, and tst-sem10 in the glibc testsuite.

Comment 9 Florian Weimer 2018-06-14 14:27:26 UTC
lll_futex_timed_wait_bitset and its callers do not agree whether error return codes are negative.  This appears to fix the issue:

diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
index 5fd4e07..99c2fe9 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
@@ -233,7 +233,8 @@ LLL_STUB_UNWIND_INFO_END
                              __lll_private_flag (__op, private),             \
                              (val), (timespec), NULL /* Unused.  */,         \
                              FUTEX_BITSET_MATCH_ANY);                        \
-    INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret;                \
+    (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret, __err))               \
+     ? -INTERNAL_SYSCALL_ERRNO (__ret, __err) : 0);                           \
   })

Comment 10 Florian Weimer 2018-06-14 15:11:23 UTC
The broken code happens to work on POWER because INTERNAL_SYSCALL_ERROR_P looks at a different register there, and the kernel returns a *positive* error number, so negating that gives you a negative error code, as expected by the callers.

On x86-64, however, the kernel already gives us a negative error code, and we negate that again, giving us a positive return value for lll_futex_timed_wait_bitset on error.

Comment 11 Carlos O'Donell 2018-06-14 19:45:01 UTC
This is fixed in glibc-2.17-258.

*** This bug has been marked as a duplicate of bug 1401665 ***