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 8DF58C02181 for ; Mon, 20 Jan 2025 18:41:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19DA36B0085; Mon, 20 Jan 2025 13:41:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 127136B0088; Mon, 20 Jan 2025 13:41:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBAEA6B0089; Mon, 20 Jan 2025 13:41:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C8BA66B0085 for ; Mon, 20 Jan 2025 13:41:49 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 793AF160210 for ; Mon, 20 Jan 2025 18:41:49 +0000 (UTC) X-FDA: 83028699138.05.D042680 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by imf07.hostedemail.com (Postfix) with ESMTP id 85E0840006 for ; Mon, 20 Jan 2025 18:41:47 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nQbmjS8I; spf=pass (imf07.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737398507; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DIBwpgd4nZZVUOe5igOTj25p3iSQrZ0QRAo6bvYlPtM=; b=YhlQ08/QGw6I9ZaPaO1l1gFcT6P+BmK4AioeRKbIkPZBPDiCI5SoFKXcHBcCwo6/8WvJU7 pA9S/y0EzoVIFrtnkCqo7iM+tyO0OQOtoEiKeierEPphBPmgC4Z+z6f0U3dWCJldEGbMJE CR+HkIzYSVoI9u83tfuu/cfjw55NhVg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nQbmjS8I; spf=pass (imf07.hostedemail.com: domain of david.laight.linux@gmail.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=david.laight.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737398507; a=rsa-sha256; cv=none; b=HEu08IWrfXmclZzztzWNEhJ/IIyPTXbD4fw7n/oG/1Rd6Wne5MTdKGQMZacc0MzeT5xoS6 QlDUDvhRlTQnKsAYLRWAU05XFEKzBtSW9sHmtUz9KLW+1GtWUZAKJOwyaWiRp+c7Rx3x6U oHCygrhqsG3u4held7Vl4dE/26jhVmw= Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4361f65ca01so49284225e9.1 for ; Mon, 20 Jan 2025 10:41:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737398506; x=1738003306; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=DIBwpgd4nZZVUOe5igOTj25p3iSQrZ0QRAo6bvYlPtM=; b=nQbmjS8IYyUyIqliXQoBJgtakyOSsX/o+FwALKDTh4w/0JA9IDpmsGuDRZ+BoMDWmH f3ib1qNYTa63Axj9kv3mUz6j8RVAiV1NRsANlBH69k//Eqbloz8XghAPvO3gTQZk8wAa o3VCroAN/R7tIk6u8nFtYGxql//8FTt5Bx8Q7TrBKeWrW9Xokkg38uQ/j9ZhpLdNXuft bQZG20OxNFKTmYfAb9I7neSX3uJX7YbTZN1eB1HwaDFyDGRZBPYz8+mhn+OOxeqlVX82 rWzz62WKB7TtvpjEDmNU2PrDXRkF7UQpvrc0Z4leGOiLNkwjOnUgsNrB25me2FjBoMzi n9rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737398506; x=1738003306; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DIBwpgd4nZZVUOe5igOTj25p3iSQrZ0QRAo6bvYlPtM=; b=LT8TTwo/aIzRCPqE/iUayEGpxEwHNR/w2P82EsiIVUPsKw0IwQzb6UU4e9pkFcGjAx /PgCUBceBL0OqBywrQ6Bv0ZtXlZAgABt5qUA3MKKSOlJxqfS+jVt4S7vtc3a6aSm2yjg QLlYfvY5CAYD2HQAWRSccVWZBVE2x3zBwD0ho2T9XgNxUnjDtmLFGXcu18kk/yuf5mln m52/8JesSW/eeXW3v7l4bHaU+ocss0UUTbsG8iFA6yt/rIni6BVbEN7MxkzJKcBFHnf4 pn4qpj71H4t2pBmAySOLkLom+dk9vJc5bcG3GqZ6O+nW1E5D8FFh2FApryI3rciftSgh eQTw== X-Forwarded-Encrypted: i=1; AJvYcCWv1uL7zxhFPqEjNKsMKbqU3G7D0+SwaEh8+14crDO+6aleAoYAGmZ1NAQ0SXPNbvcZ+xwNBpCj1w==@kvack.org X-Gm-Message-State: AOJu0YwTh/fJfuQT/qrm9GpWTiBgR47P5oP6PcSfn7lRLt2Ar1gcJXN4 HnY2nBJ2RNMTs6ModvbQFEHrFFS0MGIAQoMTx9192zFXbs7acokQ X-Gm-Gg: ASbGncsEZEJoIgfX083dG+4wjSsUpi4FPxVkldKL84yEIppZi5oMeTfMSZa1VHuwXjZ u7ktrLBGB+mNe9Buhhr3aS6bldxWk5QBHmcW3pBTTKfNdHilFl1oLKLOWYucqQrei6UitphBR6b Qb3IeWR2kwSQJ50tcZWuijJ3+MLcQv1pw8FSJMHbuPB5wcm1p9HnXYXx4nYem7Q4zahP0bfxyh4 E8SheMQ8N72j+2vq5/7ULo4XUnjQdB7U9706Un02Y54NnSedeJ0/O7biHJcvtrPwXVJWnwqL/gO voUqpEcO58rT8v8fEgMxUadWcP2ickBg X-Google-Smtp-Source: AGHT+IEn3fWuuB2LneTt6yQ3PstmeBWVOQXwkDbyDPfhPGTU6q73G1l86IByTH3i/KUxwcvQA0z7UA== X-Received: by 2002:a05:600c:4f05:b0:434:fe62:28c1 with SMTP id 5b1f17b1804b1-438913ef83bmr125983915e9.18.1737398505721; Mon, 20 Jan 2025 10:41:45 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43890462195sm148506615e9.30.2025.01.20.10.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 10:41:45 -0800 (PST) Date: Mon, 20 Jan 2025 18:41:43 +0000 From: David Laight To: Guenter Roeck Cc: Jani Nikula , 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 Message-ID: <20250120184143.47615b21@pumpkin> In-Reply-To: <0a65de6c-74d5-4d3e-be75-0aa9ecc82da1@roeck-us.net> References: <34d53778977747f19cce2abb287bb3e6@AcuMS.aculab.com> <20250118170959.3aa56f4d@pumpkin> <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> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 85E0840006 X-Stat-Signature: gbz6tjig6g5mnosdz3nu5x8ag34jfgbu X-Rspam-User: X-HE-Tag: 1737398507-266639 X-HE-Meta: U2FsdGVkX18kKrTPT8P5+iWpaYqEWcKPxFeD0ADbVebnOfEoq0NVuq9G0ode2eI6AZHStH9kx1/Yc02xGjPUO1iGsNiZRB1HmTNNrUPutzPXRfRZL56QW70gQzyyXc4dkvbKO7us/jsWH260YNLh1cLwCBYzyp70dooUceGGY5ATqOibFHbChDHcOwK4UcCdl1zwh36sfq8ABorYrPfS33s2KmyNyL2PkzSFUG7Ntd+uRB3QQgpe6eWCQnL/hb4/o1kC9lt4Rb8YTMJtqNbmv0vTYTo1DCcB/ZgC45LpJ2fxxb1fc3ymSDbJDVsLVHa9WmDHUuBS4jjQbCYqs1AIeu6V5ETx1aUqFr27Y2MkvrVpnEc/YypvAi0j8wox4xNcjvzF6E4t9XYYSWZEwQCFyinHcP+3GzUBgm7QvjBiRfNWpu5Uvr2uCGq6wfz7hKIlceDpgV/PC9msubQLI4PCQA+90ODMkhi9uZMYYJfo4P1XjMnRppcMszVabRLzWLj4PjiIHxlNo2E3DYph4/BeJwJn/g6dqorwnyiFqdXfYuH20RowmvZ1JfWT01rla7jpj0IaFpT4mHawCA4zBfc64FAV7tjjBQihneyecEsvaE10sp43DtxsCiaeitMh3O+RmsiC+Wqkl6+iDEyZsghMmZDuH1kxZOdVIeGicNhF1IAdAwwZeYRY9zS1pis8aAgtazWSh8y52L5C5AHQ/yIm57yEETw+ZQJF0t0eDNu/MvQnZVVylMkruqsXmGx5Q5biHGC3D84M6Y9yzCqENOJPSnw8AKDsfMUKqWfjqaoAAIv5CCxhTta/9RSJZREMgVn/yXuZ2xKjwYhdJk1nguV7u3c0s805flwlSAioX0rX22EJqGai2YyOhZMPXhLSVB45KqkS6Zv6fP7Yght3E5NsoZnbOO/u2IXPLtSKue3qtgh2MGb7xRekBP/I/ddYcBbdtKs9TFBoS6byIaRUxYP J41Hp3Aw tdKnXVNlC3ihq6MzBP/mefXGAYYuFLsGyUlvaofdqihoiVEyiwTflrcwXo28HUQK1jWf3o56+25OCKv3ZuCs2vwvuexaBvfd4UqL6Tlym341LrldP6Bo+B+xAwtbpfJRR4ePprzc3UhYSwRJx8P2uRw9Itr4rVXPpSFCrDgaJydicgO++yeFDy4n7HzVRp/4DESYl/2pP1fGUsRnCseM4kJEivgSVWd32Uex3bSgoAwq1v6bYkpQ9Hb+BB/HI+vp5LEimOpVJVKVaJgo0HbelHMA6A292Arx79AN/9zy0F0iYhmJfLW319foA9xBXlCA06onIMKrKFTjEbLxI3jjW0SEd/VbN8OlIwmzReJOGz+fxUMoAPjNT3cHx4T3lyweuPzYzjYh5WyMuvFIeZ0AyqKMrSevKRfa9SKIRZq60b+w24gZBHIuzmNwtrBijy2lTUG2jxjqyd4rZQFPm8zOv6lGbo7mjKpspxCJkNZFkRUjmcQj5/zwAADNt2wigfnFtuMzI116jnYvnZ5yhcR6L4oZlL+L9IC0BtJuzycu6KtF1YXYg85u7A4zaVQ/OLiPwK8LEBW05hElzE4tJx3J9+V+AUCBm9txiZqDqjJCMqpA1wV58MwwkCVjqZVLMu072Ipim6o4k1HAFxRUFS6/kazUgdTe4xSmaldE8BDCPInXFuiI= 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, 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; David > > Thanks, > Guenter >