page alloc wrapper: Fix get_pfnblock_flags_mask prototype
[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 20
5b465053
MD
21/* Include page_alloc wrapper before pageblock-flags.h. */
22#include <wrapper/page_alloc.h>
23
24#include <linux/pageblock-flags.h>
389d7070
MD
25#include <linux/kallsyms.h>
26#include <linux/mm_types.h>
27#include <linux/module.h>
5a2f5e92 28#include <wrapper/kallsyms.h>
5b465053
MD
29#include <lttng/kernel-version.h>
30
31#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0))
32static
33unsigned long (*get_pfnblock_flags_mask_sym)(const struct page *page,
34 unsigned long pfn,
35 unsigned long mask);
36
37unsigned long wrapper_get_pfnblock_flags_mask(const struct page *page,
38 unsigned long pfn,
39 unsigned long mask)
40{
41 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
42 if (get_pfnblock_flags_mask_sym) {
43 struct irq_ibt_state irq_ibt_state;
44 unsigned long ret;
45
46 irq_ibt_state = wrapper_irq_ibt_save();
47 ret = get_pfnblock_flags_mask_sym(page, pfn, mask);
48 wrapper_irq_ibt_restore(irq_ibt_state);
49 return ret;
50 } else {
51 return -ENOSYS;
52 }
53}
54#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0))
55static
56unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page,
57 unsigned long pfn,
58 unsigned long mask);
389d7070 59
5b465053
MD
60unsigned long wrapper_get_pfnblock_flags_mask(struct page *page,
61 unsigned long pfn,
62 unsigned long mask)
63{
64 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
65 if (get_pfnblock_flags_mask_sym) {
66 struct irq_ibt_state irq_ibt_state;
67 unsigned long ret;
68
69 irq_ibt_state = wrapper_irq_ibt_save();
70 ret = get_pfnblock_flags_mask_sym(page, pfn, mask);
71 wrapper_irq_ibt_restore(irq_ibt_state);
72 return ret;
73 } else {
74 return -ENOSYS;
75 }
76}
77#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
389d7070
MD
78static
79unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page,
80 unsigned long pfn,
81 unsigned long end_bitidx,
82 unsigned long mask);
83
84unsigned long wrapper_get_pfnblock_flags_mask(struct page *page,
85 unsigned long pfn,
86 unsigned long end_bitidx,
87 unsigned long mask)
88{
89 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
90 if (get_pfnblock_flags_mask_sym) {
41cbf575
MD
91 struct irq_ibt_state irq_ibt_state;
92 unsigned long ret;
93
94 irq_ibt_state = wrapper_irq_ibt_save();
95 ret = get_pfnblock_flags_mask_sym(page, pfn, end_bitidx, mask);
96 wrapper_irq_ibt_restore(irq_ibt_state);
97 return ret;
389d7070
MD
98 } else {
99 return -ENOSYS;
100 }
101}
5b465053
MD
102#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
103
389d7070
MD
104EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask);
105
106int wrapper_get_pfnblock_flags_mask_init(void)
107{
108 get_pfnblock_flags_mask_sym =
109 (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask");
110 if (!get_pfnblock_flags_mask_sym)
111 return -1;
112 return 0;
113}
1c999280 114EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
389d7070 115
0e14d6e7 116#else
389d7070
MD
117
118#include <linux/pageblock-flags.h>
119
0e14d6e7
MD
120#endif
121
122#if (defined(CONFIG_KALLSYMS) \
123 && LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,50, 3,14,0,0))
124
125#include <linux/kallsyms.h>
126#include <linux/mm_types.h>
127#include <linux/module.h>
5a2f5e92
MD
128#include <wrapper/kallsyms.h>
129#include <wrapper/page_alloc.h>
0e14d6e7
MD
130
131static
132unsigned long (*get_pageblock_flags_mask_sym)(struct page *page,
133 unsigned long end_bitidx,
134 unsigned long mask);
135
136unsigned long wrapper_get_pageblock_flags_mask(struct page *page,
137 unsigned long end_bitidx,
138 unsigned long mask)
139{
140 WARN_ON_ONCE(!get_pageblock_flags_mask_sym);
141 if (get_pageblock_flags_mask_sym) {
142 return get_pageblock_flags_mask_sym(page, end_bitidx, mask);
143 } else {
144 return -ENOSYS;
145 }
146}
147EXPORT_SYMBOL_GPL(wrapper_get_pageblock_flags_mask);
148
149int wrapper_get_pageblock_flags_mask_init(void)
150{
151 get_pageblock_flags_mask_sym =
152 (void *) kallsyms_lookup_funcptr("get_pageblock_flags_mask");
153 if (!get_pageblock_flags_mask_sym)
154 return -1;
155 return 0;
156}
1c999280 157EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
0e14d6e7
MD
158
159#else
160
161#include <linux/pageblock-flags.h>
162
163#endif
This page took 0.059537 seconds and 4 git commands to generate.