Commit | Line | Data |
---|---|---|
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 | ||
5a90857e | 12 | #ifdef CONFIG_KALLSYMS |
389d7070 | 13 | |
d16e08f9 MD |
14 | /* Include page_alloc wrapper before pageblock-flags.h. */ |
15 | #include <wrapper/page_alloc.h> | |
16 | ||
17 | #include <linux/pageblock-flags.h> | |
389d7070 MD |
18 | #include <linux/kallsyms.h> |
19 | #include <linux/mm_types.h> | |
20 | #include <linux/module.h> | |
5a2f5e92 | 21 | #include <wrapper/kallsyms.h> |
d16e08f9 MD |
22 | #include <lttng/kernel-version.h> |
23 | ||
24 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0)) | |
25 | static | |
26 | unsigned long (*get_pfnblock_flags_mask_sym)(const struct page *page, | |
27 | unsigned long pfn, | |
28 | unsigned long mask); | |
29 | ||
30 | unsigned long wrapper_get_pfnblock_flags_mask(const struct page *page, | |
31 | unsigned long pfn, | |
32 | unsigned long mask) | |
33 | { | |
34 | WARN_ON_ONCE(!get_pfnblock_flags_mask_sym); | |
35 | if (get_pfnblock_flags_mask_sym) { | |
36 | struct irq_ibt_state irq_ibt_state; | |
37 | unsigned long ret; | |
389d7070 | 38 | |
d16e08f9 MD |
39 | irq_ibt_state = wrapper_irq_ibt_save(); |
40 | ret = get_pfnblock_flags_mask_sym(page, pfn, mask); | |
41 | wrapper_irq_ibt_restore(irq_ibt_state); | |
42 | return ret; | |
43 | } else { | |
44 | return -ENOSYS; | |
45 | } | |
46 | } | |
47 | #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) | |
48 | static | |
49 | unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page, | |
50 | unsigned long pfn, | |
51 | unsigned long mask); | |
52 | ||
53 | unsigned long wrapper_get_pfnblock_flags_mask(struct page *page, | |
54 | unsigned long pfn, | |
55 | unsigned long mask) | |
56 | { | |
57 | WARN_ON_ONCE(!get_pfnblock_flags_mask_sym); | |
58 | if (get_pfnblock_flags_mask_sym) { | |
59 | struct irq_ibt_state irq_ibt_state; | |
60 | unsigned long ret; | |
61 | ||
62 | irq_ibt_state = wrapper_irq_ibt_save(); | |
63 | ret = get_pfnblock_flags_mask_sym(page, pfn, mask); | |
64 | wrapper_irq_ibt_restore(irq_ibt_state); | |
65 | return ret; | |
66 | } else { | |
67 | return -ENOSYS; | |
68 | } | |
69 | } | |
70 | #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */ | |
389d7070 MD |
71 | static |
72 | unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page, | |
73 | unsigned long pfn, | |
74 | unsigned long end_bitidx, | |
75 | unsigned long mask); | |
76 | ||
77 | unsigned long wrapper_get_pfnblock_flags_mask(struct page *page, | |
78 | unsigned long pfn, | |
79 | unsigned long end_bitidx, | |
80 | unsigned long mask) | |
81 | { | |
82 | WARN_ON_ONCE(!get_pfnblock_flags_mask_sym); | |
83 | if (get_pfnblock_flags_mask_sym) { | |
92e2c5fe MD |
84 | struct irq_ibt_state irq_ibt_state; |
85 | unsigned long ret; | |
86 | ||
87 | irq_ibt_state = wrapper_irq_ibt_save(); | |
88 | ret = get_pfnblock_flags_mask_sym(page, pfn, end_bitidx, mask); | |
89 | wrapper_irq_ibt_restore(irq_ibt_state); | |
90 | return ret; | |
389d7070 MD |
91 | } else { |
92 | return -ENOSYS; | |
93 | } | |
94 | } | |
d16e08f9 MD |
95 | #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,9,0)) */ |
96 | ||
389d7070 MD |
97 | EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask); |
98 | ||
99 | int wrapper_get_pfnblock_flags_mask_init(void) | |
100 | { | |
101 | get_pfnblock_flags_mask_sym = | |
102 | (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask"); | |
103 | if (!get_pfnblock_flags_mask_sym) | |
104 | return -1; | |
105 | return 0; | |
106 | } | |
1c999280 | 107 | EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init); |
389d7070 | 108 | |
0e14d6e7 | 109 | #else |
389d7070 MD |
110 | |
111 | #include <linux/pageblock-flags.h> | |
112 | ||
0e14d6e7 | 113 | #endif |