From patchwork Mon Oct 24 19:51:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 59366 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5EB538582A0 for ; Mon, 24 Oct 2022 19:51:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 9B2BF3858412 for ; Mon, 24 Oct 2022 19:51:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B2BF3858412 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.95,210,1661846400"; d="scan'208,223";a="85440147" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 24 Oct 2022 11:51:20 -0800 IronPort-SDR: kqxN7BWu43kOBd14YIYXSXpIOsoNLfXEoWCThHB+KW4+oQc2Xj1Ey+lPmpXKwCran5hTG7UT2Z FgbSwv3HWDWW5VReuutLN1/YbZeeIOtn7mPxpmnSxDHtwRa4Ftt9jKw1lvM+4JAcVtr6+toDD1 TmWVN/2BTX9aVZn3isiR9H7kbmQUoMdZVz96f3zPSiKxFvSjM6ZE/3FBiMeP14j7dg5HZalj8k NH5+nvbbbXuIe0JtwSEkQT8vfnLCJlhEaJKip3ZN2OaSncAfE6dyp4e8zs2TQI6UWbIs3U6vWS elA= From: Thomas Schwinge To: Jakub Jelinek , Tobias Burnus , Subject: libgomp/nvptx: Prepare for reverse-offload callback handling, resolve spurious SIGSEGVs (was: [Patch][v5] libgomp/nvptx: Prepare for reverse-offload callback handling) In-Reply-To: <87o7u1ox4n.fsf@euler.schwinge.homeip.net> References: <3f0fc49f-b07f-bee2-51a8-a5d03f1c33ed@codesourcery.com> <30e3ed49-0d14-8015-57ef-3d70b1dea69a@codesourcery.com> <3ebce406-46e4-8f98-8c53-83b61423644e@codesourcery.com> <798d7ee1-2ffa-a591-38cb-a9ad421265d0@codesourcery.com> <832946f-bb12-23d7-7d64-47b85c95125@ispras.ru> <1e56b27f-3c74-8bc2-028b-9091fa1ae7b1@codesourcery.com> <87r0yxoxdh.fsf@euler.schwinge.homeip.net> <87o7u1ox4n.fsf@euler.schwinge.homeip.net> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Mon, 24 Oct 2022 21:51:13 +0200 Message-ID: <87mt9lvw3y.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Monakov Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On 2022-10-24T21:11:04+0200, I wrote: > On 2022-10-24T21:05:46+0200, I wrote: >> On 2022-10-24T16:07:25+0200, Jakub Jelinek via Gcc-patches wrote: >>> On Wed, Oct 12, 2022 at 10:55:26AM +0200, Tobias Burnus wrote: >>>> libgomp/nvptx: Prepare for reverse-offload callback handling >> >>> Ok, thanks. >> >> Per commit r13-3460-g131d18e928a3ea1ab2d3bf61aa92d68a8a254609 >> "libgomp/nvptx: Prepare for reverse-offload callback handling", >> I'm seeing a lot of libgomp execution test regressions. Random >> example, 'libgomp.c-c++-common/error-1.c': >> >> [...] >> GOMP_OFFLOAD_run: kernel main$_omp_fn$0: launch [(teams: 1), 1, 1] [(lanes: 32), (threads: 8), 1] >> >> Thread 1 "a.out" received signal SIGSEGV, Segmentation fault. >> 0x00007ffff793b87d in GOMP_OFFLOAD_run (ord=, tgt_fn=, tgt_vars=, args=) at [...]/source-gcc/libgomp/plugin/plugin-nvptx.c:2127 >> 2127 if (__atomic_load_n (&ptx_dev->rev_data->fn, __ATOMIC_ACQUIRE) != 0) >> (gdb) print ptx_dev >> $1 = (struct ptx_device *) 0x6a55a0 >> (gdb) print ptx_dev->rev_data >> $2 = (struct rev_offload *) 0xffffffff00000000 >> (gdb) print ptx_dev->rev_data->fn >> Cannot access memory at address 0xffffffff00000000 >> >> Why is it even taking this 'if (reverse_offload)' code path, which isn't >> applicable to this test case (as far as I understand)? (Well, the answer >> is 'bool reverse_offload = ptx_dev->rev_data != NULL;', but why is that?) > > Well. > > --- a/libgomp/plugin/plugin-nvptx.c > +++ b/libgomp/plugin/plugin-nvptx.c > > @@ -329,6 +332,7 @@ struct ptx_device > pthread_mutex_t lock; > } omp_stacks; > > + struct rev_offload *rev_data; > struct ptx_device *next; > }; > > ... but as far as I can tell, this is never initialized in > 'nvptx_open_device', which does 'ptx_dev = GOMP_PLUGIN_malloc ([...]);'. > Would the following be the correct fix (currently testing)? > > --- libgomp/plugin/plugin-nvptx.c > +++ libgomp/plugin/plugin-nvptx.c > @@ -546,6 +546,8 @@ nvptx_open_device (int n) > ptx_dev->omp_stacks.size = 0; > pthread_mutex_init (&ptx_dev->omp_stacks.lock, NULL); > > + ptx_dev->rev_data = NULL; > + > return ptx_dev; > } That did clean up libgomp execution test regressions; pushed to master branch commit 205538832b7033699047900cf25928f5920d8b93 "libgomp/nvptx: Prepare for reverse-offload callback handling, resolve spurious SIGSEGVs", see attached. Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From 205538832b7033699047900cf25928f5920d8b93 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 24 Oct 2022 21:11:47 +0200 Subject: [PATCH] libgomp/nvptx: Prepare for reverse-offload callback handling, resolve spurious SIGSEGVs Per commit r13-3460-g131d18e928a3ea1ab2d3bf61aa92d68a8a254609 "libgomp/nvptx: Prepare for reverse-offload callback handling", I'm seeing a lot of libgomp execution test regressions. Random example, 'libgomp.c-c++-common/error-1.c': [...] GOMP_OFFLOAD_run: kernel main$_omp_fn$0: launch [(teams: 1), 1, 1] [(lanes: 32), (threads: 8), 1] Thread 1 "a.out" received signal SIGSEGV, Segmentation fault. 0x00007ffff793b87d in GOMP_OFFLOAD_run (ord=, tgt_fn=, tgt_vars=, args=) at [...]/source-gcc/libgomp/plugin/plugin-nvptx.c:2127 2127 if (__atomic_load_n (&ptx_dev->rev_data->fn, __ATOMIC_ACQUIRE) != 0) (gdb) print ptx_dev $1 = (struct ptx_device *) 0x6a55a0 (gdb) print ptx_dev->rev_data $2 = (struct rev_offload *) 0xffffffff00000000 (gdb) print ptx_dev->rev_data->fn Cannot access memory at address 0xffffffff00000000 libgomp/ * plugin/plugin-nvptx.c (nvptx_open_device): Initialize 'ptx_dev->rev_data'. --- libgomp/plugin/plugin-nvptx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index ad057edabec..0768fca350b 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -546,6 +546,8 @@ nvptx_open_device (int n) ptx_dev->omp_stacks.size = 0; pthread_mutex_init (&ptx_dev->omp_stacks.lock, NULL); + ptx_dev->rev_data = NULL; + return ptx_dev; } -- 2.35.1