Skip to contentSkip to conversation

acpi: Fix and cleanup in acpi.

PATCH In review Tang Chen 4 participants 10 messages Sep 3, 2013 – Sep 5, 2013

Subsystems (3)
lore
Share & tools
lore

Tang Chen

author
#0 lore raw

v2 cover acpi: Fix and cleanup in acpi.

This patch-set fix the following problems:

1. Kill useless function save_add_info() which will block us from using numa when MEMORY_HOTPLUG is not configured.
2. acpi_table_parse() didn't check if @id is NULL.
3. Fix incorrect comment in acpi_table_parse(), and return -ENOENT if a table is not found.

And also did some cleanup.

change log v1 -> v2:
1. Use pr_fmt() to simply the SRAT message.
Suggested by Joe Perches <[email protected]>
2. Improve the log in patch 4, and change the return value of the stub of acpi_table_parse() in linux/acpi.h
Suggested by Toshi Kani <[email protected]>
3. Merge the two pr_{info|err} patches into one.
4. Remove on of the patch that has been merged by Rafael.

Tang Chen (4):
acpi, numa, mem_hotplug: Kill save_add_info(). acpi cleanup: Use pr_{info|err}() instead of printk() in

    arch/x86/mm/srat.c

acpi: Check if @id is NULL in acpi_table_parse()
acpi: Return -ENOENT in acpi_table_parse() and fix wrong comment.

 arch/x86/mm/srat.c    |   40 +++++++++++++++++-----------------------
 drivers/acpi/tables.c |    9 +++++----
 include/linux/acpi.h  |    2 +-
 3 files changed, 23 insertions(+), 28 deletions(-)
author
#1 lore raw

PATCH v2 1/4 acpi, numa, mem_hotplug: Kill save_add_info().

save_add_info() is defined as:

	#ifdef CONFIG_MEMORY_HOTPLUG
	static inline int save_add_info(void) {return 1;}
	#else
	static inline int save_add_info(void) {return 0;}
	#endif

which means it is true when memory hotplug is configured.

In acpi_numa_memory_affinity_init(), it checks the memory hotplug flag in SRAT memory affinity and save_add_info() like this:

	if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
		goto out_err;
	......
	node = setup_node(pxm);
	numa_add_memblk(node, start, end);
	......

which means if the memory range is hotpluggable, but memory hotplug is not configured, it won't add these memory to numa_meminfo.

After this, numa_meminfo_cover_memory() will fail, which will finally cause numa_init() to fail.

numa_init()
|->numa_register_memblks()

     |->numa_meminfo_cover_memory()

When numa_init() fails, it will fallback to numa_init(dummy_numa_init), and all numa architecture will not be setup.

This is nonsense. Even if memory hotplug is not configured, we can also use numa architecture.

Actually, save_add_info() is added by commit 71efa8fdc55e70ec6687c897a30759f0a2c2ad7e in 2006. And now it is useless.

So this patch kill save_add_info() and the nonsense checking.

---
 arch/x86/mm/srat.c |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)
arch/x86/mm/srat.c +0 -8
index cdd0da9..1613c02 100644
@@ -135,12 +135,6 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 	       pxm, apic_id, node);
 }
 
-#ifdef CONFIG_MEMORY_HOTPLUG
-static inline int save_add_info(void) {return 1;}
-#else
-static inline int save_add_info(void) {return 0;}
-#endif
-
 /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
 int __init
 acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
@@ -154,8 +148,6 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 		goto out_err_bad_srat;
 	if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
 		goto out_err;
-	if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
-		goto out_err;
 
 	start = ma->base_address;
 	end = start + ma->length;
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH v2 2/4 acpi cleanup: Use pr_{info|err}() instead of printk() in arch/x86/mm/srat.c

In reply to Tang Chen

Use pr_{info|err}() instead of printk() in arch/x86/mm/srat.c.

As suggested by Joe Perches <[email protected]>, use pr_fmt(fmt) to simplify the output format.

---
 arch/x86/mm/srat.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/mm/srat.c +17 -15
index 1613c02..5adfcfb 100644
@@ -24,6 +24,8 @@
 #include <asm/apic.h>
 #include <asm/uv/uv.h>
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 int acpi_numa __initdata;
 
 static __init int setup_node(int pxm)
@@ -33,7 +35,7 @@ static __init int setup_node(int pxm)
 
 static __init void bad_srat(void)
 {
-	printk(KERN_ERR "SRAT: SRAT not used.\n");
+	pr_err("SRAT not used.\n");
 	acpi_numa = -1;
 }
 
@@ -71,26 +73,26 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 	pxm = pa->proximity_domain;
 	apic_id = pa->apic_id;
 	if (!apic->apic_id_valid(apic_id)) {
-		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
-			 pxm, apic_id);
+		pr_info("PXM %u -> X2APIC 0x%04x ignored\n",
+			pxm, apic_id);
 		return;
 	}
 	node = setup_node(pxm);
 	if (node < 0) {
-		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
+		pr_err("Too many proximity domains %x\n", pxm);
 		bad_srat();
 		return;
 	}
 
 	if (apic_id >= MAX_LOCAL_APIC) {
-		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
+		pr_info("PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
 		return;
 	}
 	set_apicid_to_node(apic_id, node);
 	node_set(node, numa_nodes_parsed);
 	acpi_numa = 1;
-	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
-	       pxm, apic_id, node);
+	pr_info("PXM %u -> APIC 0x%04x -> Node %u\n",
+	        pxm, apic_id, node);
 }
 
 /* Callback for Proximity Domain -> LAPIC mapping */
@@ -113,7 +115,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 		pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
 	node = setup_node(pxm);
 	if (node < 0) {
-		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
+		pr_err("Too many proximity domains %x\n", pxm);
 		bad_srat();
 		return;
 	}
@@ -124,15 +126,15 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 		apic_id = pa->apic_id;
 
 	if (apic_id >= MAX_LOCAL_APIC) {
-		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
+		pr_info("PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
 		return;
 	}
 
 	set_apicid_to_node(apic_id, node);
 	node_set(node, numa_nodes_parsed);
 	acpi_numa = 1;
-	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
-	       pxm, apic_id, node);
+	pr_info("PXM %u -> APIC 0x%02x -> Node %u\n",
+	        pxm, apic_id, node);
 }
 
 /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
@@ -157,7 +159,7 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 
 	node = setup_node(pxm);
 	if (node < 0) {
-		printk(KERN_ERR "SRAT: Too many proximity domains.\n");
+		pr_err("Too many proximity domains.\n");
 		goto out_err_bad_srat;
 	}
 
@@ -166,9 +168,9 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 
 	node_set(node, numa_nodes_parsed);
 
-	printk(KERN_INFO "SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]\n",
-	       node, pxm,
-	       (unsigned long long) start, (unsigned long long) end - 1);
+	pr_info("Node %u PXM %u [mem %#010Lx-%#010Lx]\n",
+	        node, pxm,
+	        (unsigned long long) start, (unsigned long long) end - 1);
 
 	return 0;
 out_err_bad_srat:
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH v2 2/4] acpi cleanup: Use pr_{info|err}() instead of printk() in arch/x86/mm/srat.c

Quoted 34 lines · Tang Chen

Use pr_{info|err}() instead of printk() in arch/x86/mm/srat.c.

As suggested by Joe Perches <[email protected]>, use pr_fmt(fmt) to simplify the output format.

---
  arch/x86/mm/srat.c |   32 +++++++++++++++++---------------
  1 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/mm/srat.c +3 -1
index 1613c02..5adfcfb 100644
@@ -24,6 +24,8 @@
  #include <asm/apic.h>
  #include <asm/uv/uv.h>
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
  int acpi_numa __initdata;
 
  static __init int setup_node(int pxm)
@@ -33,7 +35,7 @@ static __init int setup_node(int pxm)
 
  static __init void bad_srat(void)
  {
-	printk(KERN_ERR "SRAT: SRAT not used.\n");
+	pr_err("SRAT not used.\n");
  	acpi_numa = -1;
  }
 

arch/x86/mm/srat.c acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) · line 78

Quoted 8 lines
arch/x86/mm/srat.c +2 -2
@@ -71,26 +73,26 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
  	pxm = pa->proximity_domain;
  	apic_id = pa->apic_id;
  	if (!apic->apic_id_valid(apic_id)) {
 
-		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
-			 pxm, apic_id);
+		pr_info("PXM %u -> X2APIC 0x%04x ignored\n",
+			pxm, apic_id);

It should be one line.

Quoted 13 lines
arch/x86/mm/srat.c +2 -2
  		return;
  	}
  	node = setup_node(pxm);
  	if (node < 0) {
-		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
+		pr_err("Too many proximity domains %x\n", pxm);
  		bad_srat();
  		return;
  	}
 
  	if (apic_id >= MAX_LOCAL_APIC) {
-		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
+		pr_info("PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);

arch/x86/mm/srat.c acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)

Quoted 10 lines
arch/x86/mm/srat.c +2 -2
  		return;
  	}
  	set_apicid_to_node(apic_id, node);
  	node_set(node, numa_nodes_parsed);
  	acpi_numa = 1;
 
-	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
-	       pxm, apic_id, node);
+	pr_info("PXM %u -> APIC 0x%04x -> Node %u\n",
+	        pxm, apic_id, node);

ditto.

Quoted 19 lines
arch/x86/mm/srat.c +0 -0
  }

/* Callback for Proximity Domain -> LAPIC mapping */

arch/x86/mm/srat.c +2 -2
@@ -113,7 +115,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
  		pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
  	node = setup_node(pxm);
  	if (node < 0) {
-		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
+		pr_err("Too many proximity domains %x\n", pxm);
  		bad_srat();
  		return;
  	}
@@ -124,15 +126,15 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
  		apic_id = pa->apic_id;
 
  	if (apic_id >= MAX_LOCAL_APIC) {
-		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
+		pr_info("PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  		return;

arch/x86/mm/srat.c acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) · line 138

Quoted 10 lines
arch/x86/mm/srat.c +2 -2
  	}
 
  	set_apicid_to_node(apic_id, node);
  	node_set(node, numa_nodes_parsed);
  	acpi_numa = 1;
 
-	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
-	       pxm, apic_id, node);
+	pr_info("PXM %u -> APIC 0x%02x -> Node %u\n",
+	        pxm, apic_id, node);

ditto.

Quoted 13 lines
arch/x86/mm/srat.c +0 -0
  }
 

/* Callback for parsing of the Proximity Domain <-> Memory Area mappings */

arch/x86/mm/srat.c +1 -1
@@ -157,7 +159,7 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 
  	node = setup_node(pxm);
  	if (node < 0) {
-		printk(KERN_ERR "SRAT: Too many proximity domains.\n");
+		pr_err("Too many proximity domains.\n");
  		goto out_err_bad_srat;
  	}
 

arch/x86/mm/srat.c acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma) · line 174

Quoted 10 lines
arch/x86/mm/srat.c +3 -3
@@ -166,9 +168,9 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 
  	node_set(node, numa_nodes_parsed);
 
 
-	printk(KERN_INFO "SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]\n",
-	       node, pxm,
-	       (unsigned long long) start, (unsigned long long) end - 1);
+	pr_info("Node %u PXM %u [mem %#010Lx-%#010Lx]\n",
+	        node, pxm,
+	        (unsigned long long) start, (unsigned long long) end - 1);

It should be two lines.

Thanks,
Yasuaki Ishimatsu

Quoted 4 lines
arch/x86/mm/srat.c +0 -0
  	return 0;
  out_err_bad_srat:
author
#4 lore raw

PATCH v2 3/4 acpi: Check if @id is NULL in acpi_table_parse()

In reply to Tang Chen

strncmp() does not check if the params are NULL. In acpi_table_parse(), if @id is NULL, the kernel will panic.

---
 drivers/acpi/tables.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/acpi/tables.c +1 -1
index d67a1fe..5a5263b 100644
@@ -293,7 +293,7 @@ int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
 	if (acpi_disabled)
 		return -ENODEV;
 
-	if (!handler)
+	if (!id || !handler)
 		return -EINVAL;
 
 	if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
Signature · 1 line
1.7.1
author
#5 lore raw

PATCH v2 4/4 acpi: Return -ENOENT in acpi_table_parse() and fix wrong comment.

In reply to Tang Chen

The comment about return value of acpi_table_parse() is incorrect. This patch fix it.

Since all callers only check if the function succeeded or not, this patch simplifies the semantics by returning -errno for all failure cases. This will also simply the comment.

As suggested by Toshi Kani <[email protected]>, also change the stub in linux/acpi.h to return -ENODEV.

---
 drivers/acpi/tables.c |    7 ++++---
 include/linux/acpi.h  |    2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/acpi/tables.c +4 -3
index 5a5263b..e6de24f 100644
@@ -278,12 +278,13 @@ acpi_table_parse_madt(enum acpi_madt_type id,
 
 /**
  * acpi_table_parse - find table with @id, run @handler on it
- *
  * @id: table id to find
  * @handler: handler to run
  *
  * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
- * run @handler on it.  Return 0 if table found, return on if not.
+ * run @handler on it.
+ *
+ * Return 0 on success, -errno on failure.
  */
 int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
 {
@@ -306,7 +307,7 @@ int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
 		early_acpi_os_unmap_memory(table, tbl_size);
 		return 0;
 	} else
-		return 1;
+		return -ENOENT;
 }
 
 /* 
include/linux/acpi.h +1 -1
index 353ba25..39fd53a 100644
@@ -443,7 +443,7 @@ struct acpi_table_header;
 static inline int acpi_table_parse(char *id,
 				int (*handler)(struct acpi_table_header *))
 {
-	return -1;
+	return -ENODEV;
 }
 
 static inline int acpi_nvs_register(__u64 start, __u64 size)
Signature · 1 line
1.7.1
Acked-by on v2 4/4
#6 lore raw

Re: [PATCH v2 4/4] acpi: Return -ENOENT in acpi_table_parse() and fix wrong comment.

Quoted 11 lines · Tang Chen

The comment about return value of acpi_table_parse() is incorrect. This patch fix it.

Since all callers only check if the function succeeded or not, this patch simplifies the semantics by returning -errno for all failure cases. This will also simply the comment.

As suggested by Toshi Kani <[email protected]>, also change the stub in linux/acpi.h to return -ENODEV.

Thanks,
-Toshi

#7 lore raw
In reply to Tang Chen
Quoted 19 lines · Tang Chen

This patch-set fix the following problems:

1. Kill useless function save_add_info() which will block us from using numa when MEMORY_HOTPLUG is not configured.
2. acpi_table_parse() didn't check if @id is NULL.
3. Fix incorrect comment in acpi_table_parse(), and return -ENOENT if a table is not found.

And also did some cleanup.

change log v1 -> v2:
1. Use pr_fmt() to simply the SRAT message.
Suggested by Joe Perches <[email protected]>
2. Improve the log in patch 4, and change the return value of the stub of acpi_table_parse() in linux/acpi.h
Suggested by Toshi Kani <[email protected]>
3. Merge the two pr_{info|err} patches into one.
4. Remove on of the patch that has been merged by Rafael.

Quoted 6 lines

Tang Chen (4):
acpi, numa, mem_hotplug: Kill save_add_info(). acpi cleanup: Use pr_{info|err}() instead of printk() in

    arch/x86/mm/srat.c

acpi: Check if @id is NULL in acpi_table_parse()
acpi: Return -ENOENT in acpi_table_parse() and fix wrong comment.

Thanks for the patches!

Peter, any objections against [1-2/4]? If not, I'll queue them up for 3.13.

Thanks,
Rafael

author
#8 lore raw
Quoted 27 lines · Rafael J. Wysocki
Quoted 19 lines · Tang Chen

This patch-set fix the following problems:

1. Kill useless function save_add_info() which will block us from using numa when MEMORY_HOTPLUG is not configured.
2. acpi_table_parse() didn't check if @id is NULL.
3. Fix incorrect comment in acpi_table_parse(), and return -ENOENT if a table is not found.

And also did some cleanup.

change log v1 -> v2:
1. Use pr_fmt() to simply the SRAT message.
Suggested by Joe Perches<[email protected]>
2. Improve the log in patch 4, and change the return value of the stub of acpi_table_parse() in linux/acpi.h
Suggested by Toshi Kani<[email protected]>
3. Merge the two pr_{info|err} patches into one.
4. Remove on of the patch that has been merged by Rafael.

Quoted 6 lines

Tang Chen (4):
acpi, numa, mem_hotplug: Kill save_add_info(). acpi cleanup: Use pr_{info|err}() instead of printk() in

     arch/x86/mm/srat.c

acpi: Check if @id is NULL in acpi_table_parse()
acpi: Return -ENOENT in acpi_table_parse() and fix wrong comment.

Quoted 3 lines

Thanks for the patches!

Peter, any objections against [1-2/4]? If not, I'll queue them up for 3.13.

Hi Rafael,

Thanks for the checking. As Ishimatu has sent some comments for patch 2, I'd like to send a v3 patch-set soon. Please queue the coming v3 patches.

Thanks.

#9 lore raw
Quoted 30 lines · Tang Chen
Quoted 29 lines · Rafael J. Wysocki
Quoted 19 lines · Tang Chen

This patch-set fix the following problems:

1. Kill useless function save_add_info() which will block us from using numa when MEMORY_HOTPLUG is not configured.
2. acpi_table_parse() didn't check if @id is NULL.
3. Fix incorrect comment in acpi_table_parse(), and return -ENOENT if a table is not found.

And also did some cleanup.

change log v1 -> v2:
1. Use pr_fmt() to simply the SRAT message.
Suggested by Joe Perches<[email protected]>
2. Improve the log in patch 4, and change the return value of the stub of acpi_table_parse() in linux/acpi.h
Suggested by Toshi Kani<[email protected]>
3. Merge the two pr_{info|err} patches into one.
4. Remove on of the patch that has been merged by Rafael.

Quoted 6 lines

Tang Chen (4):
acpi, numa, mem_hotplug: Kill save_add_info(). acpi cleanup: Use pr_{info|err}() instead of printk() in

     arch/x86/mm/srat.c

acpi: Check if @id is NULL in acpi_table_parse()
acpi: Return -ENOENT in acpi_table_parse() and fix wrong comment.

Thanks for the patches!

Quoted 7 lines
Quoted 1 line

Peter, any objections against [1-2/4]? If not, I'll queue them up for 3.13.

Hi Rafael,

Thanks for the checking. As Ishimatu has sent some comments for patch 2, I'd like
to send a v3 patch-set soon. Please queue the coming v3 patches.

Sure, thanks.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.