Skip to content

Commit 0aaa58e

Browse files
committed
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
2 parents c150d66 + 40e64a8 commit 0aaa58e

File tree

10 files changed

+51
-53
lines changed

10 files changed

+51
-53
lines changed

Documentation/core-api/printk-formats.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ Flags bitfields such as page flags, gfp_flags
580580

581581
::
582582

583-
%pGp referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff
583+
%pGp 0x17ffffc0002036(referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff)
584584
%pGg GFP_USER|GFP_DMA32|GFP_NOWARN
585585
%pGv read|exec|mayread|maywrite|mayexec|denywrite
586586

arch/ia64/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ config DISABLE_VHPT
3939

4040
config IA64_DEBUG_CMPXCHG
4141
bool "Turn on compare-and-exchange bug checking (slow!)"
42-
depends on DEBUG_KERNEL
42+
depends on DEBUG_KERNEL && PRINTK
4343
help
4444
Selecting this option turns on bug checking for the IA-64
4545
compare-and-exchange instructions. This is slow! Itaniums

kernel/printk/index.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos)
2626
if (mod) {
2727
entries = mod->printk_index_start;
2828
nr_entries = mod->printk_index_size;
29-
}
29+
} else
3030
#endif
31-
32-
if (!mod) {
31+
{
3332
/* vmlinux, comes from linker symbols */
3433
entries = __start_printk_index;
3534
nr_entries = __stop_printk_index - __start_printk_index;

kernel/printk/printk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ static int devkmsg_open(struct inode *inode, struct file *file)
847847
return err;
848848
}
849849

850-
user = kmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
850+
user = kvmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
851851
if (!user)
852852
return -ENOMEM;
853853

@@ -875,7 +875,7 @@ static int devkmsg_release(struct inode *inode, struct file *file)
875875
ratelimit_state_exit(&user->rs);
876876

877877
mutex_destroy(&user->lock);
878-
kfree(user);
878+
kvfree(user);
879879
return 0;
880880
}
881881

@@ -2066,6 +2066,7 @@ u16 printk_parse_prefix(const char *text, int *level,
20662066
return prefix_len;
20672067
}
20682068

2069+
__printf(5, 0)
20692070
static u16 printk_sprint(char *text, u16 size, int facility,
20702071
enum printk_info_flags *flags, const char *fmt,
20712072
va_list args)

lib/test_printf.c

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -586,70 +586,59 @@ struct page_flags_test {
586586
int width;
587587
int shift;
588588
int mask;
589-
unsigned long value;
590589
const char *fmt;
591590
const char *name;
592591
};
593592

594-
static struct page_flags_test pft[] = {
593+
static const struct page_flags_test pft[] = {
595594
{SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK,
596-
0, "%d", "section"},
595+
"%d", "section"},
597596
{NODES_WIDTH, NODES_PGSHIFT, NODES_MASK,
598-
0, "%d", "node"},
597+
"%d", "node"},
599598
{ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK,
600-
0, "%d", "zone"},
599+
"%d", "zone"},
601600
{LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK,
602-
0, "%#x", "lastcpupid"},
601+
"%#x", "lastcpupid"},
603602
{KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK,
604-
0, "%#x", "kasantag"},
603+
"%#x", "kasantag"},
605604
};
606605

607606
static void __init
608607
page_flags_test(int section, int node, int zone, int last_cpupid,
609-
int kasan_tag, int flags, const char *name, char *cmp_buf)
608+
int kasan_tag, unsigned long flags, const char *name,
609+
char *cmp_buf)
610610
{
611611
unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag};
612-
unsigned long page_flags = 0;
613-
unsigned long size = 0;
612+
unsigned long size;
614613
bool append = false;
615614
int i;
616615

617-
flags &= PAGEFLAGS_MASK;
618-
if (flags) {
619-
page_flags |= flags;
620-
snprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
621-
size = strlen(cmp_buf);
622-
#if SECTIONS_WIDTH || NODES_WIDTH || ZONES_WIDTH || \
623-
LAST_CPUPID_WIDTH || KASAN_TAG_WIDTH
624-
/* Other information also included in page flags */
625-
snprintf(cmp_buf + size, BUF_SIZE - size, "|");
626-
size = strlen(cmp_buf);
627-
#endif
628-
}
616+
for (i = 0; i < ARRAY_SIZE(values); i++)
617+
flags |= (values[i] & pft[i].mask) << pft[i].shift;
629618

630-
/* Set the test value */
631-
for (i = 0; i < ARRAY_SIZE(pft); i++)
632-
pft[i].value = values[i];
619+
size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags);
620+
if (flags & PAGEFLAGS_MASK) {
621+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
622+
append = true;
623+
}
633624

634625
for (i = 0; i < ARRAY_SIZE(pft); i++) {
635626
if (!pft[i].width)
636627
continue;
637628

638-
if (append) {
639-
snprintf(cmp_buf + size, BUF_SIZE - size, "|");
640-
size = strlen(cmp_buf);
641-
}
629+
if (append)
630+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
642631

643-
page_flags |= (pft[i].value & pft[i].mask) << pft[i].shift;
644-
snprintf(cmp_buf + size, BUF_SIZE - size, "%s=", pft[i].name);
645-
size = strlen(cmp_buf);
646-
snprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
647-
pft[i].value & pft[i].mask);
648-
size = strlen(cmp_buf);
632+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
633+
pft[i].name);
634+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
635+
values[i] & pft[i].mask);
649636
append = true;
650637
}
651638

652-
test(cmp_buf, "%pGp", &page_flags);
639+
snprintf(cmp_buf + size, BUF_SIZE - size, ")");
640+
641+
test(cmp_buf, "%pGp", &flags);
653642
}
654643

655644
static void __init

lib/vsprintf.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
408408
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
409409
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
410410

411+
static_assert(SIGN == 1);
411412
static_assert(ZEROPAD == ('0' - ' '));
412-
static_assert(SMALL == ' ');
413+
static_assert(SMALL == ('a' ^ 'A'));
413414

414415
enum format_type {
415416
FORMAT_TYPE_NONE, /* Just a string part */
@@ -2023,6 +2024,11 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
20232024
bool append = false;
20242025
int i;
20252026

2027+
buf = number(buf, end, flags, default_flag_spec);
2028+
if (buf < end)
2029+
*buf = '(';
2030+
buf++;
2031+
20262032
/* Page flags from the main area. */
20272033
if (main_flags) {
20282034
buf = format_flags(buf, end, main_flags, pageflag_names);
@@ -2051,6 +2057,9 @@ char *format_page_flags(char *buf, char *end, unsigned long flags)
20512057

20522058
append = true;
20532059
}
2060+
if (buf < end)
2061+
*buf = ')';
2062+
buf++;
20542063

20552064
return buf;
20562065
}

mm/debug.c

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

165-
pr_warn("%sflags: %#lx(%pGp)%s\n", type, head->flags, &head->flags,
165+
pr_warn("%sflags: %pGp%s\n", type, &head->flags,
166166
page_cma ? " CMA" : "");
167167
print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32,
168168
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)