Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2285059iob; Sun, 15 May 2022 13:46:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmMEwxUqkLJjvwNV1OA3PLmpQ0Z3Lp8PTJSztwUqt2hB6McCsJaZvVdMlKl8Z4YxMtmO+F X-Received: by 2002:a05:6000:2cf:b0:20c:58de:18c4 with SMTP id o15-20020a05600002cf00b0020c58de18c4mr11448855wry.530.1652647576392; Sun, 15 May 2022 13:46:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652647576; cv=none; d=google.com; s=arc-20160816; b=0TjuIJOXn/Sqb/PDFIs+BUDVWuvv85+2yKUYN/w0uiWhhHj9FUAXYmGnG6VPxl9Hev ofHD8BCrJCtVPiRdD+3aRBVTCy0AAQWK7OMODj0Px6t0ZaF3tTaQNq4Abbbs6uy2gGPE XdN5KLBilqew6XHAi19IpHe7uOjn4rwhtcA0toxis6pIL6yh4oIG5JHlHuZejMGrsnA9 yrT9TyNOd2XqD4eKh4xwYXUZumzX7WFwiWgz+zCpmxMwovwZmNEDz8mBbvYgYZ/exrM+ WoZnYQOYw0y9bbxmdYDha8gf0lHvQhEe+Z36gXWUwNMxLwFEiTH8s+haC+m3I04uRluS VwQQ== 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=EUwJph95+QtgVEYpOk4h8MUmP3EN23IIGoIBGE07ovI=; b=T7aN2pYtg0QUhQt0TcIzJCLX+eqh88rOdYaT4x1GzAMaGJfDVXWDhnsA9nFV2dPCay NW+G+yDy3Snfs2XFp5k31NQHUQjx06VVQpwgHrokedhjReFekCQhHsiY0Oy+Y5+q7DiF eJh3yvxs/I5fc1EkeeXA8CjEeQYHfE87oEXw5M5yZ7eujeQ5yge4QO+R78b/6ZvVMM1E yZzl923DlVFbBKxl8b2/b0uEr9kHP1+ShrgHiCeOeGNkyxz6IUozspH71i6g3QKx/n0p doa/PgRhwYfNbhl0O+zEVfNBUE4bxqpvugjKofbLQV1ZFzpIoGQTpntblJjKqOae9zV1 +RKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PDZGlc0Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020adfda49000000b00207a4d881a4si7836150wrl.349.2022.05.15.13.45.49; Sun, 15 May 2022 13:46:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PDZGlc0Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233878AbiEOCfl (ORCPT + 99 others); Sat, 14 May 2022 22:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233800AbiEOCfR (ORCPT ); Sat, 14 May 2022 22:35:17 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD226BF44 for ; Sat, 14 May 2022 19:35:15 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id h128-20020a636c86000000b003c574b3422aso5673542pgc.12 for ; Sat, 14 May 2022 19:35:15 -0700 (PDT) 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=EUwJph95+QtgVEYpOk4h8MUmP3EN23IIGoIBGE07ovI=; b=PDZGlc0QzpODkc7dmkDeYxiYCZPbcORZBrrzUTn6k3D3SZY7PbQm0ZXd2IW+sOUcbS Xo/fMyFUqZ1MfPE7KjvD1HFOoKFRkYUHKAVvf1VIFlKP8N7bWGPWYWNRzEnXgpO2PIDH 808VikSXzNhMH2ZaMUaHgFvbK6M6E+3CmGXWQ/tFRAUGdnThnx5OCM8tB0SDrpb5/K4M x0t6mUWNAKdmuRFlk6RTn9mfd5kqItz7GI+N7IBtsJPOKuErr9wiCmXd9ZHUnDVq8d/+ QwUnKS3979H8Oq+Ejg40FwzfS7cnE1rESwD7zLfGGgUTKx3KVKQ81Nou3l0sEKcUR/hP jJBA== 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=EUwJph95+QtgVEYpOk4h8MUmP3EN23IIGoIBGE07ovI=; b=PWBTH1N0RrLr29p0oJLp2qgVfyu3URx790RDcILwonWtPB8UqQHo8rn7OwyFYn31bO Cizjhgw53wIla79cTjp6+nulnPIMM4urn5Oh+8BZpVCaK1d3N4/kvn2vy9EATuXBoRnf j/RGbPKLww1+nrOCUT3rjKZzW6ptrVN4ahrRc1fPohjPd/gbpS8JP31p2WcYiag/dpRb m4mwkgcbvXUDnwq8FNapMXREO8+eXcqKeVmY1CZrPHnJ9rVr4nVdADv1KY3CMB0qhT7h GWXIRu4uZhMc39CBVfkb9Mj8s7rj/BduzUpUuPon2X+c4rNhMotWDUGaljELF1g5PgwT OHJQ== X-Gm-Message-State: AOAM5325CirmbZgdRq8SxF7vu5gLj794B3Jaa4g2SmFvTNFHnBS1v9Su vcehf9t5MM/PO+e1MeLQ+AslahGE3sp/wKD/ X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:903:2348:b0:15f:2b4a:29c2 with SMTP id c8-20020a170903234800b0015f2b4a29c2mr11740589plh.37.1652582115174; Sat, 14 May 2022 19:35:15 -0700 (PDT) Date: Sun, 15 May 2022 02:34:59 +0000 In-Reply-To: <20220515023504.1823463-1-yosryahmed@google.com> Message-Id: <20220515023504.1823463-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220515023504.1823463-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [RFC PATCH bpf-next v2 2/7] cgroup: bpf: flush bpf stats on rstat flush From: Yosry Ahmed To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Roman Gushchin , Michal Hocko Cc: Stanislav Fomichev , David Rientjes , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, Yosry Ahmed Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 When an rstat flush is ongoing for a cgroup, also flush bpf stats by running any attached rstat flush programs. Signed-off-by: Yosry Ahmed --- include/linux/bpf-rstat.h | 6 ++++++ kernel/bpf/rstat.c | 21 +++++++++++++++++++++ kernel/cgroup/rstat.c | 2 ++ 3 files changed, 29 insertions(+) diff --git a/include/linux/bpf-rstat.h b/include/linux/bpf-rstat.h index 23cad23b5fc2..55e000fe0f47 100644 --- a/include/linux/bpf-rstat.h +++ b/include/linux/bpf-rstat.h @@ -12,6 +12,8 @@ int bpf_rstat_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); +void bpf_rstat_flush(struct cgroup *cgrp, int cpu); + #else /* defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_CGROUPS) */ static inline int bpf_rstat_link_attach(const union bpf_attr *attr, @@ -20,6 +22,10 @@ static inline int bpf_rstat_link_attach(const union bpf_attr *attr, return -ENOTSUPP; } +static inline void bpf_rstat_flush(struct cgroup *cgrp, int cpu) +{ +} + #endif /* defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_CGROUPS) */ #endif /* _BPF_RSTAT */ diff --git a/kernel/bpf/rstat.c b/kernel/bpf/rstat.c index 5f529002d4b9..e96bc080f4b9 100644 --- a/kernel/bpf/rstat.c +++ b/kernel/bpf/rstat.c @@ -164,3 +164,24 @@ int bpf_rstat_link_attach(const union bpf_attr *attr, return bpf_link_settle(&link_primer); } + +void bpf_rstat_flush(struct cgroup *cgrp, int cpu) +{ + struct bpf_rstat_flusher *flusher; + struct bpf_rstat_flush_ctx ctx = { + .cgrp = cgrp, + .parent = cgroup_parent(cgrp), + .cpu = cpu, + }; + + rcu_read_lock(); + migrate_disable(); + spin_lock(&bpf_rstat_flushers_lock); + + list_for_each_entry(flusher, &bpf_rstat_flushers, list) + (void) bpf_prog_run(flusher->prog, &ctx); + + spin_unlock(&bpf_rstat_flushers_lock); + migrate_enable(); + rcu_read_unlock(); +} diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 24b5c2ab5598..0285d496e807 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -2,6 +2,7 @@ #include "cgroup-internal.h" #include +#include static DEFINE_SPINLOCK(cgroup_rstat_lock); static DEFINE_PER_CPU(raw_spinlock_t, cgroup_rstat_cpu_lock); @@ -168,6 +169,7 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp, bool may_sleep) struct cgroup_subsys_state *css; cgroup_base_stat_flush(pos, cpu); + bpf_rstat_flush(pos, cpu); rcu_read_lock(); list_for_each_entry_rcu(css, &pos->rstat_css_list, -- 2.36.0.550.gb090851708-goog