Skip to content

Commit d5d2c26

Browse files
lyctwpalmer-dabbelt
authored andcommitted
riscv: Improve PTDUMP to show RSW with non-zero value
RSW field can be used to encode 2 bits of software defined information. Currently, PTDUMP only prints "RSW" when its value is 1 or 3. To fix this issue and improve the debugging experience with PTDUMP, we redefine _PAGE_SPECIAL to its original value and use _PAGE_SOFT as the RSW mask, allow it to print the RSW with any non-zero value. This patch also removes the val from the struct prot_bits as it is no longer needed. Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 0bb80ec commit d5d2c26

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

arch/riscv/include/asm/pgtable-bits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#define _PAGE_GLOBAL (1 << 5) /* Global */
1717
#define _PAGE_ACCESSED (1 << 6) /* Set by hardware on any access */
1818
#define _PAGE_DIRTY (1 << 7) /* Set by hardware on any write */
19-
#define _PAGE_SOFT (1 << 8) /* Reserved for software */
19+
#define _PAGE_SOFT (3 << 8) /* Reserved for software */
2020

21-
#define _PAGE_SPECIAL _PAGE_SOFT
21+
#define _PAGE_SPECIAL (1 << 8) /* RSW: 0x1 */
2222
#define _PAGE_TABLE _PAGE_PRESENT
2323

2424
/*

arch/riscv/mm/ptdump.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,55 +129,45 @@ static struct ptd_mm_info efi_ptd_info = {
129129
/* Page Table Entry */
130130
struct prot_bits {
131131
u64 mask;
132-
u64 val;
133132
const char *set;
134133
const char *clear;
135134
};
136135

137136
static const struct prot_bits pte_bits[] = {
138137
{
139138
.mask = _PAGE_SOFT,
140-
.val = _PAGE_SOFT,
141-
.set = "RSW",
142-
.clear = " ",
139+
.set = "RSW(%d)",
140+
.clear = " .. ",
143141
}, {
144142
.mask = _PAGE_DIRTY,
145-
.val = _PAGE_DIRTY,
146143
.set = "D",
147144
.clear = ".",
148145
}, {
149146
.mask = _PAGE_ACCESSED,
150-
.val = _PAGE_ACCESSED,
151147
.set = "A",
152148
.clear = ".",
153149
}, {
154150
.mask = _PAGE_GLOBAL,
155-
.val = _PAGE_GLOBAL,
156151
.set = "G",
157152
.clear = ".",
158153
}, {
159154
.mask = _PAGE_USER,
160-
.val = _PAGE_USER,
161155
.set = "U",
162156
.clear = ".",
163157
}, {
164158
.mask = _PAGE_EXEC,
165-
.val = _PAGE_EXEC,
166159
.set = "X",
167160
.clear = ".",
168161
}, {
169162
.mask = _PAGE_WRITE,
170-
.val = _PAGE_WRITE,
171163
.set = "W",
172164
.clear = ".",
173165
}, {
174166
.mask = _PAGE_READ,
175-
.val = _PAGE_READ,
176167
.set = "R",
177168
.clear = ".",
178169
}, {
179170
.mask = _PAGE_PRESENT,
180-
.val = _PAGE_PRESENT,
181171
.set = "V",
182172
.clear = ".",
183173
}
@@ -208,15 +198,20 @@ static void dump_prot(struct pg_state *st)
208198
unsigned int i;
209199

210200
for (i = 0; i < ARRAY_SIZE(pte_bits); i++) {
211-
const char *s;
212-
213-
if ((st->current_prot & pte_bits[i].mask) == pte_bits[i].val)
214-
s = pte_bits[i].set;
215-
else
216-
s = pte_bits[i].clear;
201+
char s[7];
202+
unsigned long val;
203+
204+
val = st->current_prot & pte_bits[i].mask;
205+
if (val) {
206+
if (pte_bits[i].mask == _PAGE_SOFT)
207+
sprintf(s, pte_bits[i].set, val >> 8);
208+
else
209+
sprintf(s, "%s", pte_bits[i].set);
210+
} else {
211+
sprintf(s, "%s", pte_bits[i].clear);
212+
}
217213

218-
if (s)
219-
pt_dump_seq_printf(st->seq, " %s", s);
214+
pt_dump_seq_printf(st->seq, " %s", s);
220215
}
221216
}
222217

0 commit comments

Comments
 (0)