[PATCH v2] drm/xe: Explicitly cast to u64 to avoid overflow

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Jun 14 07:00:01 UTC 2024


On Thu, Jun 13, 2024 at 11:55:27PM -0700, Dixit, Ashutosh wrote:
> On Thu, 13 Jun 2024 23:24:15 -0700, Zbigniew Kempczyński wrote:
> >
> 
> Hi Zbyzsek,
> 
> > Without casting whole expression will be calculated on u32 what
> > means adding U32_MAX effectively decreases the result by one due to
> > overflow. Fix this and use explicit cast to u64.
> >
> > Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> > Cc: Matthew Brost <matthew.brost at intel.com>
> > ---
> > v2: Fix spacing
> > ---
> >  drivers/gpu/drm/xe/xe_guc_submit.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
> > index 74552391dc5a..f46d1e18f8e7 100644
> > --- a/drivers/gpu/drm/xe/xe_guc_submit.c
> > +++ b/drivers/gpu/drm/xe/xe_guc_submit.c
> > @@ -967,7 +967,7 @@ static bool check_timeout(struct xe_exec_queue *q, struct xe_sched_job *job)
> >	xe_gt_assert(gt, timeout_ms < 100 * MSEC_PER_SEC);
> >
> >	if (ctx_timestamp < ctx_job_timestamp)
> > -		diff = ctx_timestamp + U32_MAX - ctx_job_timestamp;
> > +		diff = (u64)ctx_timestamp + U32_MAX - ctx_job_timestamp;
> >	else
> >		diff = ctx_timestamp - ctx_job_timestamp;
> 
> Looks like the function expects to be called every 100 ms, and counter
> wraps around 223 s, so previous code is fine with normal 2's complement
> arithmetic?

Yes, you're totally right. Sorry for the noise.

--
Zbigniew

> 
> Thanks.
> --
> Ashutosh


More information about the Intel-xe mailing list