Skip to contentSkip to conversation

mm/hugetlb.c: fix printk format warning for 32-bit phys_addr_t

PATCH In review Randy Dunlap 2 participants 6 messages Mar 18, 2020 – Mar 20, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hugetlb.c: fix printk format warning for 32-bit phys_addr_t

From: Randy Dunlap <[email protected]>

Fix printk format warnings when phys_addr_t is 32 bits, i.e., CONFIG_PHYS_ADDR_T_64BIT is not set/enabled.

Fixes these build warnings:
CC mm/hugetlb.o
In file included from ../include/linux/printk.h:7:0,

                 from ../include/linux/kernel.h:15,
                 from ../include/linux/list.h:9,
                 from ../mm/hugetlb.c:6:
../mm/hugetlb.c: In function ‘hugetlb_cma_reserve’:
../include/linux/kern_levels.h:5:18: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘unsigned int’ [-Wformat=]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
../include/linux/kern_levels.h:12:22: note: in expansion of macro ‘KERN_SOH’
 #define KERN_WARNING KERN_SOH "4" /* warning conditions */
                      ^~~~~~~~
../include/linux/printk.h:306:9: note: in expansion of macro ‘KERN_WARNING’
  printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         ^~~~~~~~~~~~

../mm/hugetlb.c:5472:4: note: in expansion of macro ‘pr_warn’
pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)", ^~~~~~~
../mm/hugetlb.c:5472:67: note: format string is defined here

    pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
                                                                ~~~^
                                                                %u
In file included from ../include/linux/printk.h:7:0,
                 from ../include/linux/kernel.h:15,
                 from ../include/linux/list.h:9,
                 from ../mm/hugetlb.c:6:
../include/linux/kern_levels.h:5:18: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 5 has type ‘unsigned int’ [-Wformat=]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
../include/linux/kern_levels.h:12:22: note: in expansion of macro ‘KERN_SOH’
 #define KERN_WARNING KERN_SOH "4" /* warning conditions */
                      ^~~~~~~~
../include/linux/printk.h:306:9: note: in expansion of macro ‘KERN_WARNING’
  printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         ^~~~~~~~~~~~

../mm/hugetlb.c:5472:4: note: in expansion of macro ‘pr_warn’
pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)", ^~~~~~~
../mm/hugetlb.c:5472:73: note: format string is defined here

    pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
                                                                      ~~~^
                                                                      %u
---
 mm/hugetlb.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/hugetlb.c +4 -2
@@ -5469,8 +5469,10 @@ void __init hugetlb_cma_reserve(int orde
 					     0, false,
 					     "hugetlb", &hugetlb_cma[nid]);
 		if (res) {
-			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
-				res, nid, PFN_PHYS(min_pfn), PFN_PHYS(max_pfn));
+			phys_addr_t begpa = PFN_PHYS(min_pfn);
+			phys_addr_t endpa = PFN_PHYS(max_pfn);
+			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%pap, %pap)",
+				res, nid, &begpa, &endpa);
 			break;
 		}
 
#1 lore raw
Quoted 4 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

Fix printk format warnings when phys_addr_t is 32 bits, i.e., CONFIG_PHYS_ADDR_T_64BIT is not set/enabled.

[]

Quoted 3 lines

../mm/hugetlb.c:5472:73: note: format string is defined here
pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
~~~^

[]

mm/hugetlb.c void __init hugetlb_cma_reserve(int orde · line 5475

Quoted 12 lines
mm/hugetlb.c +4 -2
@@ -5469,8 +5469,10 @@ void __init hugetlb_cma_reserve(int orde
 					     0, false,
 					     "hugetlb", &hugetlb_cma[nid]);
 		if (res) {
-			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
-				res, nid, PFN_PHYS(min_pfn), PFN_PHYS(max_pfn));
+			phys_addr_t begpa = PFN_PHYS(min_pfn);
+			phys_addr_t endpa = PFN_PHYS(max_pfn);
+			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%pap, %pap)",
+				res, nid, &begpa, &endpa);

You might correct the odd use of an open bracket
then close parenthesis and add a new line too

Perhaps:

			pr_warn("%s: reservation failed: err %d, node %d, [%pap, %pap]\n",
				__func__, res, nid, &begpa, &endpa);
#2 lore raw
Quoted 10 lines · Joe Perches
Quoted 4 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

Fix printk format warnings when phys_addr_t is 32 bits, i.e., CONFIG_PHYS_ADDR_T_64BIT is not set/enabled.

[]

Quoted 3 lines

../mm/hugetlb.c:5472:73: note: format string is defined here
pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
~~~^

[]

Quoted 15 lines

mm/hugetlb.c void __init hugetlb_cma_reserve(int orde · line 5475

Quoted 12 lines
mm/hugetlb.c +4 -2
@@ -5469,8 +5469,10 @@ void __init hugetlb_cma_reserve(int orde
 					     0, false,
 					     "hugetlb", &hugetlb_cma[nid]);
 		if (res) {
-			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
-				res, nid, PFN_PHYS(min_pfn), PFN_PHYS(max_pfn));
+			phys_addr_t begpa = PFN_PHYS(min_pfn);
+			phys_addr_t endpa = PFN_PHYS(max_pfn);
+			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%pap, %pap)",
+				res, nid, &begpa, &endpa);

You might correct the odd use of an open bracket
then close parenthesis and add a new line too

Definitely needs a newline char.

I'm fairly sure that the [begin, end) notation is done on purpose, meaning <begin> is included in the range and <end> is not included in the range.

Quoted 6 lines

Perhaps:

			pr_warn("%s: reservation failed: err %d, node %d, [%pap, %pap]\n",
				__func__, res, nid, &begpa, &endpa);

thanks.

Signature · 1 line
~Randy
#3 lore raw
Quoted 27 lines · Randy Dunlap
Quoted 10 lines · Joe Perches
Quoted 4 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

Fix printk format warnings when phys_addr_t is 32 bits, i.e., CONFIG_PHYS_ADDR_T_64BIT is not set/enabled.

[]

Quoted 3 lines

../mm/hugetlb.c:5472:73: note: format string is defined here
pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
~~~^

[]

Quoted 15 lines

mm/hugetlb.c void __init hugetlb_cma_reserve(int orde · line 5475

Quoted 12 lines
mm/hugetlb.c +4 -2
@@ -5469,8 +5469,10 @@ void __init hugetlb_cma_reserve(int orde
 					     0, false,
 					     "hugetlb", &hugetlb_cma[nid]);
 		if (res) {
-			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
-				res, nid, PFN_PHYS(min_pfn), PFN_PHYS(max_pfn));
+			phys_addr_t begpa = PFN_PHYS(min_pfn);
+			phys_addr_t endpa = PFN_PHYS(max_pfn);
+			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%pap, %pap)",
+				res, nid, &begpa, &endpa);

You might correct the odd use of an open bracket
then close parenthesis and add a new line too

Quoted 4 lines

Definitely needs a newline char.

I'm fairly sure that the [begin, end) notation is done on purpose, meaning <begin> is included in the range and <end> is not included in the range.

OK, that seems a pretty obscure and not obvious use of interval notation, at least to me. (18 uses treewide ?)

Maybe it could be documented somewhere?

It's an odd pattern to grep. Maybe I missed some.

$ git grep -P '".*[\[\{]\s*%\d*[ldux]+\s*[/:,\.\-]?\s*%\d*[ldux]+\).*"'
arch/x86/kernel/alternative.c:  DUMP_BYTES(instr, a->instrlen, "%px: [%d:%d) optimized NOPs: ",
drivers/clk/qcom/clk-alpha-pll.c:               pr_err("%s: Rounded rate %lu not within range [%lu, %lu)\n",
fs/ext4/extents_status.c:               printk(KERN_DEBUG " [%u/%u) %llu %x",
fs/ext4/extents_status.c:                       es_debug("%u cached by [%u/%u) %llu %x\n",
fs/ext4/extents_status.c:       es_debug("add [%u/%u) %llu %x to extent status tree of inode %lu\n",
fs/ext4/extents_status.c:                       es_debug("%u cached by [%u/%u)\n",
fs/ext4/extents_status.c:       es_debug("remove [%u/%u) from extent status tree of inode %lu\n",
fs/nilfs2/cpfile.c:                       "cannot delete checkpoints: invalid range [%llu, %llu)",
fs/nilfs2/dat.c:                          "%s: invalid vblocknr = %llu, [%llu, %llu)",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%lld/%lld)",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu found %d [%u/%u) %llu %s",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s "
mm/hugetlb.c:                   pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
mm/kasan/report.c:              pr_err(" [%lu, %lu) '%s'", offset, offset + size, token);
mm/page_alloc.c:                pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
tools/testing/selftests/kvm/demand_paging_test.c:               PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",
#4 lore raw
Quoted 30 lines · Joe Perches
Quoted 29 lines · Randy Dunlap
Quoted 10 lines · Joe Perches
Quoted 4 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

Fix printk format warnings when phys_addr_t is 32 bits, i.e., CONFIG_PHYS_ADDR_T_64BIT is not set/enabled.

[]

Quoted 3 lines

../mm/hugetlb.c:5472:73: note: format string is defined here
pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
~~~^

[]

Quoted 15 lines

mm/hugetlb.c void __init hugetlb_cma_reserve(int orde · line 5475

Quoted 12 lines
mm/hugetlb.c +4 -2
@@ -5469,8 +5469,10 @@ void __init hugetlb_cma_reserve(int orde
 					     0, false,
 					     "hugetlb", &hugetlb_cma[nid]);
 		if (res) {
-			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
-				res, nid, PFN_PHYS(min_pfn), PFN_PHYS(max_pfn));
+			phys_addr_t begpa = PFN_PHYS(min_pfn);
+			phys_addr_t endpa = PFN_PHYS(max_pfn);
+			pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%pap, %pap)",
+				res, nid, &begpa, &endpa);

You might correct the odd use of an open bracket
then close parenthesis and add a new line too

Definitely needs a newline char.

Quoted 7 lines
Quoted 2 lines

I'm fairly sure that the [begin, end) notation is done on purpose, meaning <begin> is included in the range and <end> is not included in the range.

OK, that seems a pretty obscure and not obvious use of interval notation, at least to me. (18 uses treewide ?)

Maybe it could be documented somewhere?

I thought about where to put that and came up empty.

Quoted 1 line

It's an odd pattern to grep. Maybe I missed some.

It's probably not used much more than this.

Quoted 11 lines
$ git grep -P '".*[\[\{]\s*%\d*[ldux]+\s*[/:,\.\-]?\s*%\d*[ldux]+\).*"'
arch/x86/kernel/alternative.c:  DUMP_BYTES(instr, a->instrlen, "%px: [%d:%d) optimized NOPs: ",
drivers/clk/qcom/clk-alpha-pll.c:               pr_err("%s: Rounded rate %lu not within range [%lu, %lu)\n",
fs/ext4/extents_status.c:               printk(KERN_DEBUG " [%u/%u) %llu %x",
fs/ext4/extents_status.c:                       es_debug("%u cached by [%u/%u) %llu %x\n",
fs/ext4/extents_status.c:       es_debug("add [%u/%u) %llu %x to extent status tree of inode %lu\n",
fs/ext4/extents_status.c:                       es_debug("%u cached by [%u/%u)\n",
fs/ext4/extents_status.c:       es_debug("remove [%u/%u) from extent status tree of inode %lu\n",
fs/nilfs2/cpfile.c:                       "cannot delete checkpoints: invalid range [%llu, %llu)",
fs/nilfs2/dat.c:                          "%s: invalid vblocknr = %llu, [%llu, %llu)",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s",
Quoted 10 lines
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%lld/%lld)",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu found %d [%u/%u) %llu %s",
include/trace/events/ext4.h:    TP_printk("dev %d,%d ino %lu es [%u/%u) mapped %llu status %s "
mm/hugetlb.c:                   pr_warn("hugetlb_cma: reservation failed: err %d, node %d, [%llu, %llu)",
mm/kasan/report.c:              pr_err(" [%lu, %lu) '%s'", offset, offset + size, token);
mm/page_alloc.c:                pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
tools/testing/selftests/kvm/demand_paging_test.c:               PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",

thanks.

Signature · 1 line
~Randy
#5 lore raw
Quoted 5 lines · Randy Dunlap
Quoted 4 lines · Joe Perches
Quoted 2 lines · Randy Dunlap

I'm fairly sure that the [begin, end) notation is done on purpose, meaning

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

<begin> is included in the range and <end> is not included in the range.

OK, that seems a pretty obscure and not obvious use of interval notation, at least to me. (18 uses treewide ?)

Maybe it could be documented somewhere?

I thought about where to put that and came up empty.

No worries then, it's likely not _too_ obscure
to anyone that's sent a log for analysis.