Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3783390ybi; Mon, 10 Jun 2019 17:02:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2JA2Hv7+nO9Mtmj8PcFT9oQCyuYQ8a4mmsPlDdAFN3hMB/GldfJjG3IXgorQzG+92zk+E X-Received: by 2002:a17:902:2ac8:: with SMTP id j66mr31938265plb.273.1560211378659; Mon, 10 Jun 2019 17:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560211378; cv=none; d=google.com; s=arc-20160816; b=eGY96Qczk6uWtCJnZCNM0hOpvwM663icaUIM7d/QXc5hhDInxEdX/UYh66oDXsZuJb adsrQRXIor6bPNCUxD8pyo70/b5bfAvC8lRuzKTFdfa+H4wxVS1kaH9k4+uWw1iLptAG NzruFgzkH3YDZ7oBdba8aWIyA4IBSi7sBPpfk0kVzTIVgxem1/B3Jsju9mwF5hlZA3// 10luAE1FGhmnKLrb9yeF2d6V6Ih0J0F9fCxaOK7ZWcsiZAh3LiujG+y2Q4mDdvDeFCAM 9OqxebL9YvDMPtFTu57Msxc72nCYYW9+Xu682mxLZp059YK09gEO7V/9IjNHYJHPIgD4 6ydg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:from :subject:mime-version:message-id:date:dkim-signature; bh=M35jpHh+HUdAc93UKOjDO7JbyHiHSckhQH2gYDGobXY=; b=MI0l7Opb5JSKkE/y8QdUIkTHP+cJTiWVDvr3i/vhfb/czEAwMxjYSm24jbJpZztbLc sni0C25+A3yF6Br+xA++EQMgauC0+fXOKJxmRs7Oq54O+sJ4BAM1A8Q2HiQ7PpLGLQ/S T3pbPZNaCommUnQVwCFd+triA1lyNiB7w+DHbFH0J0BDyKX1oFz2ZvRsNo28xZY7or/0 8ULHmBMazrpHkKmfuhsTMF/YZd5p3rYdbd2c4HB3vtmjHWRpCd5GqupEWJhX57rKHmK6 zyEdAjKcPi222mV9VrciFG4K8pz+6Jph7lKL5kiuyrteXF0ep2FKXHADV7pKx4qH/BKw srLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kmOt5FFc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j36si11351816plb.77.2019.06.10.17.02.43; Mon, 10 Jun 2019 17:02:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kmOt5FFc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390858AbfFKACe (ORCPT + 99 others); Mon, 10 Jun 2019 20:02:34 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:44826 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390557AbfFKACd (ORCPT ); Mon, 10 Jun 2019 20:02:33 -0400 Received: by mail-pg1-f202.google.com with SMTP id a21so7889814pgh.11 for ; Mon, 10 Jun 2019 17:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=M35jpHh+HUdAc93UKOjDO7JbyHiHSckhQH2gYDGobXY=; b=kmOt5FFcxJJcGbgX/KhbCPUkNJRtfC5SMHXTm1h8fiJNch0lsXUvnJM+rymoJnYK+M /9i448oQsz9LkakuACRu2808YeoiGQWVOXnOaRsyISwhCPK8dP9o1miiBce5frGWE16z eGHzXgV/sirfWV3aYlwKlCVRz8JLalQNNdlrgqf9Kk4okfh7+/qEmYCsVmvDyQQYCeq5 eHBMKdhUJ4uO5yV4bLwIo6RYC+dEkR71ldwMuJ4oc5OgIdl0EfB1YFOsZhanV9n4KLVA PxmWWkH9kRJjk7Cph1crz80X/0wZ+pmtVZn24/1sSr59fSCDJU9Md8pOSeNyHY/QtHrB lvsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=M35jpHh+HUdAc93UKOjDO7JbyHiHSckhQH2gYDGobXY=; b=hm91I0odM2v75B2eNWtCBmMDYgPsO7pMXFNBRdaVKqEfLBYIZvheLg+tpwVws1gp7i ckzrv7fJMqM6mck/411+d70NGTBiBI9qihgGVTMad/WflbLybQ5LF9TN+YV0Br4MRj4e gMzn9hdArAeMf9zMZ9myymZnUx2AVL9iyTZc/lr1rrWG5k95II7pN2XCQDkN7taeY5+r N5kM6BRyXufvhs/GMhYonkLoXIBFRE7B+IH8M/1FFqaa5jbWybP1SHAUDeFZEJ+4zRS7 XWfDiL5yEVQ/AAexOmC2VQtv0gnDHGf4yJSUNb3mE/UXDOi3bvL6xXAm+VeDcEqougaw J4oQ== X-Gm-Message-State: APjAAAXji0AgfESXC7IfYdTrWYKIPnhMS5x7T8xS8HJlJL3GUUcvoMsr 0MmS3QQhrSjEV434c8rGHRRyUuH8ydSM9CMbjzso9M7mriHazZUt0luah7OT4rF0xXvXd7u/J5t 0KhUJwHy14eSyrcCYKAlUBMOCAgSlPsLtEQ4V/Do0uD1Y9cNirKCPYNmYoV+MCwwuuAo= X-Received: by 2002:a63:6105:: with SMTP id v5mr17769974pgb.312.1560211352554; Mon, 10 Jun 2019 17:02:32 -0700 (PDT) Date: Mon, 10 Jun 2019 17:02:27 -0700 Message-Id: <20190611000230.152670-1-fengc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [RESEND PATCH v3 0/3] Improve the dma-buf tracking From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: Sumit Semwal , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, all dma-bufs share the same anonymous inode. 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. And in 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. To resolve the issue above and provide better method for userspace to track the dma-buf usage across different processes, the following changes are proposed in dma-buf kernel side. First of all, replace the singleton inode inside the dma-buf subsystem with a mini-filesystem, and assign each dma-buf a unique inode out of this filesystem. With this change, calling 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 assigned to each dma-buffer. Secoundly, add the inode information to /sys/kernel/debug/dma_buf/bufinfo so in the case where a buffer is mmap()ed into a process=E2=80=99s address = space but all remaining fds have been closed, we can still get the dma-buf information and try to accociate it with the process by searching the proc/pid/maps and looking for the corresponding inode number exposed in dma-buf debug fs. Thirdly, created an ioctl to assign names to dma-bufs which lets userspace assign short names (e.g., "CAMERA") to buffers. This information can be extremely helpful for tracking and accounting shared buffers based on their usage and original purpose. Last but not least, add dma-buf information to /proc/pid/fdinfo by adding a show_fdinfo() handler to dma_buf_file_operations. The handler will print the file_count and name of each buffer. Change in v2: * Add a check to prevent changing dma-buf name when it is attached to devices. * Fixed some compile warnings Change in v3: * Removed the GET_DMA_BUF_NAME ioctls, add the dma_buf pointer to dentry d_fsdata so the name can be displayed in proc/pid/maps and proc/pid/map_files. Greg Hackmann (3): dma-buf: give each buffer a full-fledged inode dma-buf: add DMA_BUF_{GET,SET}_NAME ioctls dma-buf: add show_fdinfo handler drivers/dma-buf/dma-buf.c | 122 +++++++++++++++++++++++++++++++++-- include/linux/dma-buf.h | 5 +- include/uapi/linux/dma-buf.h | 3 + include/uapi/linux/magic.h | 1 + 4 files changed, 124 insertions(+), 7 deletions(-) --=20 2.21.0.1020.gf2820cf01a-goog