Skip to content

Commit 0effdf4

Browse files
Muchun Songakpm00
Muchun Song
authored andcommitted
mm: hugetlb_vmemmap: disable hugetlb_optimize_vmemmap when struct page crosses page boundaries
Patch series "add hugetlb_optimize_vmemmap sysctl", v11. This series aims to add hugetlb_optimize_vmemmap sysctl to enable or disable the feature of optimizing vmemmap pages associated with HugeTLB pages. This patch (of 4): If the size of "struct page" is not the power of two but with the feature of minimizing overhead of struct page associated with each HugeTLB is enabled, then the vmemmap pages of HugeTLB will be corrupted after remapping (panic is about to happen in theory). But this only exists when !CONFIG_MEMCG && !CONFIG_SLUB on x86_64. However, it is not a conventional configuration nowadays. So it is not a real word issue, just the result of a code review. But we cannot prevent anyone from configuring that combined configure. This hugetlb_optimize_vmemmap should be disable in this case to fix this issue. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Muchun Song <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Iurii Zaikin <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Xiongchun Duan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a00a875 commit 0effdf4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

mm/hugetlb_vmemmap.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ EXPORT_SYMBOL(hugetlb_optimize_vmemmap_key);
2828

2929
static int __init hugetlb_vmemmap_early_param(char *buf)
3030
{
31-
/* We cannot optimize if a "struct page" crosses page boundaries. */
32-
if (!is_power_of_2(sizeof(struct page))) {
33-
pr_warn("cannot free vmemmap pages because \"struct page\" crosses page boundaries\n");
34-
return 0;
35-
}
36-
3731
if (!buf)
3832
return -EINVAL;
3933

@@ -119,6 +113,12 @@ void __init hugetlb_vmemmap_init(struct hstate *h)
119113
if (!hugetlb_optimize_vmemmap_enabled())
120114
return;
121115

116+
if (!is_power_of_2(sizeof(struct page))) {
117+
pr_warn_once("cannot optimize vmemmap pages because \"struct page\" crosses page boundaries\n");
118+
static_branch_disable(&hugetlb_optimize_vmemmap_key);
119+
return;
120+
}
121+
122122
vmemmap_pages = (nr_pages * sizeof(struct page)) >> PAGE_SHIFT;
123123
/*
124124
* The head page is not to be freed to buddy allocator, the other tail

0 commit comments

Comments
 (0)