Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1881524ybv; Fri, 14 Feb 2020 07:36:42 -0800 (PST) X-Google-Smtp-Source: APXvYqxvMU0X99LNyC3jJnDXhixIt3YPHnHy7rMFWEFhsYsd2Sr8iqfLrMbbSFLB7wwdFrkZGwte X-Received: by 2002:a05:6830:1d7b:: with SMTP id l27mr2586233oti.251.1581694601963; Fri, 14 Feb 2020 07:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581694601; cv=none; d=google.com; s=arc-20160816; b=ZpKT0VTVcRBcYMEgyHD45lJz3GT1zMi0xEfV/xSmYzlhzDrNUE5agnRhnpNLZjMm+M Db2OI8+ZTd/OKqS9Jrnp57jX2EHRQ2XRTiTL0XIH0yDJkHd5adlnv82msRkR51tSb8WM zNhYTiJDIVl+leomb5cgCvoC09zEsqdHqIUbD61bXgEYydtwTnXepkDOacGhzD0s4gdV Dd/DzqioFyNvcQZFbY6lxtoyHGqt20cJFdUc5pWsZ+R7A1aoQFeXKEDiovgb9PydVSmS A8ytcs18Osr6gPaytuPupme1GwTk6t1kNCxR2NhGwWCZ5H1JAEGrq3fadiAWJUenclG5 ieoQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=5/YMGbcVxrKES+tSdpaFaI7ZCYvsepdC8GfJ2T7UFlg=; b=KC8+4OKPa2SlVFphtZyVFG4RLJpV9MfTD+PvmL/P8nMR2VRQXm+soheQGXo3CjCamT zf6jdMF6/HYMMcKp+v8zLHmx8tBzTa3nHqREw01o2xSFhd7qVVuYpVQpDBuXAhO7F5WM s8o1YFSB8fVxEJoW9sI6WOmCYyaDxIznK6TFNcTjRHBl6NQSgGxsTnF0OATL/beew+UE 9w6LfAGMedrxVQCcusUJqd8ykmlOCOMOHP8wQ4cteXTL2a7qx91pWO571L7/hApGqBq0 D9iOhfifUyD9uy5dxoCT04DmiY+J6GCJSLbHObXQ6XKMb75RCVimwAuuZ/OBlDvDEuto qvxg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si2965333oti.226.2020.02.14.07.36.28; Fri, 14 Feb 2020 07:36:41 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729472AbgBNPgX (ORCPT + 99 others); Fri, 14 Feb 2020 10:36:23 -0500 Received: from mail.netline.ch ([148.251.143.178]:57912 "EHLO netline-mail3.netline.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbgBNPgX (ORCPT ); Fri, 14 Feb 2020 10:36:23 -0500 Received: from localhost (localhost [127.0.0.1]) by netline-mail3.netline.ch (Postfix) with ESMTP id C35892A6046; Fri, 14 Feb 2020 16:36:19 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at netline-mail3.netline.ch Received: from netline-mail3.netline.ch ([127.0.0.1]) by localhost (netline-mail3.netline.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id hkjvpc2T5O5o; Fri, 14 Feb 2020 16:36:19 +0100 (CET) Received: from thor (252.80.76.83.dynamic.wline.res.cust.swisscom.ch [83.76.80.252]) by netline-mail3.netline.ch (Postfix) with ESMTPSA id 2BE0F2A6045; Fri, 14 Feb 2020 16:36:19 +0100 (CET) Received: from localhost ([::1]) by thor with esmtp (Exim 4.93) (envelope-from ) id 1j2d0r-000ACQ-Qm; Fri, 14 Feb 2020 16:36:17 +0100 Subject: Re: [PATCH] drm/i915: Cast remain to unsigned long in eb_relocate_vma To: Jani Nikula , Chris Wilson , Joonas Lahtinen , Nathan Chancellor , Rodrigo Vivi Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, clang-built-linux@googlegroups.com References: <20200214054706.33870-1-natechancellor@gmail.com> <87v9o965gg.fsf@intel.com> <158166913989.4660.10674824117292988120@skylake-alporthouse-com> <87o8u1wfqs.fsf@intel.com> From: =?UTF-8?Q?Michel_D=c3=a4nzer?= Message-ID: Date: Fri, 14 Feb 2020 16:36:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <87o8u1wfqs.fsf@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-CA Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-02-14 12:49 p.m., Jani Nikula wrote: > On Fri, 14 Feb 2020, Chris Wilson wrote: >> Quoting Jani Nikula (2020-02-14 06:36:15) >>> 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, >> >> But the whole point was that the compiler could see that it was >> impossible and not emit the code. Doesn't this break that? > > It seems that goal and the warning are fundamentally incompatible. Not really: if (sizeof(remain) >= sizeof(unsigned long) && unlikely(remain > N_RELOC(ULONG_MAX))) return -EINVAL; In contrast to the cast, this doesn't generate any machine code on 64-bit: https://godbolt.org/z/GmUE4S but still generates the same code on 32-bit: https://godbolt.org/z/hAoz8L -- Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and X developer