From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41A4AC02181 for ; Mon, 20 Jan 2025 10:48:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3C07280005; Mon, 20 Jan 2025 05:48:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AEC14280004; Mon, 20 Jan 2025 05:48:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B362280005; Mon, 20 Jan 2025 05:48:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7B7BC280004 for ; Mon, 20 Jan 2025 05:48:26 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2B7C7C29E8 for ; Mon, 20 Jan 2025 10:48:26 +0000 (UTC) X-FDA: 83027506212.21.89D7D64 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by imf24.hostedemail.com (Postfix) with ESMTP id 70502180005 for ; Mon, 20 Jan 2025 10:48:23 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Z2XPMpCl; spf=pass (imf24.hostedemail.com: domain of jani.nikula@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=jani.nikula@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737370104; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wAE5mmY2q+fmH8Jg1aYmcRqGYHWTBElKZmzXAXv4uj4=; b=mricJgGep+tAZ1gYEIjjU8epRIfNpAKRaoxwPWVhEDk/lJZ8IWjYXKfCFlZWWni50KAbFr 56/pVPCiIa0x/grMsItIfizEAug1+sjTEZweRaCG5F17q46eKmxAtgq3bhxCfRkNQv6c/A WrtcFoqeeuasx92/vIETFkRTHitTSyc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Z2XPMpCl; spf=pass (imf24.hostedemail.com: domain of jani.nikula@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=jani.nikula@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737370104; a=rsa-sha256; cv=none; b=eZDxZ+Z+yawZK2HrYQlKtBp0p/CyGPvSrUcr8GZkCrqwgj7kYf6Hi4Mxj5iNr30hb4w+OG 3zUuM84oU7wMZUbo4zmhl9hchTUbPJSr+goEGaCHsTMeE26QlKdRtDS5fq0FHmfeQG0C9/ S3Qp5QrGE9D8m8ghanimNn/eQs4aVxk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737370104; x=1768906104; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=AhqnX1Rc1BlqEuPFl2fOCR2Q3CPQjAkoWdXUXERjTwk=; b=Z2XPMpClnevTDNfFE/iSBcie2dbi5z3E1UAYz4qTLsNRAlmrdWSEfs5v hkXWmO5ZhHp2HRHkKrCJoUHI+w1313tBP4RJRCrsVoXoYQRGUla8j8+Fp yXH8wlxvI87yZmUt6e1Ke2QVG/EY2agGIMEb0xUcHGiJnhxFnjEH4Ippf H7GfY6b6xjCiwU15hiI3y80bavenM0cu0uacHpzFGKGdKLXkfDRhZyJVY WHS6FAmFNyH1grLu13W1807tuKE2RDjtCXE16pmo8k6H3GrWx70jef6v4 eiNVXqLQBR2dnddKqP4alWJ2PrsVa0DfbtJJAPl/nnvegRg9Bo0RFPP79 g==; X-CSE-ConnectionGUID: BuyxlXVPSh6Q5wYHVo+Njg== X-CSE-MsgGUID: nirrk/7hR4+mFZV7mY/Dww== X-IronPort-AV: E=McAfee;i="6700,10204,11320"; a="37904201" X-IronPort-AV: E=Sophos;i="6.13,218,1732608000"; d="scan'208";a="37904201" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2025 02:48:22 -0800 X-CSE-ConnectionGUID: /czmvD02RK2MKgy4cJuIDg== X-CSE-MsgGUID: Z8jjReY2S7GydVJhOLE+vA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="107375612" Received: from mjarzebo-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.246.106]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2025 02:48:14 -0800 From: Jani Nikula To: David Laight , Guenter Roeck Cc: Linus Torvalds , David Laight , Arnd Bergmann , "linux-kernel@vger.kernel.org" , Jens Axboe , Matthew Wilcox , Christoph Hellwig , Andrew Morton , Andy Shevchenko , Dan Carpenter , "Jason A . Donenfeld" , "pedro.falcato@gmail.com" , Mateusz Guzik , "linux-mm@kvack.org" , Lorenzo Stoakes , intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, David Airlie , Simona Vetter , Rodrigo Vivi Subject: Re: Buiild error in i915/xe In-Reply-To: <20250119090935.7c690f85@pumpkin> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <34d53778977747f19cce2abb287bb3e6@AcuMS.aculab.com> <20250118170959.3aa56f4d@pumpkin> <29ef57a1-e4dd-4d5d-8726-f1f79c698b66@roeck-us.net> <20250118221123.5bb65e64@pumpkin> <20250119090935.7c690f85@pumpkin> Date: Mon, 20 Jan 2025 12:48:11 +0200 Message-ID: <87ed0xrcb8.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 70502180005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: xxhgqfgqo9ura3jppau11k6hz9b6cc73 X-HE-Tag: 1737370103-335313 X-HE-Meta: U2FsdGVkX198L52CB29fZcpMEcNwTQUbf/BRyWFpI0Ag4XXF6BN+DX7sGbQx8YXDiWSUdYTEkN/EzHk+Y5VQifzaknhSjFxkbkH5zQW59smjS/GV9XdOi6s9zJZm4lD9OhoUpdjdARpyftME3bFX9OeP1RsqBLzvCxWksf543ruTZqlum3IsSGkz55Tce/K6Tzt24VCLWttslS34xzttvi53wULUhvtAv78alGZQ96NonSgJ4Y0xWBFCngg9/h7YOquiFNN8gX0XOjlOXk3ufVhW2tR9YVESV07RdkYXZa1vTwZk86iZuNdxbjPg10hDj9Qj12FVXsAD45kXsovyIwIxs9/CEPzdZl+Gre7zonxW/R6fWppZVT8BkWIL9MBGj6Odd6mEKKXl8OrZOYQ4uvkIoDtjNqSVdJU8dw00cX+MkDgdMtjGaq9+8+R49kWe1yhNr3ABFiRquAVLdHjOunHhyFohvV8L6+QLv/lRUjqzPEKiiN9Hj1SNoRsLiNhIavVf2NVHjkSerbp8YPnNYqJARploxcvU0Xn8jzmuxuLZ2UAqhfFZny0xVB0ScS51UkZHscDCACTl1z3ENeKClnp0/qWOpn+lu2Qwy+Fk/lssufh6LAjNiNWruXnMzAMM40EnT1NRkW9IAeewCQnShGBS/oGYiXLU4TDp7ryPD7aalHc2XsaEMsya8VvWb+TcdCFJFRe+q2yAZq6yepU6z153Pct0Lu0LqoJSpfiurtM6mL0N0eHGIiyxNEqWBSoVendAnlMWA5rTEayT3g4EvyBT8xUnT6owTCQ743NMssJ4EX3mly5jOLb9hxdkqAYknYu/AWCo2FooS5TE7o6tbPdpoY6BLFU64L7uSz53E84IBAeVaUzSlBweMzGElxPiePw6gw0utvMxc49NavQ+Z915cwGFwKLqFFnOiQFSzJzdMuFrw0zn1MpnBkNY1yFy9CHqPbyEzDBiWS7i30g FTeDsuHl AX9bp2zad5ddVgEoAPXFQapGBGMRT+1zHedFp58/xPwFUneZ8QEiM+u0gIy0CIhTcYSUw5mrrgRv1PiWfzCm3RzpjQW0XtEwdmUOnz2bb93IoPwMzvOx4UstRRGLPfocq3xIpvPmDkoUGHAYqjei67euQzHcW+Do6zC9p3/opkeeOZuIGxkDkgny5/pBIMgkpPHZYpp7JWRyRohJTm3gIftnMjIqaPa4Ms657l7D0zOLainKB42Z0Il9cmUj0hMUmoA9wjm12T7pLaybEpMoUn49E6MZGaTnSfjvhgVCtvzIqRACdYp4ef4hHt05wg6suqJZG31ZxuL+nS8TqPdJpjguzSHerblYvzLQeuIiv22P/8HAdgFPINKZsonO63UIVgw8YVu7rm4ce4Ynxdviuu7QcMH3LkPrOmcv+Qk4k9GWaDcFCjyi0LS/DN+SZQEwmkacmlLy7KleyGdparywdlpVBmShj0MCtwOuuMw/Hfql1E349SeqoKRqnUsnqiTi2mJgu37YRwIvEoTjzmGevZZZ1K+fdvr+Wbz6HUVZsZsCwJA+ufY3jzhtmgw9Mc87DkPJbP1VLyBe0bfZGJYHdMfWNYNphxPaC1w7U X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sun, 19 Jan 2025, David Laight wrote: > On Sat, 18 Jan 2025 14:58:48 -0800 > Guenter Roeck wrote: > >> On 1/18/25 14:11, David Laight wrote: >> > On Sat, 18 Jan 2025 13:21:39 -0800 >> > Linus Torvalds wrote: >> > >> >> On Sat, 18 Jan 2025 at 09:49, Guenter Roeck wrote: >> >>> >> >>> No idea why the compiler would know that the values are invalid. >> >> >> >> It's not that the compiler knows tat they are invalid, but I bet what >> >> happens is in scale() (and possibly other places that do similar >> >> checks), which does this: >> >> >> >> WARN_ON(source_min > source_max); >> >> ... >> >> source_val = clamp(source_val, source_min, source_max); >> >> >> >> and the compiler notices that the ordering comparison in the first >> >> WARN_ON() is the same as the one in clamp(), so it basically converts >> >> the logic to >> >> >> >> if (source_min > source_max) { >> >> WARN(..); >> >> /* Do the clamp() knowing that source_min > source_max */ >> >> source_val = clamp(source_val, source_min, source_max); >> >> } else { >> >> /* Do the clamp knowing that source_min <= source_max */ >> >> source_val = clamp(source_val, source_min, source_max); >> >> } >> >> >> >> (obviously I dropped the other WARN_ON in the conversion, it wasn't >> >> relevant for this case). >> >> >> >> And now that first clamp() case is done with source_min > source_max, >> >> and it triggers that build error because that's invalid. >> >> >> >> So the condition is not statically true in the *source* code, but in >> >> the "I have moved code around to combine tests" case it now *is* >> >> statically true as far as the compiler is concerned. >> > >> > Well spotted :-) >> > >> > One option would be to move the WARN_ON() below the clamp() and >> > add an OPTIMISER_HIDE_VAR(source_max) between them. >> > >> > Or do something more sensible than the WARN(). >> > Perhaps return target_min on any such errors? >> > >> >> This helps: >> >> - WARN_ON(source_min > source_max); >> - WARN_ON(target_min > target_max); >> - >> /* defensive */ >> source_val = clamp(source_val, source_min, source_max); >> >> + WARN_ON(source_min > source_max); >> + WARN_ON(target_min > target_max); > > That is a 'quick fix' ... > > Much better would be to replace the WARN() with (say): > if (target_min >= target_max) > return target_min; > if (source_min >= source_max) > return target_min + (target_max - target_min)/2; > So that the return values are actually in range (in as much as one is defined). > Note that the >= cpmparisons also remove a divide by zero. I want the loud and early warnings for clear bugs instead of "gracefully" silencing the errors only to be found through debugging user reports. BR, Jani. -- Jani Nikula, Intel