Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16F7BC27C77 for ; Fri, 14 Jun 2024 06:57:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AE61810EC3C; Fri, 14 Jun 2024 06:57:44 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Lgav/+wu"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B6A110EC36 for ; Fri, 14 Jun 2024 06:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718348259; x=1749884259; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version:content-transfer-encoding; bh=yCVLXPKtlkoNS8blC+1fPsfr2Zp1g8wKmAc+cJVLxoA=; b=Lgav/+wuSMZixGjrbSCCpgpPSQUFGrH1N8eexh6NeI3/80zwyC9Gg772 fkPWQZ4ZdoDMcvQGeb6GTnfBpDzj8aFiEKXBhzAYkO6bDEJihXcWbO4xD ugHa1OxA8Vh4BxoBA+qPI/2kMQW4DQwXbiv88HdMhrH/P1KFLvBfOjKZX aDVFuzSbCrg8JKwXN07FAFXRSDwm07I6hmyuFZBiabC9hFWIi/Xn6B1Cf 6dOHZSDlaTBdTTnZ6i5dDLk5l7HOuyVIK0oyaDD4gWpJJBrfDfijKa2QI 0/pNaqNrN8i9P46z+6HTKy1MYibE+BxDSUxfHjXJzO8k7LpC1y885xgdc Q==; X-CSE-ConnectionGUID: +RM00pptThi2sMSQ6TFJ1g== X-CSE-MsgGUID: gwHpRkxAQXWFr/AdVasfWA== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="26639776" X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="26639776" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 23:57:39 -0700 X-CSE-ConnectionGUID: zzFwDU5XTpmDrqXKJIAjtQ== X-CSE-MsgGUID: XDEysfITQECiwb1DRUW4eA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,237,1712646000"; d="scan'208";a="40260100" Received: from mridulya-mobl.amr.corp.intel.com (HELO adixit-arch.intel.com) ([10.125.147.12]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 23:57:39 -0700 Date: Thu, 13 Jun 2024 23:55:27 -0700 Message-ID: <877cest3mo.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Zbigniew =?ISO-8859-2?Q?Kempczy=F1ski?= Cc: intel-xe@lists.freedesktop.org, Matthew Brost Subject: Re: [PATCH v2] drm/xe: Explicitly cast to u64 to avoid overflow In-Reply-To: <20240614062415.260340-1-zbigniew.kempczynski@intel.com> References: <20240614062415.260340-1-zbigniew.kempczynski@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" On Thu, 13 Jun 2024 23:24:15 -0700, Zbigniew Kempczy=F1ski 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=F1ski > Cc: Matthew Brost > --- > 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_g= uc_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, st= ruct xe_sched_job *job) > xe_gt_assert(gt, timeout_ms < 100 * MSEC_PER_SEC); > > if (ctx_timestamp < ctx_job_timestamp) > - diff =3D ctx_timestamp + U32_MAX - ctx_job_timestamp; > + diff =3D (u64)ctx_timestamp + U32_MAX - ctx_job_timestamp; > else > diff =3D 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? Thanks. -- Ashutosh