page alloc wrapper: Fix get_pfnblock_flags_mask prototype
[lttng-modules.git] / wrapper / page_alloc.c
CommitLineData
9f36eaed 1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
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
5a2f5e92 12#include <lttng-kernel-version.h>
389d7070 13
ffc696db 14#if (defined(CONFIG_KALLSYMS) \
2d042821 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
7a03a49a
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>
7a03a49a
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 return get_pfnblock_flags_mask_sym(page, pfn, mask);
44 } else {
45 return -ENOSYS;
46 }
47}
48#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0))
49static
50unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page,
51 unsigned long pfn,
52 unsigned long mask);
389d7070 53
7a03a49a
MD
54unsigned long wrapper_get_pfnblock_flags_mask(struct page *page,
55 unsigned long pfn,
56 unsigned long mask)
57{
58 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
59 if (get_pfnblock_flags_mask_sym) {
60 return get_pfnblock_flags_mask_sym(page, pfn, mask);
61 } else {
62 return -ENOSYS;
63 }
64}
65#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
389d7070
MD
66static
67unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page,
68 unsigned long pfn,
69 unsigned long end_bitidx,
70 unsigned long mask);
71
72unsigned long wrapper_get_pfnblock_flags_mask(struct page *page,
73 unsigned long pfn,
74 unsigned long end_bitidx,
75 unsigned long mask)
76{
77 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
78 if (get_pfnblock_flags_mask_sym) {
79 return get_pfnblock_flags_mask_sym(page, pfn, end_bitidx, mask);
80 } else {
81 return -ENOSYS;
82 }
83}
7a03a49a
MD
84#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
85
389d7070
MD
86EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask);
87
88int wrapper_get_pfnblock_flags_mask_init(void)
89{
90 get_pfnblock_flags_mask_sym =
91 (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask");
92 if (!get_pfnblock_flags_mask_sym)
93 return -1;
94 return 0;
95}
d4d4da49 96EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
389d7070 97
0e14d6e7 98#else
389d7070
MD
99
100#include <linux/pageblock-flags.h>
101
0e14d6e7
MD
102#endif
103
104#if (defined(CONFIG_KALLSYMS) \
105 && LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,50, 3,14,0,0))
106
107#include <linux/kallsyms.h>
108#include <linux/mm_types.h>
109#include <linux/module.h>
5a2f5e92
MD
110#include <wrapper/kallsyms.h>
111#include <wrapper/page_alloc.h>
0e14d6e7
MD
112
113static
114unsigned long (*get_pageblock_flags_mask_sym)(struct page *page,
115 unsigned long end_bitidx,
116 unsigned long mask);
117
118unsigned long wrapper_get_pageblock_flags_mask(struct page *page,
119 unsigned long end_bitidx,
120 unsigned long mask)
121{
122 WARN_ON_ONCE(!get_pageblock_flags_mask_sym);
123 if (get_pageblock_flags_mask_sym) {
124 return get_pageblock_flags_mask_sym(page, end_bitidx, mask);
125 } else {
126 return -ENOSYS;
127 }
128}
129EXPORT_SYMBOL_GPL(wrapper_get_pageblock_flags_mask);
130
131int wrapper_get_pageblock_flags_mask_init(void)
132{
133 get_pageblock_flags_mask_sym =
134 (void *) kallsyms_lookup_funcptr("get_pageblock_flags_mask");
135 if (!get_pageblock_flags_mask_sym)
136 return -1;
137 return 0;
138}
d4d4da49 139EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
0e14d6e7
MD
140
141#else
142
143#include <linux/pageblock-flags.h>
144
145#endif
This page took 0.049261 seconds and 4 git commands to generate.