From patchwork Mon Jan 9 21:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "T.J. Mercier" X-Patchwork-Id: 13094384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 940FEC54EBE for ; Mon, 9 Jan 2023 21:38:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 225538E0003; Mon, 9 Jan 2023 16:38:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D5148E0001; Mon, 9 Jan 2023 16:38:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 077668E0003; Mon, 9 Jan 2023 16:38:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EC2878E0001 for ; Mon, 9 Jan 2023 16:38:22 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B86A516104B for ; Mon, 9 Jan 2023 21:38:22 +0000 (UTC) X-FDA: 80336574444.15.8F94B58 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf16.hostedemail.com (Postfix) with ESMTP id 239E618000C for ; Mon, 9 Jan 2023 21:38:20 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lp6mFgIF; spf=pass (imf16.hostedemail.com: domain of 3S4m8YwkKCHQlbeWjUaWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--tjmercier.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3S4m8YwkKCHQlbeWjUaWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--tjmercier.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673300301; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=g7XZ6zbY4DVhx/1OXdLF/gOX5xZT7N2TM5K+hmXQB+Q=; b=wkWcrc3BIELYOhFKIO4CKxuzrEkih0CYaws+xyi1kdP/AZ4pxHuNsapgBOwjNzSLUZaVnJ jsMwXPxQcCnu6sHuLIQp6BtGepBVELOcU3RhP90A4B1vVQUA7vpAbaYIOjftj4Gj9ADyLr u3l3MUj1bBImz2FnWXkYtosesYLQQbU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lp6mFgIF; spf=pass (imf16.hostedemail.com: domain of 3S4m8YwkKCHQlbeWjUaWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--tjmercier.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3S4m8YwkKCHQlbeWjUaWjYggYdW.Ugedafmp-eecnSUc.gjY@flex--tjmercier.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673300301; a=rsa-sha256; cv=none; b=h+qJ5lRKEoJJkeOQa//j3HqLC/yG5FeNv4oL7nGxNlEZZHNAS5OUa5wAJiFU+hfe5gpIHd /olxtabV+yLVkDvKfIG3VRghEdPcHi+YqhytGRhwtEyn0ZkDrPB0x0GTB7F8AxFBAuyKkP 21CQCDXrY2zKaHLDpQVr0FQIeOS+4tU= Received: by mail-pj1-f73.google.com with SMTP id q9-20020a17090a304900b00226e84c4880so3204849pjl.4 for ; Mon, 09 Jan 2023 13:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=g7XZ6zbY4DVhx/1OXdLF/gOX5xZT7N2TM5K+hmXQB+Q=; b=lp6mFgIFtl15wfLpEIICylaN7ba0rLKWyBcSmwWXHBIHGw2PfI8uc5JoYpz78iGrzt q7BwcvepUR121HS9evBvJZvukxIVfLEQnv4pKm0uyiAQHZ2lPiVMGwyZcSxUFbhaL90/ ucKWwiEICRsvndQmUOtOCqlM9msyGSEUsXD5lwlIQfLeTtimxNUVh0grkxXS2J8ZCHmG Om+IZIdCATJX9OXIuWLzOFPLT1CV83yldN+eGwxCxvUZBerXOoxKxtFA5g5ttfCJSVS7 8JY1ciKixBdA0fOe8xhy0huWzEPzI2dQz1uyE93OBKFPfOC0Iwt7BiU0pYO43R8uQXJv jjig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=g7XZ6zbY4DVhx/1OXdLF/gOX5xZT7N2TM5K+hmXQB+Q=; b=dTusUtoyWrAGNV0emQhJ2Mp2DvtaUOVx+3flUhGBSEvsVmClCI9GvnjmFeX1ssBI+O 8OvL59c16HMVzmkS4hUmQHUEJtBWWIWzfcuUJ6Id4U9BfL+ctEx27Mb5IX8M//BhWKX9 FjjOjrB4DpA3jlW0FHJxlrkoHVafltl8YhA44Z/EY/w+T9ITNHmvl0KMVKG8NhxWqWzB kfML5+3Rv+qrRM6BlkYOR0FMJDU/AS3HHwmlexwPScyQ4N7oOuLMPejjJ897C99Z172M XAqyK9EmzAheNQ5qKLXf7q89+xn9jev7VpYH2E6XuOQmG3aJkw0Qil7IzG3/sM+EmfMD yweg== X-Gm-Message-State: AFqh2kr2UBwnrJjFk0WZwXtV+/yGna/2aWmSylWzrFqJk77b+gC4/w8a Pd8s0Dj04aF46x4p8X4XFJtVOQ2N9MQTb4s= X-Google-Smtp-Source: AMrXdXtQbTYSpTLTOjbwoiA82zlu8FrSWZKcx71vLDnaBfZa7QUA/oE7cdXqxYT9vkecD3g3+ea7/6F21U6cq64= X-Received: from tj.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:53a]) (user=tjmercier job=sendgmr) by 2002:a05:6a00:1384:b0:56b:9ce2:891f with SMTP id t4-20020a056a00138400b0056b9ce2891fmr3675608pfg.43.1673300299885; Mon, 09 Jan 2023 13:38:19 -0800 (PST) Date: Mon, 9 Jan 2023 21:38:03 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109213809.418135-1-tjmercier@google.com> Subject: [PATCH 0/4] Track exported dma-buffers with memcg From: "T.J. Mercier" To: tjmercier@google.com, Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Greg Kroah-Hartman , " =?utf-8?q?Arve_Hj?= =?utf-8?q?=C3=B8nnev=C3=A5g?= " , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Sumit Semwal , " =?utf-8?q?Christian_K=C3=B6nig?= " , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris Cc: daniel.vetter@ffwll.ch, android-mm@google.com, jstultz@google.com, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 239E618000C X-Rspam-User: X-Stat-Signature: 1yin5zfpn9cgui3uec1ekkezbajk7nue X-HE-Tag: 1673300300-630649 X-HE-Meta: U2FsdGVkX1/zCARVcz50/tgGpSWOM7fjm2FEDds+fARsWz2yQrzzAAlIGJFInHsV/xn8fP68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xbB6Axkqy+53NzzwrMKQU2UQZwBg1/nMQs6D4IU1hsG330Wq6SJvDLnd/HsCJJEIRrZnCgVtmVhVcdZhkClPWxKLKtVdVyRZqgS9cUWQAyCT5Sl0dGHgwIBIEQxEDv5jfMIwLB/v8WeM3oiOIqH97PzeVkNCKotRSiGe4RjIjZzo51Ugtg/o4e0VZembaAegbuEp8TuWeDu6yaxxg1ue1tigOP05On+abvys9tHo3hSCx2cCt3WAyMsb+N+sGlMrv0zDV+1DJ6k+p/CH2Ep1ltb5U6UgEa31SELlUiOOLjdMYkK+/7CeS/3RJ82s8Z1TE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Based on discussions at LPC, this series adds a memory.stat counter for exported dmabufs. This counter allows us to continue tracking system-wide total exported buffer sizes which there is no longer any way to get without DMABUF_SYSFS_STATS, and adds a new capability to track per-cgroup exported buffer sizes. The total (root counter) is helpful for accounting in-kernel dmabuf use (by comparing with the sum of child nodes or with the sum of sizes of mapped buffers or FD references in procfs) in addition to helping identify driver memory leaks when in-kernel use continually increases over time. With per-application cgroups, the per-cgroup counter allows us to quickly see how much dma-buf memory an application has caused to be allocated. This avoids the need to read through all of procfs which can be a lengthy process, and causes the charge to "stick" to the allocating process/cgroup as long as the buffer is alive, regardless of how the buffer is shared (unless the charge is transferred). The first patch adds the counter to memcg. The next two patches allow the charge for a buffer to be transferred across cgroups which is necessary because of the way most dmabufs are allocated from a central process on Android. The fourth patch adds a SELinux hook to binder in order to control who is allowed to transfer buffer charges. [1] https://lore.kernel.org/all/20220617085702.4298-1-christian.koenig@amd.com/ Hridya Valsaraju (1): binder: Add flags to relinquish ownership of fds T.J. Mercier (3): memcg: Track exported dma-buffers dmabuf: Add cgroup charge transfer function security: binder: Add transfer_charge SElinux hook Documentation/admin-guide/cgroup-v2.rst | 5 +++ drivers/android/binder.c | 36 +++++++++++++++-- drivers/dma-buf/dma-buf.c | 54 +++++++++++++++++++++++-- include/linux/dma-buf.h | 5 +++ include/linux/lsm_hook_defs.h | 2 + include/linux/lsm_hooks.h | 6 +++ include/linux/memcontrol.h | 7 ++++ include/linux/security.h | 2 + include/uapi/linux/android/binder.h | 23 +++++++++-- mm/memcontrol.c | 4 ++ security/security.c | 6 +++ security/selinux/hooks.c | 9 +++++ security/selinux/include/classmap.h | 2 +- 13 files changed, 149 insertions(+), 12 deletions(-) base-commit: b7bfaa761d760e72a969d116517eaa12e404c262