From nobody Wed Nov 27 13:01:03 2024 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E521C20968C; Fri, 11 Oct 2024 04:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728619456; cv=none; b=gsQX5zmsvsuWLaFmriJLBq34jZTUtevWSCI5+yRqeD86gGjYfK0IS8iEsApJ2VvGaNkBQQrkLGooJ5Wfddq8PU0+PhkOno0di4O9F5ocKa6x6tsV3axCYwxhSSpyus7Z1mBZhOrAKzezQ3idrpJrlSZtzkBKAyraXIC43xIenns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728619456; c=relaxed/simple; bh=iteL6mM7W2wCmg62ZEOzFSnuAD2y1jb3hsKNq7Exj+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WKXBpZZATsktyQnLyRbkFZ6cpIRlY0DdTk9rDtuYtOBaWZ/+Q7wKxJvgb3ecoiKcnJr7tdzaw5EC0PbZGdEx1EI3ZQVZ61T6RKWsQ6U6mlDfx6oHEGbWXBr7deB+d/pBA9uG6wLDn1kudrIVtttRDKTR3xlxGdR05I1N5Z6tGDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jCXqc0xy; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jCXqc0xy" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20bb39d97d1so15174655ad.2; Thu, 10 Oct 2024 21:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728619453; x=1729224253; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ib/V9nv2y/EnyCZ3p2wVDpRbPGsIUIc315orCHypSCg=; b=jCXqc0xyvmCi7CtTBMeUn6mX4p08PzOBgdNYIJidOp2Ti99/zuctplF8qlTqtfBF/j gd8/XhCZEw8ChbMstoyhVRe+xed7fGRxOP/5tDOxjtw8R+s76erTklq17IvZ8GbtPhj6 qBdV7VqjUTI81Mf/RataetZ93ELdY2OXm9thj3Qg+RKlJXst5ZCOtIyb0/hAqXK3Pz57 UxMX04Lc95pzR8UVhGrFBbDDwvb69MmmVtwN7aesUVcSUBVToflw/J6EyqHtLXepzI9P ehZ5DAkRNnpDmLZnQVuhCWFSh4/sQQ+CI4nWuum89/0oLrcwEKwmty3Hx0JeW2AEfOm+ zAYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728619453; x=1729224253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ib/V9nv2y/EnyCZ3p2wVDpRbPGsIUIc315orCHypSCg=; b=YDHwoOqeHcTFV40OEwl2BFVZ45TC5UYW/i8S3/CPx2QONhJH0TZ3ozpoY0mWC8ceyT hiAJJLpyAxUiZHuo38oVrRQRrOJUNVveIGzovlA6jC/38MEMqmVR7ueNPfPjlBBeBkYQ McjfF6gGe8taMf/qVHgjlkhyC0bXDOmnROLx9bhFXrgrjkTyjvGgxaC8Xu1rstUcrM4Z G5UOuvVvfTYEoyV8DzoBm1VTw1cJrW1rK6OLlteGmu0ROvOgioDqofUX6p3SxTMAMfF8 nlAy+yUz8uTPsHPIjPbb0nkMmcbJZGXmbgPybu35T8Po1unnUZAWW4JSGyAxoAmOPkGk LqBg== X-Forwarded-Encrypted: i=1; AJvYcCUMvCZZPnotY/yStbAaa/YHLzwfuR860JPZ1j8WuMD7K5baUt4qnyl5PKPuzgjaacNzGk1bbhrY@vger.kernel.org, AJvYcCUbPVV0j1nzRtAXG7Bd4hS1hOab7HtEO8LkO78TSp5k9wJj4Sf7H1GxBmy+hrf3OuV1qSbuBqyXS5TCBUG5DdHF@vger.kernel.org, AJvYcCWMSCKxgfkERAy1ZpqMR5J2bA3Dn2fO5eU0fi7DWXPsMsGELs9q6yRMeaFJROvNNiv5ADSJWnFpVE8alB8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5OYE12TgB3og+oi9u25KMEkZCL6SE7NUGyKDPk4RXRwDtaIJF l4Iv/VQ2RN/CWDSeS+nyz5+Xmr4PVsBQxfZBth8OOgM/QyWUW7U= X-Google-Smtp-Source: AGHT+IG+iGFC1ezY4bo4Kt82GyildGRx28m9LszrWJuL1H/fpChv4+Cx0ydDteDQJRfDw9B18QrLmA== X-Received: by 2002:a17:902:fc8f:b0:20c:a19b:8ddd with SMTP id d9443c01a7336-20ca19b8fd3mr15234265ad.51.1728619452909; Thu, 10 Oct 2024 21:04:12 -0700 (PDT) Received: from vagrant.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8c0e7716sm16443865ad.122.2024.10.10.21.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 21:04:12 -0700 (PDT) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, LKML Subject: [PATCH,bpf-next v2 4/4] samples/bpf: remove obsolete tracing related tests Date: Fri, 11 Oct 2024 04:03:48 +0000 Message-ID: <20241011040348.98042-5-danieltimlee@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241011040348.98042-1-danieltimlee@gmail.com> References: <20241011040348.98042-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The samples/bpf has become outdated and often does not follow up with the latest. This commit removes obsolete tracing-related tests. Specifically, 'test_overhead' is duplicate with selftests (and bench), and 'test_override_return', 'test_probe_write_user' tests are obsolete since they have been replaced by kprobe_multi_override and probe_user from selftests respectively. The following files are removed: - test_overhead: tests the overhead of BPF programs with task_rename, now covered by selftests and benchmark tests (rename-*). [1] - test_override_return: tests the return override functionality, now handled by kprobe_multi_override in selftests. - test_probe_write_user: tests the probe_write_user functionality, now replaced by the probe_user test in selftests. This cleanup will help to streamline the testing framework by removing redundant tests. [1]: https://patchwork.kernel.org/cover/13759916 Signed-off-by: Daniel T. Lee --- samples/bpf/Makefile | 11 -- samples/bpf/test_overhead_kprobe.bpf.c | 41 ----- samples/bpf/test_overhead_raw_tp.bpf.c | 17 -- samples/bpf/test_overhead_tp.bpf.c | 23 --- samples/bpf/test_overhead_user.c | 225 ----------------------- samples/bpf/test_override_return.sh | 16 -- samples/bpf/test_probe_write_user.bpf.c | 52 ------ samples/bpf/test_probe_write_user_user.c | 108 ----------- samples/bpf/tracex7.bpf.c | 15 -- samples/bpf/tracex7_user.c | 56 ------ 10 files changed, 564 deletions(-) delete mode 100644 samples/bpf/test_overhead_kprobe.bpf.c delete mode 100644 samples/bpf/test_overhead_raw_tp.bpf.c delete mode 100644 samples/bpf/test_overhead_tp.bpf.c delete mode 100644 samples/bpf/test_overhead_user.c delete mode 100755 samples/bpf/test_override_return.sh delete mode 100644 samples/bpf/test_probe_write_user.bpf.c delete mode 100644 samples/bpf/test_probe_write_user_user.c delete mode 100644 samples/bpf/tracex7.bpf.c delete mode 100644 samples/bpf/tracex7_user.c diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 66827dbb93b3..31bf0c665963 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -17,14 +17,11 @@ tprogs-y +=3D tracex3 tprogs-y +=3D tracex4 tprogs-y +=3D tracex5 tprogs-y +=3D tracex6 -tprogs-y +=3D tracex7 -tprogs-y +=3D test_probe_write_user tprogs-y +=3D trace_output tprogs-y +=3D lathist tprogs-y +=3D offwaketime tprogs-y +=3D spintest tprogs-y +=3D map_perf_test -tprogs-y +=3D test_overhead tprogs-y +=3D test_cgrp2_attach tprogs-y +=3D xdp_router_ipv4 tprogs-y +=3D trace_event @@ -62,8 +59,6 @@ tracex3-objs :=3D tracex3_user.o tracex4-objs :=3D tracex4_user.o tracex5-objs :=3D tracex5_user.o $(TRACE_HELPERS) tracex6-objs :=3D tracex6_user.o -tracex7-objs :=3D tracex7_user.o -test_probe_write_user-objs :=3D test_probe_write_user_user.o trace_output-objs :=3D trace_output_user.o lathist-objs :=3D lathist_user.o offwaketime-objs :=3D offwaketime_user.o $(TRACE_HELPERS) @@ -96,9 +91,7 @@ always-y +=3D tracex3.bpf.o always-y +=3D tracex4.bpf.o always-y +=3D tracex5.bpf.o always-y +=3D tracex6.bpf.o -always-y +=3D tracex7.bpf.o always-y +=3D sock_flags.bpf.o -always-y +=3D test_probe_write_user.bpf.o always-y +=3D trace_output.bpf.o always-y +=3D tcbpf1_kern.o always-y +=3D tc_l2_redirect_kern.o @@ -106,9 +99,6 @@ always-y +=3D lathist_kern.o always-y +=3D offwaketime.bpf.o always-y +=3D spintest.bpf.o always-y +=3D map_perf_test.bpf.o -always-y +=3D test_overhead_tp.bpf.o -always-y +=3D test_overhead_raw_tp.bpf.o -always-y +=3D test_overhead_kprobe.bpf.o always-y +=3D parse_varlen.o parse_simple.o parse_ldabs.o always-y +=3D trace_event_kern.o always-y +=3D sampleip_kern.o @@ -182,7 +172,6 @@ TPROGLDLIBS_xdp_router_ipv4 +=3D -lm -pthread TPROGLDLIBS_tracex4 +=3D -lrt TPROGLDLIBS_trace_output +=3D -lrt TPROGLDLIBS_map_perf_test +=3D -lrt -TPROGLDLIBS_test_overhead +=3D -lrt =20 # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine o= n cmdline: # make M=3Dsamples/bpf LLC=3D~/git/llvm-project/llvm/build/bin/llc CLANG= =3D~/git/llvm-project/llvm/build/bin/clang diff --git a/samples/bpf/test_overhead_kprobe.bpf.c b/samples/bpf/test_over= head_kprobe.bpf.c deleted file mode 100644 index 668cf5259c60..000000000000 --- a/samples/bpf/test_overhead_kprobe.bpf.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (c) 2016 Facebook - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - */ -#include "vmlinux.h" -#include -#include -#include -#include - -SEC("kprobe/__set_task_comm") -int prog(struct pt_regs *ctx) -{ - struct signal_struct *signal; - struct task_struct *tsk; - char oldcomm[TASK_COMM_LEN] =3D {}; - char newcomm[TASK_COMM_LEN] =3D {}; - u16 oom_score_adj; - u32 pid; - - tsk =3D (void *)PT_REGS_PARM1_CORE(ctx); - - pid =3D BPF_CORE_READ(tsk, pid); - bpf_core_read_str(oldcomm, sizeof(oldcomm), &tsk->comm); - bpf_core_read_str(newcomm, sizeof(newcomm), - (void *)PT_REGS_PARM2(ctx)); - signal =3D BPF_CORE_READ(tsk, signal); - oom_score_adj =3D BPF_CORE_READ(signal, oom_score_adj); - return 0; -} - -SEC("kprobe/fib_table_lookup") -int prog2(struct pt_regs *ctx) -{ - return 0; -} - -char _license[] SEC("license") =3D "GPL"; -u32 _version SEC("version") =3D LINUX_VERSION_CODE; diff --git a/samples/bpf/test_overhead_raw_tp.bpf.c b/samples/bpf/test_over= head_raw_tp.bpf.c deleted file mode 100644 index 6af39fe3f8dd..000000000000 --- a/samples/bpf/test_overhead_raw_tp.bpf.c +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Copyright (c) 2018 Facebook */ -#include "vmlinux.h" -#include - -SEC("raw_tracepoint/task_rename") -int prog(struct bpf_raw_tracepoint_args *ctx) -{ - return 0; -} - -SEC("raw_tracepoint/fib_table_lookup") -int prog2(struct bpf_raw_tracepoint_args *ctx) -{ - return 0; -} -char _license[] SEC("license") =3D "GPL"; diff --git a/samples/bpf/test_overhead_tp.bpf.c b/samples/bpf/test_overhead= _tp.bpf.c deleted file mode 100644 index 5dc08b587978..000000000000 --- a/samples/bpf/test_overhead_tp.bpf.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (c) 2016 Facebook - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - */ -#include "vmlinux.h" -#include - -/* from /sys/kernel/tracing/events/task/task_rename/format */ -SEC("tracepoint/task/task_rename") -int prog(struct trace_event_raw_task_rename *ctx) -{ - return 0; -} - -/* from /sys/kernel/tracing/events/fib/fib_table_lookup/format */ -SEC("tracepoint/fib/fib_table_lookup") -int prog2(struct trace_event_raw_fib_table_lookup *ctx) -{ - return 0; -} -char _license[] SEC("license") =3D "GPL"; diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_u= ser.c deleted file mode 100644 index dbd86f7b1473..000000000000 --- a/samples/bpf/test_overhead_user.c +++ /dev/null @@ -1,225 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2016 Facebook - */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_CNT 1000000 -#define DUMMY_IP "127.0.0.1" -#define DUMMY_PORT 80 - -static struct bpf_link *links[2]; -static struct bpf_object *obj; -static int cnt; - -static __u64 time_get_ns(void) -{ - struct timespec ts; - - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000000000ull + ts.tv_nsec; -} - -static void test_task_rename(int cpu) -{ - char buf[] =3D "test\n"; - __u64 start_time; - int i, fd; - - fd =3D open("/proc/self/comm", O_WRONLY|O_TRUNC); - if (fd < 0) { - printf("couldn't open /proc\n"); - exit(1); - } - start_time =3D time_get_ns(); - for (i =3D 0; i < MAX_CNT; i++) { - if (write(fd, buf, sizeof(buf)) < 0) { - printf("task rename failed: %s\n", strerror(errno)); - close(fd); - return; - } - } - printf("task_rename:%d: %lld events per sec\n", - cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); - close(fd); -} - -static void test_fib_table_lookup(int cpu) -{ - struct sockaddr_in addr; - char buf[] =3D "test\n"; - __u64 start_time; - int i, fd; - - fd =3D socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (fd < 0) { - printf("couldn't open socket\n"); - exit(1); - } - memset((char *)&addr, 0, sizeof(addr)); - addr.sin_addr.s_addr =3D inet_addr(DUMMY_IP); - addr.sin_port =3D htons(DUMMY_PORT); - addr.sin_family =3D AF_INET; - start_time =3D time_get_ns(); - for (i =3D 0; i < MAX_CNT; i++) { - if (sendto(fd, buf, strlen(buf), 0, - (struct sockaddr *)&addr, sizeof(addr)) < 0) { - printf("failed to start ping: %s\n", strerror(errno)); - close(fd); - return; - } - } - printf("fib_table_lookup:%d: %lld events per sec\n", - cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); - close(fd); -} - -static void loop(int cpu, int flags) -{ - cpu_set_t cpuset; - - CPU_ZERO(&cpuset); - CPU_SET(cpu, &cpuset); - sched_setaffinity(0, sizeof(cpuset), &cpuset); - - if (flags & 1) - test_task_rename(cpu); - if (flags & 2) - test_fib_table_lookup(cpu); -} - -static void run_perf_test(int tasks, int flags) -{ - pid_t pid[tasks]; - int i; - - for (i =3D 0; i < tasks; i++) { - pid[i] =3D fork(); - if (pid[i] =3D=3D 0) { - loop(i, flags); - exit(0); - } else if (pid[i] =3D=3D -1) { - printf("couldn't spawn #%d process\n", i); - exit(1); - } - } - for (i =3D 0; i < tasks; i++) { - int status; - - assert(waitpid(pid[i], &status, 0) =3D=3D pid[i]); - assert(status =3D=3D 0); - } -} - -static int load_progs(char *filename) -{ - struct bpf_program *prog; - int err =3D 0; - - obj =3D bpf_object__open_file(filename, NULL); - err =3D libbpf_get_error(obj); - if (err < 0) { - fprintf(stderr, "ERROR: opening BPF object file failed\n"); - return err; - } - - /* load BPF program */ - err =3D bpf_object__load(obj); - if (err < 0) { - fprintf(stderr, "ERROR: loading BPF object file failed\n"); - return err; - } - - bpf_object__for_each_program(prog, obj) { - links[cnt] =3D bpf_program__attach(prog); - err =3D libbpf_get_error(links[cnt]); - if (err < 0) { - fprintf(stderr, "ERROR: bpf_program__attach failed\n"); - links[cnt] =3D NULL; - return err; - } - cnt++; - } - - return err; -} - -static void unload_progs(void) -{ - while (cnt) - bpf_link__destroy(links[--cnt]); - - bpf_object__close(obj); -} - -int main(int argc, char **argv) -{ - int num_cpu =3D sysconf(_SC_NPROCESSORS_ONLN); - int test_flags =3D ~0; - char filename[256]; - int err =3D 0; - - - if (argc > 1) - test_flags =3D atoi(argv[1]) ? : test_flags; - if (argc > 2) - num_cpu =3D atoi(argv[2]) ? : num_cpu; - - if (test_flags & 0x3) { - printf("BASE\n"); - run_perf_test(num_cpu, test_flags); - } - - if (test_flags & 0xC) { - snprintf(filename, sizeof(filename), - "%s_kprobe.bpf.o", argv[0]); - - printf("w/KPROBE\n"); - err =3D load_progs(filename); - if (!err) - run_perf_test(num_cpu, test_flags >> 2); - - unload_progs(); - } - - if (test_flags & 0x30) { - snprintf(filename, sizeof(filename), - "%s_tp.bpf.o", argv[0]); - printf("w/TRACEPOINT\n"); - err =3D load_progs(filename); - if (!err) - run_perf_test(num_cpu, test_flags >> 4); - - unload_progs(); - } - - if (test_flags & 0xC0) { - snprintf(filename, sizeof(filename), - "%s_raw_tp.bpf.o", argv[0]); - printf("w/RAW_TRACEPOINT\n"); - err =3D load_progs(filename); - if (!err) - run_perf_test(num_cpu, test_flags >> 6); - - unload_progs(); - } - - return err; -} diff --git a/samples/bpf/test_override_return.sh b/samples/bpf/test_overrid= e_return.sh deleted file mode 100755 index 35db26f736b9..000000000000 --- a/samples/bpf/test_override_return.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -rm -r tmpmnt -rm -f testfile.img -dd if=3D/dev/zero of=3Dtestfile.img bs=3D1M seek=3D1000 count=3D1 -DEVICE=3D$(losetup --show -f testfile.img) -mkfs.btrfs -f $DEVICE -mkdir tmpmnt -./tracex7 $DEVICE -if [ $? -eq 0 ] -then - echo "SUCCESS!" -else - echo "FAILED!" -fi -losetup -d $DEVICE diff --git a/samples/bpf/test_probe_write_user.bpf.c b/samples/bpf/test_pro= be_write_user.bpf.c deleted file mode 100644 index a4f3798b7fb0..000000000000 --- a/samples/bpf/test_probe_write_user.bpf.c +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2016 Sargun Dhillon - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - */ -#include "vmlinux.h" -#include -#include -#include -#include -#include - -struct { - __uint(type, BPF_MAP_TYPE_HASH); - __type(key, struct sockaddr_in); - __type(value, struct sockaddr_in); - __uint(max_entries, 256); -} dnat_map SEC(".maps"); - -/* kprobe is NOT a stable ABI - * kernel functions can be removed, renamed or completely change semantics. - * Number of arguments and their positions can change, etc. - * In such case this bpf+kprobe example will no longer be meaningful - * - * This example sits on a syscall, and the syscall ABI is relatively stable - * of course, across platforms, and over time, the ABI may change. - */ -SEC("ksyscall/connect") -int BPF_KSYSCALL(bpf_prog1, int fd, struct sockaddr_in *uservaddr, - int addrlen) -{ - struct sockaddr_in new_addr, orig_addr =3D {}; - struct sockaddr_in *mapped_addr; - - if (addrlen > sizeof(orig_addr)) - return 0; - - if (bpf_probe_read_user(&orig_addr, sizeof(orig_addr), uservaddr) !=3D 0) - return 0; - - mapped_addr =3D bpf_map_lookup_elem(&dnat_map, &orig_addr); - if (mapped_addr !=3D NULL) { - memcpy(&new_addr, mapped_addr, sizeof(new_addr)); - bpf_probe_write_user(uservaddr, &new_addr, - sizeof(new_addr)); - } - return 0; -} - -char _license[] SEC("license") =3D "GPL"; -u32 _version SEC("version") =3D LINUX_VERSION_CODE; diff --git a/samples/bpf/test_probe_write_user_user.c b/samples/bpf/test_pr= obe_write_user_user.c deleted file mode 100644 index 2a539aec4116..000000000000 --- a/samples/bpf/test_probe_write_user_user.c +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int ac, char **argv) -{ - struct sockaddr_in *serv_addr_in, *mapped_addr_in, *tmp_addr_in; - struct sockaddr serv_addr, mapped_addr, tmp_addr; - int serverfd, serverconnfd, clientfd, map_fd; - struct bpf_link *link =3D NULL; - struct bpf_program *prog; - struct bpf_object *obj; - socklen_t sockaddr_len; - char filename[256]; - char *ip; - - serv_addr_in =3D (struct sockaddr_in *)&serv_addr; - mapped_addr_in =3D (struct sockaddr_in *)&mapped_addr; - tmp_addr_in =3D (struct sockaddr_in *)&tmp_addr; - - snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); - obj =3D bpf_object__open_file(filename, NULL); - if (libbpf_get_error(obj)) { - fprintf(stderr, "ERROR: opening BPF object file failed\n"); - return 0; - } - - prog =3D bpf_object__find_program_by_name(obj, "bpf_prog1"); - if (libbpf_get_error(prog)) { - fprintf(stderr, "ERROR: finding a prog in obj file failed\n"); - goto cleanup; - } - - /* load BPF program */ - if (bpf_object__load(obj)) { - fprintf(stderr, "ERROR: loading BPF object file failed\n"); - goto cleanup; - } - - map_fd =3D bpf_object__find_map_fd_by_name(obj, "dnat_map"); - if (map_fd < 0) { - fprintf(stderr, "ERROR: finding a map in obj file failed\n"); - goto cleanup; - } - - link =3D bpf_program__attach(prog); - if (libbpf_get_error(link)) { - fprintf(stderr, "ERROR: bpf_program__attach failed\n"); - link =3D NULL; - goto cleanup; - } - - assert((serverfd =3D socket(AF_INET, SOCK_STREAM, 0)) > 0); - assert((clientfd =3D socket(AF_INET, SOCK_STREAM, 0)) > 0); - - /* Bind server to ephemeral port on lo */ - memset(&serv_addr, 0, sizeof(serv_addr)); - serv_addr_in->sin_family =3D AF_INET; - serv_addr_in->sin_port =3D 0; - serv_addr_in->sin_addr.s_addr =3D htonl(INADDR_LOOPBACK); - - assert(bind(serverfd, &serv_addr, sizeof(serv_addr)) =3D=3D 0); - - sockaddr_len =3D sizeof(serv_addr); - assert(getsockname(serverfd, &serv_addr, &sockaddr_len) =3D=3D 0); - ip =3D inet_ntoa(serv_addr_in->sin_addr); - printf("Server bound to: %s:%d\n", ip, ntohs(serv_addr_in->sin_port)); - - memset(&mapped_addr, 0, sizeof(mapped_addr)); - mapped_addr_in->sin_family =3D AF_INET; - mapped_addr_in->sin_port =3D htons(5555); - mapped_addr_in->sin_addr.s_addr =3D inet_addr("255.255.255.255"); - - assert(!bpf_map_update_elem(map_fd, &mapped_addr, &serv_addr, BPF_ANY)); - - assert(listen(serverfd, 5) =3D=3D 0); - - ip =3D inet_ntoa(mapped_addr_in->sin_addr); - printf("Client connecting to: %s:%d\n", - ip, ntohs(mapped_addr_in->sin_port)); - assert(connect(clientfd, &mapped_addr, sizeof(mapped_addr)) =3D=3D 0); - - sockaddr_len =3D sizeof(tmp_addr); - ip =3D inet_ntoa(tmp_addr_in->sin_addr); - assert((serverconnfd =3D accept(serverfd, &tmp_addr, &sockaddr_len)) > 0); - printf("Server received connection from: %s:%d\n", - ip, ntohs(tmp_addr_in->sin_port)); - - sockaddr_len =3D sizeof(tmp_addr); - assert(getpeername(clientfd, &tmp_addr, &sockaddr_len) =3D=3D 0); - ip =3D inet_ntoa(tmp_addr_in->sin_addr); - printf("Client's peer address: %s:%d\n", - ip, ntohs(tmp_addr_in->sin_port)); - - /* Is the server's getsockname =3D the socket getpeername */ - assert(memcmp(&serv_addr, &tmp_addr, sizeof(struct sockaddr_in)) =3D=3D 0= ); - -cleanup: - bpf_link__destroy(link); - bpf_object__close(obj); - return 0; -} diff --git a/samples/bpf/tracex7.bpf.c b/samples/bpf/tracex7.bpf.c deleted file mode 100644 index ab8d6704a5a4..000000000000 --- a/samples/bpf/tracex7.bpf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "vmlinux.h" -#include -#include - -SEC("kprobe/open_ctree") -int bpf_prog1(struct pt_regs *ctx) -{ - unsigned long rc =3D -12; - - bpf_override_return(ctx, rc); - return 0; -} - -char _license[] SEC("license") =3D "GPL"; -u32 _version SEC("version") =3D LINUX_VERSION_CODE; diff --git a/samples/bpf/tracex7_user.c b/samples/bpf/tracex7_user.c deleted file mode 100644 index b10b5e03a226..000000000000 --- a/samples/bpf/tracex7_user.c +++ /dev/null @@ -1,56 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include - -int main(int argc, char **argv) -{ - struct bpf_link *link =3D NULL; - struct bpf_program *prog; - struct bpf_object *obj; - char filename[256]; - char command[256]; - int ret =3D 0; - FILE *f; - - if (!argv[1]) { - fprintf(stderr, "ERROR: Run with the btrfs device argument!\n"); - return 0; - } - - snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); - obj =3D bpf_object__open_file(filename, NULL); - if (libbpf_get_error(obj)) { - fprintf(stderr, "ERROR: opening BPF object file failed\n"); - return 0; - } - - prog =3D bpf_object__find_program_by_name(obj, "bpf_prog1"); - if (!prog) { - fprintf(stderr, "ERROR: finding a prog in obj file failed\n"); - goto cleanup; - } - - /* load BPF program */ - if (bpf_object__load(obj)) { - fprintf(stderr, "ERROR: loading BPF object file failed\n"); - goto cleanup; - } - - link =3D bpf_program__attach(prog); - if (libbpf_get_error(link)) { - fprintf(stderr, "ERROR: bpf_program__attach failed\n"); - link =3D NULL; - goto cleanup; - } - - snprintf(command, 256, "mount %s tmpmnt/", argv[1]); - f =3D popen(command, "r"); - ret =3D pclose(f); - -cleanup: - bpf_link__destroy(link); - bpf_object__close(obj); - return ret ? 0 : 1; -} --=20 2.43.0