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 31C3DC02182 for ; Mon, 20 Jan 2025 18:55:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9464A6B007B; Mon, 20 Jan 2025 13:55:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CF6C6B0083; Mon, 20 Jan 2025 13:55:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 749036B0085; Mon, 20 Jan 2025 13:55:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5245A6B007B for ; Mon, 20 Jan 2025 13:55:48 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DF74FC0240 for ; Mon, 20 Jan 2025 18:55:47 +0000 (UTC) X-FDA: 83028734334.25.E199143 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by imf02.hostedemail.com (Postfix) with ESMTP id 2B5F380015 for ; Mon, 20 Jan 2025 18:55:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ZegXYD8d; spf=none (imf02.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.198.163.17) smtp.mailfrom=andriy.shevchenko@linux.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=1737399345; 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=lalXFA0kcJvGe1gFNVf8mCa72epTDjsD6LFoTHshmOE=; b=5p9TuJp8BaTWxsCmIMk+1Fl2RJX4wy+yFVrC3Dc+zyEmzGRUymVUCcsO+jWU10akL11C0y Z2hiqZtCefkkenfeg8/lIdgDTE+5xhTPXIiEFOwxiKdoNqkFlRdp0kQAPotXDcFPRS6+Z4 bOqSq1tkeJ+NV0fead6ovJ7wghyvxnY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ZegXYD8d; spf=none (imf02.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.198.163.17) smtp.mailfrom=andriy.shevchenko@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737399345; a=rsa-sha256; cv=none; b=oIipQcdIUBgxT8bTmWG390S4FQ8qPcGcWCtcOKAFPNdKTlqTBzynhpSAQWHc2gBROzObpV JVJzM/X0XMH1+gsiMOvNHlwHiUvSSRzaecuihlXYR8kLq8UP36beIsLSJP3goJhfP80WtR yiQZaQ1Ms7/TqJWplSg2GXI7r1eqHlA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737399345; x=1768935345; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=op5oAGTrMnHrTtMQubTxdXMZzxdcxLlUbJi6A9RKoMo=; b=ZegXYD8dxMXTGudckZe+KXpmVCi8kip2aMhl0gzWiDvg/bsBIBZmU3ZT jjgDj2uu2S3uXHCGdwbYMCKe4pnIIxy8ufe6ZoYJPkCVO5+XnAZ2okrSr sTppyLgG2QDYcK0AaR94Zo2YmFJbphGDHAZkJ/VXqUQtqZMFeu7E/XaTu 70hIGmFQ3SqDqfUUFaFjAHFaB3zt+/TAJFC8je6tiWWykclJ1SLw4DhfF AFtcSH1EJtlSmcphrSBO2FmqN5z6IUDHQ6f5Cg1zlXvhUsKUaA3o/gfaR OgFk5+y630t5brNVKGH1/kxjLL6+AUgt8HuDW5659H5cRlQq7ssvL4BZL A==; X-CSE-ConnectionGUID: 4qAlhxvlQbCCWoB99XDBiw== X-CSE-MsgGUID: 9pThyKKxRiOPAweQLS9IGg== X-IronPort-AV: E=McAfee;i="6700,10204,11321"; a="37718315" X-IronPort-AV: E=Sophos;i="6.13,219,1732608000"; d="scan'208";a="37718315" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2025 10:55:43 -0800 X-CSE-ConnectionGUID: p5dQ9kclQL6q2hlmyNaNeg== X-CSE-MsgGUID: yU17x0vTTAasbq8m/yd+eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,219,1732608000"; d="scan'208";a="107205604" Received: from smile.fi.intel.com ([10.237.72.58]) by fmviesa009.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2025 10:55:39 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.98) (envelope-from ) id 1tZwvv-00000003XJZ-0XDD; Mon, 20 Jan 2025 20:55:35 +0200 Date: Mon, 20 Jan 2025 20:55:34 +0200 From: Andy Shevchenko To: David Laight Cc: Guenter Roeck , Jani Nikula , Linus Torvalds , David Laight , Arnd Bergmann , "linux-kernel@vger.kernel.org" , Jens Axboe , Matthew Wilcox , Christoph Hellwig , Andrew Morton , 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 Message-ID: References: <29ef57a1-e4dd-4d5d-8726-f1f79c698b66@roeck-us.net> <20250118221123.5bb65e64@pumpkin> <20250119090935.7c690f85@pumpkin> <87ed0xrcb8.fsf@intel.com> <20250120111551.435176c4@pumpkin> <878qr5ras2.fsf@intel.com> <0a65de6c-74d5-4d3e-be75-0aa9ecc82da1@roeck-us.net> <20250120184143.47615b21@pumpkin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250120184143.47615b21@pumpkin> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2B5F380015 X-Stat-Signature: y6fc9w77t54hgxhz74zmou3kkjwnko9b X-Rspam-User: X-HE-Tag: 1737399344-725000 X-HE-Meta: U2FsdGVkX1/YUZZ3Hc8kezZsXx0+6O8vSH+2o0IXzh042nSusX3p/cjYi0SlAL8DEY2cLMWZTE9enilUKMARkQBoRyVNwyI4/BnS6y3tXBgq78aypU2y3LBj8IHLgJLLF1k1ymuCvdzYUO/s3Ty6LVmTkFjhO1ZTjf7WZBBiUI2pK4i9OUqbJ1enzIhSQwZOxWeVqH8ySxpUl/oZlstUFj0l8jvQNQ3eFCh2Djzx/y+3IQEvPZBa1499tsAq8ZlTyj+1Tn6HN/FHmu7M57sP5i1imW7qh4WaEiESYLYmoD6ou/lNqyH7oSm/YFlFXBBYUqKVR1D/N9pF0on3Et5ws6eA+0FYh4sJWtNeM4x21pfznfur0t7iyMs4gtpQLneUWwl5XPFTroisSXNTE0AShvOf4xKbn8oHAKupPT9Apw4qw5G2UWS3sFSDu/fOsvg9tDd4t4feYF1A7gpb9NmyvTd06CtVcHTC5uohvWttkF7IlmoYSDFT3u4uRMY2L7gnKId1FylJkKCXpPiag+Vt7QIpJJILflP0V8t/+BAGgkpsVQntXhV3hHFXmShXrIbqMir1tskrNGgfkd25XRv6fv2xucheewuk5MIhKnLS4hQkfJ9a/Y7faRwvWxtrHoQrGG4+DdBeM+wk3DxAyhSMCW9UJE8kKga5M2+SB5m9Q6NlepizEW06kY1hgqsFwrRbNnPDiw7s0NI9UCV49HDPsk2cEMWI5A0OTeJUEVEdXrHCtpjky2iXp9Bbl9WJp5mvjfjxyMrQ2AGTeRfUheDDBycjGi9j0E0tgihgrl3g4D9p+gVcGOXZtp0BDjxUQlV07ql88Abd4Lfj8y8mV9f1CWmVCqjhWBkYGb+xn2zN1ducR7Nczc2e/xc7WcyjYNx5O8qz/HvHvBfaIw84+MYW6W/M8MK/WUgZc/1hBie4eBbrfdgrNAJRxtmk5Zn8M+xchlDZCFY97s0tVqB8e8U ekAWyQ0G o/6JZRLkLmxNLzoyNbXnx/ZdWG1ugc7i6+unlhSiy1sRgkCkciK8YYGDe0M4bMXUdQ0Nnzln3v1Es97e9uekBs3VPkomIRcfJy/agfpxVVyW8O+1OiP7suvYbAVV1rSfQr6QtclVMq1s6vsk1/xaxDeZWKwsC7D+SNLZ1epY/zd1SoyMsGR5xnh7E8uw5VxuZVGUSnEpM4W/8x53a32zOb910ZqKexaDEGSuS1bourWIhiOt4paighi4zViAn4E14e5inPiVhJxDU2v8NeTHbM59ud1IrB1NNSThHD9nC86notk3uF8U2Vm1+ZS8IYYORZH+gW/fN5MfRolm390IafDJ+GnVbObh3DCMt2xirg0NhEjSJNQRxEdiW6YUjNDXBb57FQgKwYQhbSwySJrldgQ3XZADHnoQ/Em3UVBGkRdeu0MEODGTIXNQ8PWqeKW65ASZFxlsMlnXD9SwrQlsluDStxfeyF3W6B5JmkP+TDDIuRRqxG3XAy0U2Vw== 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 Mon, Jan 20, 2025 at 06:41:43PM +0000, David Laight wrote: > On Mon, 20 Jan 2025 06:15:30 -0800 > Guenter Roeck wrote: > > On 1/20/25 03:21, Jani Nikula wrote: > > > On Mon, 20 Jan 2025, David Laight wrote: > > >> On Mon, 20 Jan 2025 12:48:11 +0200 > > >> Jani Nikula wrote: > > >>> 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. > > >> > > >> A user isn't going to notice a WARN() - not until you tell them to look for it. > > >> In any case even if you output a message you really want to return a 'sane' > > >> value, who knows what effect a very out of range value is going to have. > > > > > > The point is, we'll catch the WARN in CI before it goes out to users. > > > > It isn't going to catch the divide by 0 error, and it obviously doesn't > > catch the build problem on parisc with gcc 13.x because the CI isn't > > testing it. > > > > How about disabling DRM_XE on architectures where it isn't supported, > > matching DRM_I915 ? > > That'll just bite back later. > As Linus spotted the compiler is just 'optimising' some code paths. > It could happen for any architecture including x64. > The repeated tests are basically slightly odd, although you might only > expect them to be present in debug builds. > > An alternative would be to replace the clamp() with: > if (source_val <= source_min) > return target_min; > if (source_val >= source_max) > return target_max; Excuse me if I am missing something, but clamp() has a warning inside it, correct? Why do wee need an additional warning on top of that? P.S. However, I agree that ideally clamp() should work independently on the caller to use WARN*() or other similar stuff. -- With Best Regards, Andy Shevchenko