Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp114507iob; Tue, 17 May 2022 20:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJWz7E8mOaiuQe0heQBNE0rOZGCe/yhOJ2k2bCocPwTNwL8JS/ss5ibxudszA8I4oBkKpG X-Received: by 2002:a62:e710:0:b0:518:2a84:7d85 with SMTP id s16-20020a62e710000000b005182a847d85mr980102pfh.38.1652845336258; Tue, 17 May 2022 20:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845336; cv=none; d=google.com; s=arc-20160816; b=CF3qmdz+P9TM86QUSv96qExLQJQsy5S4iSU7bXsAM9LGlHVIVzsxJLoqkXW1VK8IP0 NHsSydZBV7tyOEWKsHup8m+uiHsNlUFr462YN4AaOk6w7xWZlyFaXS/Vdhj7L6MJ7Akl rE9NxVGrg3tW4jyWCE7l6wMK20BKfwEPfLrVLzyupWAQEoJt/qPyh19RCkKWujhbkGfP gnXNLQNjSyuXNouBPwmZBOMuiD82Lhis04wrb8obRzowtaF3mcmHY3qU+PcYVUT2Hifk kdPraveFuIxcJq2S4SJc/DcwsMI2s49RCVs1vZ+6n1nqva3W4dI1SUCg+LGH80Zb7yHl 4peA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aMzWkBZQL9aXbZvmMQEZqAkqSC2fGMMdXYlck3K8ttk=; b=VX2p5HqkbepXM9eiK8XNOfX+0rZeiKwKkOzyIzuTc7u3oiV1BR1SjqB47AMomAxvTw irLV0ULQoU0kDU5KdURDCZDLs/azzAsAo3rCoQw+k55x+Ld6ckhJkvQ82c1zsHyg2lzr 7lt5tl4S3+REyEbEDa8U9blpj8tfaCnFtOV8uEFNVem3C/y5wYO9QAQr5KssePBQWDU0 3srL036e+Ip9KA+L/BQb8kpYbsJlDGFWm07FalAvl343Nsi/zSAl5n8zmGD3qty/tRnS gE7sdYoAIKsUhZ3p7jSedks2OKTsIVrkahwdPz5a87RDqQYPRkwJgET9SVCSAOE1VEKw HBbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lRZ5Gxxx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id b16-20020a056a000a9000b004fa5a66305esi1852587pfl.36.2022.05.17.20.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:42:16 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lRZ5Gxxx; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 921437A479; Tue, 17 May 2022 20:29:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiEQVwc (ORCPT + 99 others); Tue, 17 May 2022 17:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiEQVw2 (ORCPT ); Tue, 17 May 2022 17:52:28 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20BAF4CD75 for ; Tue, 17 May 2022 14:52:27 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id f2so178055wrc.0 for ; Tue, 17 May 2022 14:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aMzWkBZQL9aXbZvmMQEZqAkqSC2fGMMdXYlck3K8ttk=; b=lRZ5GxxxrkWxHuTV9nhyvyTmdpz78TOI1zQA1xl82f7kTLOB3C3gakvuMQbXDJXl2J fogZI6IRq2L0TyIBR/A2xVS650k799Zw2lpmLrIq6BDVqOgi8hE7V6afS8zj/ASXKIML hBwLR1q4KHyqWqK02TMxkkTUfiMmnIqO/KZQUBnZY7i4cpePrAZ7IcaqWfDjdYjhsEuv CETs/qZ6oMbCJA3bXYsZ1e739HI5xqLkrgtNhwmuDCLZtqFcXquVY4QfqTGpKwF+W/p1 5Nqm7UL1nc1wjchOez5kkQqqyoXFBp6pKjpGucj3YGrBFFJ489gN2zLQOxiFk0KMwXRv IEIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aMzWkBZQL9aXbZvmMQEZqAkqSC2fGMMdXYlck3K8ttk=; b=SQPpB13D+P1Hebk4stI6jffMCIl8ndl1UuP0AcJuj3AP7sbAzg4ECmKFcQ4f+2TV7e 9ACfuX094SYstWr9lC8Se6yBJDStTKUXtEKkafNJH8y13ABq80h/LSiqL3e3L88aqw8i SR4O1riwRYL8gfVukw2qG98PEFVQPRgaIBzC3xH9EA9emcygTSf5N0x+HvEfG17poxe+ o9uJxawrJ9AkfmFDZjxjvIbaNbqg1R1d+8YGLn3jA1zE6PKCKD0zPpz9vAzqm6BwhPSj RBhztXtB/piqKYYieVYLrRPpIIOgU+OlBBoiyq+I0mEkTBob/pSeAG3f3l0RyQo1BzGn w+Yg== X-Gm-Message-State: AOAM532xKG/kwQK6SkiI5Bh2zjpQuwcQbYl/d1T0MtczJEaBcGKLPHPX E51bk++rCpbSeHElCdCVJlyfwLmxbtZ9SNQzV1WpdiCfQe+tFw== X-Received: by 2002:adf:fb05:0:b0:20a:e113:8f3f with SMTP id c5-20020adffb05000000b0020ae1138f3fmr20501121wrr.534.1652824345517; Tue, 17 May 2022 14:52:25 -0700 (PDT) MIME-Version: 1.0 References: <20220515023504.1823463-1-yosryahmed@google.com> <20220515023504.1823463-3-yosryahmed@google.com> <20220517020840.vyfp5cit66fs2k2o@MBP-98dd607d3435.dhcp.thefacebook.com> In-Reply-To: <20220517020840.vyfp5cit66fs2k2o@MBP-98dd607d3435.dhcp.thefacebook.com> From: Yosry Ahmed Date: Tue, 17 May 2022 14:51:49 -0700 Message-ID: Subject: Re: [RFC PATCH bpf-next v2 2/7] cgroup: bpf: flush bpf stats on rstat flush To: Alexei Starovoitov Cc: 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 , Stanislav Fomichev , David Rientjes , Greg Thelen , Shakeel Butt , Linux Kernel Mailing List , Networking , bpf , cgroups@vger.kernel.org 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 On Mon, May 16, 2022 at 7:08 PM Alexei Starovoitov wrote: > > On Sun, May 15, 2022 at 02:34:59AM +0000, Yosry Ahmed wrote: > > + > > +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); > > Please use the following approach instead: > > __weak noinline void bpf_rstat_flush(struct cgroup *cgrp, struct cgroup *parent, int cpu) > { > } > > and change above line to: > bpf_rstat_flush(pos, cgroup_parent(pos), cpu); > > Then tracing bpf fentry progs will be able to attach to bpf_rstat_flush. > Pretty much the patches 1, 2, 3 are not necessary. > In patch 4 add bpf_cgroup_rstat_updated/flush as two kfuncs instead of stable helpers. > > This way patches 1,2,3,4 will become 2 trivial patches and we will be > able to extend the interface between cgroup rstat and bpf whenever we need > without worrying about uapi stability. > > We had similar discusison with HID subsystem that plans to use bpf in HID > with the same approach. > See this patch set: > https://lore.kernel.org/bpf/20220421140740.459558-2-benjamin.tissoires@redhat.com/ > You'd need patch 1 from it to enable kfuncs for tracing. > > Your patch 5 is needed as-is. > Yonghong, > please review it. > Different approach for patch 1-4 won't affect patch 5. > Patches 6 and 7 look good. > > With this approach that patch 7 will mostly stay as-is. Instead of: > +SEC("rstat/flush") > +int vmscan_flush(struct bpf_rstat_flush_ctx *ctx) > +{ > + struct vmscan_percpu *pcpu_stat; > + struct vmscan *total_stat, *parent_stat; > + struct cgroup *cgrp = ctx->cgrp, *parent = ctx->parent; > > it will become > > SEC("fentry/bpf_rstat_flush") > int BPF_PROG(vmscan_flush, struct cgroup *cgrp, struct cgroup *parent, int cpu) Thanks so much for taking the time to look into this. Indeed, this approach looks cleaner and simpler. I will incorporate that into a V1 and send it. Thanks!