From patchwork Wed Oct 2 11:24:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 2974411 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1C2509F245 for ; Wed, 2 Oct 2013 11:26:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5AB8420207 for ; Wed, 2 Oct 2013 11:26:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3D6A9201F4 for ; Wed, 2 Oct 2013 11:26:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1661BE7749 for ; Wed, 2 Oct 2013 04:26:29 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com [74.125.83.52]) by gabe.freedesktop.org (Postfix) with ESMTP id 75841E5CC4 for ; Wed, 2 Oct 2013 04:25:05 -0700 (PDT) Received: by mail-ee0-f52.google.com with SMTP id c41so313572eek.25 for ; Wed, 02 Oct 2013 04:25:04 -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; bh=/Rk6zGjKzFFxjSAYS+LYOFthoebxz1NzKYq0SAdUguU=; b=e2D9bsLt7fgtdRMpxS4/Sr3nG6XRM+892I+oi+frm4C9RfaSX418aUUICXI/QXnKUE myVg2xip/avW9HLxRbo2ZpOg6LdYcVbLi+Y5UhlCu9zq+NS2tV8dr11Rz3HGL255lZfx wFJDxj0NH0hZswVqn3adFy0Ea3uK/Io+g+IqqQP3vSiK0WydQIdN9R8Dc5JMENZN/2PC dSx33IP8OXzSQzVw1L9ZSkZm5vSQWQxQsnFOT09088DG1hDOedXZtcIfL1bZoFFWomdw DewHgdTTe6pGIh7T18vZK3GZkOMyxhP2O76xgWBR8wI7kE1V66ArSULVMAbsh8TiZtnI lORw== X-Received: by 10.14.32.129 with SMTP id o1mr2893617eea.47.1380713104437; Wed, 02 Oct 2013 04:25:04 -0700 (PDT) Received: from localhost.localdomain (stgt-5f71b885.pool.mediaWays.net. [95.113.184.133]) by mx.google.com with ESMTPSA id d8sm2750955eeh.8.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Oct 2013 04:25:03 -0700 (PDT) From: David Herrmann To: Linus Torvalds , Al Viro Subject: [PATCH v2 1/2] anon_inodes: allow external inode allocations Date: Wed, 2 Oct 2013 13:24:25 +0200 Message-Id: <1380713066-32519-1-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 1.8.4 Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Wanted-by: Daniel Vetter --- 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 */