From patchwork Thu May 10 23:33:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vesely X-Patchwork-Id: 10392585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1351460236 for ; Thu, 10 May 2018 23:33:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA40728B29 for ; Thu, 10 May 2018 23:33:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF09028BF3; Thu, 10 May 2018 23:33:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4121F28B29 for ; Thu, 10 May 2018 23:33:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DBC836E2C9; Thu, 10 May 2018 23:33:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id A0D106E2C9 for ; Thu, 10 May 2018 23:33:18 +0000 (UTC) Received: by mail-qk0-x244.google.com with SMTP id l132-v6so3006038qke.3 for ; Thu, 10 May 2018 16:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scarletmail-rutgers-edu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:subject:date:message-id; bh=g+Ra2FDISHn1vAffEoa5KW62Ebp0AHwF5qTBUdQS9zo=; b=ZFc8xyvaIumc5u7fCHk7B0fmm9vzoL/9gDeDlx6PXvzE61vHqYWj0bMILOqUib36h/ gvUioduWisIHUt+a3D39kkXWM37N/urEas/niCRu6NdSgnnXvYUlzkG6y+zJuf5vr2KA kinRil+TXVrNsPeIYgQzM84lGADrULAeDn4z5S2fjzYMCxVGIPvN8pOHPkUlPClUBSIj o8TCopiEyfVlnMB0YyHICk50lTORlqXq9+qCzob1eF28/QphW4jssvJnbB7VmrbRoysj 0uOCdSISrQYGPSBsOaYnkECwSkrBbB+JLoXJJ692KrQ7QTSAY93AfBDxiWoWNQ40qdcs xl1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id; bh=g+Ra2FDISHn1vAffEoa5KW62Ebp0AHwF5qTBUdQS9zo=; b=eh1FcLZ3PFbMovaqMp2viLswDJcAlVgpeQc7hl7EpaxVQJEXX4aRZT+ZfFDpii+Suf 9o7e3YYtMUzO5Ns4ADBfQqPdYyn7XuJsLg8kLvN/9nJTW9C2joEEn6MY9rbzgmt5Nz42 +mhwHWKK3TO35U3sgKx7DdA7hN89L43eu21zEXNQ8oJvEF2pa9z02bEk7sOpx7At9642 5VXoNyDhSY7OQaVn4k5AlMrMAUm8NCUJlZydyiUQ9dDzP3/rnBZUoogc4oxMNG9Kcpr3 tT/n2cagJLcA2sLzoZ7FJ9DKM5tDyiMEsi2l3zgDFcq3fvtutNI2MkVPcgwL5NAISzSZ oRIA== X-Gm-Message-State: ALKqPwcwNND0l0pmIX+WMZr0H1mfe9tD46DDy1DktQT2blOcvOEZQoYt Gs/JJoJdr/3Tywbh4ZZm68Dr1GUKrDE= X-Google-Smtp-Source: AB8JxZr6NUf69xEwWbOuebcKUFM7bMkeUN9bUmLPmQ9g2F9DzETAZuUm7t6hFwQmeN41nTUFXXXNdw== X-Received: by 2002:a37:15ea:: with SMTP id 103-v6mr3121798qkv.349.1525995197813; Thu, 10 May 2018 16:33:17 -0700 (PDT) Received: from adriatix.rutgers.edu (pool-128-6-37-254.nat.rutgers.edu. [128.6.37.254]) by smtp.gmail.com with ESMTPSA id w51-v6sm1512697qtc.97.2018.05.10.16.33.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 16:33:17 -0700 (PDT) From: Jan Vesely To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/1] amdgpu: Take lock before removing devices from fd_tab hash table. Date: Thu, 10 May 2018 19:33:16 -0400 Message-Id: <20180510233316.21437-1-jan.vesely@rutgers.edu> X-Mailer: git-send-email 2.17.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Close the file descriptors under lock as well. Signed-off-by: Jan Vesely --- amdgpu/amdgpu_device.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c index 983b19ab..f71fc050 100644 --- a/amdgpu/amdgpu_device.c +++ b/amdgpu/amdgpu_device.c @@ -126,6 +126,13 @@ static int amdgpu_get_auth(int fd, int *auth) static void amdgpu_device_free_internal(amdgpu_device_handle dev) { + pthread_mutex_lock(&fd_mutex); + close(dev->fd); + if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd)) + close(dev->flink_fd); + util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd)); + pthread_mutex_unlock(&fd_mutex); + amdgpu_vamgr_deinit(&dev->vamgr_32); amdgpu_vamgr_deinit(&dev->vamgr); amdgpu_vamgr_deinit(&dev->vamgr_high_32); @@ -133,10 +140,6 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev) util_hash_table_destroy(dev->bo_flink_names); util_hash_table_destroy(dev->bo_handles); pthread_mutex_destroy(&dev->bo_table_mutex); - util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd)); - close(dev->fd); - if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd)) - close(dev->flink_fd); free(dev->marketing_name); free(dev); }