From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, davem@davemloft.net,
kuba@kernel.org, hawk@kernel.org, pabeni@redhat.com,
edumazet@google.com, toke@redhat.com, memxor@gmail.com,
alardam@gmail.com, saeedm@nvidia.com, anthony.l.nguyen@intel.com,
gospo@broadcom.com, vladimir.oltean@nxp.com, nbd@nbd.name,
john@phrozen.org, leon@kernel.org, simon.horman@corigine.com,
aelior@marvell.com, christophe.jaillet@wanadoo.fr,
ecree.xilinx@gmail.com, mst@redhat.com, bjorn@kernel.org,
magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
intel-wired-lan@lists.osuosl.org, lorenzo.bianconi@redhat.com,
martin.lau@linux.dev
Subject: Re: [PATCH v3 bpf-next 5/8] libbpf: add API to get XDP/XSK supported features
Date: Sat, 28 Jan 2023 13:48:43 +0100 [thread overview]
Message-ID: <Y9UZqxwNPDQ9jEu3@lore-desk> (raw)
In-Reply-To: <CAEf4BzYjt3J5_ESMKjRFRh6ROg-CN=QazAZpKd9wnaSxjjKbAg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4641 bytes --]
> On Thu, Jan 26, 2023 at 4:59 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >
> > Extend bpf_xdp_query routine in order to get XDP/XSK supported features
> > of netdev over route netlink interface.
> > Extend libbpf netlink implementation in order to support netlink_generic
> > protocol.
> >
> > Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> > Co-developed-by: Marek Majtyka <alardam@gmail.com>
> > Signed-off-by: Marek Majtyka <alardam@gmail.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> > tools/lib/bpf/libbpf.h | 3 +-
> > tools/lib/bpf/netlink.c | 99 +++++++++++++++++++++++++++++++++++++++++
> > tools/lib/bpf/nlattr.h | 12 +++++
> > 3 files changed, 113 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index 898db26e42e9..29cb7040fa77 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -982,9 +982,10 @@ struct bpf_xdp_query_opts {
> > __u32 hw_prog_id; /* output */
> > __u32 skb_prog_id; /* output */
> > __u8 attach_mode; /* output */
> > + __u64 fflags; /* output */
> > size_t :0;
> > };
> > -#define bpf_xdp_query_opts__last_field attach_mode
> > +#define bpf_xdp_query_opts__last_field fflags
>
> is "fflags" an obvious name in this context? I'd expect
> "feature_flags", especially that there are already "flags". Is saving
> a few characters worth the confusion?
ack, I will fix it.
>
>
> >
> > LIBBPF_API int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags,
> > const struct bpf_xdp_attach_opts *opts);
> > diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
> > index d2468a04a6c3..674e4d61e67e 100644
> > --- a/tools/lib/bpf/netlink.c
> > +++ b/tools/lib/bpf/netlink.c
> > @@ -9,6 +9,7 @@
> > #include <linux/if_ether.h>
> > #include <linux/pkt_cls.h>
> > #include <linux/rtnetlink.h>
> > +#include <linux/netdev.h>
> > #include <sys/socket.h>
> > #include <errno.h>
> > #include <time.h>
> > @@ -39,6 +40,12 @@ struct xdp_id_md {
> > int ifindex;
> > __u32 flags;
> > struct xdp_link_info info;
> > + __u64 fflags;
> > +};
> > +
> > +struct xdp_features_md {
> > + int ifindex;
> > + __u64 flags;
> > };
> >
> > static int libbpf_netlink_open(__u32 *nl_pid, int proto)
>
> [...]
>
> > int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)
> > {
> > struct libbpf_nla_req req = {
> > @@ -393,6 +460,38 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)
> > OPTS_SET(opts, skb_prog_id, xdp_id.info.skb_prog_id);
> > OPTS_SET(opts, attach_mode, xdp_id.info.attach_mode);
> >
> > + if (OPTS_HAS(opts, fflags)) {
>
> maybe invert condition, return early, reduce nesting of the following code?
ack, fine, I will fix it.
>
> > + struct xdp_features_md md = {
> > + .ifindex = ifindex,
> > + };
> > + __u16 id;
> > +
> > + err = libbpf_netlink_resolve_genl_family_id("netdev",
> > + sizeof("netdev"),
> > + &id);
>
> nit: if it fits under 100 characters, let's leave it on a single line
ack, fine, I will fix it (I am still used to 79 char limits :))
Regards,
Lorenzo
>
> > + if (err < 0)
> > + return libbpf_err(err);
> > +
> > + memset(&req, 0, sizeof(req));
> > + req.nh.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
> > + req.nh.nlmsg_flags = NLM_F_REQUEST;
> > + req.nh.nlmsg_type = id;
> > + req.gnl.cmd = NETDEV_CMD_DEV_GET;
> > + req.gnl.version = 2;
> > +
> > + err = nlattr_add(&req, NETDEV_A_DEV_IFINDEX, &ifindex,
> > + sizeof(ifindex));
> > + if (err < 0)
> > + return err;
> > +
> > + err = libbpf_netlink_send_recv(&req, NETLINK_GENERIC,
> > + parse_xdp_features, NULL, &md);
> > + if (err)
> > + return libbpf_err(err);
> > +
> > + opts->fflags = md.flags;
> > + }
> > +
> > return 0;
> > }
> >
>
> [...]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2023-01-28 12:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 12:58 [PATCH v3 bpf-next 0/8] xdp: introduce xdp-feature support Lorenzo Bianconi
2023-01-26 12:58 ` [PATCH v3 bpf-next 1/8] netdev-genl: create a simple family for netdev stuff Lorenzo Bianconi
2023-01-26 12:58 ` [PATCH v3 bpf-next 2/8] drivers: net: turn on XDP features Lorenzo Bianconi
2023-01-26 18:27 ` sdf
2023-01-26 12:58 ` [PATCH v3 bpf-next 3/8] xsk: add usage of XDP features flags Lorenzo Bianconi
2023-01-26 12:58 ` [PATCH v3 bpf-next 4/8] libbpf: add the capability to specify netlink proto in libbpf_netlink_send_recv Lorenzo Bianconi
2023-01-26 12:58 ` [PATCH v3 bpf-next 5/8] libbpf: add API to get XDP/XSK supported features Lorenzo Bianconi
2023-01-27 23:38 ` Andrii Nakryiko
2023-01-28 12:48 ` Lorenzo Bianconi [this message]
2023-01-26 12:58 ` [PATCH v3 bpf-next 6/8] bpf: devmap: check XDP features in __xdp_enqueue routine Lorenzo Bianconi
2023-01-26 12:58 ` [PATCH v3 bpf-next 7/8] selftests/bpf: add test for bpf_xdp_query xdp-features support Lorenzo Bianconi
2023-01-26 18:28 ` sdf
2023-01-26 12:58 ` [PATCH v3 bpf-next 8/8] selftests/bpf: introduce XDP compliance test tool Lorenzo Bianconi
2023-01-26 18:36 ` sdf
2023-01-27 8:19 ` Martin KaFai Lau
2023-01-27 17:26 ` Lorenzo Bianconi
2023-01-27 17:26 ` Lorenzo Bianconi
2023-01-27 17:41 ` Stanislav Fomichev
2023-01-27 17:52 ` Toke Høiland-Jørgensen
2023-01-27 17:58 ` Lorenzo Bianconi
2023-01-27 17:59 ` Stanislav Fomichev
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=Y9UZqxwNPDQ9jEu3@lore-desk \
--to=lorenzo@kernel.org \
--cc=aelior@marvell.com \
--cc=alardam@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=anthony.l.nguyen@intel.com \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=edumazet@google.com \
--cc=gospo@broadcom.com \
--cc=hawk@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=lorenzo.bianconi@redhat.com \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mst@redhat.com \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=simon.horman@corigine.com \
--cc=toke@redhat.com \
--cc=vladimir.oltean@nxp.com \
/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).