Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6863961rwl; Mon, 9 Jan 2023 14:14:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXs4v1IDWmJQVJHPwOGzueCv/+4J+2iBs3OYw4xF3Knl5DjNt50bePm5s8a0OTlfg6znUkFw X-Received: by 2002:a17:902:e8c5:b0:192:b6ae:ecc7 with SMTP id v5-20020a170902e8c500b00192b6aeecc7mr33377186plg.34.1673302456528; Mon, 09 Jan 2023 14:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673302456; cv=none; d=google.com; s=arc-20160816; b=DCUnyUbL5l5KsA5lhLY++/7+AVTWmHp6ihePExtM4e34bb2PvlQC1AopAQU4TGMW+I OE5bCj0UoHK8QZI3Qx9FcOterm98nKSVJEPfHqmG67hpY+l7hLvX+JuWjnTDOZk0ZQqc rorWBWZNU+8C0aTp8YeDAk5mhDHL9Bds9Hja0LjT27XRRt984gSarQbBNvzn3C4nVJvb oZlbNtemu3gmkj8f1o4JZRkjP4O9xyfzp7kRszhJaqBGtg72AM3QFr09AddsObDLmiAa ZWvQE7RNPGRy9f2EOmsAzn9uJcE+FsMsyy/jR7hgYGM+5pFW9d3Y6mpSfQowlua5r+O1 pEFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=g7XZ6zbY4DVhx/1OXdLF/gOX5xZT7N2TM5K+hmXQB+Q=; b=WtKflDkaM/pszcvbSEg5PeJzfBEl8WQ5ceYXbmlrMIXe6VbUeyaKKrUJ93ewa0KMhI rxVxAYUY4cgXaeZOawsYpwELp3dwNyW17GdewnW0Wu3Xza7fhB3KacBTM+ovnt+bY7Nw 8/S8e4E3eEtvZXevjzAmG1p6yQYb039CnERUl9jmD4Wb8w0WUJuoC1mk10X3pqnP+nfR VXaYbC51s3yB+dNLnh80nus0iCK93THiEgQshKBU2dhbKkf3y3XSkRRhCLqGmYZfcOsE JRjtmrThxnCwz0eC8fwx/HxuOlSem4XmB7aaMxzTUTM49Qf1RFBuX1pUsmHznoaJuaKa ZbjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lp6mFgIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a170903301500b0017486813f81si8781408pla.528.2023.01.09.14.14.09; Mon, 09 Jan 2023 14:14:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lp6mFgIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237597AbjAIVkF (ORCPT + 53 others); Mon, 9 Jan 2023 16:40:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238074AbjAIVjf (ORCPT ); Mon, 9 Jan 2023 16:39:35 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F703590D for ; Mon, 9 Jan 2023 13:38:20 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id p2-20020a17090a74c200b00226cc39b0afso3680744pjl.2 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=cAdP153Xr88Y0GvdLQMfIPZ6ytmiiV0THX8RwnmEZr0bFV4YPGYH1E5F6kl9sXkYLD F4X929lEyAf12UBrAFogteI3hTnoas5CDjbfeotryXAMxz6Rnk7TGh0tJLjtkr3YiSCS 8cz92CCAyCjQG+lCCicohjBL7NDvOL90GebYhYOahziFlkQijzi6kHuMtZn6O1ueLDAT FhtyCBEXCXP3zgooIrrNSrcPw4sA5j7FxwDbnkvuV6tj7skzbgpukQe3wsnOfs2SZae+ 3ULRkWd0X+8Z/0B7TgqHrJsxP1WCD9qKp9v1Sv7RXG7CMeMaxyzKmpt5GoJzG5MXGZa8 zAQA== X-Gm-Message-State: AFqh2kqVadAyrmkFWO1O3IguONyHH4JcPTnO8WYKwCaJYZx/nLX5xLl3 7cG9g91ytH7QKg4u0HBnbxCSTZG+sO6XR1s= 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=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Sumit Semwal , "=?UTF-8?q?Christian=20K=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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.39.0.314.g84b9a713c41-goog