From patchwork Mon Mar 26 19:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 10308501 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 9195F600CC for ; Mon, 26 Mar 2018 19:00:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F97128F80 for ; Mon, 26 Mar 2018 19:00:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72EEA29762; Mon, 26 Mar 2018 19:00:52 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 B5E9628F80 for ; Mon, 26 Mar 2018 19:00:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 78A306E1E6; Mon, 26 Mar 2018 19:00:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id F413B6E1E6 for ; Mon, 26 Mar 2018 19:00:47 +0000 (UTC) Received: by mail-pf0-x242.google.com with SMTP id u5so7894153pfh.6 for ; Mon, 26 Mar 2018 12:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=a7Dl0xxkNFP3feHOLEOt/R5716RuZK2ghwLGgM11jII=; b=EUncTLiK9xWuVYqT+JNYjoYFoNaIgFk7iIo8XNTDTqYh0rh5oDYDMqDurdpplns6aV C+/CONND+ToAv4h0fJPdKVEAV5hnfHEomREFXamiasnThbm6aVadB8Abn0hl2iPNnETl zihpQKkQTimzo6eR7tGBmQa0YUzNP0YU4CZQ9VtJetrU8pNWtMkbjaihkB+JkV4dsuZG /u2AA35O8iBuLRmwAqe4MGBE87tEozYEKNmYL0T7YcFk2wzEpfDMt80e8hPnJq6JpR2+ QJUwLGxdLh0EoxCwUc2xI22yhl5jLhhQY6/8njbW3balBn4h7wUH3Mwxlv+s/SSMVxf3 jV3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=a7Dl0xxkNFP3feHOLEOt/R5716RuZK2ghwLGgM11jII=; b=Kb7uwMOMs9Z/TTARkB6NPEX0qxnJCmFXxv1bi4SKKwfuAwtfXsTGACT2sCrUKAkt7t VhUfJtI2v3qmSYwmu85hTb6nWf0+Cxkc6KwXUXR+gYIJ7THvKXDqfknYKB04mHoEGypS +Ac8heLo23dDZTKUu0FYFcsgSZGv89G7YQDbvEspx+58QiHIVKWhymJn9ZinWlwprsDN 7QU4yOBp8gj1OFGIgg/nO+poOh6d9tft1IHJm3bu6ZNWpneK6q+uvxQbvZJJjmAftwCx lDmhjZOZBODssRzyC6PWUW16N+yBFscZlGtqPq4GdlXSFgB4hiQFo052Xcne1r6xHDIt re1Q== X-Gm-Message-State: AElRT7G08kTqYnjJ8CeTDxTkR21iCgmfAGGdFhSL7XwKRLtNBm4tOLfP 9UWaLh6h/1ILrbVI1a1ybLVloQ== X-Google-Smtp-Source: AIpwx484EmVHeQvM/p4alZ5S+OoM84Kv4wDhHO6W8pZX4IQeGpNzkaEei93JkFrqvipa1dxzDOxR6A== X-Received: by 10.98.171.25 with SMTP id p25mr1319204pff.227.1522090847454; Mon, 26 Mar 2018 12:00:47 -0700 (PDT) Received: from omlet.jf.intel.com (fmdmzpr04-ext.fm.intel.com. [192.55.54.39]) by smtp.gmail.com with ESMTPSA id c62sm34232303pfk.179.2018.03.26.12.00.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Mar 2018 12:00:46 -0700 (PDT) From: Jason Ekstrand X-Google-Original-From: Jason Ekstrand To: stable@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH] drm/syncobj: Stop reusing the same struct file for all syncobj -> fd Date: Mon, 26 Mar 2018 12:00:37 -0700 Message-Id: <1522090837-13789-1-git-send-email-jason.ekstrand@intel.com> X-Mailer: git-send-email 2.5.0.400.gff86faf 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: , Cc: Dave Airlie , Jason Ekstrand MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Wilson The vk cts test: dEQP-VK.api.external.semaphore.opaque_fd.export_multiple_times_temporary triggers a lot of VFS: Close: file count is 0 Dave pointed out that clearing the syncobj->file from drm_syncobj_file_release() was sufficient to silence the test, but that opens a can of worm since we assumed that the syncobj->file was never unset. Stop trying to reuse the same struct file for every fd pointing to the drm_syncobj, and allocate one file for each fd instead. v2: Fixup return handling of drm_syncobj_fd_to_handle v2.1: [airlied: fix possible syncobj ref race] v2.2: [jekstrand: back-port to 4.14] Reported-by: Dave Airlie Signed-off-by: Chris Wilson Tested-by: Dave Airlie Reviewed-by: Daniel Vetter Signed-off-by: Dave Airlie Signed-off-by: Jason Ekstrand Tested-by: Clayton Craft --- The back-port from 4.15 to 4.14 was non-trivial. It'd be good if Chris and maybe Daniel could do a quick re-review. drivers/gpu/drm/drm_syncobj.c | 81 ++++++++++++++++--------------------------- include/drm/drm_syncobj.h | 5 --- 2 files changed, 30 insertions(+), 56 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 0422b8c..7bcf570 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -328,28 +328,11 @@ static const struct file_operations drm_syncobj_file_fops = { .release = drm_syncobj_file_release, }; -static int drm_syncobj_alloc_file(struct drm_syncobj *syncobj) -{ - struct file *file = anon_inode_getfile("syncobj_file", - &drm_syncobj_file_fops, - syncobj, 0); - if (IS_ERR(file)) - return PTR_ERR(file); - - drm_syncobj_get(syncobj); - if (cmpxchg(&syncobj->file, NULL, file)) { - /* lost the race */ - fput(file); - } - - return 0; -} - static int drm_syncobj_handle_to_fd(struct drm_file *file_private, u32 handle, int *p_fd) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); - int ret; + struct file *file; int fd; if (!syncobj) @@ -361,46 +344,40 @@ static int drm_syncobj_handle_to_fd(struct drm_file *file_private, return fd; } - if (!syncobj->file) { - ret = drm_syncobj_alloc_file(syncobj); - if (ret) - goto out_put_fd; + file = anon_inode_getfile("syncobj_file", + &drm_syncobj_file_fops, + syncobj, 0); + if (IS_ERR(file)) { + put_unused_fd(fd); + drm_syncobj_put(syncobj); + return PTR_ERR(file); } - fd_install(fd, syncobj->file); - drm_syncobj_put(syncobj); + + drm_syncobj_get(syncobj); + fd_install(fd, file); + *p_fd = fd; return 0; -out_put_fd: - put_unused_fd(fd); - drm_syncobj_put(syncobj); - return ret; } -static struct drm_syncobj *drm_syncobj_fdget(int fd) -{ - struct file *file = fget(fd); - - if (!file) - return NULL; - if (file->f_op != &drm_syncobj_file_fops) - goto err; - - return file->private_data; -err: - fput(file); - return NULL; -}; - static int drm_syncobj_fd_to_handle(struct drm_file *file_private, int fd, u32 *handle) { - struct drm_syncobj *syncobj = drm_syncobj_fdget(fd); + struct drm_syncobj *syncobj; + struct file *file; int ret; - if (!syncobj) + file = fget(fd); + if (!file) + return -EINVAL; + + if (file->f_op != &drm_syncobj_file_fops) { + fput(file); return -EINVAL; + } /* take a reference to put in the idr */ + syncobj = file->private_data; drm_syncobj_get(syncobj); idr_preload(GFP_KERNEL); @@ -409,12 +386,14 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, spin_unlock(&file_private->syncobj_table_lock); idr_preload_end(); - if (ret < 0) { - fput(syncobj->file); - return ret; - } - *handle = ret; - return 0; + if (ret > 0) { + *handle = ret; + ret = 0; + } else + drm_syncobj_put(syncobj); + + fput(file); + return ret; } int drm_syncobj_import_sync_file_fence(struct drm_file *file_private, diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h index c00fee5..6d45aae 100644 --- a/include/drm/drm_syncobj.h +++ b/include/drm/drm_syncobj.h @@ -60,11 +60,6 @@ struct drm_syncobj { * locks cb_list and write-locks fence. */ spinlock_t lock; - /** - * @file: - * a file backing for this syncobj. - */ - struct file *file; }; typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj,