ptdump.c (8dd06ef34b6e2f41b29fbf5fc1663780f2524285) ptdump.c (d8ed45c5dcd455fc5848d47f86883a1b872ac0d0)
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/pagewalk.h>
4#include <linux/ptdump.h>
5#include <linux/kasan.h>
6
7#ifdef CONFIG_KASAN
8/*

--- 22 unchanged lines hidden (view full) ---

31 struct ptdump_state *st = walk->private;
32 pgd_t val = READ_ONCE(*pgd);
33
34#if CONFIG_PGTABLE_LEVELS > 4 && defined(CONFIG_KASAN)
35 if (pgd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_p4d)))
36 return note_kasan_page_table(walk, addr);
37#endif
38
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/pagewalk.h>
4#include <linux/ptdump.h>
5#include <linux/kasan.h>
6
7#ifdef CONFIG_KASAN
8/*

--- 22 unchanged lines hidden (view full) ---

31 struct ptdump_state *st = walk->private;
32 pgd_t val = READ_ONCE(*pgd);
33
34#if CONFIG_PGTABLE_LEVELS > 4 && defined(CONFIG_KASAN)
35 if (pgd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_p4d)))
36 return note_kasan_page_table(walk, addr);
37#endif
38
39 if (st->effective_prot)
40 st->effective_prot(st, 0, pgd_val(val));
41
39 if (pgd_leaf(val))
40 st->note_page(st, addr, 0, pgd_val(val));
41
42 return 0;
43}
44
45static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
46 unsigned long next, struct mm_walk *walk)
47{
48 struct ptdump_state *st = walk->private;
49 p4d_t val = READ_ONCE(*p4d);
50
51#if CONFIG_PGTABLE_LEVELS > 3 && defined(CONFIG_KASAN)
52 if (p4d_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pud)))
53 return note_kasan_page_table(walk, addr);
54#endif
55
42 if (pgd_leaf(val))
43 st->note_page(st, addr, 0, pgd_val(val));
44
45 return 0;
46}
47
48static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
49 unsigned long next, struct mm_walk *walk)
50{
51 struct ptdump_state *st = walk->private;
52 p4d_t val = READ_ONCE(*p4d);
53
54#if CONFIG_PGTABLE_LEVELS > 3 && defined(CONFIG_KASAN)
55 if (p4d_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pud)))
56 return note_kasan_page_table(walk, addr);
57#endif
58
59 if (st->effective_prot)
60 st->effective_prot(st, 1, p4d_val(val));
61
56 if (p4d_leaf(val))
57 st->note_page(st, addr, 1, p4d_val(val));
58
59 return 0;
60}
61
62static int ptdump_pud_entry(pud_t *pud, unsigned long addr,
63 unsigned long next, struct mm_walk *walk)
64{
65 struct ptdump_state *st = walk->private;
66 pud_t val = READ_ONCE(*pud);
67
68#if CONFIG_PGTABLE_LEVELS > 2 && defined(CONFIG_KASAN)
69 if (pud_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pmd)))
70 return note_kasan_page_table(walk, addr);
71#endif
72
62 if (p4d_leaf(val))
63 st->note_page(st, addr, 1, p4d_val(val));
64
65 return 0;
66}
67
68static int ptdump_pud_entry(pud_t *pud, unsigned long addr,
69 unsigned long next, struct mm_walk *walk)
70{
71 struct ptdump_state *st = walk->private;
72 pud_t val = READ_ONCE(*pud);
73
74#if CONFIG_PGTABLE_LEVELS > 2 && defined(CONFIG_KASAN)
75 if (pud_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pmd)))
76 return note_kasan_page_table(walk, addr);
77#endif
78
79 if (st->effective_prot)
80 st->effective_prot(st, 2, pud_val(val));
81
73 if (pud_leaf(val))
74 st->note_page(st, addr, 2, pud_val(val));
75
76 return 0;
77}
78
79static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,
80 unsigned long next, struct mm_walk *walk)
81{
82 struct ptdump_state *st = walk->private;
83 pmd_t val = READ_ONCE(*pmd);
84
85#if defined(CONFIG_KASAN)
86 if (pmd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pte)))
87 return note_kasan_page_table(walk, addr);
88#endif
89
82 if (pud_leaf(val))
83 st->note_page(st, addr, 2, pud_val(val));
84
85 return 0;
86}
87
88static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,
89 unsigned long next, struct mm_walk *walk)
90{
91 struct ptdump_state *st = walk->private;
92 pmd_t val = READ_ONCE(*pmd);
93
94#if defined(CONFIG_KASAN)
95 if (pmd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pte)))
96 return note_kasan_page_table(walk, addr);
97#endif
98
99 if (st->effective_prot)
100 st->effective_prot(st, 3, pmd_val(val));
90 if (pmd_leaf(val))
91 st->note_page(st, addr, 3, pmd_val(val));
92
93 return 0;
94}
95
96static int ptdump_pte_entry(pte_t *pte, unsigned long addr,
97 unsigned long next, struct mm_walk *walk)
98{
99 struct ptdump_state *st = walk->private;
101 if (pmd_leaf(val))
102 st->note_page(st, addr, 3, pmd_val(val));
103
104 return 0;
105}
106
107static int ptdump_pte_entry(pte_t *pte, unsigned long addr,
108 unsigned long next, struct mm_walk *walk)
109{
110 struct ptdump_state *st = walk->private;
111 pte_t val = READ_ONCE(*pte);
100
112
101 st->note_page(st, addr, 4, pte_val(READ_ONCE(*pte)));
113 if (st->effective_prot)
114 st->effective_prot(st, 4, pte_val(val));
102
115
116 st->note_page(st, addr, 4, pte_val(val));
117
103 return 0;
104}
105
106static int ptdump_hole(unsigned long addr, unsigned long next,
107 int depth, struct mm_walk *walk)
108{
109 struct ptdump_state *st = walk->private;
110

--- 10 unchanged lines hidden (view full) ---

121 .pte_entry = ptdump_pte_entry,
122 .pte_hole = ptdump_hole,
123};
124
125void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)
126{
127 const struct ptdump_range *range = st->range;
128
118 return 0;
119}
120
121static int ptdump_hole(unsigned long addr, unsigned long next,
122 int depth, struct mm_walk *walk)
123{
124 struct ptdump_state *st = walk->private;
125

--- 10 unchanged lines hidden (view full) ---

136 .pte_entry = ptdump_pte_entry,
137 .pte_hole = ptdump_hole,
138};
139
140void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)
141{
142 const struct ptdump_range *range = st->range;
143
129 down_read(&mm->mmap_sem);
144 mmap_read_lock(mm);
130 while (range->start != range->end) {
131 walk_page_range_novma(mm, range->start, range->end,
132 &ptdump_ops, pgd, st);
133 range++;
134 }
145 while (range->start != range->end) {
146 walk_page_range_novma(mm, range->start, range->end,
147 &ptdump_ops, pgd, st);
148 range++;
149 }
135 up_read(&mm->mmap_sem);
150 mmap_read_unlock(mm);
136
137 /* Flush out the last page */
138 st->note_page(st, 0, -1, 0);
139}
151
152 /* Flush out the last page */
153 st->note_page(st, 0, -1, 0);
154}