From: Konstantin Khorenko <[email protected]> Sometimes a function which allocates high order pages is called with different flags while kvmalloc() should be called with at least GFP_KERNEL.
kvmalloc_check() function uses kvmalloc() when possible depending on flags provided. https://jira.sw.ru/browse/PSBM-82593 Signed-off-by: Konstantin Khorenko <[email protected]> Reviewed-by: Andrey Ryabinin <[email protected]> [VvS RHEL77b rebase] (cherry picked from commit def125fece273fbcf26310d3af80ca90ac8f5400) VZ 8 rebase part https://jira.sw.ru/browse/PSBM-127798 Signed-off-by: Alexander Mikhalitsyn <[email protected]> --- include/linux/mm.h | 1 + mm/util.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 807ecde29a42..1ae180a3f4a9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -667,6 +667,7 @@ static inline void *kvcalloc(size_t n, size_t size, gfp_t flags) return kvmalloc_array(n, size, flags | __GFP_ZERO); } +extern void *kvmalloc_check(size_t size, gfp_t flags); extern void kvfree(const void *addr); static inline int compound_mapcount(struct page *page) diff --git a/mm/util.c b/mm/util.c index e99de9d3c8ae..b8b568fce0f9 100644 --- a/mm/util.c +++ b/mm/util.c @@ -502,6 +502,20 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) } EXPORT_SYMBOL(kvmalloc_node); +/* + * Sometimes a function which allocates high order pages is called with + * different flags while kvmalloc() should be called with at least GFP_KERNEL. + * This function uses kvmalloc() when possible depending on flags provided. + */ +void *kvmalloc_check(size_t size, gfp_t flags) +{ + if ((flags & GFP_KERNEL) == GFP_KERNEL) + return kvmalloc(size, flags); + else + return kmalloc(size, flags); +} +EXPORT_SYMBOL(kvmalloc_check); + void kvfree(const void *addr) { if (is_vmalloc_addr(addr)) -- 2.28.0 _______________________________________________ Devel mailing list [email protected] https://lists.openvz.org/mailman/listinfo/devel
