Commit 0aaa58ec authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'printk-for-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux

Pull printk updates from Petr Mladek:

 - Extend %pGp print format to print hex value of the page flags

 - Use kvmalloc instead of kmalloc to allocate devkmsg buffers

 - Misc cleanup and warning fixes

* tag 'printk-for-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
  vsprintf: Update %pGp documentation about that it prints hex value
  lib/vsprintf.c: Amend static asserts for format specifier flags
  vsprintf: Make %pGp print the hex value
  test_printf: Append strings more efficiently
  test_printf: Remove custom appending of '|'
  test_printf: Remove separate page_flags variable
  test_printf: Make pft array const
  ia64: don't do IA64_CMPXCHG_DEBUG without CONFIG_PRINTK
  printk: use gnu_printf format attribute for printk_sprint()
  printk: avoid -Wsometimes-uninitialized warning
  printk: use kvmalloc instead of kmalloc for devkmsg_user
parents c150d66b 40e64a88
...@@ -580,7 +580,7 @@ Flags bitfields such as page flags, gfp_flags ...@@ -580,7 +580,7 @@ Flags bitfields such as page flags, gfp_flags
:: ::
%pGp referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff %pGp 0x17ffffc0002036(referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff)
%pGg GFP_USER|GFP_DMA32|GFP_NOWARN %pGg GFP_USER|GFP_DMA32|GFP_NOWARN
%pGv read|exec|mayread|maywrite|mayexec|denywrite %pGv read|exec|mayread|maywrite|mayexec|denywrite
......
...@@ -39,7 +39,7 @@ config DISABLE_VHPT ...@@ -39,7 +39,7 @@ config DISABLE_VHPT
config IA64_DEBUG_CMPXCHG config IA64_DEBUG_CMPXCHG
bool "Turn on compare-and-exchange bug checking (slow!)" bool "Turn on compare-and-exchange bug checking (slow!)"
depends on DEBUG_KERNEL depends on DEBUG_KERNEL && PRINTK
help help
Selecting this option turns on bug checking for the IA-64 Selecting this option turns on bug checking for the IA-64
compare-and-exchange instructions. This is slow! Itaniums compare-and-exchange instructions. This is slow! Itaniums
......
...@@ -26,10 +26,9 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos) ...@@ -26,10 +26,9 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos)
if (mod) { if (mod) {
entries = mod->printk_index_start; entries = mod->printk_index_start;
nr_entries = mod->printk_index_size; nr_entries = mod->printk_index_size;
} } else
#endif #endif
{
if (!mod) {
/* vmlinux, comes from linker symbols */ /* vmlinux, comes from linker symbols */
entries = __start_printk_index; entries = __start_printk_index;
nr_entries = __stop_printk_index - __start_printk_index; nr_entries = __stop_printk_index - __start_printk_index;
......
...@@ -847,7 +847,7 @@ static int devkmsg_open(struct inode *inode, struct file *file) ...@@ -847,7 +847,7 @@ static int devkmsg_open(struct inode *inode, struct file *file)
return err; return err;
} }
user = kmalloc(sizeof(struct devkmsg_user), GFP_KERNEL); user = kvmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
if (!user) if (!user)
return -ENOMEM; return -ENOMEM;
...@@ -875,7 +875,7 @@ static int devkmsg_release(struct inode *inode, struct file *file) ...@@ -875,7 +875,7 @@ static int devkmsg_release(struct inode *inode, struct file *file)
ratelimit_state_exit(&user->rs); ratelimit_state_exit(&user->rs);
mutex_destroy(&user->lock); mutex_destroy(&user->lock);
kfree(user); kvfree(user);
return 0; return 0;
} }
...@@ -2066,6 +2066,7 @@ u16 printk_parse_prefix(const char *text, int *level, ...@@ -2066,6 +2066,7 @@ u16 printk_parse_prefix(const char *text, int *level,
return prefix_len; return prefix_len;
} }
__printf(5, 0)
static u16 printk_sprint(char *text, u16 size, int facility, static u16 printk_sprint(char *text, u16 size, int facility,
enum printk_info_flags *flags, const char *fmt, enum printk_info_flags *flags, const char *fmt,
va_list args) va_list args)
......
...@@ -586,70 +586,59 @@ struct page_flags_test { ...@@ -586,70 +586,59 @@ struct page_flags_test {
int width; int width;
int shift; int shift;
int mask; int mask;
unsigned long value;
const char *fmt; const char *fmt;
const char *name; const char *name;
}; };
static struct page_flags_test pft[] = { static const struct page_flags_test pft[] = {
{SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK,
0, "%d", "section"}, "%d", "section"},
{NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK,
0, "%d", "node"}, "%d", "node"},
{ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK,
0, "%d", "zone"}, "%d", "zone"},
{LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK,
0, "%#x", "lastcpupid"}, "%#x", "lastcpupid"},
{KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK,
0, "%#x", "kasantag"}, "%#x", "kasantag"},
}; };
static void __init static void __init
page_flags_test(int section, int node, int zone, int last_cpupid, page_flags_test(int section, int node, int zone, int last_cpupid,
int kasan_tag, int flags, const char *name, char *cmp_buf) int kasan_tag, unsigned long flags, const char *name,
char *cmp_buf)
{ {
unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag}; unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag};
unsigned long page_flags = 0; unsigned long size;
unsigned long size = 0;
bool append = false; bool append = false;
int i; int i;
flags &= PAGEFLAGS_MASK; for (i = 0; i < ARRAY_SIZE(values); i++)
if (flags) { flags |= (values[i] & pft[i].mask) << pft[i].shift;
page_flags |= flags;
snprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
size = strlen(cmp_buf);
#if SECTIONS_WIDTH || NODES_WIDTH || ZONES_WIDTH || \
LAST_CPUPID_WIDTH || KASAN_TAG_WIDTH
/* Other information also included in page flags */
snprintf(cmp_buf + size, BUF_SIZE - size, "|");
size = strlen(cmp_buf);
#endif
}
/* Set the test value */ size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags);
for (i = 0; i < ARRAY_SIZE(pft); i++) if (flags & PAGEFLAGS_MASK) {
pft[i].value = values[i]; size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
append = true;
}
for (i = 0; i < ARRAY_SIZE(pft); i++) { for (i = 0; i < ARRAY_SIZE(pft); i++) {
if (!pft[i].width) if (!pft[i].width)
continue; continue;
if (append) { if (append)
snprintf(cmp_buf + size, BUF_SIZE - size, "|"); size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
size = strlen(cmp_buf);
}
page_flags |= (pft[i].value & pft[i].mask) << pft[i].shift; size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
snprintf(cmp_buf + size, BUF_SIZE - size, "%s=", pft[i].name); pft[i].name);
size = strlen(cmp_buf); size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
snprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt, values[i] & pft[i].mask);
pft[i].value & pft[i].mask);
size = strlen(cmp_buf);
append = true; append = true;
} }
test(cmp_buf, "%pGp", &page_flags); snprintf(cmp_buf + size, BUF_SIZE - size, ")");
test(cmp_buf, "%pGp", &flags);
} }
static void __init static void __init
......
...@@ -408,8 +408,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width) ...@@ -408,8 +408,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */ #define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */ #define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
static_assert(SIGN == 1);
static_assert(ZEROPAD == ('0' - ' ')); static_assert(ZEROPAD == ('0' - ' '));
static_assert(SMALL == ' '); static_assert(SMALL == ('a' ^ 'A'));
enum format_type { enum format_type {
FORMAT_TYPE_NONE, /* Just a string part */ FORMAT_TYPE_NONE, /* Just a string part */
...@@ -2023,6 +2024,11 @@ char *format_page_flags(char *buf, char *end, unsigned long flags) ...@@ -2023,6 +2024,11 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
bool append = false; bool append = false;
int i; int i;
buf = number(buf, end, flags, default_flag_spec);
if (buf < end)
*buf = '(';
buf++;
/* Page flags from the main area. */ /* Page flags from the main area. */
if (main_flags) { if (main_flags) {
buf = format_flags(buf, end, main_flags, pageflag_names); buf = format_flags(buf, end, main_flags, pageflag_names);
...@@ -2051,6 +2057,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags) ...@@ -2051,6 +2057,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
append = true; append = true;
} }
if (buf < end)
*buf = ')';
buf++;
return buf; return buf;
} }
......
...@@ -162,7 +162,7 @@ static void __dump_page(struct page *page) ...@@ -162,7 +162,7 @@ static void __dump_page(struct page *page)
out_mapping: out_mapping:
BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1); 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" : ""); page_cma ? " CMA" : "");
print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32, print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32,
sizeof(unsigned long), page, sizeof(unsigned long), page,
......
...@@ -2109,14 +2109,14 @@ static int __soft_offline_page(struct page *page) ...@@ -2109,14 +2109,14 @@ static int __soft_offline_page(struct page *page)
if (!list_empty(&pagelist)) if (!list_empty(&pagelist))
putback_movable_pages(&pagelist); putback_movable_pages(&pagelist);
pr_info("soft offline: %#lx: %s migration failed %d, type %lx (%pGp)\n", pr_info("soft offline: %#lx: %s migration failed %d, type %pGp\n",
pfn, msg_page[huge], ret, page->flags, &page->flags); pfn, msg_page[huge], ret, &page->flags);
if (ret > 0) if (ret > 0)
ret = -EBUSY; ret = -EBUSY;
} }
} else { } else {
pr_info("soft offline: %#lx: %s isolation failed, page count %d, type %lx (%pGp)\n", pr_info("soft offline: %#lx: %s isolation failed, page count %d, type %pGp\n",
pfn, msg_page[huge], page_count(page), page->flags, &page->flags); pfn, msg_page[huge], page_count(page), &page->flags);
ret = -EBUSY; ret = -EBUSY;
} }
return ret; return ret;
......
...@@ -351,12 +351,12 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, ...@@ -351,12 +351,12 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
pageblock_mt = get_pageblock_migratetype(page); pageblock_mt = get_pageblock_migratetype(page);
page_mt = gfp_migratetype(page_owner->gfp_mask); page_mt = gfp_migratetype(page_owner->gfp_mask);
ret += snprintf(kbuf + ret, count - ret, 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, pfn,
migratetype_names[page_mt], migratetype_names[page_mt],
pfn >> pageblock_order, pfn >> pageblock_order,
migratetype_names[pageblock_mt], migratetype_names[pageblock_mt],
page->flags, &page->flags); &page->flags);
if (ret >= count) if (ret >= count)
goto err; goto err;
......
...@@ -763,9 +763,9 @@ void print_tracking(struct kmem_cache *s, void *object) ...@@ -763,9 +763,9 @@ void print_tracking(struct kmem_cache *s, void *object)
static void print_page_info(struct page *page) 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, page->objects, page->inuse, page->freelist,
page->flags, &page->flags); &page->flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment