From: Martin KaFai Lau <kafai@fb.com>
To: Song Liu <song@kernel.org>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
David Miller <davem@davemloft.net>,
Kernel Team <kernel-team@fb.com>,
Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf-next 4/4] bpf: inet_diag: Dump bpf_sk_storages in inet_diag_dump()
Date: Tue, 25 Feb 2020 09:08:24 -0800 [thread overview]
Message-ID: <20200225170824.dhwkw2ojzsfz223k@kafai-mbp> (raw)
In-Reply-To: <CAPhsuW4BuGQP8+QGG+E9A+n=8DV0Gg=UmWzeScrbFxBp7O_ojw@mail.gmail.com>
On Mon, Feb 24, 2020 at 09:47:33PM -0800, Song Liu wrote:
> On Fri, Feb 21, 2020 at 10:49 AM Martin KaFai Lau <kafai@fb.com> wrote:
> >
> > This patch will dump out the bpf_sk_storages of a sk
> > if the request has the INET_DIAG_REQ_SK_BPF_STORAGES nlattr.
> >
> > An array of SK_DIAG_BPF_STORAGE_REQ_MAP_FD can be specified in
> > INET_DIAG_REQ_SK_BPF_STORAGES to select which bpf_sk_storage to dump.
> > If no map_fd is specified, all bpf_sk_storages of a sk will be dumped.
> [...]
>
> > Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> > ---
> > include/linux/inet_diag.h | 4 ++
> > include/linux/netlink.h | 4 +-
> > include/uapi/linux/inet_diag.h | 2 +
> > net/ipv4/inet_diag.c | 71 ++++++++++++++++++++++++++++++++++
> > 4 files changed, 79 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
> > index 1bb94cac265f..e4ba25d63913 100644
> > --- a/include/linux/inet_diag.h
> > +++ b/include/linux/inet_diag.h
> > @@ -38,9 +38,13 @@ struct inet_diag_handler {
> > __u16 idiag_info_size;
> > };
> >
> > +struct bpf_sk_storage_diag;
> > struct inet_diag_dump_data {
> > struct nlattr *req_nlas[__INET_DIAG_REQ_MAX];
> > #define inet_diag_nla_bc req_nlas[INET_DIAG_REQ_BYTECODE]
> > +#define inet_diag_nla_bpf_stgs req_nlas[INET_DIAG_REQ_SK_BPF_STORAGES]
> > +
> > + struct bpf_sk_storage_diag *bpf_stg_diag;
> > };
> >
> > struct inet_connection_sock;
> > diff --git a/include/linux/netlink.h b/include/linux/netlink.h
> > index 205fa7b1f07a..788969ccbbde 100644
> > --- a/include/linux/netlink.h
> > +++ b/include/linux/netlink.h
> > @@ -188,10 +188,10 @@ struct netlink_callback {
> > struct module *module;
> > struct netlink_ext_ack *extack;
> > u16 family;
> > - u16 min_dump_alloc;
> > - bool strict_check;
> > u16 answer_flags;
> > + u32 min_dump_alloc;
>
> Maybe highlight this change in the commit log?
ok.
>
> > unsigned int prev_seq, seq;
> > + bool strict_check;
> > union {
> > u8 ctx[48];
> >
[ ... ]
> > diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
> > index 4bce8a477699..8ca4d54d7c5a 100644
[ ... ]
> > @@ -1022,8 +1069,11 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
> > const struct inet_diag_req_v2 *r)
> > {
> > const struct inet_diag_handler *handler;
> > + u32 prev_min_dump_alloc;
> > int err = 0;
> >
> > +again:
> > + prev_min_dump_alloc = cb->min_dump_alloc;
> > handler = inet_diag_lock_handler(r->sdiag_protocol);
> > if (!IS_ERR(handler))
> > handler->dump(skb, cb, r);
> > @@ -1031,6 +1081,12 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
> > err = PTR_ERR(handler);
> > inet_diag_unlock_handler(handler);
> >
> > + if (!skb->len && cb->min_dump_alloc > prev_min_dump_alloc) {
>
> Why do we check for !skb->len here?
skb contains the info of sk(s) to be dumped to the userspace.
It may contain no sk info (i.e. !skb->len), 1 sk info, 2 sk info...etc.
It only retries if there is no sk info and the cb->min_dump_alloc becomes
larger (together, it means the current skb is not large enough to fit one
sk info).
>
> > + err = pskb_expand_head(skb, 0, cb->min_dump_alloc, GFP_KERNEL);
> > + if (!err)
> > + goto again;
> > + }
> > +
> > return err ? : skb->len;
> > }
> >
next prev parent reply other threads:[~2020-02-25 17:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-21 18:46 [PATCH bpf-next 0/4] Provide bpf_sk_storage data in INET_DIAG Martin KaFai Lau
2020-02-21 18:46 ` [PATCH bpf-next 1/4] inet_diag: Refactor inet_sk_diag_fill(), dump(), and dump_one() Martin KaFai Lau
2020-02-25 0:12 ` Song Liu
2020-02-21 18:47 ` [PATCH bpf-next 2/4] inet_diag: Move the INET_DIAG_REQ_BYTECODE nlattr to cb->data Martin KaFai Lau
2020-02-25 0:37 ` Song Liu
2020-02-21 18:47 ` [PATCH bpf-next 3/4] bpf: INET_DIAG support in bpf_sk_storage Martin KaFai Lau
2020-02-25 5:23 ` Song Liu
2020-02-21 18:47 ` [PATCH bpf-next 4/4] bpf: inet_diag: Dump bpf_sk_storages in inet_diag_dump() Martin KaFai Lau
2020-02-25 5:47 ` Song Liu
2020-02-25 17:08 ` Martin KaFai Lau [this message]
2020-02-25 17:11 ` Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200225170824.dhwkw2ojzsfz223k@kafai-mbp \
--to=kafai@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).