From patchwork Wed Jun 12 21:48:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Feng X-Patchwork-Id: 10991265 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 A0AFF924 for ; Thu, 13 Jun 2019 07:28:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ED79204C1 for ; Thu, 13 Jun 2019 07:28:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82F842887B; Thu, 13 Jun 2019 07:28:36 +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 14E50204C1 for ; Thu, 13 Jun 2019 07:28:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 95816892EA; Thu, 13 Jun 2019 07:27:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9C2F89242 for ; Wed, 12 Jun 2019 21:48:29 +0000 (UTC) Received: by mail-qk1-x749.google.com with SMTP id v80so14869125qkb.19 for ; Wed, 12 Jun 2019 14:48:29 -0700 (PDT) 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=x5JY2SGL+SYSEHfOtRFLuisOxAVpr293xNU/5K/Orhw=; b=OfTvkGIC+tb+TYWB0K+7dF9qwUa9lgtNNORkoa+g7fhCIqGOTgmvhOePnrK/PoRdTM CaJGxfIByEDRjRxpYe4ihQr1lMl+BAEHVh4gR/EvAn0PvSWXUCP2l27eXmowTvLJP4Fm Jvz9vQZrcTtH2jOPUi2u6+fnYjPw5ozq0dsAmujwieZOxw2z1THVJIwlGgdIXBNlVYLf RoqGZ0Vd7amHMBfro43hycszgNzHEta+znCQt1GlsLzgjQ0jMGpPoKZirX2vdxbasLki F5fL7eGQTg+guEa8h2Av+lbHlcstF9JwF9Kj3mBWuWLjWmDu7TGNxIk2HBc/SM21QWIS D/dQ== X-Gm-Message-State: APjAAAUm4Nr9u8wD9Srgb6QaJSdkbjvtg70lJsxBA6nRY6U3NGLN6dt8 oW3uqC9wRhGKRVlym109F67QfkxLdg== X-Google-Smtp-Source: APXvYqwr+6rEdJFDESoMYNaauRo/3rWccerZ0C2ktPwJ7mVmdx1JRJZW8i/Lp6aMelPjce+Ea2P6/S8itQ== X-Received: by 2002:ac8:7c7:: with SMTP id m7mr68019754qth.28.1560376108860; Wed, 12 Jun 2019 14:48:28 -0700 (PDT) Date: Wed, 12 Jun 2019 14:48:21 -0700 In-Reply-To: <20190612214823.251491-1-fengc@google.com> Message-Id: <20190612214823.251491-2-fengc@google.com> Mime-Version: 1.0 References: <20190612214823.251491-1-fengc@google.com> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v4 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 X-Mailman-Approved-At: Thu, 13 Jun 2019 07:27:23 +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=x5JY2SGL+SYSEHfOtRFLuisOxAVpr293xNU/5K/Orhw=; b=UUaKcHV0d/LC9+lq01zBflV+hCjVCVqmBE3jKTCQMDYMhgFQy+hqBR570RqhY5BnO5 2IdZs3XxNUJtkmViwwhRiHpFp/XG+c+QSQrYmi51xctcNWKz5S4Txw2nmLK71Ro1G0EN OaJ166g8QaVYhoP5Tsycy2cjIRDzgW4ij0dL3tEm4k9n+z0cxZ/9Hady/0qGiVWaVUTd Y8An01p9TIj02KL22FwkySr1gVzpRzokRLgL8in5Bdgod1xbgpPxT104Qjd9D7R+5LZ0 /HmuO037rHLdWnkRlHMbQzG5jNpPL7ICo6CSqH65uQqvTLy7hmDpNxpPnOT3mViN9Rp3 B/9A== 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: kernel-team@android.com 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 | 63 ++++++++++++++++++++++++++++++++++---- include/uapi/linux/magic.h | 1 + 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 7c858020d14b..ffd5a2ad7d6f 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,31 @@ 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) +{ + 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", + flags, &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,8 +479,7 @@ 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; @@ -1025,8 +1070,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 +1082,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) { @@ -1136,6 +1182,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(); @@ -1146,5 +1196,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 Jun 12 21:48:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Feng X-Patchwork-Id: 10991267 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 DF51C924 for ; Thu, 13 Jun 2019 07:28:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1A9204C1 for ; Thu, 13 Jun 2019 07:28:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0EB92870E; Thu, 13 Jun 2019 07:28:37 +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 51C07288A9 for ; Thu, 13 Jun 2019 07:28:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9023289319; Thu, 13 Jun 2019 07:27:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3A2C489255 for ; Wed, 12 Jun 2019 21:48:32 +0000 (UTC) Received: by mail-yb1-xb49.google.com with SMTP id y3so16637657ybp.23 for ; Wed, 12 Jun 2019 14:48:32 -0700 (PDT) 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=UTvLD/wD588ESHmoVIZCejau/hPfDwnsdJsCywqHwAA=; b=pS25RWNLpiYYNLFdha3btFZHkHFnZDdxYnKlBke2vvldMIGvzfOmSqUxpuaBHyHwna qGX4TpyNiDPRQ/KKhoFcM6Towxl4BBdNYbuuKJ1CsVQqv9lnoXrx71wGJNca/Ae8OP3N GEoOmS7ECUef0jVC8CLu51+RXKia27Z1J6xPdXaw4OSmE1Fl7V+OiPyKljylYHT3coWR Wk7zXH1jZokHyLkKX3yG6sxBsS72jnIeq5AY/nrVNJWXyDTtZJRDOHq3FD4iu1ph6K0L aQ6hB8+ylGClQ98T9MObGO9uuY5LtBgdJFlBMmU4wgwwSkO5TYtlrW0lYEfMoBfRVfIU kiZg== X-Gm-Message-State: APjAAAVME4VEfY80f9nbmMLpFW1iCf1JD6HKg5aflDzyfZ/I9S9D/XIj ow/BjFsN08X2c/BsB/u2bfrjq1Sfyg== X-Google-Smtp-Source: APXvYqxzVHSBLfhQspuBOmQnqTs3mkYhIaCZKmk5HFnMNN5m3v06aytJ4m926pXsuFtvTrJvWi1F8oKmwQ== X-Received: by 2002:a81:5944:: with SMTP id n65mr25260743ywb.182.1560376111464; Wed, 12 Jun 2019 14:48:31 -0700 (PDT) Date: Wed, 12 Jun 2019 14:48:22 -0700 In-Reply-To: <20190612214823.251491-1-fengc@google.com> Message-Id: <20190612214823.251491-3-fengc@google.com> Mime-Version: 1.0 References: <20190612214823.251491-1-fengc@google.com> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v4 2/3] dma-buf: add DMA_BUF_SET_NAME ioctls From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-Mailman-Approved-At: Thu, 13 Jun 2019 07:27:23 +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=UTvLD/wD588ESHmoVIZCejau/hPfDwnsdJsCywqHwAA=; b=Mu7ieJ4dJr5A88meQ9qVtn/HkSV/004ezi4zuqk7cCe+YsOH9wCM4of1Oqhr2u8V98 A7XEWbgP/tsh554OaRpnmXbSFFre7Jc+QrCaTmhJOqBSWnqBgBgTo9cBXLXVcmziWkS1 UjQXUsPXhBsbOWxWOGA6PMqDywM9rQ8BfeZRifMf/pQPnIYQ7ECbI3tgKqvYJFI8Cj3h BIdUd4vPAPPZEIC14cPiFvZSxyRgoGgqjwM9FOZUONWn1COvjWof9/mLG+Xlg46zmROQ 1o7LZTchCx0+tfw8XyQx8m7VHr1vBOnvbdMnFrCNcHpK4S1tnsPi2ptbqadwtHiHkbGT SJbA== 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: kernel-team@android.com 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 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 | 64 ++++++++++++++++++++++++++++++++++-- include/linux/dma-buf.h | 5 ++- include/uapi/linux/dma-buf.h | 3 ++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index ffd5a2ad7d6f..87a928c93c1a 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -48,8 +48,24 @@ struct dma_buf_list { static struct dma_buf_list db_list; +static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen) +{ + struct dma_buf *dmabuf; + char name[DMA_BUF_NAME_LEN]; + size_t ret = 0; + + dmabuf = dentry->d_fsdata; + mutex_lock(&dmabuf->lock); + if (dmabuf->name) + ret = strlcpy(name, dmabuf->name, DMA_BUF_NAME_LEN); + mutex_unlock(&dmabuf->lock); + + return dynamic_dname(dentry, buffer, buflen, "/%s:%s", + dentry->d_name.name, ret > 0 ? name : ""); +} + static const struct dentry_operations dma_buf_dentry_ops = { - .d_dname = simple_dname, + .d_dname = dmabuffs_dname, }; static struct vfsmount *dma_buf_mnt; @@ -297,6 +313,42 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) return events; } +/** + * dma_buf_set_name - Set a name to a specific dma_buf to track the usage. + * The name of the dma-buf buffer can only be set when the dma-buf is not + * attached to any devices. It could theoritically support changing the + * name of the dma-buf if the same piece of memory is used for multiple + * purpose between different devices. + * + * @dmabuf [in] dmabuf buffer that will be renamed. + * @buf: [in] A piece of userspace memory that contains the name of + * the dma-buf. + * + * Returns 0 on success. If the dma-buf buffer is already attached to + * devices, return -EBUSY. + * + */ +static long dma_buf_set_name(struct dma_buf *dmabuf, const char __user *buf) +{ + char *name = strndup_user(buf, DMA_BUF_NAME_LEN); + long ret = 0; + + if (IS_ERR(name)) + return PTR_ERR(name); + + mutex_lock(&dmabuf->lock); + if (!list_empty(&dmabuf->attachments)) { + ret = -EBUSY; + goto out_unlock; + } + kfree(dmabuf->name); + dmabuf->name = name; + +out_unlock: + mutex_unlock(&dmabuf->lock); + return ret; +} + static long dma_buf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -335,6 +387,10 @@ 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); + default: return -ENOTTY; } @@ -376,6 +432,7 @@ static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags) goto err_alloc_file; file->f_flags = flags & (O_ACCMODE | O_NONBLOCK); file->private_data = dmabuf; + file->f_path.dentry->d_fsdata = dmabuf; return file; @@ -1082,12 +1139,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..dbc7092e04b5 100644 --- a/include/uapi/linux/dma-buf.h +++ b/include/uapi/linux/dma-buf.h @@ -35,7 +35,10 @@ 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 *) #endif From patchwork Wed Jun 12 21:48:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Feng X-Patchwork-Id: 10991295 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 DC1A014E5 for ; Thu, 13 Jun 2019 07:29:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB644204C1 for ; Thu, 13 Jun 2019 07:29:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFC3C2887B; Thu, 13 Jun 2019 07:29:45 +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 7340F204C1 for ; Thu, 13 Jun 2019 07:29:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 14AA6893B9; Thu, 13 Jun 2019 07:28:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-x24a.google.com (mail-oi1-x24a.google.com [IPv6:2607:f8b0:4864:20::24a]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD3E689255 for ; Wed, 12 Jun 2019 21:48:34 +0000 (UTC) Received: by mail-oi1-x24a.google.com with SMTP id t198so6028811oih.20 for ; Wed, 12 Jun 2019 14:48:34 -0700 (PDT) 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=xFZI9Cn8XQ9WD/uM2zeIjsdArEKjTB6MEJpCpF8H2cY=; b=Yb0kfnphvJpARkZEYpoV8WdHFu8YkW8lZ1aomaua75sQP3jfWB9lIkhXtSK7MQ01vz +XkhgDJxrF9HuI2r7NNzAPHcb/VSu4xE62poHQUw8esWXT1/wcMdhKTP5P4n6sCHhwz/ kY406ExKg0NTZjvDGPbUdq6Nh2Qg8qs8Fdy0i9Jq6/4XU1xop8/NOG6fgD3dogykYLXJ rKphL1D2RZdZOqgtPc8XeNNYq7Ha57VgYz8KOyCl3qphYnGQhLUZ9XV2Vwelx1FdbjDV xcw7Z2EDN3dWOkyVTlftsm3Dcs62GWGZkBG2FIvXO6Nl4zqF19er/5d8OvwV2OoTZFnX 2yRQ== X-Gm-Message-State: APjAAAUfH6OsPamUBbETKBpbeaC6H0LI1hgfPcCOafevyrOVdWbI2Enf OmUrdbp1Wxr695ljOu0nupDgIMM0mA== X-Google-Smtp-Source: APXvYqxn5WIL38quMvWm0NFNVoCMoq509G4lVulP6aIh3DMM/7wKweu86NGynkKEkLolsMXyoApH36EYpQ== X-Received: by 2002:a9d:7650:: with SMTP id o16mr19689292otl.0.1560376114065; Wed, 12 Jun 2019 14:48:34 -0700 (PDT) Date: Wed, 12 Jun 2019 14:48:23 -0700 In-Reply-To: <20190612214823.251491-1-fengc@google.com> Message-Id: <20190612214823.251491-4-fengc@google.com> Mime-Version: 1.0 References: <20190612214823.251491-1-fengc@google.com> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v4 3/3] dma-buf: add show_fdinfo handler From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-Mailman-Approved-At: Thu, 13 Jun 2019 07:27:23 +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=xFZI9Cn8XQ9WD/uM2zeIjsdArEKjTB6MEJpCpF8H2cY=; b=svuswpTBA4Vx+DLei1h+oVomOQmLsZNHTti0CIQZQVpzQDIyHeME0lAHPve5gT8exd E79eA8Ev5/qmWH+q1GOZI/aoxL+R3S0AW9XY83rHhXMkYf3xYQNqMgX+ONGiiVasflGI eI4w2zUXmOl99uOnNm49b46Ho4C7q5YMdGb57vi+f+sAvCHkeXb/szZbGc1dYp0RHLUX Bb7SqaKZDqXDMG/xtvv6j+JphFCnnBeglrzOcsw04pOqmrnqEZOKJYQBPtYglaBDlDdo k8HUtS4ismdMPZzP+d61mUgOI2udfdS0JqERvV7uLB3RxgaFRt3+YQiwnIdWGJ5Hgvtl 5Usw== 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: kernel-team@android.com 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 87a928c93c1a..ff8421668331 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -396,6 +396,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, @@ -405,6 +419,7 @@ static const struct file_operations dma_buf_fops = { #ifdef CONFIG_COMPAT .compat_ioctl = dma_buf_ioctl, #endif + .show_fdinfo = dma_buf_show_fdinfo, }; /*