OSDN Git Service

arm64: Add vmap_stack header file
authorJames Morse <james.morse@arm.com>
Mon, 8 Jan 2018 15:38:10 +0000 (15:38 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Sat, 13 Jan 2018 10:45:03 +0000 (10:45 +0000)
Today the arm64 arch code allocates an extra IRQ stack per-cpu. If we
also have SDEI and VMAP stacks we need two extra per-cpu VMAP stacks.

Move the VMAP stack allocation out to a helper in a new header file.
This avoids missing THREADINFO_GFP, or getting the all-important alignment
wrong.

Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/vmap_stack.h [new file with mode: 0644]
arch/arm64/kernel/irq.c

diff --git a/arch/arm64/include/asm/vmap_stack.h b/arch/arm64/include/asm/vmap_stack.h
new file mode 100644 (file)
index 0000000..0b5ec6e
--- /dev/null
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2017 Arm Ltd.
+#ifndef __ASM_VMAP_STACK_H
+#define __ASM_VMAP_STACK_H
+
+#include <linux/bug.h>
+#include <linux/gfp.h>
+#include <linux/kconfig.h>
+#include <linux/vmalloc.h>
+#include <asm/memory.h>
+#include <asm/pgtable.h>
+#include <asm/thread_info.h>
+
+/*
+ * To ensure that VMAP'd stack overflow detection works correctly, all VMAP'd
+ * stacks need to have the same alignment.
+ */
+static inline unsigned long *arch_alloc_vmap_stack(size_t stack_size, int node)
+{
+       BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK));
+
+       return __vmalloc_node_range(stack_size, THREAD_ALIGN,
+                                   VMALLOC_START, VMALLOC_END,
+                                   THREADINFO_GFP, PAGE_KERNEL, 0, node,
+                                   __builtin_return_address(0));
+}
+
+#endif /* __ASM_VMAP_STACK_H */
index 713561e..60e5fc6 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/irqchip.h>
 #include <linux/seq_file.h>
 #include <linux/vmalloc.h>
+#include <asm/vmap_stack.h>
 
 unsigned long irq_err_count;
 
@@ -58,17 +59,7 @@ static void init_irq_stacks(void)
        unsigned long *p;
 
        for_each_possible_cpu(cpu) {
-               /*
-               * To ensure that VMAP'd stack overflow detection works
-               * correctly, the IRQ stacks need to have the same
-               * alignment as other stacks.
-               */
-               p = __vmalloc_node_range(IRQ_STACK_SIZE, THREAD_ALIGN,
-                                        VMALLOC_START, VMALLOC_END,
-                                        THREADINFO_GFP, PAGE_KERNEL,
-                                        0, cpu_to_node(cpu),
-                                        __builtin_return_address(0));
-
+               p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
                per_cpu(irq_stack_ptr, cpu) = p;
        }
 }