Skip to contentSkip to conversation

2.6.33-rc2 - pci: Commit e0cd516 causes OOPS

Regression Superseded David John 6 participants 11 messages Jan 1, 2010 – Jan 4, 2010

Subsystems (2)
lore
Share & tools
lore

David John

author
#0 lore raw

Hi All,

Commit e0cd516 causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

The patch following this mail fixes the problem for x86. Perhaps a more thorough solution would be to fix the PCI layer to set the node information for devices to zero rather than -1 (Since if CONFIG_NUMA=y we have node 0)? I don't know whether it is safe / correct to do this.

Regards,
David.

author
#1 lore raw

PATCH 1/1 Check the node argument passed to cpumask_of_node

Ensure that the node value is valid.

arch/x86/include/asm/topology.h +2 -1
index c5087d7..1141a6e 100644
@@ -99,7 +99,8 @@ extern const struct cpumask *cpumask_of_node(int node);
 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
 static inline const struct cpumask *cpumask_of_node(int node)
 {
-	return node_to_cpumask_map[node];
+	return (node < 0 || node >= nr_node_ids) ? cpu_online_mask :
+						   node_to_cpumask_map[node];
 }
 #endif
 
#2 lore raw
In reply to David John
Quoted 1 line · David John

Hi All,

Hi,

Quoted 9 lines

Commit e0cd516 causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

The patch following this mail fixes the problem for x86. Perhaps a more thorough solution would be to fix the PCI layer to set the node information for devices to zero rather than -1 (Since if CONFIG_NUMA=y we have node 0)? I don't know whether it is safe / correct to do this.

First, it would be nicer if you said what the commit subject was in addition to providing its hash.

Second, why don't you put the information above into the changelog of your patch?

Rafael

author
#3 lore raw

PATCH v2 1/1 Check the node argument passed to cpumask_of_node

Commit e0cd516 "PCI: derive nearby CPUs from device's instead of bus' NUMA information" causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

Ensure that the node value is valid.

arch/x86/include/asm/topology.h +2 -1
index c5087d7..1141a6e 100644
@@ -99,7 +99,8 @@ extern const struct cpumask *cpumask_of_node(int node);
 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
 static inline const struct cpumask *cpumask_of_node(int node)
 {
-	return node_to_cpumask_map[node];
+	return (node < 0 || node >= nr_node_ids) ? cpu_online_mask :
+						   node_to_cpumask_map[node];
 }
 #endif
 
#4 lore raw

Re: [PATCH v2] Check the node argument passed to cpumask_of_node

Quoted 6 lines · David John

Commit e0cd516 "PCI: derive nearby CPUs from device's instead of bus' NUMA information" causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

Ensure that the node value is valid.

This only works for x86, and only for !CONFIG_DEBUG_PER_CPU_MAPS.

I suggest fixing the callers introduced in e0cd516 for the moment, then if you feel enthused, change the semantics of cpumask_of_node and remove the checks from the various callers.

(And please only check for -1: it has a special meaning, unlike other invalid numbers which indicate a bug).

Thanks,
Rusty.

author
#5 lore raw

Re: [PATCH v2] Check the node argument passed to cpumask_of_node

Quoted 6 lines · Rusty Russell
Quoted 5 lines · David John

Commit e0cd516 "PCI: derive nearby CPUs from device's instead of bus' NUMA information" causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

Quoted 7 lines
Quoted 1 line

Ensure that the node value is valid.

This only works for x86, and only for !CONFIG_DEBUG_PER_CPU_MAPS.

I suggest fixing the callers introduced in e0cd516 for the moment, then if you feel enthused, change the semantics of cpumask_of_node and remove the checks from the various callers.

Okay, I'll do as you suggested.

Regards,
David.

author
#6 lore raw

PATCH v3 1/1 Check the node argument passed to cpumask_of_node

Commit e0cd516 "PCI: derive nearby CPUs from device's instead of bus' NUMA information" causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

Add a check to prevent this.

drivers/pci/pci-sysfs.c +4 -2
index c5df94e..807224e 100644
@@ -75,7 +75,8 @@ static ssize_t local_cpus_show(struct device *dev,
 	int len;
 
 #ifdef CONFIG_NUMA
-	mask = cpumask_of_node(dev_to_node(dev));
+	mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
+					  cpumask_of_node(dev_to_node(dev));
 #else
 	mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
 #endif
@@ -93,7 +94,8 @@ static ssize_t local_cpulist_show(struct device *dev,
 	int len;
 
 #ifdef CONFIG_NUMA
-	mask = cpumask_of_node(dev_to_node(dev));
+	mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
+					  cpumask_of_node(dev_to_node(dev));
 #else
 	mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
 #endif
Applied
#7 lore raw

Re: [PATCH v3] Check the node argument passed to cpumask_of_node

Quoted 31 lines · On Mon, 4 Jan 2010 20:28:57 +0530 David John <[email protected]> wrote:

Commit e0cd516 "PCI: derive nearby CPUs from device's instead of bus' NUMA information" causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

Add a check to prevent this.

drivers/pci/pci-sysfs.c +2 -1
index c5df94e..807224e 100644
@@ -75,7 +75,8 @@ static ssize_t local_cpus_show(struct device *dev,
 	int len;
 
 #ifdef CONFIG_NUMA
-	mask = cpumask_of_node(dev_to_node(dev));
+	mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
+

cpumask_of_node(dev_to_node(dev)); #else

drivers/pci/pci-sysfs.c +2 -1
 	mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
 #endif
@@ -93,7 +94,8 @@ static ssize_t local_cpulist_show(struct device
 *dev, int len;
 
 #ifdef CONFIG_NUMA
-	mask = cpumask_of_node(dev_to_node(dev));
+	mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
+
Quoted 4 lines

cpumask_of_node(dev_to_node(dev)); #else
mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
#endif

Applied to my for-linus branch, thanks David.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#8 lore raw

Re: [PATCH v2] Check the node argument passed to cpumask_of_node

In reply to David John

Hi, David

This problem also happened when the CONFIG_DEBUG_PER_CPU_MAPS was used, so how about modifying the code for it working well?

Best Regards,
Jin Dongming

Quoted 30 lines · David John

Commit e0cd516 "PCI: derive nearby CPUs from device's instead of bus' NUMA information" causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

Ensure that the node value is valid.

arch/x86/include/asm/topology.h +2 -2
index c5087d7..1141a6e 100644
@@ -99,7 +99,8 @@ extern const struct cpumask *cpumask_of_node(int node);
 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
 static inline const struct cpumask *cpumask_of_node(int node)
 {
-	return node_to_cpumask_map[node];
+	return (node < 0 || node >= nr_node_ids) ? cpu_online_mask :
+						   node_to_cpumask_map[node];
 }
 #endif
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#9 lore raw
In reply to David John
Quoted 11 lines · David John

Hi All,

Commit e0cd516 causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

The patch following this mail fixes the problem for x86. Perhaps a more thorough solution would be to fix the PCI layer to set the node information for devices to zero rather than -1 (Since if CONFIG_NUMA=y we have node 0)? I don't know whether it is safe / correct to do this.

no.

1. -1, mean calling code will use node that code is running on.
2. the system that have two or more nodes, and more peer root buses. if the first node doesn't have RAM installed, no node0 then.

YH

author
#10 lore raw
Quoted 13 lines · Yinghai Lu
Quoted 11 lines · David John

Hi All,

Commit e0cd516 causes an null pointer dereference when reading from the sysfs attributes local_cpu* on Intel machines with no ACPI NUMA proximity info, since dev->numa_node gets set to -1 for all PCI devices, which then gets passed to cpumask_of_node.

The patch following this mail fixes the problem for x86. Perhaps a more thorough solution would be to fix the PCI layer to set the node information for devices to zero rather than -1 (Since if CONFIG_NUMA=y we have node 0)? I don't know whether it is safe / correct to do this.

Quoted 8 lines

no.

1. -1, mean calling code will use node that code is running on.
2. the system that have two or more nodes, and more peer root buses. if the first node doesn't have RAM installed, no node0 then.

YH

Oh I see. Thanks.

Regards,
David.