From patchwork Thu May 9 21:04:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 10937719 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 094D6112C for ; Thu, 9 May 2019 21:04:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAEBC28AD1 for ; Thu, 9 May 2019 21:04:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D962328AFB; Thu, 9 May 2019 21:04:53 +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,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 6D3C628AD1 for ; Thu, 9 May 2019 21:04:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1420789B95; Thu, 9 May 2019 21:04:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on060e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe45::60e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F85B89B95; Thu, 9 May 2019 21:04:48 +0000 (UTC) Received: from MWHPR12CA0034.namprd12.prod.outlook.com (2603:10b6:301:2::20) by DM5PR1201MB0060.namprd12.prod.outlook.com (2603:10b6:4:54::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.15; Thu, 9 May 2019 21:04:45 +0000 Received: from CO1NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::201) by MWHPR12CA0034.outlook.office365.com (2603:10b6:301:2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1878.21 via Frontend Transport; Thu, 9 May 2019 21:04:45 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT005.mail.protection.outlook.com (10.152.80.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Thu, 9 May 2019 21:04:44 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 9 May 2019 16:04:42 -0500 From: Kenny Ho To: , , , , , , , , Subject: [RFC PATCH v2 1/5] cgroup: Introduce cgroup for drm subsystem Date: Thu, 9 May 2019 17:04:06 -0400 Message-ID: <20190509210410.5471-2-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509210410.5471-1-Kenny.Ho@amd.com> References: <20181120185814.13362-1-Kenny.Ho@amd.com> <20190509210410.5471-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(136003)(39860400002)(2980300002)(428003)(189003)(199004)(478600001)(47776003)(1076003)(72206003)(50226002)(81166006)(81156014)(8676002)(8936002)(6666004)(356004)(14444005)(305945005)(53416004)(5024004)(2616005)(476003)(11346002)(446003)(86362001)(126002)(486006)(426003)(186003)(26005)(77096007)(48376002)(110136005)(50466002)(5660300002)(2201001)(336012)(53936002)(68736007)(7696005)(2870700001)(76176011)(51416003)(2906002)(70586007)(70206006)(316002)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR1201MB0060; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 601a1d46-a0f3-4dd8-addd-08d6d4c1f6bd X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328); SRVR:DM5PR1201MB0060; X-MS-TrafficTypeDiagnostic: DM5PR1201MB0060: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-Forefront-PRVS: 003245E729 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: /g/WIAAD+T/l6ZZpl8UZgSVYU8UKyRJEQ2kup3NZhBuClnD15gSy+XTg/vMLcQH1/9LRwXLVh2rDQ3H6GBCk4vsHZ9FfhGc853lKtJC2V48bNfrsjseWUQY9GrqKj9WZDijgjKLX94s/H5mNu5hlKlK83Eyyq4LZarImXXaPSIiuqX/FOIRq9PAB71egCxsF0aj9zy2v4/dmGOmuwLiuQY5DMiELMpi3UTec3PXspWwrX3GRyZwAxss+mDboeUdxDkYx04HbNKf7ecWRGnF5xoIRrsr60MqBMCuLTsIDiOaHgQgBRTLuC4WZqTJPHWg1nTsUww7Sys0CMchhs+IfX8OhqKNNq3NT8rLQ7+BWQ+vPcXRstOZvgAcJJ9m0qvK/6oE+D6EUlzG4YSpkHbh40jRejMEOiVqtiaPwRlOWgo0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2019 21:04:44.9608 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 601a1d46-a0f3-4dd8-addd-08d6d4c1f6bd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0060 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7YOVKDWqtsp3YOBhGBQhAAXk2OeBSRU2dQNs+Dfx/+U=; b=tXUFCw7oPwjifIZLe81w7Zc2oACV/bgrI6ivuuvl9Nv61IWawG9tdQmXwk1H8HYE1luoEj8fDQa1BiLUrgk06OPa1gqGuORgmDwh9VeJOptZHFipyafKxZQZom82DJA3WMPqx+uQ77/VQ+vFg1ZxFa6LyXtvyd71kyW28qUbSYw= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=permerror action=none header.from=amd.com; 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change-Id: I6830d3990f63f0c13abeba29b1d330cf28882831 Signed-off-by: Kenny Ho --- include/linux/cgroup_drm.h | 32 ++++++++++++++++++++++++++ include/linux/cgroup_subsys.h | 4 ++++ init/Kconfig | 5 +++++ kernel/cgroup/Makefile | 1 + kernel/cgroup/drm.c | 42 +++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 include/linux/cgroup_drm.h create mode 100644 kernel/cgroup/drm.c diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h new file mode 100644 index 000000000000..121001be1230 --- /dev/null +++ b/include/linux/cgroup_drm.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: MIT + * Copyright 2019 Advanced Micro Devices, Inc. + */ +#ifndef _CGROUP_DRM_H +#define _CGROUP_DRM_H + +#ifdef CONFIG_CGROUP_DRM + +#include + +struct drmcgrp { + struct cgroup_subsys_state css; +}; + +static inline struct drmcgrp *css_drmcgrp(struct cgroup_subsys_state *css) +{ + return css ? container_of(css, struct drmcgrp, css) : NULL; +} + +static inline struct drmcgrp *get_drmcgrp(struct task_struct *task) +{ + return css_drmcgrp(task_get_css(task, drm_cgrp_id)); +} + + +static inline struct drmcgrp *parent_drmcgrp(struct drmcgrp *cg) +{ + return css_drmcgrp(cg->css.parent); +} + +#endif /* CONFIG_CGROUP_DRM */ +#endif /* _CGROUP_DRM_H */ diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h index acb77dcff3b4..ddedad809e8b 100644 --- a/include/linux/cgroup_subsys.h +++ b/include/linux/cgroup_subsys.h @@ -61,6 +61,10 @@ SUBSYS(pids) SUBSYS(rdma) #endif +#if IS_ENABLED(CONFIG_CGROUP_DRM) +SUBSYS(drm) +#endif + /* * The following subsystems are not supported on the default hierarchy. */ diff --git a/init/Kconfig b/init/Kconfig index d47cb77a220e..0b0f112eb23b 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -839,6 +839,11 @@ config CGROUP_RDMA Attaching processes with active RDMA resources to the cgroup hierarchy is allowed even if can cross the hierarchy's limit. +config CGROUP_DRM + bool "DRM controller (EXPERIMENTAL)" + help + Provides accounting and enforcement of resources in the DRM subsystem. + config CGROUP_FREEZER bool "Freezer controller" help diff --git a/kernel/cgroup/Makefile b/kernel/cgroup/Makefile index bfcdae896122..6af14bd93050 100644 --- a/kernel/cgroup/Makefile +++ b/kernel/cgroup/Makefile @@ -4,5 +4,6 @@ obj-y := cgroup.o rstat.o namespace.o cgroup-v1.o obj-$(CONFIG_CGROUP_FREEZER) += freezer.o obj-$(CONFIG_CGROUP_PIDS) += pids.o obj-$(CONFIG_CGROUP_RDMA) += rdma.o +obj-$(CONFIG_CGROUP_DRM) += drm.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_DEBUG) += debug.o diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c new file mode 100644 index 000000000000..620c887d6d24 --- /dev/null +++ b/kernel/cgroup/drm.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: MIT +// Copyright 2019 Advanced Micro Devices, Inc. +#include +#include +#include + +static struct drmcgrp *root_drmcgrp __read_mostly; + +static void drmcgrp_css_free(struct cgroup_subsys_state *css) +{ + struct drmcgrp *drmcgrp = css_drmcgrp(css); + + kfree(css_drmcgrp(css)); +} + +static struct cgroup_subsys_state * +drmcgrp_css_alloc(struct cgroup_subsys_state *parent_css) +{ + struct drmcgrp *parent = css_drmcgrp(parent_css); + struct drmcgrp *drmcgrp; + + drmcgrp = kzalloc(sizeof(struct drmcgrp), GFP_KERNEL); + if (!drmcgrp) + return ERR_PTR(-ENOMEM); + + if (!parent) + root_drmcgrp = drmcgrp; + + return &drmcgrp->css; +} + +struct cftype files[] = { + { } /* terminate */ +}; + +struct cgroup_subsys drm_cgrp_subsys = { + .css_alloc = drmcgrp_css_alloc, + .css_free = drmcgrp_css_free, + .early_init = false, + .legacy_cftypes = files, + .dfl_cftypes = files, +}; From patchwork Thu May 9 21:04:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 10937725 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 778661390 for ; Thu, 9 May 2019 21:05:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68FD028740 for ; Thu, 9 May 2019 21:05:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A06A287AB; Thu, 9 May 2019 21:05:00 +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,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 DBEA728740 for ; Thu, 9 May 2019 21:04:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DFE2289CCE; Thu, 9 May 2019 21:04:52 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-eopbgr810085.outbound.protection.outlook.com [40.107.81.85]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2187A89BF8; Thu, 9 May 2019 21:04:49 +0000 (UTC) Received: from MWHPR12CA0032.namprd12.prod.outlook.com (2603:10b6:301:2::18) by BN7PR12MB2658.namprd12.prod.outlook.com (2603:10b6:408:29::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.12; Thu, 9 May 2019 21:04:46 +0000 Received: from CO1NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::205) by MWHPR12CA0032.outlook.office365.com (2603:10b6:301:2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1878.21 via Frontend Transport; Thu, 9 May 2019 21:04:46 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT005.mail.protection.outlook.com (10.152.80.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Thu, 9 May 2019 21:04:46 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 9 May 2019 16:04:43 -0500 From: Kenny Ho To: , , , , , , , , Subject: [RFC PATCH v2 2/5] cgroup: Add mechanism to register DRM devices Date: Thu, 9 May 2019 17:04:07 -0400 Message-ID: <20190509210410.5471-3-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509210410.5471-1-Kenny.Ho@amd.com> References: <20181120185814.13362-1-Kenny.Ho@amd.com> <20190509210410.5471-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(396003)(376002)(136003)(39860400002)(346002)(2980300002)(428003)(199004)(189003)(72206003)(47776003)(305945005)(48376002)(50466002)(478600001)(5660300002)(11346002)(316002)(70586007)(70206006)(50226002)(51416003)(7696005)(76176011)(2870700001)(110136005)(2906002)(53936002)(6666004)(356004)(1076003)(14444005)(446003)(36756003)(186003)(77096007)(476003)(2616005)(2201001)(336012)(426003)(86362001)(53416004)(486006)(8936002)(81166006)(81156014)(8676002)(126002)(26005)(68736007); DIR:OUT; SFP:1101; SCL:1; SRVR:BN7PR12MB2658; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31415bab-964f-444d-e0da-08d6d4c1f766 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328); SRVR:BN7PR12MB2658; X-MS-TrafficTypeDiagnostic: BN7PR12MB2658: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:663; X-Forefront-PRVS: 003245E729 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: g2PtkT3bEYSwvzNjkNT2oNOitOeg67m36U7LBlLd3Oo0Uv5gmzv+L47TWBVCe+4n77/YYQ/BzdVW4fgcidp+WglDlv8d7mQ3QXNi6rmMlLvKUTDp6Cht5+TDpCSKMMI6iW3VIYDLITGC8/N0GPEvrbfuBj1q9aeIKSCeYvpQBbS5YlYXEphbLzsaWc91yPibNoPaEtXvCHKYtmFSdb9gU2shBgSGZY6Cb9rxmbLuAvdzOAznaU+nbBSK/2XGvOpwtwKYfKLdSVNr4pfswQxh8P8XzKZLgfplacHLqobmg96K38EUmY/eEOkEODDpVXJDYKY29/6vWpoBeLJedDhQthmQcHE6UUAkTZFVLVhVt+c4pL34AuxMBWH2hU2zOYJrUqhv3dDVkTLEoK7jYomM/NUbXLpfDFgHHmsxpOgMWCU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2019 21:04:46.0952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31415bab-964f-444d-e0da-08d6d4c1f766 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2658 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kQLJJ8Yh38Q57nt87ttc/UN4TMRcEVVhzIf4fqMum0I=; b=HP7Cc6OIKyuVxgHGDZp6Jj4eWORS/dMXpecLkpRWjUBrAIva+/w7why5AJkg36/opzT5OCyMZNwd50sn6Usu/IoZGNupl3BjtFrdKzD2RSxwU1bNoYggPc2WZQdEOOlGPZoorEOsEGcVews9a855OSMelUHwiabDVko519oT2/A= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=permerror action=none header.from=amd.com; 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change-Id: I908ee6975ea0585e4c30eafde4599f87094d8c65 Signed-off-by: Kenny Ho --- include/drm/drm_cgroup.h | 24 ++++++++ include/linux/cgroup_drm.h | 10 ++++ kernel/cgroup/drm.c | 118 ++++++++++++++++++++++++++++++++++++- 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 include/drm/drm_cgroup.h diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h new file mode 100644 index 000000000000..ddb9eab64360 --- /dev/null +++ b/include/drm/drm_cgroup.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: MIT + * Copyright 2019 Advanced Micro Devices, Inc. + */ +#ifndef __DRM_CGROUP_H__ +#define __DRM_CGROUP_H__ + +#ifdef CONFIG_CGROUP_DRM + +int drmcgrp_register_device(struct drm_device *device); + +int drmcgrp_unregister_device(struct drm_device *device); + +#else +static inline int drmcgrp_register_device(struct drm_device *device) +{ + return 0; +} + +static inline int drmcgrp_unregister_device(struct drm_device *device) +{ + return 0; +} +#endif /* CONFIG_CGROUP_DRM */ +#endif /* __DRM_CGROUP_H__ */ diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index 121001be1230..d7ccf434ca6b 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -6,10 +6,20 @@ #ifdef CONFIG_CGROUP_DRM +#include #include +#include + +/* limit defined per the way drm_minor_alloc operates */ +#define MAX_DRM_DEV (64 * DRM_MINOR_RENDER) + +struct drmcgrp_device_resource { + /* for per device stats */ +}; struct drmcgrp { struct cgroup_subsys_state css; + struct drmcgrp_device_resource *dev_resources[MAX_DRM_DEV]; }; static inline struct drmcgrp *css_drmcgrp(struct cgroup_subsys_state *css) diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index 620c887d6d24..f9ef4bf042d8 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -1,16 +1,79 @@ // SPDX-License-Identifier: MIT // Copyright 2019 Advanced Micro Devices, Inc. +#include #include #include +#include +#include +#include #include +#include +#include + +static DEFINE_MUTEX(drmcgrp_mutex); + +struct drmcgrp_device { + struct drm_device *dev; + struct mutex mutex; +}; + +/* indexed by drm_minor for access speed */ +static struct drmcgrp_device *known_drmcgrp_devs[MAX_DRM_DEV]; + +static int max_minor; + static struct drmcgrp *root_drmcgrp __read_mostly; static void drmcgrp_css_free(struct cgroup_subsys_state *css) { struct drmcgrp *drmcgrp = css_drmcgrp(css); + int i; + + for (i = 0; i <= max_minor; i++) { + if (drmcgrp->dev_resources[i] != NULL) + kfree(drmcgrp->dev_resources[i]); + } + + kfree(drmcgrp); +} + +static inline int init_drmcgrp_single(struct drmcgrp *drmcgrp, int i) +{ + struct drmcgrp_device_resource *ddr = drmcgrp->dev_resources[i]; + + if (ddr == NULL) { + ddr = kzalloc(sizeof(struct drmcgrp_device_resource), + GFP_KERNEL); + + if (!ddr) + return -ENOMEM; + + drmcgrp->dev_resources[i] = ddr; + } + + /* set defaults here */ + + return 0; +} + +static inline int init_drmcgrp(struct drmcgrp *drmcgrp, struct drm_device *dev) +{ + int rc = 0; + int i; + + if (dev != NULL) { + rc = init_drmcgrp_single(drmcgrp, dev->primary->index); + return rc; + } + + for (i = 0; i <= max_minor; i++) { + rc = init_drmcgrp_single(drmcgrp, i); + if (rc) + return rc; + } - kfree(css_drmcgrp(css)); + return 0; } static struct cgroup_subsys_state * @@ -18,11 +81,18 @@ drmcgrp_css_alloc(struct cgroup_subsys_state *parent_css) { struct drmcgrp *parent = css_drmcgrp(parent_css); struct drmcgrp *drmcgrp; + int rc; drmcgrp = kzalloc(sizeof(struct drmcgrp), GFP_KERNEL); if (!drmcgrp) return ERR_PTR(-ENOMEM); + rc = init_drmcgrp(drmcgrp, NULL); + if (rc) { + drmcgrp_css_free(&drmcgrp->css); + return ERR_PTR(rc); + } + if (!parent) root_drmcgrp = drmcgrp; @@ -40,3 +110,49 @@ struct cgroup_subsys drm_cgrp_subsys = { .legacy_cftypes = files, .dfl_cftypes = files, }; + +int drmcgrp_register_device(struct drm_device *dev) +{ + struct drmcgrp_device *ddev; + struct cgroup_subsys_state *pos; + struct drmcgrp *child; + + ddev = kzalloc(sizeof(struct drmcgrp_device), GFP_KERNEL); + if (!ddev) + return -ENOMEM; + + ddev->dev = dev; + mutex_init(&ddev->mutex); + + mutex_lock(&drmcgrp_mutex); + known_drmcgrp_devs[dev->primary->index] = ddev; + max_minor = max(max_minor, dev->primary->index); + mutex_unlock(&drmcgrp_mutex); + + /* init cgroups created before registration (i.e. root cgroup) */ + if (root_drmcgrp != NULL) { + init_drmcgrp(root_drmcgrp, dev); + + rcu_read_lock(); + css_for_each_child(pos, &root_drmcgrp->css) { + child = css_drmcgrp(pos); + init_drmcgrp(child, dev); + } + rcu_read_unlock(); + } + + return 0; +} +EXPORT_SYMBOL(drmcgrp_register_device); + +int drmcgrp_unregister_device(struct drm_device *dev) +{ + mutex_lock(&drmcgrp_mutex); + + kfree(known_drmcgrp_devs[dev->primary->index]); + known_drmcgrp_devs[dev->primary->index] = NULL; + + mutex_unlock(&drmcgrp_mutex); + return 0; +} +EXPORT_SYMBOL(drmcgrp_unregister_device); From patchwork Thu May 9 21:04:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 10937727 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 D03F71390 for ; Thu, 9 May 2019 21:05:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF4F728769 for ; Thu, 9 May 2019 21:05:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFFF6287AB; Thu, 9 May 2019 21:05:01 +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,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 6BE4328740 for ; Thu, 9 May 2019 21:05:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1924389CDB; Thu, 9 May 2019 21:04:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700063.outbound.protection.outlook.com [40.107.70.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5077389CCE; Thu, 9 May 2019 21:04:51 +0000 (UTC) Received: from MWHPR12CA0034.namprd12.prod.outlook.com (2603:10b6:301:2::20) by SN6PR12MB2671.namprd12.prod.outlook.com (2603:10b6:805:6f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1878.21; Thu, 9 May 2019 21:04:49 +0000 Received: from CO1NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::201) by MWHPR12CA0034.outlook.office365.com (2603:10b6:301:2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1878.21 via Frontend Transport; Thu, 9 May 2019 21:04:49 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT005.mail.protection.outlook.com (10.152.80.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Thu, 9 May 2019 21:04:48 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 9 May 2019 16:04:43 -0500 From: Kenny Ho To: , , , , , , , , Subject: [RFC PATCH v2 3/5] drm/amdgpu: Register AMD devices for DRM cgroup Date: Thu, 9 May 2019 17:04:08 -0400 Message-ID: <20190509210410.5471-4-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509210410.5471-1-Kenny.Ho@amd.com> References: <20181120185814.13362-1-Kenny.Ho@amd.com> <20190509210410.5471-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(136003)(376002)(346002)(396003)(39860400002)(2980300002)(428003)(199004)(189003)(476003)(2616005)(126002)(72206003)(336012)(81156014)(305945005)(81166006)(486006)(53416004)(7696005)(36756003)(426003)(446003)(51416003)(11346002)(2870700001)(2906002)(6666004)(478600001)(76176011)(8936002)(47776003)(316002)(1076003)(77096007)(26005)(70586007)(70206006)(48376002)(2201001)(356004)(86362001)(50226002)(50466002)(8676002)(110136005)(53936002)(68736007)(5660300002)(186003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2671; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b43026b-8ffb-4019-38bb-08d6d4c1f8f4 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328); SRVR:SN6PR12MB2671; X-MS-TrafficTypeDiagnostic: SN6PR12MB2671: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:346; X-Forefront-PRVS: 003245E729 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: MPYqT7IjpALzQyud7sj3ZC1neMDLVqQ9PTQBmy9eRsk4/7/VdC3dk0fEJTW5qvaFReyND1socHkpealQbUON3b20/uB0WzHf2ePVgqoi+GUsOkA9vYsT83gjwbhtGMtG4F1iCU2MZWWI0VnhDF+8gQEcmo07Yf6U7QfJYsqF8Bp6gggxh21YiCXSwI2wv5t5551PCiHOzhQoMlTSNNgcKaAzlBLYlmU5zjRNnPCc/OjFjTQXhLYQ23sW1PW5Eq2ai++6Z06xqmMSwKrafjPPRKHs2v9Ttf75yawGqceZCDMOZdd8MVM2VKJPZfjYAqhuYRpWuVD+UtO3kwalx9QSrgL8sbhdBiEVyLcK9/Wifjm1v5lSQnoFy7tkKf/waXxFjzSJ+3yx0IrUEKMR1MMxr9J4MyRIBeNcO2wxs6B3pY0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2019 21:04:48.7103 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b43026b-8ffb-4019-38bb-08d6d4c1f8f4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2671 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0p3P4yVdgVx46kHS0E6T83+GWZwfheVmXlIy09vAgIk=; b=WsBq3K/Tc7Gn9tdmTGQntaQcOuhQf14sKmWxNLajbdZVhoJAUHPCCwQKGPhYz1wXcirVbzxLtseGix1riQXLybhsqbHbeEy8gE+EcOIKKmBM4iw6pWuhMSXYC6A/yMiYHCVxIRpmdjh34yAGZZPWI+X9CmwtEWgAKAcU1Du10TQ= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=permerror action=none header.from=amd.com; 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change-Id: I3750fc657b956b52750a36cb303c54fa6a265b44 Signed-off-by: Kenny Ho --- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index da7b4fe8ade3..2568fd730161 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -28,6 +28,7 @@ #include #include "amdgpu.h" #include +#include #include "amdgpu_sched.h" #include "amdgpu_uvd.h" #include "amdgpu_vce.h" @@ -97,6 +98,7 @@ void amdgpu_driver_unload_kms(struct drm_device *dev) amdgpu_device_fini(adev); + drmcgrp_unregister_device(dev); done_free: kfree(adev); dev->dev_private = NULL; @@ -141,6 +143,8 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags) struct amdgpu_device *adev; int r, acpi_status; + drmcgrp_register_device(dev); + #ifdef CONFIG_DRM_AMDGPU_SI if (!amdgpu_si_support) { switch (flags & AMD_ASIC_MASK) { From patchwork Thu May 9 21:04:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 10937729 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 71556112C for ; Thu, 9 May 2019 21:05:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6188A28740 for ; Thu, 9 May 2019 21:05:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55128287AB; Thu, 9 May 2019 21:05:04 +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,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 6F63828740 for ; Thu, 9 May 2019 21:05:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6FC8489CF8; Thu, 9 May 2019 21:04:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700049.outbound.protection.outlook.com [40.107.70.49]) by gabe.freedesktop.org (Postfix) with ESMTPS id E1D1E89CDF; Thu, 9 May 2019 21:04:53 +0000 (UTC) Received: from MWHPR12CA0034.namprd12.prod.outlook.com (2603:10b6:301:2::20) by SN6PR12MB2671.namprd12.prod.outlook.com (2603:10b6:805:6f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1878.21; Thu, 9 May 2019 21:04:51 +0000 Received: from CO1NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::201) by MWHPR12CA0034.outlook.office365.com (2603:10b6:301:2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1878.21 via Frontend Transport; Thu, 9 May 2019 21:04:51 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT005.mail.protection.outlook.com (10.152.80.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Thu, 9 May 2019 21:04:50 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 9 May 2019 16:04:44 -0500 From: Kenny Ho To: , , , , , , , , Subject: [RFC PATCH v2 4/5] drm, cgroup: Add total GEM buffer allocation limit Date: Thu, 9 May 2019 17:04:09 -0400 Message-ID: <20190509210410.5471-5-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509210410.5471-1-Kenny.Ho@amd.com> References: <20181120185814.13362-1-Kenny.Ho@amd.com> <20190509210410.5471-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(136003)(376002)(346002)(396003)(39860400002)(2980300002)(428003)(199004)(189003)(476003)(2616005)(14444005)(126002)(72206003)(336012)(81156014)(305945005)(81166006)(486006)(53416004)(7696005)(36756003)(426003)(446003)(51416003)(11346002)(2870700001)(2906002)(6666004)(478600001)(76176011)(8936002)(47776003)(316002)(1076003)(77096007)(26005)(70586007)(70206006)(48376002)(2201001)(356004)(86362001)(50226002)(50466002)(8676002)(110136005)(53936002)(30864003)(68736007)(5660300002)(186003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR12MB2671; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54b7ce6a-b3f8-492a-5086-08d6d4c1fa46 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328); SRVR:SN6PR12MB2671; X-MS-TrafficTypeDiagnostic: SN6PR12MB2671: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:989; X-Forefront-PRVS: 003245E729 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Q3OGCQVDfZJjjuZcuLP8vt0dBVC4q0wSKGcb6jy9YxTATRS8HHwBII83/AOk7VglLgaFQmBELaOq5CjxWWvPBeJNWsBTnQuXhOAPkLXF49yyM3v0lUbgW4JZHXoJlNYoOzimZFiJ0Nj9tktmyxqBZILSl6s57oLv7aDiXT73Ayf8Z8LkTgnTbz6j8wwrZlEbV3tbuUkA4TlGq7UD1GKJYKNKFOYlUETYlo1SFvvZMiIwOu7fzudvDsumdJbTdVLHfCtGgOrlLcwQABzeWfvm3JNk3dReKPmjPlUtOQA2buCvQKG/Z/uhRJIBcuAGM9AYhexUW2IZU+bBRpm9jXDdUV9PoRRwqHsYyY2PuRkEOqksJzRDo8VcTA0maUXsG3tWk0WNvdQQlDYhbtL+Kpbf1vxvUt7p8F/qTYZyUU0sD6Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2019 21:04:50.9130 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54b7ce6a-b3f8-492a-5086-08d6d4c1fa46 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2671 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a9QVh0gSfL5n76wZ8WGqfnlFCaOlDZ4oBdpy8yxVj+I=; b=g0DxwaWytGafXyfd4B2X4BXSudujT5e+1PKfJIvNJYeZir07vsaeNtWYMIVMzm2Qcol3eilW1aG51Jvqi7gWW6ON6cMQNN+LDT6D6mpYnY6NoB5hPUhBY5Z+aIZ+Qjepj92xc4f+36CuCTAWc+QfgciKmU6QOYraKoou6VHi6JU= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=permerror action=none header.from=amd.com; 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The drm resource being measured and limited here is the GEM buffer objects. User applications allocate and free these buffers. In addition, a process can allocate a buffer and share it with another process. The consumer of a shared buffer can also outlive the allocator of the buffer. For the purpose of cgroup accounting and limiting, ownership of the buffer is deemed to be the cgroup for which the allocating process belongs to. There is one limit per drm device. In order to prevent the buffer outliving the cgroup that owns it, a process is prevented from importing buffers that are not own by the process' cgroup or the ancestors of the process' cgroup. For this resource, the control files are prefixed with drm.buffer.total. There are four control file types, stats (ro) - display current measured values for a resource max (rw) - limits for a resource default (ro, root cgroup only) - default values for a resource help (ro, root cgroup only) - help string for a resource Each file is multi-lined with one entry/line per drm device. Usage examples: // set limit for card1 to 1GB sed -i '2s/.*/1073741824/' /sys/fs/cgroup//drm.buffer.total.max // set limit for card0 to 512MB sed -i '1s/.*/536870912/' /sys/fs/cgroup//drm.buffer.total.max Change-Id: I4c249d06d45ec709d6481d4cbe87c5168545c5d0 Signed-off-by: Kenny Ho --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 + drivers/gpu/drm/drm_gem.c | 7 + drivers/gpu/drm/drm_prime.c | 9 + include/drm/drm_cgroup.h | 34 ++- include/drm/drm_gem.h | 11 + include/linux/cgroup_drm.h | 3 + kernel/cgroup/drm.c | 280 +++++++++++++++++++++ 7 files changed, 346 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 93b2c5a48a71..b4c078b7ad63 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "amdgpu.h" #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h" @@ -446,6 +447,9 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, if (!amdgpu_bo_validate_size(adev, size, bp->domain)) return -ENOMEM; + if (!drmcgrp_bo_can_allocate(current, adev->ddev, size)) + return -ENOMEM; + *bo_ptr = NULL; acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size, diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 6a80db077dc6..cbd49bf34dcf 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -37,10 +37,12 @@ #include #include #include +#include #include #include #include #include +#include #include "drm_internal.h" /** @file drm_gem.c @@ -154,6 +156,9 @@ void drm_gem_private_object_init(struct drm_device *dev, obj->handle_count = 0; obj->size = size; drm_vma_node_reset(&obj->vma_node); + + obj->drmcgrp = get_drmcgrp(current); + drmcgrp_chg_bo_alloc(obj->drmcgrp, dev, size); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -804,6 +809,8 @@ drm_gem_object_release(struct drm_gem_object *obj) if (obj->filp) fput(obj->filp); + drmcgrp_unchg_bo_alloc(obj->drmcgrp, obj->dev, obj->size); + drm_gem_free_mmap_offset(obj); } EXPORT_SYMBOL(drm_gem_object_release); diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 231e3f6d5f41..faed5611a1c6 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "drm_internal.h" @@ -794,6 +795,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, { struct dma_buf *dma_buf; struct drm_gem_object *obj; + struct drmcgrp *drmcgrp = get_drmcgrp(current); int ret; dma_buf = dma_buf_get(prime_fd); @@ -818,6 +820,13 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, goto out_unlock; } + /* only allow bo from the same cgroup or its ancestor to be imported */ + if (drmcgrp != NULL && + !drmcgrp_is_self_or_ancestor(drmcgrp, obj->drmcgrp)) { + ret = -EACCES; + goto out_unlock; + } + if (obj->dma_buf) { WARN_ON(obj->dma_buf != dma_buf); } else { diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h index ddb9eab64360..8711b7c5f7bf 100644 --- a/include/drm/drm_cgroup.h +++ b/include/drm/drm_cgroup.h @@ -4,12 +4,20 @@ #ifndef __DRM_CGROUP_H__ #define __DRM_CGROUP_H__ +#include + #ifdef CONFIG_CGROUP_DRM int drmcgrp_register_device(struct drm_device *device); - int drmcgrp_unregister_device(struct drm_device *device); - +bool drmcgrp_is_self_or_ancestor(struct drmcgrp *self, + struct drmcgrp *relative); +void drmcgrp_chg_bo_alloc(struct drmcgrp *drmcgrp, struct drm_device *dev, + size_t size); +void drmcgrp_unchg_bo_alloc(struct drmcgrp *drmcgrp, struct drm_device *dev, + size_t size); +bool drmcgrp_bo_can_allocate(struct task_struct *task, struct drm_device *dev, + size_t size); #else static inline int drmcgrp_register_device(struct drm_device *device) { @@ -20,5 +28,27 @@ static inline int drmcgrp_unregister_device(struct drm_device *device) { return 0; } + +static inline bool drmcgrp_is_self_or_ancestor(struct drmcgrp *self, + struct drmcgrp *relative) +{ + return false; +} + +static inline void drmcgrp_chg_bo_alloc(struct drmcgrp *drmcgrp, + struct drm_device *dev, size_t size) +{ +} + +static inline void drmcgrp_unchg_bo_alloc(struct drmcgrp *drmcgrp, + struct drm_device *dev, size_t size) +{ +} + +static inline bool drmcgrp_bo_can_allocate(struct task_struct *task, + struct drm_device *dev, size_t size) +{ + return true; +} #endif /* CONFIG_CGROUP_DRM */ #endif /* __DRM_CGROUP_H__ */ diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index c95727425284..02854c674b5c 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -272,6 +272,17 @@ struct drm_gem_object { * */ const struct drm_gem_object_funcs *funcs; + + /** + * @drmcgrp: + * + * DRM cgroup this GEM object belongs to. + * + * This is used to track and limit the amount of GEM objects a user + * can allocate. Since GEM objects can be shared, this is also used + * to ensure GEM objects are only shared within the same cgroup. + */ + struct drmcgrp *drmcgrp; }; /** diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index d7ccf434ca6b..fe14ba7bb1cf 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -15,6 +15,9 @@ struct drmcgrp_device_resource { /* for per device stats */ + s64 bo_stats_total_allocated; + + s64 bo_limits_total_allocated; }; struct drmcgrp { diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index f9ef4bf042d8..bc3abff09113 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -15,6 +15,22 @@ static DEFINE_MUTEX(drmcgrp_mutex); struct drmcgrp_device { struct drm_device *dev; struct mutex mutex; + + s64 bo_limits_total_allocated_default; +}; + +#define DRMCG_CTF_PRIV_SIZE 3 +#define DRMCG_CTF_PRIV_MASK GENMASK((DRMCG_CTF_PRIV_SIZE - 1), 0) + +enum drmcgrp_res_type { + DRMCGRP_TYPE_BO_TOTAL, +}; + +enum drmcgrp_file_type { + DRMCGRP_FTYPE_STATS, + DRMCGRP_FTYPE_MAX, + DRMCGRP_FTYPE_DEFAULT, + DRMCGRP_FTYPE_HELP, }; /* indexed by drm_minor for access speed */ @@ -53,6 +69,10 @@ static inline int init_drmcgrp_single(struct drmcgrp *drmcgrp, int i) } /* set defaults here */ + if (known_drmcgrp_devs[i] != NULL) { + ddr->bo_limits_total_allocated = + known_drmcgrp_devs[i]->bo_limits_total_allocated_default; + } return 0; } @@ -99,7 +119,187 @@ drmcgrp_css_alloc(struct cgroup_subsys_state *parent_css) return &drmcgrp->css; } +static inline void drmcgrp_print_stats(struct drmcgrp_device_resource *ddr, + struct seq_file *sf, enum drmcgrp_res_type type) +{ + if (ddr == NULL) { + seq_puts(sf, "\n"); + return; + } + + switch (type) { + case DRMCGRP_TYPE_BO_TOTAL: + seq_printf(sf, "%lld\n", ddr->bo_stats_total_allocated); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + +static inline void drmcgrp_print_limits(struct drmcgrp_device_resource *ddr, + struct seq_file *sf, enum drmcgrp_res_type type) +{ + if (ddr == NULL) { + seq_puts(sf, "\n"); + return; + } + + switch (type) { + case DRMCGRP_TYPE_BO_TOTAL: + seq_printf(sf, "%lld\n", ddr->bo_limits_total_allocated); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + +static inline void drmcgrp_print_default(struct drmcgrp_device *ddev, + struct seq_file *sf, enum drmcgrp_res_type type) +{ + if (ddev == NULL) { + seq_puts(sf, "\n"); + return; + } + + switch (type) { + case DRMCGRP_TYPE_BO_TOTAL: + seq_printf(sf, "%lld\n", ddev->bo_limits_total_allocated_default); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + +static inline void drmcgrp_print_help(int cardNum, struct seq_file *sf, + enum drmcgrp_res_type type) +{ + switch (type) { + case DRMCGRP_TYPE_BO_TOTAL: + seq_printf(sf, + "Total amount of buffer allocation in bytes for card%d\n", + cardNum); + break; + default: + seq_puts(sf, "\n"); + break; + } +} + +int drmcgrp_bo_show(struct seq_file *sf, void *v) +{ + struct drmcgrp *drmcgrp = css_drmcgrp(seq_css(sf)); + struct drmcgrp_device_resource *ddr = NULL; + enum drmcgrp_file_type f_type = seq_cft(sf)-> + private & DRMCG_CTF_PRIV_MASK; + enum drmcgrp_res_type type = seq_cft(sf)-> + private >> DRMCG_CTF_PRIV_SIZE; + struct drmcgrp_device *ddev; + int i; + + for (i = 0; i <= max_minor; i++) { + ddr = drmcgrp->dev_resources[i]; + ddev = known_drmcgrp_devs[i]; + + switch (f_type) { + case DRMCGRP_FTYPE_STATS: + drmcgrp_print_stats(ddr, sf, type); + break; + case DRMCGRP_FTYPE_MAX: + drmcgrp_print_limits(ddr, sf, type); + break; + case DRMCGRP_FTYPE_DEFAULT: + drmcgrp_print_default(ddev, sf, type); + break; + case DRMCGRP_FTYPE_HELP: + drmcgrp_print_help(i, sf, type); + break; + default: + seq_puts(sf, "\n"); + break; + } + } + + return 0; +} + +ssize_t drmcgrp_bo_limit_write(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + struct drmcgrp *drmcgrp = css_drmcgrp(of_css(of)); + enum drmcgrp_res_type type = of_cft(of)->private >> DRMCG_CTF_PRIV_SIZE; + char *cft_name = of_cft(of)->name; + char *limits = strstrip(buf); + struct drmcgrp_device_resource *ddr; + char *sval; + s64 val; + int i = 0; + int rc; + + while (i <= max_minor && limits != NULL) { + sval = strsep(&limits, "\n"); + rc = kstrtoll(sval, 0, &val); + + if (rc) { + pr_err("drmcgrp: %s: minor %d, err %d. ", + cft_name, i, rc); + pr_cont_cgroup_name(drmcgrp->css.cgroup); + pr_cont("\n"); + } else { + ddr = drmcgrp->dev_resources[i]; + switch (type) { + case DRMCGRP_TYPE_BO_TOTAL: + if (val < 0) continue; + ddr->bo_limits_total_allocated = val; + break; + default: + break; + } + } + + i++; + } + + if (i <= max_minor) { + pr_err("drmcgrp: %s: less entries than # of drm devices. ", + cft_name); + pr_cont_cgroup_name(drmcgrp->css.cgroup); + pr_cont("\n"); + } + + return nbytes; +} + struct cftype files[] = { + { + .name = "buffer.total.stats", + .seq_show = drmcgrp_bo_show, + .private = (DRMCGRP_TYPE_BO_TOTAL << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_STATS, + }, + { + .name = "buffer.total.default", + .seq_show = drmcgrp_bo_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = (DRMCGRP_TYPE_BO_TOTAL << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_DEFAULT, + }, + { + .name = "buffer.total.help", + .seq_show = drmcgrp_bo_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = (DRMCGRP_TYPE_BO_TOTAL << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_HELP, + }, + { + .name = "buffer.total.max", + .write = drmcgrp_bo_limit_write, + .seq_show = drmcgrp_bo_show, + .private = (DRMCGRP_TYPE_BO_TOTAL << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_MAX, + }, { } /* terminate */ }; @@ -122,6 +322,8 @@ int drmcgrp_register_device(struct drm_device *dev) return -ENOMEM; ddev->dev = dev; + ddev->bo_limits_total_allocated_default = S64_MAX; + mutex_init(&ddev->mutex); mutex_lock(&drmcgrp_mutex); @@ -156,3 +358,81 @@ int drmcgrp_unregister_device(struct drm_device *dev) return 0; } EXPORT_SYMBOL(drmcgrp_unregister_device); + +bool drmcgrp_is_self_or_ancestor(struct drmcgrp *self, struct drmcgrp *relative) +{ + for (; self != NULL; self = parent_drmcgrp(self)) + if (self == relative) + return true; + + return false; +} +EXPORT_SYMBOL(drmcgrp_is_self_or_ancestor); + +bool drmcgrp_bo_can_allocate(struct task_struct *task, struct drm_device *dev, + size_t size) +{ + struct drmcgrp *drmcgrp = get_drmcgrp(task); + struct drmcgrp_device_resource *ddr; + struct drmcgrp_device_resource *d; + int devIdx = dev->primary->index; + bool result = true; + s64 delta = 0; + + if (drmcgrp == NULL || drmcgrp == root_drmcgrp) + return true; + + ddr = drmcgrp->dev_resources[devIdx]; + mutex_lock(&known_drmcgrp_devs[devIdx]->mutex); + for ( ; drmcgrp != root_drmcgrp; drmcgrp = parent_drmcgrp(drmcgrp)) { + d = drmcgrp->dev_resources[devIdx]; + delta = d->bo_limits_total_allocated - + d->bo_stats_total_allocated; + + if (delta <= 0 || size > delta) { + result = false; + break; + } + } + mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex); + + return result; +} +EXPORT_SYMBOL(drmcgrp_bo_can_allocate); + +void drmcgrp_chg_bo_alloc(struct drmcgrp *drmcgrp, struct drm_device *dev, + size_t size) +{ + struct drmcgrp_device_resource *ddr; + int devIdx = dev->primary->index; + + if (drmcgrp == NULL || known_drmcgrp_devs[devIdx] == NULL) + return; + + mutex_lock(&known_drmcgrp_devs[devIdx]->mutex); + for ( ; drmcgrp != NULL; drmcgrp = parent_drmcgrp(drmcgrp)) { + ddr = drmcgrp->dev_resources[devIdx]; + + ddr->bo_stats_total_allocated += (s64)size; + } + mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex); +} +EXPORT_SYMBOL(drmcgrp_chg_bo_alloc); + +void drmcgrp_unchg_bo_alloc(struct drmcgrp *drmcgrp, struct drm_device *dev, + size_t size) +{ + struct drmcgrp_device_resource *ddr; + int devIdx = dev->primary->index; + + if (drmcgrp == NULL || known_drmcgrp_devs[devIdx] == NULL) + return; + + ddr = drmcgrp->dev_resources[devIdx]; + mutex_lock(&known_drmcgrp_devs[devIdx]->mutex); + for ( ; drmcgrp != NULL; drmcgrp = parent_drmcgrp(drmcgrp)) + drmcgrp->dev_resources[devIdx]->bo_stats_total_allocated + -= (s64)size; + mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex); +} +EXPORT_SYMBOL(drmcgrp_unchg_bo_alloc); From patchwork Thu May 9 21:04:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 10937731 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 B1F651390 for ; Thu, 9 May 2019 21:05:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A31DE2875E for ; Thu, 9 May 2019 21:05:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94D5A28740; Thu, 9 May 2019 21:05:06 +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,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 E8C5228740 for ; Thu, 9 May 2019 21:05:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7867889D02; Thu, 9 May 2019 21:04:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-eopbgr780045.outbound.protection.outlook.com [40.107.78.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1CB3B89CDE; Thu, 9 May 2019 21:04:56 +0000 (UTC) Received: from MWHPR12CA0042.namprd12.prod.outlook.com (2603:10b6:301:2::28) by MWHPR1201MB0061.namprd12.prod.outlook.com (2603:10b6:301:54::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.11; Thu, 9 May 2019 21:04:53 +0000 Received: from CO1NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::202) by MWHPR12CA0042.outlook.office365.com (2603:10b6:301:2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1878.20 via Frontend Transport; Thu, 9 May 2019 21:04:53 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT005.mail.protection.outlook.com (10.152.80.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Thu, 9 May 2019 21:04:53 +0000 Received: from kho-5039A.amd.com (10.180.168.240) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 9 May 2019 16:04:45 -0500 From: Kenny Ho To: , , , , , , , , Subject: [RFC PATCH v2 5/5] drm, cgroup: Add peak GEM buffer allocation limit Date: Thu, 9 May 2019 17:04:10 -0400 Message-ID: <20190509210410.5471-6-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509210410.5471-1-Kenny.Ho@amd.com> References: <20181120185814.13362-1-Kenny.Ho@amd.com> <20190509210410.5471-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(396003)(376002)(2980300002)(428003)(199004)(189003)(81156014)(81166006)(8936002)(68736007)(36756003)(72206003)(50466002)(1076003)(50226002)(8676002)(476003)(478600001)(53936002)(53416004)(48376002)(14444005)(5660300002)(2870700001)(446003)(305945005)(2906002)(11346002)(426003)(2616005)(126002)(6666004)(356004)(336012)(47776003)(7696005)(51416003)(486006)(2201001)(76176011)(77096007)(86362001)(26005)(70206006)(316002)(186003)(70586007)(110136005); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0061; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e055f11-83d4-4e02-854b-08d6d4c1fb93 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328); SRVR:MWHPR1201MB0061; X-MS-TrafficTypeDiagnostic: MWHPR1201MB0061: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 003245E729 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Ps+ODp0IwguOyY+6VgoeC6NjqACH/9+Iy5YkyFC3G/Z4ugfx18vukJobaCQuSvrk6poMA9Xgs1lUk3k6Y1m0hdzuZ2KknrYAlrLT0xhUq3+d0//gRSyG/7NE/el0tzFW4D4z+sK4KeYQo0n175Q0C6yAIg5NRoyBvcZFUAlmZ4/bRWGY7sQkiulrQOlwrY4lbhWE57oIoOjWK3011AgpmPkTkF8FPmsJOFY0AnbVqBp4hgga88L84hZ2SaRuNQhSW5o90NPw3lSh17oGeo3+0Hp+Su2FLk4Aoam33blsxzVpuXYZjBN+BJ4HM1IVLiHKKpVH6crSLZCa35uWfBsDRe54TbNNaPC5A9gAp4vPW+mfslruZALM5eUAGk+hjoSfxOhSEgm6vVsaaz9d5WzXA4SDtfDezCU+fbNBrK4bpuA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2019 21:04:53.1137 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e055f11-83d4-4e02-854b-08d6d4c1fb93 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0061 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uxfB8umjujUKa550IKO39yIy4Zl3LfD2QKKjPG+Msgg=; b=HrrTuh25eUqPy979GWkxIFXJfHBliSGPxA5Znv5LY26uJbRRjiJnHwBo8TrRrQJ7dQdJkWyODzSTCh6JZmKkft8d7h4C3gmAYtykObX/labk6S+VzRSWaYzWewNkUz3S1FncpDZc3MLMGhLpzJgmjSXcA9ASA+TPhVY0lpqBFUk= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=permerror action=none header.from=amd.com; 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This new drmcgrp resource limits the largest GEM buffer that can be allocated in a cgroup. Change-Id: I0830d56775568e1cf215b56cc892d5e7945e9f25 Signed-off-by: Kenny Ho --- include/linux/cgroup_drm.h | 2 ++ kernel/cgroup/drm.c | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h index fe14ba7bb1cf..57c07a148975 100644 --- a/include/linux/cgroup_drm.h +++ b/include/linux/cgroup_drm.h @@ -16,8 +16,10 @@ struct drmcgrp_device_resource { /* for per device stats */ s64 bo_stats_total_allocated; + size_t bo_stats_peak_allocated; s64 bo_limits_total_allocated; + size_t bo_limits_peak_allocated; }; struct drmcgrp { diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c index bc3abff09113..5c7e1b8059ce 100644 --- a/kernel/cgroup/drm.c +++ b/kernel/cgroup/drm.c @@ -17,6 +17,7 @@ struct drmcgrp_device { struct mutex mutex; s64 bo_limits_total_allocated_default; + size_t bo_limits_peak_allocated_default; }; #define DRMCG_CTF_PRIV_SIZE 3 @@ -24,6 +25,7 @@ struct drmcgrp_device { enum drmcgrp_res_type { DRMCGRP_TYPE_BO_TOTAL, + DRMCGRP_TYPE_BO_PEAK, }; enum drmcgrp_file_type { @@ -72,6 +74,9 @@ static inline int init_drmcgrp_single(struct drmcgrp *drmcgrp, int i) if (known_drmcgrp_devs[i] != NULL) { ddr->bo_limits_total_allocated = known_drmcgrp_devs[i]->bo_limits_total_allocated_default; + + ddr->bo_limits_peak_allocated = + known_drmcgrp_devs[i]->bo_limits_peak_allocated_default; } return 0; @@ -131,6 +136,9 @@ static inline void drmcgrp_print_stats(struct drmcgrp_device_resource *ddr, case DRMCGRP_TYPE_BO_TOTAL: seq_printf(sf, "%lld\n", ddr->bo_stats_total_allocated); break; + case DRMCGRP_TYPE_BO_PEAK: + seq_printf(sf, "%zu\n", ddr->bo_stats_peak_allocated); + break; default: seq_puts(sf, "\n"); break; @@ -149,6 +157,9 @@ static inline void drmcgrp_print_limits(struct drmcgrp_device_resource *ddr, case DRMCGRP_TYPE_BO_TOTAL: seq_printf(sf, "%lld\n", ddr->bo_limits_total_allocated); break; + case DRMCGRP_TYPE_BO_PEAK: + seq_printf(sf, "%zu\n", ddr->bo_limits_peak_allocated); + break; default: seq_puts(sf, "\n"); break; @@ -167,6 +178,9 @@ static inline void drmcgrp_print_default(struct drmcgrp_device *ddev, case DRMCGRP_TYPE_BO_TOTAL: seq_printf(sf, "%lld\n", ddev->bo_limits_total_allocated_default); break; + case DRMCGRP_TYPE_BO_PEAK: + seq_printf(sf, "%zu\n", ddev->bo_limits_peak_allocated_default); + break; default: seq_puts(sf, "\n"); break; @@ -182,6 +196,11 @@ static inline void drmcgrp_print_help(int cardNum, struct seq_file *sf, "Total amount of buffer allocation in bytes for card%d\n", cardNum); break; + case DRMCGRP_TYPE_BO_PEAK: + seq_printf(sf, + "Largest buffer allocation in bytes for card%d\n", + cardNum); + break; default: seq_puts(sf, "\n"); break; @@ -254,6 +273,10 @@ ssize_t drmcgrp_bo_limit_write(struct kernfs_open_file *of, char *buf, if (val < 0) continue; ddr->bo_limits_total_allocated = val; break; + case DRMCGRP_TYPE_BO_PEAK: + if (val < 0) continue; + ddr->bo_limits_peak_allocated = val; + break; default: break; } @@ -300,6 +323,33 @@ struct cftype files[] = { .private = (DRMCGRP_TYPE_BO_TOTAL << DRMCG_CTF_PRIV_SIZE) | DRMCGRP_FTYPE_MAX, }, + { + .name = "buffer.peak.stats", + .seq_show = drmcgrp_bo_show, + .private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_STATS, + }, + { + .name = "buffer.peak.default", + .seq_show = drmcgrp_bo_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_DEFAULT, + }, + { + .name = "buffer.peak.help", + .seq_show = drmcgrp_bo_show, + .flags = CFTYPE_ONLY_ON_ROOT, + .private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_HELP, + }, + { + .name = "buffer.peak.max", + .write = drmcgrp_bo_limit_write, + .seq_show = drmcgrp_bo_show, + .private = (DRMCGRP_TYPE_BO_PEAK << DRMCG_CTF_PRIV_SIZE) | + DRMCGRP_FTYPE_MAX, + }, { } /* terminate */ }; @@ -323,6 +373,7 @@ int drmcgrp_register_device(struct drm_device *dev) ddev->dev = dev; ddev->bo_limits_total_allocated_default = S64_MAX; + ddev->bo_limits_peak_allocated_default = SIZE_MAX; mutex_init(&ddev->mutex); @@ -393,6 +444,11 @@ bool drmcgrp_bo_can_allocate(struct task_struct *task, struct drm_device *dev, result = false; break; } + + if (d->bo_limits_peak_allocated < size) { + result = false; + break; + } } mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex); @@ -414,6 +470,9 @@ void drmcgrp_chg_bo_alloc(struct drmcgrp *drmcgrp, struct drm_device *dev, ddr = drmcgrp->dev_resources[devIdx]; ddr->bo_stats_total_allocated += (s64)size; + + if (ddr->bo_stats_peak_allocated < (size_t)size) + ddr->bo_stats_peak_allocated = (size_t)size; } mutex_unlock(&known_drmcgrp_devs[devIdx]->mutex); }