From patchwork Thu Nov 18 20:28:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 12627631 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C6B5C433FE for ; Thu, 18 Nov 2021 20:29:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 744C96113D for ; Thu, 18 Nov 2021 20:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232262AbhKRUbz (ORCPT ); Thu, 18 Nov 2021 15:31:55 -0500 Received: from mail-dm6nam12on2046.outbound.protection.outlook.com ([40.107.243.46]:2785 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231377AbhKRUby (ORCPT ); Thu, 18 Nov 2021 15:31:54 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZDPr/t08HLkE2+OZS7T4GI90llVYSftOdqUlL3i+NXMGyXvlfaiWjWyMAKqG7pSkk7TAZPDQXzx6UGnZjsQTiuPq5ghJsUFDsn3bgS7eLSKSwr33zKPMoHimnI2y323t7npZVkyemvYkgzUyl7zSse79JzVqHcC3g8JgarVKtIkHHOnliNszMZCGuIDmWLVrTgu4VOXZLrjZXoP3qOcRwUNzDDTRhPcY2iSZ/ZDZj26QO8XykEGzD+Zy6X/wnYQL2gwgAQNRxpLU5M7xx3PjtIrgmrgHP6sbi+75ZS1rxAz66Se5M5dnjiZ5x13EJFqzh0v+77atHaCNYAhY6abu4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T73Z7+mHYZvKeeLZYHXHafx8/Qc7zeDlNYSdd4qtgbo=; b=Yl2q7gAq3wbUdSIUdZZBhLOq478GvdEZyJfp0zx1eFlnq1koS+Txvlg4fyKnRb06mbSBAyhsTTzyHBXjocyCxU/1jGF4wGAzrRK6FfJa7LqO08xQKRTD2idTUPZtiexfoGIyD4mCIX4HPDMiWXts9yrhvze1m1qwWaWkGQYz340ODl+cnJCCDocpsRfCxHyHkEErLd4mhu9Xvc9HiB9auFTRKeRneeNNDJX9va10YRp504j8myjSVI2cdyDi6ggw8SSDJ9RJm8pdeKGLfTf/RilqzcGRMHikY+oZTfgQiC5mgFj8V8fHvJyKw5PPG3rpC+/bBnRSSLP66+nGpAvBZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T73Z7+mHYZvKeeLZYHXHafx8/Qc7zeDlNYSdd4qtgbo=; b=wxcAhmkVD9KITXfdrfqNJoaxKdmvkDxIo3OS3l8HuvtFtZAjzGw/9TSEqfMARb6VnPlttvf6EWlkaXu4UHwHgKvnKfewCsdoy65QdKce6TZUCdFLB8g9favxHatOhIdawqe+agtj/JlXRyjfrDIi6aX6ipVSYaLdksWBKbgERd0= Received: from MW4PR03CA0232.namprd03.prod.outlook.com (2603:10b6:303:b9::27) by MWHPR12MB1838.namprd12.prod.outlook.com (2603:10b6:300:106::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Thu, 18 Nov 2021 20:28:51 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::8d) by MW4PR03CA0232.outlook.office365.com (2603:10b6:303:b9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 20:28:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.20 via Frontend Transport; Thu, 18 Nov 2021 20:28:51 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 14:28:50 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 14:28:50 -0600 Received: from yuho-dev.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 18 Nov 2021 14:28:47 -0600 From: Kenny Ho To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Tejun Heo , Zefan Li , "Johannes Weiner" , Peter Zijlstra , "Ingo Molnar" , Arnaldo Carvalho de Melo , "Mark Rutland" , Alexander Shishkin , Jiri Olsa , "Namhyung Kim" , Steven Rostedt , , , , , , , , Subject: [PATCH RFC 1/4] cgroup, perf: Add ability to connect to perf cgroup from other cgroup controller Date: Thu, 18 Nov 2021 15:28:37 -0500 Message-ID: <20211118202840.1001787-2-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118202840.1001787-1-Kenny.Ho@amd.com> References: <20211118202840.1001787-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb775d17-7613-4d35-a35a-08d9aad208b6 X-MS-TrafficTypeDiagnostic: MWHPR12MB1838: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JK+oj26aoQC1ub443bHMQHXqzxAoSF2xwS4bFsJwuMTS7mnVFAaxEfGKX6UEyLnaSow3sK8/9cF25HEoQ8GgD1oxo5gBRcRXRABIGSJ8Yp2w5xqwMie4VNAq+/6OyDalEIlNvAO3AG60fknLGy7PFdHJnhSUZL1dZ4IwXDxiXI6T3XrYYkNWq+d55jDBDMyuGiBStfR2iKr4WiYnn8m9YLc9S/0FGebW016lgh45+QagXQz0x25wJU1b3x9spqJY9XtsmdbcT5iEbLzgeGD6MXE3MoH9+JJ2/9cXeqQh3+0tHEsdCY0z9kTEJ6i0KL4jZYWbHRZoSXses3yezEibROzZT8qj4ebO2/QZFkWLA5PFmZe27l4sJWT7z6bRKz23bHpV/YowdI4Q6PQQ5wEwqqdKHlMP+sSma86JuOe6dd6/INKYTWZRbwCBpYF9w/CLIyLV0tMVsZ5X7XIJwfJ0iLTe+YG89/rw6p+yCxnaB+TV0rVbwhExL3SsSuXxhP82Gk/Hb/iTaWMndKohuSyidbytYW+8JGHh0A7xUvjVZ9/FAungfvLH8iLvcKSUZWDUZ2cEiFEh86xyPrTt/Ssfld7QnI11of6TTIVxuI9JSdBoJilkaRc9FNZjUsKYWKwbTKaPrZe8ucyZHPEliLSUtjhRnhbgoWu023mkuTQMeG65HBh936jMYYPEDkKuCYQD54RpzrebBBVOgGe/xdK+XdkWwUvz49DvbgrNyDyuRBGbVSQRGIeBsebtjiENDsMO X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(82310400003)(336012)(186003)(47076005)(426003)(5660300002)(508600001)(70586007)(2616005)(70206006)(83380400001)(36756003)(8936002)(8676002)(7416002)(356005)(316002)(36860700001)(110136005)(81166007)(921005)(7696005)(1076003)(86362001)(26005)(2906002)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 20:28:51.4117 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb775d17-7613-4d35-a35a-08d9aad208b6 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1838 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This provides the ability to allocate cgroup specific perf_event by bpf-cgroup in later patch Change-Id: I13aa7f3dfc2883ba3663c0b94744a6169504bbd8 Signed-off-by: Kenny Ho --- include/linux/cgroup.h | 2 ++ include/linux/perf_event.h | 2 ++ kernel/cgroup/cgroup.c | 4 ++-- kernel/events/core.c | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 75c151413fda..1754e33cfe5e 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -97,6 +97,8 @@ extern struct css_set init_css_set; bool css_has_online_children(struct cgroup_subsys_state *css); struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss); +struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgroup, + struct cgroup_subsys *ss); struct cgroup_subsys_state *cgroup_e_css(struct cgroup *cgroup, struct cgroup_subsys *ss); struct cgroup_subsys_state *cgroup_get_e_css(struct cgroup *cgroup, diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 0cbc5dfe1110..9c440db65c18 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -926,6 +926,8 @@ struct perf_cgroup { struct perf_cgroup_info __percpu *info; }; +extern struct perf_cgroup *cgroup_tryget_perf_cgroup(struct cgroup *cgrp); + /* * Must ensure cgroup is pinned (css_get) before calling * this function. In other words, we cannot call this function diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 570b0c97392a..a645b212b69b 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -495,8 +495,8 @@ static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp, * Find and get @cgrp's css associated with @ss. If the css doesn't exist * or is offline, %NULL is returned. */ -static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp, - struct cgroup_subsys *ss) +struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp, + struct cgroup_subsys *ss) { struct cgroup_subsys_state *css; diff --git a/kernel/events/core.c b/kernel/events/core.c index 20367196fa9a..d34e00749c9b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -941,6 +941,18 @@ static int perf_cgroup_ensure_storage(struct perf_event *event, return ret; } +struct perf_cgroup *cgroup_tryget_perf_cgroup(struct cgroup *cgrp) +{ + struct cgroup_subsys_state *css; + + css = cgroup_tryget_css(cgrp, &perf_event_cgrp_subsys); + + if (!css) + return NULL; + + return container_of(css, struct perf_cgroup, css); +} + static inline int perf_cgroup_connect(int fd, struct perf_event *event, struct perf_event_attr *attr, struct perf_event *group_leader) @@ -1080,6 +1092,11 @@ static inline void perf_cgroup_sched_in(struct task_struct *prev, { } +struct perf_cgroup *cgroup_tryget_perf_cgroup(struct cgroup *cgrp) +{ + return NULL; +} + static inline int perf_cgroup_connect(pid_t pid, struct perf_event *event, struct perf_event_attr *attr, struct perf_event *group_leader) From patchwork Thu Nov 18 20:28:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 12627637 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A15BC433EF for ; Thu, 18 Nov 2021 20:29:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 454FC6113D for ; Thu, 18 Nov 2021 20:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234108AbhKRUcG (ORCPT ); Thu, 18 Nov 2021 15:32:06 -0500 Received: from mail-bn7nam10on2087.outbound.protection.outlook.com ([40.107.92.87]:45825 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233918AbhKRUb7 (ORCPT ); Thu, 18 Nov 2021 15:31:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kA/iyLG/p0Z8wvtYA+kuFOpL2+XzUsmbM9Nldw57kHLOnW/cglV8hSe2wWokiT+H1d07KCfS/enbYBnZTbZ1OF3iZtjDjINGn/j63EzvXIlIsyhCDDy3yfjQfxfTag6upj/txhR0hJVDw/0Qb7Zs+7Cg/YI+eafiwnG4KFg8vyR7PjXkbcjzF/J7yxY9Nb2wTJlFAOSE1xlOxmL8TXtOB7Ka+6wvG3AHOZHKbxdDh9qYMDEl6UFEqHl10AHoAZjEOSAzY/5kJ2k9hjYqMPmBE5fWk8vU2oPxo8BpCbb6gtcrwQVC9CDwbKk16VRM0odMbcZFxi9kZMolakL6As1kag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9LTCxDJv3hxoUKuAs/bDMtp2aWzOrmYrLj1GHD61d7s=; b=BaNMWAK86OrCRHumfAzuCfkeAhxmeub4/zVYIcuHNJX79n9XPsM//Raxm11e25EZhSB5vU8ifAHN/0BYAEdmA+zM9KTUSJhGi1EcWS6Uq3bcpf4t61Aux4esoAUXGlq+Gg+q5bZ598UR6nn7v/iVUJqWmSH2xmflHUyNyVVVwqW39s3bwKSeQj4TwNVDz/2lfsNs+BBEeX4t8pvXu+HSbSvFm9NmKReE7kx7uNiIIwz6RXo4NrvoQ0IvFCoBwLnQXgMIPHldszQB2dx5ZWWNb0coMofa7GaI0NlNGYDScsEsCh6S4dwNiYKXgBEJUIsN1EaWDMCOzy/die19zqKdFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9LTCxDJv3hxoUKuAs/bDMtp2aWzOrmYrLj1GHD61d7s=; b=ApN7FpnWJgqBMOzvj8slk3X08GPp57/v2+cNanaKEgPqjegxvtz3347IPTRrSvrek4f4tL/M5DmZnjC/TFa9HHUAooH40Fo78JPeZERa+z77stRYrNwE26g2gnjX+RQsXBtkab95HUWPTk5ZtbuIsM0SOhOO1NFA5WwS0O+CytY= Received: from CO1PR15CA0100.namprd15.prod.outlook.com (2603:10b6:101:21::20) by DM5PR12MB1884.namprd12.prod.outlook.com (2603:10b6:3:10d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.19; Thu, 18 Nov 2021 20:28:54 +0000 Received: from CO1NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:101:21:cafe::69) by CO1PR15CA0100.outlook.office365.com (2603:10b6:101:21::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 20:28:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT006.mail.protection.outlook.com (10.13.174.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.20 via Frontend Transport; Thu, 18 Nov 2021 20:28:53 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 14:28:52 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 12:28:52 -0800 Received: from yuho-dev.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 18 Nov 2021 14:28:50 -0600 From: Kenny Ho To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Tejun Heo , Zefan Li , "Johannes Weiner" , Peter Zijlstra , "Ingo Molnar" , Arnaldo Carvalho de Melo , "Mark Rutland" , Alexander Shishkin , Jiri Olsa , "Namhyung Kim" , Steven Rostedt , , , , , , , , Subject: [PATCH RFC 2/4] bpf, perf: add ability to attach complete array of bpf prog to perf event Date: Thu, 18 Nov 2021 15:28:38 -0500 Message-ID: <20211118202840.1001787-3-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118202840.1001787-1-Kenny.Ho@amd.com> References: <20211118202840.1001787-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: be50af72-0c38-4f0f-df92-08d9aad20a22 X-MS-TrafficTypeDiagnostic: DM5PR12MB1884: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:949; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1WZwLl9IAM2ZRnfg9gPck5Of6ZECwY/ibq3TKbVkdNuKLAX9SZXMR/k2vitWydD5ylQ0712qRpizTCFosrvtLJiEeCc4KdPA4hzHOpKvfGpwsO/LR1bW9VGP+4/aUFfz2UwlLUiWJ0NrPVJHVRYv6AA4UjiV0geERUaENmmxtZ4AuuyhYlIhaD9Hc2LTu7od5rzgg1+2BZEDa/QqC1rICF3ocNb5538sKBq3Z9Uj8AFXK48wHWoRHej0ErZ/SioQcVgowqcJtBiZvwF2qK/LnhmwIe3/Y2HUUk0ddBo5z141uElM/YACQxwwoUPCaHWfS8FgTjI/tOItdKm1BB4PCPxrq5maOdL2ww7VYHVmmZwr0YmVybhQckLsH/fOb2DVz/pOaItajv7OwjK3D/32akzFA3ULou6zXF/1q36SrQi50vqNBizanlSrgZ1L0la88wlGiTrSB1gnmgCKQL+sNNbEA9YovZDexJYR/RRjMahrBxdYaJRasN+MLoZ+vjr56cARr1ZO4RLqk3lLN3kvxSvxlEMnWW68IGZjpdUTp8fOe4PauM/HgzI1DrWdS4Chrcu2bqO9fD9Fsj8o33k7ws0G/HatwZvLlA3k50LlMUhr/NH4PVQRm02t50/RNtPXUMBBhsfUW4BMmOwo3N8XeneT6Z9npr6LKQMpr7u+JueDw6Qwx27CbIrKVRCIibF/pYXHG+pGJ1UShXGJz7OcbihXXj34kq+uZJ88Z+0oMtR4HfX9X+aGS3KokxWrsouO X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(316002)(7416002)(36860700001)(426003)(110136005)(336012)(2906002)(83380400001)(47076005)(508600001)(8936002)(921005)(1076003)(356005)(70586007)(70206006)(7696005)(82310400003)(36756003)(5660300002)(81166007)(186003)(26005)(2616005)(86362001)(6666004)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 20:28:53.8038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be50af72-0c38-4f0f-df92-08d9aad20a22 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1884 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Change-Id: Ie2580c3a71e2a5116551879358cb5304b04d3838 Signed-off-by: Kenny Ho --- include/linux/trace_events.h | 9 +++++++++ kernel/trace/bpf_trace.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 3e475eeb5a99..5cfe3d08966c 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -725,6 +725,8 @@ trace_trigger_soft_disabled(struct trace_event_file *file) #ifdef CONFIG_BPF_EVENTS unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx); +int perf_event_attach_bpf_prog_array(struct perf_event *event, + struct bpf_prog_array *new_array); int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie); void perf_event_detach_bpf_prog(struct perf_event *event); int perf_event_query_prog_array(struct perf_event *event, void __user *info); @@ -741,6 +743,13 @@ static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *c return 1; } +static inline int +int perf_event_attach_bpf_prog_array(struct perf_event *event, + struct bpf_prog_array *new_array) +{ + return -EOPNOTSUPP; +} + static inline int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie) { diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 6b3153841a33..8addd10202c2 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1802,6 +1802,34 @@ static DEFINE_MUTEX(bpf_event_mutex); #define BPF_TRACE_MAX_PROGS 64 +int perf_event_attach_bpf_prog_array(struct perf_event *event, + struct bpf_prog_array *new_array) +{ + struct bpf_prog_array_item *item; + struct bpf_prog_array *old_array; + + if (!new_array) + return -EINVAL; + + if (bpf_prog_array_length(new_array) >= BPF_TRACE_MAX_PROGS) + return -E2BIG; + + if (!trace_kprobe_on_func_entry(event->tp_event) || + !trace_kprobe_error_injectable(event->tp_event)) + for (item = new_array->items; item->prog; item++) + if (item->prog->kprobe_override) + return -EINVAL; + + mutex_lock(&bpf_event_mutex); + + old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); + rcu_assign_pointer(event->tp_event->prog_array, new_array); + bpf_prog_array_free(old_array); + + mutex_unlock(&bpf_event_mutex); + return 0; +} + int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie) From patchwork Thu Nov 18 20:28:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 12627633 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC525C4332F for ; Thu, 18 Nov 2021 20:29:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4FB0611BF for ; Thu, 18 Nov 2021 20:29:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234061AbhKRUcE (ORCPT ); Thu, 18 Nov 2021 15:32:04 -0500 Received: from mail-mw2nam12on2041.outbound.protection.outlook.com ([40.107.244.41]:13192 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233895AbhKRUb6 (ORCPT ); Thu, 18 Nov 2021 15:31:58 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q0hMj4rk06u/kij7N+os4PjyJFKO0l2DDhi5mbOxJUbuJxj+zg+HDAJw3g0j8O2agYudK9qNnxPBleAO57OJgIisjLf/MNKDCtcyV3CHWAHJpJV9VfCbyhIeV9ZerCeS/mIGLEw3q4Vm17nicVpfNo+c6nUR0jZjH+UUzrAAj1MDLnzaBhwHFFq+KbKqjTV/FbnLbr12ccy98fCTg7QGdkfMdRQzFLAwcuzLN0s6OIrirTbgVGwthw0Q94C5L5+lUJDhqCLJnQNsKFVoqSi9rUn86CkHi8LKBoEXXPSHzeDGBXp6o4uzltBYpET4vH7MAG12h32SM0aLYpiS8q02Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zNMAi1WdxhVnAKx+riu3QqHHlJ+TKfyDHX8K1xNetEE=; b=fQy7+xyB7cSLNE4tB2FR9ky0LQRTiYLsdg0B4D4Vgvmnl9Lru5Uoq7Sz4IErmBZ8swEfzBmP/WZqwkZ/JMc4u9+M4a+H/s5C14ng+z698AUMr/yPRkUjs5u36h4Q9DxFw7Kkc/fQRvN/awINscJ8OjNsNdOb6yGrZVcu+d/6lPmZwI4pt0bEbvTrf80r+Fh4ilhd1StXC0BlyQnXmyPjtJPi0u9mdm4eKih9vj7jduwN6Rh1GIxmpdh1vKrFnoyQXxbNJq+7TfPR1rshHbKlOY4482mdmW0h+PCAAEPJIwjpEmWho/YVxZSAbx9yscgEI6LiGDGj5W4IhzyJLf24ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zNMAi1WdxhVnAKx+riu3QqHHlJ+TKfyDHX8K1xNetEE=; b=5TqTqCfvd+8BmSaBqAPtukxZWjL5/LDuG2DsrNn11en8iKpMDJY2dgGjheSYYcQ5mgPbIkzeyUDWnglQQNw0doP33el4b8S8+KtixeXTdAJgalyL3mpPGedVvJwCEfMeMBWhB7XYu3BHoWRMeE5gX/vvgTNnggdRXoRH2BQ4hVU= Received: from BN9PR03CA0249.namprd03.prod.outlook.com (2603:10b6:408:ff::14) by DM4PR12MB5165.namprd12.prod.outlook.com (2603:10b6:5:394::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.26; Thu, 18 Nov 2021 20:28:55 +0000 Received: from BN8NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::9b) by BN9PR03CA0249.outlook.office365.com (2603:10b6:408:ff::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 20:28:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT059.mail.protection.outlook.com (10.13.177.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.20 via Frontend Transport; Thu, 18 Nov 2021 20:28:54 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 14:28:54 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 12:28:54 -0800 Received: from yuho-dev.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 18 Nov 2021 14:28:52 -0600 From: Kenny Ho To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Tejun Heo , Zefan Li , "Johannes Weiner" , Peter Zijlstra , "Ingo Molnar" , Arnaldo Carvalho de Melo , "Mark Rutland" , Alexander Shishkin , Jiri Olsa , "Namhyung Kim" , Steven Rostedt , , , , , , , , Subject: [PATCH RFC 3/4] bpf,cgroup,tracing: add new BPF_PROG_TYPE_CGROUP_TRACEPOINT Date: Thu, 18 Nov 2021 15:28:39 -0500 Message-ID: <20211118202840.1001787-4-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118202840.1001787-1-Kenny.Ho@amd.com> References: <20211118202840.1001787-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 395f279e-781e-4e25-18a4-08d9aad20aaf X-MS-TrafficTypeDiagnostic: DM4PR12MB5165: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:792; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xmy7P12GEdvXiwAcGgcttINUgXRCHwWPK9L3Cx2TE21hc9kQ1bjueMkH/4X7Ow+qOb9m4S4iJAhLVh+ro52meoV4Tov90msY0Pm0JgcorIwu2svw1jQQKdWwq4jOiPzdz/tUuq5JzOg40rPRWbIT9QJrj3fUzqy8D41N4scFWDzB/kPa02PYMTFjiqcY7aaa2xOqAgahuivaUAYN3X/cPy7VNAH6s2Qq9pyXib7sTdJ8u0JIerE4Nv90Qt6GJqUs8v7ywclNPsot0ki6YTgxzPsJi5xyiWL4SrafZbGtFMSXVLuVSjCwWOnkjq0Wx4EqATnhlIRKPkgPN0107xEfPimPKznk8uy92Vef64sNAts1Mnj2FWaKaPZdKRSzltjH+U27bdSPjfI7wRe1kPqlSTLmdWSsjHMpEsEyimuMUSM7LZVWSVr8xLTIcfiL0+7tl97eX/6J0lD+kho8gBl9bjeew9wPRM6Fbd1x7JbGGucWUa91wuLZjArkY2YMkkV4d105JQHR4cEos8EKFEOzQVHacDlA79tmCijMZvUf9/rZ3wARz+56MTZPDEpbB0GwI7UC1XjwpBaitxFJK6ZVIjPgewVJuNUkNuOR8X/2JfM8eTrMy3McuHru3hD4idcthXuBpgsmLO6TMt31muNgdqYN/8PnAtYCC1OKSHgO1Uhm0dhMh/9Ul1fgOlDLbjT9j6HGsud5WVFGkJWXVSuacZu82bJKVIgavJ7afUFeUqJJxqNwgtzfq7UtWSYiv63S X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(81166007)(921005)(316002)(6666004)(110136005)(186003)(2906002)(36756003)(26005)(2616005)(36860700001)(336012)(7416002)(82310400003)(83380400001)(5660300002)(356005)(86362001)(8676002)(1076003)(7696005)(426003)(47076005)(70206006)(508600001)(70586007)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 20:28:54.8297 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 395f279e-781e-4e25-18a4-08d9aad20aaf 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5165 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Change-Id: Ic9727186bb8c76c757e48635143b16e607f2299f Signed-off-by: Kenny Ho --- include/linux/bpf-cgroup.h | 2 ++ include/linux/bpf_types.h | 4 ++++ include/uapi/linux/bpf.h | 2 ++ kernel/bpf/syscall.c | 4 ++++ kernel/trace/bpf_trace.c | 8 ++++++++ 5 files changed, 20 insertions(+) diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 2746fd804216..a5e4d9b19470 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -48,6 +48,7 @@ enum cgroup_bpf_attach_type { CGROUP_INET4_GETSOCKNAME, CGROUP_INET6_GETSOCKNAME, CGROUP_INET_SOCK_RELEASE, + CGROUP_TRACEPOINT, MAX_CGROUP_BPF_ATTACH_TYPE }; @@ -81,6 +82,7 @@ to_cgroup_bpf_attach_type(enum bpf_attach_type attach_type) CGROUP_ATYPE(CGROUP_INET4_GETSOCKNAME); CGROUP_ATYPE(CGROUP_INET6_GETSOCKNAME); CGROUP_ATYPE(CGROUP_INET_SOCK_RELEASE); + CGROUP_ATYPE(CGROUP_TRACEPOINT); default: return CGROUP_BPF_ATTACH_TYPE_INVALID; } diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h index 9c81724e4b98..c108f498a35e 100644 --- a/include/linux/bpf_types.h +++ b/include/linux/bpf_types.h @@ -57,6 +57,10 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SYSCTL, cg_sysctl, BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCKOPT, cg_sockopt, struct bpf_sockopt, struct bpf_sockopt_kern) #endif +#if defined (CONFIG_BPF_EVENTS) && defined (CONFIG_CGROUP_BPF) +BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_TRACEPOINT, cg_tracepoint, + __u64, u64) +#endif #ifdef CONFIG_BPF_LIRC_MODE2 BPF_PROG_TYPE(BPF_PROG_TYPE_LIRC_MODE2, lirc_mode2, __u32, u32) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 6fc59d61937a..014ffaa3fc2a 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -949,6 +949,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_LSM, BPF_PROG_TYPE_SK_LOOKUP, BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */ + BPF_PROG_TYPE_CGROUP_TRACEPOINT, }; enum bpf_attach_type { @@ -994,6 +995,7 @@ enum bpf_attach_type { BPF_SK_REUSEPORT_SELECT, BPF_SK_REUSEPORT_SELECT_OR_MIGRATE, BPF_PERF_EVENT, + BPF_CGROUP_TRACEPOINT, __MAX_BPF_ATTACH_TYPE }; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4e50c0bfdb7d..d77598fa4eb2 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2149,6 +2149,7 @@ static bool is_perfmon_prog_type(enum bpf_prog_type prog_type) case BPF_PROG_TYPE_LSM: case BPF_PROG_TYPE_STRUCT_OPS: /* has access to struct sock */ case BPF_PROG_TYPE_EXT: /* extends any prog */ + case BPF_PROG_TYPE_CGROUP_TRACEPOINT: return true; default: return false; @@ -3137,6 +3138,8 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type) return BPF_PROG_TYPE_SK_LOOKUP; case BPF_XDP: return BPF_PROG_TYPE_XDP; + case BPF_CGROUP_TRACEPOINT: + return BPF_PROG_TYPE_CGROUP_TRACEPOINT; default: return BPF_PROG_TYPE_UNSPEC; } @@ -3189,6 +3192,7 @@ static int bpf_prog_attach(const union bpf_attr *attr) case BPF_PROG_TYPE_CGROUP_SOCK_ADDR: case BPF_PROG_TYPE_CGROUP_SOCKOPT: case BPF_PROG_TYPE_CGROUP_SYSCTL: + case BPF_PROG_TYPE_CGROUP_TRACEPOINT: case BPF_PROG_TYPE_SOCK_OPS: ret = cgroup_bpf_prog_attach(attr, ptype, prog); break; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 8addd10202c2..4ad864a4852a 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1798,6 +1798,14 @@ const struct bpf_verifier_ops perf_event_verifier_ops = { const struct bpf_prog_ops perf_event_prog_ops = { }; +const struct bpf_verifier_ops cg_tracepoint_verifier_ops = { + .get_func_proto = tp_prog_func_proto, + .is_valid_access = tp_prog_is_valid_access, +}; + +const struct bpf_prog_ops cg_tracepoint_prog_ops = { +}; + static DEFINE_MUTEX(bpf_event_mutex); #define BPF_TRACE_MAX_PROGS 64 From patchwork Thu Nov 18 20:28:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho, Kenny" X-Patchwork-Id: 12627635 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 206E2C433FE for ; Thu, 18 Nov 2021 20:29:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 054286113D for ; Thu, 18 Nov 2021 20:29:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233992AbhKRUcH (ORCPT ); Thu, 18 Nov 2021 15:32:07 -0500 Received: from mail-mw2nam12on2055.outbound.protection.outlook.com ([40.107.244.55]:8577 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233954AbhKRUcA (ORCPT ); Thu, 18 Nov 2021 15:32:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kKw7arrQDSXkNb9FrD0yev+FIbggyh+5MXM3ke/FlnbhfVk/CO5kVCXVVe/gU9MNJ6msmH6RgLOOpC39je7kIUkFQLw9ARt0+MriigJUt0GORh6Vqz5gdmj81n4OfLUaHndIDsHCtjZ+F//jqwlvgpbilCjen+kcMFTQs5ga0vpwZjxmzFUp5bx+A6Lo+bN3QNHL2t7I0W1INpHg8QwOgbYqfIR15N6qjgsQlTv1N31Ug40VjlqcR1Mv4vWmruDcuY/fso4cs6Rw5qFuD/+FWbHUwXErt7kvTldUKJI+k/Ok2lCwZwHE2+tsG3APPgkd4IL80DOsxSlvT72M+LCQag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NHKhQbOAr7Mm7h+PoDJFTwWLZ8WOF7rmrZsjJYFpFsc=; b=YY+PRWsWCgU2XmCbwkAXclxnp/srqGkoO62V6tAOvvw2SOn6CAa5IWnhwcvd0fGf84fyfEgIrOAlhQniPO4hNnZdJWOSa1QqPWQlroYeyFCSYOkRbRx1dr4GncxvjMZFqC2XVnAwu3Lmw1e1hRhVOJuD/7h4d0GhAMQORGJTWtUhoIcjXrd2I4IE1AQcZGCY71H4jJlhtbZQrgCY5gA9ebnV9pVgLutqo5qGytHypyFCfEsX+oNvn1878lfc4wlml8KgvNDSIQ1AnzFfFNvOY+KzfzuNSBSG6YyJqsFVIxypeRCrx/Y1XMz3sp+LmKtjB23x4Pg6SMMnHgewslxheQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NHKhQbOAr7Mm7h+PoDJFTwWLZ8WOF7rmrZsjJYFpFsc=; b=rPxETzrKb9U4nxyEatf1AHRYpnXTHjHKNcBdovdowIUL96wxaNdUcVPvVBxqtYyfIMFGFt/Y5Qrdw4gAnBatwntYFsU+0r1MIHZTbjbx/T8TSQ+VjM+MMQP752e8h9igtt4pILIy1+hBrAGnWzYvF/O32jV5UOrTxyXckpXd1Ws= Received: from BN9PR03CA0446.namprd03.prod.outlook.com (2603:10b6:408:113::31) by MN2PR12MB4125.namprd12.prod.outlook.com (2603:10b6:208:1d9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21; Thu, 18 Nov 2021 20:28:57 +0000 Received: from BN8NAM11FT061.eop-nam11.prod.protection.outlook.com (2603:10b6:408:113:cafe::65) by BN9PR03CA0446.outlook.office365.com (2603:10b6:408:113::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21 via Frontend Transport; Thu, 18 Nov 2021 20:28:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT061.mail.protection.outlook.com (10.13.177.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.20 via Frontend Transport; Thu, 18 Nov 2021 20:28:56 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 14:28:56 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 18 Nov 2021 14:28:55 -0600 Received: from yuho-dev.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 18 Nov 2021 14:28:54 -0600 From: Kenny Ho To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Tejun Heo , Zefan Li , "Johannes Weiner" , Peter Zijlstra , "Ingo Molnar" , Arnaldo Carvalho de Melo , "Mark Rutland" , Alexander Shishkin , Jiri Olsa , "Namhyung Kim" , Steven Rostedt , , , , , , , , Subject: [PATCH RFC 4/4] bpf,cgroup,perf: extend bpf-cgroup to support tracepoint attachment Date: Thu, 18 Nov 2021 15:28:40 -0500 Message-ID: <20211118202840.1001787-5-Kenny.Ho@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118202840.1001787-1-Kenny.Ho@amd.com> References: <20211118202840.1001787-1-Kenny.Ho@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6322ec77-87ca-4ded-f98a-08d9aad20be5 X-MS-TrafficTypeDiagnostic: MN2PR12MB4125: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1227; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6ckTjSvKwirqerWSm1wep54SJO7m5glFpWd/uMxNQjGRbZ6nlquZ/frxFP49UpGfRIAv7rDkoxmmKPqnxqJmE4nfu8IPh3q62/G3Er9N+gyNV8cnPfJxkwkMucMK4a5KbY544gEaLxQzLXUPatcaQfG8g9D/r6S/MYGPKSXFdI1M9Ub0TeoLmKj2nlNjLzvEO7EEVyTvHrP7rpo1NMHsQYWlI+GZ78p129KDhK18B791fWMbF1Ce7uLeOKsJIwFTEsNuCGVzXFpe3+Eq5iQoUU08k7YfWp48vlW9voDNGdEOOJneAGbBoqqiS6mjJYBLxQt10tY7SWnIufDQE2FRiXNJdgj1Mjj8q0Q1remwcKlmfyzh8CYMym833QY/0nAtiT7zuhmHUGN9hAdkQtvhfmwUE/LlGza7yhS4BAdCS24LNq/mYqY9FuwzWM3qPM6p5HeFiBnkHwmMicSzSWgh3XSXRwNNZ0+esbcpT0kajc6Q9yaMil1VLZ5nRmG/EZsIR5Y6BuTaaTzp1EwBhXSkzg0VslWC9YGSTqOE7i/7GUQ3r8lJBhTIt4nyQytddonPEjMRVsEcCkJwFQeyVqRnVu3KxME3Ga/kuDg3E5eSUK6DsymtC3/lvArzVu/J95B6QkdWNcXWT/qSPAKc8KwSlK+f5Zj6c2Rj6j5puSSUdEs2UgrCWiRLYKiXH75MMhad7nOwoaSLYENUv26QL/UUXXZPzYpoPHQdEsbuiJzt2vfr7irhJLfegsBqfVu9jw/A X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(921005)(186003)(36860700001)(2906002)(36756003)(7416002)(1076003)(508600001)(26005)(8936002)(8676002)(356005)(81166007)(83380400001)(86362001)(7696005)(47076005)(316002)(30864003)(336012)(2616005)(70586007)(426003)(82310400003)(70206006)(5660300002)(110136005)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 20:28:56.8691 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6322ec77-87ca-4ded-f98a-08d9aad20be5 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT061.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4125 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC bpf progs are attached to cgroups as usual with the idea of effective progs remain the same. The perf event / tracepoint's fd is defined as attachment 'subtype'. The 'subtype' is passed along during attachment via bpf_attr, reusing replace_bpf_fd field. After the effective progs are calculated, perf_event is allocated using the 'subtype'/'fd' value for all cpus filtering on the perf cgroup that corresponds to the bpf-cgroup (with assumption of a unified hierarchy.) The effective bpf prog array is then attached to each newly allocated perf_event and subsequently enabled by activate_effective_progs. Change-Id: I07a4dcaa0a682bafa496f05411365100d6c84fff Signed-off-by: Kenny Ho --- include/linux/bpf-cgroup.h | 15 ++++-- include/linux/perf_event.h | 4 ++ kernel/bpf/cgroup.c | 96 +++++++++++++++++++++++++++++++------- kernel/cgroup/cgroup.c | 9 ++-- kernel/events/core.c | 45 ++++++++++++++++++ 5 files changed, 142 insertions(+), 27 deletions(-) diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index a5e4d9b19470..b6e22fd2aa6e 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -154,6 +154,11 @@ struct cgroup_bpf { /* cgroup_bpf is released using a work queue */ struct work_struct release_work; + + /* list of perf events (per child cgroups) for tracepoint/kprobe/uprobe bpf attachment to cgroup */ + /* TODO: array of tp type with array of events for each cgroup + * currently only one tp type supported at a time */ + struct list_head per_cg_events; }; int cgroup_bpf_inherit(struct cgroup *cgrp); @@ -161,21 +166,21 @@ void cgroup_bpf_offline(struct cgroup *cgrp); int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, struct bpf_prog *replace_prog, - struct bpf_cgroup_link *link, + struct bpf_cgroup_link *link, int bpf_attach_subtype, enum bpf_attach_type type, u32 flags); int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, struct bpf_cgroup_link *link, - enum bpf_attach_type type); + enum bpf_attach_type type, int bpf_attach_subtype); int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, union bpf_attr __user *uattr); /* Wrapper for __cgroup_bpf_*() protected by cgroup_mutex */ int cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, struct bpf_prog *replace_prog, - struct bpf_cgroup_link *link, enum bpf_attach_type type, - u32 flags); + struct bpf_cgroup_link *link, int bpf_attach_subtype, + enum bpf_attach_type type, u32 flags); int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, - enum bpf_attach_type type); + enum bpf_attach_type type, int bpf_attach_subtype); int cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, union bpf_attr __user *uattr); diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 9c440db65c18..5a149d8865a1 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -776,6 +776,7 @@ struct perf_event { #ifdef CONFIG_CGROUP_PERF struct perf_cgroup *cgrp; /* cgroup event is attach to */ + struct list_head bpf_cg_list; #endif #ifdef CONFIG_SECURITY @@ -982,6 +983,9 @@ extern void perf_pmu_resched(struct pmu *pmu); extern int perf_event_refresh(struct perf_event *event, int refresh); extern void perf_event_update_userpage(struct perf_event *event); extern int perf_event_release_kernel(struct perf_event *event); +extern int perf_event_create_for_all_cpus(struct perf_event_attr *attr, + struct cgroup *cgroup, + struct list_head *entries); extern struct perf_event * perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 03145d45e3d5..0ecf465ddfb2 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include @@ -112,6 +114,8 @@ static void cgroup_bpf_release(struct work_struct *work) struct bpf_prog_array *old_array; struct list_head *storages = &cgrp->bpf.storages; struct bpf_cgroup_storage *storage, *stmp; + struct list_head *events = &cgrp->bpf.per_cg_events; + struct perf_event *event, *etmp; unsigned int atype; @@ -141,6 +145,10 @@ static void cgroup_bpf_release(struct work_struct *work) bpf_cgroup_storage_free(storage); } + list_for_each_entry_safe(event, etmp, events, bpf_cg_list) { + perf_event_release_kernel(event); + } + mutex_unlock(&cgroup_mutex); for (p = cgroup_parent(cgrp); p; p = cgroup_parent(p)) @@ -226,13 +234,16 @@ static bool hierarchy_allows_attach(struct cgroup *cgrp, */ static int compute_effective_progs(struct cgroup *cgrp, enum cgroup_bpf_attach_type atype, + int bpf_attach_subtype, struct bpf_prog_array **array) { struct bpf_prog_array_item *item; struct bpf_prog_array *progs; struct bpf_prog_list *pl; struct cgroup *p = cgrp; - int cnt = 0; + struct perf_event *event, *etmp; + struct perf_event_attr attr = {}; + int rc, cnt = 0; /* count number of effective programs by walking parents */ do { @@ -245,6 +256,21 @@ static int compute_effective_progs(struct cgroup *cgrp, if (!progs) return -ENOMEM; + if (atype == CGROUP_TRACEPOINT) { + /* TODO: only create event for cgroup that can have process */ + + attr.config = bpf_attach_subtype; + attr.type = PERF_TYPE_TRACEPOINT; + attr.sample_type = PERF_SAMPLE_RAW; + attr.sample_period = 1; + attr.wakeup_events = 1; + + rc = perf_event_create_for_all_cpus(&attr, cgrp, + &cgrp->bpf.per_cg_events); + if (rc) + goto err; + } + /* populate the array with effective progs */ cnt = 0; p = cgrp; @@ -264,20 +290,41 @@ static int compute_effective_progs(struct cgroup *cgrp, } } while ((p = cgroup_parent(p))); + if (atype == CGROUP_TRACEPOINT) { + list_for_each_entry_safe(event, etmp, &cgrp->bpf.per_cg_events, bpf_cg_list) { + rc = perf_event_attach_bpf_prog_array(event, progs); + if (rc) + goto err_attach; + } + } + *array = progs; return 0; +err_attach: + list_for_each_entry_safe(event, etmp, &cgrp->bpf.per_cg_events, bpf_cg_list) + perf_event_release_kernel(event); +err: + bpf_prog_array_free(progs); + return rc; } static void activate_effective_progs(struct cgroup *cgrp, enum cgroup_bpf_attach_type atype, struct bpf_prog_array *old_array) { - old_array = rcu_replace_pointer(cgrp->bpf.effective[atype], old_array, - lockdep_is_held(&cgroup_mutex)); - /* free prog array after grace period, since __cgroup_bpf_run_*() - * might be still walking the array - */ - bpf_prog_array_free(old_array); + struct perf_event *event, *etmp; + + if (atype == CGROUP_TRACEPOINT) + list_for_each_entry_safe(event, etmp, &cgrp->bpf.per_cg_events, bpf_cg_list) + perf_event_enable(event); + else { + old_array = rcu_replace_pointer(cgrp->bpf.effective[atype], old_array, + lockdep_is_held(&cgroup_mutex)); + /* free prog array after grace period, since __cgroup_bpf_run_*() + * might be still walking the array + */ + bpf_prog_array_free(old_array); + } } /** @@ -306,9 +353,10 @@ int cgroup_bpf_inherit(struct cgroup *cgrp) INIT_LIST_HEAD(&cgrp->bpf.progs[i]); INIT_LIST_HEAD(&cgrp->bpf.storages); + INIT_LIST_HEAD(&cgrp->bpf.per_cg_events); for (i = 0; i < NR; i++) - if (compute_effective_progs(cgrp, i, &arrays[i])) + if (compute_effective_progs(cgrp, i, -1, &arrays[i])) goto cleanup; for (i = 0; i < NR; i++) @@ -328,7 +376,8 @@ int cgroup_bpf_inherit(struct cgroup *cgrp) } static int update_effective_progs(struct cgroup *cgrp, - enum cgroup_bpf_attach_type atype) + enum cgroup_bpf_attach_type atype, + int bpf_attach_subtype) { struct cgroup_subsys_state *css; int err; @@ -340,7 +389,8 @@ static int update_effective_progs(struct cgroup *cgrp, if (percpu_ref_is_zero(&desc->bpf.refcnt)) continue; - err = compute_effective_progs(desc, atype, &desc->bpf.inactive); + err = compute_effective_progs(desc, atype, bpf_attach_subtype, + &desc->bpf.inactive); if (err) goto cleanup; } @@ -424,6 +474,7 @@ static struct bpf_prog_list *find_attach_entry(struct list_head *progs, * @prog: A program to attach * @link: A link to attach * @replace_prog: Previously attached program to replace if BPF_F_REPLACE is set + * @bpf_attach_subtype: Type ID of perf tracing event for tracepoint/kprobe/uprobe * @type: Type of attach operation * @flags: Option flags * @@ -432,7 +483,7 @@ static struct bpf_prog_list *find_attach_entry(struct list_head *progs, */ int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, struct bpf_prog *replace_prog, - struct bpf_cgroup_link *link, + struct bpf_cgroup_link *link, int bpf_attach_subtype, enum bpf_attach_type type, u32 flags) { u32 saved_flags = (flags & (BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI)); @@ -454,6 +505,14 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, if (!!replace_prog != !!(flags & BPF_F_REPLACE)) /* replace_prog implies BPF_F_REPLACE, and vice versa */ return -EINVAL; + if ((type == BPF_CGROUP_TRACEPOINT) && + ((flags & BPF_F_REPLACE) || (bpf_attach_subtype < 0) || !(flags & BPF_F_ALLOW_MULTI))) + /* replace fd is used to pass the subtype */ + /* subtype is required for BPF_CGROUP_TRACEPOINT */ + /* not allow multi BPF progs for the attach type for now */ + return -EINVAL; + + /* TODO check bpf_attach_subtype is valid */ atype = to_cgroup_bpf_attach_type(type); if (atype < 0) @@ -499,7 +558,7 @@ int __cgroup_bpf_attach(struct cgroup *cgrp, bpf_cgroup_storages_assign(pl->storage, storage); cgrp->bpf.flags[atype] = saved_flags; - err = update_effective_progs(cgrp, atype); + err = update_effective_progs(cgrp, atype, bpf_attach_subtype); if (err) goto cleanup; @@ -679,7 +738,8 @@ static struct bpf_prog_list *find_detach_entry(struct list_head *progs, * Must be called with cgroup_mutex held. */ int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, - struct bpf_cgroup_link *link, enum bpf_attach_type type) + struct bpf_cgroup_link *link, enum bpf_attach_type type, + int bpf_attach_subtype) { enum cgroup_bpf_attach_type atype; struct bpf_prog *old_prog; @@ -708,7 +768,7 @@ int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, pl->prog = NULL; pl->link = NULL; - err = update_effective_progs(cgrp, atype); + err = update_effective_progs(cgrp, atype, bpf_attach_subtype); if (err) goto cleanup; @@ -809,7 +869,7 @@ int cgroup_bpf_prog_attach(const union bpf_attr *attr, } } - ret = cgroup_bpf_attach(cgrp, prog, replace_prog, NULL, + ret = cgroup_bpf_attach(cgrp, prog, replace_prog, NULL, attr->replace_bpf_fd, attr->attach_type, attr->attach_flags); if (replace_prog) @@ -832,7 +892,7 @@ int cgroup_bpf_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype) if (IS_ERR(prog)) prog = NULL; - ret = cgroup_bpf_detach(cgrp, prog, attr->attach_type); + ret = cgroup_bpf_detach(cgrp, prog, attr->attach_type, attr->replace_bpf_fd); if (prog) bpf_prog_put(prog); @@ -861,7 +921,7 @@ static void bpf_cgroup_link_release(struct bpf_link *link) } WARN_ON(__cgroup_bpf_detach(cg_link->cgroup, NULL, cg_link, - cg_link->type)); + cg_link->type, -1)); cg = cg_link->cgroup; cg_link->cgroup = NULL; @@ -961,7 +1021,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto out_put_cgroup; } - err = cgroup_bpf_attach(cgrp, NULL, NULL, link, + err = cgroup_bpf_attach(cgrp, NULL, NULL, link, -1, link->type, BPF_F_ALLOW_MULTI); if (err) { bpf_link_cleanup(&link_primer); diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index a645b212b69b..17a1269dc2f9 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6626,25 +6626,26 @@ void cgroup_sk_free(struct sock_cgroup_data *skcd) #ifdef CONFIG_CGROUP_BPF int cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog, struct bpf_prog *replace_prog, - struct bpf_cgroup_link *link, + struct bpf_cgroup_link *link, int bpf_attach_subtype, enum bpf_attach_type type, u32 flags) { int ret; mutex_lock(&cgroup_mutex); - ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags); + ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, + bpf_attach_subtype, type, flags); mutex_unlock(&cgroup_mutex); return ret; } int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog, - enum bpf_attach_type type) + enum bpf_attach_type type, int bpf_attach_subtype) { int ret; mutex_lock(&cgroup_mutex); - ret = __cgroup_bpf_detach(cgrp, prog, NULL, type); + ret = __cgroup_bpf_detach(cgrp, prog, NULL, type, bpf_attach_subtype); mutex_unlock(&cgroup_mutex); return ret; } diff --git a/kernel/events/core.c b/kernel/events/core.c index d34e00749c9b..71056af4322b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -12511,6 +12511,51 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, } EXPORT_SYMBOL_GPL(perf_event_create_kernel_counter); +int perf_event_create_for_all_cpus(struct perf_event_attr *attr, + struct cgroup *cgroup, + struct list_head *entries) +{ + struct perf_event **events; + struct perf_cgroup *perf_cgrp; + int cpu, i = 0; + + events = kzalloc(sizeof(struct perf_event *) * num_possible_cpus(), + GFP_KERNEL); + + if (!events) + return -ENOMEM; + + for_each_possible_cpu(cpu) { + /* allocate first, connect the cgroup later */ + events[i] = perf_event_create_kernel_counter(attr, cpu, NULL, NULL, NULL); + + if (IS_ERR(events[i])) + goto err; + + i++; + } + + perf_cgrp = cgroup_tryget_perf_cgroup(cgroup); + if (!perf_cgrp) + goto err; + + for (i--; i >= 0; i--) { + events[i]->cgrp = perf_cgrp; + + list_add(&events[i]->bpf_cg_list, entries); + } + + kfree(events); + return 0; + +err: + for (i--; i >= 0; i--) + free_event(events[i]); + + kfree(events); + return -ENOMEM; +} + void perf_pmu_migrate_context(struct pmu *pmu, int src_cpu, int dst_cpu) { struct perf_event_context *src_ctx;