From patchwork Fri Dec 6 08:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Curutchet X-Patchwork-Id: 847960 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D33721B532F; Fri, 6 Dec 2024 08:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733472769; cv=none; b=SGBqLKe1yqGGnsQNrXHK9sQMZFlyP6FGUESGHN3sx+I3VSZQUljV5T08IgN7l7obqFXGV7OvTYonWEdgo3lx88y3JD4T6hvjGH3hKtoRWcIfdIPi4qSoNnp9LFx7PATVSyYHui94NOUSGoi7x3U0xL3gfwz92CPiRf1ZCTyNicY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733472769; c=relaxed/simple; bh=bnEbn3CujnN83vLQm/WOWv+T+v3MHKR7OIRFzBENolM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bSbAd1OBptsYvx4msMlSxg7LLps/ifnTZO9/LugC0A8EpEIs725tCOiGnxA53Saum7EKGK+7zyHjgyfMMVPC9h53xZRDcepjY1e66lJVKD/18O7aXSj0eVa8iMWkZy+Nto34sO+L31WRdfEMEbDxYR2Nu48qxmcMAbjO1jdJmEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=EtCsGQm6; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="EtCsGQm6" Received: by mail.gandi.net (Postfix) with ESMTPSA id BDFC940006; Fri, 6 Dec 2024 08:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733472757; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Or7+rx4R//1Hmn+698riCJsFcFYwFbW8Po0XkdG2iPY=; b=EtCsGQm6o+O79Pzpgt0WzKhQdo8Gru2AMtltjixihlpyF9Te15SR//6fXS8tNDlzKlbNR3 si2aIgeRKNjbVDPkFNAkd4voXQrTMLS3G+j+p5RpYskgd5pzfix8w785sxkojzmZyKnfNs n9VEFSk1j+eri5kuQhcIIWgyvL1lzvxGuqse4fiB5MuAFIcKA75vyIdSwJuP1JF5/RboHy TCNBz9VHjE46ulSh55t5GVzCehT5w29Dii6ChFhDs77dFI3bm9dlawra+tRWGbPbYcxw6Z 5RwcBa89/aWk7soGhkYSmAWGR97Rhg7Wk23Vm8CchpXlL+j+4NUogETN19bvag== From: Bastien Curutchet Date: Fri, 06 Dec 2024 09:12:13 +0100 Subject: [PATCH bpf-next 1/2] selftests/bpf: test_xdp_meta: Rename BPF sections Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241206-xdp_meta-v1-1-5c150618f6e9@bootlin.com> References: <20241206-xdp_meta-v1-0-5c150618f6e9@bootlin.com> In-Reply-To: <20241206-xdp_meta-v1-0-5c150618f6e9@bootlin.com> To: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: Alexis Lothore , Thomas Petazzoni , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Bastien Curutchet X-Mailer: b4 0.14.2 X-GND-Sasl: bastien.curutchet@bootlin.com SEC("t") and SEC("x") can't be loaded by the __load() helper. Rename these sections SEC("tc") and SEC("xdp") so they can be interpreted by the __load() helper in upcoming patch. Update the test_xdp_meta.sh to fit these new names. Signed-off-by: Bastien Curutchet (eBPF Foundation) --- tools/testing/selftests/bpf/progs/test_xdp_meta.c | 4 ++-- tools/testing/selftests/bpf/test_xdp_meta.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/test_xdp_meta.c b/tools/testing/selftests/bpf/progs/test_xdp_meta.c index a7c4a7d49fe6b54b5841e36bcbe9ae9c8577df38..fe2d71ae0e717a32bd2b3a891da8e0d6fa3eba2c 100644 --- a/tools/testing/selftests/bpf/progs/test_xdp_meta.c +++ b/tools/testing/selftests/bpf/progs/test_xdp_meta.c @@ -8,7 +8,7 @@ #define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1) #define ctx_ptr(ctx, mem) (void *)(unsigned long)ctx->mem -SEC("t") +SEC("tc") int ing_cls(struct __sk_buff *ctx) { __u8 *data, *data_meta, *data_end; @@ -28,7 +28,7 @@ int ing_cls(struct __sk_buff *ctx) return diff ? TC_ACT_SHOT : TC_ACT_OK; } -SEC("x") +SEC("xdp") int ing_xdp(struct xdp_md *ctx) { __u8 *data, *data_meta, *data_end; diff --git a/tools/testing/selftests/bpf/test_xdp_meta.sh b/tools/testing/selftests/bpf/test_xdp_meta.sh index 2740322c1878b3687d9cc4295f81a40042dd24c6..6039b92f10949d48cd9d703d6981ae8a9388e8df 100755 --- a/tools/testing/selftests/bpf/test_xdp_meta.sh +++ b/tools/testing/selftests/bpf/test_xdp_meta.sh @@ -43,11 +43,11 @@ ip netns exec ${NS2} ip addr add 10.1.1.22/24 dev veth2 ip netns exec ${NS1} tc qdisc add dev veth1 clsact ip netns exec ${NS2} tc qdisc add dev veth2 clsact -ip netns exec ${NS1} tc filter add dev veth1 ingress bpf da obj ${BPF_FILE} sec t -ip netns exec ${NS2} tc filter add dev veth2 ingress bpf da obj ${BPF_FILE} sec t +ip netns exec ${NS1} tc filter add dev veth1 ingress bpf da obj ${BPF_FILE} sec tc +ip netns exec ${NS2} tc filter add dev veth2 ingress bpf da obj ${BPF_FILE} sec tc -ip netns exec ${NS1} ip link set dev veth1 xdp obj ${BPF_FILE} sec x -ip netns exec ${NS2} ip link set dev veth2 xdp obj ${BPF_FILE} sec x +ip netns exec ${NS1} ip link set dev veth1 xdp obj ${BPF_FILE} sec xdp +ip netns exec ${NS2} ip link set dev veth2 xdp obj ${BPF_FILE} sec xdp ip netns exec ${NS1} ip link set dev veth1 up ip netns exec ${NS2} ip link set dev veth2 up From patchwork Fri Dec 6 08:12:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Curutchet X-Patchwork-Id: 848376 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B175D1DDA0F; Fri, 6 Dec 2024 08:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733472769; cv=none; b=tKeF24/mu0WT5+LAHiCTGskikkFDktEW8+ZWql7++DhmEVeM6UC3gNhm5M+HRiuA1hDye8EvGzMUjCEcDaVEWxbcMxi1J8sk9mafx2UTpZaq1feQ99ZIYoPlzgE4FlpxGMZyDib634BMEP1XeaCFB1VYN/dbByLsObUFk0/ZoTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733472769; c=relaxed/simple; bh=4zp8xIEIY6gFij/l6U5xJS8txUvJpjK5nVV4VMaXCrw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Yts3XwNGChuILt75wfKLzc4fTWmEJJMUOtK2o9Q8v5/Z4fUUhxw5JkQC5dw9cNC4rAZLE59zSiqz3MKTJFmc3/pc+WYZO1N05tK24df79vvK33jcCaqBVHr/GN/W1Q5W9Q6OPzzbChtMS2fA9ga6HIGv5IBk6cvlO5lc9fOnDAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=gCTbTHkL; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="gCTbTHkL" Received: by mail.gandi.net (Postfix) with ESMTPSA id C696B4000A; Fri, 6 Dec 2024 08:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733472758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iHhOnwJ3Hdk8LZG7baZNdrSouCArkr9q3HbqfhV8XLY=; b=gCTbTHkLLTPpOxcvA9A31VR8jwCkpXpC3iAoLWp94qnCsu3GfdT4GEcSD7TKmoIobncWAy 6sydiiSyjOsg0KePH7zmp6f1PEi9gc5FeO1GEpfMR5sPjcrLb20L9cyM20UwbnZweCLRH7 M99/SaKFRN38x8aJuFW35la1e1H1FOVjqF3fx1Ijyka+JPMX60FugPj1O3UTKi6u6QDkm5 hOjUqoc4QYGmvjr+qIqkOxX13d0ELRB431S5zY3f8J1tOARWExdaN66azmO3Q+ckYnefzE Ulbdx0jbopDoVFm+rCNgStB/aYb+xiB10boLTZSN9Gl1SJhPYNQfX+XtXF5yEQ== From: Bastien Curutchet Date: Fri, 06 Dec 2024 09:12:14 +0100 Subject: [PATCH bpf-next 2/2] selftests/bpf: Migrate test_xdp_meta.sh into xdp_context_test_run.c Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241206-xdp_meta-v1-2-5c150618f6e9@bootlin.com> References: <20241206-xdp_meta-v1-0-5c150618f6e9@bootlin.com> In-Reply-To: <20241206-xdp_meta-v1-0-5c150618f6e9@bootlin.com> To: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: Alexis Lothore , Thomas Petazzoni , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Bastien Curutchet X-Mailer: b4 0.14.2 X-GND-Sasl: bastien.curutchet@bootlin.com test_xdp_meta.sh can't be used by the BPF CI. Migrate test_xdp_meta.sh in a new test case in xdp_context_test_run.c. It uses the same BPF programs located in progs/test_xdp_meta.c and the same network topology. Remove test_xdp_meta.sh and its Makefile entry. Signed-off-by: Bastien Curutchet (eBPF Foundation) --- tools/testing/selftests/bpf/Makefile | 1 - .../bpf/prog_tests/xdp_context_test_run.c | 86 ++++++++++++++++++++++ tools/testing/selftests/bpf/test_xdp_meta.sh | 58 --------------- 3 files changed, 86 insertions(+), 59 deletions(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index a1964d40a60ea5b195e6e75bde5796eea63179bb..af03527bb13ad7a0ee121d3fc00599449e1a396c 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -129,7 +129,6 @@ TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) TEST_PROGS := test_kmod.sh \ test_xdp_redirect.sh \ test_xdp_redirect_multi.sh \ - test_xdp_meta.sh \ test_tunnel.sh \ test_lwt_seg6local.sh \ test_lirc_mode2.sh \ diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c b/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c index e6a783c7f5db9c818bd354027bae7393ee3c166b..1d4d9c9edb7dffa6d60865497c0b9d40a92278ba 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c @@ -2,6 +2,14 @@ #include #include #include "test_xdp_context_test_run.skel.h" +#include "test_xdp_meta.skel.h" + +#define TX_ADDR "10.0.0.1" +#define RX_ADDR "10.0.0.2" +#define RX_NAME "veth0" +#define TX_NAME "veth1" +#define TX_NETNS "xdp_context_tx" +#define RX_NETNS "xdp_context_rx" void test_xdp_context_error(int prog_fd, struct bpf_test_run_opts opts, __u32 data_meta, __u32 data, __u32 data_end, @@ -103,3 +111,81 @@ void test_xdp_context_test_run(void) test_xdp_context_test_run__destroy(skel); } + +void test_xdp_context_functional(void) +{ + LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS); + LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1); + struct bpf_program *tc_prog, *xdp_prog; + struct netns_obj *rx_ns, *tx_ns; + struct test_xdp_meta *skel; + struct nstoken *nstoken; + int rx_ifindex; + int ret; + + tx_ns = netns_new(TX_NETNS, false); + if (!ASSERT_OK_PTR(tx_ns, "create tx_ns")) + return; + + rx_ns = netns_new(RX_NETNS, false); + if (!ASSERT_OK_PTR(rx_ns, "create rx_ns")) + goto free_txns; + + SYS(free_rxns, "ip link add " RX_NAME " netns " RX_NETNS + " type veth peer name " TX_NAME " netns " TX_NETNS); + + nstoken = open_netns(RX_NETNS); + if (!ASSERT_OK_PTR(nstoken, "setns rx_ns")) + goto free_rxns; + + SYS(free_rxns, "ip addr add " RX_ADDR "/24 dev " RX_NAME); + SYS(free_rxns, "ip link set dev " RX_NAME " up"); + + skel = test_xdp_meta__open_and_load(); + if (!ASSERT_OK_PTR(skel, "open and load skeleton")) + goto free_rxns; + + rx_ifindex = if_nametoindex(RX_NAME); + if (!ASSERT_GE(rx_ifindex, 0, "if_nametoindex rx")) + goto destroy_skel; + + tc_hook.ifindex = rx_ifindex; + ret = bpf_tc_hook_create(&tc_hook); + if (!ASSERT_OK(ret, "bpf_tc_hook_create")) + goto destroy_skel; + + tc_prog = bpf_object__find_program_by_name(skel->obj, "ing_cls"); + if (!ASSERT_OK_PTR(tc_prog, "open ing_cls prog")) + goto destroy_skel; + + tc_opts.prog_fd = bpf_program__fd(tc_prog); + ret = bpf_tc_attach(&tc_hook, &tc_opts); + if (!ASSERT_OK(ret, "bpf_tc_attach")) + goto destroy_skel; + + xdp_prog = bpf_object__find_program_by_name(skel->obj, "ing_xdp"); + if (!ASSERT_OK_PTR(xdp_prog, "open ing_xdp prog")) + goto destroy_skel; + + ret = bpf_xdp_attach(rx_ifindex, + bpf_program__fd(xdp_prog), + 0, NULL); + if (!ASSERT_GE(ret, 0, "bpf_xdp_attach")) + goto destroy_skel; + + nstoken = open_netns(TX_NETNS); + if (!ASSERT_OK_PTR(nstoken, "setns tx_ns")) + goto destroy_skel; + + SYS(destroy_skel, "ip addr add " TX_ADDR "/24 dev " TX_NAME); + SYS(destroy_skel, "ip link set dev " TX_NAME " up"); + SYS(destroy_skel, "ping -c 1 " RX_ADDR); + +destroy_skel: + test_xdp_meta__destroy(skel); +free_rxns: + netns_free(rx_ns); +free_txns: + netns_free(tx_ns); +} + diff --git a/tools/testing/selftests/bpf/test_xdp_meta.sh b/tools/testing/selftests/bpf/test_xdp_meta.sh deleted file mode 100755 index 6039b92f10949d48cd9d703d6981ae8a9388e8df..0000000000000000000000000000000000000000 --- a/tools/testing/selftests/bpf/test_xdp_meta.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh - -BPF_FILE="test_xdp_meta.bpf.o" -# Kselftest framework requirement - SKIP code is 4. -readonly KSFT_SKIP=4 -readonly NS1="ns1-$(mktemp -u XXXXXX)" -readonly NS2="ns2-$(mktemp -u XXXXXX)" - -cleanup() -{ - if [ "$?" = "0" ]; then - echo "selftests: test_xdp_meta [PASS]"; - else - echo "selftests: test_xdp_meta [FAILED]"; - fi - - set +e - ip link del veth1 2> /dev/null - ip netns del ${NS1} 2> /dev/null - ip netns del ${NS2} 2> /dev/null -} - -ip link set dev lo xdp off 2>/dev/null > /dev/null -if [ $? -ne 0 ];then - echo "selftests: [SKIP] Could not run test without the ip xdp support" - exit $KSFT_SKIP -fi -set -e - -ip netns add ${NS1} -ip netns add ${NS2} - -trap cleanup 0 2 3 6 9 - -ip link add veth1 type veth peer name veth2 - -ip link set veth1 netns ${NS1} -ip link set veth2 netns ${NS2} - -ip netns exec ${NS1} ip addr add 10.1.1.11/24 dev veth1 -ip netns exec ${NS2} ip addr add 10.1.1.22/24 dev veth2 - -ip netns exec ${NS1} tc qdisc add dev veth1 clsact -ip netns exec ${NS2} tc qdisc add dev veth2 clsact - -ip netns exec ${NS1} tc filter add dev veth1 ingress bpf da obj ${BPF_FILE} sec tc -ip netns exec ${NS2} tc filter add dev veth2 ingress bpf da obj ${BPF_FILE} sec tc - -ip netns exec ${NS1} ip link set dev veth1 xdp obj ${BPF_FILE} sec xdp -ip netns exec ${NS2} ip link set dev veth2 xdp obj ${BPF_FILE} sec xdp - -ip netns exec ${NS1} ip link set dev veth1 up -ip netns exec ${NS2} ip link set dev veth2 up - -ip netns exec ${NS1} ping -c 1 10.1.1.22 -ip netns exec ${NS2} ping -c 1 10.1.1.11 - -exit 0