Skip to content

Commit

Permalink
nios2: Don't use _end for calculating min_low_pfn
Browse files Browse the repository at this point in the history
If there is a initramfs linked into the kernel which will be
freed later on there is free memory somewhere between _etext
and _end, thus using _end for min_low_pfn is not correct.
This may lead to issues in dma_capable when checking
'min(addr, end) < phys_to_dma(dev, PFN_PHYS(min_low_pfn)))'
as the address addr might be below min_low_pfn. Picked
find_limits from architecture arm for applying min_low_pfn and
max_low_pfn. Maybe using _etext for min_low_pfn would be
fine too.

Signed-off-by: Andreas Oetken <andreas.oetken@siemens.com>
Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com>
  • Loading branch information
Andreas Oetken authored and Ley Foon Tan committed Feb 19, 2021
1 parent 9abcfcb commit 7f7bc20
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions arch/nios2/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ EXPORT_SYMBOL(memory_start);
unsigned long memory_end;
EXPORT_SYMBOL(memory_end);

unsigned long memory_size;

static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0};
Expand Down Expand Up @@ -141,16 +139,22 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
parse_early_param();
}

static void __init find_limits(unsigned long *min, unsigned long *max_low,
unsigned long *max_high)
{
*max_low = PFN_DOWN(memblock_get_current_limit());
*min = PFN_UP(memblock_start_of_DRAM());
*max_high = PFN_DOWN(memblock_end_of_DRAM());
}

void __init setup_arch(char **cmdline_p)
{
int dram_start;

console_verbose();

dram_start = memblock_start_of_DRAM();
memory_size = memblock_phys_mem_size();
memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
memory_start = memblock_start_of_DRAM();
memory_end = memblock_end_of_DRAM();

init_mm.start_code = (unsigned long) _stext;
init_mm.end_code = (unsigned long) _etext;
Expand All @@ -161,11 +165,10 @@ void __init setup_arch(char **cmdline_p)
/* Keep a copy of command line */
*cmdline_p = boot_command_line;

min_low_pfn = PFN_UP(memory_start);
max_low_pfn = PFN_DOWN(memory_end);
find_limits(&min_low_pfn, &max_low_pfn, &max_pfn);
max_mapnr = max_low_pfn;

memblock_reserve(dram_start, memory_start - dram_start);
memblock_reserve(__pa_symbol(_stext), _end - _stext);
#ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start) {
memblock_reserve(virt_to_phys((void *)initrd_start),
Expand Down

0 comments on commit 7f7bc20

Please sign in to comment.