Skip to content

Commit

Permalink
vsprintf: Make %pGp print the hex value
Browse files Browse the repository at this point in the history
All existing users of %pGp want the hex value as well as the decoded
flag names.  This looks awkward (passing the same parameter to printf
twice), so move that functionality into the core.  If we want, we
can make that optional with flag arguments to %pGp in the future.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: Yafang Shao <[email protected]>
Reviewed-by: Petr Mladek <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
Matthew Wilcox (Oracle) authored and pmladek committed Oct 27, 2021
1 parent 507f986 commit 23efd08
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/test_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,14 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
char *cmp_buf)
{
unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag};
unsigned long size = 0;
unsigned long size;
bool append = false;
int i;

for (i = 0; i < ARRAY_SIZE(values); i++)
flags |= (values[i] & pft[i].mask) << pft[i].shift;

size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags);
if (flags & PAGEFLAGS_MASK) {
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
append = true;
Expand All @@ -625,14 +629,15 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
if (append)
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");

flags |= (values[i] & pft[i].mask) << pft[i].shift;
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
pft[i].name);
size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
values[i] & pft[i].mask);
append = true;
}

snprintf(cmp_buf + size, BUF_SIZE - size, ")");

test(cmp_buf, "%pGp", &flags);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,11 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
bool append = false;
int i;

buf = number(buf, end, flags, default_flag_spec);
if (buf < end)
*buf = '(';
buf++;

/* Page flags from the main area. */
if (main_flags) {
buf = format_flags(buf, end, main_flags, pageflag_names);
Expand Down Expand Up @@ -2051,6 +2056,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)

append = true;
}
if (buf < end)
*buf = ')';
buf++;

return buf;
}
Expand Down
2 changes: 1 addition & 1 deletion mm/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void __dump_page(struct page *page)
out_mapping:
BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1);

pr_warn("%sflags: %#lx(%pGp)%s\n", type, head->flags, &head->flags,
pr_warn("%sflags: %pGp%s\n", type, &head->flags,
page_cma ? " CMA" : "");
print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32,
sizeof(unsigned long), page,
Expand Down
8 changes: 4 additions & 4 deletions mm/memory-failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -2109,14 +2109,14 @@ static int __soft_offline_page(struct page *page)
if (!list_empty(&pagelist))
putback_movable_pages(&pagelist);

pr_info("soft offline: %#lx: %s migration failed %d, type %lx (%pGp)\n",
pfn, msg_page[huge], ret, page->flags, &page->flags);
pr_info("soft offline: %#lx: %s migration failed %d, type %pGp\n",
pfn, msg_page[huge], ret, &page->flags);
if (ret > 0)
ret = -EBUSY;
}
} else {
pr_info("soft offline: %#lx: %s isolation failed, page count %d, type %lx (%pGp)\n",
pfn, msg_page[huge], page_count(page), page->flags, &page->flags);
pr_info("soft offline: %#lx: %s isolation failed, page count %d, type %pGp\n",
pfn, msg_page[huge], page_count(page), &page->flags);
ret = -EBUSY;
}
return ret;
Expand Down
4 changes: 2 additions & 2 deletions mm/page_owner.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
pageblock_mt = get_pageblock_migratetype(page);
page_mt = gfp_migratetype(page_owner->gfp_mask);
ret += snprintf(kbuf + ret, count - ret,
"PFN %lu type %s Block %lu type %s Flags %#lx(%pGp)\n",
"PFN %lu type %s Block %lu type %s Flags %pGp\n",
pfn,
migratetype_names[page_mt],
pfn >> pageblock_order,
migratetype_names[pageblock_mt],
page->flags, &page->flags);
&page->flags);

if (ret >= count)
goto err;
Expand Down
4 changes: 2 additions & 2 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ void print_tracking(struct kmem_cache *s, void *object)

static void print_page_info(struct page *page)
{
pr_err("Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n",
pr_err("Slab 0x%p objects=%u used=%u fp=0x%p flags=%pGp\n",
page, page->objects, page->inuse, page->freelist,
page->flags, &page->flags);
&page->flags);

}

Expand Down

0 comments on commit 23efd08

Please sign in to comment.