Fix: Disable IBT around indirect function calls
[lttng-modules.git] / src / wrapper / page_alloc.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
389d7070
MD
2 * wrapper/page_alloc.c
3 *
0e14d6e7
MD
4 * wrapper around get_pfnblock_flags_mask and Ubuntu
5 * get_pageblock_flags_mask. Using KALLSYMS to get their address when
6 * available, else we need to have a kernel that exports this function
7 * to GPL modules.
389d7070
MD
8 *
9 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
389d7070
MD
10 */
11
2df37e95 12#include <lttng/kernel-version.h>
389d7070 13
ffc696db 14#if (defined(CONFIG_KALLSYMS) \
5f4c791e 15 && (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,19,2) \
36561775
MD
16 || LTTNG_KERNEL_RANGE(3,14,36, 3,15,0) \
17 || LTTNG_KERNEL_RANGE(3,18,10, 3,19,0) \
397c12b4
MD
18 || LTTNG_DEBIAN_KERNEL_RANGE(3,16,7,9,0,0, 3,17,0,0,0,0) \
19 || LTTNG_UBUNTU_KERNEL_RANGE(3,16,7,34, 3,17,0,0)))
389d7070
MD
20
21#include <linux/kallsyms.h>
22#include <linux/mm_types.h>
23#include <linux/module.h>
5a2f5e92
MD
24#include <wrapper/kallsyms.h>
25#include <wrapper/page_alloc.h>
389d7070
MD
26
27static
28unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page,
29 unsigned long pfn,
30 unsigned long end_bitidx,
31 unsigned long mask);
32
33unsigned long wrapper_get_pfnblock_flags_mask(struct page *page,
34 unsigned long pfn,
35 unsigned long end_bitidx,
36 unsigned long mask)
37{
38 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
39 if (get_pfnblock_flags_mask_sym) {
41cbf575
MD
40 struct irq_ibt_state irq_ibt_state;
41 unsigned long ret;
42
43 irq_ibt_state = wrapper_irq_ibt_save();
44 ret = get_pfnblock_flags_mask_sym(page, pfn, end_bitidx, mask);
45 wrapper_irq_ibt_restore(irq_ibt_state);
46 return ret;
389d7070
MD
47 } else {
48 return -ENOSYS;
49 }
50}
51EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask);
52
53int wrapper_get_pfnblock_flags_mask_init(void)
54{
55 get_pfnblock_flags_mask_sym =
56 (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask");
57 if (!get_pfnblock_flags_mask_sym)
58 return -1;
59 return 0;
60}
1c999280 61EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
389d7070 62
3dfec228
MJ
63/*
64 * Canary function to check for 'get_pfnblock_flags_mask()' at compile time.
65 *
66 * From 'include/linux/pageblock-flags.h':
67 *
68 * unsigned long get_pfnblock_flags_mask(struct page *page,
69 * unsigned long pfn,
70 * unsigned long end_bitidx,
71 * unsigned long mask);
72 */
73__attribute__((unused)) static
74unsigned long __canary__get_pfnblock_flags_mask(struct page *page,
75 unsigned long pfn,
76 unsigned long end_bitidx,
77 unsigned long mask)
78{
79 return get_pfnblock_flags_mask(page, pfn, end_bitidx, mask);
80}
81
0e14d6e7 82#else
389d7070
MD
83
84#include <linux/pageblock-flags.h>
85
0e14d6e7
MD
86#endif
87
88#if (defined(CONFIG_KALLSYMS) \
89 && LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,50, 3,14,0,0))
90
91#include <linux/kallsyms.h>
92#include <linux/mm_types.h>
93#include <linux/module.h>
5a2f5e92
MD
94#include <wrapper/kallsyms.h>
95#include <wrapper/page_alloc.h>
0e14d6e7
MD
96
97static
98unsigned long (*get_pageblock_flags_mask_sym)(struct page *page,
99 unsigned long end_bitidx,
100 unsigned long mask);
101
102unsigned long wrapper_get_pageblock_flags_mask(struct page *page,
103 unsigned long end_bitidx,
104 unsigned long mask)
105{
106 WARN_ON_ONCE(!get_pageblock_flags_mask_sym);
107 if (get_pageblock_flags_mask_sym) {
108 return get_pageblock_flags_mask_sym(page, end_bitidx, mask);
109 } else {
110 return -ENOSYS;
111 }
112}
113EXPORT_SYMBOL_GPL(wrapper_get_pageblock_flags_mask);
114
115int wrapper_get_pageblock_flags_mask_init(void)
116{
117 get_pageblock_flags_mask_sym =
118 (void *) kallsyms_lookup_funcptr("get_pageblock_flags_mask");
119 if (!get_pageblock_flags_mask_sym)
120 return -1;
121 return 0;
122}
1c999280 123EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
0e14d6e7
MD
124
125#else
126
127#include <linux/pageblock-flags.h>
128
129#endif
This page took 0.055583 seconds and 4 git commands to generate.