vsprintf: Make %pGp print the hex value
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 19 Oct 2021 14:26:21 +0000 (15:26 +0100)
committerPetr Mladek <pmladek@suse.com>
Wed, 27 Oct 2021 11:40:14 +0000 (13:40 +0200)
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) <willy@infradead.org>
Reviewed-by: Yafang Shao <laoar.shao@gmail.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20211019142621.2810043-6-willy@infradead.org
lib/test_printf.c
lib/vsprintf.c
mm/debug.c
mm/memory-failure.c
mm/page_owner.c
mm/slub.c

index d09993fca46397c0008d00e284eec2d59a09c98c..07309c45f327965fdbaca087cd83c138a331a1d9 100644 (file)
@@ -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;
@@ -625,7 +629,6 @@ 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,
@@ -633,6 +636,8 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
                append = true;
        }
 
+       snprintf(cmp_buf + size, BUF_SIZE - size, ")");
+
        test(cmp_buf, "%pGp", &flags);
 }
 
index d7ad44f2c8f5715552ca7e63a8a79aecdb995dce..2140982486101fb91204b52968bd3b4e7e7c91c2 100644 (file)
@@ -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);
@@ -2051,6 +2056,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
 
                append = true;
        }
+       if (buf < end)
+               *buf = ')';
+       buf++;
 
        return buf;
 }
index e73fe0a8ec3d25fe4af305cb89c83288fbba1d18..ca9611784e4b027735e44f1d34564cbf2b7a8ee4 100644 (file)
@@ -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,
index 54879c3390243603ecdcb39686def20d66c6facb..58ab5161a8cef88541a4d2afb50f3e03bed05619 100644 (file)
@@ -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;
index 62402d22539b8e47bc2996cae5f86b63138ae593..4afc713ca5258c1392663f1d3456b0b3ac6141ac 100644 (file)
@@ -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;
index 3d2025f7163b295c45c2b26a8c5260414b2fc238..f7ac28646580e65a200a270cba181f53d85ea828 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -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);
 
 }