Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The custom helper `__div_round_up64` silently truncates 64-bit divisors to 32 bits, creating a mathematically unsound helper. - [Low] Inverted architecture check for 64-bit division causes a `__divdi3` link error on 32-bit builds, and needlessly uses a custom fallback on 64-bit builds. --
commit 2d4751e6d3870228fa27b4fdbbb10070a48ae9ce Author: Alan Previn <[email protected]> drm/xe/mmio: Fix xe_mmio_wait32() to honor delay/sleep maximums This commit fixes xe_mmio_wait32() to honor delay and sleep maximums by checking for overflow in udelay and usleep_range. It also adds a custom 64-bit division helper and caps the in-loop wait time to prevent intolerably large delays. > diff --git a/drivers/gpu/drm/xe/xe_mmio.c b/drivers/gpu/drm/xe/xe_mmio.c > index 7fa18dfcb5a28..1ae382f009de5 100644 > --- a/drivers/gpu/drm/xe/xe_mmio.c > +++ b/drivers/gpu/drm/xe/xe_mmio.c [ ... ] > +static inline s64 __div_round_up64(s64 dividend, s64 divisor) > +{ > + u64 abs_dividend = abs(dividend); > + u64 abs_divisor = abs(divisor); > + u64 result = abs_dividend + abs_divisor - 1; > + > + do_div(result, abs_divisor); [Severity: Medium] Does passing a 64-bit divisor to do_div() cause silent truncation here? The do_div() macro is strictly designed for 32-bit divisors and will silently truncate the 64-bit abs_divisor parameter. While the current caller in __xe_mmio_wait32() only passes USEC_PER_MSEC (which fits in 32 bits), creating a generic helper that accepts an s64 divisor is structurally unsafe. Could this use DIV64_U64_ROUND_UP() from linux/math64.h instead? > + /* dont check for negative values as local caller only uses positive > numbers */ > + return (s64)result; > +} [ ... ] > @@ -349,11 +375,25 @@ static int __xe_mmio_wait32(struct xe_mmio *mmio, > struct xe_reg reg, u32 mask, u [ ... ] > - if (atomic) > - udelay(wait); > - else > - usleep_range(wait, wait << 1); > - wait <<= 1; > +#define __XE_MMIO_WAIT_MAX_INLOOP_100MS (100 * USEC_PER_MSEC) > + if (atomic) { > + if (wait <= MAX_UDELAY_MS * USEC_PER_MSEC) > + udelay(wait); > + else if (BITS_PER_LONG == 32) > + mdelay(DIV_ROUND_UP(wait, USEC_PER_MSEC)); [Severity: Low] Does this architecture check invert the intended 64-bit division logic? When BITS_PER_LONG == 32, this branch executes the native 64-bit division DIV_ROUND_UP(wait, USEC_PER_MSEC). This causes a __divdi3 unresolved symbol link error on 32-bit builds, which appears to be the exact build break this helper was intended to avoid. > + else > + mdelay(__div_round_up64(wait, USEC_PER_MSEC)); Consequently, 64-bit builds will take this else branch and needlessly use the custom division helper instead of the native division macro. > + } else { > + usleep_range(wait, wait + (wait >> 2)); /* range till > wait + 25% */ > + } [ ... ] -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
