@@ -64,15 +64,6 @@ EXPORT_SYMBOL(memstart_addr);
64
64
*/
65
65
phys_addr_t __ro_after_init arm64_dma_phys_limit ;
66
66
67
- /* Current arm64 boot protocol requires 2MB alignment */
68
- #define CRASH_ALIGN SZ_2M
69
-
70
- #define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit
71
- #define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1)
72
- #define CRASH_HIGH_SEARCH_BASE SZ_4G
73
-
74
- #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20)
75
-
76
67
/*
77
68
* To make optimal use of block mappings when laying out the linear
78
69
* mapping, round down the base of physical memory to a size that can
@@ -100,140 +91,25 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit;
100
91
#define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT)
101
92
#endif
102
93
103
- static int __init reserve_crashkernel_low (unsigned long long low_size )
104
- {
105
- unsigned long long low_base ;
106
-
107
- low_base = memblock_phys_alloc_range (low_size , CRASH_ALIGN , 0 , CRASH_ADDR_LOW_MAX );
108
- if (!low_base ) {
109
- pr_err ("cannot allocate crashkernel low memory (size:0x%llx).\n" , low_size );
110
- return - ENOMEM ;
111
- }
112
-
113
- pr_info ("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n" ,
114
- low_base , low_base + low_size , low_size >> 20 );
115
-
116
- crashk_low_res .start = low_base ;
117
- crashk_low_res .end = low_base + low_size - 1 ;
118
- insert_resource (& iomem_resource , & crashk_low_res );
119
-
120
- return 0 ;
121
- }
122
-
123
- /*
124
- * reserve_crashkernel() - reserves memory for crash kernel
125
- *
126
- * This function reserves memory area given in "crashkernel=" kernel command
127
- * line parameter. The memory reserved is used by dump capture kernel when
128
- * primary kernel is crashing.
129
- */
130
- static void __init reserve_crashkernel (void )
94
+ static void __init arch_reserve_crashkernel (void )
131
95
{
132
- unsigned long long crash_low_size = 0 , search_base = 0 ;
133
- unsigned long long crash_max = CRASH_ADDR_LOW_MAX ;
96
+ unsigned long long low_size = 0 ;
134
97
unsigned long long crash_base , crash_size ;
135
98
char * cmdline = boot_command_line ;
136
- bool fixed_base = false;
137
99
bool high = false;
138
100
int ret ;
139
101
140
102
if (!IS_ENABLED (CONFIG_KEXEC_CORE ))
141
103
return ;
142
104
143
- /* crashkernel=X[@offset] */
144
105
ret = parse_crashkernel (cmdline , memblock_phys_mem_size (),
145
- & crash_size , & crash_base , NULL , NULL );
146
- if (ret == - ENOENT ) {
147
- ret = parse_crashkernel_high (cmdline , 0 , & crash_size , & crash_base );
148
- if (ret || !crash_size )
149
- return ;
150
-
151
- /*
152
- * crashkernel=Y,low can be specified or not, but invalid value
153
- * is not allowed.
154
- */
155
- ret = parse_crashkernel_low (cmdline , 0 , & crash_low_size , & crash_base );
156
- if (ret == - ENOENT )
157
- crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE ;
158
- else if (ret )
159
- return ;
160
-
161
- search_base = CRASH_HIGH_SEARCH_BASE ;
162
- crash_max = CRASH_ADDR_HIGH_MAX ;
163
- high = true;
164
- } else if (ret || !crash_size ) {
165
- /* The specified value is invalid */
106
+ & crash_size , & crash_base ,
107
+ & low_size , & high );
108
+ if (ret )
166
109
return ;
167
- }
168
-
169
- crash_size = PAGE_ALIGN (crash_size );
170
-
171
- /* User specifies base address explicitly. */
172
- if (crash_base ) {
173
- fixed_base = true;
174
- search_base = crash_base ;
175
- crash_max = crash_base + crash_size ;
176
- }
177
-
178
- retry :
179
- crash_base = memblock_phys_alloc_range (crash_size , CRASH_ALIGN ,
180
- search_base , crash_max );
181
- if (!crash_base ) {
182
- /*
183
- * For crashkernel=size[KMG]@offset[KMG], print out failure
184
- * message if can't reserve the specified region.
185
- */
186
- if (fixed_base ) {
187
- pr_warn ("crashkernel reservation failed - memory is in use.\n" );
188
- return ;
189
- }
190
-
191
- /*
192
- * For crashkernel=size[KMG], if the first attempt was for
193
- * low memory, fall back to high memory, the minimum required
194
- * low memory will be reserved later.
195
- */
196
- if (!high && crash_max == CRASH_ADDR_LOW_MAX ) {
197
- crash_max = CRASH_ADDR_HIGH_MAX ;
198
- search_base = CRASH_ADDR_LOW_MAX ;
199
- crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE ;
200
- goto retry ;
201
- }
202
-
203
- /*
204
- * For crashkernel=size[KMG],high, if the first attempt was
205
- * for high memory, fall back to low memory.
206
- */
207
- if (high && crash_max == CRASH_ADDR_HIGH_MAX ) {
208
- crash_max = CRASH_ADDR_LOW_MAX ;
209
- search_base = 0 ;
210
- goto retry ;
211
- }
212
- pr_warn ("cannot allocate crashkernel (size:0x%llx)\n" ,
213
- crash_size );
214
- return ;
215
- }
216
-
217
- if ((crash_base >= CRASH_ADDR_LOW_MAX ) && crash_low_size &&
218
- reserve_crashkernel_low (crash_low_size )) {
219
- memblock_phys_free (crash_base , crash_size );
220
- return ;
221
- }
222
-
223
- pr_info ("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n" ,
224
- crash_base , crash_base + crash_size , crash_size >> 20 );
225
-
226
- /*
227
- * The crashkernel memory will be removed from the kernel linear
228
- * map. Inform kmemleak so that it won't try to access it.
229
- */
230
- kmemleak_ignore_phys (crash_base );
231
- if (crashk_low_res .end )
232
- kmemleak_ignore_phys (crashk_low_res .start );
233
110
234
- crashk_res .start = crash_base ;
235
- crashk_res .end = crash_base + crash_size - 1 ;
236
- insert_resource (& iomem_resource , & crashk_res );
111
+ reserve_crashkernel_generic (cmdline , crash_size , crash_base ,
112
+ low_size , high );
237
113
}
238
114
239
115
/*
@@ -479,7 +355,7 @@ void __init bootmem_init(void)
479
355
* request_standard_resources() depends on crashkernel's memory being
480
356
* reserved, so do it here.
481
357
*/
482
- reserve_crashkernel ();
358
+ arch_reserve_crashkernel ();
483
359
484
360
memblock_dump_all ();
485
361
}
0 commit comments