Skip to content

Commit f6e5a07

Browse files
author
Fox Snowpatch
committed
1 parent f85c105 commit f6e5a07

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

arch/powerpc/include/asm/fadump.h

+7
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ extern int early_init_dt_scan_fw_dump(unsigned long node, const char *uname,
3434
int depth, void *data);
3535
extern int fadump_reserve_mem(void);
3636
#endif
37+
38+
#if defined(CONFIG_FA_DUMP) && defined(CONFIG_CMA)
39+
void fadump_cma_init(void);
40+
#else
41+
static inline void fadump_cma_init(void) { }
42+
#endif
43+
3744
#endif /* _ASM_POWERPC_FADUMP_H */

arch/powerpc/kernel/fadump.c

+28-27
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,38 @@ static struct cma *fadump_cma;
7878
* But for some reason even if it fails we still have the memory reservation
7979
* with us and we can still continue doing fadump.
8080
*/
81-
static int __init fadump_cma_init(void)
81+
void __init fadump_cma_init(void)
8282
{
83-
unsigned long long base, size;
83+
unsigned long long base, size, end;
8484
int rc;
8585

86-
if (!fw_dump.fadump_enabled)
87-
return 0;
88-
86+
if (!fw_dump.fadump_supported || !fw_dump.fadump_enabled ||
87+
fw_dump.dump_active)
88+
return;
8989
/*
9090
* Do not use CMA if user has provided fadump=nocma kernel parameter.
91-
* Return 1 to continue with fadump old behaviour.
9291
*/
93-
if (fw_dump.nocma)
94-
return 1;
92+
if (fw_dump.nocma || !fw_dump.boot_memory_size)
93+
return;
9594

95+
/*
96+
* [base, end) should be reserved during early init in
97+
* fadump_reserve_mem(). No need to check this here as
98+
* cma_init_reserved_mem() already checks for overlap.
99+
* Here we give the aligned chunk of this reserved memory to CMA.
100+
*/
96101
base = fw_dump.reserve_dump_area_start;
97102
size = fw_dump.boot_memory_size;
103+
end = base + size;
98104

99-
if (!size)
100-
return 0;
105+
base = ALIGN(base, CMA_MIN_ALIGNMENT_BYTES);
106+
end = ALIGN_DOWN(end, CMA_MIN_ALIGNMENT_BYTES);
107+
size = end - base;
108+
109+
if (end <= base) {
110+
pr_warn("%s: Too less memory to give to CMA\n", __func__);
111+
return;
112+
}
101113

102114
rc = cma_init_reserved_mem(base, size, 0, "fadump_cma", &fadump_cma);
103115
if (rc) {
@@ -108,7 +120,7 @@ static int __init fadump_cma_init(void)
108120
* blocked from production system usage. Hence return 1,
109121
* so that we can continue with fadump.
110122
*/
111-
return 1;
123+
return;
112124
}
113125

114126
/*
@@ -120,15 +132,13 @@ static int __init fadump_cma_init(void)
120132
/*
121133
* So we now have successfully initialized cma area for fadump.
122134
*/
123-
pr_info("Initialized 0x%lx bytes cma area at %ldMB from 0x%lx "
135+
pr_info("Initialized [0x%llx, %luMB] cma area from [0x%lx, %luMB] "
124136
"bytes of memory reserved for firmware-assisted dump\n",
125-
cma_get_size(fadump_cma),
126-
(unsigned long)cma_get_base(fadump_cma) >> 20,
127-
fw_dump.reserve_dump_area_size);
128-
return 1;
137+
cma_get_base(fadump_cma), cma_get_size(fadump_cma) >> 20,
138+
fw_dump.reserve_dump_area_start,
139+
fw_dump.boot_memory_size >> 20);
140+
return;
129141
}
130-
#else
131-
static int __init fadump_cma_init(void) { return 1; }
132142
#endif /* CONFIG_CMA */
133143

134144
/*
@@ -558,13 +568,6 @@ int __init fadump_reserve_mem(void)
558568
if (!fw_dump.dump_active) {
559569
fw_dump.boot_memory_size =
560570
PAGE_ALIGN(fadump_calculate_reserve_size());
561-
#ifdef CONFIG_CMA
562-
if (!fw_dump.nocma) {
563-
fw_dump.boot_memory_size =
564-
ALIGN(fw_dump.boot_memory_size,
565-
CMA_MIN_ALIGNMENT_BYTES);
566-
}
567-
#endif
568571

569572
bootmem_min = fw_dump.ops->fadump_get_bootmem_min();
570573
if (fw_dump.boot_memory_size < bootmem_min) {
@@ -637,8 +640,6 @@ int __init fadump_reserve_mem(void)
637640

638641
pr_info("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n",
639642
(size >> 20), base, (memblock_phys_mem_size() >> 20));
640-
641-
ret = fadump_cma_init();
642643
}
643644

644645
return ret;

arch/powerpc/kernel/setup-common.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,11 @@ void __init setup_arch(char **cmdline_p)
997997
initmem_init();
998998

999999
/*
1000-
* Reserve large chunks of memory for use by CMA for KVM and hugetlb. These must
1001-
* be called after initmem_init(), so that pageblock_order is initialised.
1000+
* Reserve large chunks of memory for use by CMA for fadump, KVM and
1001+
* hugetlb. These must be called after initmem_init(), so that
1002+
* pageblock_order is initialised.
10021003
*/
1004+
fadump_cma_init();
10031005
kvm_cma_reserve();
10041006
gigantic_hugetlb_cma_reserve();
10051007

mm/cma.c

+9
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
182182
if (!size || !memblock_is_region_reserved(base, size))
183183
return -EINVAL;
184184

185+
/*
186+
* CMA uses CMA_MIN_ALIGNMENT_BYTES as alignment requirement which
187+
* needs pageblock_order to be initialized. Let's enforce it.
188+
*/
189+
if (!pageblock_order) {
190+
pr_err("pageblock_order not yet initialized. Called during early boot?\n");
191+
return -EINVAL;
192+
}
193+
185194
/* ensure minimal alignment required by mm core */
186195
if (!IS_ALIGNED(base | size, CMA_MIN_ALIGNMENT_BYTES))
187196
return -EINVAL;

0 commit comments

Comments
 (0)