Skip to content

Commit acc3d3a

Browse files
Sebastian EneMarc Zyngier
authored andcommitted
arm64: ptdump: Expose the attribute parsing functionality
Reuse the descriptor parsing functionality to keep the same output format as the original ptdump code. In order for this to happen, move the state tracking objects into a common header. [maz: Fixed note_page() stub as suggested by Will] Signed-off-by: Sebastian Ene <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 29caeda commit acc3d3a

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

arch/arm64/include/asm/ptdump.h

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef __ASM_PTDUMP_H
66
#define __ASM_PTDUMP_H
77

8+
#include <linux/ptdump.h>
9+
810
#ifdef CONFIG_PTDUMP_CORE
911

1012
#include <linux/mm_types.h>
@@ -21,14 +23,52 @@ struct ptdump_info {
2123
unsigned long base_addr;
2224
};
2325

26+
struct ptdump_prot_bits {
27+
u64 mask;
28+
u64 val;
29+
const char *set;
30+
const char *clear;
31+
};
32+
33+
struct ptdump_pg_level {
34+
const struct ptdump_prot_bits *bits;
35+
char name[4];
36+
int num;
37+
u64 mask;
38+
};
39+
40+
/*
41+
* The page dumper groups page table entries of the same type into a single
42+
* description. It uses pg_state to track the range information while
43+
* iterating over the pte entries. When the continuity is broken it then
44+
* dumps out a description of the range.
45+
*/
46+
struct ptdump_pg_state {
47+
struct ptdump_state ptdump;
48+
struct seq_file *seq;
49+
const struct addr_marker *marker;
50+
const struct mm_struct *mm;
51+
unsigned long start_address;
52+
int level;
53+
u64 current_prot;
54+
bool check_wx;
55+
unsigned long wx_pages;
56+
unsigned long uxn_pages;
57+
};
58+
2459
void ptdump_walk(struct seq_file *s, struct ptdump_info *info);
60+
void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
61+
u64 val);
2562
#ifdef CONFIG_PTDUMP_DEBUGFS
2663
#define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64
2764
void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name);
2865
#else
2966
static inline void ptdump_debugfs_register(struct ptdump_info *info,
3067
const char *name) { }
31-
#endif
68+
#endif /* CONFIG_PTDUMP_DEBUGFS */
69+
#else
70+
static inline void note_page(struct ptdump_state *pt_st, unsigned long addr,
71+
int level, u64 val) { }
3272
#endif /* CONFIG_PTDUMP_CORE */
3373

3474
#endif /* __ASM_PTDUMP_H */

arch/arm64/mm/ptdump.c

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,7 @@
3838
seq_printf(m, fmt); \
3939
})
4040

41-
/*
42-
* The page dumper groups page table entries of the same type into a single
43-
* description. It uses pg_state to track the range information while
44-
* iterating over the pte entries. When the continuity is broken it then
45-
* dumps out a description of the range.
46-
*/
47-
struct pg_state {
48-
struct ptdump_state ptdump;
49-
struct seq_file *seq;
50-
const struct addr_marker *marker;
51-
const struct mm_struct *mm;
52-
unsigned long start_address;
53-
int level;
54-
u64 current_prot;
55-
bool check_wx;
56-
unsigned long wx_pages;
57-
unsigned long uxn_pages;
58-
};
59-
60-
struct prot_bits {
61-
u64 mask;
62-
u64 val;
63-
const char *set;
64-
const char *clear;
65-
};
66-
67-
static const struct prot_bits pte_bits[] = {
41+
static const struct ptdump_prot_bits pte_bits[] = {
6842
{
6943
.mask = PTE_VALID,
7044
.val = PTE_VALID,
@@ -143,14 +117,7 @@ static const struct prot_bits pte_bits[] = {
143117
}
144118
};
145119

146-
struct pg_level {
147-
const struct prot_bits *bits;
148-
char name[4];
149-
int num;
150-
u64 mask;
151-
};
152-
153-
static struct pg_level pg_level[] __ro_after_init = {
120+
static struct ptdump_pg_level pg_level[] __ro_after_init = {
154121
{ /* pgd */
155122
.name = "PGD",
156123
.bits = pte_bits,
@@ -174,7 +141,7 @@ static struct pg_level pg_level[] __ro_after_init = {
174141
},
175142
};
176143

177-
static void dump_prot(struct pg_state *st, const struct prot_bits *bits,
144+
static void dump_prot(struct ptdump_pg_state *st, const struct ptdump_prot_bits *bits,
178145
size_t num)
179146
{
180147
unsigned i;
@@ -192,7 +159,7 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits,
192159
}
193160
}
194161

195-
static void note_prot_uxn(struct pg_state *st, unsigned long addr)
162+
static void note_prot_uxn(struct ptdump_pg_state *st, unsigned long addr)
196163
{
197164
if (!st->check_wx)
198165
return;
@@ -206,7 +173,7 @@ static void note_prot_uxn(struct pg_state *st, unsigned long addr)
206173
st->uxn_pages += (addr - st->start_address) / PAGE_SIZE;
207174
}
208175

209-
static void note_prot_wx(struct pg_state *st, unsigned long addr)
176+
static void note_prot_wx(struct ptdump_pg_state *st, unsigned long addr)
210177
{
211178
if (!st->check_wx)
212179
return;
@@ -221,10 +188,10 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr)
221188
st->wx_pages += (addr - st->start_address) / PAGE_SIZE;
222189
}
223190

224-
static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
225-
u64 val)
191+
void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
192+
u64 val)
226193
{
227-
struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);
194+
struct ptdump_pg_state *st = container_of(pt_st, struct ptdump_pg_state, ptdump);
228195
static const char units[] = "KMGTPE";
229196
u64 prot = 0;
230197

@@ -286,12 +253,12 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
286253
void ptdump_walk(struct seq_file *s, struct ptdump_info *info)
287254
{
288255
unsigned long end = ~0UL;
289-
struct pg_state st;
256+
struct ptdump_pg_state st;
290257

291258
if (info->base_addr < TASK_SIZE_64)
292259
end = TASK_SIZE_64;
293260

294-
st = (struct pg_state){
261+
st = (struct ptdump_pg_state){
295262
.seq = s,
296263
.marker = info->markers,
297264
.mm = info->mm,
@@ -324,7 +291,7 @@ static struct ptdump_info kernel_ptdump_info __ro_after_init = {
324291

325292
bool ptdump_check_wx(void)
326293
{
327-
struct pg_state st = {
294+
struct ptdump_pg_state st = {
328295
.seq = NULL,
329296
.marker = (struct addr_marker[]) {
330297
{ 0, NULL},

0 commit comments

Comments
 (0)