Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/xsk: Query for native XDP support

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.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20220901114813.16275-2-maciej.fijalkowski@intel.com

authored by

Maciej Fijalkowski and committed by
Daniel Borkmann
0d68e6fe 8cc61b7a

+37 -2
+37 -2
tools/testing/selftests/bpf/xskxceiver.c
··· 99 99 #include <stdatomic.h> 100 100 #include "xsk.h" 101 101 #include "xskxceiver.h" 102 + #include <bpf/bpf.h> 103 + #include <linux/filter.h> 102 104 #include "../kselftest.h" 103 105 104 106 /* AF_XDP APIs were moved into libxdp and marked as deprecated in libbpf. ··· 1714 1712 free(ifobj); 1715 1713 } 1716 1714 1715 + static bool is_xdp_supported(struct ifobject *ifobject) 1716 + { 1717 + int flags = XDP_FLAGS_DRV_MODE; 1718 + 1719 + LIBBPF_OPTS(bpf_link_create_opts, opts, .flags = flags); 1720 + struct bpf_insn insns[2] = { 1721 + BPF_MOV64_IMM(BPF_REG_0, XDP_PASS), 1722 + BPF_EXIT_INSN() 1723 + }; 1724 + int ifindex = if_nametoindex(ifobject->ifname); 1725 + int prog_fd, insn_cnt = ARRAY_SIZE(insns); 1726 + int err; 1727 + 1728 + prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL); 1729 + if (prog_fd < 0) 1730 + return false; 1731 + 1732 + err = bpf_xdp_attach(ifindex, prog_fd, flags, NULL); 1733 + if (err) { 1734 + close(prog_fd); 1735 + return false; 1736 + } 1737 + 1738 + bpf_xdp_detach(ifindex, flags, NULL); 1739 + close(prog_fd); 1740 + 1741 + return true; 1742 + } 1743 + 1717 1744 int main(int argc, char **argv) 1718 1745 { 1719 1746 struct pkt_stream *pkt_stream_default; 1720 1747 struct ifobject *ifobj_tx, *ifobj_rx; 1748 + int modes = TEST_MODE_SKB + 1; 1721 1749 u32 i, j, failed_tests = 0; 1722 1750 struct test_spec test; 1723 1751 ··· 1775 1743 init_iface(ifobj_rx, MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, 1776 1744 worker_testapp_validate_rx); 1777 1745 1746 + if (is_xdp_supported(ifobj_tx)) 1747 + modes++; 1748 + 1778 1749 test_spec_init(&test, ifobj_tx, ifobj_rx, 0); 1779 1750 pkt_stream_default = pkt_stream_generate(ifobj_tx->umem, DEFAULT_PKT_CNT, PKT_SIZE); 1780 1751 if (!pkt_stream_default) 1781 1752 exit_with_error(ENOMEM); 1782 1753 test.pkt_stream_default = pkt_stream_default; 1783 1754 1784 - ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); 1755 + ksft_set_plan(modes * TEST_TYPE_MAX); 1785 1756 1786 - for (i = 0; i < TEST_MODE_MAX; i++) 1757 + for (i = 0; i < modes; i++) 1787 1758 for (j = 0; j < TEST_TYPE_MAX; j++) { 1788 1759 test_spec_init(&test, ifobj_tx, ifobj_rx, i); 1789 1760 run_pkt_test(&test, i, j);