All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] samples/bpf: simple fixes
@ 2018-07-04 13:36 Taeung Song
  2018-07-04 13:36 ` [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h> Taeung Song
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Taeung Song @ 2018-07-04 13:36 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, linux-kernel, Taeung Song

v2:
- in error cases, do return; instead of break; in loop

Hello,
This patchset fixes trivial things that I found
when testing 'samples/bpf/' sample code.
I'd appreciate it, if you review this.

Thanks,
Taeung

Taeung Song (4):
  samples/bpf: add missing <linux/if_vlan.h>
  samples/bpf: Check the result of system()
  samples/bpf: Check the error of write() and read()
  samples/bpf: add .gitignore file

 samples/bpf/.gitignore           | 49 ++++++++++++++++++++++++++++++++
 samples/bpf/parse_varlen.c       |  6 +---
 samples/bpf/test_overhead_user.c | 19 ++++++++++---
 samples/bpf/trace_event_user.c   | 27 ++++++++++++++++--
 4 files changed, 89 insertions(+), 12 deletions(-)
 create mode 100644 samples/bpf/.gitignore

-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h>
  2018-07-04 13:36 [PATCH v2 0/4] samples/bpf: simple fixes Taeung Song
@ 2018-07-04 13:36 ` Taeung Song
  2018-07-05  5:24   ` David Miller
  2018-07-04 13:36 ` [PATCH v2 2/4] samples/bpf: Check the result of system() Taeung Song
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Taeung Song @ 2018-07-04 13:36 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, linux-kernel, Taeung Song

This fixes build error regarding redefinition:

    CLANG-bpf  samples/bpf/parse_varlen.o
  samples/bpf/parse_varlen.c:111:8: error: redefinition of 'vlan_hdr'
  struct vlan_hdr {
         ^
  ./include/linux/if_vlan.h:38:8: note: previous definition is here

So remove duplicate 'struct vlan_hdr' in sample code and include if_vlan.h

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 samples/bpf/parse_varlen.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/samples/bpf/parse_varlen.c b/samples/bpf/parse_varlen.c
index 95c16324760c..0b6f22feb2c9 100644
--- a/samples/bpf/parse_varlen.c
+++ b/samples/bpf/parse_varlen.c
@@ -6,6 +6,7 @@
  */
 #define KBUILD_MODNAME "foo"
 #include <linux/if_ether.h>
+#include <linux/if_vlan.h>
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/in.h>
@@ -108,11 +109,6 @@ static int parse_ipv6(void *data, uint64_t nh_off, void *data_end)
 	return 0;
 }
 
-struct vlan_hdr {
-	uint16_t h_vlan_TCI;
-	uint16_t h_vlan_encapsulated_proto;
-};
-
 SEC("varlen")
 int handle_ingress(struct __sk_buff *skb)
 {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/4] samples/bpf: Check the result of system()
  2018-07-04 13:36 [PATCH v2 0/4] samples/bpf: simple fixes Taeung Song
  2018-07-04 13:36 ` [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h> Taeung Song
@ 2018-07-04 13:36 ` Taeung Song
  2018-07-05  5:24   ` David Miller
  2018-07-04 13:36 ` [PATCH v2 3/4] samples/bpf: Check the error of write() and read() Taeung Song
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Taeung Song @ 2018-07-04 13:36 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, linux-kernel, Taeung Song, Teng Qin

To avoid the below build warning message,
use new generate_load() checking the return value.

  ignoring return value of ‘system’, declared with attribute warn_unused_result

And it also refactors the duplicate code of both
test_perf_event_all_cpu() and test_perf_event_task()

Cc: Teng Qin <qinteng@fb.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 samples/bpf/trace_event_user.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c
index 1fa1becfa641..d08046ab81f0 100644
--- a/samples/bpf/trace_event_user.c
+++ b/samples/bpf/trace_event_user.c
@@ -122,6 +122,16 @@ static void print_stacks(void)
 	}
 }
 
+static inline int generate_load(void)
+{
+	if (system("dd if=/dev/zero of=/dev/null count=5000k status=none") < 0) {
+		printf("failed to generate some load with dd: %s\n", strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
 static void test_perf_event_all_cpu(struct perf_event_attr *attr)
 {
 	int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
@@ -142,7 +152,11 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr)
 		assert(ioctl(pmu_fd[i], PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
 		assert(ioctl(pmu_fd[i], PERF_EVENT_IOC_ENABLE) == 0);
 	}
-	system("dd if=/dev/zero of=/dev/null count=5000k status=none");
+
+	if (generate_load() < 0) {
+		error = 1;
+		goto all_cpu_err;
+	}
 	print_stacks();
 all_cpu_err:
 	for (i--; i >= 0; i--) {
@@ -156,7 +170,7 @@ static void test_perf_event_all_cpu(struct perf_event_attr *attr)
 
 static void test_perf_event_task(struct perf_event_attr *attr)
 {
-	int pmu_fd;
+	int pmu_fd, error = 0;
 
 	/* per task perf event, enable inherit so the "dd ..." command can be traced properly.
 	 * Enabling inherit will cause bpf_perf_prog_read_time helper failure.
@@ -171,10 +185,17 @@ static void test_perf_event_task(struct perf_event_attr *attr)
 	}
 	assert(ioctl(pmu_fd, PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
 	assert(ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE) == 0);
-	system("dd if=/dev/zero of=/dev/null count=5000k status=none");
+
+	if (generate_load() < 0) {
+		error = 1;
+		goto err;
+	}
 	print_stacks();
+err:
 	ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
 	close(pmu_fd);
+	if (error)
+		int_exit(0);
 }
 
 static void test_bpf_perf_event(void)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/4] samples/bpf: Check the error of write() and read()
  2018-07-04 13:36 [PATCH v2 0/4] samples/bpf: simple fixes Taeung Song
  2018-07-04 13:36 ` [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h> Taeung Song
  2018-07-04 13:36 ` [PATCH v2 2/4] samples/bpf: Check the result of system() Taeung Song
@ 2018-07-04 13:36 ` Taeung Song
  2018-07-05  5:24   ` David Miller
  2018-07-04 13:36 ` [PATCH v2 4/4] samples/bpf: add .gitignore file Taeung Song
  2018-07-05  8:03 ` [PATCH v2 0/4] samples/bpf: simple fixes Daniel Borkmann
  4 siblings, 1 reply; 10+ messages in thread
From: Taeung Song @ 2018-07-04 13:36 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, linux-kernel, Taeung Song

test_task_rename() and test_urandom_read()
can be failed during write() and read(),
So check the result of them.

Reviewed-by: David Laight <David.Laight@ACULAB.COM>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 samples/bpf/test_overhead_user.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_user.c
index 6caf47afa635..9d6dcaa9db92 100644
--- a/samples/bpf/test_overhead_user.c
+++ b/samples/bpf/test_overhead_user.c
@@ -6,6 +6,7 @@
  */
 #define _GNU_SOURCE
 #include <sched.h>
+#include <errno.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <asm/unistd.h>
@@ -44,8 +45,13 @@ static void test_task_rename(int cpu)
 		exit(1);
 	}
 	start_time = time_get_ns();
-	for (i = 0; i < MAX_CNT; i++)
-		write(fd, buf, sizeof(buf));
+	for (i = 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);
@@ -63,8 +69,13 @@ static void test_urandom_read(int cpu)
 		exit(1);
 	}
 	start_time = time_get_ns();
-	for (i = 0; i < MAX_CNT; i++)
-		read(fd, buf, sizeof(buf));
+	for (i = 0; i < MAX_CNT; i++) {
+		if (read(fd, buf, sizeof(buf)) < 0) {
+			printf("failed to read from /dev/urandom: %s\n", strerror(errno));
+			close(fd);
+			return;
+		}
+	}
 	printf("urandom_read:%d: %lld events per sec\n",
 	       cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
 	close(fd);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 4/4] samples/bpf: add .gitignore file
  2018-07-04 13:36 [PATCH v2 0/4] samples/bpf: simple fixes Taeung Song
                   ` (2 preceding siblings ...)
  2018-07-04 13:36 ` [PATCH v2 3/4] samples/bpf: Check the error of write() and read() Taeung Song
@ 2018-07-04 13:36 ` Taeung Song
  2018-07-05  5:24   ` David Miller
  2018-07-05  8:03 ` [PATCH v2 0/4] samples/bpf: simple fixes Daniel Borkmann
  4 siblings, 1 reply; 10+ messages in thread
From: Taeung Song @ 2018-07-04 13:36 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, linux-kernel, Taeung Song

For untracked executables of samples/bpf, add this.

  Untracked files:
    (use "git add <file>..." to include in what will be committed)

  	samples/bpf/cpustat
  	samples/bpf/fds_example
  	samples/bpf/lathist
  	samples/bpf/load_sock_ops
	...

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 samples/bpf/.gitignore | 49 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 samples/bpf/.gitignore

diff --git a/samples/bpf/.gitignore b/samples/bpf/.gitignore
new file mode 100644
index 000000000000..8ae4940025f8
--- /dev/null
+++ b/samples/bpf/.gitignore
@@ -0,0 +1,49 @@
+cpustat
+fds_example
+lathist
+load_sock_ops
+lwt_len_hist
+map_perf_test
+offwaketime
+per_socket_stats_example
+sampleip
+sock_example
+sockex1
+sockex2
+sockex3
+spintest
+syscall_nrs.h
+syscall_tp
+task_fd_query
+tc_l2_redirect
+test_cgrp2_array_pin
+test_cgrp2_attach
+test_cgrp2_attach2
+test_cgrp2_sock
+test_cgrp2_sock2
+test_current_task_under_cgroup
+test_lru_dist
+test_map_in_map
+test_overhead
+test_probe_write_user
+trace_event
+trace_output
+tracex1
+tracex2
+tracex3
+tracex4
+tracex5
+tracex6
+tracex7
+xdp1
+xdp2
+xdp_adjust_tail
+xdp_fwd
+xdp_monitor
+xdp_redirect
+xdp_redirect_cpu
+xdp_redirect_map
+xdp_router_ipv4
+xdp_rxq_info
+xdp_tx_iptunnel
+xdpsock
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h>
  2018-07-04 13:36 ` [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h> Taeung Song
@ 2018-07-05  5:24   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-07-05  5:24 UTC (permalink / raw)
  To: treeze.taeung; +Cc: ast, daniel, netdev, linux-kernel

From: Taeung Song <treeze.taeung@gmail.com>
Date: Wed,  4 Jul 2018 22:36:36 +0900

> This fixes build error regarding redefinition:
> 
>     CLANG-bpf  samples/bpf/parse_varlen.o
>   samples/bpf/parse_varlen.c:111:8: error: redefinition of 'vlan_hdr'
>   struct vlan_hdr {
>          ^
>   ./include/linux/if_vlan.h:38:8: note: previous definition is here
> 
> So remove duplicate 'struct vlan_hdr' in sample code and include if_vlan.h
> 
> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/4] samples/bpf: Check the result of system()
  2018-07-04 13:36 ` [PATCH v2 2/4] samples/bpf: Check the result of system() Taeung Song
@ 2018-07-05  5:24   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-07-05  5:24 UTC (permalink / raw)
  To: treeze.taeung; +Cc: ast, daniel, netdev, linux-kernel, qinteng

From: Taeung Song <treeze.taeung@gmail.com>
Date: Wed,  4 Jul 2018 22:36:37 +0900

> To avoid the below build warning message,
> use new generate_load() checking the return value.
> 
>   ignoring return value of ‘system’, declared with attribute warn_unused_result
> 
> And it also refactors the duplicate code of both
> test_perf_event_all_cpu() and test_perf_event_task()
> 
> Cc: Teng Qin <qinteng@fb.com>
> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/4] samples/bpf: Check the error of write() and read()
  2018-07-04 13:36 ` [PATCH v2 3/4] samples/bpf: Check the error of write() and read() Taeung Song
@ 2018-07-05  5:24   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-07-05  5:24 UTC (permalink / raw)
  To: treeze.taeung; +Cc: ast, daniel, netdev, linux-kernel

From: Taeung Song <treeze.taeung@gmail.com>
Date: Wed,  4 Jul 2018 22:36:38 +0900

> test_task_rename() and test_urandom_read()
> can be failed during write() and read(),
> So check the result of them.
> 
> Reviewed-by: David Laight <David.Laight@ACULAB.COM>
> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 4/4] samples/bpf: add .gitignore file
  2018-07-04 13:36 ` [PATCH v2 4/4] samples/bpf: add .gitignore file Taeung Song
@ 2018-07-05  5:24   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-07-05  5:24 UTC (permalink / raw)
  To: treeze.taeung; +Cc: ast, daniel, netdev, linux-kernel

From: Taeung Song <treeze.taeung@gmail.com>
Date: Wed,  4 Jul 2018 22:36:39 +0900

> For untracked executables of samples/bpf, add this.
> 
>   Untracked files:
>     (use "git add <file>..." to include in what will be committed)
> 
>   	samples/bpf/cpustat
>   	samples/bpf/fds_example
>   	samples/bpf/lathist
>   	samples/bpf/load_sock_ops
> 	...
> 
> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/4] samples/bpf: simple fixes
  2018-07-04 13:36 [PATCH v2 0/4] samples/bpf: simple fixes Taeung Song
                   ` (3 preceding siblings ...)
  2018-07-04 13:36 ` [PATCH v2 4/4] samples/bpf: add .gitignore file Taeung Song
@ 2018-07-05  8:03 ` Daniel Borkmann
  4 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2018-07-05  8:03 UTC (permalink / raw)
  To: Taeung Song, Alexei Starovoitov; +Cc: netdev, linux-kernel

On 07/04/2018 03:36 PM, Taeung Song wrote:
> v2:
> - in error cases, do return; instead of break; in loop
> 
> Hello,
> This patchset fixes trivial things that I found
> when testing 'samples/bpf/' sample code.
> I'd appreciate it, if you review this.
> 
> Thanks,
> Taeung

Applied to bpf, thanks Taeung!

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-07-05  8:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-04 13:36 [PATCH v2 0/4] samples/bpf: simple fixes Taeung Song
2018-07-04 13:36 ` [PATCH v2 1/4] samples/bpf: add missing <linux/if_vlan.h> Taeung Song
2018-07-05  5:24   ` David Miller
2018-07-04 13:36 ` [PATCH v2 2/4] samples/bpf: Check the result of system() Taeung Song
2018-07-05  5:24   ` David Miller
2018-07-04 13:36 ` [PATCH v2 3/4] samples/bpf: Check the error of write() and read() Taeung Song
2018-07-05  5:24   ` David Miller
2018-07-04 13:36 ` [PATCH v2 4/4] samples/bpf: add .gitignore file Taeung Song
2018-07-05  5:24   ` David Miller
2018-07-05  8:03 ` [PATCH v2 0/4] samples/bpf: simple fixes Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.