Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1399363ybv; Thu, 13 Feb 2020 22:36:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxrKfO3ovn8gdrgiq9pR1FlVuOckCW1ZDNkFbPzTnmfLyDRLw8utrDgww5eR51lBJV3j4xd X-Received: by 2002:a05:6830:12c3:: with SMTP id a3mr1072135otq.341.1581662186357; Thu, 13 Feb 2020 22:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581662186; cv=none; d=google.com; s=arc-20160816; b=z4GvfSJh9RWLBLMZBlSHjUcmOFXIrFRQem/325CNufipY/JWyqy9V5yHs33uNzGtVF Y3Ef4qbcZkdIINnOBLeSy5aMshqqjTTGM7+ENYlVrPojWzZVQedhNSsZwqo5/RqRuynb Fz7ZAz4UQO2BtB+wp2RWIfCynrLjISNtjm0cgtot+ErskY3L2zThMjkrSfdINBw0iG1I qEuuYwjjtm4sxV52MnPdfTc2JxS/3tix9wfj6d+AkQjqX3TU09vzTgFePU8tKM0yJwYe iJ2c3Gw+xGMOZoAwInXlT5NF59YPYGb55wh1DgHW2qv8/hq+vecPa865rLbrEq8dP+WJ 1G2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:references:organization:in-reply-to:subject:cc:to :from; bh=+0vUTo00whMG1QKritdMR6/RcaYTUhJvkzs13it3w5c=; b=DXhkKEufl8bbZ6MU8DryX1HJ1lMiXrjPxU8/GL1xzRsVfYpCaQALNO9NEFytr0TOIA +gtdA5f0G+3VEIe3gG02TP+g4hy9d2KuVliSiASYUH1hD1BD+0V/KaDgIyD9uPUTNTqp ugTPKr0kkktTKtC50okhN1uNRRSgrIM+ga+fWJJZS6d26nFtH0TjP2vpQpcPoGyc9SzR cndudKlgJiLdLkxFXMfshCeRzU3AY47kETtsHRj1fyhhXYNj8NR24hag2XrRBBtiqDyf wCv4P94RZMc5oLhd1z5I+EeFEcMdyCi6pil+s/d9rFqEVJ4WpU5mAPjg+7o6wyFjOZqX bluA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si2356369otn.189.2020.02.13.22.36.14; Thu, 13 Feb 2020 22:36:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728881AbgBNGfw convert rfc822-to-8bit (ORCPT + 99 others); Fri, 14 Feb 2020 01:35:52 -0500 Received: from mga09.intel.com ([134.134.136.24]:50157 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725990AbgBNGfv (ORCPT ); Fri, 14 Feb 2020 01:35:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2020 22:35:51 -0800 X-IronPort-AV: E=Sophos;i="5.70,439,1574150400"; d="scan'208";a="227499154" Received: from ablank-mobl.ger.corp.intel.com (HELO localhost) ([10.252.39.179]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2020 22:35:48 -0800 From: Jani Nikula To: Nathan Chancellor , Joonas Lahtinen , Rodrigo Vivi Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nathan Chancellor , Michel =?utf-8?Q?D=C3=A4nzer?= , Chris Wilson Subject: Re: [PATCH] drm/i915: Cast remain to unsigned long in eb_relocate_vma In-Reply-To: <20200214054706.33870-1-natechancellor@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20200214054706.33870-1-natechancellor@gmail.com> Date: Fri, 14 Feb 2020 08:36:15 +0200 Message-ID: <87v9o965gg.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Feb 2020, Nathan Chancellor wrote: > A recent commit in clang added -Wtautological-compare to -Wall, which is > enabled for i915 after -Wtautological-compare is disabled for the rest > of the kernel so we see the following warning on x86_64: > > ../drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1433:22: warning: > result of comparison of constant 576460752303423487 with expression of > type 'unsigned int' is always false > [-Wtautological-constant-out-of-range-compare] > if (unlikely(remain > N_RELOC(ULONG_MAX))) > ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ > ../include/linux/compiler.h:78:42: note: expanded from macro 'unlikely' > # define unlikely(x) __builtin_expect(!!(x), 0) > ^ > 1 warning generated. > > It is not wrong in the case where ULONG_MAX > UINT_MAX but it does not > account for the case where this file is built for 32-bit x86, where > ULONG_MAX == UINT_MAX and this check is still relevant. > > Cast remain to unsigned long, which keeps the generated code the same > (verified with clang-11 on x86_64 and GCC 9.2.0 on x86 and x86_64) and > the warning is silenced so we can catch more potential issues in the > future. > > Link: https://github.com/ClangBuiltLinux/linux/issues/778 > Suggested-by: Michel Dänzer > Signed-off-by: Nathan Chancellor Works for me as a workaround, Reviewed-by: Jani Nikula > --- > > Round 3 :) > > Previous threads/patches: > > https://lore.kernel.org/lkml/20191123195321.41305-1-natechancellor@gmail.com/ > https://lore.kernel.org/lkml/20200211050808.29463-1-natechancellor@gmail.com/ > > drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c > index 60c984e10c4a..47f4d8ab281e 100644 > --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c > +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c > @@ -1430,7 +1430,7 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma) > > urelocs = u64_to_user_ptr(entry->relocs_ptr); > remain = entry->relocation_count; > - if (unlikely(remain > N_RELOC(ULONG_MAX))) > + if (unlikely((unsigned long)remain > N_RELOC(ULONG_MAX))) > return -EINVAL; > > /* -- Jani Nikula, Intel Open Source Graphics Center