* [PATCH] selftest/mm: fix pointer comparison in mremap_test
@ 2025-11-06 10:49 Ankit Khushwaha
2025-11-06 11:18 ` David Hildenbrand (Red Hat)
2025-11-06 14:40 ` Lorenzo Stoakes
0 siblings, 2 replies; 11+ messages in thread
From: Ankit Khushwaha @ 2025-11-06 10:49 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm,
linux-kselftest
Cc: linux-kernel, Ankit Khushwaha
Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment'
triggers following warning:
mremap_test.c:1035:31: warning: pointer comparison always evaluates to
false [-Wtautological-compare]
1035 | if (addr + c.dest_alignment < addr) {
| ^
typecasting 'addr' to 'unsigned long long' to fix pointer comparison.
Signed-off-by: Ankit Khushwaha <ankitkhushwaha.linux@gmail.com>
---
tools/testing/selftests/mm/mremap_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
index a95c0663a011..5ae0400176af 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -1032,7 +1032,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
/* Don't destroy existing mappings unless expected to overlap */
while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) {
/* Check for unsigned overflow */
- if (addr + c.dest_alignment < addr) {
+ if ((unsigned long long) addr + c.dest_alignment < (unsigned long long) addr) {
ksft_print_msg("Couldn't find a valid region to remap to\n");
ret = -1;
goto clean_up_src;
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-06 10:49 [PATCH] selftest/mm: fix pointer comparison in mremap_test Ankit Khushwaha @ 2025-11-06 11:18 ` David Hildenbrand (Red Hat) 2025-11-06 12:02 ` Ankit Khushwaha 2025-11-06 14:40 ` Lorenzo Stoakes 1 sibling, 1 reply; 11+ messages in thread From: David Hildenbrand (Red Hat) @ 2025-11-06 11:18 UTC (permalink / raw) To: Ankit Khushwaha, Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest Cc: linux-kernel On 06.11.25 11:49, Ankit Khushwaha wrote: > Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > triggers following warning: > > mremap_test.c:1035:31: warning: pointer comparison always evaluates to > false [-Wtautological-compare] > 1035 | if (addr + c.dest_alignment < addr) { > | ^ > > typecasting 'addr' to 'unsigned long long' to fix pointer comparison. With which compiler are you seeing this? -- Cheers David ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-06 11:18 ` David Hildenbrand (Red Hat) @ 2025-11-06 12:02 ` Ankit Khushwaha 2025-11-06 14:26 ` Lorenzo Stoakes 2025-11-07 9:27 ` David Hildenbrand (Red Hat) 0 siblings, 2 replies; 11+ messages in thread From: Ankit Khushwaha @ 2025-11-06 12:02 UTC (permalink / raw) To: David Hildenbrand (Red Hat) Cc: Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote: > On 06.11.25 11:49, Ankit Khushwaha wrote: > > Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > > triggers following warning: > > > > mremap_test.c:1035:31: warning: pointer comparison always evaluates to > > false [-Wtautological-compare] > > 1035 | if (addr + c.dest_alignment < addr) { > > | ^ > > > > typecasting 'addr' to 'unsigned long long' to fix pointer comparison. > > With which compiler are you seeing this? Hi David, clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning. To reproduce: make -C tools/testing/selftests/mm CC=clang Thanks, -- Ankit ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-06 12:02 ` Ankit Khushwaha @ 2025-11-06 14:26 ` Lorenzo Stoakes 2025-11-07 9:27 ` David Hildenbrand (Red Hat) 1 sibling, 0 replies; 11+ messages in thread From: Lorenzo Stoakes @ 2025-11-06 14:26 UTC (permalink / raw) To: Ankit Khushwaha Cc: David Hildenbrand (Red Hat), Andrew Morton, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On Thu, Nov 06, 2025 at 05:32:47PM +0530, Ankit Khushwaha wrote: > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote: > > On 06.11.25 11:49, Ankit Khushwaha wrote: > > > Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > > > triggers following warning: > > > > > > mremap_test.c:1035:31: warning: pointer comparison always evaluates to > > > false [-Wtautological-compare] > > > 1035 | if (addr + c.dest_alignment < addr) { > > > | ^ > > > > > > typecasting 'addr' to 'unsigned long long' to fix pointer comparison. > > > > With which compiler are you seeing this? > > Hi David, > > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning. > > To reproduce: > make -C tools/testing/selftests/mm CC=clang FYI That doesn't work: $ make -C tools/testing/selftests/mm CC=clang make: Entering directory '/data/kerndev/kernels/mm/tools/testing/selftests/mm' warning: the compiler differs from the one used to build the kernel The kernel was built by: gcc (GCC) 15.2.1 20250813 You are using: clang version 20.1.8 CC [M] page_frag_test.o clang: error: unknown argument: '-fmin-function-alignment=16' clang: error: unknown argument: '-fconserve-stack' clang: error: unsupported option '-mrecord-mcount' for target 'x86_64-unknown-linux-gnu' make[4]: *** [/usr/lib/modules/6.17.2-arch1-1/build/scripts/Makefile.build:287: page_frag_test.o] Error 1 make[3]: *** [/usr/lib/modules/6.17.2-arch1-1/build/Makefile:2011: .] Error 2 make[2]: *** [Makefile:248: __sub-make] Error 2 make[1]: *** [Makefile:15: all] Error 2 make: *** [../lib.mk:146: gen_mods_dir] Error 2 make: Leaving directory '/data/kerndev/kernels/mm/tools/testing/selftests/mm' [649ms][2][review/loz-v2][~/kerndev/kernels/mm]$ cd tools/testing/selftests/mm Even if I rebuild the entire kernel using clang via LLVM=1 it doesn't work. The following KIND OF works: $ make -C tools/testing/selftests/mm clean $ make tools/testing/selftests/mm LLVM=1 But I still get: warning: the compiler differs from the one used to build the kernel The kernel was built by: gcc (GCC) 15.2.1 20250813 You are using: clang version 20.1.8 CC [M] page_frag_test.o clang: error: unknown argument: '-fmin-function-alignment=16' clang: error: unknown argument: '-fconserve-stack' clang: error: unsupported option '-mrecord-mcount' for target 'x86_64-unknown-linux-gnu' make[4]: *** [/usr/lib/modules/6.17.2-arch1-1/build/scripts/Makefile.build:287: page_frag_test.o] Error 1 make[3]: *** [/usr/lib/modules/6.17.2-arch1-1/build/Makefile:2011: .] Error 2 make[2]: *** [Makefile:248: __sub-make] Error 2 make[1]: *** [Makefile:15: all] Error 2 make: *** [../lib.mk:146: gen_mods_dir] Error 2 make: Leaving directory '/data/kerndev/kernels/mm/tools/testing/selftests/mm' Errors, presumably unless you build _the entire kernel_ using LLVM=1 :) > > Thanks, > -- > Ankit It may be worth looking at how to make this behave better because this seems silly if clang will pick up additional warnings. Cheers, Lorenzo ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-06 12:02 ` Ankit Khushwaha 2025-11-06 14:26 ` Lorenzo Stoakes @ 2025-11-07 9:27 ` David Hildenbrand (Red Hat) 2025-11-08 0:08 ` Andrew Morton 1 sibling, 1 reply; 11+ messages in thread From: David Hildenbrand (Red Hat) @ 2025-11-07 9:27 UTC (permalink / raw) To: Ankit Khushwaha Cc: Andrew Morton, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On 06.11.25 13:02, Ankit Khushwaha wrote: > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote: >> On 06.11.25 11:49, Ankit Khushwaha wrote: >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' >>> triggers following warning: >>> >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to >>> false [-Wtautological-compare] >>> 1035 | if (addr + c.dest_alignment < addr) { >>> | ^ >>> >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison. >> >> With which compiler are you seeing this? > > Hi David, > > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning. > > To reproduce: > make -C tools/testing/selftests/mm CC=clang Thanks, and thanks to Lorenzo for the details. Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> -- Cheers David ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-07 9:27 ` David Hildenbrand (Red Hat) @ 2025-11-08 0:08 ` Andrew Morton 2025-11-08 16:03 ` Ankit Khushwaha 2025-11-09 6:54 ` Mike Rapoport 0 siblings, 2 replies; 11+ messages in thread From: Andrew Morton @ 2025-11-08 0:08 UTC (permalink / raw) To: David Hildenbrand (Red Hat) Cc: Ankit Khushwaha, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On Fri, 7 Nov 2025 10:27:27 +0100 "David Hildenbrand (Red Hat)" <david@kernel.org> wrote: > On 06.11.25 13:02, Ankit Khushwaha wrote: > > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote: > >> On 06.11.25 11:49, Ankit Khushwaha wrote: > >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > >>> triggers following warning: > >>> > >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to > >>> false [-Wtautological-compare] > >>> 1035 | if (addr + c.dest_alignment < addr) { > >>> | ^ > >>> > >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison. > >> > >> With which compiler are you seeing this? > > > > Hi David, > > > > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning. > > > > To reproduce: > > make -C tools/testing/selftests/mm CC=clang > > Thanks, and thanks to Lorenzo for the details. > > Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> I must say, applying this would be an unhappy life event. if (void* + ulong < void*) makes perfect sense in a world which permits void* arithmetic (ie, ours). So what the heck is clang doing?? If we do void *addr2 = addr + c.dest_alignment; if (addr2 < addr) ... then which statement warns, and why? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-08 0:08 ` Andrew Morton @ 2025-11-08 16:03 ` Ankit Khushwaha 2025-11-09 6:54 ` Mike Rapoport 1 sibling, 0 replies; 11+ messages in thread From: Ankit Khushwaha @ 2025-11-08 16:03 UTC (permalink / raw) To: Andrew Morton Cc: David Hildenbrand (Red Hat), Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On Fri, Nov 07, 2025 at 04:08:55PM -0800, Andrew Morton wrote: > > void *addr2 = addr + c.dest_alignment; > if (addr2 < addr) > ... > Hi Andrew, i have tried this and clang is raising no warning. I will send v2 patch with this changes. Thanks -- Ankit ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-08 0:08 ` Andrew Morton 2025-11-08 16:03 ` Ankit Khushwaha @ 2025-11-09 6:54 ` Mike Rapoport 2025-11-09 19:11 ` Vlastimil Babka 1 sibling, 1 reply; 11+ messages in thread From: Mike Rapoport @ 2025-11-09 6:54 UTC (permalink / raw) To: Andrew Morton, Nathan Chancellor Cc: David Hildenbrand (Red Hat), Ankit Khushwaha, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel (added Nathan for clang advice) On Fri, Nov 07, 2025 at 04:08:55PM -0800, Andrew Morton wrote: > On Fri, 7 Nov 2025 10:27:27 +0100 "David Hildenbrand (Red Hat)" <david@kernel.org> wrote: > > > On 06.11.25 13:02, Ankit Khushwaha wrote: > > > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote: > > >> On 06.11.25 11:49, Ankit Khushwaha wrote: > > >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > > >>> triggers following warning: > > >>> > > >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to > > >>> false [-Wtautological-compare] > > >>> 1035 | if (addr + c.dest_alignment < addr) { > > >>> | ^ > > >>> > > >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison. > > >> > > >> With which compiler are you seeing this? > > > > > > Hi David, > > > > > > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning. > > > > > > To reproduce: > > > make -C tools/testing/selftests/mm CC=clang > > > > Thanks, and thanks to Lorenzo for the details. > > > > Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> > > I must say, applying this would be an unhappy life event. > > if (void* + ulong < void*) > > makes perfect sense in a world which permits void* arithmetic (ie, > ours). So what the heck is clang doing?? > > If we do > > void *addr2 = addr + c.dest_alignment; > if (addr2 < addr) > ... > > then which statement warns, and why? -- Sincerely yours, Mike. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-09 6:54 ` Mike Rapoport @ 2025-11-09 19:11 ` Vlastimil Babka 2025-11-10 21:43 ` Nathan Chancellor 0 siblings, 1 reply; 11+ messages in thread From: Vlastimil Babka @ 2025-11-09 19:11 UTC (permalink / raw) To: Mike Rapoport, Andrew Morton, Nathan Chancellor Cc: David Hildenbrand (Red Hat), Ankit Khushwaha, Lorenzo Stoakes, Liam R. Howlett, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On 11/9/25 07:54, Mike Rapoport wrote: > (added Nathan for clang advice) > > On Fri, Nov 07, 2025 at 04:08:55PM -0800, Andrew Morton wrote: >> On Fri, 7 Nov 2025 10:27:27 +0100 "David Hildenbrand (Red Hat)" <david@kernel.org> wrote: >> >> > On 06.11.25 13:02, Ankit Khushwaha wrote: >> > > On Thu, Nov 06, 2025 at 12:18:57PM +0100, David Hildenbrand (Red Hat) wrote: >> > >> On 06.11.25 11:49, Ankit Khushwaha wrote: >> > >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' >> > >>> triggers following warning: >> > >>> >> > >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to >> > >>> false [-Wtautological-compare] >> > >>> 1035 | if (addr + c.dest_alignment < addr) { >> > >>> | ^ >> > >>> >> > >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison. >> > >> >> > >> With which compiler are you seeing this? >> > > >> > > Hi David, >> > > >> > > clang version 20.1.8 (Fedora 20.1.8-4.fc42) raised this warning. >> > > >> > > To reproduce: >> > > make -C tools/testing/selftests/mm CC=clang >> > >> > Thanks, and thanks to Lorenzo for the details. >> > >> > Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> >> >> I must say, applying this would be an unhappy life event. >> >> if (void* + ulong < void*) >> >> makes perfect sense in a world which permits void* arithmetic (ie, >> ours). So what the heck is clang doing?? My (not very informed) guess would be something about undefined behavior because pointer arithmetic is strictly speaking only valid within an array, so void* + ulong is also still in the same array, and thus can't become smaller by an overflow, because overflow can't happen if we're still within the same valid array... But I don't know if this strictness is only applied to the warning itself or to the actual compilation too (does it eliminate everything as dead code then?) >> If we do >> >> void *addr2 = addr + c.dest_alignment; >> if (addr2 < addr) >> ... >> >> then which statement warns, and why? As the answer was that nothing warns, I'd think it just isn't able to warn if it's no longer part of the same statement. Whether it also means it's not eliminated as dead code anymore, dunno. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-09 19:11 ` Vlastimil Babka @ 2025-11-10 21:43 ` Nathan Chancellor 0 siblings, 0 replies; 11+ messages in thread From: Nathan Chancellor @ 2025-11-10 21:43 UTC (permalink / raw) To: Vlastimil Babka Cc: Mike Rapoport, Andrew Morton, David Hildenbrand (Red Hat), Ankit Khushwaha, Lorenzo Stoakes, Liam R. Howlett, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On Sun, Nov 09, 2025 at 08:11:09PM +0100, Vlastimil Babka wrote: > >> > >>> Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > >> > >>> triggers following warning: > >> > >>> > >> > >>> mremap_test.c:1035:31: warning: pointer comparison always evaluates to > >> > >>> false [-Wtautological-compare] > >> > >>> 1035 | if (addr + c.dest_alignment < addr) { > >> > >>> | ^ > >> > >>> > >> > >>> typecasting 'addr' to 'unsigned long long' to fix pointer comparison. ... > >> I must say, applying this would be an unhappy life event. > >> > >> if (void* + ulong < void*) > >> > >> makes perfect sense in a world which permits void* arithmetic (ie, > >> ours). So what the heck is clang doing?? > > My (not very informed) guess would be something about undefined behavior > because pointer arithmetic is strictly speaking only valid within an array, > so void* + ulong is also still in the same array, and thus can't become > smaller by an overflow, because overflow can't happen if we're still within > the same valid array... It is indeed due to undefined behavior but more so that without -fwrapv-pointer (set via -fno-strict-overflow for the kernel build), the addition of an unsigned index and a pointer cannot wrap. This warning is a result of the following change in clang-20: https://github.com/llvm/llvm-project/commit/6d34cfac53b993a6cdf3d6669e017eac3a2296c8 https://godbolt.org/z/hvMoPYb17 which I made sure respected the value of -fwrapv-pointer in https://github.com/llvm/llvm-project/commit/f0dcf3240dffe3767c7f3a2e2da5b92ae9fd1bef But it looks like the mm selftests do not build with -fno-strict-overflow. Maybe it should? > But I don't know if this strictness is only applied to the warning itself or > to the actual compilation too (does it eliminate everything as dead code then?) Yes, it would turn that if (addr + c.dest_alignment < addr) { into just if (false) { based on the above Godbolt link. > >> If we do > >> > >> void *addr2 = addr + c.dest_alignment; > >> if (addr2 < addr) > >> ... > >> > >> then which statement warns, and why? > > As the answer was that nothing warns, I'd think it just isn't able to warn > if it's no longer part of the same statement. Whether it also means it's not > eliminated as dead code anymore, dunno. Based on the above Godbolt link, it appears it will be optimized the same way, just without the warning letting you know something is up. Cheers, Nathan ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] selftest/mm: fix pointer comparison in mremap_test 2025-11-06 10:49 [PATCH] selftest/mm: fix pointer comparison in mremap_test Ankit Khushwaha 2025-11-06 11:18 ` David Hildenbrand (Red Hat) @ 2025-11-06 14:40 ` Lorenzo Stoakes 1 sibling, 0 replies; 11+ messages in thread From: Lorenzo Stoakes @ 2025-11-06 14:40 UTC (permalink / raw) To: Ankit Khushwaha Cc: Andrew Morton, David Hildenbrand, Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan, linux-mm, linux-kselftest, linux-kernel On Thu, Nov 06, 2025 at 04:19:17PM +0530, Ankit Khushwaha wrote: > Pointer arthemitic with 'void * addr' and 'unsigned long long dest_alignment' > triggers following warning: > > mremap_test.c:1035:31: warning: pointer comparison always evaluates to > false [-Wtautological-compare] > 1035 | if (addr + c.dest_alignment < addr) { > | ^ > > typecasting 'addr' to 'unsigned long long' to fix pointer comparison. Thanks for raising! > > Signed-off-by: Ankit Khushwaha <ankitkhushwaha.linux@gmail.com> See below, but the fix seems ok despite the existing code being really horrible + in need of rework: Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> > --- > tools/testing/selftests/mm/mremap_test.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c > index a95c0663a011..5ae0400176af 100644 > --- a/tools/testing/selftests/mm/mremap_test.c > +++ b/tools/testing/selftests/mm/mremap_test.c > @@ -1032,7 +1032,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb, > /* Don't destroy existing mappings unless expected to overlap */ > while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) { > /* Check for unsigned overflow */ > - if (addr + c.dest_alignment < addr) { > + if ((unsigned long long) addr + c.dest_alignment < (unsigned long long) addr) { Hmm this is odd though. gcc (and presumably for compatibility clang) treat void * arithmetic as if void * was of size 1, so on 64-bit systems this should be: 64-bit value + 64-bit value < 64-bit value Which is a valid check for overflow right? On 32-bit it seems even more so: 32-bit value + 64-bit value < 64-bit value So I'm not sure why this warning is happening. Maybe clang is doing some very clever checks to determine this is false. In practice I don't see how this could happen given userland pointers are already restricted on upper bits. BUT at the same time this is something that the rest of the test code does so it seems fine to take this. Also, (to be clear - it's not your fault Ankit): This (existing code) is horrible, I don't know why we're using unsigned long long _anyway_ here, the whole function is appalling. Your fix is in line with the existing code but is still quite horrible (again _not your fault_ :). So on the basis that it shuts this error up I guess we can take this patch as the fix is equally as gross as the existing code, but can we please: a. do away with the unsigned long long nonsense if possible (presumably to try to detect overflow on 32-bit systems, but I do not understand why we are bothering it seems totally overengineered and pointless for arbitrary mremap tests) b. For the love of all spiders, cats and other beautiful things on planet earth, let's please store a local unsigned long variable for the address and convert from void * _once_ :) > ksft_print_msg("Couldn't find a valid region to remap to\n"); > ret = -1; > goto clean_up_src; > -- > 2.51.0 > Thanks, Lorenzo ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-11-10 21:43 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-06 10:49 [PATCH] selftest/mm: fix pointer comparison in mremap_test Ankit Khushwaha 2025-11-06 11:18 ` David Hildenbrand (Red Hat) 2025-11-06 12:02 ` Ankit Khushwaha 2025-11-06 14:26 ` Lorenzo Stoakes 2025-11-07 9:27 ` David Hildenbrand (Red Hat) 2025-11-08 0:08 ` Andrew Morton 2025-11-08 16:03 ` Ankit Khushwaha 2025-11-09 6:54 ` Mike Rapoport 2025-11-09 19:11 ` Vlastimil Babka 2025-11-10 21:43 ` Nathan Chancellor 2025-11-06 14:40 ` Lorenzo Stoakes
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).