Received: by 10.213.65.68 with SMTP id h4csp876862imn; Tue, 27 Mar 2018 10:24:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/62Hi14Nm5oqm+WSJE+QcXTVfxbYKTJY17gU9TdK2EeXrEs5VdVYYtqlXJpFpG398nkRgz X-Received: by 2002:a17:902:2f:: with SMTP id 44-v6mr181457pla.187.1522171477566; Tue, 27 Mar 2018 10:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522171477; cv=none; d=google.com; s=arc-20160816; b=lUeJStmRTKP0mtfyrfk2CXb3L1GN8zWYwU3t5rpdTRrOqmPbTagF8dC+nl7QRVjaTv FDpsvuZJGCn0VHCT/nb6AEv3HAjphxSSzqg+lVM2lrhS90HKDsFw7uuQgztaYkFFmzfg QeBBGASfNjZXukRYm3emgmOk7zwa4u7i18SFxHgHr8c5hdgW9FslBx/FGsctDHQk4mmd hgtOyFeXAduUyKrIxDcSwsAv+GKcw6rtrbnpi84olJ1UKdNfQ9bTIKIcAFvoAXUySElr +3qRsNVPCFlgx4+b0/MMzs9O1BF81WB3IA0JNZEZpwUU5lrWYguiE7puYcmR/pNGNbb7 Y1PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=odODr9SQf+cWPpCy2zJHWmTHjqUQDDthLflWwCxUdQ8=; b=I0jXWMtkHoNYlubJ/PuEVksv7hXIq6H3AA6vVW4fqz5bTB8yEgxaYGuyBWXU7qkfbh SrGpzUxziJJ3dpfbH1HVtw+/UPfuhHIO6FFWE92FXwPZDA4FqFVIFDxCCurfUkPIsJjc 0icMxilOTahMQ9udq9LMiRSEh+j0cvpqXUFMH8lL8K0eEANUcQjo7BUayfrHByPhXgRR sX5AGE12Kc9zOqm046Oc+1uyVSFT9/+9PSZHmoYMqCf4xZGY10Kv4Dw+ibbYw17jtjed ydDviSw9vBv8Ba9UR/p0HKu+ZA7lu0YfEllfuycymBh6sykx3xJzoK2pNQu/eZO/WG8i 5dMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 85si1099232pfo.234.2018.03.27.10.24.23; Tue, 27 Mar 2018 10:24:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755006AbeC0Qhl (ORCPT + 99 others); Tue, 27 Mar 2018 12:37:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46364 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754991AbeC0Qhi (ORCPT ); Tue, 27 Mar 2018 12:37:38 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 65E58FC7; Tue, 27 Mar 2018 16:37:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Airlie , Chris Wilson , Daniel Vetter , Jason Ekstrand , Clayton Craft Subject: [PATCH 4.14 086/101] drm/syncobj: Stop reusing the same struct file for all syncobj -> fd Date: Tue, 27 Mar 2018 18:27:58 +0200 Message-Id: <20180327162755.341782872@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Wilson commit e7cdf5c82f1773c3386b93bbcf13b9bfff29fa31 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_syncobj.c | 81 +++++++++++++++--------------------------- include/drm/drm_syncobj.h | 5 -- 2 files changed, 30 insertions(+), 56 deletions(-) --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -328,28 +328,11 @@ static const struct file_operations drm_ .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(stru 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(stru 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, --- 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,