[igt-dev] [PATCH i-g-t 1/2] lib: Beware implicit sign extension on large constants

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Mon Jun 21 10:59:21 UTC 2021


From: Chris Wilson <chris.p.wilson at intel.com>

(gdb) p/x (long long unsigned int)(1 << 31)
$1 = 0xffffffff80000000
(gdb) p/x (long long unsigned int)(1u << 31)
$2 = 0x80000000

The impact of this is that the random address we were placing the spinner
at was always invalid on modern machines, causing the kernel to relocate
the spinners wherever and thus undergoing relocations.

Signed-off-by: Chris Wilson <chris.p.wilson at intel.com>
---
 lib/igt_dummyload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c
index 82459e524..63b1fc73b 100644
--- a/lib/igt_dummyload.c
+++ b/lib/igt_dummyload.c
@@ -119,7 +119,7 @@ emit_recursive_batch(igt_spin_t *spin,
 	 */
 	addr = gem_aperture_size(fd) / 2;
 	if (addr >> 31)
-		addr = 1 << 31;
+		addr = 1u << 31;
 	addr += random() % addr / 2;
 	addr &= -4096;
 
-- 
2.26.0



More information about the igt-dev mailing list