lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YrBSKTsQjShydeAw@boxer>
Date:   Mon, 20 Jun 2022 12:55:37 +0200
From:   Maciej Fijalkowski <maciej.fijalkowski@...el.com>
To:     John Fastabend <john.fastabend@...il.com>
Cc:     bpf@...r.kernel.org, ast@...nel.org, daniel@...earbox.net,
        netdev@...r.kernel.org, magnus.karlsson@...el.com,
        bjorn@...nel.org, kuba@...nel.org
Subject: Re: [PATCH v4 bpf-next 05/10] selftests: xsk: query for native XDP
 support

On Fri, Jun 17, 2022 at 07:12:00PM -0700, John Fastabend wrote:
> Maciej Fijalkowski wrote:
> > Currently, xdpxceiver assumes that underlying device supports XDP in
> > native mode - it is fine by now since tests can run only on a veth pair.
> > Future commit is going to allow running test suite against physical
> > devices, so let us query the device if it is capable of running XDP
> > programs in native mode. This way xdpxceiver will not try to run
> > TEST_MODE_DRV if device being tested is not supporting it.
> > 
> > Acked-by: Magnus Karlsson <magnus.karlsson@...el.com>
> > Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
> > ---
> >  tools/testing/selftests/bpf/xdpxceiver.c | 36 ++++++++++++++++++++++--
> >  1 file changed, 34 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
> > index e5992a6b5e09..a1e410f6a5d8 100644
> > --- a/tools/testing/selftests/bpf/xdpxceiver.c
> > +++ b/tools/testing/selftests/bpf/xdpxceiver.c
> > @@ -98,6 +98,8 @@
> >  #include <unistd.h>
> >  #include <stdatomic.h>
> >  #include <bpf/xsk.h>
> > +#include <bpf/bpf.h>
> > +#include <linux/filter.h>
> >  #include "xdpxceiver.h"
> >  #include "../kselftest.h"
> >  
> > @@ -1605,10 +1607,37 @@ static void ifobject_delete(struct ifobject *ifobj)
> >  	free(ifobj);
> >  }
> >  
> > +static bool is_xdp_supported(struct ifobject *ifobject)
> > +{
> > +	int flags = XDP_FLAGS_DRV_MODE;
> > +
> > +	LIBBPF_OPTS(bpf_link_create_opts, opts, .flags = flags);
> > +	struct bpf_insn insns[2] = {
> > +		BPF_MOV64_IMM(BPF_REG_0, XDP_PASS),
> > +		BPF_EXIT_INSN()
> > +	};
> > +	int ifindex = if_nametoindex(ifobject->ifname);
> > +	int prog_fd, insn_cnt = ARRAY_SIZE(insns);
> > +	int err;
> > +
> > +	prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL);
> > +	if (prog_fd < 0)
> > +		return false;
> > +
> > +	err = bpf_xdp_attach(ifindex, prog_fd, flags, NULL);
> > +	if (err)
> 
> Best not to leave around prog_fd in the error case or in the
> good case.
> 
> > +		return false;
> > +
> > +	bpf_xdp_detach(ifindex, flags, NULL);
> > +
> 
> close(prog_fd)

Will fix

> 
> > +	return true;
> > +}
> > +

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ