Received: by 10.213.65.68 with SMTP id h4csp1289924imn; Wed, 4 Apr 2018 16:32:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/rPcKAv9f5+WGUq36YimBbqVm+L3msg6f9pPvBGdTASLVs1J1ml3QQqxJxisgggr2BX0vW X-Received: by 10.98.11.144 with SMTP id 16mr15248820pfl.228.1522884760173; Wed, 04 Apr 2018 16:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522884760; cv=none; d=google.com; s=arc-20160816; b=x+Q0fUBvqKBmA+qdxt7D5+nUTjna7YSjJdErnSNCAv27+72MTtBYKQgtcNHC7lvelo ezZYvo90eKtKwlRo0vThQ9INwWvHXWVTqRLcBp6tfNjS0gt5u3GNUl/4UB7QUQ0dmldX lF24yK2EX67duwzpyxZ7ofQuz7ZMfv2GBDDLmBWg/kC3hrrJGRas5EH8jvBNFLvN35YU njjaJuNYQIvtAm6n2Vm3zvlMB1kR8XNzqsw7Uofx74RGH397KkdCkz4nrAWWeK/pntvY ZE6UZSB7y4k6F6de98Xfymh7yGC7PVnnAW0z1KRcu8y0aF3oeGmdN6V/2TCuzge4u8ag FL5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=xZYemq29u5B+gAFxsw3Ymxj7k59Ku5Ez8ervLqXRmgM=; b=djUaDUZrH+rAXtlyQygowWxohFT8oHvTtNo3IuWg5TiBzIwIQBjkvjTMw772vs7o9z /maexgX306MxwgtSdf/GDqfwRdzQX6QjAfMLL1P8JAfvFfznrVo326APu04Xey+EcHM7 RQi2kh61Ug0iXY1z+3QZUXBQrQSlFH/salAo4FmCuHhEkO2jcBkb0P5DzV/74nncq1Di 9Rm8DdKwCFSd2KVVCODrj83ly9Nd/IIbxzYBhGWco9ymV1EiiD+T8/NkDXa3EDlOMtkl 70PJjqLTaLLzVQjhem5dn+RVEffC4LtGVIfT+DrR/ZHdWrd31VsqtMkvkkBCFHSLkzv2 EO7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Z2heRo/+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si4547222pge.659.2018.04.04.16.32.26; Wed, 04 Apr 2018 16:32:40 -0700 (PDT) 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; dkim=pass header.i=@chromium.org header.s=google header.b=Z2heRo/+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752615AbeDDXbO (ORCPT + 99 others); Wed, 4 Apr 2018 19:31:14 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:37386 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752454AbeDDXbN (ORCPT ); Wed, 4 Apr 2018 19:31:13 -0400 Received: by mail-pl0-f68.google.com with SMTP id v5-v6so14431766plo.4 for ; Wed, 04 Apr 2018 16:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xZYemq29u5B+gAFxsw3Ymxj7k59Ku5Ez8ervLqXRmgM=; b=Z2heRo/+HfANi4lh6QlhW5Ksie+oQxP8TVSwbyvHfu+2QWWsVnNMK1PKGG0Huw5E1a 6GyG1riVlljflag4gUdvfebBaak/RwAI4JU2vPDgGpVaG2CDh6V54iO3csIyYm2SSEou zIj60sgYSXfDidGJVExWKwbVEaNm5YB2PF/6g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xZYemq29u5B+gAFxsw3Ymxj7k59Ku5Ez8ervLqXRmgM=; b=iGYwxFsLyPEfenMThLqKm+VWdjAmskt+G2w+m03wjVbmwUeqzsirwuuadOVrONQ/Hb tkWrz6I/HOi7kZQouICd3E9UryyJLLUu0M9uE6Vmh8010pjv75WyPvln1w57MhbhwSJ/ ECa92Hs8uZ7tcTiNUvZ43QIosUyeAVp84bAz4RyvH7qX5daHIcj5ZdJfBz3tzdIfq5mI YwEWBWGl7RPeB7tSlszrEd0Sqfag2Ii/8BZLPSAn4ZYc69WddSt7cKWfUuMCttsZDbMf 2S7d3T3VMAyIkfxNqDEsznNN7G40ypfP2SxviujavEpVvdk26EHLPQqNE+fO/SPj/2lq hCEw== X-Gm-Message-State: AElRT7GnGSt54/lVJ+GcUJGLmZpQVtmaIBcK0Sc2QVPD/40Ngl29Vt7y Du1NRtJ7mNQiOMx6cNgiQigOQw== X-Received: by 10.99.119.9 with SMTP id s9mr13113117pgc.276.1522884672691; Wed, 04 Apr 2018 16:31:12 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id k24sm11120405pff.77.2018.04.04.16.31.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Apr 2018 16:31:12 -0700 (PDT) Date: Wed, 4 Apr 2018 16:31:11 -0700 From: Matthias Kaehlcke To: Linus Torvalds Cc: Arnd Bergmann , Peter Zijlstra , Ingo Molnar , Linux Kernel Mailing List , Thomas Gleixner , Andrew Morton , James Y Knight , Chandler Carruth , Stephen Hines , Nick Desaulniers , Kees Cook , Guenter Roeck , Greg Hackmann , Greg Kroah-Hartman Subject: Re: [GIT PULL] x86/build changes for v4.17 Message-ID: <20180404233111.GJ87376@google.com> References: <20180403180658.GE87376@google.com> <20180404093007.GI4082@hirez.programming.kicks-ass.net> <20180404191724.GF87376@google.com> <20180404205848.GG87376@google.com> <20180404214639.GH87376@google.com> <20180404221744.GI87376@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org El Wed, Apr 04, 2018 at 03:39:24PM -0700 Linus Torvalds ha dit: > On Wed, Apr 4, 2018 at 3:17 PM, Matthias Kaehlcke wrote: > > > > Getting our compiler team high to look into this might affect a timely > > (and correct ...) implementation of asm-goto and others important > > features. Arnd, do you have another, preferably simple instance to > > keep our compiler folks (halfway) sane? > > I don't know if clang actually already gets this right or not, but as > an example of a case where we have a semantic difference between "is > this a constant or not", a much simpler case is in > > - arch/x86/include/asm/uaccess.h: > > /* > * Test whether a block of memory is a valid user space address. > * Returns 0 if the range is valid, nonzero otherwise. > */ > static inline bool __chk_range_not_ok(unsigned long addr, unsigned > long size, unsigned long limit) > { > /* > * If we have used "sizeof()" for the size, > * we know it won't overflow the limit (but > * it might overflow the 'addr', so it's > * important to subtract the size from the > * limit, not add it to the address). > */ > if (__builtin_constant_p(size)) > return unlikely(addr > limit - size); > > /* Arbitrary sizes? Be careful about overflow */ > addr += size; > if (unlikely(addr < size)) > return true; > return unlikely(addr > limit); > } > > where the actual check itself is simplified for the constant size case > (because we know that constant sizes are never going to have the > overflow issue with the address size limit) > > That inline function itself is then wrapped with a couple of macros, > and the usual use-case is through "access_ok()", which then typically > just gets either a sizeof(), or a non-constant length. > > Of course, we've been walking away from having people do "access_ok() > + __copy_from_user()" (the latter does some conceptually similar > optimizations on constant sizes), so those probably simply don't > matter much any more in practice. > > But they are certainly a lot simpler to look at than the more exciting > 32-bit asm-generic "do_div()" case is ;) Thanks, that was useful! From some experiments it looks like clang, in difference to gcc, does not treat constant values passed as parameters to inline function as constants. I'll ask our compiler folks to take a look, with lower priority than other issues in this thread though.