Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selftests/bpf: fix compiler warnings reported in -O2 mode #5764

Closed

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: selftests/bpf: fix compiler warnings reported in -O2 mode
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=789783

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 2147c8d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=789783
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 2147c8d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=789783
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 93fb277
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=789783
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=789783
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: selftests/bpf: fix compiler warnings reported in -O2 mode
Using index info to reconstruct a base tree...
M	tools/testing/selftests/bpf/Makefile
M	tools/testing/selftests/bpf/xskxceiver.c
Falling back to patching base and 3-way merge...
Auto-merging tools/testing/selftests/bpf/xskxceiver.c
CONFLICT (content): Merge conflict in tools/testing/selftests/bpf/xskxceiver.c
Auto-merging tools/testing/selftests/bpf/Makefile
Patch failed at 0001 selftests/bpf: fix compiler warnings reported in -O2 mode
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc tools/testing/selftests/bpf/xskxceiver.c
index 837e0ffbdc47,b0ee1307a63b..000000000000
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@@ -1040,67 -1004,79 +1040,79 @@@ static int complete_pkts(struct xsk_soc
  	return TEST_PASS;
  }
  
 -static int receive_pkts(struct test_spec *test, struct pollfd *fds)
 +static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
  {
 -	struct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};
 -	struct pkt_stream *pkt_stream = test->ifobj_rx->pkt_stream;
 -	struct xsk_socket_info *xsk = test->ifobj_rx->xsk;
 +	u32 frags_processed = 0, nb_frags = 0, pkt_len = 0;
  	u32 idx_rx = 0, idx_fq = 0, rcvd, pkts_sent = 0;
 +	struct pkt_stream *pkt_stream = xsk->pkt_stream;
  	struct ifobject *ifobj = test->ifobj_rx;
  	struct xsk_umem_info *umem = xsk->umem;
 +	struct pollfd fds = { };
  	struct pkt *pkt;
 +	u64 first_addr;
  	int ret;
  
++<<<<<<< HEAD
 +	fds.fd = xsk_socket__fd(xsk->xsk);
 +	fds.events = POLLIN;
++=======
+ 	ret = gettimeofday(&tv_now, NULL);
+ 	if (ret)
+ 		exit_with_error(errno);
+ 	timeradd(&tv_now, &tv_timeout, &tv_end);
+ 
+ 	pkt = pkt_stream_get_next_rx_pkt(pkt_stream, &pkts_sent);
+ 	while (pkt) {
+ 		u32 frags_processed = 0, nb_frags = 0, pkt_len = 0;
+ 		u64 first_addr = 0;
++>>>>>>> selftests/bpf: fix compiler warnings reported in -O2 mode
  
 -		ret = gettimeofday(&tv_now, NULL);
 -		if (ret)
 -			exit_with_error(errno);
 -		if (timercmp(&tv_now, &tv_end, >)) {
 -			ksft_print_msg("ERROR: [%s] Receive loop timed out\n", __func__);
 -			return TEST_FAILURE;
 -		}
 +	ret = kick_rx(xsk);
 +	if (ret)
 +		return TEST_FAILURE;
  
 -		ret = kick_rx(xsk);
 -		if (ret)
 +	if (ifobj->use_poll) {
 +		ret = poll(&fds, 1, POLL_TMOUT);
 +		if (ret < 0)
  			return TEST_FAILURE;
  
 -		if (ifobj->use_poll) {
 -			ret = poll(fds, 1, POLL_TMOUT);
 -			if (ret < 0)
 -				return TEST_FAILURE;
 -
 -			if (!ret) {
 -				if (!is_umem_valid(test->ifobj_tx))
 -					return TEST_PASS;
 -
 -				ksft_print_msg("ERROR: [%s] Poll timed out\n", __func__);
 -				return TEST_FAILURE;
 -			}
 +		if (!ret) {
 +			if (!is_umem_valid(test->ifobj_tx))
 +				return TEST_PASS;
  
 -			if (!(fds->revents & POLLIN))
 -				continue;
 +			ksft_print_msg("ERROR: [%s] Poll timed out\n", __func__);
 +			return TEST_CONTINUE;
  		}
  
 -		rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
 -		if (!rcvd)
 -			continue;
 +		if (!(fds.revents & POLLIN))
 +			return TEST_CONTINUE;
 +	}
  
 -		if (ifobj->use_fill_ring) {
 -			ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
 -			while (ret != rcvd) {
 -				if (xsk_ring_prod__needs_wakeup(&umem->fq)) {
 -					ret = poll(fds, 1, POLL_TMOUT);
 -					if (ret < 0)
 -						return TEST_FAILURE;
 -				}
 -				ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
 +	rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
 +	if (!rcvd)
 +		return TEST_CONTINUE;
 +
 +	if (ifobj->use_fill_ring) {
 +		ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
 +		while (ret != rcvd) {
 +			if (xsk_ring_prod__needs_wakeup(&umem->fq)) {
 +				ret = poll(&fds, 1, POLL_TMOUT);
 +				if (ret < 0)
 +					return TEST_FAILURE;
  			}
 +			ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
  		}
 +	}
  
 -		while (frags_processed < rcvd) {
 -			const struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++);
 -			u64 addr = desc->addr, orig;
 +	while (frags_processed < rcvd) {
 +		const struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++);
 +		u64 addr = desc->addr, orig;
  
 -			orig = xsk_umem__extract_addr(addr);
 -			addr = xsk_umem__add_offset_to_addr(addr);
 +		orig = xsk_umem__extract_addr(addr);
 +		addr = xsk_umem__add_offset_to_addr(addr);
  
 +		if (!nb_frags) {
 +			pkt = pkt_stream_get_next_rx_pkt(pkt_stream, &pkts_sent);
  			if (!pkt) {
  				ksft_print_msg("[%s] received too many packets addr: %lx len %u\n",
  					       __func__, addr, desc->len);

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 9c8c3fa
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=790721
version: 2

Fix a bunch of potentially unitialized variable usage warnings that are
reported by GCC in -O2 mode. Also silence overzealous stringop-truncation
class of warnings.

Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Add support for building selftests with -O2 level of optimization, which
allows more compiler warnings detection (like lots of potentially
uninitialized usage), but also is useful to have a faster-running test
for some CPU-intensive tests.

One can build optimized versions of libbpf and selftests by running:

  $ make RELEASE=1

There is a measurable speed up of about 10 seconds for me locally,
though it's mostly capped by non-parallelized serial tests. User CPU
time goes down by total 40 seconds, from 1m10s to 0m28s.

Unoptimized build (-O0)
=======================
Summary: 430/3544 PASSED, 25 SKIPPED, 4 FAILED

real    1m59.937s
user    1m10.877s
sys     3m14.880s

Optimized build (-O2)
=====================
Summary: 425/3543 PASSED, 25 SKIPPED, 9 FAILED

real    1m50.540s
user    0m28.406s
sys     3m13.198s

Acked-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
We currently expect up to a three-digit number of tests and subtests, so:

  #999/999: some_test/some_subtest: ...

Is the largest test/subtest we can see. If we happen to cross into
1000s, current logic will just truncate everything after 7th character.
This patch fixes this truncate and allows to go way higher (up to 31
characters in total). We still nicely align test numbers:

  #60/66   core_reloc_btfgen/type_based___incompat:OK
  #60/67   core_reloc_btfgen/type_based___fn_wrong_args:OK
  #60/68   core_reloc_btfgen/type_id:OK
  #60/69   core_reloc_btfgen/type_id___missing_targets:OK
  #60/70   core_reloc_btfgen/enumval:OK

Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=790721 irrelevant now. Closing PR.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot deleted the series/789783=>bpf-next branch October 6, 2023 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant