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 730ADC3DA7E for ; Tue, 30 Jul 2024 16:36:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6E906B0082; Tue, 30 Jul 2024 12:36:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF8666B0083; Tue, 30 Jul 2024 12:36:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C70D26B0085; Tue, 30 Jul 2024 12:36:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A58B46B0082 for ; Tue, 30 Jul 2024 12:36:09 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5A48CA036A for ; Tue, 30 Jul 2024 16:36:09 +0000 (UTC) X-FDA: 82396971258.13.FC1F1A2 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf12.hostedemail.com (Postfix) with ESMTP id 30FE04002A for ; Tue, 30 Jul 2024 16:36:05 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b=bZ779yS5; spf=pass (imf12.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.218.43 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722357339; 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=KLHg6Rt8hE2c6f9s+Hk5e7EMcF8gl1hqD8o20b3cA+8=; b=wMGLJKmRnVcga09fZUkKdcN6Y1A1G/xE8m1liS853jVJjI7AzOPy59T62TrDFIidHv2tEG W1r/sGLZAiuCise4OCcKRxnNSQkyg1iJo57N5QyRoZ1V7+OjRNaJxuRNPTSm5y4VHTN51m 7srPyUH2/ePLuM+3N4GPvU9Yxuixc+w= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b=bZ779yS5; spf=pass (imf12.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.218.43 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722357339; a=rsa-sha256; cv=none; b=yiNIAUbnCrKvZC20Y1UWdOImO64wRJnQDQbT2TVZhiJc5n8QQK/A32/wcsyrjMAE7x7APU wkNe41+n9+8G9fnQpA1cKj/8U7uCtg07DvUZsUcaHbeIzR/kBGMSflSuKtQ0OsNwpXLgXX zmohKcUEEgnowI4jX4DU77L/S4ODf58= Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a7a8e73b29cso356481666b.3 for ; Tue, 30 Jul 2024 09:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1722357364; x=1722962164; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KLHg6Rt8hE2c6f9s+Hk5e7EMcF8gl1hqD8o20b3cA+8=; b=bZ779yS5pF19MKUJpPtGixolxvTzQTvpyax+57IGCNif1fXWtTi6UcvtBQC4cwINXC CLgkiyM6/BNLdfRQRxjl4T+tBKa8q70jPeSmzfxuqIUT2sPs4sV2fDAC9jc7ZodtLRxN hb1OAIOwRkRyD88kZtRm3dRWkn727zkEfIrzg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722357364; x=1722962164; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KLHg6Rt8hE2c6f9s+Hk5e7EMcF8gl1hqD8o20b3cA+8=; b=PXcoFcuiXHcPJhpcbPdzhb9Gectl1MDzvVzWIdRccG5qezeHsyVeVW3d+Xy0FJV2PR xp69Gui3sRS6WiEZ7276nMNKYgD9XKTgpW18BmyRLPLM+hNutvIrl1vEXTDkL9fsxNSY ItjK0KizHagTO9o91P/NHTD1bRCiYjd3dWO3bnFZq1juGd2BfMARfoiHbvOGUXZenvQH +/Rqp4oYAOjY87UnQx1pzTzPVmeqivofuvGUg7X1x5p+GlBhv6bjw052r9Z0mSk5cbIm VQZ8uu4J4LGq9GWYk21k0o/CJWXieKDnq0AQqL1XRyyJ1gfe+1hejzYtACNqZd7B8U3z ULXA== X-Forwarded-Encrypted: i=1; AJvYcCXxkOWDyC6OLFaR8mHQGOmBZVp0ZyF9Xlc6MEvB3NSzpml0dFYaVJNEsF0CYmoC2pU/IN69IFi/DXQiGbv8eFkdfJU= X-Gm-Message-State: AOJu0YwqeqOPtrOKEnME7MZ83ulWIeZrVFS+cXp0fv7y2jvgBBMsG3Co RjkjMciDoBbymSJofLXXgOXzQv5Tlo6hjWIDE3FaVpeaP0FJqIU8eluCgWU8vKdyFSvXE1Hu4UK ohBrDxQ== X-Google-Smtp-Source: AGHT+IEAzauu/kVpHiwxSxMb1TfCUFvEOuX5MwlmnBaBz2RTtFPBxjcqT3DHqeGZBSmP+TO8Nk+0Vw== X-Received: by 2002:a17:907:d18:b0:a77:e2e3:354d with SMTP id a640c23a62f3a-a7d3ffa3102mr692311266b.23.1722357364073; Tue, 30 Jul 2024 09:36:04 -0700 (PDT) Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com. [209.85.208.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb8072sm659895366b.196.2024.07.30.09.36.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jul 2024 09:36:02 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5a3b866ebc9so6693680a12.3 for ; Tue, 30 Jul 2024 09:36:02 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWuNRpcLO9ii8ktPO5MlOVu+x5nDYq+E+p3EB5H0RgBcC6e4hmUVFbkiaBi0M2TW0yfVsbgIBJJsVWsvkMQIq+m4d0= X-Received: by 2002:a50:d55c:0:b0:57c:78fb:1a32 with SMTP id 4fb4d7f45d1cf-5b020ba8220mr7207696a12.19.1722357362359; Tue, 30 Jul 2024 09:36:02 -0700 (PDT) MIME-Version: 1.0 References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> <5cd3e11780df40b0b771da5548966ebd@AcuMS.aculab.com> In-Reply-To: From: Linus Torvalds Date: Tue, 30 Jul 2024 09:35:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/8] minmax: Put all the clamp() definitions together To: Arnd Bergmann Cc: David Laight , "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 Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 30FE04002A X-Stat-Signature: rmk3c3xtbyp97ypd7o6ro8t1t8yt77y1 X-HE-Tag: 1722357365-118616 X-HE-Meta: U2FsdGVkX18X+H5uDBrY7t2FzuxXM/ZRdHFox6X1K4Wcqt7HissOAY0AwfKqB8JsOLAnCbzDneAFDFG16LlFZmrENyaa6f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Jp7XgkMyNbgqSZlqvSpZr03xztMF9Dh9CA/eiLYvsh+hy6I0bXUSpf4JWfxvZ1n7G1h+Lbks2O3QyXhMZ9H3KAy0c9/J7bheUwfWfxhFEuVJqGHq1KE15SIFlxnFErayV2Fj6fOn0x+wc/kRMuDDbydr3b5fLfrIG6aadiFmTE0OwywzX+9my5XtpY41jkZtQFsiU2ikdOf1DGipgyeidUoFx472hF2TSN5SQT8ZajB0pHlf7/+rLTHUj5JEUi7rLLUBKD114FGAx+PBml/jUpJUi35Q7XQK8piAnf2tZ5qnAhaIk4UfyTEVuJzRN6cWEW/D85M6YEFhPQucA1PvkkQ0NCm3tzbY2g= 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 Tue, 30 Jul 2024 at 03:11, Arnd Bergmann wrote: > > I'm giving this a spin on the randconfig test setup now to see > if there are some other cases like the bcachefs one. So far I've > seen one failure, but I can't make sense of it yet: So the new checks are actually a lot smarter, since unlike the old ones they don't require a C constant expression, and will find cases where the compiler can see expressions that turn out statically optimizable. This is a great example of that, although "great" in this case is sadly not what we want: > drivers/gpu/drm/i915/display/intel_backlight.c: In function 'scale': > include/linux/compiler_types.h:510:45: error: call to '__compiletime_assert_905' declared with attribute error: clamp() low limit source_min greater than high limit source_max > include/linux/minmax.h:107:9: note: in expansion of macro 'BUILD_BUG_ON_MSG' > 107 | BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ > drivers/gpu/drm/i915/display/intel_backlight.c:47:22: note: in expansion of macro 'clamp' > 47 | source_val = clamp(source_val, source_min, source_max); So here *locally*, source_min and source_max can't be ordered, but what I think has happened is that we had that earlier WARN_ON(source_min > source_max); and then gcc sees the "statically_true(ulo > uhi)" test, and will do CSE on the variables and on the test condition and the conditional, and basically have turned all of this into if (source_min > source_max) { WARN(..) source_val = clamp(source_val, source_min, source_max); } else { source_val = clamp(source_val, source_min, source_max); } and now the case with the WARN() will statically obviously be bad. I don't see the failure, so it clearly depends on some config default, and I suspect with my allmodconfig build, for example, there is so much else going on that gcc won't have done the above trivial conversion. The old code never saw any of this, because the old code was using the terminally stupid _static_assert(), and within the much more limited scope of a "C constant expression", that "source_min < source_max" could never be true, even if there are code paths where it *is* true. But here I think we were bitten by excessive cleverness. > That's still a typo in the 32-bit case, right? > I've changed > > __builtin_choose_expr(sizeof(ux)>32,1LL,1L)) > > to check for sizeof(ux)>4 for my testing. Bah yes. I had that fix locally, and sent the old patch. Linus