Skip to contentSkip to conversation

ACPI Fixes for Hotplug

PATCH In review Joerg Roedel 5 participants 14 messages Mar 22, 2017 – Apr 19, 2017 ACPI

lore
Share & tools
lore
#0 lore raw

cover ACPI Fixes for Hotplug

Hi,

here are fixes for three issues I found in ACPI code during hotplug testing. Patches 2 and 3 fix the same issue, but I think both make sense on their own.

Please review.

Thanks,

Joerg

Joerg Roedel (3):
ACPI, ioapic: Clear on-stack resource before using it
ACPI: Remove platform devices from a bus on removal
ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

 drivers/acpi/acpi_platform.c |  8 +++++---
 drivers/acpi/ioapic.c        |  6 ++++++
 drivers/acpi/scan.c          | 26 ++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)
Signature · 1 line
1.9.1
#5 lore raw

PATCH 3/3 ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

From: Joerg Roedel <[email protected]>

No platform-device is required for IO(x)APICs, so don't even create them.

---
 drivers/acpi/acpi_platform.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpi_platform.c +5 -3
index b4c1a6a..03250e1 100644
@@ -25,9 +25,11 @@
 ACPI_MODULE_NAME("platform");
 
 static const struct acpi_device_id forbidden_id_list[] = {
-	{"PNP0000", 0},	/* PIC */
-	{"PNP0100", 0},	/* Timer */
-	{"PNP0200", 0},	/* AT DMA Controller */
+	{"PNP0000",  0},	/* PIC */
+	{"PNP0100",  0},	/* Timer */
+	{"PNP0200",  0},	/* AT DMA Controller */
+	{"ACPI0009", 0},	/* IOxAPIC */
+	{"ACPI000A", 0},	/* IOAPIC */
 	{"", 0},
 };
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/3 ACPI, ioapic: Clear on-stack resource before using it

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

The on-stack resource-window 'win' in setup_res() is not properly initialized. This causes the pointers in the embedded 'struct resource' to contain stale pointers.

These pointers (in my case the ->child pointer) gets later propagated to the global iomem_resources list, causing a #GP exception when the list is traversed in iomem_map_sanity_check().

Fixes c183619b63ec ('x86/irq, ACPI: Implement ACPI driver to support IOAPIC hotplug')
---
 drivers/acpi/ioapic.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/acpi/ioapic.c +6 -0
index 1120dfd6..7e4fbf9 100644
@@ -45,6 +45,12 @@ static acpi_status setup_res(struct acpi_resource *acpi_res, void *data)
 	struct resource *res = data;
 	struct resource_win win;
 
+	/*
+	 * We might assign this to 'res' later, make sure all pointers are
+	 * cleared before the resource is added to the global list
+	 */
+	memset(&win, 0, sizeof(win));
+
 	res->flags = 0;
 	if (acpi_dev_filter_resource_type(acpi_res, IORESOURCE_MEM))
 		return AE_OK;
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/3 ACPI: Remove platform devices from a bus on removal

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

The function acpi_bus_attach() creates platform_devices if this is specified by the firmware. But in acpi_bus_trim() these devices are not removed, leaving a dangling reference to the parent device.

In the case of a PCI root-bus, this results in the host_bridge device not being released on hot-remove.

Fix it by scanning the list of platform_devices for devices to be removed with the bus.

---
 drivers/acpi/scan.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/acpi/scan.c +26 -0
index 1926918..b07518b 100644
@@ -13,6 +13,7 @@
 #include <linux/dmi.h>
 #include <linux/nls.h>
 #include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
 
 #include <asm/pgtable.h>
 
@@ -1928,6 +1929,25 @@ int acpi_bus_scan(acpi_handle handle)
 EXPORT_SYMBOL(acpi_bus_scan);
 
 /**
+ * acpi_bus_trim_platform_device - Check and remove a platform device
+ *				   from a bus
+ * @dev: Platform device to check
+ * @data: pointer to the acpi_device to check dev against
+ *
+ * Checks whether the platform_device dev belongs to the acpi_device
+ * data and unregisters dev if it matches.
+ */
+static int acpi_bus_trim_platform_device(struct device *dev, void *data)
+{
+	struct acpi_device *adev = data;
+
+	if (dev->fwnode == acpi_fwnode_handle(adev))
+		platform_device_unregister(to_platform_device(dev));
+
+	return 0;
+}
+
+/**
  * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
  * @adev: Root of the ACPI namespace scope to walk.
  *
@@ -1950,6 +1970,12 @@ void acpi_bus_trim(struct acpi_device *adev)
 	} else {
 		device_release_driver(&adev->dev);
 	}
+
+	/* Remove platform devices from the bus */
+	if (adev->pnp.type.platform_id)
+		bus_for_each_dev(&platform_bus_type, NULL, adev,
+				 acpi_bus_trim_platform_device);
+
 	/*
 	 * Most likely, the device is going away, so put it into D3cold before
 	 * that.
Signature · 1 line
1.9.1
#6 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

In reply to Joerg Roedel
Quoted 6 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

No platform-device is required for IO(x)APICs, so don't even create them.

If we do this, I'd prefer not to do [2/3], because we'll introduce code that will be essentially dead then.

Quoted 9 lines
---
 drivers/acpi/acpi_platform.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpi_platform.c +0 -0
index b4c1a6a..03250e1 100644

drivers/acpi/acpi_platform.c line 30

Quoted 6 lines
drivers/acpi/acpi_platform.c +0 -3
@@ -25,9 +25,11 @@
 ACPI_MODULE_NAME("platform");
 
 static const struct acpi_device_id forbidden_id_list[] = {
-	{"PNP0000", 0},	/* PIC */
-	{"PNP0100", 0},	/* Timer */
-	{"PNP0200", 0},	/* AT DMA Controller */

Why do you change the existing entries?

drivers/acpi/acpi_platform.c line 35

Quoted 9 lines
drivers/acpi/acpi_platform.c +5 -0
+	{"PNP0000",  0},	/* PIC */
+	{"PNP0100",  0},	/* Timer */
+	{"PNP0200",  0},	/* AT DMA Controller */
+	{"ACPI0009", 0},	/* IOxAPIC */
+	{"ACPI000A", 0},	/* IOAPIC */
 	{"", 0},
 };
 

Thanks,
Rafael

#7 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Hi Rafael,

Quoted 10 lines · Rafael J. Wysocki
Quoted 6 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

No platform-device is required for IO(x)APICs, so don't even create them.

If we do this, I'd prefer not to do [2/3], because we'll introduce code that will be essentially dead then.

In this case the code in acpi_bus_attach() adding platform_devices is also dead. Could it be removed then?

Quoted 12 lines
Quoted 12 lines
---
 drivers/acpi/acpi_platform.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpi_platform.c +0 -0
index b4c1a6a..03250e1 100644
@@ -25,9 +25,11 @@
 ACPI_MODULE_NAME("platform");
 
Quoted 6 lines

drivers/acpi/acpi_platform.c line 30

Quoted 4 lines
drivers/acpi/acpi_platform.c +0 -3
 static const struct acpi_device_id forbidden_id_list[] = {
-	{"PNP0000", 0},	/* PIC */
-	{"PNP0100", 0},	/* Timer */
-	{"PNP0200", 0},	/* AT DMA Controller */

Why do you change the existing entries?

Just to align the '0's in one column :)

Joerg

#8 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Quoted 9 lines · Joerg Roedel

Hi Rafael,

Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

No platform-device is required for IO(x)APICs, so don't even create them.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

If we do this, I'd prefer not to do [2/3], because we'll introduce code that will be essentially dead then.

In this case the code in acpi_bus_attach() adding platform_devices is also dead. Could it be removed then?

It is not dead.

Platform devices are actually created by it, but they never go away.

Thanks,
Rafael

#9 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Quoted 15 lines · Rafael J. Wysocki
Quoted 14 lines · Joerg Roedel

Hi Rafael,

Quoted 10 lines · Rafael J. Wysocki
Quoted 6 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

No platform-device is required for IO(x)APICs, so don't even create them.

If we do this, I'd prefer not to do [2/3], because we'll introduce code that will be essentially dead then.

Quoted 6 lines
Quoted 2 lines

In this case the code in acpi_bus_attach() adding platform_devices is also dead. Could it be removed then?

It is not dead.

Platform devices are actually created by it, but they never go away.

IOW, they should never be created for anything hot-removable.

If they are, this is a bug (as you noticed).

Thanks,
Rafael

#10 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Quoted 9 lines · Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

It is not dead.

Platform devices are actually created by it, but they never go away.

IOW, they should never be created for anything hot-removable.

If they are, this is a bug (as you noticed).

Okay, in this case patch 2 can be omitted.

But for my understanding, platform_devices created in acpi_bus_attach() that are not hot-removable don't take a reference to the host_bridge, right (at least when the host-bridge is hot-removable)?

Otherwise this would be a leak again in case the host-bridge gets removed.

Joerg

#11 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Quoted 9 lines · Joerg Roedel
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

It is not dead.

Platform devices are actually created by it, but they never go away.

IOW, they should never be created for anything hot-removable.

Quoted 7 lines
Quoted 1 line

If they are, this is a bug (as you noticed).

Okay, in this case patch 2 can be omitted.

But for my understanding, platform_devices created in acpi_bus_attach() that are not hot-removable don't take a reference to the host_bridge, right (at least when the host-bridge is hot-removable)?

They shouldn't.

Quoted 2 lines

Otherwise this would be a leak again in case the host-bridge gets removed.

Right.

The main problem is that representing anything hot-removable as a platform device is inherently fragile, as the platform bus type has no idea whatever about things that may physically go away and platform drivers don't expect that devices may vanish from under them in general and so on. Unregistration alone doesn't help much with that, so IMO at least for now it's better to avoid using platform_device for hot-removable stuff.

Thanks,
Rafael

#12 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Quoted 7 lines · Rafael J. Wysocki

The main problem is that representing anything hot-removable as a platform device is inherently fragile, as the platform bus type has no idea whatever about things that may physically go away and platform drivers don't expect that devices may vanish from under them in general and so on. Unregistration alone doesn't help much with that, so IMO at least for now it's better to avoid using platform_device for hot-removable stuff.

Okay, thanks for the explanation. So patch 2 could be dropped, should I resend without that patch or do you want to pick them up from this post?

Joerg

#13 lore raw

Re: [PATCH 3/3] ACPI: Don't create a platform_device for IOAPIC/IOxAPIC

Quoted 11 lines · Joerg Roedel
Quoted 7 lines · Rafael J. Wysocki

The main problem is that representing anything hot-removable as a platform device is inherently fragile, as the platform bus type has no idea whatever about things that may physically go away and platform drivers don't expect that devices may vanish from under them in general and so on. Unregistration alone doesn't help much with that, so IMO at least for now it's better to avoid using platform_device for hot-removable stuff.

Okay, thanks for the explanation. So patch 2 could be dropped, should I resend without that patch or do you want to pick them up from this post?

I can pick them up easily enough, thanks!

Take care,
Rafael

#3 lore raw

Re: [PATCH 2/3] ACPI: Remove platform devices from a bus on removal

In reply to Joerg Roedel
Quoted 57 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The function acpi_bus_attach() creates platform_devices if this is specified by the firmware. But in acpi_bus_trim() these devices are not removed, leaving a dangling reference to the parent device.

In the case of a PCI root-bus, this results in the host_bridge device not being released on hot-remove.

Fix it by scanning the list of platform_devices for devices to be removed with the bus.

---
 drivers/acpi/scan.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/acpi/scan.c +20 -0
index 1926918..b07518b 100644
@@ -13,6 +13,7 @@
 #include <linux/dmi.h>
 #include <linux/nls.h>
 #include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
 
 #include <asm/pgtable.h>
 
@@ -1928,6 +1929,25 @@ int acpi_bus_scan(acpi_handle handle)
 EXPORT_SYMBOL(acpi_bus_scan);
 
 /**
+ * acpi_bus_trim_platform_device - Check and remove a platform device
+ *				   from a bus
+ * @dev: Platform device to check
+ * @data: pointer to the acpi_device to check dev against
+ *
+ * Checks whether the platform_device dev belongs to the acpi_device
+ * data and unregisters dev if it matches.
+ */
+static int acpi_bus_trim_platform_device(struct device *dev, void *data)
+{
+	struct acpi_device *adev = data;
+
+	if (dev->fwnode == acpi_fwnode_handle(adev))
+		platform_device_unregister(to_platform_device(dev));
+
+	return 0;
+}
+
+/**
  * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
  * @adev: Root of the ACPI namespace scope to walk.
  *

drivers/acpi/scan.c void acpi_bus_trim(struct acpi_device *adev) · line 1975

Quoted 6 lines
drivers/acpi/scan.c +3 -0
@@ -1950,6 +1970,12 @@ void acpi_bus_trim(struct acpi_device *adev)
 	} else {
 		device_release_driver(&adev->dev);
 	}
+
+	/* Remove platform devices from the bus */
+	if (adev->pnp.type.platform_id)

This patch cases that dock_notify() is broken in find_dock_station() because the dock_station platform device was removed.

If anyone wants to apply this patch, then the dock device should be excluded:

+ if (is_dock_device(adev) && adev->pnp.type.platform_id)

drivers/acpi/scan.c void acpi_bus_trim(struct acpi_device *adev) · line 1981

Quoted 6 lines
drivers/acpi/scan.c +3 -0
+		bus_for_each_dev(&platform_bus_type, NULL, adev,
+				 acpi_bus_trim_platform_device);
+
 	/*
 	 * Most likely, the device is going away, so put it into D3cold before
 	 * that.

Thanks a lot!
Joey Lee

#4 lore raw

Re: [PATCH 2/3] ACPI: Remove platform devices from a bus on removal

Quoted 71 lines · joeyli
Quoted 57 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The function acpi_bus_attach() creates platform_devices if this is specified by the firmware. But in acpi_bus_trim() these devices are not removed, leaving a dangling reference to the parent device.

In the case of a PCI root-bus, this results in the host_bridge device not being released on hot-remove.

Fix it by scanning the list of platform_devices for devices to be removed with the bus.

---
 drivers/acpi/scan.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/acpi/scan.c +20 -0
index 1926918..b07518b 100644
@@ -13,6 +13,7 @@
 #include <linux/dmi.h>
 #include <linux/nls.h>
 #include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
 
 #include <asm/pgtable.h>
 
@@ -1928,6 +1929,25 @@ int acpi_bus_scan(acpi_handle handle)
 EXPORT_SYMBOL(acpi_bus_scan);
 
 /**
+ * acpi_bus_trim_platform_device - Check and remove a platform device
+ *				   from a bus
+ * @dev: Platform device to check
+ * @data: pointer to the acpi_device to check dev against
+ *
+ * Checks whether the platform_device dev belongs to the acpi_device
+ * data and unregisters dev if it matches.
+ */
+static int acpi_bus_trim_platform_device(struct device *dev, void *data)
+{
+	struct acpi_device *adev = data;
+
+	if (dev->fwnode == acpi_fwnode_handle(adev))
+		platform_device_unregister(to_platform_device(dev));
+
+	return 0;
+}
+
+/**
  * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
  * @adev: Root of the ACPI namespace scope to walk.
  *

drivers/acpi/scan.c void acpi_bus_trim(struct acpi_device *adev) · line 1975

Quoted 6 lines
drivers/acpi/scan.c +3 -0
@@ -1950,6 +1970,12 @@ void acpi_bus_trim(struct acpi_device *adev)
 	} else {
 		device_release_driver(&adev->dev);
 	}
+
+	/* Remove platform devices from the bus */
+	if (adev->pnp.type.platform_id)

This patch cases that dock_notify() is broken in find_dock_station() because the dock_station platform device was removed.

If anyone wants to apply this patch, then the dock device should be excluded:

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (is_dock_device(adev) && adev->pnp.type.platform_id)

Sorry, it should be:
+ if (!is_dock_device(adev) && adev->pnp.type.platform_id)

Quoted 8 lines

drivers/acpi/scan.c void acpi_bus_trim(struct acpi_device *adev) · line 1981

Quoted 7 lines
drivers/acpi/scan.c +3 -0
+		bus_for_each_dev(&platform_bus_type, NULL, adev,
+				 acpi_bus_trim_platform_device);
+
 	/*
 	 * Most likely, the device is going away, so put it into D3cold before
 	 * that.

Joey Lee