Commit 828f193d authored by Steve Capper's avatar Steve Capper Committed by Catalin Marinas

arm64: hugetlb: Cleanup setup_hugepagesz

Replace a lot of if statements with switch and case labels to make it
much clearer which huge page sizes are supported.

Also, we prevent PUD_SIZE from being used on systems not running with
4KB PAGE_SIZE. Before if one supplied PUD_SIZE in these circumstances,
then unusuable huge page sizes would be in use.

Fixes: 084bd298 ("ARM64: mm: HugeTLB support.")
Cc: David Woods <dwoods@mellanox.com>
Signed-off-by: default avatarSteve Capper <steve.capper@arm.com>
Signed-off-by: default avatarPunit Agrawal <punit.agrawal@arm.com>
Reviewed-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 5cd028b9
...@@ -404,20 +404,20 @@ static __init int setup_hugepagesz(char *opt) ...@@ -404,20 +404,20 @@ static __init int setup_hugepagesz(char *opt)
{ {
unsigned long ps = memparse(opt, &opt); unsigned long ps = memparse(opt, &opt);
if (ps == PMD_SIZE) { switch (ps) {
hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT); #ifdef CONFIG_ARM64_4K_PAGES
} else if (ps == PUD_SIZE) { case PUD_SIZE:
hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT); #endif
} else if (ps == (PAGE_SIZE * CONT_PTES)) { case PMD_SIZE * CONT_PMDS:
hugetlb_add_hstate(CONT_PTE_SHIFT); case PMD_SIZE:
} else if (ps == (PMD_SIZE * CONT_PMDS)) { case PAGE_SIZE * CONT_PTES:
hugetlb_add_hstate((PMD_SHIFT + CONT_PMD_SHIFT) - PAGE_SHIFT); hugetlb_add_hstate(ilog2(ps) - PAGE_SHIFT);
} else { return 1;
}
hugetlb_bad_size(); hugetlb_bad_size();
pr_err("hugepagesz: Unsupported page size %lu K\n", ps >> 10); pr_err("hugepagesz: Unsupported page size %lu K\n", ps >> 10);
return 0; return 0;
}
return 1;
} }
__setup("hugepagesz=", setup_hugepagesz); __setup("hugepagesz=", setup_hugepagesz);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment