From patchwork Wed Aug 3 18:04:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9261703 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 A08C760754 for ; Wed, 3 Aug 2016 18:05:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9615C281F9 for ; Wed, 3 Aug 2016 18:05:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AE5C28249; Wed, 3 Aug 2016 18:05:32 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E71D9281F9 for ; Wed, 3 Aug 2016 18:05:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0259F6E89A; Wed, 3 Aug 2016 18:05:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1408C6E896 for ; Wed, 3 Aug 2016 18:05:02 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id o80so37486506wme.0 for ; Wed, 03 Aug 2016 11:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gkSOqM46k5a8R8GOwPRhSLZiBSmyQYkDcBRCF3nZ2RU=; b=ro/FWKxpjUc7JAg9M+apsVRkSHOb3iazdd3Plujd1oycb+rd0UiaDSmFht2sj5uCWV A/wj7rB8tDXK481nxJ5HcXbWOr/EqF2OSMDmL8JyCQeaq62JO7Apk+0AUmxNgUPR/3gX 0Mp/80kb3C2IlG2Q92Lexc95OICU/fyb36smURCIpHkvUd/JO43pvN9PspI7wIcxSJR4 SFCgSRchzPWntNR7pIADCZsb+ltIvMAFIC67lpc1DWenWHzS/Gia1f40/TU5PXRCZGb0 krGAv/+6T31je4OVL1gWTkT4hSviyNiRvlURvppaEVErnDFxQrlCNAxGQkXlZSwR4doF qLZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gkSOqM46k5a8R8GOwPRhSLZiBSmyQYkDcBRCF3nZ2RU=; b=ITmaQx2lwpWIpqMHhXNiBEjYQyJMicPDV4m+Z4whAIjyTOTC+lgfYrByezx7sbfmzg +MptdAAYrHc7EBBgIPprWnghhc4LftQQoS1tZ+gyEM9+H0/HBKaNHP/a+MvtTQY9x9L5 DMYhqyJJRIs1lFgi3Gqp3fgNC1FmcsrMcE9m36CaQxvVsE4un288xgKOc9xqBQa1OzdJ iq+2soWSLUjQYakeN+6p4ezcjtCHFvx5fZNkImO3DP6wnGS0TOTFY2ZgnlGslUxN+sK7 ZYjUxInqCXqtiTbCDA7C4lz6eXU6f+w9AmwX2RTmqrKgWhoTQFRocICsBq6X6Pk3N+sw zCDw== X-Gm-Message-State: AEkoouuzhYEIGGfnopmKBjFIqVpEz/TWWiOTNXXN9vnWIROQ3mHOCgDdvRCWfTuFCa6OJQ== X-Received: by 10.194.77.142 with SMTP id s14mr60985840wjw.77.1470247499164; Wed, 03 Aug 2016 11:04:59 -0700 (PDT) Received: from localhost.localdomain ([37.120.18.65]) by smtp.gmail.com with ESMTPSA id va3sm8854296wjb.18.2016.08.03.11.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2016 11:04:58 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/8] drm: make vma-manager entries untyped Date: Wed, 3 Aug 2016 20:04:28 +0200 Message-Id: <20160803180432.1341-5-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160803180432.1341-1-dh.herrmann@gmail.com> References: <20160803180432.1341-1-dh.herrmann@gmail.com> Cc: Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 Right now, the vma-manager requires all entries to provide a "struct file*" as identifier. This is confusing, since there is no inherent connection to "struct file" in the vma-manager at all, but it is exclusively used as tag. Replace its usage with a simple "void *tag" and make sure callers can use arbitrary tags. Signed-off-by: David Herrmann Reviewed-by: Chris Wilson --- drivers/gpu/drm/drm_vma_manager.c | 40 +++++++++++++++++++-------------------- include/drm/drm_vma_manager.h | 18 ++++++++---------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/drm_vma_manager.c b/drivers/gpu/drm/drm_vma_manager.c index f306c88..954248e 100644 --- a/drivers/gpu/drm/drm_vma_manager.c +++ b/drivers/gpu/drm/drm_vma_manager.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -277,9 +276,9 @@ EXPORT_SYMBOL(drm_vma_offset_remove); /** * drm_vma_node_allow - Add open-file to list of allowed users * @node: Node to modify - * @filp: Open file to add + * @tag: Tag of file to remove * - * Add @filp to the list of allowed open-files for this node. If @filp is + * Add @tag to the list of allowed open-files for this node. If @tag is * already on this list, the ref-count is incremented. * * The list of allowed-users is preserved across drm_vma_offset_add() and @@ -294,7 +293,7 @@ EXPORT_SYMBOL(drm_vma_offset_remove); * RETURNS: * 0 on success, negative error code on internal failure (out-of-mem) */ -int drm_vma_node_allow(struct drm_vma_offset_node *node, struct file *filp) +int drm_vma_node_allow(struct drm_vma_offset_node *node, void *tag) { struct rb_node **iter; struct rb_node *parent = NULL; @@ -315,10 +314,10 @@ int drm_vma_node_allow(struct drm_vma_offset_node *node, struct file *filp) parent = *iter; entry = rb_entry(*iter, struct drm_vma_offset_file, vm_rb); - if (filp == entry->vm_filp) { + if (tag == entry->vm_tag) { entry->vm_count++; goto unlock; - } else if (filp > entry->vm_filp) { + } else if (tag > entry->vm_tag) { iter = &(*iter)->rb_right; } else { iter = &(*iter)->rb_left; @@ -330,7 +329,7 @@ int drm_vma_node_allow(struct drm_vma_offset_node *node, struct file *filp) goto unlock; } - new->vm_filp = filp; + new->vm_tag = tag; new->vm_count = 1; rb_link_node(&new->vm_rb, parent, iter); rb_insert_color(&new->vm_rb, &node->vm_files); @@ -346,17 +345,17 @@ EXPORT_SYMBOL(drm_vma_node_allow); /** * drm_vma_node_revoke - Remove open-file from list of allowed users * @node: Node to modify - * @filp: Open file to remove + * @tag: Tag of file to remove * - * Decrement the ref-count of @filp in the list of allowed open-files on @node. - * If the ref-count drops to zero, remove @filp from the list. You must call - * this once for every drm_vma_node_allow() on @filp. + * Decrement the ref-count of @tag in the list of allowed open-files on @node. + * If the ref-count drops to zero, remove @tag from the list. You must call + * this once for every drm_vma_node_allow() on @tag. * * This is locked against concurrent access internally. * - * If @filp is not on the list, nothing is done. + * If @tag is not on the list, nothing is done. */ -void drm_vma_node_revoke(struct drm_vma_offset_node *node, struct file *filp) +void drm_vma_node_revoke(struct drm_vma_offset_node *node, void *tag) { struct drm_vma_offset_file *entry; struct rb_node *iter; @@ -366,13 +365,13 @@ void drm_vma_node_revoke(struct drm_vma_offset_node *node, struct file *filp) iter = node->vm_files.rb_node; while (likely(iter)) { entry = rb_entry(iter, struct drm_vma_offset_file, vm_rb); - if (filp == entry->vm_filp) { + if (tag == entry->vm_tag) { if (!--entry->vm_count) { rb_erase(&entry->vm_rb, &node->vm_files); kfree(entry); } break; - } else if (filp > entry->vm_filp) { + } else if (tag > entry->vm_tag) { iter = iter->rb_right; } else { iter = iter->rb_left; @@ -386,9 +385,9 @@ EXPORT_SYMBOL(drm_vma_node_revoke); /** * drm_vma_node_is_allowed - Check whether an open-file is granted access * @node: Node to check - * @filp: Open-file to check for + * @tag: Tag of file to remove * - * Search the list in @node whether @filp is currently on the list of allowed + * Search the list in @node whether @tag is currently on the list of allowed * open-files (see drm_vma_node_allow()). * * This is locked against concurrent access internally. @@ -396,8 +395,7 @@ EXPORT_SYMBOL(drm_vma_node_revoke); * RETURNS: * true iff @filp is on the list */ -bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, - struct file *filp) +bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, void *tag) { struct drm_vma_offset_file *entry; struct rb_node *iter; @@ -407,9 +405,9 @@ bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, iter = node->vm_files.rb_node; while (likely(iter)) { entry = rb_entry(iter, struct drm_vma_offset_file, vm_rb); - if (filp == entry->vm_filp) + if (tag == entry->vm_tag) break; - else if (filp > entry->vm_filp) + else if (tag > entry->vm_tag) iter = iter->rb_right; else iter = iter->rb_left; diff --git a/include/drm/drm_vma_manager.h b/include/drm/drm_vma_manager.h index 06ea8e07..6edc968 100644 --- a/include/drm/drm_vma_manager.h +++ b/include/drm/drm_vma_manager.h @@ -24,7 +24,6 @@ */ #include -#include #include #include #include @@ -33,7 +32,7 @@ struct drm_vma_offset_file { struct rb_node vm_rb; - struct file *vm_filp; + void *vm_tag; unsigned long vm_count; }; @@ -62,10 +61,9 @@ int drm_vma_offset_add(struct drm_vma_offset_manager *mgr, void drm_vma_offset_remove(struct drm_vma_offset_manager *mgr, struct drm_vma_offset_node *node); -int drm_vma_node_allow(struct drm_vma_offset_node *node, struct file *filp); -void drm_vma_node_revoke(struct drm_vma_offset_node *node, struct file *filp); -bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, - struct file *filp); +int drm_vma_node_allow(struct drm_vma_offset_node *node, void *tag); +void drm_vma_node_revoke(struct drm_vma_offset_node *node, void *tag); +bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, void *tag); /** * drm_vma_offset_exact_lookup_locked() - Look up node by exact address @@ -216,9 +214,9 @@ static inline void drm_vma_node_unmap(struct drm_vma_offset_node *node, /** * drm_vma_node_verify_access() - Access verification helper for TTM * @node: Offset node - * @filp: Open-file + * @tag: Tag of file to check * - * This checks whether @filp is granted access to @node. It is the same as + * This checks whether @tag is granted access to @node. It is the same as * drm_vma_node_is_allowed() but suitable as drop-in helper for TTM * verify_access() callbacks. * @@ -226,9 +224,9 @@ static inline void drm_vma_node_unmap(struct drm_vma_offset_node *node, * 0 if access is granted, -EACCES otherwise. */ static inline int drm_vma_node_verify_access(struct drm_vma_offset_node *node, - struct file *filp) + void *tag) { - return drm_vma_node_is_allowed(node, filp) ? 0 : -EACCES; + return drm_vma_node_is_allowed(node, tag) ? 0 : -EACCES; } #endif /* __DRM_VMA_MANAGER_H__ */