Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp85626lqh; Wed, 27 Mar 2024 15:55:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFlF5jyzQqk226RkfeNoUUaqRYZwcb3Tukb4MPMIv0fgcxgzYUBHHK/q5ba5EIG6r9w08yoo63aE70/ZIFPbn3s1/NDB0bitvagmmwtQ== X-Google-Smtp-Source: AGHT+IHjwwkV2x9Cm64pZaOA7zqPs1TnI85vWWqwSYnjnE8GunxRDClyAHiyg4skb8DQBuj2Sdr5 X-Received: by 2002:a2e:80d0:0:b0:2d4:92ea:21de with SMTP id r16-20020a2e80d0000000b002d492ea21demr913578ljg.0.1711580108072; Wed, 27 Mar 2024 15:55:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711580108; cv=pass; d=google.com; s=arc-20160816; b=rXlBTpDtvBs9sTs3uriYByAjjeZbWNfqTVipCXRkzBwXJeTrj/oDtZ6Zsng5zNitLN bOm8eB6Iglf2qkYaCy5htZGLD4PrutQFFib8f5IVBDqYt3LQNz1OHCg21BWTnomhhcxr hkLrSf/8lipgnMN7KWYbcwl/slsYzncA6cL1PEAuapBDaa5r40EgTwHLQHddKotRi18M K+DmLn8k1nyxrowFcWDm1ZLiW7hel5tkS+/ArpKBt6qvQ3afle1jHFKefP+8OCUy9V07 MsirKjdlJlgDOgO4ql6qN75cuG0I4cOp3nvddxTZwucAqwDbZ0qbWXt32+SOfpcYKj5p KooQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=G15/cZOUwJ4wAwK3pv4/rQlxMz/GUR4FC5RGf/w3iUA=; fh=nEQJWRimrtMQud0GFtdvNzxghtkQZ7mvaeIZA/qi9Ls=; b=igrcEv7x+QvQrndN2hNpA+1X0sOnBptt1UZNXJ0fKnW4eFVW/xWOJ5Shn6eGJtNejE xqiVz3O83V7vd7N8Ic6+lKLDsS8qhociL+DQL6xMRMknHtBfOxfTWO2A3sgArtcm/9/7 ts9men2T4bOk3JHSMyOQb1+L2pfjdDdYHX/yU9+B88lC5fAyQxH0Tt6vT4RP2CDCg03i j8GQN6H1afve7xs8CWzC6TU4xMQRsOPw9JdOtF/deaHu0pvOwmHtfUt0nyfUe8EdmnL1 BgwZaU3rOkSVsLimJmDoNSMMqw6/ysBUjFdOP4IPZNbd/6EbnPgZbxpFmvbH6Uu8j5Dd nXGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BgsOZ+JQ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-122126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w15-20020a05640234cf00b0056c3049714fsi93444edc.551.2024.03.27.15.55.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 15:55:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BgsOZ+JQ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-122126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A453F1F2E9D4 for ; Wed, 27 Mar 2024 22:55:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 485CD154445; Wed, 27 Mar 2024 22:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BgsOZ+JQ" Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C152D2EB04; Wed, 27 Mar 2024 22:54:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711580090; cv=none; b=BloZVl3iC5pDrj16S+g43NmUasnD8RLtNovTo3YVt/GODSI9b8Cvh6tPRu+L1stN3NBnbtJeHOcH/J/fFyTIszLzqwGXbRTdyQr83q/P6TVj0iemiBodXyRnaPDatSezDRZDR8ZVAEtrIuzw9Dyu6E5230n7k5Rx9YYWqeKPN8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711580090; c=relaxed/simple; bh=B4kQ7Md5GvHsR2L+XgbgKogJenUHgF+GDFDTZ3omF3c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ORPFDO2pm2QK8dSlaCnZhWu/IZGMUCqdQECTh/G9Yx5kXQGivFvrr4/7ITYk2UmenMD1ZuGlCI1Lcn2qwt0LLAuAE/p1fI6Eb3A3rFcfW+9shCZfRMWNTgg94d2IIVx6jbKQxSwYxMsogk8InNIYZH8AU7NCN54AT8oiuBDHn9U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BgsOZ+JQ; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-34100f4f9a2so162724f8f.2; Wed, 27 Mar 2024 15:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711580087; x=1712184887; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G15/cZOUwJ4wAwK3pv4/rQlxMz/GUR4FC5RGf/w3iUA=; b=BgsOZ+JQH2nJUYy46m09uxxwJ2bqyPAio0LRk7LBu6Y6JCEIXzj1yw4g0ao+ZpoRPG BQMW9INaHpPeC6VKysMxpxksQim8xwTRGJZJASfxbCWOmoxUo1K/vuSPcVfXD955G5kF qy9S2Jn9NWdtFZ+urA2jRG1SXvm6MwOhmUR44DJpfgJwxPOsMrZQeTxga5+Z7SXIcetz XcZ8H3Dh4TefXYBbEOcvszOQ4G9PVG9FxrI2T2+CHfEv52ozE8IqumsXrjxHHHyQIpWj JouBMzvg7owUNN5vwlcPlbA8wQMzzkrdwKOtgfIgJzenw5rjLE6Q7kH83Rr4vgOD1yar PQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711580087; x=1712184887; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G15/cZOUwJ4wAwK3pv4/rQlxMz/GUR4FC5RGf/w3iUA=; b=ioMugbPVZ7NEMzGG0Z+I5fcxi1XH4RRGZZ5eDANgQhi6DhYlVbU0x2bFQ43XyQzIgY 5jT2z72LJnt0ICok9GLe6IHaRrjNLmC3OzVM4rWNZHvxxDLNTiA6bwtjjOExSMt9KPM1 tVUhWaaey+7P02IhvPm74gUNLG+SkVPhR6L4OQzL0ikbTBWcWvbL5Evabl+t18I87YP/ GzsF9Flmu1tvKPy7S0qkLASCMdvP8CFsSq+MZX9krtAG3afTqsZzN0SGwqnq68IyAev0 HOHk6ueUDBMJIyXjLGLGWm1sfg+ql681YbInpnYun/X154vRedvIyUFTAKBUKA+YhAsL MLdQ== X-Forwarded-Encrypted: i=1; AJvYcCWr3UFDKITQ+sQVpwylQiD46pls6J28lERwOsDcdTDM0243xS09EWm4rPtkyBlbPAZJZ8yxIxmkz0Uz5XhA0YwrkbHICclURfZXLKc+kMX0+tGiMKx9llLKfMPAvzkR6er5iYw3NXxmB4YGPYI1iuMX+7cphHzbghUBjZbL/pX0HKp2+yjLCci0rPbtGavp0Cxrp+8A62ugPKoplg== X-Gm-Message-State: AOJu0YzbQ5U8ISo92LYsMTpyFjpebbKCCL6zYHhlZcoCMqtypwvpPoNH QcBFRAJ+GmtlK1ZAvLb4w404cANlfFaEmQVbm9Y4u7Y966V4WzM6 X-Received: by 2002:a5d:400e:0:b0:33e:69a8:fe85 with SMTP id n14-20020a5d400e000000b0033e69a8fe85mr858630wrp.37.1711580086806; Wed, 27 Mar 2024 15:54:46 -0700 (PDT) Received: from rorona-tty.. ([154.121.114.3]) by smtp.googlemail.com with ESMTPSA id cc7-20020a5d5c07000000b0033e75e5f280sm152348wrb.113.2024.03.27.15.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 15:54:46 -0700 (PDT) From: Djalal Harouni To: tixxdz@gmail.com Cc: Tejun Heo , Zefan Li , Johannes Weiner , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH bpf-next 0/3] bpf: freeze a task cgroup from bpf Date: Wed, 27 Mar 2024 23:53:22 +0100 Message-Id: <20240327225334.58474-1-tixxdz@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327-ccb56fc7a6e80136db80876c@djalal> References: <20240327-ccb56fc7a6e80136db80876c@djalal> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch series adds support to freeze the task cgroup hierarchy that is on a default cgroup v2 without going through kernfs interface. For some cases we want to freeze the cgroup of a task based on some signals, doing so from bpf is better than user space which could be too late. Planned users of this feature are: tetragon and systemd when freezing a cgroup hierarchy that could be a K8s pod, container, system service or a user session. Patch 1: cgroup: add cgroup_freeze_no_kn() to freeze a cgroup from bpf Patch 2: bpf: add bpf_task_freeze_cgroup() to freeze the cgroup of a task Patch 3: selftests/bpf: add selftest for bpf_task_freeze_cgroup include/linux/cgroup.h | 2 ++ kernel/bpf/helpers.c | 31 ++++ kernel/cgroup/cgroup.c | 67 ++++++++ tools/testing/selftests/bpf/prog_tests/task_freeze_cgroup.c | 165 +++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_task_freeze_cgroup.c | 110 ++++++++++++++ 5 files changed, 375 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/task_freeze_cgroup.c create mode 100644 tools/testing/selftests/bpf/progs/test_task_freeze_cgroup.c -- 2.34.1