]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/i915/selftests: fix subtraction overflow bug
authorAndrzej Hajda <andrzej.hajda@intel.com>
Fri, 12 Dec 2025 05:46:33 +0000 (13:46 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:10:11 +0000 (13:10 +0100)
[ Upstream commit ab3edc679c552a466e4bf0b11af3666008bd65a2 ]

On some machines hole_end can be small enough to cause subtraction
overflow. On the other side (addr + 2 * min_alignment) can overflow
in case of mock tests. This patch should handle both cases.

Fixes: e1c5f754067b59 ("drm/i915: Avoid overflow in computing pot_hole loop termination")
Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/3674
Signed-off-by: Andrzej Hajda <andrzej.hajda@intel.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220624113528.2159210-1-andrzej.hajda@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
[ Using I915_GTT_PAGE_SIZE instead of min_alignment due to 5.15 missing commit:87bd701ee268 ("drm/i915: enforce min GTT alignment for discrete cards")]
Signed-off-by: Rajani Kantha <681739313@139.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c

index df3934a990d0857af6cd39d0afaa42d0e2dbfce3..cd0494b849597a157a04a905722ae31328aca37a 100644 (file)
@@ -715,7 +715,7 @@ static int pot_hole(struct i915_address_space *vm,
                u64 addr;
 
                for (addr = round_up(hole_start + I915_GTT_PAGE_SIZE, step) - I915_GTT_PAGE_SIZE;
-                    addr <= round_down(hole_end - 2*I915_GTT_PAGE_SIZE, step) - I915_GTT_PAGE_SIZE;
+                    hole_end > addr && hole_end - addr >= 2 * I915_GTT_PAGE_SIZE;
                     addr += step) {
                        err = i915_vma_pin(vma, 0, 0, addr | flags);
                        if (err) {