From patchwork Thu Jan 16 19:41:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942164 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2026.outbound.protection.outlook.com [40.92.58.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66459234CE4; Thu, 16 Jan 2025 19:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.58.26 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056528; cv=fail; b=Kb6x51PaVGBx8AfHp3B95WZmLaFgO8sRxB27vBAJIXKijcHCIamMnbw9SXjCx/8G3kcOCSsbMTmdrlgcy2kUJeqs/ezFX9Im3IkGpeFF5TF95klyg5ev3TvIo31jrCtMgFXuPVfoA11sVPxb0H65y6jCcugecJRkuU8RRsKDDkQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056528; c=relaxed/simple; bh=yTQvdSOtuJcPj4ny6zc1xdoIzByebbD+8jrsXyzGG84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=IV1K5Daqrj5mgaoEOLVl/FGmdoZzdZbqaZuj4F8s/Z+4/YxziM7M+AaYmtbT5b4F7VsI9HSVXxdNR8vaoXkJq/8C0WpZC0ORCree9F0jw9RH8k3FRtnq/RaNAVPokcNSRTNjk9e1LQdjwcWSQtyw8ZRwaNqNG75EdcgMa2gIuQw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=pYXER8RK; arc=fail smtp.client-ip=40.92.58.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="pYXER8RK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PNtzapdGchXMO7O176llssAz+/9YvqGhcaQRW0mMRLvg7KJ6ZwbHZ7yBfFiQrM0Y2cfioL0kx4Y/6ASeO1xXXSzMME/ZIgKY5RkJlzO8Mnhq4K+o8ep+sy8LJ/CcvefG5gZ3oYmDzmHFFL3RV8idO03uLy6IMqALntsw8yidXAq3HsEgcqdf7nqo0Wf3yS37RVwYdK34wJyqz5sMbR1FJJzvTW/DwQ5ExU2lZnZ57CI8qyWQJU+IOTSKgu8Qe5jozy374BX0WsqzdRs9AfoYPDdBurj0ri2oiigdr3n7lJkKCYD08vFGGE0JQB3wC0Uo4AmeEhhyKDdUCw5i9Xnpkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=UGxmuHETQpwNYtW9+AVSXZNH5VfN43vz5MYkRkzXh94=; b=E6qlTrHPwngJml8bXKi9zDvm5y2J/X0OXs2nXDDz2ZTsdhFR+DzoSexHhBhrusgtcwusuENWPoNYlugMtgYj4RxQKOu+loEj3dDRu7x5+d4zUSK+5b9tlUQStugt6RV+MpPyB5oIqt6JNu31RCCC53+yCU85OyEjg7MFDq1xvad2veW86Bo+WqAVHkcLti7NWePgOOjxuymE9szTL6R975adieBosaT6u0Nn6BHYoGd3m+R0RHFmVvHvRz4UMAv4yucM+FGSvZrVtkIARWo8OfaCqEtktuUH+OPbgBDWz1lB46xlQ81wIHdB2xMi9yHNZ/XM4EiWaQa9QSH1xcCoXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UGxmuHETQpwNYtW9+AVSXZNH5VfN43vz5MYkRkzXh94=; b=pYXER8RKqoXU2k61QvYt02yADzEn+mkIEV5uhcKrunvp4eSJtMsW+FVPWmcKDve9yqOhG7SCF+5KbcBgPKwMk8B9khCjr2T9EHHU4ur/VSbFcYaERfWT56RLGWOz5vcJ8AwLvlJucT8HNUL3JsKXi74oJR+M6+Dpp5OmHmsTyWhM3aTUyCTpeG4Yw7DZN3eRcmKxzcXTc3isBFHwN7ILV5/50XmoCaOdrXk+GLTlTITUZtYTjI0+y3YB14BFvfsIs2OBQ5mAIGVdvqbEQJCMkfZZFqaT9rMvd8jQlnnS+KAL1pPHxhTk2scl9YFRr7UDcAqzqnCNzsUbbUAanL+ClA== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:42:03 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:42:03 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 1/7] bpf: Add capability field to BTF_ID_FLAGS Date: Thu, 16 Jan 2025 19:41:06 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-1-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: 611c2115-ae97-4c2e-cdfc-08dd3665d9bb X-MS-Exchange-SLBlob-MailProps: laRBL560oLQowKaVx7aWRf9b2EXVRKJlixpb9KbybYeRvjszgbH2TPiV5QgSJ8uCbY8pah3QCemwVa6GoygoznUMIq/gd1yFtd9Sj4iX7pAuWRb9VWKj74Ajlq4tEOK+Oijmd2dTIyr3OPfEJ58CkN1xv8EDCx7lFZZV6UcLGdht2uGEF7kgi+QrAhjeOBvTpQpPnjq9qLWqozQ6KNW4dbNX0zrmnNOCqMPPM/l1OgGA73bQprIQzuvyAHCo5REE7CstKyBTKXRX35w2zCmzovsqBfSyPoyOdXYyD00FsbB5E3jk1EpAu2NkixOmVp4rkNa9raA0ITQtexMjIJVxe0PU5FeVmDPHMSUlWvrarypDhnxvWSjYF5NxWvrwoXXhDWL4cSj+PmVq3yaEhUhKVj/sSXvefZ6fgO/IfEe9fLM6X321Ii778We8WOVaUlnXdLqRTmAoLa2+StymLHUyXiu4eD4TxhXnHA48CW4G4BeWB4BOXgbTIZ/JGryM3w/vtBgzJ7H1Jww1OybmRG9vBWuTAcy9qMg4FViCohNFDIiBx2i45uf4h7LNU5wl6tcj1dGQlBOsRs92jjMPZZ/bVhGJQ7YhSyG3IN9FT3fi2P7pXqjMisfIkDJcNCKz5JzdqQvFLp935LlzFqB3u3Zq72WK6iZR23bAc93pukHwPOZTFOnKEpJUGcRsPcdHZL3j6+vnEz8u1pg3TfIdRIamec2/sAWr1OVZmyc+nWBjmpSEiXwV7jj8UVZjuUXEKOPNhr5ga62SIdeWnMXUqJ6J6kXaNhL+HWXT X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025; X-Microsoft-Antispam-Message-Info: lEPWNHOocb3c+5KZ67VmJJeuGT9p5xTWFKcnnLa9bH+p4t4UAVbjIBhHleQrQXiPoqU0514HZaskwKivXAswuxegKfKZGpM1PmO03LD3xZ+0Z1W43ENmvXV9CcnZNeq0am4newCHuABOt8i/c/J4S0gztUCPPuZFjeqR8PdjRG+ZXUFMfGNqpgCHGcZhM6RZUtH+Jz5iowH3UQAnNt2pzw+e2CGWMQJeNqxxC6HaGUuWyu8OJRdGdRqBfv+i6m7/u5podraU0/MmdywM/p/mRTqguwY0BLkVpc7Ro2Zt7dbcvpa3Iq1I1FrgsnfdT6POoO/GutHVDoiFmRD7y27MlSaHba6Re85JYM4mYL6jj9ywFnCVcbvPP7YHKXoELqyi/Zk7EX8JxbNsU2QXERCP34hh89JrAqLL7SJSwdms/WYEKicm7LH6fc2rk0OxzPEmFCArPvbjgkgLL0w5DC/vLmxEAG0mSS8jyaMhxb9btIh/Q0UVYKMlJN3hyrSfwLEGjEfwFIhuDFIoQ+SmWKfmLxUCW1jGVk4x8Igc2z1o0GwhF1xoQWYt3oeA0NPvZr7ALhZX8WTBb05p2xcTHnqmqbcWW9Ih+FfWduQfr9BfV1AW9VRJ9nc23qOaQENtl3Fepz2C4cWSvyhPy7BO2ynDNxYjKAgBGJFibw2W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gEqs81ExNIfdMaXJWISttOrMx+o6huowFO58jPXxY80Yi6MnV0OTBrqqOUVB+bRmySPnRGHCYr8EQ90SANvOP7GHOSWcLWJna+GagIqnGWLo2adJ58Q+EXT07Fq4lwXBztUW9YuSeCu/mDYaQFwriEFZnrs+wRCyWeCug2L/rnBEY4/JmVrWXL/DCcLVVQiFDZTnyDzVikbIX4yW+0lGOqktCOb/pc8JtUqrOLvzLPHGi1WvsmT6pPVSDssAOu2l+6j8s1H+CX4I6FiGTfvwhY8uNXVYk2cv0R1gS89Jkj6ij1lH1d4737L/ewhszDQiwVz6scVYt75ulAiKQMQUnALZ3jtZ7P6NI89BSPBHQg29r6o6vOFGiv6U5hvTnTe/qh6c/cfZ8U/2lAD2tFiF7QwDuATXo2wNyl3+Ec7bssE9MQufFcr/z1UuY/pJZ4zr3nO4zB1KbpsWkfS751l2K9f103gS9/kU5/UswahrJPFWANbf7r4QrDx9+cWHE7Eb3DgLKk5gJrGW2phCCNAX1LlZyRg/6THS1zkmcsKCneuC0GeQUapxHwnJd6ANQ5Uwp/yCqp2X6eJ2kERCVNK6FZzf5Dbb87iFlxMWeUX4lnmyhgsNCImNNl478YJl3cg38jmk0LwzWPtEi+a2V2j X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 611c2115-ae97-4c2e-cdfc-08dd3665d9bb X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:42:03.4870 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds capability field to BTF_ID_FLAGS to record capability information of each kfunc. Note that the capability field is just a placeholder, the actual capability value is set in btf_populate_kfunc_set_cap. Signed-off-by: Juntong Deng --- include/linux/btf_ids.h | 6 +++++- tools/bpf/resolve_btfids/main.c | 2 +- tools/include/linux/btf_ids.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index 139bdececdcf..40231ea36058 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -19,6 +19,7 @@ struct btf_id_set8 { struct { u32 id; u32 flags; + u32 capability; } pairs[]; }; @@ -65,7 +66,10 @@ word \ __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "") #define ____BTF_ID_FLAGS(prefix, name, flags) \ - __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n") + __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), \ + ".long " #flags "\n" \ + ".zero 4 \n") + #define __BTF_ID_FLAGS(prefix, name, flags, ...) \ ____BTF_ID_FLAGS(prefix, name, flags) #define BTF_ID_FLAGS(prefix, name, ...) \ diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c index d47191c6e55e..48be22f9a14e 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -495,7 +495,7 @@ static int symbols_collect(struct object *obj) * that - 1. */ if (id) { - id->cnt = sym.st_size / sizeof(uint64_t) - 1; + id->cnt = (sym.st_size - sizeof(u32) * 2) / (sizeof(u32) * 3); id->is_set8 = true; } /* set */ diff --git a/tools/include/linux/btf_ids.h b/tools/include/linux/btf_ids.h index 72ea363d434d..a6c9b560b6ce 100644 --- a/tools/include/linux/btf_ids.h +++ b/tools/include/linux/btf_ids.h @@ -16,6 +16,7 @@ struct btf_id_set8 { struct { u32 id; u32 flags; + u32 capability; } pairs[]; }; From patchwork Thu Jan 16 19:41:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942165 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2051.outbound.protection.outlook.com [40.92.59.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B52722E409; Thu, 16 Jan 2025 19:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.59.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056597; cv=fail; b=SmnIDJrm/Wu129415OhCq1YbNti9nOvhZNZFo/FFjU8CKt2F+CFywUUXjK9XUFe7LHchOh6j05dR1nAj9MfACOONTwxcPa4q/1zA1xexcFe2vGMI3dNgmwraw485sUrZzKZUny/3gqWb+/mef/aR9QIKwbsdD9P7YxQ+xI0zHVA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056597; c=relaxed/simple; bh=WzL0JC6Cz5/FF98R9p6CG/sIhh6XxgQPgoMzxIGocyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=BObO52AwPnaypRKX8wQvk4NJBz3RxvnqxKamx6g9/220CW/DhBu0b/b/JzfniYHR/fbwahncQ4fwzcCiEAWHykq4bKcD7S0DqK/ynZrvIwu8aDJrIapT/pVXnxWjOL3wlWkiBCa2Tgr2WUC+bFZLL0LuMwRu0IFC/lWJTuOeVD8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=Vh8Ada/s; arc=fail smtp.client-ip=40.92.59.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="Vh8Ada/s" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kHNAD1hPkJPrlCmuXQUvTf9az1TEk2hYk2kIP0DpMEDpHCZwXnI5GOZuZ6Nw3uR875k5CHQpy3x/WklD6kzybu7MapfuhYKbjEIA0DFRgggchNDtbAjyVjzEf+iRDSNTvhoLj/z4xT5qk9iqhhDXPcOAthaWGrRdxRvr6iCnYGhZOVnLAi1+X/3PtoT3A8rGa1g0Yy7XAD1ip4Q6upvUbgiyvEvXN4OGNDkJ3/1rLIc3bjA8BMihz/9NWjGblJSsxoMa+3xL7NF14/yT/aKQKSZhFAxcGaTlylqPgN/qf9ioyajeka3TY9HC9ngd0ab2PV7AXGWsuaKuk+8PEjF1VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=2kZyZ6v6BsmVdg6OwQQcMrbODiao6uodG37JMurUyC0=; b=qClWbvyu0IB6wgbAIyJTucad1wWcy40mkVL6p882+DTI1L9eC2D8D4yoH1LQKqxh30nLzTpeGHjZVp9omErah4QQb9JAFxgLF9qaSSRdZ+dx+GErAVSnhi01ELCHDgK8oy6OBqYRwKIsC1PAZ+xb3nJd1kxkLRiaDW6TMymuMvrtph/WwVH8x/NnQHEu6pMJ+Lul8TQdydoO5bvgKnL63pg79/P7YfBQuRkOLwdzFxICQ391Sn3oRsNSwC2B1skfzJQAsD42ulw4IviPxnIbCzoYhV7N1dBnh+VJnToEXeag2ePj6YM0+zEjoNVjghUf5L5FiabW/rchiYvle2ufuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2kZyZ6v6BsmVdg6OwQQcMrbODiao6uodG37JMurUyC0=; b=Vh8Ada/szZ5Xo+sEb+R9BO4Wcs11pzQrJP+NVm34XZSGfUiaHVVxJzE53IbbUgnFhc4KlVoosJcWxiqSgCo8dvtYaqacZAo5tzwdMBa1Ae6MNZgMf5lhUf7iK+W2hzsFwRwy5RgtC9udub/XuLN3a42dUnItm4N3BnB8spIwRiAt8nn9Z872E6s3bfLZStpIEnZ+DcFxh2ZWf7vZCyHCDShD+a+Ms+l6j0pzAbpHu4vKvjhnTFTq9hy4veAfhJZt3fWcn0ENHEjux3YMaL9Xt/NgCBA4m8LQLM/9ebxdmH2Nxe5pNJJRTKXbYixoDuRvn+5tNY8Syv4X/cGvE7fKbQ== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:43:13 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:43:13 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 2/7] bpf: Add enum bpf_capability Date: Thu, 16 Jan 2025 19:41:07 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-2-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: fc354ca9-6584-4aff-5329-08dd3666036e X-MS-Exchange-SLBlob-MailProps: znQPCv1HvwU46ctkesNAQSdI89rGQphJEVobBKesdTHfPyAMsuVrUV8yCepNesYZyT+MXfGD6BOlLfAlvnbsREvwmysJBCk/tJyzSoIKXZYTWB59SHlQkRK6Czh/OFW+3+CufSuDxCFHeawShgQfom3wJPAKE3BPVzn89TBeUzCyr6i9tYDyWIw4VsQqpBdyjC2+deXuRivmTLgfh9sGYQOD/8ytv4K2VediD+yGMoZIZFYgXW/7zlRAeydxk8eMz5oCpx2Z9QPpma3Fu76z0tSOb87Bum+gCb6AiwaIxm0tHo+1mJ0gjERYat81aHt26g4XqvMRWgD4RdlIaiplQ7oKOsc3IN1VpirCqK7EKOAsWYTXIWxc2WuiZuGYbTlyLzc7YCEg3CpLkpkS1Etpr5z6bv9K5eV3OtSe4PaSJANQVKFXUcgAQxytT8LODhVFIEnoiFHCq+7P0XGGtdKcsDmtlNntsL5U8gEI52ODG5S9+YFCP5F6GFQb3mZJOoS7twgS6puL/fS5RG8fCixbd6zgiZOwGPnvnK1OLW6RWGxqU158WMWLqErzqBrpDWbhJQ3jpbXdh1kB0sQtjC3AuI4piAG5zf8iLh7KbGz3dUesKKHavSbztlRX9RMvPjmMqtpTTwI72QwuH7RZ+d0oZ3mgWSqbcQw8ziCO1Cf+xi6g6qR5K8TsBE3jAoh9+Nq0RpreMVed04FFgXhkgaktAPve+fig7tPQgoro2Zh8ProyaVWFKV9950KqCx2Wj5x7tvHn7m3+KYg= X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025; X-Microsoft-Antispam-Message-Info: am+r6Q06inOs6MQwJztvw+B0t5FJJ6fgUL0AwJy0cDlDn4TJ15IEv+LoKlewsCuRCwa+YWphVfXDt0wK8Hktho8n2nCZ+MvJq7naQKYPVwDlpx76vjfduSsmCkiqjBi4bqbcihLCYqkUaUHD3NkFrDx5N5ML+xdsm8YddVaPZKckfia6hurbEWw1O7pHhv09MocqtPDMvTghMJoNioicDl6N2fCXkAEB81BRuuoyhprBQ79WVUmTqS09ISaD9de4l+KGDIfiA9yuJQwa0c5FTpMCwR4uyM4bpm+EJTQRBN4FBPkTGxrMfyCU5ECz/fpaxppD38R8xRPb02DS1EuBjXKPdzjwwGWwfsAbj+7MQIDt3AXK2XZDcI3537P9U1UcFrHruZxbGMnYJOAs/eOrFA5Le+CQcLSFKF2chkqmrqf8lr8QgRPageDSp067c6lai6MvZtLBqNtJjKAVPNw9Ew/PU7tsoGGz0lp8J2oa+Pcx4DzK0otgsq6AQwHNaxs3USkixGt1nhoKIlvHd8HKSyz3YkoN0FbNKWBpTP5xOnxk2EDBHx/yZfhU6chVDo+43lpEzSamUUT3/2NuFp3IGCPB965iy2iyV+f+DpqSLfMwXfr0NxsTjqwr5kJjt1b50FUC2GEDGdcSpirlRtGXzp4CiPmAVSguXIFcLTny9j+7lsM2s0IsFJ7eVrlQ8UvT/VAqupuzfBTtlcu5EGNg8ToBO4AkWNLdlG/RXuASsq2XhIce+bPkzQJZoRGjd8ss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+f6FXSthCh1RuDCc2eIOkxGxBoWQI+fXvVCEvy5/nvRjilB4zb+dWs1QXfMprZP3eel+B7i4CAH4SyBMUb3Snxgej/4U9oZW0gaZ5Ek2J50VF43ub5ap9aldS4EqUCygL4ZKVh4M7DS8LTptfpy3pZ4jZnc0n1hRUIKydn6XzplHe+oMIMIZynTlVrjfroE/Ui8l7tUXp2cj2oyznQAlLoFRqo+1hccaZfj14s3KRJuj129wrWJmcqaZSI3U4w70qeUIQUGZCHiDHotSmR+qvZEMB5MMv1CwygKOz4dEoXGqYq6IZhW7vecCtQ5OZMb1Mr1wyYc6MzSqgvih67DHPa8YEfWoMPEle8aIyP1dOpmadyFggfKQRZUcHf2gL9cJQeYGT2afYUUeTwrzUiid1te4e78iq9FaM11X/VjXxWVlFYTDYP4tScVS3pZ4YoEOoIvyZWnZ7ED1ZQxm1odmYMMeECnHKzcWMAqdbFMleASz667JBRZuTLDs+aNskUwhNp1HnlHQiGrEd091kaOj1oNu9KMomE9H X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc354ca9-6584-4aff-5329-08dd3666036e X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:43:13.1296 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds enum bpf_capability, currently only for proof of concept. Signed-off-by: Juntong Deng --- include/uapi/linux/bpf.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 2acf9b336371..94c21d4eb786 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1058,6 +1058,21 @@ enum bpf_prog_type { __MAX_BPF_PROG_TYPE }; +enum bpf_capability { + BPF_CAP_NONE = 0, + BPF_CAP_TEST_1, + BPF_CAP_TEST_2, + BPF_CAP_TEST_3, + BPF_CAP_SCX_ANY, + BPF_CAP_SCX_KF_UNLOCKED, + BPF_CAP_SCX_KF_CPU_RELEASE, + BPF_CAP_SCX_KF_DISPATCH, + BPF_CAP_SCX_KF_ENQUEUE, + BPF_CAP_SCX_KF_SELECT_CPU, + BPF_CAP_SCX_KF_REST, + __MAX_BPF_CAP +}; + enum bpf_attach_type { BPF_CGROUP_INET_INGRESS, BPF_CGROUP_INET_EGRESS, From patchwork Thu Jan 16 19:41:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942166 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03olkn2040.outbound.protection.outlook.com [40.92.57.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED43214AD2B; Thu, 16 Jan 2025 19:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.57.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056672; cv=fail; b=fSXPyFnASs1iq5h7pvINlNFaury33g04yPZF6Sdi2Ql5twqgitQGhezlfQ5rQoOO7dZpefzpZvqTkxz3K+suqmZ6qtacK6N4MbCfwylBHnsUBcpwwyxcMl1J0XeXt2amFkd3GlqUs3FOQD2IqVAzFWmSYV+rorYnSjNE9Rjylto= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056672; c=relaxed/simple; bh=TdnqlHyEHw6/HWMktIaFaVMal6vOshEfTy4z9mEud24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=cWdoXJwrr9di0jCyxge82iG8VMsh3J/2EJyvUfCZRI+ebeYVsZZZirbj0MJMSWIpM4qEBJomxS8n8iEwnGK/EW45hQRvFVUmN78cwN6Pd9pEKpVlFNEyGpI3SQZBchgLWVbJJFSt18p83hcDASaY6E9jHQc20w6564YMpM/Obwg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=BYhATwA8; arc=fail smtp.client-ip=40.92.57.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="BYhATwA8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IKIxRcfy/Y4cFwoHS3nqVpHb5DEMwK/l5+nySpzzeI9Rs1s9eM/KGDNlBn6QksJ6+72umFzE9HV7JHmHLkC0Hbp5Gvg8uTP4hW6OnWAlefTB3kRHggFO4SBO6G/RIs2bArp10ksf8OTnow5ySrEWCuj/aK08mphFpsnH3okgzdfndyHy3zpNVL/2kxgyLu4IjyGAMUQx7dv1EvkCuphtCPmhYrWGtmtbhyDtmOUixLkEgZNn8YSQBYjYo2/nQgT8sC2VCl1mlyLpX85QNN8jNt5bdSjidEdgdCqFNVrYck45ctOFc5tRc+OccK9JfybvwpiGtfhsdHcmNrpuxNSuBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=dvIeYHB/ZIAD8T2ESpfoSLTIGJUkVMWdBsKU9gs7Dro=; b=JkcrysWU8ZL5Xdv0MteKZl2kWHyRboK+xbCwWHf4qOCf0dIurI4cVplCQzXNSNEERJiRd0lXX7HnlhwDgiUMWM5UqanJsoUCnGaka54SC5cBOloukjGwPdOvEguTeGJ/Uh6dV91oEVb+JoEJMaUUj0A3Wc5+Rz099DF5D5p1NIGGwcgTeCXq10YzeB97edu2FOJIPV2+fGGkRfqrrUkI8faEwgPWcNUEaFlaiY63PSELQ4JBgXJRy9LHwClRirPl07fBTYhi3noQlrNtJney4gpSdBzezGqmT6vA1nzOsjY/tBJUAyWePBYkRoLqtSisTikG3HjTJUwGzkz41FRT6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dvIeYHB/ZIAD8T2ESpfoSLTIGJUkVMWdBsKU9gs7Dro=; b=BYhATwA87JMIaOrqhf3jhNaLRBevDzTaoHuowee7oUphTuh2KM6j43K9sk2rs/it+t5V3/ztQB6f1UhLmJZ5KHUYgyFSw0NmX0wZDHdedFgFtt0SOJd3cZeuywhQPINHIa+ftyTiBx9DNp5Uk8mMCZIwW5U1OtJNMHmFdoqkY+JGNKa16VQ42dugyLOuYgXI53+YVSqPKa72zd0t+dan4QPWct6nTvylWDcDRdMtjK2R+fc0Bf6kKYuV5OogN5EUpe4RBfy6X6GD2DzeQMHcsPM9d9XIZtdGcTWtV3Z3vNKWJmsiFj8ffU4tXDeWSGCIfD9Md9UMYAB0BYr+kAbKAQ== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:44:27 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:44:27 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 3/7] bpf: Add capabilities version of kfuncs registration Date: Thu, 16 Jan 2025 19:41:08 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-3-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d13a809-f710-4a98-d674-08dd36662f40 X-MS-Exchange-SLBlob-MailProps: znQPCv1HvwU46ctkesNAQSdI89rGQphJlfXOd4NGK4dtPeZj1fNJdZ6TCQh/SLkHkYr81oaksgrv+flMfLvYR4XUqmRHYHmB6rojPv6DN+8QIXhFI6M1fpRfPv7NPlIbR6jak0okOndjIkOGRYLMhbUGLBlmfcNERIm6cUJrcZBLAYqxXks8S1BwHao9aBD6x6Rp0Rj2BBZV9gU370RQp1ag9vSVSY567cdJsWcaUgx0EEqysZXu+S9xivRZxMFIRQ14f/Ez4bPpnWEt2oXb+dsxJ8GCVLI3HVPRGFn2yO00XgFTMEygZZA4ZzsgoplAX6STtBkLG6Y2AncGSRbRGz5XAZ5uzPftN0Ax15o5xE0hfHrsg/OZnM1HUb1X4iBF5sWg9JXKjuTYOZrydEzFi6HbjZU+YuA7GrPTDf1/KB5KrI/wQOxO55s8Wr4e8M1nHqJScJpIA5UFfwFvXmjw9C0OjseFSCdXspmjMD+fC0ATwslJGmZ/dtjSuqe6Llr3zf3Nidqeidr3ZWf4mWB7TCKmmYb8O5ogNuogUbb57QYP/+E0YRJP80t6Emh6d7T4GLZOoaMSef5nzVFy5qdlP0oVcplkFMtAck+kc6zOlKbyHrz25tP9Hv/EqV5Rv/z3GpGYn8j445iN2KfgGZ4+B12mOsWLJSN7h8RjPpWHFaTzND7aJIMI7Hc1KBIGEFjzngZTV8o8GSnuGQVbKLOenIaLR5qEAqo+XG5DTEFQaPaS0/ZnkSdZOgeSAmBhz3q1a6ax1qefi/c= X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025|41001999003|12091999003; X-Microsoft-Antispam-Message-Info: 9rrhcaDe3b2qH4IUJQyljH4Yro9eWxZjEUF56vqVv5uqjyMuF00QHxURlcdlmOTxweKrH09ZdxUUib5bSz2qTUpJj5KyXqwHr+ZiLSAnJ5tI64TAwycYwCiCc6iRPuBNpY/CNjz0sStjRTGwAz91lP1lpNNgEZmBSa9NBzZo4EZ759qeEoj4DLfqifiVjXEcEKRm/60XP6Q/T6It1Dxbk3siZUeXvwkVC1trh7s/DgSGhW9vb9SPHOs4T6u7QBa0GgzNaT5do7QvBiAV21a37W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u5EQgG6FutA5BAExr X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d13a809-f710-4a98-d674-08dd36662f40 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:44:26.9145 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds capabilities versions of kfuncs registration related functions and data structures. btf_populate_kfunc_set_cap, __btf_kfunc_id_set_contains_cap, __register_btf_kfunc_id_set_cap, and register_btf_kfunc_id_set_cap, corresponding to btf_populate_kfunc_set, __btf_kfunc_id_set_contains, __register_btf_kfunc_id_set, and register_btf_kfunc_id_set respectively. Note that these are proof-of-concept versions of the functions. In real implementation, the original functions should be modified directly. Signed-off-by: Juntong Deng --- include/linux/btf.h | 8 ++- kernel/bpf/btf.c | 165 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 170 insertions(+), 3 deletions(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index 2a08a2b55592..71d9658ee328 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -569,11 +569,14 @@ const char *btf_str_by_offset(const struct btf *btf, u32 offset); struct btf *btf_parse_vmlinux(void); struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog); u32 *btf_kfunc_id_set_contains(const struct btf *btf, u32 kfunc_btf_id, - const struct bpf_prog *prog); + const struct bpf_prog *prog, + u32 *capability); u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_prog *prog); int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, const struct btf_kfunc_id_set *s); +int register_btf_kfunc_id_set_cap(enum bpf_capability capability, + const struct btf_kfunc_id_set *s); int register_btf_fmodret_id_set(const struct btf_kfunc_id_set *kset); s32 btf_find_dtor_kfunc(struct btf *btf, u32 btf_id); int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt, @@ -632,7 +635,8 @@ static inline const char *btf_name_by_offset(const struct btf *btf, } static inline u32 *btf_kfunc_id_set_contains(const struct btf *btf, u32 kfunc_btf_id, - struct bpf_prog *prog) + struct bpf_prog *prog, + u32 *capability) { return NULL; diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 8396ce1d0fba..535074527e80 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -236,6 +236,7 @@ struct btf_kfunc_hook_filter { struct btf_kfunc_set_tab { struct btf_id_set8 *sets[BTF_KFUNC_HOOK_MAX]; struct btf_kfunc_hook_filter hook_filters[BTF_KFUNC_HOOK_MAX]; + struct btf_id_set8 *cap_poc_set; }; struct btf_id_dtor_kfunc_tab { @@ -8483,6 +8484,96 @@ static int btf_populate_kfunc_set(struct btf *btf, enum btf_kfunc_hook hook, return ret; } +static int btf_populate_kfunc_set_cap(struct btf *btf, enum bpf_capability capability, + const struct btf_kfunc_id_set *kset) +{ + struct btf_id_set8 *add_set = kset->set; + bool vmlinux_set = !btf_is_module(btf); + struct btf_kfunc_set_tab *tab; + struct btf_id_set8 *set; + u32 set_cnt, i; + int ret; + + if (capability >= __MAX_BPF_CAP) { + ret = -EINVAL; + goto end; + } + + if (!add_set->cnt) + return 0; + + tab = btf->kfunc_set_tab; + + if (!tab) { + tab = kzalloc(sizeof(*tab), GFP_KERNEL | __GFP_NOWARN); + if (!tab) + return -ENOMEM; + btf->kfunc_set_tab = tab; + } + + set = tab->cap_poc_set; + /* Warn when register_btf_kfunc_id_set is called twice for the same hook + * for module sets. + */ + if (WARN_ON_ONCE(set && !vmlinux_set)) { + ret = -EINVAL; + goto end; + } + + /* In case of vmlinux sets, there may be more than one set being + * registered per hook. To create a unified set, we allocate a new set + * and concatenate all individual sets being registered. While each set + * is individually sorted, they may become unsorted when concatenated, + * hence re-sorting the final set again is required to make binary + * searching the set using btf_id_set8_contains function work. + * + * For module sets, we need to allocate as we may need to relocate + * BTF ids. + */ + set_cnt = set ? set->cnt : 0; + + if (set_cnt > U32_MAX - add_set->cnt) { + ret = -EOVERFLOW; + goto end; + } + + if (set_cnt + add_set->cnt > BTF_KFUNC_SET_MAX_CNT) { + ret = -E2BIG; + goto end; + } + + /* Grow set */ + set = krealloc(tab->cap_poc_set, + offsetof(struct btf_id_set8, pairs[set_cnt + add_set->cnt]), + GFP_KERNEL | __GFP_NOWARN); + if (!set) { + ret = -ENOMEM; + goto end; + } + + /* For newly allocated set, initialize set->cnt to 0 */ + if (!tab->cap_poc_set) + set->cnt = 0; + tab->cap_poc_set = set; + + /* Concatenate the two sets */ + memcpy(set->pairs + set->cnt, add_set->pairs, add_set->cnt * sizeof(set->pairs[0])); + /* Now that the set is copied, update with relocated BTF ids */ + for (i = set->cnt; i < set->cnt + add_set->cnt; i++) { + set->pairs[i].id = btf_relocate_id(btf, set->pairs[i].id); + set->pairs[i].capability = capability; + } + + set->cnt += add_set->cnt; + + sort(set->pairs, set->cnt, sizeof(set->pairs[0]), btf_id_cmp_func, NULL); + + return 0; +end: + btf_free_kfunc_set_tab(btf); + return ret; +} + static u32 *__btf_kfunc_id_set_contains(const struct btf *btf, enum btf_kfunc_hook hook, u32 kfunc_btf_id, @@ -8511,6 +8602,30 @@ static u32 *__btf_kfunc_id_set_contains(const struct btf *btf, return id + 1; } +static u32 *__btf_kfunc_id_set_contains_cap(const struct btf *btf, + u32 kfunc_btf_id, + const struct bpf_prog *prog, + u32 *capability) +{ + struct btf_id_set8 *set; + u32 *id; + + if (!btf->kfunc_set_tab) + return NULL; + + set = btf->kfunc_set_tab->cap_poc_set; + if (!set) + return NULL; + id = btf_id_set8_contains(set, kfunc_btf_id); + if (!id) + return NULL; + /* The capability is next to flags */ + if (capability) + *capability = *(id + 2); + /* The flags for BTF ID are located next to it */ + return id + 1; +} + static int bpf_prog_type_to_kfunc_hook(enum bpf_prog_type prog_type) { switch (prog_type) { @@ -8565,12 +8680,20 @@ static int bpf_prog_type_to_kfunc_hook(enum bpf_prog_type prog_type) */ u32 *btf_kfunc_id_set_contains(const struct btf *btf, u32 kfunc_btf_id, - const struct bpf_prog *prog) + const struct bpf_prog *prog, + u32 *capability) { enum bpf_prog_type prog_type = resolve_prog_type(prog); enum btf_kfunc_hook hook; u32 *kfunc_flags; + kfunc_flags = __btf_kfunc_id_set_contains_cap(btf, kfunc_btf_id, prog, capability); + if (kfunc_flags) + return kfunc_flags; + + if (capability) + *capability = BPF_CAP_NONE; + kfunc_flags = __btf_kfunc_id_set_contains(btf, BTF_KFUNC_HOOK_COMMON, kfunc_btf_id, prog); if (kfunc_flags) return kfunc_flags; @@ -8611,6 +8734,31 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook, return ret; } +static int __register_btf_kfunc_id_set_cap(enum bpf_capability capability, + const struct btf_kfunc_id_set *kset) +{ + struct btf *btf; + int ret, i; + + btf = btf_get_module_btf(kset->owner); + if (!btf) + return check_btf_kconfigs(kset->owner, "kfunc"); + if (IS_ERR(btf)) + return PTR_ERR(btf); + + for (i = 0; i < kset->set->cnt; i++) { + ret = btf_check_kfunc_protos(btf, btf_relocate_id(btf, kset->set->pairs[i].id), + kset->set->pairs[i].flags); + if (ret) + goto err_out; + } + + ret = btf_populate_kfunc_set_cap(btf, capability, kset); +err_out: + btf_put(btf); + return ret; +} + /* This function must be invoked only from initcalls/module init functions */ int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, const struct btf_kfunc_id_set *kset) @@ -8630,6 +8778,21 @@ int register_btf_kfunc_id_set(enum bpf_prog_type prog_type, } EXPORT_SYMBOL_GPL(register_btf_kfunc_id_set); +int register_btf_kfunc_id_set_cap(enum bpf_capability capability, + const struct btf_kfunc_id_set *kset) +{ + /* All kfuncs need to be tagged as such in BTF. + * WARN() for initcall registrations that do not check errors. + */ + if (!(kset->set->flags & BTF_SET8_KFUNCS)) { + WARN_ON(!kset->owner); + return -EINVAL; + } + + return __register_btf_kfunc_id_set_cap(capability, kset); +} +EXPORT_SYMBOL_GPL(register_btf_kfunc_id_set_cap); + /* This function must be invoked only from initcalls/module init functions */ int register_btf_fmodret_id_set(const struct btf_kfunc_id_set *kset) { From patchwork Thu Jan 16 19:41:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942167 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2032.outbound.protection.outlook.com [40.92.58.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 888831527B4; Thu, 16 Jan 2025 19:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.58.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056745; cv=fail; b=lRTjOdMOdBRXOoEi4TOMpu8BVzcHWdyU7q3yhSpqBZq45CLN6IpQ6Gxt0jYfe7pXNtIhyu3YqTqHnL4kd2WLCAT2EFxtsT7qkURGreNYb80t4WAxlsF0tVLdu5jkLdC3/XzzoO1cAbj8XIsR8/uDXjW7jzmsEO23gLvBPdJwBw0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056745; c=relaxed/simple; bh=qYc0Mk+oq3SF5tEx3Oxl8JrWIBAg78j0UJctpFlVKOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=NLvIlDHwIRYoBtFn4KI8g0VnvRimmChVLwLXsyfdWthJuGHzWIllxWsgiO727du2Q0IpAIaHtRpvDb6r6DOeC4ZWWMI4TvpRk6ph9QTJGSru9ghGB3F6oTO+1WBC9yPITU1vw3Xxoy6NlLrmAHT7p5ySPzkqKuw3/J1I/E4YWg4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=URBON3jR; arc=fail smtp.client-ip=40.92.58.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="URBON3jR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h5RYbKvY2z7lR5rxoRRM7yLhqL38siMdiPLcoHHf4yGe3iOCnOlog2mHwT2aqta5K+WaTJpNJKzBJ+ZHubOw6HijrXfwZL1mPNkcBxeMukEQgYdvVHA+fj/5wKMryX24lRjaPR35llD7N35WmsUJRZrcH69+0zhAwg6ftmZGTbPlqk6jB/yocM399lqN8x52NERnntpPTEcyQoXTXBcIpXmZupA01fiW97jk4h0KjclZq+mKmmr4PZ2sNgbMhkRdOG5TizDzV5c88QO5F2MfhykwxIBh3X/0ovHZyXvYHE13jVw+7hHH0oHiHg7kcfWnv5JZRIhfzXtoSM1yglfh7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=lZ9YSceYPrJEUJzJz46nOW+u8zgXkOEFtS8jiMDdIro=; b=ycWWhJjjstq3xPHxxMzVlG8j+LAvqStuQ79Yi1WV4uJXB5AuWV2hZH145v9/Qm3jUTcgC1CamdhFw9WyfqYgeu6CjnGV4tCFagR8g6/eZc3v6CrqaWjrzswXSowoRgeV1997H9uiNXvFIbg6CY1sb5Fa+8TuGDD4QUAcHo/IMdjGWmaczZZvq3u1nOMNSjHpfDbAEyZyv90Xc3mI6LJRQ0wX15cIUIS0l+GdOj63iqEhHZKDFK5syrUQSesSuxpYiEqx2b9X19jCSvb6U1tHPTl9FPFeCUu3cEJ+M5018quzqdXuSI8YIdFkFgyH/ElhUPvt35eiEPLMrh+Jlmo18Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lZ9YSceYPrJEUJzJz46nOW+u8zgXkOEFtS8jiMDdIro=; b=URBON3jRsF1g5ntykJHAFmBFUVtOpsRTTMYxKGzNcEynyUYajGCyV2DRt9aN4rWWLRwJonNrdv2MhCF+/py2RfjKKJMUi0gZwZ0XK1Bo4RBaNDQI4sC0vQMYBSJn5Cuog5ftgtSB7uqmcaXojtZsa6xhi4QMyr3mssWUL/MmkbZT1FbSl2euX44fFfebfxKQm1tx4aif0xoyXvnoWx2kEA5dVsGzqDJXY5hkV9sFINVXD2XG2yd26XO5mTxcNkESLA90uS+xyEt/O6ViEG4Wn8BXWjWuvdN1hbUpysoAbEgmdKiLCXXFdS71X4TPAkzckJ6Fum07ncc+o7V50uT9uA== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:45:41 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:45:41 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 4/7] bpf: Make the verifier support BPF capabilities Date: Thu, 16 Jan 2025 19:41:09 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-4-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: fe7547fd-5214-4a27-11c4-08dd36665b88 X-MS-Exchange-SLBlob-MailProps: Vs63Iqe4sQl3RqqletCEFdzMlpBSGXYP8fjZ5AYySPYTL5oCz2L4FhceluvsHVmhFXe3I2OznKbyKoEDa6/OrYjqGbYaDNqcxP0Zv/0l8xxPYs5QHukxpRD8n9ONTInkf4Q7WB/IFAmWtopuKKb/J7kGli+6up+Zn1fEElSEUnPhjH2McukRpa53Yl1E808V92CuY30rCmPCstIp97/J8mBSjRLyFQIY/F0W6ETuceDdI3VFsE/3G9vJyU5pztea20ZKbrfv+cS8t0wSDaBLbt7jjhkUsEcng71nN/QwhkgDJBCFMTscvnH9qTywNOtTsoIwXXxDB438vsqXHk547wxQ7xdN+by/XM2hJOZBngvLsaNBrgB+Lfp/d0fgCKvkd25ltshM5MlQvgqnV64aaG1CSJ5V+PbYp2+Y21AAGD+Cvf4dPQlBtOHIxbKNipNnvaqRd9Wbi24wksHTT/hpTlAKsHRTlyGEHoQi1WhDzmA+MnzO/GT7rBi6VAwCnKmG0c6otZUMhgdvEx4Is3Lf/x1O+trEsIjDtEURvwLTNkUDYypRwTqTMVIKHAegh0WhJdXRkCpoyQ3vGLSd41ObleSPqORU2nYasVWyzYxVoHlNe+2Jbs6TPJyup60eTKfQAzbpdQTkVj7LmWe7+HzjoA7zwVCx6KCQdHx248b7/ZlWcjdzaiKDrY1ZDtm9tUgEEhJZadGJfHgZOHc0YcEOJTDifRy/o6TcIn4VUjDkddk= X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025|41001999003; X-Microsoft-Antispam-Message-Info: 77a3TJaYO8vym8xbDPuV+t+QvIUxAeMpWUalHZyA+snB3vbpzT/IRcSF55NzEG7GUhbobOSlqGwqTWCBGr2ow4uhf5HsgvGqrYwgHa2+zKCbYSRoeVFH48nYPm1niSexb+AM7A5AMnfa7POpxlYv2e66cA8p5ntNOVwhs4QWNR5mpAw+bhpynTAX01+B5dDNB7aHKFTVWG9NphMCiLxDK/RIDsTV1h85dIgi6xINxIBq425LW6pv+O4onyIBAZcX6/wHEafy2R+7Mc8YmEz+k22xz2ONCAzXKyJ+vlPap9m9AC4HIeBBTqteIA//TwN1i/7M1fLpHKB2O655lQLFbjt0SvyqN20ukwEjuUUv9l3m8u9JFDwgI1rGpNeIlt19/ogyw/l+usLVLPbzd8Bm+bHz6QwYXMR0DAbHldA7L4Ks+kRnbiOpNuQq5gmm78hpdAq/g0uHCmSszyumSHZnhweXp/FGWwG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4X7c//AULehxdw0xLirimBpy0TUwndXC0aXXD31g3jjwZ3CMoRBy5MZ36FNnbJIhV1N3CeLm7T/buzo+fDJ9Fm6ELd/XnXvl/8KyIHj80by3zVh3BWOp2wiPTfzytybvC9XOqL68aCBsghCZoY7Wto9/VDTTWqoOKNiP3Gq6u7vcBT/qxcaEJ/jbsdv+X1Hg8zpSUJHGgdD0Vgf7eo1ImeNJ3aw93hs7wnxlYxZ6GUrNydkYeiMXp/rugM3mqfqVDwobbewZPE35fNEnFLJMPID1c6MIQVHBnGYKXbd/ntoBWhoAI4AKWoW0ARFhtRR7d8R1DETpoya7cJa249cKYspkBQROHr9W6Q3Tma4CMqPmj0iT+VGrZzGHvt7nB2/AcwYXgYo12Y+DgmgYZHGV+H5AvcD6kVqKl8lVKkafXHppQd/lScDUv+ssd/Sk+HCUC7sT0zOncIyEORXlaQjVWJAsZ2hXJ2wk+K3YQy63g1zH9y/pQtY1hfPCWjezxkjGiLlq4EvClroKEigxPwA5Rb/yjrHok9ibakf5lYPdNutS+uLC8Mv2fJ3P+zBbJFRjWYP0xwg3DIdcpYCrDSsgHRy8fcCvBdRUeIu92y046WEXzn31mQkfyHzKLXaIf2EENtXaq+e2MBOjrula0rX7/LLOiQx/nIQTGJIPjM9NXt1kdhDvzx069p7txJm5hJ0sZa2Ass0Lg5rRePNyiBhbSV25bFW7zmvuN38tqYtbiDuswJvZ1MG5P6Ldiu3hraMCFpLhu0gvAfoNLGSEH82S07pTBXJHVgB/1q0zPf5EdySeXhzE78G8oDG7juLhF+GMbbkt+lqj42NID2ryeBqMAC3lutVM5VtHdtL8SV0KFGAFIEXJ13K3UxGuEEcbMdkJ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe7547fd-5214-4a27-11c4-08dd36665b88 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:45:40.9287 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch makes the verifier support BPF capabilities. Add bpf_capabilities bitmap and context_info to struct bpf_verifier_env. Add bpf_capabilities_adjust callback function to struct bpf_verifier_ops. Add check for BPF capabilities in check_kfunc_call. Add call to bpf_capabilities_adjust callback function in do_check_common. Signed-off-by: Juntong Deng --- include/linux/bpf.h | 2 ++ include/linux/bpf_verifier.h | 6 ++++++ kernel/bpf/verifier.c | 29 ++++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index feda0ce90f5a..73d2ff1003ac 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1021,6 +1021,8 @@ struct bpf_verifier_ops { int (*btf_struct_access)(struct bpf_verifier_log *log, const struct bpf_reg_state *reg, int off, int size); + int (*bpf_capabilities_adjust)(unsigned long *bpf_capabilities, + u32 context_info, bool enter); }; struct bpf_prog_offload_ops { diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 32c23f2a3086..6d0dad5f756d 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -784,8 +784,14 @@ struct bpf_verifier_env { char tmp_str_buf[TMP_STR_BUF_LEN]; struct bpf_insn insn_buf[INSN_BUF_SIZE]; struct bpf_insn epilogue_buf[INSN_BUF_SIZE]; + DECLARE_BITMAP(bpf_capabilities, __MAX_BPF_CAP); + u32 context_info; }; +#define ENABLE_BPF_CAPABILITY(caps, cap) __set_bit(cap, caps) +#define DISABLE_BPF_CAPABILITY(caps, cap) __clear_bit(cap, caps) +#define IS_BPF_CAPABILITY_ENABLED(caps, cap) test_bit(cap, caps) + static inline struct bpf_func_info_aux *subprog_aux(struct bpf_verifier_env *env, int subprog) { return &env->prog->aux->func_info_aux[subprog]; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index b8ca227c78af..2a321a641b4a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "disasm.h" @@ -12917,7 +12918,8 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ static int fetch_kfunc_meta(struct bpf_verifier_env *env, struct bpf_insn *insn, struct bpf_kfunc_call_arg_meta *meta, - const char **kfunc_name) + const char **kfunc_name, + u32 *capability) { const struct btf_type *func, *func_proto; u32 func_id, *kfunc_flags; @@ -12941,7 +12943,7 @@ static int fetch_kfunc_meta(struct bpf_verifier_env *env, *kfunc_name = func_name; func_proto = btf_type_by_id(desc_btf, func->type); - kfunc_flags = btf_kfunc_id_set_contains(desc_btf, func_id, env->prog); + kfunc_flags = btf_kfunc_id_set_contains(desc_btf, func_id, env->prog, capability); if (!kfunc_flags) { return -EACCES; } @@ -12972,16 +12974,26 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, const struct btf_param *args; const struct btf_type *ret_t; struct btf *desc_btf; + u32 capability; /* skip for now, but return error when we find this in fixup_kfunc_call */ if (!insn->imm) return 0; - err = fetch_kfunc_meta(env, insn, &meta, &func_name); + err = fetch_kfunc_meta(env, insn, &meta, &func_name, &capability); if (err == -EACCES && func_name) verbose(env, "calling kernel function %s is not allowed\n", func_name); if (err) return err; + + if (capability != BPF_CAP_NONE) { + if (!IS_BPF_CAPABILITY_ENABLED(env->bpf_capabilities, capability) && func_name) { + verbose(env, "The bpf program does not have the capability to call %s\n", + func_name); + return -EACCES; + } + } + desc_btf = meta.btf; insn_aux = &env->insn_aux_data[insn_idx]; @@ -16824,7 +16836,7 @@ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env, struct bpf_kfunc_call_arg_meta meta; int err; - err = fetch_kfunc_meta(env, call, &meta, NULL); + err = fetch_kfunc_meta(env, call, &meta, NULL, NULL); if (err < 0) /* error would be reported later */ return; @@ -16980,7 +16992,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env) if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) { struct bpf_kfunc_call_arg_meta meta; - ret = fetch_kfunc_meta(env, insn, &meta, NULL); + ret = fetch_kfunc_meta(env, insn, &meta, NULL, NULL); if (ret == 0 && is_iter_next_kfunc(&meta)) { mark_prune_point(env, t); /* Checking and saving state checkpoints at iter_next() call @@ -22093,6 +22105,9 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog) state->first_insn_idx = env->subprog_info[subprog].start; state->last_insn_idx = -1; + if (env->ops->bpf_capabilities_adjust) + env->ops->bpf_capabilities_adjust(env->bpf_capabilities, env->context_info, true); + regs = state->frame[state->curframe]->regs; if (subprog || env->prog->type == BPF_PROG_TYPE_EXT) { const char *sub_name = subprog_name(env, subprog); @@ -22176,6 +22191,9 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog) ret = do_check(env); out: + if (env->ops->bpf_capabilities_adjust) + env->ops->bpf_capabilities_adjust(env->bpf_capabilities, env->context_info, false); + /* check for NULL is necessary, since cur_state can be freed inside * do_check() under memory pressure. */ @@ -22385,6 +22403,7 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env) prog->aux->attach_func_proto = func_proto; prog->aux->attach_func_name = mname; env->ops = st_ops->verifier_ops; + env->context_info = __btf_member_bit_offset(t, member) / 8; // moff return 0; } From patchwork Thu Jan 16 19:41:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942168 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2079.outbound.protection.outlook.com [40.92.58.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AE4322DC2B; Thu, 16 Jan 2025 19:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.58.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056783; cv=fail; b=TCF0swhf25w3DiEu93NiRi+JU8Qa9ia4M1BXIGCrfCdHMCimrEfGTuuNrli+u0Qx+D8vWCWyNWFpn5McvHULQf7aystTKsjv4+uVgNQUVEHbSz20ZtX8tb9RsYz2ASIUJ8C9IMTLnAIL2qpY7wF39ZARzkRdgD6o9SadXf0YmzU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056783; c=relaxed/simple; bh=OxXjD/dGBq/vZAn2GQDS0goOix0417cy8O8ZQKseT7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Q+0nNJdUhcNjtzks6z9A0Ev3fMbEY7QiMw09+z59coz5/PYNgwpEsykSm8j+vcC6c8NdSqXScLyk+wYhM9Fb2NYZc1wBPHI+dfom6MrjhNF8dJGPdEDhDJ7GWKMgWH37UwWznJG51+9aF6tekxF6nG3qZ6drlYXvGoRWMXzSZsw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=PBBNb1JN; arc=fail smtp.client-ip=40.92.58.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="PBBNb1JN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k6sUmg0E42rJTCXENJxcRU+WhDWSPvzbpM+uMhUHpu/4DwhZlX3C3tfHt4ScA4CzfMedc1w06f2oPY+biz31Mp3LvO6GIm64ymG5ZJPzpPgflGsQoFdKTWMvU4HV/8ZgURL9or95709hVi4zy0agE1sivF9pjijHWmpNv/R2qrcamo1EOMdQ933zTVh7a+dJtqGM1oTQe38u6IapeQ6eVJrQCoqSdXbILe04C7+6oDIlEHKQ0/h9/yBdbSnr2Y1Co/3ww9ZeZ9Hacc7eJAOiFN3zt7HfbNmALLdu7BJlAkjaHj1Jc3E2UxzpjQjdUXwNQbHQyBtotyzupbBeSVoFUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=cZ6A4w4OHkXdtMbn1yg1U3YXnst3cLDL8hDYwE5DRCM=; b=wzLE1gy8FNYX3RMQqXjtIVyCIpZGkdpyJIoj/4rvVdQF5sRQaAHP/iAeMf1O3gsOO+vslTm1gyJ0WyeDGFZeH0Vapu/2KKDCPJWq6ZWwYLFKHExzQ2K0aMRkqqci/Pb4YAUgA0vuxfuZr5VKsafQXrVEycwz8LZBc9Z1rh0lnCxJ5CLLavZRyQt2+UF/AKvlGDR//PLnW1h9gQhTm5czc60XZ3mWTsfcTmJBX8OIAIi4iHI9JGPf6KBW45dnfyXJFmjr/87RrKm6pQfM7DbTYE/69sRW+gzKlzJ+Qu40InTTFnGfREVJEHZu/gA+2E0KgGbZAejraODdMx0h21YcmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cZ6A4w4OHkXdtMbn1yg1U3YXnst3cLDL8hDYwE5DRCM=; b=PBBNb1JNcNMMW4r5iNzGA1KumXFeIHbkyy780r2f+XR0CQxciRm7AiYZdsKhTinPKVMVLe/wfgcxm1qNkYwnJ9dNZQmEJAe/goE9QITeGtoWiwihR4RKi6ERIMtebhLmSQVZz4hTrJWyrjoMDFx48a6d26KzL0HBmVy3Fn1oLEHGWEBrNj0z+LKrz3fuRZZmwG/USmhaUx9nVTMBm26oU6UZ87kIr6CxJqDWcdM4xtgOPthKSe7A8jmmL9DqDmVRyAZRNkNmnFXR/LPIN+6MVlIRwZ4yID0H0Feto8Q/kKzjxd2Gdsf4KtyTxMHuJfeDz9JpbQakkoaldmfLsDNDkg== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:46:18 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:46:18 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 5/7] bpf: Add default BPF capabilities initialization for program types Date: Thu, 16 Jan 2025 19:41:10 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-5-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: 46a5e83f-cdf3-4749-efa0-08dd36667215 X-MS-Exchange-SLBlob-MailProps: znQPCv1HvwU46ctkesNAQSdI89rGQphJWvyCmanD08b/nTnXOhcKMdvQzGpECoPIv4qmjXoe6E2p5tYkxI56t7Nerty9iwVCTmhex/4j1aRPnaicq8LIeJYJgNVvVdpyPOH55ZXYz3T5BJREEcMBd5srOKp/I57c98P9QRNvM0gcOghnlPlh64xEVozLpshLRDKM6q2UloQVz+PKgy/bpuLjcepZtOFozbsKXzNy5wInDNKX7yFDHcENFaw0gL+AG4HwVirTn024ft3GAQYlZyrn/suEUR5WkUyWOy68FTWOTXP4+7Qp8EZz6TzIashXPIeu1wFyvDJ0G1C2Ta7hqz0o14ztFYPCkW58H4nE3v92RDrj0OB0bESs4rqR9zA/sZU9F6MrGSF8NCzASuoGPATnF5aWvUgpMAnKPN+e+GzBGpy2n8oAumkUSNsGcwgizjycy1ym4fbepuDQC0SI3Wvc1/x2Q/H0VhaUyR07TcXIQbAqHgJH9AyQLa362rHUobA3vJ0ttnu9BTsguQzKz01nF2o2HedRH/4sUNzfnL9rHo9cG53EnlZTkeM+eTUNxuTIgvkjH+E8KvU4Aagzpd+Lc7coUzFFoM02DTb0XGcm+56r8CorwyPLmneAm0gcLuz+u3o1wO+0VfqaNlVUTeRkGPOmLWJzfWlarUpz5GbGXt7KGiLgs5UYLUrH16DcSk/fhdRMD4V5d7UNPnFOSko2qkYyjEGZhwbiVVYqSljaF/2x6wNnyqbtmRZJfgk//NjTb+ZbRxE= X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025|18061999003|19111999003|41001999003; X-Microsoft-Antispam-Message-Info: 6S+5rMPWLrCM9df4YY5gdU2sIUA9hmT4NlJcdTzRKLuW4n60FKabVOmt0Qh7ICB9H1VCUVD3bWj8x+DTpm06TfFX1yV2pw0rO9iD8iNAnLdQkGXqk8N/L9IL2qGiW7RKfJqWorn4+gilE7BlWC9EL8qdI7W455Shte+yz+tmUYeS/axJBJhWPyYV8edBKXaSg76UJYMn9TTghEoVRCmT4193rJ4cQ5QATDXgzcrBDUMZe1YmBOs7ZWjwKaYtLQg3LrrJDlxfgY/lQmubbfkg4AgTbtw0f1C17u2Tf0AhSN2+NVX6Yiqep9TLWJqfkiW1x17xAPAKKzupCxQPA82Hu/Eln1lG0Wk1WBxjw2SCIc1TQhIzVvWy42y5xMjN9AkBPGUQsO3JCEheyKCGUv/wDq2hH82wp0EZyjBNJIeBGAEYDV03yIkFPZyDf5OxaT/o63GF0LsGawz8EQNYlFUCPInz/3tbhwlMVU8JKcRrLyKQDfQLNpws/TtGt2FwQGV9wDkhxyb8PlXNCtWCn/FAXo1muWiAYsdA99/noQQAWFN7uQCANTgGunNVbBPj+nY/rEZTIqtAscYxqkrEiAcZBLk1VsqerznkHs/n+fHFvL860JZLUiYkeI7mj/UBlQwW0mrUj0tRi2oGFjuA1AgnWRjZfc/cvnROik3FKX5WYi6hbyEQJlafdsrVJXqRa2nXrs7H2ZwIuzELQnftcm4rhMs0b73ns4KL7UVPfV5PUrl8a7avb42YJLn6DpwJmn5SN/PC3dSKSvTuunr0E7ujwCQOQpozIGV7qtL0vCRyp+y93h7A0B9P87cykvVb3269I0PMUp+yRNtyfSv7/F2bYYp1aHI22IZgBO1N2owQONGTLlQBQIO/2OkGqK1P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XuwGFZKO9WuyP0qY9kRlyh8Wgnuni6VFnxFPfXg7C+iDkAVYfdTOjbe721E4IaWenj3/RHzp4L0aXZZsbhve1YeAfEsg41vh7mHo3rXdT4mdmvOosDtZ9hjOSuufgjfJj7+nhgJkAhE7pRx1HgndWoxVuMCnxyEM/mrM0OYwRba9Ry91tbeQR/6hFpprF+sJZ04ISeEuQU5cOfMHvqOzIlOKq6r6tjHEke0geERfAqoPg0NAP7ldiBxQY+JtDwPHMq3LqYYfjqhKn7ulOq0RF8GJM/QNtCSRboqWs9+jyLxafW73DKEW9HzwJ3tJFyJvqfM/qblWY2/G1YeLgrvRZQnhzEQjJv0DbRl+X+8R5Wnq/BPNVYM1iC6ojM/kD9RqGtkQhYXdvSeoqHrsDTohjxBPrzK7EX3Roy0Jn+tVhYllf3Z0Ea8lkHJedEzJR5EfKlqCyVUWXlOWQRjttYJj7gvZmHJhITHdDvoWjxoMj8Xl8WzZd3p0iEALfU912Acj+QAjntl3QBxaiER+7+Jql+iSZJWmsUMBncx0TZ7ugFmScNLm4 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46a5e83f-cdf3-4749-efa0-08dd36667215 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:46:18.8976 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds default BPF capabilities initialization for program types. Since this is a proof of concept, only BPF capabilities initialization for BPF_PROG_TYPE_STRUCT_OPS is added. BPF_PROG_TYPE_STRUCT_OPS enables only STRUCT_OPS_BASE_CAPS and BPF_CAP_SCX_ANY by default. Signed-off-by: Juntong Deng --- kernel/bpf/verifier.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 2a321a641b4a..7a69a581861f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -22959,6 +22959,40 @@ static int process_fd_array(struct bpf_verifier_env *env, union bpf_attr *attr, return 0; } +#define STRUCT_OPS_BASE_CAPS \ + BPF_CAP_TEST_1, \ + BPF_CAP_TEST_2, \ + BPF_CAP_TEST_3 + +static const enum bpf_capability struct_ops_caps[] = { + STRUCT_OPS_BASE_CAPS, + BPF_CAP_SCX_ANY +}; + +struct bpf_program_type_caps { + enum bpf_prog_type type; + u32 size; + const enum bpf_capability *capabilities; +}; + +static const struct bpf_program_type_caps bpf_default_capabilities[] = { + { + .type = BPF_PROG_TYPE_STRUCT_OPS, + .size = ARRAY_SIZE(struct_ops_caps), + .capabilities = struct_ops_caps + }, +}; + +static void setup_bpf_capabilities(unsigned long *bpf_capabilities, + const struct bpf_program_type_caps *caps) +{ + int i; + + bitmap_zero(bpf_capabilities, __MAX_BPF_CAP); + for (i = 0; i < caps->size; i++) + ENABLE_BPF_CAPABILITY(bpf_capabilities, caps->capabilities[i]); +} + int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size) { u64 start_time = ktime_get_ns(); @@ -22997,6 +23031,9 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3 env->bypass_spec_v4 = bpf_bypass_spec_v4(env->prog->aux->token); env->bpf_capable = is_priv = bpf_token_capable(env->prog->aux->token, CAP_BPF); + if (env->prog->type == BPF_PROG_TYPE_STRUCT_OPS) + setup_bpf_capabilities(env->bpf_capabilities, &bpf_default_capabilities[0]); + bpf_get_btf_vmlinux(); /* grab the mutex to protect few globals used by verifier */ From patchwork Thu Jan 16 19:41:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942169 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2042.outbound.protection.outlook.com [40.92.58.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27BDB18FC8F; Thu, 16 Jan 2025 19:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.58.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056827; cv=fail; b=ULQkWwiJc3hU+mZDsx7XsD/YzOFeBR3lszStEEjhyzz43KnvkBEbLxvbTc6MadIiK2iUxxJ+aWkHSMGAo2ZMIN5w9PgyS4JG5STO7QAxITW1ZYvMFrX+jPgksx1C3v6WdKzxzYbNs+oRCRMbmaw53tQ55KBWJb3+jVv1zeqvtsw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056827; c=relaxed/simple; bh=h/yO9mzimRtH0uPK0V4jx5i2zzSQi8FD0DauO9EDAMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=qXEcx3VFcGYk5cyquOxtYc/bFW3CI7kadM1/n93vUGesTXxt1DIs/8HDHP/orNHR9SMv7ttVCvWqGvfaJw7KSsNThtxZW5sJQsNavzgMOBf9xsdA1AOfoysVVmzig3faxMicj74ClOALS8Nv7tFt0PdHf4/chhpcm1tYUKM6P88= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=VF5Z4Kj8; arc=fail smtp.client-ip=40.92.58.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="VF5Z4Kj8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ngCR2FXKFHtqiJbrap1tEY+9a43Lsp7doE73ckcuFuouMcYXEzZwSWbrjMiu0Slja3cV4RnrV9jeP8H/afM8D7QvubShGPjaPpFPQ3UQVxPnGPCw2/HCTZuM/kdHP3DAy8MkIT5LHw/xZdtHBKffeefbeey/bEBSTgGtYl8jf1IX4dlFIH2tw12GNNvRbdCgwZN0NDInurgs3E43jfBsucTu2k2Ro8FBgnpImLoEzzaL0nqdZyu4hpA5DRlu2sZTql5dTdmajJ7tNb5zO+BYtEvpOsqngWi2Wet2H4NA6MbrGFT3H4vKO2re/IxIX6B6RMD7KG7QpLKERNeuNgnX7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=xAi8EqhndCSzb6lqFAf7g3rU5YiypcIsgiRlRo9eF5w=; b=dur9/jYuHO3kggjpY36xMPsZ5/7EMqz2lL2/3pd6AmMA0tdxGYVWcTCex+4yZTbGGhRTtEAtNHF81cZ1Q+xljyo/791+dRPWo7FwXH5aKTWXt+Rww1Dw1RTH6EQPdLxgCS0QrB06mXBzy/I9pbyMKJ//sWxxrDWcAU5mevVrz2LMMnGR+71V56nHGVmnGWlBYecTSAQxztFb65bAOhhCb/TcVctbq1P4LMj1cjGunZVofnUY+Au84mPv3uilu6SM8LiBo2n9YhlrQuEm8A/ZjQFv8sazu5lb1V8iHir0Ku5eCBHDFYXnGNnZ6ljy/zmlUl4id0Q4s70zRcpeXUuKLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xAi8EqhndCSzb6lqFAf7g3rU5YiypcIsgiRlRo9eF5w=; b=VF5Z4Kj8LAMSF5v394pdC7y6f+dpUgOLYcPwhxOb3azCeSGZwJd4CbaF8viXwR2AlkCTUSbCl5rnKQB6Hc/gzduKoggTxmB2kooMyfK0VWLKL1TURZG5mazJi0SHVy/2dz60tH35UhV5tdiB8qlNJ3FuNbVnwz/VitV9k/iQYrZbgngU4LT2Z0dZAcOZs8aLt+FfI14gfnJSuPSrT/CLC37UuRMTOvHUKtphD05rMbxCb0HU3IcXNs5lzIFRO/993Lh/GFWxYkhhjbYbT88PwsL8vH1CQI6mS32EWlFYa1ScRNWSMfx4kl8gqi9j8bTXvZrqBJTk+MdUaXz2uj7OYg== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:47:02 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:47:00 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 6/7] sched_ext: Make SCX use BPF capabilities Date: Thu, 16 Jan 2025 19:41:11 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-6-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: cd326940-f1cd-48a0-9c28-08dd36668afd X-MS-Exchange-SLBlob-MailProps: znQPCv1HvwU46ctkesNAQSdI89rGQphJV0Vp+aV5YQnTXSmvWD3oESLrA0oPkVumYcW+fPl4RfaHXr1HVIModBzlDINeRapXZ6ohk4e2CHXxx8YtecRO9Iufa3N+edvlW5SYlD00e8DdCIAXCthxzEWEdQr6VHxkvFgn//CBMDyXotgQ1JIVlSxbmoFUiE6/lcon1ZNNOs/Pq75Y/O5NSSQt2PHA/tFXJl/8pAfG9qpJXXVpYmzXmeS/3dhgRVALEXJCNSdz7o7v6WogSgQm5Ue6JVbIrL4HX+r4ogrtw9WPdmVhSFSqgDRF+GO7GypUP13B0tW3d/Mgm3rA8Et6mH+PL1qh6fSYlLq/RrZF5Z946OY3OwIwxnPf90v5d9gPOYrvoa5Q+vbbRiA8QwpbshI43JKdEIFdcOsZ8iDzzBNudde5TmNL7idLyvMboWtxf7IN8NlpzQLY3lbWvtaOssfPGI3Im25+ZxlD2oxgIFtb7BbDMq7fcmVZqVcVnX2zA6+eeDm/PcmSj6yyYAaJscmbfBjJ9/RmA87TeoTG6iqmGqFrBrStPbfhQjrffa208qU9ysrvoKVabp3bfkhka0JVYwZqdy2ync2x+fIYp/XbDEKQZ+P/2rND8mkrpUbMP50rng+bYvm7J7rRtrxQSgEm1H9bpu9EpQ+8FkURikhgNoEkB10d6yYWNvCYjEYzznfhENObs0VZ2eeozFWYFsNWvqp33Gq496NiAoEAyaTEF4bZ+6ZkZ9/qW4NXimC/LGUdTFUOUcU= X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025|41001999003; X-Microsoft-Antispam-Message-Info: lmiOiaOPlpAQPZPzDbmQa5hnvKRvg9kIkOZX7llf7wDirddua9wpAxqtXY9Q/9dkRfr4KfB8szNRPpp31FXvVUsu/+a0ogJZjVQlsKR1KztYNHlwcRYGyGlf1irtW32qk08AwJUgoJck3/yWhoy3362MjoWviteOUGC8VsKMKDEs6gtzi5fkD0q0rbA4D3oL8vy0RUyXA6+OrmvdzInH4dSKOCMWJ7v5s3wf9BWbTj9P3s8oA+Pwj0GfqXFjxE20NEA2AHM5Gugpt8k3YIplurMCEbfQiOyEu2TGsGWMxbKWwi/YWuiufcV5LDnfeiWyWwEVcZd5ELKWUxLYUdZPOsRasRTLE+qpEZ/bAIcBTio5ejMc3YPS2hkC/XwPjm5H7qhZWI7xV2voR1pNjOZW6k4ktcIWopZF2qMedPGVLiwI8hM3uIvLJpWDbJHs7kNxPy7/EWitkqfXFCOk/MQ/N4c9VbNgbHQdcXJRBigrG0Ms/HkAcr6R7+agP3ZRgjkC6mdCSCL09IEqUIlSqlRZh4xR9PeOPR4amF64HFROXsNANDG0u0JyVp4y/k/FSf+o4E/obqt0O2UziTz5lMzDSFrxZBnrUZElwuGT44WbRq6gEzzu6pTjt7HRumcVo3AVaHCCF338gp1tg7VCTTfpiBXlgaLppQ4ofMi3L4NyhJVw6RKnkd8Zd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p8ySac4fR99l4munKPMPqtAtZBGffFsQFT353t3FEHKJL36szJLze/hnzPdGZOncRktku8n7TUdjVZuawLRkkxEracHe64lBsgoL8YjgLvibFJxnz1zX5dUEiERO/y5tNKInp61wgQroEQeTWh4bWYlskhvBwV6Ib2dgz9yVQkE/yUZCeorp2MQXbZ8JO1Q2cXgPeaiNc5VUGuvZfI6bz7XV92HVvCWjGDT63OUmObAM0AoUg6lVhzh92kr0PuKWNiNcHMcVcJ6QzCeCGn9ly9y1RDAj2zM2hjhtz26k3DobKFF+nhuhNBC/RbITNPqm3+egNDdhM1f2qU9zc7YhIOmR8X3OFv8AevFx/KHdeHw5UuH0/QPvGIQUKsWh6ckxb00BooBb8weUoYmsS5EKoMnDkL/DiKk+nnMOYau95xKUH5BXBhidymLQiGfVh6RzWg2OQ/jTFATs1Z9WYjQJzxPhMDd+efMB405LYsNnVKLoA4X3HWr7RjjE3r+jRt/6shF2AP8be/lN1hLrTEujT9iwn+h8ujgefACv+TzVuffEUHrMjHv3a3mIxXNSsU0sQeWUgKNnO76Jlbk/WOMnWKYyVtaFe2GAo78dOsDGlcKvlmAHXtKNasTCghI3Paccvuj6VFM35A453z5oIh5C3Ade2R9c8owH2tH8b17tX/go7O X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd326940-f1cd-48a0-9c28-08dd36668afd X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:47:00.7544 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch modifies SCX to use BPF capabilities. Make all SCX kfuncs register to BPF capabilities instead of BPF_PROG_TYPE_STRUCT_OPS. Add bpf_scx_bpf_capabilities_adjust as bpf_capabilities_adjust callback function. Signed-off-by: Juntong Deng --- kernel/sched/ext.c | 74 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 7fff1d045477..53cc7c3ed80b 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -5765,10 +5765,66 @@ bpf_scx_get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) } } +static int bpf_scx_bpf_capabilities_adjust(unsigned long *bpf_capabilities, + u32 context_info, bool enter) +{ + if (enter) { + switch (context_info) { + case offsetof(struct sched_ext_ops, select_cpu): + ENABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_SELECT_CPU); + ENABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_ENQUEUE); + break; + case offsetof(struct sched_ext_ops, enqueue): + ENABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_ENQUEUE); + break; + case offsetof(struct sched_ext_ops, dispatch): + ENABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_DISPATCH); + break; + case offsetof(struct sched_ext_ops, running): + case offsetof(struct sched_ext_ops, stopping): + case offsetof(struct sched_ext_ops, enable): + ENABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_REST); + break; + case offsetof(struct sched_ext_ops, init): + case offsetof(struct sched_ext_ops, exit): + ENABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_UNLOCKED); + break; + default: + return -EINVAL; + } + } else { + switch (context_info) { + case offsetof(struct sched_ext_ops, select_cpu): + DISABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_SELECT_CPU); + DISABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_ENQUEUE); + break; + case offsetof(struct sched_ext_ops, enqueue): + DISABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_ENQUEUE); + break; + case offsetof(struct sched_ext_ops, dispatch): + DISABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_DISPATCH); + break; + case offsetof(struct sched_ext_ops, running): + case offsetof(struct sched_ext_ops, stopping): + case offsetof(struct sched_ext_ops, enable): + DISABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_REST); + break; + case offsetof(struct sched_ext_ops, init): + case offsetof(struct sched_ext_ops, exit): + DISABLE_BPF_CAPABILITY(bpf_capabilities, BPF_CAP_SCX_KF_UNLOCKED); + break; + default: + return -EINVAL; + } + } + return 0; +} + static const struct bpf_verifier_ops bpf_scx_verifier_ops = { .get_func_proto = bpf_scx_get_func_proto, .is_valid_access = bpf_scx_is_valid_access, .btf_struct_access = bpf_scx_btf_struct_access, + .bpf_capabilities_adjust = bpf_scx_bpf_capabilities_adjust }; static int bpf_scx_init_member(const struct btf_type *t, @@ -7596,23 +7652,17 @@ static int __init scx_init(void) * them. For now, register them the same and make each kfunc explicitly * check using scx_kf_allowed(). */ - if ((ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + if ((ret = register_btf_kfunc_id_set_cap(BPF_CAP_SCX_KF_SELECT_CPU, &scx_kfunc_set_select_cpu)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + (ret = register_btf_kfunc_id_set_cap(BPF_CAP_SCX_KF_ENQUEUE, &scx_kfunc_set_enqueue_dispatch)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + (ret = register_btf_kfunc_id_set_cap(BPF_CAP_SCX_KF_DISPATCH, &scx_kfunc_set_dispatch)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + (ret = register_btf_kfunc_id_set_cap(BPF_CAP_SCX_KF_CPU_RELEASE, &scx_kfunc_set_cpu_release)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, - &scx_kfunc_set_unlocked)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, + (ret = register_btf_kfunc_id_set_cap(BPF_CAP_SCX_KF_UNLOCKED, &scx_kfunc_set_unlocked)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, - &scx_kfunc_set_any)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, - &scx_kfunc_set_any)) || - (ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, + (ret = register_btf_kfunc_id_set_cap(BPF_CAP_SCX_ANY, &scx_kfunc_set_any))) { pr_err("sched_ext: Failed to register kfunc sets (%d)\n", ret); return ret; From patchwork Thu Jan 16 19:41:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13942170 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2022.outbound.protection.outlook.com [40.92.59.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AEF214AD2B; Thu, 16 Jan 2025 19:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.59.22 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056866; cv=fail; b=oGMGGflStdqm9lwNfdWjkEk3RFj5t4qYuukRmoe6ZIoqHiLm3euyaZmbDycG6I4WxfCEdXGbwnWoz2DC7TENZyiYp+xsPPMGaP0T7sMTVVosSwd+xac3QrdS3f5Y4h4qYt7r7uireuCd4BOfp+eEIG8eUTGBOJfyUQuoUM3AiCc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737056866; c=relaxed/simple; bh=pdfJ4hp7/BViOvZ0UT650FbASfKhkxxC4RvGNh+Sl5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=cmvkNmwqdJYK215O49z4Q/9CPZMN9nwezRKkZb8f74hsfkm4Cc2f9omeILU4RezcKaxTFA6NtY8o/u4jEcazwIk5Hc0izNCgYXhwc/5eaa0UN8xYTcudWR4L2pDE6/s5oZ74MYBKvixOxG8WClKHlknbTyM874YQcFTbf9OQ2RY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=lkqeDlIh; arc=fail smtp.client-ip=40.92.59.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="lkqeDlIh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Fl5Zaga1ZT0VQNIFQh5WU3K4vA6g0sSg0u/aKbPIVzHlHIXxE+7bE26WI9mVXep/IyQUCQMbGc49TIca7fI8CPwBEGPI93iQny22kSID6Q59w+gbqTN6j44CxUWa0M4NvuUv22r6b1seC2Lfq4NnpZxBigIOpXw2WrtNcYM7DWE5NW+0jfsiAMM47R/RxdByKDSLnsgP2E52GbcBZySsZpmdRpd/oO7BErHTg+V2ZYk6t/92jQ3AEQx1JqYU7cHj67cEyFRgm12pz3RUgBf4lVcCjmgo6PzgVXII5/gg5tnXxyDhESzaP/wjw7PsUqCJWWZExCJqkqF2fvIJ4fnwdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ue3aM1cua/YxafH6GzXivqhlWZXDVQpuBtzoAZ3xS7Y=; b=OwquLtosnbU+LfbgKBBOZ+OE+KZXMF3G+0zIUUMD65XdhTEdaRDhq19ccQRjdXURxwxo/5soDKMHimBHbxim5XnDAlJPJnf+Sb1pjN0vuWOWWjV4+ijdSSu7dS+JG7iMnAMBZ67kMSBo+4Uz/OX7pIZrgNj8w+CeSSknzuJP/MzO+c/Y1dRlYHdiePWXdrgWsKPVLrNt8eKfnXVYUChLsq5U5vNhSt2rTzA6PjfwZ9HDDVN5BQHR9PjloDvbIXCv+FuQN/itde4ZphMcFS91174jZhz+MWBYqUarUvYfae8tG0ESxSjIOWCRIH/YTu7GY/PfJvNdHYlyErjFJOUsig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ue3aM1cua/YxafH6GzXivqhlWZXDVQpuBtzoAZ3xS7Y=; b=lkqeDlIhhqh7Df1hqy2SNfz9c0DjdW4l9HRNjyyqdOUGLo8aY2cJoUeNXm4n44hXg7DUuCN8Fr+s7FG1wia0+wULiwFBIneoxAEqd7hrsCdwpXZIB0VQHqw0IPca8jkxjqxVxAr3DIabYWeHhUaCwXK0yn1tJiA/M4GOP0BAbi2tuBIWBxjQr9SB2rGhMEFldDZaWCh8exIe2yeMq+Qg77241NCcWgf4HD0R39Q9CSb+diSMNnm9eedm8oCROM3fVET4xNG0ZWemTGVIGuCULPl8BRKWXTD0dnmvbUFHiV0w3mwLUYpn8W7NlLIauSATRX8OMvFFBe4fUpMrYN2DZQ== Received: from AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) by AS8PR03MB7970.eurprd03.prod.outlook.com (2603:10a6:20b:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Thu, 16 Jan 2025 19:47:41 +0000 Received: from AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8]) by AM6PR03MB5080.eurprd03.prod.outlook.com ([fe80::a16:9eb8:6868:f6d8%3]) with mapi id 15.20.8356.010; Thu, 16 Jan 2025 19:47:41 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, tj@kernel.org, void@manifault.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH bpf-next 7/7] sched_ext: Add proof-of-concept test case Date: Thu, 16 Jan 2025 19:41:12 +0000 Message-ID: X-Mailer: git-send-email 2.39.5 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0041.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::19) To AM6PR03MB5080.eurprd03.prod.outlook.com (2603:10a6:20b:90::20) X-Microsoft-Original-Message-ID: <20250116194112.14824-7-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5080:EE_|AS8PR03MB7970:EE_ X-MS-Office365-Filtering-Correlation-Id: 42ec5472-45a3-46ee-54c8-08dd3666a389 X-MS-Exchange-SLBlob-MailProps: Vs63Iqe4sQl3RqqletCEFdzMlpBSGXYPwmFenpr/y74wp7dRb+1jc991cfIdHMeeLHapMdZ7lqBuXELq0CtSjMKJlV0l5BgOtuFvwYEHAqcDLi5k8DHjNQrrowFJorJPts9mh2v+lDqh+vJsDjgVJ4V2UrCd6klyRn7sZ31HuQqci5m11BLzrgWpA8KXAQzV3lqequVah02kWP3QgHP9DkHLJf2rJt5ivcuAN2KTcMOZ8Zj3DllJcBRcHOnz4DLhGYBJg1hTSsRm2VzLoao4iE4VJ7z7/7vKXhfUUVFLVkhbLX4xwfMycyhzKFaWBgkDk191XroQPBImEd1xY+5MNOBoAJiYLwUGGf89vzleCmjRBq3X4BpLblHAqaRc9UjFx6gwGTEs1JXjeMpFrK9VTi2KLqy61fhpcqzbvjUuLXsjhIuI+BLACAYgjQ0SJG1ozHw93vOfmQ1t4UOaQjTPuTIE2a591dvbnicLOxd3M1Sywppkdu92Ah41oQ8IPM63fOHs81EVtl1Y+2GcWPCUAQ3AER5lXQIWLZYhbTQ3FGWB4O0jyzxRlhmBKYDPmW/9fbdE1DOywy77aw6Vb1Vh6cTw6CKNqYB0ZLFee1WHcOlvzS5ZNZt5xR/iF4ykBwjULMJWkEKGlEO9i585rFUIMXCCQ9ausSzeraHe6KsdnyteYhfeOuTo+yskKIwRX1fnepv1kJl4Xm7jWhEr63T0aG+4JpBJ70XKBb/j4RKnoZI= X-Microsoft-Antispam: BCL:0;ARA:14566002|15080799006|8060799006|5072599009|461199028|19110799003|440099028|3412199025|41001999003; X-Microsoft-Antispam-Message-Info: kkcodqdgtb/Jx6ifxV+9i1Tg4IShfPzCjy3MfUj1mK4vK1orSg0cdpX9ShTIKBYbEWNx7XIOokwylwI638NICDTDz4NxF4or/xM5MDA3en3JgkseoTIdaVtogfchS3lr4sT213ptTHwbXuCj5RrMM8h+/D4zRZXBa1LPQX1MWigH89jSVaEc8W736sOPeuYuvImJnbxjsfDX064NQJMM5EsccgKL4yXMmFNHo/CRUIqOiPI7LmfQJzPA3nDZh9u9eL/08cg/PQlMvd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ginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42ec5472-45a3-46ee-54c8-08dd3666a389 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5080.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 19:47:41.7296 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7970 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch adds a proof-of-concept test case scx_simple_cap_test, which is based on scx_simple. Add scx_bpf_dsq_move_to_local to enqueue, which will be rejected by the verifier. Signed-off-by: Juntong Deng --- tools/sched_ext/Makefile | 2 +- tools/sched_ext/scx_simple_cap_test.bpf.c | 159 ++++++++++++++++++++++ tools/sched_ext/scx_simple_cap_test.c | 107 +++++++++++++++ 3 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 tools/sched_ext/scx_simple_cap_test.bpf.c create mode 100644 tools/sched_ext/scx_simple_cap_test.c diff --git a/tools/sched_ext/Makefile b/tools/sched_ext/Makefile index ca3815e572d8..0e87aa77594b 100644 --- a/tools/sched_ext/Makefile +++ b/tools/sched_ext/Makefile @@ -176,7 +176,7 @@ $(INCLUDE_DIR)/%.bpf.skel.h: $(SCXOBJ_DIR)/%.bpf.o $(INCLUDE_DIR)/vmlinux.h $(BP SCX_COMMON_DEPS := include/scx/common.h include/scx/user_exit_info.h | $(BINDIR) -c-sched-targets = scx_simple scx_qmap scx_central scx_flatcg +c-sched-targets = scx_simple scx_qmap scx_central scx_flatcg scx_simple_cap_test $(addprefix $(BINDIR)/,$(c-sched-targets)): \ $(BINDIR)/%: \ diff --git a/tools/sched_ext/scx_simple_cap_test.bpf.c b/tools/sched_ext/scx_simple_cap_test.bpf.c new file mode 100644 index 000000000000..6bcf4dcbfcb4 --- /dev/null +++ b/tools/sched_ext/scx_simple_cap_test.bpf.c @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * A simple scheduler. + * + * By default, it operates as a simple global weighted vtime scheduler and can + * be switched to FIFO scheduling. It also demonstrates the following niceties. + * + * - Statistics tracking how many tasks are queued to local and global dsq's. + * - Termination notification for userspace. + * + * While very simple, this scheduler should work reasonably well on CPUs with a + * uniform L3 cache topology. While preemption is not implemented, the fact that + * the scheduling queue is shared across all CPUs means that whatever is at the + * front of the queue is likely to be executed fairly quickly given enough + * number of CPUs. The FIFO scheduling mode may be beneficial to some workloads + * but comes with the usual problems with FIFO scheduling where saturating + * threads can easily drown out interactive ones. + * + * Copyright (c) 2022 Meta Platforms, Inc. and affiliates. + * Copyright (c) 2022 Tejun Heo + * Copyright (c) 2022 David Vernet + */ +#include + +char _license[] SEC("license") = "GPL"; + +const volatile bool fifo_sched; + +static u64 vtime_now; +UEI_DEFINE(uei); + +/* + * Built-in DSQs such as SCX_DSQ_GLOBAL cannot be used as priority queues + * (meaning, cannot be dispatched to with scx_bpf_dsq_insert_vtime()). We + * therefore create a separate DSQ with ID 0 that we dispatch to and consume + * from. If scx_simple only supported global FIFO scheduling, then we could just + * use SCX_DSQ_GLOBAL. + */ +#define SHARED_DSQ 0 + +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(key_size, sizeof(u32)); + __uint(value_size, sizeof(u64)); + __uint(max_entries, 2); /* [local, global] */ +} stats SEC(".maps"); + +static void stat_inc(u32 idx) +{ + u64 *cnt_p = bpf_map_lookup_elem(&stats, &idx); + if (cnt_p) + (*cnt_p)++; +} + +static inline bool vtime_before(u64 a, u64 b) +{ + return (s64)(a - b) < 0; +} + +s32 BPF_STRUCT_OPS(simple_select_cpu, struct task_struct *p, s32 prev_cpu, u64 wake_flags) +{ + bool is_idle = false; + s32 cpu; + + cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &is_idle); + if (is_idle) { + stat_inc(0); /* count local queueing */ + scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL, SCX_SLICE_DFL, 0); + } + + return cpu; +} + +void BPF_STRUCT_OPS(simple_enqueue, struct task_struct *p, u64 enq_flags) +{ + stat_inc(1); /* count global queueing */ + + /* bpf capabilities test! */ + scx_bpf_dsq_move_to_local(SHARED_DSQ); + + if (fifo_sched) { + scx_bpf_dsq_insert(p, SHARED_DSQ, SCX_SLICE_DFL, enq_flags); + } else { + u64 vtime = p->scx.dsq_vtime; + + /* + * Limit the amount of budget that an idling task can accumulate + * to one slice. + */ + if (vtime_before(vtime, vtime_now - SCX_SLICE_DFL)) + vtime = vtime_now - SCX_SLICE_DFL; + + scx_bpf_dsq_insert_vtime(p, SHARED_DSQ, SCX_SLICE_DFL, vtime, + enq_flags); + } +} + +void BPF_STRUCT_OPS(simple_dispatch, s32 cpu, struct task_struct *prev) +{ + scx_bpf_dsq_move_to_local(SHARED_DSQ); +} + +void BPF_STRUCT_OPS(simple_running, struct task_struct *p) +{ + if (fifo_sched) + return; + + /* + * Global vtime always progresses forward as tasks start executing. The + * test and update can be performed concurrently from multiple CPUs and + * thus racy. Any error should be contained and temporary. Let's just + * live with it. + */ + if (vtime_before(vtime_now, p->scx.dsq_vtime)) + vtime_now = p->scx.dsq_vtime; +} + +void BPF_STRUCT_OPS(simple_stopping, struct task_struct *p, bool runnable) +{ + if (fifo_sched) + return; + + /* + * Scale the execution time by the inverse of the weight and charge. + * + * Note that the default yield implementation yields by setting + * @p->scx.slice to zero and the following would treat the yielding task + * as if it has consumed all its slice. If this penalizes yielding tasks + * too much, determine the execution time by taking explicit timestamps + * instead of depending on @p->scx.slice. + */ + p->scx.dsq_vtime += (SCX_SLICE_DFL - p->scx.slice) * 100 / p->scx.weight; +} + +void BPF_STRUCT_OPS(simple_enable, struct task_struct *p) +{ + p->scx.dsq_vtime = vtime_now; +} + +s32 BPF_STRUCT_OPS_SLEEPABLE(simple_init) +{ + return scx_bpf_create_dsq(SHARED_DSQ, -1); +} + +void BPF_STRUCT_OPS(simple_exit, struct scx_exit_info *ei) +{ + UEI_RECORD(uei, ei); +} + +SCX_OPS_DEFINE(simple_ops, + .select_cpu = (void *)simple_select_cpu, + .enqueue = (void *)simple_enqueue, + .dispatch = (void *)simple_dispatch, + .running = (void *)simple_running, + .stopping = (void *)simple_stopping, + .enable = (void *)simple_enable, + .init = (void *)simple_init, + .exit = (void *)simple_exit, + .name = "simple"); diff --git a/tools/sched_ext/scx_simple_cap_test.c b/tools/sched_ext/scx_simple_cap_test.c new file mode 100644 index 000000000000..c4a0a5b1e0cf --- /dev/null +++ b/tools/sched_ext/scx_simple_cap_test.c @@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022 Meta Platforms, Inc. and affiliates. + * Copyright (c) 2022 Tejun Heo + * Copyright (c) 2022 David Vernet + */ +#include +#include +#include +#include +#include +#include +#include "scx_simple_cap_test.bpf.skel.h" + +const char help_fmt[] = +"A simple sched_ext scheduler.\n" +"\n" +"See the top-level comment in .bpf.c for more details.\n" +"\n" +"Usage: %s [-f] [-v]\n" +"\n" +" -f Use FIFO scheduling instead of weighted vtime scheduling\n" +" -v Print libbpf debug messages\n" +" -h Display this help and exit\n"; + +static bool verbose; +static volatile int exit_req; + +static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) +{ + if (level == LIBBPF_DEBUG && !verbose) + return 0; + return vfprintf(stderr, format, args); +} + +static void sigint_handler(int simple) +{ + exit_req = 1; +} + +static void read_stats(struct scx_simple_cap_test *skel, __u64 *stats) +{ + int nr_cpus = libbpf_num_possible_cpus(); + __u64 cnts[2][nr_cpus]; + __u32 idx; + + memset(stats, 0, sizeof(stats[0]) * 2); + + for (idx = 0; idx < 2; idx++) { + int ret, cpu; + + ret = bpf_map_lookup_elem(bpf_map__fd(skel->maps.stats), + &idx, cnts[idx]); + if (ret < 0) + continue; + for (cpu = 0; cpu < nr_cpus; cpu++) + stats[idx] += cnts[idx][cpu]; + } +} + +int main(int argc, char **argv) +{ + struct scx_simple_cap_test *skel; + struct bpf_link *link; + __u32 opt; + __u64 ecode; + + libbpf_set_print(libbpf_print_fn); + signal(SIGINT, sigint_handler); + signal(SIGTERM, sigint_handler); +restart: + skel = SCX_OPS_OPEN(simple_ops, scx_simple_cap_test); + + while ((opt = getopt(argc, argv, "fvh")) != -1) { + switch (opt) { + case 'f': + skel->rodata->fifo_sched = true; + break; + case 'v': + verbose = true; + break; + default: + fprintf(stderr, help_fmt, basename(argv[0])); + return opt != 'h'; + } + } + + SCX_OPS_LOAD(skel, simple_ops, scx_simple_cap_test, uei); + link = SCX_OPS_ATTACH(skel, simple_ops, scx_simple_cap_test); + + while (!exit_req && !UEI_EXITED(skel, uei)) { + __u64 stats[2]; + + read_stats(skel, stats); + printf("local=%llu global=%llu\n", stats[0], stats[1]); + fflush(stdout); + sleep(1); + } + + bpf_link__destroy(link); + ecode = UEI_REPORT(skel, uei); + scx_simple_cap_test__destroy(skel); + + if (UEI_ECODE_RESTART(ecode)) + goto restart; + return 0; +}