lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201103012552.twbqzgbhc35nushq@kafai-mbp.dhcp.thefacebook.com>
Date:   Mon, 2 Nov 2020 17:25:52 -0800
From:   Martin KaFai Lau <kafai@...com>
To:     Alexander Duyck <alexander.duyck@...il.com>
CC:     <bpf@...r.kernel.org>, <ast@...nel.org>, <daniel@...earbox.net>,
        <john.fastabend@...il.com>, <kernel-team@...com>,
        <netdev@...r.kernel.org>, <edumazet@...gle.com>, <brakmo@...com>,
        <andrii.nakryiko@...il.com>, <alexanderduyck@...com>
Subject: Re: [bpf-next PATCH v2 5/5] selftest/bpf: Use global variables
 instead of maps for test_tcpbpf_kern

On Sat, Oct 31, 2020 at 11:52:37AM -0700, Alexander Duyck wrote:
[ ... ]

> +struct tcpbpf_globals global = { 0 };
>  int _version SEC("version") = 1;
>  
>  SEC("sockops")
> @@ -105,29 +72,15 @@ int bpf_testcb(struct bpf_sock_ops *skops)
>  
>  	op = (int) skops->op;
>  
> -	update_event_map(op);
> +	global.event_map |= (1 << op);
>  
>  	switch (op) {
>  	case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
>  		/* Test failure to set largest cb flag (assumes not defined) */
> -		bad_call_rv = bpf_sock_ops_cb_flags_set(skops, 0x80);
> +		global.bad_cb_test_rv = bpf_sock_ops_cb_flags_set(skops, 0x80);
>  		/* Set callback */
> -		good_call_rv = bpf_sock_ops_cb_flags_set(skops,
> +		global.good_cb_test_rv = bpf_sock_ops_cb_flags_set(skops,
>  						 BPF_SOCK_OPS_STATE_CB_FLAG);
> -		/* Update results */
> -		{
> -			__u32 key = 0;
> -			struct tcpbpf_globals g, *gp;
> -
> -			gp = bpf_map_lookup_elem(&global_map, &key);
> -			if (!gp)
> -				break;
> -			g = *gp;
> -			g.bad_cb_test_rv = bad_call_rv;
> -			g.good_cb_test_rv = good_call_rv;
> -			bpf_map_update_elem(&global_map, &key, &g,
> -					    BPF_ANY);
> -		}
>  		break;
>  	case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
>  		skops->sk_txhash = 0x12345f;
> @@ -143,10 +96,8 @@ int bpf_testcb(struct bpf_sock_ops *skops)
>  
>  				thdr = (struct tcphdr *)(header + offset);
>  				v = thdr->syn;
> -				__u32 key = 1;
>  
> -				bpf_map_update_elem(&sockopt_results, &key, &v,
> -						    BPF_ANY);
> +				global.tcp_saved_syn = v;
>  			}
>  		}
>  		break;
> @@ -156,25 +107,16 @@ int bpf_testcb(struct bpf_sock_ops *skops)
>  		break;
>  	case BPF_SOCK_OPS_STATE_CB:
>  		if (skops->args[1] == BPF_TCP_CLOSE) {
> -			__u32 key = 0;
> -			struct tcpbpf_globals g, *gp;
> -
> -			gp = bpf_map_lookup_elem(&global_map, &key);
> -			if (!gp)
> -				break;
> -			g = *gp;
>  			if (skops->args[0] == BPF_TCP_LISTEN) {
> -				g.num_listen++;
> +				global.num_listen++;
>  			} else {
> -				g.total_retrans = skops->total_retrans;
> -				g.data_segs_in = skops->data_segs_in;
> -				g.data_segs_out = skops->data_segs_out;
> -				g.bytes_received = skops->bytes_received;
> -				g.bytes_acked = skops->bytes_acked;
> +				global.total_retrans = skops->total_retrans;
> +				global.data_segs_in = skops->data_segs_in;
> +				global.data_segs_out = skops->data_segs_out;
> +				global.bytes_received = skops->bytes_received;
> +				global.bytes_acked = skops->bytes_acked;
>  			}
> -			g.num_close_events++;
> -			bpf_map_update_elem(&global_map, &key, &g,
> -					    BPF_ANY);
It is interesting that there is no race in the original "g.num_close_events++"
followed by the bpf_map_update_elem().  It seems quite fragile though.

> +			global.num_close_events++;
There is __sync_fetch_and_add().

not sure about the global.event_map though, may be use an individual
variable for each _CB.  Thoughts?

>  		}
>  		break;
>  	case BPF_SOCK_OPS_TCP_LISTEN_CB:
> @@ -182,9 +124,7 @@ int bpf_testcb(struct bpf_sock_ops *skops)
>  		v = bpf_setsockopt(skops, IPPROTO_TCP, TCP_SAVE_SYN,
>  				   &save_syn, sizeof(save_syn));
>  		/* Update global map w/ result of setsock opt */
> -		__u32 key = 0;
> -
> -		bpf_map_update_elem(&sockopt_results, &key, &v, BPF_ANY);
> +		global.tcp_save_syn = v;
>  		break;
>  	default:
>  		rv = -1;
> diff --git a/tools/testing/selftests/bpf/test_tcpbpf.h b/tools/testing/selftests/bpf/test_tcpbpf.h
> index 6220b95cbd02..0ed33521cbbb 100644
> --- a/tools/testing/selftests/bpf/test_tcpbpf.h
> +++ b/tools/testing/selftests/bpf/test_tcpbpf.h
> @@ -14,5 +14,7 @@ struct tcpbpf_globals {
>  	__u64 bytes_acked;
>  	__u32 num_listen;
>  	__u32 num_close_events;
> +	__u32 tcp_save_syn;
> +	__u32 tcp_saved_syn;
>  };
>  #endif
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ