From patchwork Fri May 18 17:00:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vesely X-Patchwork-Id: 10411559 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 26CF4602C2 for ; Fri, 18 May 2018 17:00:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1655628A00 for ; Fri, 18 May 2018 17:00:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B27C28A0D; Fri, 18 May 2018 17:00:16 +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 7A6D728A00 for ; Fri, 18 May 2018 17:00:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E4456EE7A; Fri, 18 May 2018 17:00:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3102C6EE50 for ; Fri, 18 May 2018 17:00:11 +0000 (UTC) Received: by mail-qt0-x241.google.com with SMTP id m5-v6so11150752qti.1 for ; Fri, 18 May 2018 10:00:11 -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=IF3UrJDQb2XIMJ/EnoS6doSPSAFVZpaDVKG7pXqAXko=; b=o6MPaNgm9iL4cIas3mBlSI4WKc+USbSFmvHG5bT1JeQEXHF3SrUUxfullUHz4FDHBx bcSmH2LpvIbq8cd2rFFYlQhEQ6X1fHfccnOJhUNDkCLbbfEg170+kDOLAaWOxHLEjvCF BoOBR8eKnq224MV0SpHpqoR7u02MtPucHoV9/qDkS4g9PTiJ8TB3KCXpcJHbp+MNibgT IzRYLmk0STGxH0mKVQzsqsNBwK2E8hcjYs8MIJs0HD9LyEfqb3RsCG6cL/DJeb+e29tw uK8Ns1R6GmTXCB+QsZWeoT1x3wIllq1KD2EV8eIFIUmWSdBWv5EsEdOXaaP48JHzOlnW erBQ== 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=IF3UrJDQb2XIMJ/EnoS6doSPSAFVZpaDVKG7pXqAXko=; b=qkBdNvjVjB7F99qtC5yYU7OO6UE0PLqMKIBnyWZb9n9d9jhYCGLI3aV08DstcpulG7 HDfE/QynVGdOUlA2QBN3/1XBQvHiJCcIxVGYMVM8wifoJ4Hf3ch7uW8+Mb6hixbyBJgN KBeHg74gStCEA6HIXwbeKSVqxah204ix/Uy5nXv+bt7xtHvOHo4NJmi+iWkhbyrQEPrY 68+LD/KExQHyk8anVJpal30ZIYexbpolT3mxw3TU6Cl/AxFLHtU75XPTq5sEREIN5IpS yCIRI+P7SOTN+/63t1t66eRFrn6EWDO5F9Eiy4Ek/L1TM2OxU6yHw/7PiWx3GSCyxCTV Gg/g== X-Gm-Message-State: ALKqPwerr9eGHyiDCkTjKUlDHsfxdGCzNosYS5MtPEF0lCJjZj/jO9jz onR5w6jseEJzKBBxMVEpjT7r7epG8ZE= X-Google-Smtp-Source: AB8JxZoH2OkRXs+qqAkd6IwjOgjyM3geXI1qrsY0NtAJM8WvjwIROdYBz2EqM4x/7KqspmF96qudsQ== X-Received: by 2002:ac8:41cc:: with SMTP id o12-v6mr9926878qtm.227.1526662810067; Fri, 18 May 2018 10:00:10 -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 b27-v6sm5969152qtc.66.2018.05.18.10.00.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 10:00:08 -0700 (PDT) From: Jan Vesely To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH libdrm v2 1/3] amdgpu: Take lock before removing devices from fd_tab hash table. Date: Fri, 18 May 2018 13:00:05 -0400 Message-Id: <20180518170007.2847-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. v2: close fds after removing from hash table 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..e23dd3b3 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); + 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); + 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); }