hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/arch/x86/include/asm/boot.h
....@@ -40,23 +40,40 @@
4040 #ifdef CONFIG_X86_64
4141 # define BOOT_STACK_SIZE 0x4000
4242
43
-# define BOOT_INIT_PGT_SIZE (6*4096)
44
-# ifdef CONFIG_RANDOMIZE_BASE
4543 /*
46
- * Assuming all cross the 512GB boundary:
47
- * 1 page for level4
48
- * (2+2)*4 pages for kernel, param, cmd_line, and randomized kernel
49
- * 2 pages for first 2M (video RAM: CONFIG_X86_VERBOSE_BOOTUP).
50
- * Total is 19 pages.
44
+ * Used by decompressor's startup_32() to allocate page tables for identity
45
+ * mapping of the 4G of RAM in 4-level paging mode:
46
+ * - 1 level4 table;
47
+ * - 1 level3 table;
48
+ * - 4 level2 table that maps everything with 2M pages;
49
+ *
50
+ * The additional level5 table needed for 5-level paging is allocated from
51
+ * trampoline_32bit memory.
5152 */
52
-# ifdef CONFIG_X86_VERBOSE_BOOTUP
53
-# define BOOT_PGT_SIZE (19*4096)
54
-# else /* !CONFIG_X86_VERBOSE_BOOTUP */
55
-# define BOOT_PGT_SIZE (17*4096)
56
-# endif
57
-# else /* !CONFIG_RANDOMIZE_BASE */
58
-# define BOOT_PGT_SIZE BOOT_INIT_PGT_SIZE
59
-# endif
53
+# define BOOT_INIT_PGT_SIZE (6*4096)
54
+
55
+/*
56
+ * Total number of page tables kernel_add_identity_map() can allocate,
57
+ * including page tables consumed by startup_32().
58
+ *
59
+ * Worst-case scenario:
60
+ * - 5-level paging needs 1 level5 table;
61
+ * - KASLR needs to map kernel, boot_params, cmdline and randomized kernel,
62
+ * assuming all of them cross 256T boundary:
63
+ * + 4*2 level4 table;
64
+ * + 4*2 level3 table;
65
+ * + 4*2 level2 table;
66
+ * - X86_VERBOSE_BOOTUP needs to map the first 2M (video RAM):
67
+ * + 1 level4 table;
68
+ * + 1 level3 table;
69
+ * + 1 level2 table;
70
+ * Total: 28 tables
71
+ *
72
+ * Add 4 spare table in case decompressor touches anything beyond what is
73
+ * accounted above. Warn if it happens.
74
+ */
75
+# define BOOT_PGT_SIZE_WARN (28*4096)
76
+# define BOOT_PGT_SIZE (32*4096)
6077
6178 #else /* !CONFIG_X86_64 */
6279 # define BOOT_STACK_SIZE 0x1000