From patchwork Thu Apr 23 14:11:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 1275787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 497K4L487Mz9sSd for ; Fri, 24 Apr 2020 00:12:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFD1B386F474; Thu, 23 Apr 2020 14:11:58 +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 97B6F385DC23 for ; Thu, 23 Apr 2020 14:11:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 97B6F385DC23 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Andrew_Stubbs@mentor.com IronPort-SDR: a/IIzcc7I3P6igmzyZpmcxXXwDutHYOgVtueZ6hB33TSe09uk3foQiA9TePRk6mKxMl4Jmbkov dfoO3m3v+XeWG5a3KPmn3K+yMUOARMjx1BKaOW/47nYBntUNxqExcdEn3e3+roGPPiecCFHzzg U/O2ffdSWpSkxjucpCDhmX2k0S0UhsLD1oicyJ6Kr3FVHqFqVzwsMaUA9idUJaih59VUJ+J+BF Ey0Ey2UHwJSvd9pY5tJ+SsG5mM01L0MUxkbJXZDtsmGV7/BAAdAehDgWfA4OI3ltHbjnNABq2O niM= X-IronPort-AV: E=Sophos;i="5.73,307,1583222400"; d="scan'208";a="48092235" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 23 Apr 2020 06:11:55 -0800 IronPort-SDR: OE4NOjayEu0LDfnbPkcArOc6eK4u640NQ/v1wug4IQiOwJEKt5NNDK2KXLJsrERfXJ+d2oVbQv lhkHuzRBi6jSBHigjsabpWhDqD96nyf2/MFUByMb17ZHJr+Sz/FW+C46GPc6XoPfJBAaG2nQEy 5tW6TpOmaTrkjPM9UQbAxoaleoblJGs3yZoGQhnLR8aUayOG7u3k79qrKIuohGv/m2x+FEkZvv SWbKCccVeXWmOqNw4nWeUjd79I7vem31p97FDYe7Hb6CbTapJ7h6HVdAW+opS0h3Jv3qCEYsf2 Zqs= From: Andrew Stubbs Subject: [committed] amdgcn: Check HSA return codes [PR94629] To: "gcc-patches@gcc.gnu.org" Message-ID: <49dcbe1d-78d9-f33d-682d-b91c20bed478@codesourcery.com> Date: Thu, 23 Apr 2020 15:11:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Language: en-GB X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-06.mgc.mentorg.com (139.181.222.6) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-23.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch adds some additional checking to ensure that the HSA runtime call do not return errors. Previously the return codes were ignored, but failure still detected by the output data still having its initial value. This was probably safe, but a static analyzer correctly noticed that the status was ignored. Anyway, this is probably good practice. Andrew amdgcn: Check HSA return codes [PR94629] Ensure that the returned status values are not ignored. The old code was not broken, but this is both safer and satisfies static analysis. 2020-04-23 Andrew Stubbs PR other/94629 libgomp/ * plugin/plugin-gcn.c (init_hsa_context): Check return value from hsa_iterate_agents. (GOMP_OFFLOAD_init_device): Check return values from both calls to hsa_agent_iterate_regions. diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index dc72c90962c..4c6a4c03b6e 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -1508,6 +1508,8 @@ init_hsa_context (void) = GOMP_PLUGIN_malloc_cleared (hsa_context.agent_count * sizeof (struct agent_info)); status = hsa_fns.hsa_iterate_agents_fn (assign_agent_ids, &agent_index); + if (status != HSA_STATUS_SUCCESS) + return hsa_error ("Scanning compute agents failed", status); if (agent_index != hsa_context.agent_count) { GOMP_PLUGIN_error ("Failed to assign IDs to all GCN agents"); @@ -3473,6 +3475,9 @@ GOMP_OFFLOAD_init_device (int n) status = hsa_fns.hsa_agent_iterate_regions_fn (agent->id, get_kernarg_memory_region, &agent->kernarg_region); + if (status != HSA_STATUS_SUCCESS + && status != HSA_STATUS_INFO_BREAK) + hsa_error ("Scanning memory regions failed", status); if (agent->kernarg_region.handle == (uint64_t) -1) { GOMP_PLUGIN_error ("Could not find suitable memory region for kernel " @@ -3486,6 +3491,9 @@ GOMP_OFFLOAD_init_device (int n) status = hsa_fns.hsa_agent_iterate_regions_fn (agent->id, get_data_memory_region, &agent->data_region); + if (status != HSA_STATUS_SUCCESS + && status != HSA_STATUS_INFO_BREAK) + hsa_error ("Scanning memory regions failed", status); if (agent->data_region.handle == (uint64_t) -1) { GOMP_PLUGIN_error ("Could not find suitable memory region for device "