Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp422983oof; Mon, 24 Sep 2018 23:06:28 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Vfxfxg4ruoeMGzDsu9f3/aYWbvDAFXlz2SLeB7WDZS1NLzwqfrDBJaPykM06Su+/Q3eTK X-Received: by 2002:a17:902:a9cc:: with SMTP id b12-v6mr1913577plr.198.1537855588045; Mon, 24 Sep 2018 23:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537855588; cv=none; d=google.com; s=arc-20160816; b=tyiy8QHHV9NsRmXEMpfyLWj4mBmM2H9HkHlAwSEL/SzbN/KheA3JpgBo3K75HFAQ3d HyuhFljDu7pum3fzsfyj8f5c66qQNu5A+ppEZ6Xuz0r3V5xz4Wm2GfFPre9oBqaPVbeW akTRhHfyfbMGjRAp2gn4KE/5u//RuxWfNPNkkCdu1+Xo4XLU4B8ba9nYg/9e2poSRM/g gza/pwVl53TjEykNHWmQHOi7wzSaAnEvNB3w7FkkARBk//Q62zJ/kGQIjAtBSMjx+zvn 3y0zc/stlKvaPAt3hxh9jS3gUwsP4iTIlYIAf977aPcaRiLFTj2/SW8NpfWfvXwBIpP8 H7/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vGVBWiOEehjlGaUxSGMTAJgtuA8Ax/SjOyge4f6TSY4=; b=R8bqUNo8xknEup4eW4EPJMid1nGHMpG7RwQ/RKheTkW3tK/TlZk9qqIpkytJFUgfed Dtls5U8tMABjIBkJp4LpbaXcN1HQt5kQWEdA3fTQulVXijFb25h4PA8yvk/nSsRrmRYU rp+yEpY3dvDl4ccCH/09VBlNVeSkKVGDlZClrzyxBmXi7/t6WYhrxP1s04vrmqe0VkeG ox2QT7O55mUdK0UuWO3hv9vESkhxUx8AG2/neY/LEyuzE0bBeFe/ArUVCvIC6rt2qGrK E3AUyjbNYw82bcl3aI+QnocHKJ3nO8S2ES5X6lsjRQZZNDifUCVeteO4CWdcP1sAUebF zYoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SeiWFdu7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184-v6si1393842pgb.587.2018.09.24.23.06.12; Mon, 24 Sep 2018 23:06:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SeiWFdu7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728028AbeIYML6 (ORCPT + 99 others); Tue, 25 Sep 2018 08:11:58 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:43609 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbeIYMLz (ORCPT ); Tue, 25 Sep 2018 08:11:55 -0400 Received: by mail-qt1-f193.google.com with SMTP id l16-v6so11649585qtq.10; Mon, 24 Sep 2018 23:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vGVBWiOEehjlGaUxSGMTAJgtuA8Ax/SjOyge4f6TSY4=; b=SeiWFdu7zm9Cbm3yM/E9ua4vB/wi4zAdEfxzqBgtLzrPBGtfJabpAnMGTEUxoI8aSf fQNrukC9l0JEmVhwBjtstD/XhY+n6EAvZsGtgcypRxJzccvatiYhGl4gEO4MGMIWeTn6 27AF7magY83Y0iasoUnw9rC043xnmWZkKqjd1JJIj2hXnNasiQbN0jmQnJDxCoi8a/JB h/DJoLRxGq8MH7nLfnd9EEQu4DR8BonGzDxXtSwlQywDB62NZi6azzSjqVQr6LPZOp4t 0/IXk6j/rERSh0yJ/GJTrsIUerYY3Sqb42JR4mvNHDZDhrkrp+bYQHVCFgxT+XQGuOIk A/sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vGVBWiOEehjlGaUxSGMTAJgtuA8Ax/SjOyge4f6TSY4=; b=EsWNzUqV8O0KSJbW5cyG6OGGfDgEvq++cDg60g/kqoKr3UXcHqIFsoLHoTSmRZMwOm YaMIXHl6FswyxOsli+H1rAkA3SzT5IE6Cv4rd8TK8X+IOZkxrB9pjs/DS9Yhgb5RlvDj E0RpqVjUXATP+sdLWtz3SgexvVejuH0InwlWLI+F5zG8+LH7QWJgWO/DzSOxIXAXvCaZ IKq+C9eVmuJG75fxKxV5T5H6GasYI0Czw4rPsDBDvI8eOga1XJMa3CafQgNu0f5LqGyz N+QD8lpbNCUA8jWvlkT4zaKB51wvBaW9cx/B7SY4BS9uhzaUJGKkQ9rKN61D3XFu4tQ0 7H6Q== X-Gm-Message-State: ABuFfogIwx3OJeDFJN6Y18bUX4dmg1+YCdiBRrHbMVWFMndz8OtvWbq2 3YDqHujrpMizoUKTmkNavk2BB4+Fl91gVM/m1maFirWO X-Received: by 2002:ac8:2f01:: with SMTP id j1-v6mr1681222qta.87.1537855560063; Mon, 24 Sep 2018 23:06:00 -0700 (PDT) MIME-Version: 1.0 References: <20180921171353.11050-1-guro@fb.com> <20180921171353.11050-2-guro@fb.com> In-Reply-To: <20180921171353.11050-2-guro@fb.com> From: Song Liu Date: Mon, 24 Sep 2018 23:05:48 -0700 Message-ID: Subject: Re: [PATCH bpf-next 2/9] bpf: rework cgroup storage pointer passing To: guro@fb.com Cc: Networking , open list , Kernel-team@fb.com, Daniel Borkmann , Alexei Starovoitov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 21, 2018 at 10:16 AM Roman Gushchin wrote: > > To simplify the following introduction of per-cpu cgroup storage, > let's rework a bit a mechanism of passing a pointer to a cgroup > storage into the bpf_get_local_storage(). Let's save a pointer > to the corresponding bpf_cgroup_storage structure, instead of > a pointer to the actual buffer. > > It will help us to handle per-cpu storage later, which has > a different way of accessing to the actual data. > > Signed-off-by: Roman Gushchin > Cc: Daniel Borkmann > Cc: Alexei Starovoitov Acked-by: Song Liu > --- > include/linux/bpf-cgroup.h | 13 ++++--------- > kernel/bpf/helpers.c | 8 ++++++-- > kernel/bpf/local_storage.c | 3 ++- > 3 files changed, 12 insertions(+), 12 deletions(-) > > diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h > index e9871b012dac..7e0c9a1d48b7 100644 > --- a/include/linux/bpf-cgroup.h > +++ b/include/linux/bpf-cgroup.h > @@ -23,7 +23,8 @@ struct bpf_cgroup_storage; > extern struct static_key_false cgroup_bpf_enabled_key; > #define cgroup_bpf_enabled static_branch_unlikely(&cgroup_bpf_enabled_key) > > -DECLARE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); > +DECLARE_PER_CPU(struct bpf_cgroup_storage*, > + bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); > > #define for_each_cgroup_storage_type(stype) \ > for (stype = 0; stype < MAX_BPF_CGROUP_STORAGE_TYPE; stype++) > @@ -115,15 +116,9 @@ static inline void bpf_cgroup_storage_set(struct bpf_cgroup_storage > *storage[MAX_BPF_CGROUP_STORAGE_TYPE]) > { > enum bpf_cgroup_storage_type stype; > - struct bpf_storage_buffer *buf; > - > - for_each_cgroup_storage_type(stype) { > - if (!storage[stype]) > - continue; > > - buf = READ_ONCE(storage[stype]->buf); > - this_cpu_write(bpf_cgroup_storage[stype], &buf->data[0]); > - } > + for_each_cgroup_storage_type(stype) > + this_cpu_write(bpf_cgroup_storage[stype], storage[stype]); > } > > struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog, > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > index 9070b2ace6aa..e42f8789b7ea 100644 > --- a/kernel/bpf/helpers.c > +++ b/kernel/bpf/helpers.c > @@ -195,7 +195,8 @@ const struct bpf_func_proto bpf_get_current_cgroup_id_proto = { > }; > > #ifdef CONFIG_CGROUP_BPF > -DECLARE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); > +DECLARE_PER_CPU(struct bpf_cgroup_storage*, > + bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); > > BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) > { > @@ -204,8 +205,11 @@ BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) > * verifier checks that its value is correct. > */ > enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); > + struct bpf_cgroup_storage *storage; > > - return (unsigned long) this_cpu_read(bpf_cgroup_storage[stype]); > + storage = this_cpu_read(bpf_cgroup_storage[stype]); > + > + return (unsigned long)&READ_ONCE(storage->buf)->data[0]; > } > > const struct bpf_func_proto bpf_get_local_storage_proto = { > diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c > index 0bd9f19fc557..6742292fb39e 100644 > --- a/kernel/bpf/local_storage.c > +++ b/kernel/bpf/local_storage.c > @@ -7,7 +7,8 @@ > #include > #include > > -DEFINE_PER_CPU(void*, bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); > +DEFINE_PER_CPU(struct bpf_cgroup_storage*, > + bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); > > #ifdef CONFIG_CGROUP_BPF > > -- > 2.17.1 >