Skip to content

Commit 23efd08

Browse files
Matthew Wilcox (Oracle)pmladek
authored andcommitted
vsprintf: Make %pGp print the hex value
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]
1 parent 507f986 commit 23efd08

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

lib/test_printf.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,14 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
609609
char *cmp_buf)
610610
{
611611
unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag};
612-
unsigned long size = 0;
612+
unsigned long size;
613613
bool append = false;
614614
int i;
615615

616+
for (i = 0; i < ARRAY_SIZE(values); i++)
617+
flags |= (values[i] & pft[i].mask) << pft[i].shift;
618+
619+
size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags);
616620
if (flags & PAGEFLAGS_MASK) {
617621
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
618622
append = true;
@@ -625,14 +629,15 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
625629
if (append)
626630
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
627631

628-
flags |= (values[i] & pft[i].mask) << pft[i].shift;
629632
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
630633
pft[i].name);
631634
size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
632635
values[i] & pft[i].mask);
633636
append = true;
634637
}
635638

639+
snprintf(cmp_buf + size, BUF_SIZE - size, ")");
640+
636641
test(cmp_buf, "%pGp", &flags);
637642
}
638643

lib/vsprintf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,11 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
20232023
bool append = false;
20242024
int i;
20252025

2026+
buf = number(buf, end, flags, default_flag_spec);
2027+
if (buf < end)
2028+
*buf = '(';
2029+
buf++;
2030+
20262031
/* Page flags from the main area. */
20272032
if (main_flags) {
20282033
buf = format_flags(buf, end, main_flags, pageflag_names);
@@ -2051,6 +2056,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
20512056

20522057
append = true;
20532058
}
2059+
if (buf < end)
2060+
*buf = ')';
2061+
buf++;
20542062

20552063
return buf;
20562064
}

mm/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static void __dump_page(struct page *page)
160160
out_mapping:
161161
BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1);
162162

163-
pr_warn("%sflags: %#lx(%pGp)%s\n", type, head->flags, &head->flags,
163+
pr_warn("%sflags: %pGp%s\n", type, &head->flags,
164164
page_cma ? " CMA" : "");
165165
print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32,
166166
sizeof(unsigned long), page,

mm/memory-failure.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,14 +2109,14 @@ static int __soft_offline_page(struct page *page)
21092109
if (!list_empty(&pagelist))
21102110
putback_movable_pages(&pagelist);
21112111

2112-
pr_info("soft offline: %#lx: %s migration failed %d, type %lx (%pGp)\n",
2113-
pfn, msg_page[huge], ret, page->flags, &page->flags);
2112+
pr_info("soft offline: %#lx: %s migration failed %d, type %pGp\n",
2113+
pfn, msg_page[huge], ret, &page->flags);
21142114
if (ret > 0)
21152115
ret = -EBUSY;
21162116
}
21172117
} else {
2118-
pr_info("soft offline: %#lx: %s isolation failed, page count %d, type %lx (%pGp)\n",
2119-
pfn, msg_page[huge], page_count(page), page->flags, &page->flags);
2118+
pr_info("soft offline: %#lx: %s isolation failed, page count %d, type %pGp\n",
2119+
pfn, msg_page[huge], page_count(page), &page->flags);
21202120
ret = -EBUSY;
21212121
}
21222122
return ret;

mm/page_owner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
351351
pageblock_mt = get_pageblock_migratetype(page);
352352
page_mt = gfp_migratetype(page_owner->gfp_mask);
353353
ret += snprintf(kbuf + ret, count - ret,
354-
"PFN %lu type %s Block %lu type %s Flags %#lx(%pGp)\n",
354+
"PFN %lu type %s Block %lu type %s Flags %pGp\n",
355355
pfn,
356356
migratetype_names[page_mt],
357357
pfn >> pageblock_order,
358358
migratetype_names[pageblock_mt],
359-
page->flags, &page->flags);
359+
&page->flags);
360360

361361
if (ret >= count)
362362
goto err;

mm/slub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,9 @@ void print_tracking(struct kmem_cache *s, void *object)
763763

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

770770
}
771771

0 commit comments

Comments
 (0)