Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1339107ybl; Tue, 3 Dec 2019 05:44:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwL8Exd+xxq6cflvVXhdJnp/XoyTICcTaYykztvBs5W17GpQ73093rsNhhml2Oc75j8JwoZ X-Received: by 2002:aca:5cc4:: with SMTP id q187mr3678605oib.45.1575380649965; Tue, 03 Dec 2019 05:44:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575380649; cv=none; d=google.com; s=arc-20160816; b=wacrAwBOyljgDUeYvGucbseaAEjJAvAp9Nu1xCVu+kaVBHlCSGG//wbDeD9tFr97gZ mLBvStlEcN+IkORsNlGIWSCbhxsggC490yf8FsgvyjkA3MLUe0n38bmmafXdT9K0Pozk 0ZvYPcESr/PHamCNk3kaH3+gor6suUvxKsRFxqdeL3tE6huHZPZIh0POrArUJ03+ivoK 4fziif0IFuFNfWjR7w7ZIEgxcP/iljpmffA7tnoATOkJ5ZnA9Rq485QcYApuNT1HZtdz OkLBrO6GzQ5VxT1TK1ZHjL9068gZdWXXe0izbv21nUT/8Lw4jhIja0IeHOUkVZL5yUHr txrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version; bh=bUiKTedCaLpRWI2wMvnliHvSXWDx37KLQkssyfIOas0=; b=yv4aZzZmnVpS6qvi/8ytH+r0oU14FfIUxNi2Bp8A1XF0eGPEqu7QiIifuzvKNYsOaW 9etveyGlB0OejkdTQ3EwNxNXhzHDTno7TwO1GkWMcUoAptt/A43lx0kUGLb/srlDbK5f mKKFOAQwVlFQsI+wyeZC23XkUenLgM33I7JjZzb53s9k5TQvsa0RMW4iRr9vRhPHo4s9 Iot4Y2IT33voZ/Ql6jb+B8mjeGdgDFA7DGSSbggFqbsRGdDBlM+zAcj8CIPA2yNf4Rs+ Ol4wVQ4TZsW8bl4Pu2eNk/WZiFVi/8V47TKzE2/mZZl+aaLLi6LWTZvfHDOp/Ibs5Tvk Ui8A== 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 c20si1143955otm.50.2019.12.03.05.43.57; Tue, 03 Dec 2019 05:44:09 -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 S1726131AbfLCNm4 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 3 Dec 2019 08:42:56 -0500 Received: from mail.fireflyinternet.com ([109.228.58.192]:52688 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726079AbfLCNm4 (ORCPT ); Tue, 3 Dec 2019 08:42:56 -0500 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 19443048-1500050 for multiple; Tue, 03 Dec 2019 13:42:48 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Nick Desaulniers From: Chris Wilson In-Reply-To: Cc: Jani Nikula , Joonas Lahtinen , Nathan Chancellor , Rodrigo Vivi , intel-gfx@lists.freedesktop.org, dri-devel , LKML , clang-built-linux References: <20191123195321.41305-1-natechancellor@gmail.com> <157453950786.2524.16955749910067219709@skylake-alporthouse-com> Message-ID: <157538056769.7230.15356495786856166580@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [PATCH] drm/i915: Remove tautological compare in eb_relocate_vma Date: Tue, 03 Dec 2019 13:42:47 +0000 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Nick Desaulniers (2019-12-02 19:18:20) > On Sat, Nov 23, 2019 at 12:05 PM Chris Wilson wrote: > > > > Quoting Nathan Chancellor (2019-11-23 19:53:22) > > > -Wtautological-compare was recently added to -Wall in LLVM, which > > > exposed an if statement in i915 that is always false: > > > > > > ../drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1485: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))) > > > ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ > > > > > > Since remain is an unsigned int, it can never be larger than UINT_MAX, > > > which is less than ULONG_MAX / sizeof(struct drm_i915_gem_relocation_entry). > > > Remove this statement to fix the warning. > > > > The check should remain as we do want to document the overflow > > calculation, and it should represent the types used -- it's much easier > > What do you mean "represent the types used?" Are you concerned that > the type of drm_i915_gem_exec_object2->relocation_count might change > in the future? We may want to change the restriction, yes. > > to review a stub than trying to find a missing overflow check. If the > > overflow cannot happen as the types are wide enough, no problem, the > > compiler can remove the known false branch. > > What overflow are you trying to protect against here? These values are under user control, our validation steps should be clear and easy to check. If we have the types wrong, if the checks are wrong, we need to fix them. If the code is removed because it can be evaluated by the compiler to be redundant, it is much harder for us to verify that we have tried to validate user input. > > Tautology here has a purpose for conveying information to the reader. > > Well leaving a warning unaddressed is also not a solution. Either > replace it with a comment or turn off the warning for your subdir. My personal preference would be to use a bunch of central macros for the various type/kmalloc overflows, and have the warnings suppressed there since they are very much about documenting user input validation. -Chris