* [PATCH] mm/page_alloc: Restrict and formalize compound_page_dtors[]
@ 2020-05-18 9:59 Anshuman Khandual
2020-05-18 10:05 ` David Hildenbrand
0 siblings, 1 reply; 2+ messages in thread
From: Anshuman Khandual @ 2020-05-18 9:59 UTC (permalink / raw)
To: linux-mm; +Cc: Anshuman Khandual, Andrew Morton, linux-kernel
Restrict elements in compound_page_dtors[] array per NR_COMPOUND_DTORS and
explicitly position them according to enum compound_dtor_id. This improves
protection against possible misalignment between compound_page_dtors[] and
enum compound_dtor_id later on.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
include/linux/mm.h | 2 +-
mm/page_alloc.c | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 688558c57751..d1bd7736a5e5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -856,7 +856,7 @@ enum compound_dtor_id {
#endif
NR_COMPOUND_DTORS,
};
-extern compound_page_dtor * const compound_page_dtors[];
+extern compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS];
static inline void set_compound_page_dtor(struct page *page,
enum compound_dtor_id compound_dtor)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index cef05d3a23f5..2e4c23b34940 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -302,14 +302,14 @@ const char * const migratetype_names[MIGRATE_TYPES] = {
#endif
};
-compound_page_dtor * const compound_page_dtors[] = {
- NULL,
- free_compound_page,
+compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS] = {
+ [NULL_COMPOUND_DTOR] = NULL,
+ [COMPOUND_PAGE_DTOR] = free_compound_page,
#ifdef CONFIG_HUGETLB_PAGE
- free_huge_page,
+ [HUGETLB_PAGE_DTOR] = free_huge_page,
#endif
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
- free_transhuge_page,
+ [TRANSHUGE_PAGE_DTOR] = free_transhuge_page,
#endif
};
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/page_alloc: Restrict and formalize compound_page_dtors[]
2020-05-18 9:59 [PATCH] mm/page_alloc: Restrict and formalize compound_page_dtors[] Anshuman Khandual
@ 2020-05-18 10:05 ` David Hildenbrand
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2020-05-18 10:05 UTC (permalink / raw)
To: Anshuman Khandual, linux-mm; +Cc: Andrew Morton, linux-kernel
On 18.05.20 11:59, Anshuman Khandual wrote:
> Restrict elements in compound_page_dtors[] array per NR_COMPOUND_DTORS and
> explicitly position them according to enum compound_dtor_id. This improves
> protection against possible misalignment between compound_page_dtors[] and
> enum compound_dtor_id later on.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> include/linux/mm.h | 2 +-
> mm/page_alloc.c | 10 +++++-----
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 688558c57751..d1bd7736a5e5 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -856,7 +856,7 @@ enum compound_dtor_id {
> #endif
> NR_COMPOUND_DTORS,
> };
> -extern compound_page_dtor * const compound_page_dtors[];
> +extern compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS];
>
> static inline void set_compound_page_dtor(struct page *page,
> enum compound_dtor_id compound_dtor)
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index cef05d3a23f5..2e4c23b34940 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -302,14 +302,14 @@ const char * const migratetype_names[MIGRATE_TYPES] = {
> #endif
> };
>
> -compound_page_dtor * const compound_page_dtors[] = {
> - NULL,
> - free_compound_page,
> +compound_page_dtor * const compound_page_dtors[NR_COMPOUND_DTORS] = {
> + [NULL_COMPOUND_DTOR] = NULL,
> + [COMPOUND_PAGE_DTOR] = free_compound_page,
> #ifdef CONFIG_HUGETLB_PAGE
> - free_huge_page,
> + [HUGETLB_PAGE_DTOR] = free_huge_page,
> #endif
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> - free_transhuge_page,
> + [TRANSHUGE_PAGE_DTOR] = free_transhuge_page,
> #endif
> };
>
>
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-18 10:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18 9:59 [PATCH] mm/page_alloc: Restrict and formalize compound_page_dtors[] Anshuman Khandual
2020-05-18 10:05 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).