linux-test-project / ltp

Linux Test Project (mailing list: https://lists.linux.it/listinfo/ltp)
https://linux-test-project.readthedocs.io/
GNU General Public License v2.0
2.31k stars 1.01k forks source link

Check integer constants are same length on 32bit and 64bit #990

Open richiejp opened 1 year ago

richiejp commented 1 year ago

If we have a constant like 1UL << 32, then it's going to be a different value on 32bit and 64bit which is usually a mistake

Mona-Bagare commented 1 year ago

Hi, Could you please elaborate a little on the issue that you are expecting to be checked?

Thanks

richiejp commented 1 year ago

This is an idea for static analysis (i.e. ltp-sparse).

coolgw commented 1 year ago

Till now seems no issue reported by this so i suppose the chance running on 32bit is low?

richiejp commented 1 year ago

We always run some tests compiled with 32bit. The ML should have some examples of errors. I usually compile and run tests with 32bit during patch review to catch these issues.

It would be nice to have more SA checks, but they are difficult to implement with our current tooling. This is a low priority ticket and could be closed if someone wants to cleanup the issue backlog.

coolgw commented 1 year ago

After some sanity check on LTP, i conclude ONLY bpf_prog05 need further check why still can work under 32.bit, correct me if i am wrong. @richiejp

grep -risn "1UL.<<.32" *

testcases/kernel/syscalls/bpf/bpf_prog05.c:111: BPF_LD_IMM64(BPF_REG_6, 1ULL << 32), testcases/kernel/syscalls/bpf/bpf_prog05.c:126: BPF_LD_IMM64(BPF_REG_6, 1ULL << 32), testcases/kernel/syscalls/bpf/bpf_prog05.c:184: expect_reg_val("src(r6)", 1ULL << 32); testcases/kernel/syscalls/bpf/bpf_prog05.c:188: expect_reg_val("src(r6)", 1ULL << 32);

testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c:27:#define FOURGB (1UL << 32) testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c:27:#define FOURGB (1UL << 32)

Test under 32bit: 1) bpf_prog05 seems still show OK result, i suppose this is what we should do cleanup? localhost:/home/ltp32/testcases/kernel/syscalls/bpf # ./bpf_prog05 tst_buffers.c:55: TINFO: Test is using guarded buffers tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s bpf_common.c:17: TINFO: Raising RLIMIT_MEMLOCK to 2162688 tst_capability.c:29: TINFO: Dropping CAP_SYS_ADMIN(21) tst_capability.c:29: TINFO: Dropping CAP_BPF(39) bpf_prog05.c:91: TINFO: Have pointer arithmetic bpf_common.c:114: TPASS: Loaded program bpf_prog05.c:183: TINFO: Check w7(-1) /= w6(0) [r7 = -1, r6 = 1 << 32] <======!!!!!!!!!! bpf_prog05.c:160: TPASS: src(r6) = 4294967296 bpf_prog05.c:160: TPASS: dst(r7) = 0 bpf_prog05.c:187: TINFO: Check w7(-1) %= w6(0) [r7 = -1, r6 = 1 << 32] bpf_prog05.c:160: TPASS: src(r6) = 4294967296 bpf_prog05.c:160: TPASS: dst(r7) = 4294967295

Summary: passed 5 failed 0 broken 0 skipped 0 warnings 0

2) The hugemmap13 already give TCONF not support 32 bit, so we do not need change anything. localhost:/home/ltp32/testcases/kernel/mem/hugetlb/hugemmap # ./hugemmap13 tst_hugepage.c:83: TINFO: 2 hugepage(s) reserved tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s hugemmap13.c:101: TCONF: Machine must be >32 bit

Summary: passed 0 failed 0 broken 0 skipped 1 warnings 0