From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11128 invoked by alias); 8 Feb 2006 10:30:09 -0000 Received: (qmail 11111 invoked by uid 22791); 8 Feb 2006 10:30:08 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 08 Feb 2006 10:30:07 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k18ATtWn030052; Wed, 8 Feb 2006 11:29:55 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k18ATt2d030051; Wed, 8 Feb 2006 11:29:55 +0100 Date: Wed, 08 Feb 2006 10:30:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Roland McGrath Cc: Glibc hackers Subject: [PATCH] Fix i?86 lll_futex_{,timed_}wait and lll_wait_tid Message-ID: <20060208102954.GH4625@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-02/txt/msg00020.txt.bz2 Hi! All other arches except i?86 have "memory" clobber in lll_futex_wait etc. (be it through INTERNAL_SYSCALL or explicitly). These macros are only used a handful time in generic code (and never in i?86 specific code) and in a big portion of those places in tight loops, without an explicit memory clobber anywhere. The syscall itself I guess servers as a CPU memory barrier, so all we need is a barrier to tell GCC not to optimize things accross it. At least 2 places are miscompiled because of this: 1) unregister_atfork (say with GCC 4.1.0pre current CVS glibc): d40c0: f0 ff 48 14 lock decl 0x14(%eax) d40c4: 8b 50 14 mov 0x14(%eax),%edx d40c7: 85 d2 test %edx,%edx d40c9: 74 22 je d40ed <__unregister_atfork+0xed> d40cb: 8d 78 14 lea 0x14(%eax),%edi d40ce: 31 f6 xor %esi,%esi d40d0: b8 f0 00 00 00 mov $0xf0,%eax d40d5: 89 f1 mov %esi,%ecx d40d7: 87 fb xchg %edi,%ebx d40d9: 65 ff 15 10 00 00 00 call *%gs:0x10 d40e0: 87 fb xchg %edi,%ebx d40e2: eb ec jmp d40d0 <__unregister_atfork+0xd0> (note the endless loop) 2) start_thread: 52b8: 8b 45 b8 mov 0xffffffb8(%ebp),%eax 52bb: f6 40 5c 40 testb $0x40,0x5c(%eax) 52bf: 75 44 jne 5305 ... 5305: 31 d2 xor %edx,%edx 5307: 89 c7 mov %eax,%edi 5309: 81 c7 e8 01 00 00 add $0x1e8,%edi 530f: 31 f6 xor %esi,%esi 5311: b8 f0 00 00 00 mov $0xf0,%eax 5316: 89 f1 mov %esi,%ecx 5318: 87 fb xchg %edi,%ebx 531a: 65 ff 15 10 00 00 00 call *%gs:0x10 5321: 87 fb xchg %edi,%ebx 5323: eb ec jmp 5311 (likewise) 2006-02-08 Jakub Jelinek * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_futex_wait, lll_futex_timedwait, lll_wait_tid): Add "memory" clobber. --- libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h.jj 2006-01-06 06:01:25.000000000 +0100 +++ libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h 2006-02-08 11:12:25.000000000 +0100 @@ -75,7 +75,8 @@ : "=a" (__status) \ : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (0), \ "c" (FUTEX_WAIT), "d" (_val), \ - "i" (offsetof (tcbhead_t, sysinfo))); \ + "i" (offsetof (tcbhead_t, sysinfo)) \ + : "memory"); \ __status; \ }) @@ -90,7 +91,8 @@ : "=a" (__status) \ : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (timeout), \ "c" (FUTEX_WAIT), "d" (_val), \ - "i" (offsetof (tcbhead_t, sysinfo))); \ + "i" (offsetof (tcbhead_t, sysinfo)) \ + : "memory"); \ __status; \ }) @@ -346,7 +348,8 @@ extern int lll_unlock_wake_cb (int *__fu : "=&a" (__ignore) \ : "i" (SYS_futex), LLL_EBX_REG (&tid), "S" (0), \ "c" (FUTEX_WAIT), "d" (_tid), \ - "i" (offsetof (tcbhead_t, sysinfo))); \ + "i" (offsetof (tcbhead_t, sysinfo)) \ + : "memory"); \ } while (0) extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime) Jakub