From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F07A531D75B; Mon, 27 Oct 2025 18:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591464; cv=none; b=DNhpmN8rBXkpLKc03QROsojap08fNbzGFI1cJpQhFa+8ByjbCKCdV6a8QuTEUjf7u4RqV1n1a0PI/5s4sLE3lKgYNwWLJqdGGea57fNyL5P3J4jBHttOBZTiEnIJ5920TzTrY4mtbHv61fQ388VwJAO7Q198Ma5mOglLobtgFPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591464; c=relaxed/simple; bh=B+yJ+mxSPgDHBGrPqhC/ATUt/zZsm83b/5FyUFzwwEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Roa0t9HnPNlOEdtd33haufOgsdGgTkH5yCp6iDwHIbfDCZouRbfSVxxyhnREVyLoSL6uQTHhLmPKMW2oafbKulHp+Hq/9GyavbrCv+TEn+tJvDYIOw0nuwOmTNZCKjz8JtZaczfbpbeMhK/yVZJ3xUx0uFVzjoD0oqvf+TehR6E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kUgOOW4W; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kUgOOW4W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75EB3C4CEF1; Mon, 27 Oct 2025 18:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761591463; bh=B+yJ+mxSPgDHBGrPqhC/ATUt/zZsm83b/5FyUFzwwEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kUgOOW4WBylW9K71h4D81lH1xR9ucseyUISi07xwJAZsGjPHolG/kJqO25PeziX37 klvekc+QnGcya0lfrCqfJCbOb+tIRj+XXYhuVbyngw9zb9UJZC20zL0bbXc2kbFLkS r7hwAlFVGWztm7bn2KGEvah91XafQXfySgK0EMjs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lorenzo Stoakes , David Laight , Linus Torvalds , Eliav Farber Subject: [PATCH 5.10 206/332] minmax: avoid overly complicated constant expressions in VM code Date: Mon, 27 Oct 2025 19:34:19 +0100 Message-ID: <20251027183530.169257339@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183524.611456697@linuxfoundation.org> References: <20251027183524.611456697@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linus Torvalds [ Upstream commit 3a7e02c040b130b5545e4b115aada7bacd80a2b6 ] The minmax infrastructure is overkill for simple constants, and can cause huge expansions because those simple constants are then used by other things. For example, 'pageblock_order' is a core VM constant, but because it was implemented using 'min_t()' and all the type-checking that involves, it actually expanded to something like 2.5kB of preprocessor noise. And when that simple constant was then used inside other expansions: #define pageblock_nr_pages (1UL << pageblock_order) #define pageblock_start_pfn(pfn) ALIGN_DOWN((pfn), pageblock_nr_pages) and we then use that inside a 'max()' macro: case ISOLATE_SUCCESS: update_cached = false; last_migrated_pfn = max(cc->zone->zone_start_pfn, pageblock_start_pfn(cc->migrate_pfn - 1)); the end result was that one statement expanding to 253kB in size. There are probably other cases of this, but this one case certainly stood out. I've added 'MIN_T()' and 'MAX_T()' macros for this kind of "core simple constant with specific type" use. These macros skip the type checking, and as such need to be very sparingly used only for obvious cases that have active issues like this. Reported-by: Lorenzo Stoakes Link: https://lore.kernel.org/all/36aa2cad-1db1-4abf-8dd2-fb20484aabc3@lucifer.local/ Cc: David Laight Signed-off-by: Linus Torvalds Signed-off-by: Eliav Farber Signed-off-by: Greg Kroah-Hartman --- include/linux/minmax.h | 7 +++++++ 1 file changed, 7 insertions(+) --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -270,4 +270,11 @@ static inline bool in_range32(u32 val, u #define swap(a, b) \ do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) +/* + * Use these carefully: no type checking, and uses the arguments + * multiple times. Use for obvious constants only. + */ +#define MIN_T(type,a,b) __cmp(min,(type)(a),(type)(b)) +#define MAX_T(type,a,b) __cmp(max,(type)(a),(type)(b)) + #endif /* _LINUX_MINMAX_H */