From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75155 invoked by alias); 12 May 2016 10:06:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 75144 invoked by uid 89); 12 May 2016 10:06:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=acc_device_t, H*Ad:U*thomas, held X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 12 May 2016 10:06:30 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F213B3B75C; Thu, 12 May 2016 10:06:28 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4CA6RKV020338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 12 May 2016 06:06:28 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u4CA6PMT031861; Thu, 12 May 2016 12:06:25 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u4CA6OVf031860; Thu, 12 May 2016 12:06:24 +0200 Date: Thu, 12 May 2016 10:06:00 -0000 From: Jakub Jelinek To: Chung-Lin Tang Cc: gcc-patches , Thomas Schwinge Subject: Re: [PATCH, libgomp] Fix deadlock in acc_set_device_type Message-ID: <20160512100624.GW28550@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <56F8FD46.1060400@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56F8FD46.1060400@codesourcery.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00887.txt.bz2 On Mon, Mar 28, 2016 at 05:45:42PM +0800, Chung-Lin Tang wrote: > Hi Jakub, there's a path for deadlock on acc_device_lock when going > through the acc_set_device_type() OpenACC library function. > Basically, the gomp_init_targets_once() function should not be > called with that held. The attached patch moves it appropriately. > > Also in this patch, there are several cases in acc_* functions > where gomp_init_targets_once() is guarded by a test of > !cached_base_dev. Since that function already uses pthread_once() to > call gomp_target_init(), and technically cached_base_dev > is protected by acc_device_lock, the cleanest way should be to > simply drop those "if(!cached_base_dev)" tests. > > Tested libgomp without regressions on an nvptx offloaded system, > is this okay for trunk? Ok, with ChangeLog nits: > > 2016-03-28 Chung-Lin Tang > > * oacc-init.c (acc_init): Remove !cached_base_dev condition on call to > gomp_init_targets_once(). > (acc_set_device_type): Remove !cached_base_dev condition on call to > gomp_init_targets_once(), move call to before acc_device_lock acquire, > to avoid deadlock. > (acc_get_device_num): Remove !cached_base_dev condition on call to > gomp_init_targets_once(). > (acc_set_device_num): Likewise. Please just use gomp_init_targets_once instead of gomp_init_targets_once() in the ChangeLog. > Index: oacc-init.c > =================================================================== > --- oacc-init.c (revision 234502) > +++ oacc-init.c (working copy) > @@ -433,8 +433,7 @@ goacc_attach_host_thread_to_device (int ord) > void > acc_init (acc_device_t d) > { > - if (!cached_base_dev) > - gomp_init_targets_once (); > + gomp_init_targets_once (); > > gomp_mutex_lock (&acc_device_lock); > > @@ -498,11 +497,10 @@ acc_set_device_type (acc_device_t d) > struct gomp_device_descr *base_dev, *acc_dev; > struct goacc_thread *thr = goacc_thread (); > > + gomp_init_targets_once (); > + > gomp_mutex_lock (&acc_device_lock); > > - if (!cached_base_dev) > - gomp_init_targets_once (); > - > cached_base_dev = base_dev = resolve_device (d, true); > acc_dev = &base_dev[goacc_device_num]; > > @@ -563,8 +561,7 @@ acc_get_device_num (acc_device_t d) > if (d >= _ACC_device_hwm) > gomp_fatal ("unknown device type %u", (unsigned) d); > > - if (!cached_base_dev) > - gomp_init_targets_once (); > + gomp_init_targets_once (); > > gomp_mutex_lock (&acc_device_lock); > dev = resolve_device (d, true); > @@ -584,8 +581,7 @@ acc_set_device_num (int ord, acc_device_t d) > struct gomp_device_descr *base_dev, *acc_dev; > int num_devices; > > - if (!cached_base_dev) > - gomp_init_targets_once (); > + gomp_init_targets_once (); > > if (ord < 0) > ord = goacc_device_num; Jakub