b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Shadow Call Stack support. |
| 4 | * |
| 5 | * Copyright (C) 2019 Google LLC |
| 6 | */ |
| 7 | |
| 8 | #include <linux/percpu.h> |
| 9 | #include <linux/vmalloc.h> |
| 10 | #include <asm/pgtable.h> |
| 11 | #include <asm/scs.h> |
| 12 | |
| 13 | DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr); |
| 14 | |
| 15 | #ifndef CONFIG_SHADOW_CALL_STACK_VMAP |
| 16 | DEFINE_PER_CPU(unsigned long [SCS_SIZE/sizeof(long)], irq_shadow_call_stack) |
| 17 | __aligned(SCS_SIZE); |
| 18 | #endif |
| 19 | |
| 20 | void scs_init_irq(void) |
| 21 | { |
| 22 | int cpu; |
| 23 | |
| 24 | for_each_possible_cpu(cpu) { |
| 25 | #ifdef CONFIG_SHADOW_CALL_STACK_VMAP |
| 26 | unsigned long *p; |
| 27 | |
| 28 | p = __vmalloc_node_range(PAGE_SIZE, SCS_SIZE, |
| 29 | VMALLOC_START, VMALLOC_END, |
| 30 | GFP_SCS, PAGE_KERNEL, |
| 31 | 0, cpu_to_node(cpu), |
| 32 | __builtin_return_address(0)); |
| 33 | |
| 34 | per_cpu(irq_shadow_call_stack_ptr, cpu) = p; |
| 35 | #else |
| 36 | per_cpu(irq_shadow_call_stack_ptr, cpu) = |
| 37 | per_cpu(irq_shadow_call_stack, cpu); |
| 38 | #endif /* CONFIG_SHADOW_CALL_STACK_VMAP */ |
| 39 | } |
| 40 | } |