From patchwork Wed Feb 27 03:54:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Feng X-Patchwork-Id: 10831433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA5BD13B5 for ; Wed, 27 Feb 2019 08:56:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D27812B002 for ; Wed, 27 Feb 2019 08:56:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C68822C162; Wed, 27 Feb 2019 08:56:49 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 599432B002 for ; Wed, 27 Feb 2019 08:56:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E6306E03E; Wed, 27 Feb 2019 08:56:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-x249.google.com (mail-oi1-x249.google.com [IPv6:2607:f8b0:4864:20::249]) by gabe.freedesktop.org (Postfix) with ESMTPS id 083A86E028 for ; Wed, 27 Feb 2019 03:54:59 +0000 (UTC) Received: by mail-oi1-x249.google.com with SMTP id a6so6646053oib.16 for ; Tue, 26 Feb 2019 19:54:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kKdTjrQBX3Yql3AnN1qxLX/9WJonljdYWNgtBrddlCE=; b=nFF5abwubvjoPvUED64dEVWhbH6L+kVevERc10kuET/mJJn56ZpTpAr0opV36maq+r 4YHHt4ki8eB8EM5S5RVnen7dJu6h4jhbX6nUYZPTD4jRwXI6luIeKHN7kSlY3li1h8Hj Jy6E1lU29dRmXFwHpTS9CJKxA+9YQ7w/zPRo0sONjlwCKRoi6shYyYXZCpeW9dQwKX37 AJ88m0hiMO09opn5/ev/yRC01KYTGVaAps7imH3SD6VWbWORusRDeyR0sDSQeSYOrE84 QBq6Xr9LxAxe/34gCnWOZoPu7+dkfGDD6TLRSsvb37Ua4RcmmCJfUlQ7RSIFfhHb0Qk2 o2UA== X-Gm-Message-State: AHQUAubsOO6vKCz1BYQatXj6jc3NWMjw0VPcYUXRoyOG8Pa0AsxmMFu4 U9yJHC+XKpxZKoc9eAmz2GsL3Kyq+A== X-Google-Smtp-Source: AHgI3IYHjeAs5NLE9M5w400hPALys90J1fOgxKIDj3TfNuH+eAUiyDpDnSMxPggiKZyB8BoksIOIOXCUkQ== X-Received: by 2002:a9d:6f98:: with SMTP id h24mr752342otq.30.1551239698302; Tue, 26 Feb 2019 19:54:58 -0800 (PST) Date: Tue, 26 Feb 2019 19:54:46 -0800 In-Reply-To: <20190227035448.117169-1-fengc@google.com> Message-Id: <20190227035448.117169-2-fengc@google.com> Mime-Version: 1.0 References: <20190227035448.117169-1-fengc@google.com> X-Mailer: git-send-email 2.21.0.rc2.261.ga7da99ff1b-goog Subject: [RFC dma-buf 1/3] dma-buf: give each buffer a full-fledged inode From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org X-Mailman-Approved-At: Wed, 27 Feb 2019 08:56:29 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kKdTjrQBX3Yql3AnN1qxLX/9WJonljdYWNgtBrddlCE=; b=ObNyAecF8hK2EvDirYGZliL4JU433V46Y4lVZLAdxq6SSa9sBlmsjKEba1KVT3Ot3R ke7l8Rb7ghv+XgR4m3GfcSEzRE+I50KbeLlD/IsggDAN0+V9lEitR3biuUdv07MeI+xq pn4vl+FXdQIXe7SYlQM0WJpgHoZMkzAl1pSmzWAumifeEdpT5xE3g+HywOBA7AvFPe+d SIO22CYtBIU1meSJLZ1BrMS92Q/0lzHvBTBieUtTYnZ4eFTS3PdRKKm7iCKtTnJVKMhB xn0HoU9DXCPgLNTm2os+xk4fHzJQRrQRfxpUGl6r67ilK/yJhOB98f2Ql88DAMPWq0ql yCkg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: erickreyes@google.com, Chenbo Feng , Greg Hackmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Greg Hackmann By traversing /proc/*/fd and /proc/*/map_files, processes with CAP_ADMIN can get a lot of fine-grained data about how shmem buffers are shared among processes. stat(2) on each entry gives the caller a unique ID (st_ino), the buffer's size (st_size), and even the number of pages currently charged to the buffer (st_blocks / 512). In contrast, all dma-bufs share the same anonymous inode. So while we can count how many dma-buf fds or mappings a process has, we can't get the size of the backing buffers or tell if two entries point to the same dma-buf. On systems with debugfs, we can get a per-buffer breakdown of size and reference count, but can't tell which processes are actually holding the references to each buffer. Replace the singleton inode with full-fledged inodes allocated by alloc_anon_inode(). This involves creating and mounting a mini-pseudo-filesystem for dma-buf, following the example in fs/aio.c. Signed-off-by: Greg Hackmann Signed-off-by: Chenbo Feng --- drivers/dma-buf/dma-buf.c | 68 +++++++++++++++++++++++++++++++++----- include/uapi/linux/magic.h | 1 + 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 02f7f9a89979..d72352356ac5 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -34,8 +34,10 @@ #include #include #include +#include #include +#include static inline int is_dma_buf_file(struct file *); @@ -46,6 +48,25 @@ struct dma_buf_list { static struct dma_buf_list db_list; +static const struct dentry_operations dma_buf_dentry_ops = { + .d_dname = simple_dname, +}; + +static struct vfsmount *dma_buf_mnt; + +static struct dentry *dma_buf_fs_mount(struct file_system_type *fs_type, + int flags, const char *name, void *data) +{ + return mount_pseudo(fs_type, "dmabuf:", NULL, &dma_buf_dentry_ops, + DMA_BUF_MAGIC); +} + +static struct file_system_type dma_buf_fs_type = { + .name = "dmabuf", + .mount = dma_buf_fs_mount, + .kill_sb = kill_anon_super, +}; + static int dma_buf_release(struct inode *inode, struct file *file) { struct dma_buf *dmabuf; @@ -338,6 +359,34 @@ static inline int is_dma_buf_file(struct file *file) return file->f_op == &dma_buf_fops; } +static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags) +{ + static const struct qstr this = QSTR_INIT("dmabuf", 6); + struct path path; + struct file *file; + struct inode *inode = alloc_anon_inode(dma_buf_mnt->mnt_sb); + + if (IS_ERR(inode)) + return ERR_CAST(inode); + + inode->i_size = dmabuf->size; + inode_set_bytes(inode, dmabuf->size); + + file = alloc_file_pseudo(inode, dma_buf_mnt, "dmabuf", + OPEN_FMODE(flags) | FMODE_LSEEK, + &dma_buf_fops); + if (IS_ERR(file)) + goto err_alloc_file; + file->f_flags = flags & (O_ACCMODE | O_NONBLOCK); + file->private_data = dmabuf; + + return file; + +err_alloc_file: + iput(inode); + return file; +} + /** * DOC: dma buf device access * @@ -433,14 +482,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) } dmabuf->resv = resv; - file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, - exp_info->flags); + file = dma_buf_getfile(dmabuf, exp_info->flags); if (IS_ERR(file)) { ret = PTR_ERR(file); goto err_dmabuf; } - - file->f_mode |= FMODE_LSEEK; dmabuf->file = file; mutex_init(&dmabuf->lock); @@ -1025,8 +1071,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) return ret; seq_puts(s, "\nDma-buf Objects:\n"); - seq_printf(s, "%-8s\t%-8s\t%-8s\t%-8s\texp_name\n", - "size", "flags", "mode", "count"); + seq_printf(s, "%-8s\t%-8s\t%-8s\t%-8s\texp_name\t%-8s\n", + "size", "flags", "mode", "count", "ino"); list_for_each_entry(buf_obj, &db_list.head, list_node) { ret = mutex_lock_interruptible(&buf_obj->lock); @@ -1037,11 +1083,12 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) continue; } - seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\n", + seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\n", buf_obj->size, buf_obj->file->f_flags, buf_obj->file->f_mode, file_count(buf_obj->file), - buf_obj->exp_name); + buf_obj->exp_name, + file_inode(buf_obj->file)->i_ino); robj = buf_obj->resv; while (true) { @@ -1146,6 +1193,10 @@ static inline void dma_buf_uninit_debugfs(void) static int __init dma_buf_init(void) { + dma_buf_mnt = kern_mount(&dma_buf_fs_type); + if (IS_ERR(dma_buf_mnt)) + return PTR_ERR(dma_buf_mnt); + mutex_init(&db_list.lock); INIT_LIST_HEAD(&db_list.head); dma_buf_init_debugfs(); @@ -1156,5 +1207,6 @@ subsys_initcall(dma_buf_init); static void __exit dma_buf_deinit(void) { dma_buf_uninit_debugfs(); + kern_unmount(dma_buf_mnt); } __exitcall(dma_buf_deinit); diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h index f8c00045d537..665e18627f78 100644 --- a/include/uapi/linux/magic.h +++ b/include/uapi/linux/magic.h @@ -91,5 +91,6 @@ #define UDF_SUPER_MAGIC 0x15013346 #define BALLOON_KVM_MAGIC 0x13661366 #define ZSMALLOC_MAGIC 0x58295829 +#define DMA_BUF_MAGIC 0x444d4142 /* "DMAB" */ #endif /* __LINUX_MAGIC_H__ */ From patchwork Wed Feb 27 03:54:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Feng X-Patchwork-Id: 10831443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FF1A13B5 for ; Wed, 27 Feb 2019 08:57:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 799862B002 for ; Wed, 27 Feb 2019 08:57:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D4052C162; Wed, 27 Feb 2019 08:57:11 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 095042B002 for ; Wed, 27 Feb 2019 08:57:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69C8A6E083; Wed, 27 Feb 2019 08:56:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by gabe.freedesktop.org (Postfix) with ESMTPS id C4A716E028 for ; Wed, 27 Feb 2019 03:55:01 +0000 (UTC) Received: by mail-pg1-x54a.google.com with SMTP id k198so11226589pgc.20 for ; Tue, 26 Feb 2019 19:55:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OeEbxgdEvD7vVmHTXrOO/jaZroEBj9Mfsqoiz7bsGqk=; b=S8eslrQ9IIt21kDh6Swl/Fy8F8nj45pmfTeOvCNfK6fC8TEqbpWzTCYJIj2izIo/4n QVEViLPsX31y22ymsz4utfaUtsTtFG+W+rTkpuA6/hSgru9qUHwhSNahRNl2Jz3Vo5P3 0JJxvgV1qPNI0c5mzbNIRtdXdRW4/7iynGFMSCiE2oc0DhYnVP9U5OdwVdAEBihkoiR4 ShicVulqEF4rEkR/1WD6WOdo/TDZj6U4X4Li9rHqoR8hyANfDHquCj7P3aQoW5TyDMLt OxcHG6N17CoGgvLOcXroN7REqT59zP/1ka3YsUC8479iHL8uzOVbqBT4COG8auuA3GRz lHJg== X-Gm-Message-State: AHQUAua+IA0WpWiDfCrOcNobZiiKMIhzF+57+jawcMQqY81Am4FVZm4H Orsw62z3ymflJFyxQ0KXaB+QzdazUw== X-Google-Smtp-Source: AHgI3Ibziiz4/32CFSgBthelLG0rzMXhLXQt6Cu1VGEvEol7+xxgXkLXAZkgND/ETrPhtm8L/iD3ZuPsEw== X-Received: by 2002:a62:6b06:: with SMTP id g6mr9965004pfc.76.1551239701364; Tue, 26 Feb 2019 19:55:01 -0800 (PST) Date: Tue, 26 Feb 2019 19:54:47 -0800 In-Reply-To: <20190227035448.117169-1-fengc@google.com> Message-Id: <20190227035448.117169-3-fengc@google.com> Mime-Version: 1.0 References: <20190227035448.117169-1-fengc@google.com> X-Mailer: git-send-email 2.21.0.rc2.261.ga7da99ff1b-goog Subject: [RFC dma-buf 2/3] dma-buf: add DMA_BUF_{GET,SET}_NAME ioctls From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org X-Mailman-Approved-At: Wed, 27 Feb 2019 08:56:29 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OeEbxgdEvD7vVmHTXrOO/jaZroEBj9Mfsqoiz7bsGqk=; b=o/Owk6qki0EHKuavI3s2QYe8Si20yn7yvy0fW7oYtTT16BFT6Ez+CxIngEz/GgBC+5 vfp2xvA6b8jy6gAvR1YAHrv2XZIRnptxj9FSgzM8SzMvy+2CnRwG5xLVnjgjqpNHRZqu UyTSA4AmMUFHsmSKY4GR6T1MhcjZRGk/f5r6h9RJDo0ag/OLdxPKmhJkFDSDtcbfdZIu EmIBTdJjel2nHHbEHp7lKLPqSaRUOBJ2rgjtIV6ArB+t1nVso2AOdCeQ8adD3HRMsJ9o teXVa5eA4TpZv5dhOq88B2ZkhGAin6Dw/M967yOlS0njb3u+w3rozr9JPm1Op2+LiXJW JqWQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: erickreyes@google.com, Chenbo Feng , Greg Hackmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Greg Hackmann This patch adds complimentary DMA_BUF_SET_NAME and DMA_BUF_GET_NAME ioctls, which lets userspace processes attach a free-form name to each buffer. This information can be extremely helpful for tracking and accounting shared buffers. For example, on Android, we know what each buffer will be used for at allocation time: GL, multimedia, camera, etc. The userspace allocator can use DMA_BUF_SET_NAME to associate that information with the buffer, so we can later give developers a breakdown of how much memory they're allocating for graphics, camera, etc. Signed-off-by: Greg Hackmann Signed-off-by: Chenbo Feng --- drivers/dma-buf/dma-buf.c | 42 ++++++++++++++++++++++++++++++++++-- include/linux/dma-buf.h | 5 ++++- include/uapi/linux/dma-buf.h | 4 ++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index d72352356ac5..e0d9cdd3520b 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -297,6 +297,36 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) return events; } +static long dma_buf_set_name(struct dma_buf *dmabuf, const char __user *buf) +{ + char *name = strndup_user(buf, DMA_BUF_NAME_LEN); + + if (IS_ERR(name)) + return PTR_ERR(name); + + mutex_lock(&dmabuf->lock); + kfree(dmabuf->name); + dmabuf->name = name; + mutex_unlock(&dmabuf->lock); + + return 0; +} + +static long dma_buf_get_name(struct dma_buf *dmabuf, char __user *buf) +{ + const char *name = ""; + long ret = 0; + + mutex_lock(&dmabuf->lock); + if (dmabuf->name) + name = dmabuf->name; + if (copy_to_user(buf, name, strlen(name) + 1)) + ret = -EFAULT; + mutex_unlock(&dmabuf->lock); + + return ret; +} + static long dma_buf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -335,6 +365,13 @@ static long dma_buf_ioctl(struct file *file, ret = dma_buf_begin_cpu_access(dmabuf, direction); return ret; + + case DMA_BUF_SET_NAME: + return dma_buf_set_name(dmabuf, (const char __user *)arg); + + case DMA_BUF_GET_NAME: + return dma_buf_get_name(dmabuf, (char __user *)arg); + default: return -ENOTTY; } @@ -1083,12 +1120,13 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) continue; } - seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\n", + seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\t%s\n", buf_obj->size, buf_obj->file->f_flags, buf_obj->file->f_mode, file_count(buf_obj->file), buf_obj->exp_name, - file_inode(buf_obj->file)->i_ino); + file_inode(buf_obj->file)->i_ino, + buf_obj->name ?: ""); robj = buf_obj->resv; while (true) { diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 58725f890b5b..582998e19df6 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -255,10 +255,12 @@ struct dma_buf_ops { * @file: file pointer used for sharing buffers across, and for refcounting. * @attachments: list of dma_buf_attachment that denotes all devices attached. * @ops: dma_buf_ops associated with this buffer object. - * @lock: used internally to serialize list manipulation, attach/detach and vmap/unmap + * @lock: used internally to serialize list manipulation, attach/detach and + * vmap/unmap, and accesses to name * @vmapping_counter: used internally to refcnt the vmaps * @vmap_ptr: the current vmap ptr if vmapping_counter > 0 * @exp_name: name of the exporter; useful for debugging. + * @name: userspace-provided name; useful for accounting and debugging. * @owner: pointer to exporter module; used for refcounting when exporter is a * kernel module. * @list_node: node for dma_buf accounting and debugging. @@ -286,6 +288,7 @@ struct dma_buf { unsigned vmapping_counter; void *vmap_ptr; const char *exp_name; + const char *name; struct module *owner; struct list_head list_node; void *priv; diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h index d75df5210a4a..4e9c5fe7aecd 100644 --- a/include/uapi/linux/dma-buf.h +++ b/include/uapi/linux/dma-buf.h @@ -35,7 +35,11 @@ struct dma_buf_sync { #define DMA_BUF_SYNC_VALID_FLAGS_MASK \ (DMA_BUF_SYNC_RW | DMA_BUF_SYNC_END) +#define DMA_BUF_NAME_LEN 32 + #define DMA_BUF_BASE 'b' #define DMA_BUF_IOCTL_SYNC _IOW(DMA_BUF_BASE, 0, struct dma_buf_sync) +#define DMA_BUF_SET_NAME _IOW(DMA_BUF_BASE, 1, const char *) +#define DMA_BUF_GET_NAME _IOR(DMA_BUF_BASE, 2, char *) #endif From patchwork Wed Feb 27 03:54:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Feng X-Patchwork-Id: 10831425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D18BC13B5 for ; Wed, 27 Feb 2019 08:56:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB4562B002 for ; Wed, 27 Feb 2019 08:56:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF98B2C162; Wed, 27 Feb 2019 08:56:40 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 657D62B002 for ; Wed, 27 Feb 2019 08:56:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8539D6E031; Wed, 27 Feb 2019 08:56:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-xd4a.google.com (mail-io1-xd4a.google.com [IPv6:2607:f8b0:4864:20::d4a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9913F6E02E for ; Wed, 27 Feb 2019 03:55:05 +0000 (UTC) Received: by mail-io1-xd4a.google.com with SMTP id k24so11930141ioa.18 for ; Tue, 26 Feb 2019 19:55:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kKIv4WwP+TPekq1SKWfh6PaUQyZ3d/TjdhpPmq98mVc=; b=bJA9ImTCG8+3VvLcGIyI7Qcaznqa+8oeIawE3MnLYzy/CJ96TiJT6RofwgrqTb2VMe vgn569MtqgtfcC4mBE0OJCCHPBXPYgRjVjPfwq2cE6ABnmDq1o4IM5nThoMNONpNOT+8 D9QYWBgj5Vz3ZDFEGwJuyEHuRBhbh9PQMTHgl5+83QaHrEZ5hWlAO38kRuJYNIOZ4yFy Uw+8A/QYBwwjhirt4yxC7i5XD3dOlhlAW9/brwuGPQEuyBcjme3RRu5Y7Y8saVE2u5+n bEB2KWmbxGAKZE2y9M3tzZhDux71n47KqY9IWlCRTuAmuyfucEK8zy/nfyUMiQ6i7c+g j4Zg== X-Gm-Message-State: AHQUAuZdI/+MkVtTbYLsWnI+HCT10C8kRKRCgyJYrtrpGaDUEBkqkKP1 LTiVvZTZvxeRZZXqexFABKHarG7gOQ== X-Google-Smtp-Source: APXvYqx9BGSeRGlUYxAEGoGkf4qYjPo4cRaBykUu+mhrePl+3xHx2M+aTvv4cinx9+w37opDghA6wrKoDw== X-Received: by 2002:a24:13d3:: with SMTP id 202mr231200itz.20.1551239704922; Tue, 26 Feb 2019 19:55:04 -0800 (PST) Date: Tue, 26 Feb 2019 19:54:48 -0800 In-Reply-To: <20190227035448.117169-1-fengc@google.com> Message-Id: <20190227035448.117169-4-fengc@google.com> Mime-Version: 1.0 References: <20190227035448.117169-1-fengc@google.com> X-Mailer: git-send-email 2.21.0.rc2.261.ga7da99ff1b-goog Subject: [RFC dma-buf 3/3] dma-buf: add show_fdinfo handler From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org X-Mailman-Approved-At: Wed, 27 Feb 2019 08:56:29 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kKIv4WwP+TPekq1SKWfh6PaUQyZ3d/TjdhpPmq98mVc=; b=YG+1PilHwX7taDLPGloi6h1wSVvw5xc9dfM9lsl6lVk5w0Z/R99JVD1tcDgiXEjnjj 79u7JiOiO8mTkub1fsvd8SiDoonspwod4sSPTeVtz9DIg4LFgeFr4ybkoUw47h89TWfF 2+D1BCkAj35/TWPT0FdXfUvzND58+2oP4RMC9OjtL8yCJqquH7RxwHWriM7UJcZGgoWX cTLvDJRUlFAPwe6f5uFdZgcnHWG/4Y3vsnzWtsG8XImB1dOwXWbenozsZXUTLcd1pfry km0sd7Y1mPsNLcPFpT32uz8sRZVVEOiT1QK6BxxEwmu6i4ZvXAMhBKvZnmJmc3MfHiy2 w/WA== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: erickreyes@google.com, Chenbo Feng , Greg Hackmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Greg Hackmann The show_fdinfo handler exports the same information available through debugfs on a per-buffer basis. Signed-off-by: Greg Hackmann Signed-off-by: Chenbo Feng --- drivers/dma-buf/dma-buf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index e0d9cdd3520b..2da3e2653f92 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -377,6 +377,20 @@ static long dma_buf_ioctl(struct file *file, } } +static void dma_buf_show_fdinfo(struct seq_file *m, struct file *file) +{ + struct dma_buf *dmabuf = file->private_data; + + seq_printf(m, "size:\t%zu\n", dmabuf->size); + /* Don't count the temporary reference taken inside procfs seq_show */ + seq_printf(m, "count:\t%ld\n", file_count(dmabuf->file) - 1); + seq_printf(m, "exp_name:\t%s\n", dmabuf->exp_name); + mutex_lock(&dmabuf->lock); + if (dmabuf->name) + seq_printf(m, "name:\t%s\n", dmabuf->name); + mutex_unlock(&dmabuf->lock); +} + static const struct file_operations dma_buf_fops = { .release = dma_buf_release, .mmap = dma_buf_mmap_internal, @@ -386,6 +400,7 @@ static const struct file_operations dma_buf_fops = { #ifdef CONFIG_COMPAT .compat_ioctl = dma_buf_ioctl, #endif + .show_fdinfo = dma_buf_show_fdinfo, }; /*