Skip to contentSkip to conversation

arch_numa: fix common code printing of phys_addr_t

PATCH In review Randy Dunlap 3 participants 6 messages Jan 28, 2021 – Feb 2, 2021 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch_numa: fix common code printing of phys_addr_t

Fix build warnings in the arch_numa common code:

../include/linux/kern_levels.h:5:18: warning: format '%Lx' expects argument of type 'long long unsigned int', but argument 3 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=] ../drivers/base/arch_numa.c:360:56: note: format string is defined here
360 | pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
../drivers/base/arch_numa.c:435:39: note: format string is defined here
435 | pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);

Fixes ae3c107cd8be ("numa: Move numa implementation to common code")
Cc Atish Patra <[email protected]>
Cc Palmer Dabbelt <[email protected]>
---
 drivers/base/arch_numa.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/base/arch_numa.c +7 -6
@@ -355,11 +355,12 @@ static int __init numa_register_nodes(vo
 	/* Check that valid nid is set to memblks */
 	for_each_mem_region(mblk) {
 		int mblk_nid = memblock_get_region_node(mblk);
+		phys_addr_t start = mblk->base;
+		phys_addr_t end = mblk->base + mblk->size - 1;
 
 		if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
-			pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
-				mblk_nid, mblk->base,
-				mblk->base + mblk->size - 1);
+			pr_warn("Warning: invalid memblk node %d [mem %pap-%pap]\n",
+				mblk_nid, &start, &end);
 			return -EINVAL;
 		}
 	}
@@ -427,14 +428,14 @@ out_free_distance:
 static int __init dummy_numa_init(void)
 {
 	phys_addr_t start = memblock_start_of_DRAM();
-	phys_addr_t end = memblock_end_of_DRAM();
+	phys_addr_t end = memblock_end_of_DRAM() - 1;
 	int ret;
 
 	if (numa_off)
 		pr_info("NUMA disabled\n"); /* Forced off on command line. */
-	pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);
+	pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);
 
-	ret = numa_add_memblk(0, start, end);
+	ret = numa_add_memblk(0, start, end + 1);
 	if (ret) {
 		pr_err("NUMA init failed\n");
 		return ret;
#1 lore raw
Quoted 2 lines · Randy Dunlap

Fix build warnings in the arch_numa common code:

This patch applies to linux-next, not mainline.

Quoted 17 lines

../include/linux/kern_levels.h:5:18: warning: format '%Lx' expects argument of type 'long long unsigned int', but argument 3 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=] ../drivers/base/arch_numa.c:360:56: note: format string is defined here
360 | pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
../drivers/base/arch_numa.c:435:39: note: format string is defined here
435 | pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);

Fixes ae3c107cd8be ("numa: Move numa implementation to common code")
Cc Atish Patra <[email protected]>
Cc Palmer Dabbelt <[email protected]>
---
 drivers/base/arch_numa.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/base/arch_numa.c +0 -0
Signature · 1 line
~Randy
Reviewed-by on v1 1/1
#2 lore raw
In reply to Randy Dunlap
Quoted 56 lines · Randy Dunlap

Fix build warnings in the arch_numa common code:

../include/linux/kern_levels.h:5:18: warning: format '%Lx' expects argument of type 'long long unsigned int', but argument 3 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=] ../drivers/base/arch_numa.c:360:56: note: format string is defined here
  360 |    pr_warn("Warning: invalid memblk node %d [mem %#010Lx- %#010Lx]\n",
../drivers/base/arch_numa.c:435:39: note: format string is defined here
  435 |  pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);

Fixes ae3c107cd8be ("numa: Move numa implementation to common code")
Cc Atish Patra <[email protected]>
Cc Palmer Dabbelt <[email protected]>

---
 drivers/base/arch_numa.c |   13 +++++++------

 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/base/arch_numa.c +2 -0
@@ -355,11 +355,12 @@ static int __init numa_register_nodes(vo
         /* Check that valid nid is set to memblks */
         for_each_mem_region(mblk) {
                 int mblk_nid = memblock_get_region_node(mblk);
+               phys_addr_t start = mblk->base;
+               phys_addr_t end = mblk->base + mblk->size - 1;


                if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
-                       pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
-                               mblk_nid, mblk->base,
-                               mblk->base + mblk->size - 1); +                       pr_warn("Warning: invalid memblk node %d [mem %pap-%pap]\n",
+                               mblk_nid, &start, &end); return -EINVAL;
                }
        }

drivers/base/arch_numa.c +1 -1
@@ -427,14 +428,14 @@ out_free_distance:
  static int __init dummy_numa_init(void)
  {
         phys_addr_t start = memblock_start_of_DRAM();
-       phys_addr_t end = memblock_end_of_DRAM();
+       phys_addr_t end = memblock_end_of_DRAM() - 1;
         int ret;


        if (numa_off)
                pr_info("NUMA disabled\n"); /* Forced off on command line. */
-       pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start,

Quoted 8 lines

end - 1);
+       pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);
-       ret = numa_add_memblk(0, start, end);
+       ret = numa_add_memblk(0, start, end + 1);
        if (ret) {
                pr_err("NUMA init failed\n");
                return ret;

Thanks for the fix.

Signature · 2 lines
Regards,
Atish
#3 lore raw
In reply to Randy Dunlap
Quoted 43 lines · On Wed, 27 Jan 2021 19:55:33 PST (-0800), [email protected] wrote:

Fix build warnings in the arch_numa common code:

../include/linux/kern_levels.h:5:18: warning: format '%Lx' expects argument of type 'long long unsigned int', but argument 3 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=] ../drivers/base/arch_numa.c:360:56: note: format string is defined here
360 | pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
../drivers/base/arch_numa.c:435:39: note: format string is defined here
435 | pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);

Fixes ae3c107cd8be ("numa: Move numa implementation to common code")
Cc Atish Patra <[email protected]>
Cc Palmer Dabbelt <[email protected]>
---
 drivers/base/arch_numa.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/base/arch_numa.c +5 -4
@@ -355,11 +355,12 @@ static int __init numa_register_nodes(vo
 	/* Check that valid nid is set to memblks */
 	for_each_mem_region(mblk) {
 		int mblk_nid = memblock_get_region_node(mblk);
+		phys_addr_t start = mblk->base;
+		phys_addr_t end = mblk->base + mblk->size - 1;
 
 		if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
-			pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
-				mblk_nid, mblk->base,
-				mblk->base + mblk->size - 1);
+			pr_warn("Warning: invalid memblk node %d [mem %pap-%pap]\n",
+				mblk_nid, &start, &end);
 			return -EINVAL;
 		}
 	}
@@ -427,14 +428,14 @@ out_free_distance:
 static int __init dummy_numa_init(void)
 {
 	phys_addr_t start = memblock_start_of_DRAM();
-	phys_addr_t end = memblock_end_of_DRAM();
+	phys_addr_t end = memblock_end_of_DRAM() - 1;
 	int ret;
 

drivers/base/arch_numa.c out_free_distance: · line 441

Quoted 10 lines
drivers/base/arch_numa.c +2 -2
 	if (numa_off)
 		pr_info("NUMA disabled\n"); /* Forced off on command line. */
-	pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);
+	pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);
 
-	ret = numa_add_memblk(0, start, end);
+	ret = numa_add_memblk(0, start, end + 1);
 	if (ret) {
 		pr_err("NUMA init failed\n");
 		return ret;

Thanks, this is on for-next. Did you, by any chance, find %Lx documented anywhere? It's not ISO C and the GCC source code says it's a GNU extension, but I couldn't find it in the documentation (or even where to add it, which I guess is how I forgot to send my version fo the patch).

#4 lore raw
Quoted 49 lines · Palmer Dabbelt
Quoted 48 lines · On Wed, 27 Jan 2021 19:55:33 PST (-0800), [email protected] wrote:

Fix build warnings in the arch_numa common code:

../include/linux/kern_levels.h:5:18: warning: format '%Lx' expects argument of type 'long long unsigned int', but argument 3 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=] ../drivers/base/arch_numa.c:360:56: note: format string is defined here
  360 |    pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
../drivers/base/arch_numa.c:435:39: note: format string is defined here
  435 |  pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);

Fixes ae3c107cd8be ("numa: Move numa implementation to common code")
Cc Atish Patra <[email protected]>
Cc Palmer Dabbelt <[email protected]>

---
 drivers/base/arch_numa.c |   13 +++++++------

 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/base/arch_numa.c +5 -4
@@ -355,11 +355,12 @@ static int __init numa_register_nodes(vo
      /* Check that valid nid is set to memblks */
      for_each_mem_region(mblk) {
          int mblk_nid = memblock_get_region_node(mblk);
+        phys_addr_t start = mblk->base;
+        phys_addr_t end = mblk->base + mblk->size - 1;
 
          if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
-            pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
-                mblk_nid, mblk->base,
-                mblk->base + mblk->size - 1);
+            pr_warn("Warning: invalid memblk node %d [mem %pap-%pap]\n",
+                mblk_nid, &start, &end);
              return -EINVAL;
          }
      }
@@ -427,14 +428,14 @@ out_free_distance:
  static int __init dummy_numa_init(void)
  {
      phys_addr_t start = memblock_start_of_DRAM();
-    phys_addr_t end = memblock_end_of_DRAM();
+    phys_addr_t end = memblock_end_of_DRAM() - 1;
      int ret;
 
      if (numa_off)

         pr_info("NUMA disabled\n"); /* Forced off on command line. */ -    pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1); +    pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);

Quoted 10 lines
Quoted 5 lines

-    ret = numa_add_memblk(0, start, end);
+    ret = numa_add_memblk(0, start, end + 1);
     if (ret) {
         pr_err("NUMA init failed\n");
         return ret;

Thanks, this is on for-next.  Did you, by any chance, find %Lx documented anywhere?  It's not ISO C and the GCC source code says it's a GNU extension, but I couldn't find it in the documentation (or even where to add it, which I guess is how I forgot to send my version fo the patch).

'man sprintf' says this:

As a nonstandard extension, the GNU implementations treats ll and L as synonyms, so that one can, for example, write llg (as a synonym for the standards-compliant Lg) and Ld (as a synonym for the standards compli- ant lld). Such usage is nonportable.

and linux/lib/vsprintf.c has some handling for it:

	if (qualifier == 'L')
		spec->type = FORMAT_TYPE_LONG_LONG;

and

		case 'L':
			if (is_sign)
				*va_arg(args, long long *) = val.s;
			else
				*va_arg(args, unsigned long long *) = val.u;
			break;

Does that help?

Signature · 1 line
~Randy
#5 lore raw
Quoted 84 lines · On Mon, 01 Feb 2021 19:51:07 PST (-0800), [email protected] wrote:
Quoted 49 lines · Palmer Dabbelt
Quoted 48 lines · On Wed, 27 Jan 2021 19:55:33 PST (-0800), [email protected] wrote:

Fix build warnings in the arch_numa common code:

../include/linux/kern_levels.h:5:18: warning: format '%Lx' expects argument of type 'long long unsigned int', but argument 3 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=] ../drivers/base/arch_numa.c:360:56: note: format string is defined here
  360 |    pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
../drivers/base/arch_numa.c:435:39: note: format string is defined here
  435 |  pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1);

Fixes ae3c107cd8be ("numa: Move numa implementation to common code")
Cc Atish Patra <[email protected]>
Cc Palmer Dabbelt <[email protected]>

---
 drivers/base/arch_numa.c |   13 +++++++------

 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/base/arch_numa.c +5 -4
@@ -355,11 +355,12 @@ static int __init numa_register_nodes(vo
      /* Check that valid nid is set to memblks */
      for_each_mem_region(mblk) {
          int mblk_nid = memblock_get_region_node(mblk);
+        phys_addr_t start = mblk->base;
+        phys_addr_t end = mblk->base + mblk->size - 1;
 
          if (mblk_nid == NUMA_NO_NODE || mblk_nid >= MAX_NUMNODES) {
-            pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
-                mblk_nid, mblk->base,
-                mblk->base + mblk->size - 1);
+            pr_warn("Warning: invalid memblk node %d [mem %pap-%pap]\n",
+                mblk_nid, &start, &end);
              return -EINVAL;
          }
      }
@@ -427,14 +428,14 @@ out_free_distance:
  static int __init dummy_numa_init(void)
  {
      phys_addr_t start = memblock_start_of_DRAM();
-    phys_addr_t end = memblock_end_of_DRAM();
+    phys_addr_t end = memblock_end_of_DRAM() - 1;
      int ret;
 
      if (numa_off)

         pr_info("NUMA disabled\n"); /* Forced off on command line. */ -    pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1); +    pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);

Quoted 10 lines
Quoted 5 lines

-    ret = numa_add_memblk(0, start, end);
+    ret = numa_add_memblk(0, start, end + 1);
     if (ret) {
         pr_err("NUMA init failed\n");
         return ret;

Thanks, this is on for-next.  Did you, by any chance, find %Lx documented anywhere?  It's not ISO C and the GCC source code says it's a GNU extension, but I couldn't find it in the documentation (or even where to add it, which I guess is how I forgot to send my version fo the patch).

'man sprintf' says this:

As a nonstandard extension, the GNU implementations treats ll and L as synonyms, so that one can, for example, write llg (as a synonym for the standards-compliant Lg) and Ld (as a synonym for the standards compli- ant lld). Such usage is nonportable.

and linux/lib/vsprintf.c has some handling for it:

	if (qualifier == 'L')
		spec->type = FORMAT_TYPE_LONG_LONG;

and

		case 'L':
			if (is_sign)
				*va_arg(args, long long *) = val.s;
			else
				*va_arg(args, unsigned long long *) = val.u;
			break;
Quoted 1 line

Does that help?

The manpage does it, I guess I just wasn't reading closely enough. Thanks!