diff mbox series

[-next] memblock: unify memblock dump and debugfs show

Message ID 20230525115856.124507-1-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series [-next] memblock: unify memblock dump and debugfs show | expand

Commit Message

Kefeng Wang May 25, 2023, 11:58 a.m. UTC
There are two interfaces to show the memblock information, memblock_dump_all()
and /sys/kernel/debug/memblock/, but the content is displayed separately,
let's unify them in case of more different changes over time.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/memblock.h |  1 +
 mm/memblock.c            | 80 ++++++++++++++++++++--------------------
 2 files changed, 42 insertions(+), 39 deletions(-)

Comments

kernel test robot May 26, 2023, 2:57 a.m. UTC | #1
Hi Kefeng,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20230525]

url:    https://github.com/intel-lab-lkp/linux/commits/Kefeng-Wang/memblock-unify-memblock-dump-and-debugfs-show/20230525-194341
base:   next-20230525
patch link:    https://lore.kernel.org/r/20230525115856.124507-1-wangkefeng.wang%40huawei.com
patch subject: [PATCH -next] memblock: unify memblock dump and debugfs show
config: arc-defconfig
compiler: arc-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/08ce8490dec830c059127709a3a692ac7368287e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kefeng-Wang/memblock-unify-memblock-dump-and-debugfs-show/20230525-194341
        git checkout 08ce8490dec830c059127709a3a692ac7368287e
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202305261014.oCTIOnRv-lkp@intel.com/

All errors (new ones prefixed by >>):

   mm/memblock.c: In function 'memblock_dump.constprop':
>> mm/memblock.c:1910:27: error: 'flagname' causes a section type conflict with 'memblock'
    1910 | static const char * const flagname[] __initdata_memblock = {
         |                           ^~~~~~~~
   mm/memblock.c:115:17: note: 'memblock' was declared here
     115 | struct memblock memblock __initdata_memblock = {
         |                 ^~~~~~~~


vim +1910 mm/memblock.c

  1909	
> 1910	static const char * const flagname[] __initdata_memblock = {
  1911		[ilog2(MEMBLOCK_HOTPLUG)]		= "HOTPLUG",
  1912		[ilog2(MEMBLOCK_MIRROR)]		= "MIRROR",
  1913		[ilog2(MEMBLOCK_NOMAP)]			= "NOMAP",
  1914		[ilog2(MEMBLOCK_DRIVER_MANAGED)]	= "DRV_MNG",
  1915		[ilog2(MEMBLOCK_MAX_UNKNOWN)]		= "UNKNOWN",
  1916	};
  1917
kernel test robot May 26, 2023, 11:09 a.m. UTC | #2
Hi Kefeng,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20230525]

url:    https://github.com/intel-lab-lkp/linux/commits/Kefeng-Wang/memblock-unify-memblock-dump-and-debugfs-show/20230525-194341
base:   next-20230525
patch link:    https://lore.kernel.org/r/20230525115856.124507-1-wangkefeng.wang%40huawei.com
patch subject: [PATCH -next] memblock: unify memblock dump and debugfs show
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20230526/202305261822.ZFRYZVQk-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/08ce8490dec830c059127709a3a692ac7368287e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kefeng-Wang/memblock-unify-memblock-dump-and-debugfs-show/20230525-194341
        git checkout 08ce8490dec830c059127709a3a692ac7368287e
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202305261822.ZFRYZVQk-lkp@intel.com/

All errors (new ones prefixed by >>):

   mm/memblock.c: In function 'memblock_dump.constprop':
>> mm/memblock.c:1910:27: error: 'flagname' causes a section type conflict with 'memblock_debug'
    1910 | static const char * const flagname[] __initdata_memblock = {
         |                           ^~~~~~~~
   mm/memblock.c:158:12: note: 'memblock_debug' was declared here
     158 | static int memblock_debug __initdata_memblock;
         |            ^~~~~~~~~~~~~~


vim +1910 mm/memblock.c

  1909	
> 1910	static const char * const flagname[] __initdata_memblock = {
  1911		[ilog2(MEMBLOCK_HOTPLUG)]		= "HOTPLUG",
  1912		[ilog2(MEMBLOCK_MIRROR)]		= "MIRROR",
  1913		[ilog2(MEMBLOCK_NOMAP)]			= "NOMAP",
  1914		[ilog2(MEMBLOCK_DRIVER_MANAGED)]	= "DRV_MNG",
  1915		[ilog2(MEMBLOCK_MAX_UNKNOWN)]		= "UNKNOWN",
  1916	};
  1917
Kefeng Wang May 26, 2023, 11:40 a.m. UTC | #3
On 2023/5/26 19:09, kernel test robot wrote:
> Hi Kefeng,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on next-20230525]
> 
Thank, I will drop __initdata_memblock .

> 
> 
> vim +1910 mm/memblock.c
> 
>    1909	
>> 1910	static const char * const flagname[] __initdata_memblock = {
>    1911		[ilog2(MEMBLOCK_HOTPLUG)]		= "HOTPLUG",
>    1912		[ilog2(MEMBLOCK_MIRROR)]		= "MIRROR",
>    1913		[ilog2(MEMBLOCK_NOMAP)]			= "NOMAP",
>    1914		[ilog2(MEMBLOCK_DRIVER_MANAGED)]	= "DRV_MNG",
>    1915		[ilog2(MEMBLOCK_MAX_UNKNOWN)]		= "UNKNOWN",
>    1916	};
>    1917	
>
diff mbox series

Patch

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index f82ee3fac1cd..d68826e8c97b 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -47,6 +47,7 @@  enum memblock_flags {
 	MEMBLOCK_MIRROR		= 0x2,	/* mirrored region */
 	MEMBLOCK_NOMAP		= 0x4,	/* don't add to kernel direct mapping */
 	MEMBLOCK_DRIVER_MANAGED = 0x8,	/* always detected via a driver */
+	MEMBLOCK_MAX_UNKNOWN	= 0x10,	/* unknow flags */
 };
 
 /**
diff --git a/mm/memblock.c b/mm/memblock.c
index c5c80d9bcea3..890ff9a16b1d 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1899,16 +1899,35 @@  phys_addr_t __init_memblock memblock_get_current_limit(void)
 	return memblock.current_limit;
 }
 
-static void __init_memblock memblock_dump(struct memblock_type *type)
+#define memblock_printf(m, to_dmesg, fmt, args...)		\
+({								\
+	if (to_dmesg)						\
+		pr_info(fmt, ##args);				\
+	else							\
+		seq_printf(m, fmt, ##args);			\
+})
+
+static const char * const flagname[] __initdata_memblock = {
+	[ilog2(MEMBLOCK_HOTPLUG)]		= "HOTPLUG",
+	[ilog2(MEMBLOCK_MIRROR)]		= "MIRROR",
+	[ilog2(MEMBLOCK_NOMAP)]			= "NOMAP",
+	[ilog2(MEMBLOCK_DRIVER_MANAGED)]	= "DRV_MNG",
+	[ilog2(MEMBLOCK_MAX_UNKNOWN)]		= "UNKNOWN",
+};
+
+static void __init_memblock memblock_dump(struct memblock_type *type,
+					  struct seq_file *m, bool to_dmesg)
 {
+	unsigned count = ARRAY_SIZE(flagname);
 	phys_addr_t base, end, size;
 	enum memblock_flags flags;
-	int idx;
 	struct memblock_region *rgn;
+	int idx, i;
 
-	pr_info(" %s.cnt  = 0x%lx\n", type->name, type->cnt);
+	memblock_printf(m, to_dmesg, " %s.cnt  = 0x%lx\n", type->name, type->cnt);
 
 	for_each_memblock_type(idx, type, rgn) {
+		const char *fp = "NONE";
 		char nid_buf[32] = "";
 
 		base = rgn->base;
@@ -1920,8 +1939,19 @@  static void __init_memblock memblock_dump(struct memblock_type *type)
 			snprintf(nid_buf, sizeof(nid_buf), " on node %d",
 				 memblock_get_region_node(rgn));
 #endif
-		pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n",
-			type->name, idx, &base, &end, &size, nid_buf, flags);
+		if (flags) {
+			fp = flagname[count];
+
+			for (i = 0; i < count; i++) {
+				if (flags & (1U << i)) {
+					fp = flagname[i];
+					break;
+				}
+			}
+		}
+
+		memblock_printf(m, to_dmesg, " %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %s\n",
+			type->name, idx, &base, &end, &size, nid_buf, fp);
 	}
 }
 
@@ -1932,10 +1962,10 @@  static void __init_memblock __memblock_dump_all(void)
 		&memblock.memory.total_size,
 		&memblock.reserved.total_size);
 
-	memblock_dump(&memblock.memory);
-	memblock_dump(&memblock.reserved);
+	memblock_dump(&memblock.memory, NULL, true);
+	memblock_dump(&memblock.reserved, NULL, true);
 #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
-	memblock_dump(&physmem);
+	memblock_dump(&physmem, NULL, true);
 #endif
 }
 
@@ -2158,41 +2188,13 @@  void __init memblock_free_all(void)
 }
 
 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK)
-static const char * const flagname[] = {
-	[ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG",
-	[ilog2(MEMBLOCK_MIRROR)] = "MIRROR",
-	[ilog2(MEMBLOCK_NOMAP)] = "NOMAP",
-	[ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG",
-};
 
 static int memblock_debug_show(struct seq_file *m, void *private)
 {
 	struct memblock_type *type = m->private;
-	struct memblock_region *reg;
-	int i, j;
-	unsigned int count = ARRAY_SIZE(flagname);
-	phys_addr_t end;
-
-	for (i = 0; i < type->cnt; i++) {
-		reg = &type->regions[i];
-		end = reg->base + reg->size - 1;
-
-		seq_printf(m, "%4d: ", i);
-		seq_printf(m, "%pa..%pa ", &reg->base, &end);
-		seq_printf(m, "%4d ", memblock_get_region_node(reg));
-		if (reg->flags) {
-			for (j = 0; j < count; j++) {
-				if (reg->flags & (1U << j)) {
-					seq_printf(m, "%s\n", flagname[j]);
-					break;
-				}
-			}
-			if (j == count)
-				seq_printf(m, "%s\n", "UNKNOWN");
-		} else {
-			seq_printf(m, "%s\n", "NONE");
-		}
-	}
+
+	memblock_dump(type, m, false);
+
 	return 0;
 }
 DEFINE_SHOW_ATTRIBUTE(memblock_debug);