scs.c (23689e91fb22c15b84ac6c22ad9942039792f3af) scs.c (f6e39794f4b6da7ca9b77f2f9ad11fd6f0ac83e5)
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/cpuhotplug.h>

--- 18 unchanged lines hidden (view full) ---

27static void *__scs_alloc(int node)
28{
29 int i;
30 void *s;
31
32 for (i = 0; i < NR_CACHED_SCS; i++) {
33 s = this_cpu_xchg(scs_cache[i], NULL);
34 if (s) {
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/cpuhotplug.h>

--- 18 unchanged lines hidden (view full) ---

27static void *__scs_alloc(int node)
28{
29 int i;
30 void *s;
31
32 for (i = 0; i < NR_CACHED_SCS; i++) {
33 s = this_cpu_xchg(scs_cache[i], NULL);
34 if (s) {
35 kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_NONE);
35 s = kasan_unpoison_vmalloc(s, SCS_SIZE,
36 KASAN_VMALLOC_PROT_NORMAL);
36 memset(s, 0, SCS_SIZE);
37 memset(s, 0, SCS_SIZE);
37 return s;
38 goto out;
38 }
39 }
40
39 }
40 }
41
41 return __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END,
42 s = __vmalloc_node_range(SCS_SIZE, 1, VMALLOC_START, VMALLOC_END,
42 GFP_SCS, PAGE_KERNEL, 0, node,
43 __builtin_return_address(0));
43 GFP_SCS, PAGE_KERNEL, 0, node,
44 __builtin_return_address(0));
45
46out:
47 return kasan_reset_tag(s);
44}
45
46void *scs_alloc(int node)
47{
48 void *s;
49
50 s = __scs_alloc(node);
51 if (!s)

--- 21 unchanged lines hidden (view full) ---

73 * so use this_cpu_cmpxchg to update the cache, and vfree_atomic
74 * to free the stack.
75 */
76
77 for (i = 0; i < NR_CACHED_SCS; i++)
78 if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL)
79 return;
80
48}
49
50void *scs_alloc(int node)
51{
52 void *s;
53
54 s = __scs_alloc(node);
55 if (!s)

--- 21 unchanged lines hidden (view full) ---

77 * so use this_cpu_cmpxchg to update the cache, and vfree_atomic
78 * to free the stack.
79 */
80
81 for (i = 0; i < NR_CACHED_SCS; i++)
82 if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL)
83 return;
84
81 kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_NONE);
85 kasan_unpoison_vmalloc(s, SCS_SIZE, KASAN_VMALLOC_PROT_NORMAL);
82 vfree_atomic(s);
83}
84
85static int scs_cleanup(unsigned int cpu)
86{
87 int i;
88 void **cache = per_cpu_ptr(scs_cache, cpu);
89

--- 65 unchanged lines hidden ---
86 vfree_atomic(s);
87}
88
89static int scs_cleanup(unsigned int cpu)
90{
91 int i;
92 void **cache = per_cpu_ptr(scs_cache, cpu);
93

--- 65 unchanged lines hidden ---