Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp730294pxm; Fri, 25 Feb 2022 18:33:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJywmCEz7bkCqdpKkMSlYVbEQ752gqhJR4tFhxrAYMq9h7/Rksd1ZtkxosOoLmkIQimgM38X X-Received: by 2002:a05:6a00:1810:b0:4e1:2d4f:14aa with SMTP id y16-20020a056a00181000b004e12d4f14aamr10762325pfa.43.1645842807191; Fri, 25 Feb 2022 18:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645842807; cv=none; d=google.com; s=arc-20160816; b=qhN6vdqp1Cv9+xIxIb2NKx+XZTQ7rTQjNXNQON3qIM4sxVnBdowFT45hAGwFDayVgB uHFMTggGNOd6D8yL7ynJNIqOxQUePTJQPeXgCzR0wf72L8O8bNq9vNy9Y/29X6H58euf tgjGegYdjnxUNy7WbgISGOMf2hkxQLApVV7UGRoOCWKnhSi5CAlWK2LiXrFkpZvoeBSN kvzaowk9IWXxM6jQSixTMHgdDWVGD3GAVj9Hv9D8Ys+PseltMj/U2XZ2T2ouUUfo9xEI gtqKmNwLYrTsa+G+0N1FIWXcEjlCQIN3F76mC/oZdEuTytgoU1i2lbcVAUGF4GyXigsi LiBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=zSQ3ZyUQ2OEfiGKk7osb66v16UBXeasV5LfSlDNJLTs=; b=m1uITvFP6s8rSbXjlWF7YYgMxmwl2NMvI/DXRjlWfVOvqsfUef7f1XuwYHRL4pehgB oadJJR1uka2XD8bOg/o00b5ahQcl9q8Igx9Re40k/W1aCMUzhzfqA9wYymhK5TsDf8/j rBM2uC/CegcR5fHvqVlFb8Eheec4WW/aXxyr7x2LNIyX8sZmVHfpXLNnzaO0cPRlCR67 JPFyhu7Mxu//tywh5JLoMZqA2U5JZmde9r7oUXLtIz02royVQmh4H3L4SKeiDxO61HW2 NlFdooH8kwT9nk7kg/DLdWWZQBRHlkIuRfwsViMzYnynht9jtJXehiQPzLowJ7qLXMoJ aVPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RAWcMz9S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m14-20020a17090a5a4e00b001bc8d7b15e7si3467204pji.166.2022.02.25.18.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:33:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RAWcMz9S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 728DC2EFA3C; Fri, 25 Feb 2022 17:59:50 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239595AbiBYXok (ORCPT + 99 others); Fri, 25 Feb 2022 18:44:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239510AbiBYXo3 (ORCPT ); Fri, 25 Feb 2022 18:44:29 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4517F1A270D for ; Fri, 25 Feb 2022 15:43:56 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id b18-20020a25fa12000000b0062412a8200eso4857681ybe.22 for ; Fri, 25 Feb 2022 15:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zSQ3ZyUQ2OEfiGKk7osb66v16UBXeasV5LfSlDNJLTs=; b=RAWcMz9SCO9AYZ5Pdggqlu3RxuyFkY6L5ZYVTbuszydG5Wij7F33XdUpXekqDNvgDb BbWbrze1Z2q5JkRVH/Mrso+MKEvpttminKC8Jc8Xr9EZ4/5mI1+WvY6YbaYulqScKQ9j 1YLBQR1mMvdAHHfUlaqPu3ftcgq2VlgRWG5Q/GgUJKgBwYQa4yvPUYeZOCtdTy2Z88cI 1OgIKH+ZbEIKHOz5hZX4svpyPB4h86ryzdTGE/bvN1dTBn28bElnZWfe4IDGdFs5di39 4PGMTjYksntvmqRVXi+U2b/LGkRjGmblq9KBt6ylJxGB+j711I9tATWezK3+pr2Z+60A c6Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zSQ3ZyUQ2OEfiGKk7osb66v16UBXeasV5LfSlDNJLTs=; b=guTZ8k35N40p3vTQZ0exh8QbZsdcVOJt553v1iFUGZiM6fS6kiVPlGdqQCAf2xhk2e hV7fpMpV95qtfzukFw7dsZjI6ZgosajrmmY6/plH5zMZrtI4N4XvPxeOvg0B7fNmobMh jU+jzu8wSTUwhtlzZcrwgI0IuFipSVw/K3qoW8UVPpi3qqFjpDjkDDdv6uTQcZRD1Vio vfC3+xhGtm6vHdpYtSICIPLAtE2SJCUQIBPur/ZQGqDRS+VhXS3kLjOaMs45COCzz/SQ j2cAOAL5TlsT5olKcKKkzO8944oDm8JiZzH24d6S1gEVyBk9/32MiTnLclqbJLtWeba1 qMig== X-Gm-Message-State: AOAM531QVR7pQT6EZgqcGQeUXpjL4AcGa2U7bGJ041ry4zGd3G5nPb9v VGqgGzhDuCCsxKcEYSW2VlC77/yM5hk= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:378d:645d:49ad:4f8b]) (user=haoluo job=sendgmr) by 2002:a25:c5d0:0:b0:624:41d4:e37c with SMTP id v199-20020a25c5d0000000b0062441d4e37cmr9499906ybe.318.1645832635508; Fri, 25 Feb 2022 15:43:55 -0800 (PST) Date: Fri, 25 Feb 2022 15:43:35 -0800 In-Reply-To: <20220225234339.2386398-1-haoluo@google.com> Message-Id: <20220225234339.2386398-6-haoluo@google.com> Mime-Version: 1.0 References: <20220225234339.2386398-1-haoluo@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH bpf-next v1 5/9] cgroup: Sleepable cgroup tracepoints. From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Shakeel Butt , Joe Burton , Tejun Heo , joshdon@google.com, sdf@google.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Hao Luo Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add two new sleepable tracepoints in cgroup: cgroup_mkdir_s and cgroup_rmdir_s. The suffix _s means they are in a sleepable context. These two tracepoints don't need full cgroup paths, they don't have to live in atomic context. These two tracepoints are also called without holding cgroup_mutex. They can be used for bpf to monitor cgroup creation and deletion. Bpf sleepable programs can attach to these two tracepoints and create corresponding directories in bpffs. The created directories don't need the cgroup paths, cgroup id is sufficient to identify the cgroup. Once the bpffs directories have been created, the bpf prog can further pin bpf objects inside the directories and allow users to read the pinned objects. This serves a way to extend the fixed cgroup interface. Cc: Tejun Heo Signed-off-by: Hao Luo --- include/trace/events/cgroup.h | 45 +++++++++++++++++++++++++++++++++++ kernel/cgroup/cgroup.c | 5 ++++ 2 files changed, 50 insertions(+) diff --git a/include/trace/events/cgroup.h b/include/trace/events/cgroup.h index dd7d7c9efecd..4483a7d6c43a 100644 --- a/include/trace/events/cgroup.h +++ b/include/trace/events/cgroup.h @@ -204,6 +204,51 @@ DEFINE_EVENT(cgroup_event, cgroup_notify_frozen, TP_ARGS(cgrp, path, val) ); +/* + * The following tracepoints are supposed to be called in a sleepable context. + */ +DECLARE_EVENT_CLASS(cgroup_sleepable_tp, + + TP_PROTO(struct cgroup *cgrp), + + TP_ARGS(cgrp), + + TP_STRUCT__entry( + __field( int, root ) + __field( int, level ) + __field( u64, id ) + ), + + TP_fast_assign( + __entry->root = cgrp->root->hierarchy_id; + __entry->id = cgroup_id(cgrp); + __entry->level = cgrp->level; + ), + + TP_printk("root=%d id=%llu level=%d", + __entry->root, __entry->id, __entry->level) +); + +#ifdef DEFINE_EVENT_SLEEPABLE +#undef DEFINE_EVENT +#define DEFINE_EVENT(template, call, proto, args) \ + DEFINE_EVENT_SLEEPABLE(template, call, PARAMS(proto), PARAMS(args)) +#endif + +DEFINE_EVENT(cgroup_sleepable_tp, cgroup_mkdir_s, + + TP_PROTO(struct cgroup *cgrp), + + TP_ARGS(cgrp) +); + +DEFINE_EVENT(cgroup_sleepable_tp, cgroup_rmdir_s, + + TP_PROTO(struct cgroup *cgrp), + + TP_ARGS(cgrp) +); + #endif /* _TRACE_CGROUP_H */ /* This part must be outside protection */ diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 9d05c3ca2d5e..f14ab00d9ef5 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5535,6 +5535,8 @@ int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode) cgroup_destroy_locked(cgrp); out_unlock: cgroup_kn_unlock(parent_kn); + if (!ret) + trace_cgroup_mkdir_s(cgrp); return ret; } @@ -5725,6 +5727,9 @@ int cgroup_rmdir(struct kernfs_node *kn) TRACE_CGROUP_PATH(rmdir, cgrp); cgroup_kn_unlock(kn); + + if (!ret) + trace_cgroup_rmdir_s(cgrp); return ret; } -- 2.35.1.574.g5d30c73bfb-goog