diff mbox series

[bpf] selftests/bpf: Fix xdp_synproxy compilation failure in 32-bit arch

Message ID 20221108131242.17362-1-yangjihong1@huawei.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf] selftests/bpf: Fix xdp_synproxy compilation failure in 32-bit arch | expand

Checks

Context Check Description
bpf/vmtest-bpf-VM_Test-1 pending Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-5 success Logs for llvm-toolchain
bpf/vmtest-bpf-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with llvm-16
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 21 of 21 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 100 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-22 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-12 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-15 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-10 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on s390x with gcc

Commit Message

Yang Jihong Nov. 8, 2022, 1:12 p.m. UTC
xdp_synproxy fails to be compiled in the 32-bit arch, log is as follows:

  xdp_synproxy.c: In function 'parse_options':
  xdp_synproxy.c:175:36: error: left shift count >= width of type [-Werror=shift-count-overflow]
    175 |                 *tcpipopts = (mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;
        |                                    ^~
  xdp_synproxy.c: In function 'syncookie_open_bpf_maps':
  xdp_synproxy.c:289:28: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
    289 |                 .map_ids = (__u64)map_ids,
        |                            ^

Fix it.

Fixes: fb5cd0ce70d4 ("selftests/bpf: Add selftests for raw syncookie helpers")
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
 tools/testing/selftests/bpf/xdp_synproxy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Yonghong Song Nov. 8, 2022, 3:59 p.m. UTC | #1
On 11/8/22 5:12 AM, Yang Jihong wrote:
> xdp_synproxy fails to be compiled in the 32-bit arch, log is as follows:
> 
>    xdp_synproxy.c: In function 'parse_options':
>    xdp_synproxy.c:175:36: error: left shift count >= width of type [-Werror=shift-count-overflow]
>      175 |                 *tcpipopts = (mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;
>          |                                    ^~
>    xdp_synproxy.c: In function 'syncookie_open_bpf_maps':
>    xdp_synproxy.c:289:28: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
>      289 |                 .map_ids = (__u64)map_ids,
>          |                            ^
> 
> Fix it.
> 
> Fixes: fb5cd0ce70d4 ("selftests/bpf: Add selftests for raw syncookie helpers")
> Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
> ---
>   tools/testing/selftests/bpf/xdp_synproxy.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/xdp_synproxy.c b/tools/testing/selftests/bpf/xdp_synproxy.c
> index ff35320d2be9..45fef01a87a8 100644
> --- a/tools/testing/selftests/bpf/xdp_synproxy.c
> +++ b/tools/testing/selftests/bpf/xdp_synproxy.c
> @@ -172,7 +172,7 @@ static void parse_options(int argc, char *argv[], unsigned int *ifindex, __u32 *
>   	if (tcpipopts_mask == 0xf) {
>   		if (mss4 == 0 || mss6 == 0 || wscale == 0 || ttl == 0)
>   			usage(argv[0]);
> -		*tcpipopts = (mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;
> +		*tcpipopts = ((unsigned long long)mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;

This looks weird. Maybe we should define mss6 as unsigned long long to 
avoid this casting at all?

>   	} else if (tcpipopts_mask != 0) {
>   		usage(argv[0]);
>   	}
> @@ -286,7 +286,7 @@ static int syncookie_open_bpf_maps(__u32 prog_id, int *values_map_fd, int *ports
>   
>   	prog_info = (struct bpf_prog_info) {
>   		.nr_map_ids = 8,
> -		.map_ids = (__u64)map_ids,
> +		.map_ids = (__u64)(unsigned long)map_ids,
>   	};
>   	info_len = sizeof(prog_info);
>
Yang Jihong Nov. 11, 2022, 3:11 a.m. UTC | #2
Hello,

On 2022/11/8 23:59, Yonghong Song wrote:
> 
> 
> On 11/8/22 5:12 AM, Yang Jihong wrote:
>> xdp_synproxy fails to be compiled in the 32-bit arch, log is as follows:
>>
>>    xdp_synproxy.c: In function 'parse_options':
>>    xdp_synproxy.c:175:36: error: left shift count >= width of type 
>> [-Werror=shift-count-overflow]
>>      175 |                 *tcpipopts = (mss6 << 32) | (ttl << 24) | 
>> (wscale << 16) | mss4;
>>          |                                    ^~
>>    xdp_synproxy.c: In function 'syncookie_open_bpf_maps':
>>    xdp_synproxy.c:289:28: error: cast from pointer to integer of 
>> different size [-Werror=pointer-to-int-cast]
>>      289 |                 .map_ids = (__u64)map_ids,
>>          |                            ^
>>
>> Fix it.
>>
>> Fixes: fb5cd0ce70d4 ("selftests/bpf: Add selftests for raw syncookie 
>> helpers")
>> Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
>> ---
>>   tools/testing/selftests/bpf/xdp_synproxy.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/xdp_synproxy.c 
>> b/tools/testing/selftests/bpf/xdp_synproxy.c
>> index ff35320d2be9..45fef01a87a8 100644
>> --- a/tools/testing/selftests/bpf/xdp_synproxy.c
>> +++ b/tools/testing/selftests/bpf/xdp_synproxy.c
>> @@ -172,7 +172,7 @@ static void parse_options(int argc, char *argv[], 
>> unsigned int *ifindex, __u32 *
>>       if (tcpipopts_mask == 0xf) {
>>           if (mss4 == 0 || mss6 == 0 || wscale == 0 || ttl == 0)
>>               usage(argv[0]);
>> -        *tcpipopts = (mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;
>> +        *tcpipopts = ((unsigned long long)mss6 << 32) | (ttl << 24) | 
>> (wscale << 16) | mss4;
> 
> This looks weird. Maybe we should define mss6 as unsigned long long to 
> avoid this casting at all?
OK, will fix in next version.

Thanks,
Yang
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/xdp_synproxy.c b/tools/testing/selftests/bpf/xdp_synproxy.c
index ff35320d2be9..45fef01a87a8 100644
--- a/tools/testing/selftests/bpf/xdp_synproxy.c
+++ b/tools/testing/selftests/bpf/xdp_synproxy.c
@@ -172,7 +172,7 @@  static void parse_options(int argc, char *argv[], unsigned int *ifindex, __u32 *
 	if (tcpipopts_mask == 0xf) {
 		if (mss4 == 0 || mss6 == 0 || wscale == 0 || ttl == 0)
 			usage(argv[0]);
-		*tcpipopts = (mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;
+		*tcpipopts = ((unsigned long long)mss6 << 32) | (ttl << 24) | (wscale << 16) | mss4;
 	} else if (tcpipopts_mask != 0) {
 		usage(argv[0]);
 	}
@@ -286,7 +286,7 @@  static int syncookie_open_bpf_maps(__u32 prog_id, int *values_map_fd, int *ports
 
 	prog_info = (struct bpf_prog_info) {
 		.nr_map_ids = 8,
-		.map_ids = (__u64)map_ids,
+		.map_ids = (__u64)(unsigned long)map_ids,
 	};
 	info_len = sizeof(prog_info);