Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp265825img; Thu, 21 Mar 2019 19:52:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx4ePf8hAL/SNG1b5x7GcBucSTlhYysmbPfFK28qYGbArMaP9OVWmBcIx7iV5ARdIg3Nii X-Received: by 2002:a17:902:a81:: with SMTP id 1mr7064863plp.308.1553223160228; Thu, 21 Mar 2019 19:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553223160; cv=none; d=google.com; s=arc-20160816; b=tvr1TjZYDKpXfNjbvC/BrVl04hmj9sf8vZAyZ0NlgEfVA4/GrRHJeufKVaC9o0ZS3G 89/B2HYQdiH1u4IJH15fEzOxyXGaRQIjXpU1YSUm3gRMH8l0PPX5A+RRZQrCle+HNQdz lCGCODWfidW6e1T2LtUgdDz791B/l067I/U5IgBHEtZuk3gIRl0xO4Y3HL1Lr6ESuXkJ iJhZSKG1XKqgM9nb27EjmlGqvAoNcOTBke4ajdj9ql4vHJeiUQP9gUXwRuM3gmKCGhtE ef/nBQkB3eiEYDUUlVZz5E6SGtimBHLweXDLuNfyFOqUOzTZhhko5Uva5WqvnN1ZCbE5 5o6g== 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=j6/zuEG9+UIoYtW3U8W38qtzXfAkrhIL3/LLIBR4owU=; b=gUnNomuFii8rHSSr40EzKuxumLx79zWdMNFeqZs6YJ6M7i9prOZn+8s7egnAkFbojB bf6GdgmoMEKwL01gvzJrLcDOR552LxtQmaYVUbDMYJPnQ0htAGMGtURzldkfGW4m3efR cggbOiteF9iAST5Bciu0oGA5G7bBD+xZIuqfKtH7Fy39f0yb93AMwpC+Lib2IZIzlm66 2emSmDk64D9h1ajMHhi3stVffmFTXeoSsGMUrja0R/k4czo93aF6f3usQwZqBbPf+oJv hEEsy8I3w6AJYrZfYxSvG0S+2Ac8jrMjTc7FtVk5IqkbO2BgKeKKh0uh3c20Mk7+NWra D52g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CyZOZBKP; 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 p10si5555392pgb.222.2019.03.21.19.52.22; Thu, 21 Mar 2019 19:52:40 -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=CyZOZBKP; 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 S1727415AbfCVCvn (ORCPT + 99 others); Thu, 21 Mar 2019 22:51:43 -0400 Received: from mail-ot1-f73.google.com ([209.85.210.73]:37962 "EHLO mail-ot1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbfCVCvm (ORCPT ); Thu, 21 Mar 2019 22:51:42 -0400 Received: by mail-ot1-f73.google.com with SMTP id u18so498329otq.5 for ; Thu, 21 Mar 2019 19:51:42 -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=j6/zuEG9+UIoYtW3U8W38qtzXfAkrhIL3/LLIBR4owU=; b=CyZOZBKPDThABvx4++PnjHBTyqsppM84QY45Tnfnue0M8+GlxUPCJ79DSuuZlIa24m /B6buINPT9/NDdN1cKcXus11GaqkiGhLBR3dXaf944zkSxqThK6hizYJFd32dB/Ewl8K Me97HW2Lf04EpNsbDyZPBga+X6bh5HRO2gG5T51eSn8Pwt0Fr24KEaMbv2+KKk92UfFB rReKWpgzDflXq8k2q2kDDRqS4/gwBtMALyl0fdKsa8kFAg1OasszIkRnAUQmiN93yWpM zMRHSczIX52FIX6SNRrqq+SegHURODWoSbSRhHPEOgFEPW3qjcJugYQUNf2he7tgnV1B 9Nfg== 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=j6/zuEG9+UIoYtW3U8W38qtzXfAkrhIL3/LLIBR4owU=; b=Bcrqq75EtqZwK9LdEbQjHrrqArrvMOYLBoVdO1PYnue3V00usblrBCCObkQ/yhVQvv raPZ6xm3odIHEL71BG7QvxX72pGu82H1+0XsTVnRQcnIQBxRjIS7UmPs/7M8Hsh87D1y fl/BZL+7txGiZmKiyrKC9CQ/F9lJdnEBSrozfdSgSslvba9gEZgKlZ32wWW1FRPRbS3W MIBUjGBRWedsOXQsQHiLyyAWegJQlSiJ9MYCVz23rG0cu81f0wIwgUfKavo94NK1p/+a uUvKgtWgVzKeLc1XKDkvAqWxhqZFQ5jyY2Z5xUYMQLaUcqloMjasEisENRKVxXaZ4WNw zgIw== X-Gm-Message-State: APjAAAUtvRinxOHr2fRFe/+J+Po+if1ZItjs1AyKD6iWlAuOS5in5XCm oq//iKk0xtqR/GQKtheHvo6VrJWIVCHDaqAWOUuvaZMVHK289CDz8S1JZ8LNoWf1OMI+Pe70nP9 L62mPs8fINZveNCpgdAtz0gO+JEVyFjADEkyBXjNihztcTAGaLqhn0emP+bUEPKJPaMk= X-Received: by 2002:aca:b683:: with SMTP id g125mr337075oif.17.1553223101756; Thu, 21 Mar 2019 19:51:41 -0700 (PDT) Date: Thu, 21 Mar 2019 19:51:32 -0700 Message-Id: <20190322025135.118201-1-fengc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog Subject: [RFC v2 dma-buf 0/3] Improve the dma-buf tracking From: Chenbo Feng To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Cc: kernel-team@android.com, Sumit Semwal , erickreyes@google.com, Daniel Vetter , Chenbo Feng 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 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 | 121 ++++++++++++++++++++++++++++++++--- include/linux/dma-buf.h | 5 +- include/uapi/linux/dma-buf.h | 4 ++ include/uapi/linux/magic.h | 1 + 4 files changed, 122 insertions(+), 9 deletions(-) --=20 2.21.0.rc2.261.ga7da99ff1b-goog