From patchwork Tue Nov 3 11:35:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 539329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 37CDF140770 for ; Tue, 3 Nov 2015 22:35:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=PzXYFZEJ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; q=dns; s=default; b=NDneYk3T0764hh9cnhI4PycE35nmL INLfL76eV+uHvujdJ9WP1cjF/fpkWxgXAxN+tPe9oCX/GB5BlTtXYsptlzIuoIaq tbGbNidw3YX8ZC2HB39ZC/6Al7lnTPxr026Mlg+vrTMxDyMmH1ffLU/f3R7e4snN Mrx2TNGa9VGZRw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; s=default; bh=9iBegOr/UwUEu7ezFo7XpG6rdew=; b=PzX YFZEJtPV6nBF4dPMGLanebK5DEi8hcD2lcexRGESyAa1sv52PS2XqLQV1+ZZuAnG d+MH8gmm1VuaGCaHFnFCIGXVO2sYBSsWWpY+RPecxXTwr/ePQzsHteq5odmR/svg 0hYUbQXBhDcni8QFWQP1W2M5K0fODx0RpZNfFOuo= Received: (qmail 67734 invoked by alias); 3 Nov 2015 11:35:48 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 67719 invoked by uid 89); 3 Nov 2015 11:35:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com To: GNU C Library From: Florian Weimer Subject: [PATCH] malloc: Fix ptmalloc_lock_all/_int_new_arena deadlock [BZ #19182] Message-ID: <56389C10.6060001@redhat.com> Date: Tue, 3 Nov 2015 12:35:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 This is just a minimal change. The fork handler lock acquisition has to go away anyway if we make fork async-signal-safe (bug 4737). 2015-11-03 Florian Weimer [BZ #19182] * malloc/arena.c (_int_new_arena): Do not acquire arena lock while list_lock is acquired. diff --git a/malloc/arena.c b/malloc/arena.c index 0f00afa..161902c 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -785,25 +785,26 @@ _int_new_arena (size_t size) set_head (top (a), (((char *) h + h->size) - ptr) | PREV_INUSE); LIBC_PROBE (memory_arena_new, 2, a, size); mstate replaced_arena = thread_arena; thread_arena = a; mutex_init (&a->mutex); - (void) mutex_lock (&a->mutex); (void) mutex_lock (&list_lock); detach_arena (replaced_arena); /* Add the new arena to the global list. */ a->next = main_arena.next; atomic_write_barrier (); main_arena.next = a; (void) mutex_unlock (&list_lock); + (void) mutex_lock (&a->mutex); + return a; } static mstate get_free_list (void)