linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Anonymous Inode Allocations
@ 2013-07-10 23:45 David Herrmann
  2013-07-10 23:45 ` [PATCH 1/2] anon_inodes: allow external inode allocations David Herrmann
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: David Herrmann @ 2013-07-10 23:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: dri-devel, Alexander Viro, Dave Airlie, linux-fsdevel,
	Andrew Morton, Daniel Vetter, David Herrmann

Hi

This implements anon_inodes_new() to create anonymous inodes. Patch #1
describes the changes to anon_inodes.c and why DRM could make great use of this.
Patch #2 converts DRM core to use anon_inodes_new() instead of delayed
dev_mapping initialization (but kept simple, TTM can be converted later).

The idea is to get an anonymous backing inode for DRM devices without waiting
for the first char-dev inode. We use it to unmap userspace mappings via
unmap_mapping_range() if we have to evict buffers if GTT runs short or if the FW
framebuffers are destroyed.
We need the inode only once the first user-space mapping was created, but the
delayed initialization causes an ugly code base and keeps inodes of char-devs
around just to preserve the address_space.

We actually only need the address_space, but mm core requires an corresponding
file* and FS core requires mapping->host to be set (although I am not sure
whether we can hit those paths with char-devs). So I went with the whole
anonymous inode approach.

If anyone has an idea how to use an embedded "struct address_space" inside of
"drm_device" and set "dev_mapping->host" to the shared anon_inode_inode, I'd be
happy to implement it. However, I didn't succeed and I am actually not sure that
separate "struct address_space" are actually supported. For instance, DRM core
uses code like:
  container_of(dev_mapping, struct inode, i_data)
So I didn't spent much time on that approach.

Cheers
David

David Herrmann (2):
  anon_inodes: allow external inode allocations
  DRM: use anon_inode instead of delayed inode init

 drivers/gpu/drm/drm_drv.c              |  1 -
 drivers/gpu/drm/drm_fops.c             | 24 +++--------------------
 drivers/gpu/drm/drm_stub.c             | 12 +++++++++++-
 drivers/gpu/drm/i915/i915_gem.c        |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_gem.c  |  2 +-
 drivers/gpu/drm/omapdrm/omap_gem.c     |  7 ++++---
 drivers/gpu/drm/qxl/qxl_object.c       |  2 +-
 drivers/gpu/drm/qxl/qxl_ttm.c          |  2 +-
 drivers/gpu/drm/radeon/radeon_object.c |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c    |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c    |  2 +-
 fs/anon_inodes.c                       | 36 +++++++++++++++++++++++++++-------
 include/drm/drmP.h                     |  2 +-
 include/linux/anon_inodes.h            |  1 +
 14 files changed, 57 insertions(+), 42 deletions(-)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH v2 1/2] anon_inodes: allow external inode allocations
@ 2013-10-02 11:24 David Herrmann
  2013-10-02 11:24 ` [PATCH 2/2] DRM: use anon_inode instead of delayed inode init David Herrmann
  0 siblings, 1 reply; 12+ messages in thread
From: David Herrmann @ 2013-10-02 11:24 UTC (permalink / raw)
  To: Linus Torvalds, Al Viro
  Cc: linux-fsdevel, linux-kernel, dri-devel, David Herrmann

DRM core shares a single address_space across all inodes that belong to
the same DRM device. This allows efficient unmapping of user-space
mappings during buffer eviction. However, there is no easy way to get a
shared address_space for DRM devices during initialization. Therefore, we
currently delay this step until the first ->open() and save the given
inode for future use.

This causes ugly delayed initialization throughout the DRM core. TTM
devices end up without a dev_mapping pointer and we have to carefully
respect any underlying filesystem implementation so we don't corrupt the
inode->i_mapping and inode->i_data fields.

We can avoid this if we were allowed to allocate an anonymous inode for
each DRM device. We only have to set file->f_mapping during ->open()
and no longer need to adjust inode mappings. As fs/anon_inodes.c already
provides a minimal internal FS mount, we extend it to also provide
anonymous inodes for use in drivers like DRM.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Wanted-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
Hi Linus & Al

Any chance I could get an ACK on this? It's fairly trivial and allows us to
simplify the DRM logic quite a bit (see patch 2/2 and I have 2 more DRM cleanup
patches pending). This has been pending on fsdevel for 2 months now and all we
need is an ACK from an VFS maintainer.

I ditched the idea to allocate "struct address_space" separately in DRM as akpm
told me that this might get messy without an underlying inode. So I think the
anon-inode approach is the way to go.

Thanks
David

 fs/anon_inodes.c            | 36 +++++++++++++++++++++++++++++-------
 include/linux/anon_inodes.h |  1 +
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 85c9618..35263a3 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -25,6 +25,7 @@
 static struct vfsmount *anon_inode_mnt __read_mostly;
 static struct inode *anon_inode_inode;
 static const struct file_operations anon_inode_fops;
+static struct dentry *anon_inode_root;
 
 /*
  * anon_inodefs_dname() is called from d_path().
@@ -87,19 +88,18 @@ static struct inode *anon_inode_mkinode(struct super_block *s)
 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
 				int flags, const char *dev_name, void *data)
 {
-	struct dentry *root;
-	root = mount_pseudo(fs_type, "anon_inode:", NULL,
+	anon_inode_root = mount_pseudo(fs_type, "anon_inode:", NULL,
 			&anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
-	if (!IS_ERR(root)) {
-		struct super_block *s = root->d_sb;
+	if (!IS_ERR(anon_inode_root)) {
+		struct super_block *s = anon_inode_root->d_sb;
 		anon_inode_inode = anon_inode_mkinode(s);
 		if (IS_ERR(anon_inode_inode)) {
-			dput(root);
+			dput(anon_inode_root);
 			deactivate_locked_super(s);
-			root = ERR_CAST(anon_inode_inode);
+			anon_inode_root = ERR_CAST(anon_inode_inode);
 		}
 	}
-	return root;
+	return anon_inode_root;
 }
 
 static struct file_system_type anon_inode_fs_type = {
@@ -285,6 +285,28 @@ err_put_unused_fd:
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfd);
 
+/**
+ * anon_inode_new - create private anonymous inode
+ *
+ * Creates a new inode on the anonymous inode FS for driver's use. The inode has
+ * it's own address_space compared to the shared anon_inode_inode. It can be
+ * used in situations where user-space mappings have to be shared across
+ * different files but no backing inode is available.
+ *
+ * Call iput(inode) to release the inode.
+ *
+ * RETURNS:
+ * New inode on success, error pointer on failure.
+ */
+struct inode *anon_inode_new(void)
+{
+	if (IS_ERR(anon_inode_root))
+		return ERR_CAST(anon_inode_root);
+
+	return anon_inode_mkinode(anon_inode_root->d_sb);
+}
+EXPORT_SYMBOL_GPL(anon_inode_new);
+
 static int __init anon_inode_init(void)
 {
 	int error;
diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h
index cf573c2..d17378c 100644
--- a/include/linux/anon_inodes.h
+++ b/include/linux/anon_inodes.h
@@ -18,6 +18,7 @@ struct file *anon_inode_getfile_private(const char *name,
 				void *priv, int flags);
 int anon_inode_getfd(const char *name, const struct file_operations *fops,
 		     void *priv, int flags);
+struct inode *anon_inode_new(void);
 
 #endif /* _LINUX_ANON_INODES_H */
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-10-02 11:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-10 23:45 [PATCH 0/2] Anonymous Inode Allocations David Herrmann
2013-07-10 23:45 ` [PATCH 1/2] anon_inodes: allow external inode allocations David Herrmann
2013-07-11  6:29   ` Daniel Vetter
2013-07-24  9:45   ` David Herrmann
2013-07-10 23:45 ` [PATCH 2/2] DRM: use anon_inode instead of delayed inode init David Herrmann
2013-07-11  6:57   ` Daniel Vetter
2013-08-13 17:42 ` [PATCH v2 0/4] Anonymous Inode Allocations David Herrmann
2013-08-13 17:42   ` [PATCH v2 1/4] anon_inodes: allow external inode allocations David Herrmann
2013-08-13 17:42   ` [PATCH v2 2/4] DRM: use anon_inode instead of delayed inode init David Herrmann
2013-08-13 17:42   ` [PATCH v2 3/4] drm: init TTM dev_mapping in ttm_bo_device_init() David Herrmann
2013-08-13 17:42   ` [PATCH v2 4/4] drm/omap: remove useless if() in evict_entry() David Herrmann
  -- strict thread matches above, loose matches on Subject: below --
2013-10-02 11:24 [PATCH v2 1/2] anon_inodes: allow external inode allocations David Herrmann
2013-10-02 11:24 ` [PATCH 2/2] DRM: use anon_inode instead of delayed inode init David Herrmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).