From patchwork Wed Oct 25 07:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuyi Zhou X-Patchwork-Id: 13435682 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 3C3E71C2BA for ; Wed, 25 Oct 2023 08:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="c63pA3MJ" Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5902C10E for ; Wed, 25 Oct 2023 01:00:22 -0700 (PDT) Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3b2e72fe47fso3592068b6e.1 for ; Wed, 25 Oct 2023 01:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698220821; x=1698825621; 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=623dJ/e0dl/9VZB/F0AUPvisvbBwnO9eeoKfg40DawY=; b=c63pA3MJG1VO2lYZk8GDp+mZCt1iE8qhQ5+IB54LTPEf0f/k4Sms99qsgZHDegM3U8 KTH9mYiN73PzC2cswq1qZnVq9OHwJLgV36A8usJRNvaNQ1Ivm3FcKUCTOH6gEicgtRfa o4pZuOuXs/7lzH6imA8D/J+/jLiw50A1m3856GkumU719qGHD0n4meBCHzYxJFrYwF1B ktkMEuSXuL65oXLgd199xPhdFUdaj5tbVxNj2uorIlTu4xh/p8Sij6xDZCfUFrlA++mV tG+hc5wL/tSA5CSWxyRgZ+NWrfz0AVbiSEcZnbBJ0Ne1ixzeYv2Zn+MnI6SMxexFHZQb sraQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698220821; x=1698825621; 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=623dJ/e0dl/9VZB/F0AUPvisvbBwnO9eeoKfg40DawY=; b=t4GnpcLZglCTkKR+FdZSEznlb82EUbLFUW+YOYrkKUzDnm9Cf8mXjwHGd8aGyipZMf L3maEWN6VMrcFm8saYZ2f//xqgPxGZonf2cJIRzOa2mytZV2mzwqP/HkqQbSYfMJVZ06 bKwaYNY6BSzOybqQNP8UrUqi2Xue5KIFULX+GE/uxBKpDrwQiTMN7aC+DzkOCr2CmtyM /nh4HUIEDbiMInVcyXZCLvDYsEm09K9Nk8FoMpFyazKMREfgH4F2yzz8tPy8WIOZ1R+N tla+XiR7L9R3s4xUtuPJPZUSmRf7IWWrJ+jVA39NnknkJ/vtpHawivqTXxXaFydgVtim GX6g== X-Gm-Message-State: AOJu0YxmNczC9wDcc4N7C18F1T4gkxEdv95tcOpQ1ansfHV+G8ua62Qh GCK2UpycVd1FRHgThwH1Wwb5xRUfgq4B1PJYbPg= X-Google-Smtp-Source: AGHT+IFNrJ6aGXsfBcfq42K58SlpCq4ESlrfgv2CoCJH4pDIc90B4PFXLHn+X0N/+cKUV52sXWfNgA== X-Received: by 2002:a05:6808:3ce:b0:3ae:55e5:43b6 with SMTP id o14-20020a05680803ce00b003ae55e543b6mr13588579oie.48.1698220821013; Wed, 25 Oct 2023 01:00:21 -0700 (PDT) Received: from n37-019-243.byted.org ([180.184.51.40]) by smtp.gmail.com with ESMTPSA id 23-20020a630f57000000b0059cc2f1b7basm8118187pgp.11.2023.10.25.01.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 01:00:20 -0700 (PDT) From: Chuyi Zhou To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, Chuyi Zhou Subject: [PATCH bpf-next v3 1/3] bpf: Relax allowlist for css_task iter Date: Wed, 25 Oct 2023 15:59:12 +0800 Message-Id: <20231025075914.30979-2-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231025075914.30979-1-zhouchuyi@bytedance.com> References: <20231025075914.30979-1-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net The newly added open-coded css_task iter would try to hold the global css_set_lock in bpf_iter_css_task_new, so the bpf side has to be careful in where it allows to use this iter. The mainly concern is dead locking on css_set_lock. check_css_task_iter_allowlist() in verifier enforced css_task can only be used in bpf_lsm hooks and sleepable bpf_iter. This patch relax the allowlist for css_task iter. Any lsm and any iter (even non-sleepable) and any sleepable are safe since they would not hold the css_set_lock before entering BPF progs context. This patch also fixes the misused BPF_TRACE_ITER in check_css_task_iter_allowlist which compared bpf_prog_type with bpf_attach_type. Fixes: 9c66dc94b62ae ("bpf: Introduce css_task open-coded iterator kfuncs") Signed-off-by: Chuyi Zhou Acked-by: Yonghong Song --- kernel/bpf/verifier.c | 16 ++++++++++++---- .../selftests/bpf/progs/iters_task_failure.c | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index e9bc5d4a25a1..9243b6ca4854 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11088,6 +11088,12 @@ static int process_kf_arg_ptr_to_rbtree_node(struct bpf_verifier_env *env, &meta->arg_rbtree_root.field); } +/* + * css_task iter allowlist is needed to avoid dead locking on css_set_lock. + * LSM hooks and iters (both sleepable and non-sleepable) are safe. + * Any sleepable progs are also safe since bpf_check_attach_target() enforce + * them can only be attached to some specific hook points. + */ static bool check_css_task_iter_allowlist(struct bpf_verifier_env *env) { enum bpf_prog_type prog_type = resolve_prog_type(env->prog); @@ -11095,10 +11101,12 @@ static bool check_css_task_iter_allowlist(struct bpf_verifier_env *env) switch (prog_type) { case BPF_PROG_TYPE_LSM: return true; - case BPF_TRACE_ITER: - return env->prog->aux->sleepable; + case BPF_PROG_TYPE_TRACING: + if (env->prog->expected_attach_type == BPF_TRACE_ITER) + return true; + fallthrough; default: - return false; + return env->prog->aux->sleepable; } } @@ -11357,7 +11365,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ case KF_ARG_PTR_TO_ITER: if (meta->func_id == special_kfunc_list[KF_bpf_iter_css_task_new]) { if (!check_css_task_iter_allowlist(env)) { - verbose(env, "css_task_iter is only allowed in bpf_lsm and bpf iter-s\n"); + verbose(env, "css_task_iter is only allowed in bpf_lsm, bpf_iter and sleepable progs\n"); return -EINVAL; } } diff --git a/tools/testing/selftests/bpf/progs/iters_task_failure.c b/tools/testing/selftests/bpf/progs/iters_task_failure.c index c3bf96a67dba..6b1588d70652 100644 --- a/tools/testing/selftests/bpf/progs/iters_task_failure.c +++ b/tools/testing/selftests/bpf/progs/iters_task_failure.c @@ -84,8 +84,8 @@ int BPF_PROG(iter_css_lock_and_unlock) return 0; } -SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") -__failure __msg("css_task_iter is only allowed in bpf_lsm and bpf iter-s") +SEC("?fentry/" SYS_PREFIX "sys_getpgid") +__failure __msg("css_task_iter is only allowed in bpf_lsm, bpf_iter and sleepable progs") int BPF_PROG(iter_css_task_for_each) { u64 cg_id = bpf_get_current_cgroup_id(); From patchwork Wed Oct 25 07:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuyi Zhou X-Patchwork-Id: 13435683 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 7B75C63CA for ; Wed, 25 Oct 2023 08:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Qwj96157" Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37800116 for ; Wed, 25 Oct 2023 01:00:24 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-581fb6f53fcso3153514eaf.2 for ; Wed, 25 Oct 2023 01:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698220823; x=1698825623; 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=vaiHO7SBSXsd0QCikkafn6mecL9krZTUGDMsMzgZbU4=; b=Qwj96157JNxA7rQQUAFID3bigfzFyCWZ7J9xAJ/FGosmsUQgSJRU8cw9CjX+jjdpuL T42a9U5/3+z1X/SbmopGM6kOo+nqpjieg5epqzCMFvLxQfxS9yYYWryXeQfBgyFvimgi gcT4rlmhwQRASM06GKAntSBzTUOLwPDXUkZzj9CEEXbkyyRJiRVsECGYL5HWPZAskfMK aqmveqoSbwXw5T+Gd11J/nRJvhrwv3jre/MUclSK/FpK05iGgpNXVmPHKGE0/ca+S14a dIMi9xj3uubL1dnnLPLS2GqxH5odLfI9/pUnMPe1+9btnHQ8Z/v0UMw8yjb3ODej6Azc nkhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698220823; x=1698825623; 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=vaiHO7SBSXsd0QCikkafn6mecL9krZTUGDMsMzgZbU4=; b=ZK0ecwhtxgU2xPJi1Dzu4Q44djJg2uRL/4WfB40JEL9W3ryweSA2iD8FmE2qsB/OS1 EJwDDP0LCrhQLXDZ2wxxuRf0uvhsud5EkcGh9dVZ51scwVeQptzEeWE4fuKYGZYDd8UZ 6IqE8wvSNGGcmRf7MyKfZrBdv3x/G87eXPQCWOJAge7s/aX/EGa+xZKx3yKQaeeWhP8j Shg03YHwkguxMABktBYOtCQum1nPs1JilnK/k3f+QTD2gXc8/jG11MtU6+H11ZE6If3H 4PIgHaG5xHO1maTi+IGsHViAX4GMvKtvVHLy169tsIzppqqlhf1aax+qomnc+DwS6ep6 zRhw== X-Gm-Message-State: AOJu0YwwgSbzWT7X98/4+VaTf/lHKmrP+4erFGqsK2r5Q7CS3nGRv4H0 zH9tPQSFzgiZ9/ahgox9kky5kupMWpcn+k+nazw= X-Google-Smtp-Source: AGHT+IGajCKoEf9uKr96cuek8ikK010TTGEC7NNwwNktxU1Llh1DQENQfFk86x4NWzzchOWCE8ktgg== X-Received: by 2002:a05:6359:593:b0:168:e9d2:6568 with SMTP id ee19-20020a056359059300b00168e9d26568mr6618931rwb.25.1698220823170; Wed, 25 Oct 2023 01:00:23 -0700 (PDT) Received: from n37-019-243.byted.org ([180.184.51.40]) by smtp.gmail.com with ESMTPSA id 23-20020a630f57000000b0059cc2f1b7basm8118187pgp.11.2023.10.25.01.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 01:00:22 -0700 (PDT) From: Chuyi Zhou To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, Chuyi Zhou Subject: [PATCH bpf-next v3 2/3] selftests/bpf: Add tests for css_task iter combining with cgroup iter Date: Wed, 25 Oct 2023 15:59:13 +0800 Message-Id: <20231025075914.30979-3-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231025075914.30979-1-zhouchuyi@bytedance.com> References: <20231025075914.30979-1-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This patch adds a test which demonstrates how css_task iter can be combined with cgroup iter and it won't cause deadlock, though cgroup iter is not sleepable. Signed-off-by: Chuyi Zhou Acked-by: Yonghong Song --- .../selftests/bpf/prog_tests/cgroup_iter.c | 33 +++++++++++++++ .../selftests/bpf/progs/iters_css_task.c | 41 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_iter.c b/tools/testing/selftests/bpf/prog_tests/cgroup_iter.c index e02feb5fae97..3679687a6927 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgroup_iter.c +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_iter.c @@ -4,6 +4,7 @@ #include #include #include +#include "iters_css_task.skel.h" #include "cgroup_iter.skel.h" #include "cgroup_helpers.h" @@ -263,6 +264,35 @@ static void test_walk_dead_self_only(struct cgroup_iter *skel) close(cgrp_fd); } +static void test_walk_self_only_css_task(void) +{ + struct iters_css_task *skel = NULL; + int err; + + skel = iters_css_task__open(); + if (!ASSERT_OK_PTR(skel, "skel_open")) + return; + + bpf_program__set_autoload(skel->progs.cgroup_id_printer, true); + + err = iters_css_task__load(skel); + if (!ASSERT_OK(err, "skel_load")) + goto cleanup; + + err = join_cgroup(cg_path[CHILD2]); + if (!ASSERT_OK(err, "join_cgroup")) + goto cleanup; + + skel->bss->target_pid = getpid(); + snprintf(expected_output, sizeof(expected_output), + PROLOGUE "%8llu\n" EPILOGUE, cg_id[CHILD2]); + read_from_cgroup_iter(skel->progs.cgroup_id_printer, cg_fd[CHILD2], + BPF_CGROUP_ITER_SELF_ONLY, "test_walk_self_only_css_task"); + ASSERT_EQ(skel->bss->css_task_cnt, 1, "css_task_cnt"); +cleanup: + iters_css_task__destroy(skel); +} + void test_cgroup_iter(void) { struct cgroup_iter *skel = NULL; @@ -293,6 +323,9 @@ void test_cgroup_iter(void) test_walk_self_only(skel); if (test__start_subtest("cgroup_iter__dead_self_only")) test_walk_dead_self_only(skel); + if (test__start_subtest("cgroup_iter__self_only_css_task")) + test_walk_self_only_css_task(); + out: cgroup_iter__destroy(skel); cleanup_cgroups(); diff --git a/tools/testing/selftests/bpf/progs/iters_css_task.c b/tools/testing/selftests/bpf/progs/iters_css_task.c index 5089ce384a1c..0974e6f44328 100644 --- a/tools/testing/selftests/bpf/progs/iters_css_task.c +++ b/tools/testing/selftests/bpf/progs/iters_css_task.c @@ -10,6 +10,7 @@ char _license[] SEC("license") = "GPL"; +struct cgroup *bpf_cgroup_acquire(struct cgroup *p) __ksym; struct cgroup *bpf_cgroup_from_id(u64 cgid) __ksym; void bpf_cgroup_release(struct cgroup *p) __ksym; @@ -45,3 +46,43 @@ int BPF_PROG(iter_css_task_for_each, struct vm_area_struct *vma, return -EPERM; } + +static inline u64 cgroup_id(struct cgroup *cgrp) +{ + return cgrp->kn->id; +} + +SEC("?iter/cgroup") +int cgroup_id_printer(struct bpf_iter__cgroup *ctx) +{ + struct seq_file *seq = ctx->meta->seq; + struct cgroup *cgrp, *acquired; + struct cgroup_subsys_state *css; + struct task_struct *task; + + cgrp = ctx->cgroup; + + /* epilogue */ + if (cgrp == NULL) { + BPF_SEQ_PRINTF(seq, "epilogue\n"); + return 0; + } + + /* prologue */ + if (ctx->meta->seq_num == 0) + BPF_SEQ_PRINTF(seq, "prologue\n"); + + BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp)); + + acquired = bpf_cgroup_from_id(cgroup_id(cgrp)); + if (!acquired) + return 0; + css = &acquired->self; + css_task_cnt = 0; + bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) { + if (task->pid == target_pid) + css_task_cnt++; + } + bpf_cgroup_release(acquired); + return 0; +} From patchwork Wed Oct 25 07:59:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuyi Zhou X-Patchwork-Id: 13435684 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 8BA551C695 for ; Wed, 25 Oct 2023 08:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="j2ANNlrU" Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E5199 for ; Wed, 25 Oct 2023 01:00:26 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6ce344fa7e4so3578677a34.0 for ; Wed, 25 Oct 2023 01:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1698220825; x=1698825625; 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=LEDb2KxkVSFe4TSUmh3nQ3qzGa9/MUfpXPnNyHh03Dw=; b=j2ANNlrUlsw9WLtlsJ/fXP9Pq+4U5oGrj44LQdoMogRIBRVfe5rDe/6a3KF62PSFKU 5xw/wSUk6uGCyySqjFv4KXDvmmbmm3AjED6sx1tBCnE3YHeaS+XXQ92yHvWDfirBxngb TTb4FnJ6Q7YT46JwIVsHSkFAEPdPe0aa/IrXVKNfKe/Qp6pG1z7Ac5G771G2NyrhwpRF tiZBT1IgueQmXw2cTeIbYbTsZYArVZcYMBQqyt/7NWEM3w/NfdkJtAKt3whMJVfd24WW UJTJUC4w+a1aSvrpULxDdr+Vk4vUrMOOXx57JFAcFtPSwow0SsAMCeR+7BdW56lgAlI8 lH4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698220825; x=1698825625; 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=LEDb2KxkVSFe4TSUmh3nQ3qzGa9/MUfpXPnNyHh03Dw=; b=KE+Obois6ASwdvg4Hy1xnXZ77IeSDIgOzPgoEvtbMWNFh0FIxChXUMkl9zZyXUwG7A uyg9ekoLNTMDS3Wy9P5nd1QSzXUN3KHY7ZUeej++SLFuC/JdmSFIMURd5RGhPabOYvcJ NZ8MkDvVdIYdPiVsk4mC7IIyDx75MekhhDUIJYKGzOwc37QogDTMvIP6ZdJ3Vs6hHAaW eLGHD/ZhNWspzq6cwqBJiBU0IkFK/JZ6jRZyxdBoKuuraVqQfq7KFdaWnD1JOmsp9Nm2 m+OtnYjC+SzVDNUJ4WPOPeHaYb9y0dcbTomLxgZAV4NQ8BIUT+UJXvlZZe/3D3aiYg8p IcXA== X-Gm-Message-State: AOJu0YynBNim6U2wa9qc46yB4/oqcMyY2IlqTeuawLgH9CJo0D0ut01C K0+Iv3gEJhiR1JvXpTDWCZWR/IjqeNytadmcjqQ= X-Google-Smtp-Source: AGHT+IEjMqibcqyAWYdN8rprIPTaemu6Y4i4SjkitUo13M46iNbSqRloJNVIv6wjqeae53PAfMDcFQ== X-Received: by 2002:a05:6871:1c5:b0:1d5:a58d:1317 with SMTP id q5-20020a05687101c500b001d5a58d1317mr15280503oad.10.1698220825247; Wed, 25 Oct 2023 01:00:25 -0700 (PDT) Received: from n37-019-243.byted.org ([180.184.51.40]) by smtp.gmail.com with ESMTPSA id 23-20020a630f57000000b0059cc2f1b7basm8118187pgp.11.2023.10.25.01.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 01:00:25 -0700 (PDT) From: Chuyi Zhou To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, Chuyi Zhou Subject: [PATCH bpf-next v3 3/3] selftests/bpf: Add test for using css_task iter in sleepable progs Date: Wed, 25 Oct 2023 15:59:14 +0800 Message-Id: <20231025075914.30979-4-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231025075914.30979-1-zhouchuyi@bytedance.com> References: <20231025075914.30979-1-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This Patch add a test to prove css_task iter can be used in normal sleepable progs. Signed-off-by: Chuyi Zhou --- .../selftests/bpf/progs/iters_task_failure.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/iters_task_failure.c b/tools/testing/selftests/bpf/progs/iters_task_failure.c index 6b1588d70652..fe0b19e545d0 100644 --- a/tools/testing/selftests/bpf/progs/iters_task_failure.c +++ b/tools/testing/selftests/bpf/progs/iters_task_failure.c @@ -103,3 +103,22 @@ int BPF_PROG(iter_css_task_for_each) bpf_cgroup_release(cgrp); return 0; } + +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") +int BPF_PROG(iter_css_task_for_each_sleep) +{ + u64 cg_id = bpf_get_current_cgroup_id(); + struct cgroup *cgrp = bpf_cgroup_from_id(cg_id); + struct cgroup_subsys_state *css; + struct task_struct *task; + + if (cgrp == NULL) + return 0; + css = &cgrp->self; + + bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) { + + } + bpf_cgroup_release(cgrp); + return 0; +}