1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
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
9 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include <lttng/kernel-version.h>
14 #if (defined(CONFIG_KALLSYMS) \
15 && (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,19,2) \
16 || LTTNG_KERNEL_RANGE(3,14,36, 3,15,0) \
17 || LTTNG_KERNEL_RANGE(3,18,10, 3,19,0) \
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)))
21 /* Include page_alloc wrapper before pageblock-flags.h. */
22 #include <wrapper/page_alloc.h>
24 #include <linux/pageblock-flags.h>
25 #include <linux/kallsyms.h>
26 #include <linux/mm_types.h>
27 #include <linux/module.h>
28 #include <wrapper/kallsyms.h>
29 #include <lttng/kernel-version.h>
31 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0))
33 unsigned long (*get_pfnblock_flags_mask_sym
)(const struct page
*page
,
37 unsigned long wrapper_get_pfnblock_flags_mask(const struct page
*page
,
41 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym
);
42 if (get_pfnblock_flags_mask_sym
) {
43 struct irq_ibt_state irq_ibt_state
;
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
);
54 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0))
56 unsigned long (*get_pfnblock_flags_mask_sym
)(struct page
*page
,
60 unsigned long wrapper_get_pfnblock_flags_mask(struct page
*page
,
64 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym
);
65 if (get_pfnblock_flags_mask_sym
) {
66 struct irq_ibt_state irq_ibt_state
;
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
);
77 #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
79 unsigned long (*get_pfnblock_flags_mask_sym
)(struct page
*page
,
81 unsigned long end_bitidx
,
84 unsigned long wrapper_get_pfnblock_flags_mask(struct page
*page
,
86 unsigned long end_bitidx
,
89 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym
);
90 if (get_pfnblock_flags_mask_sym
) {
91 struct irq_ibt_state irq_ibt_state
;
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
);
102 #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */
104 EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask
);
106 int wrapper_get_pfnblock_flags_mask_init(void)
108 get_pfnblock_flags_mask_sym
=
109 (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask");
110 if (!get_pfnblock_flags_mask_sym
)
114 EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init
);
118 #include <linux/pageblock-flags.h>
122 #if (defined(CONFIG_KALLSYMS) \
123 && LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,50, 3,14,0,0))
125 #include <linux/kallsyms.h>
126 #include <linux/mm_types.h>
127 #include <linux/module.h>
128 #include <wrapper/kallsyms.h>
129 #include <wrapper/page_alloc.h>
132 unsigned long (*get_pageblock_flags_mask_sym
)(struct page
*page
,
133 unsigned long end_bitidx
,
136 unsigned long wrapper_get_pageblock_flags_mask(struct page
*page
,
137 unsigned long end_bitidx
,
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
);
147 EXPORT_SYMBOL_GPL(wrapper_get_pageblock_flags_mask
);
149 int wrapper_get_pageblock_flags_mask_init(void)
151 get_pageblock_flags_mask_sym
=
152 (void *) kallsyms_lookup_funcptr("get_pageblock_flags_mask");
153 if (!get_pageblock_flags_mask_sym
)
157 EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init
);
161 #include <linux/pageblock-flags.h>