Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 35a1021

Browse files
torvaldsgregkh
authored andcommitted
minmax: avoid overly complex min()/max() macro arguments in xen
[ Upstream commit e8432ac ] We have some very fancy min/max macros that have tons of sanity checking to warn about mixed signedness etc. This is all things that a sane compiler should warn about, but there are no sane compiler interfaces for this, and '-Wsign-compare' is broken [1] and not useful. So then we compensate (some would say over-compensate) by doing the checks manually with some truly horrid macro games. And no, we can't just use __builtin_types_compatible_p(), because the whole question of "does it make sense to compare these two values" is a lot more complicated than that. For example, it makes a ton of sense to compare unsigned values with simple constants like "5", even if that is indeed a signed type. So we have these very strange macros to try to make sensible type checking decisions on the arguments to 'min()' and 'max()'. But that can cause enormous code expansion if the min()/max() macros are used with complicated expressions, and particularly if you nest these things so that you get the first big expansion then expanded again. The xen setup.c file ended up ballooning to over 50MB of preprocessed noise that takes 15s to compile (obviously depending on the build host), largely due to one single line. So let's split that one single line to just be simpler. I think it ends up being more legible to humans too at the same time. Now that single file compiles in under a second. Reported-and-reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Link: https://lore.kernel.org/all/c83c17bb-be75-4c67-979d-54eee38774c6@lucifer.local/ Link: https://staticthinking.wordpress.com/2023/07/25/wsign-compare-is-garbage/ [1] Cc: David Laight <David.Laight@aculab.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Stable-dep-of: be35d91 ("xen: tolerate ACPI NVS memory overlapping with Xen allocated memory") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 27f113d commit 35a1021

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/x86/xen/setup.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ char * __init xen_memory_setup(void)
691691
struct xen_memory_map memmap;
692692
unsigned long max_pages;
693693
unsigned long extra_pages = 0;
694+
unsigned long maxmem_pages;
694695
int i;
695696
int op;
696697

@@ -762,8 +763,8 @@ char * __init xen_memory_setup(void)
762763
* Make sure we have no memory above max_pages, as this area
763764
* isn't handled by the p2m management.
764765
*/
765-
extra_pages = min3(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
766-
extra_pages, max_pages - max_pfn);
766+
maxmem_pages = EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM));
767+
extra_pages = min3(maxmem_pages, extra_pages, max_pages - max_pfn);
767768
i = 0;
768769
addr = xen_e820_table.entries[0].addr;
769770
size = xen_e820_table.entries[0].size;

0 commit comments

Comments
 (0)