From patchwork Fri Jan 3 14:41:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 3431471 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 19ACAC02DC for ; Fri, 3 Jan 2014 14:42:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D70BD20108 for ; Fri, 3 Jan 2014 14:42:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 947E9200C1 for ; Fri, 3 Jan 2014 14:42:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D9AB9FA80A; Fri, 3 Jan 2014 06:42:12 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ee0-f50.google.com (mail-ee0-f50.google.com [74.125.83.50]) by gabe.freedesktop.org (Postfix) with ESMTP id D45F2FA80A for ; Fri, 3 Jan 2014 06:42:09 -0800 (PST) Received: by mail-ee0-f50.google.com with SMTP id c41so6911760eek.9 for ; Fri, 03 Jan 2014 06:42:09 -0800 (PST) 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=petVgDgsWluFuw8E5S6uWdkDJFxDqH01PKL+zPL2axQ=; b=odBnqdJ1bn+fYsXQZRctbCFQeZ3fbBKjUVqyyH6kForm8FO5zqW7i2Pl6Rx51LUxbe gHXOyAIzSrryL5dJwzoFXQsMl2Tn/zjHMwZnFCnR0nHLBkjeELVoq+PqXjdAybykkavm qu37jv6JqKiMGWb/dSInN2S+4MSmxLSWkBOAn0q3TJeQWFcy/OOzI40hs/BsqJkKIiLN 4AVDz78ZkX8mVKS9PJeTQ4ezOSzNzHe5dBoR7620dpqkw1y30eaCieR6fxyroqe1TkQJ ZnlEe/oL9Xpy+mfO/967QSRWzTYVNHiHGyva4990PuTRA04VJ6m2rwXAO3VZBgbIJ08U mxiA== X-Received: by 10.15.36.135 with SMTP id i7mr2193658eev.93.1388760129020; Fri, 03 Jan 2014 06:42:09 -0800 (PST) Received: from david-mb.uni-tuebingen.de (stgt-4d02467d.pool.mediaWays.net. [77.2.70.125]) by mx.google.com with ESMTPSA id 44sm145511028eek.5.2014.01.03.06.42.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Jan 2014 06:42:08 -0800 (PST) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [RFC v2 1/3] drm: add pseudo filesystem for shared inodes Date: Fri, 3 Jan 2014 15:41:25 +0100 Message-Id: <1388760087-17746-2-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1388760087-17746-1-git-send-email-dh.herrmann@gmail.com> References: <1388760087-17746-1-git-send-email-dh.herrmann@gmail.com> Cc: Daniel Vetter 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@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.6 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 Our current DRM design uses a single address_space for all users of the same DRM device. However, there is no way to create an anonymous address_space without an underlying inode. Therefore, we wait for the first ->open() callback on a registered char-dev and take-over the inode of the char-dev. This worked well so far, but has several drawbacks: - We screw with FS internals and rely on some non-obvious invariants like inode->i_mapping being the same as inode->i_data for char-devs. - We don't have any address_space prior to the first ->open() from user-space. This leads to ugly fallback code and we cannot allocate global objects early. As pointed out by Al-Viro, fs/anon_inode.c is *not* supposed to be used by drivers for anonymous inode-allocation. Therefore, this patch follows the proposed alternative solution and adds a pseudo filesystem mount-point to DRM. We can then allocate private inodes including a private address_space for each DRM device at initialization time. Note that we could use: sysfs_get_inode(sysfs_mnt->mnt_sb, drm_device->dev->kobj.sd); to get access to the underlying sysfs-inode of a "struct device" object. However, most of this information is currently hidden and it's not clear whether this address_space is suitable for driver access. Thus, unless linux allows anonymous address_space objects or driver-core provides a public inode per device, we're left with our own private internal mount point. Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_drv.c | 37 +++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 1 + 2 files changed, 38 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 345be03..48ee03f 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -49,6 +49,8 @@ #include #include #include +#include +#include #include #include @@ -171,6 +173,30 @@ static const struct drm_ioctl_desc drm_ioctls[] = { #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) +static struct vfsmount *drm_mnt; + +struct inode *drm_alloc_inode(void) +{ + return alloc_anon_inode(drm_mnt->mnt_sb); +} + +static const struct dentry_operations drm_dops = { + .d_dname = simple_dname, +}; + +static struct dentry *drm_mount(struct file_system_type *fs_type, int flags, + const char *dev_name, void *data) +{ + return mount_pseudo(fs_type, "drm:", NULL, &drm_dops, 0x010203ff); +} + +static struct file_system_type drm_fs = { + .name = "drm", + .owner = THIS_MODULE, + .mount = drm_mount, + .kill_sb = kill_anon_super, +}; + /** File operations structure */ static const struct file_operations drm_stub_fops = { .owner = THIS_MODULE, @@ -203,9 +229,19 @@ static int __init drm_core_init(void) goto err_p3; } + drm_mnt = kern_mount(&drm_fs); + if (IS_ERR(drm_mnt)) { + ret = PTR_ERR(drm_mnt); + DRM_ERROR("Cannot mount pseudo fs: %d\n", ret); + goto err_p4; + } + DRM_INFO("Initialized %s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); return 0; + +err_p4: + debugfs_remove(drm_debugfs_root); err_p3: drm_sysfs_destroy(); err_p2: @@ -218,6 +254,7 @@ err_p1: static void __exit drm_core_exit(void) { + kern_unmount(drm_mnt); debugfs_remove(drm_debugfs_root); drm_sysfs_destroy(); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 2fe9b5d..02637a5 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1258,6 +1258,7 @@ extern long drm_ioctl(struct file *filp, extern long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); extern int drm_lastclose(struct drm_device *dev); +extern struct inode *drm_alloc_inode(void); /* Device support (drm_fops.h) */ extern struct mutex drm_global_mutex;