Skip to contentSkip to conversation

ACPI / device_sysfs: Leave modalias empty for devices which are not present

PATCH In review Hans de Goede 4 participants 8 messages Oct 15, 2017 – Nov 18, 2017 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / device_sysfs: Leave modalias empty for devices which are not present

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

---
 drivers/acpi/device_sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/acpi/device_sysfs.c +4 -0
index 24418932612e..a041689e5701 100644
@@ -146,6 +146,10 @@ static int create_pnp_modalias(struct acpi_device *acpi_dev, char *modalias,
 	int count;
 	struct acpi_hardware_id *id;
 
+	/* Avoid unnecessarily loading modules for non present devices. */
+	if (!acpi_device_is_present(acpi_dev))
+		return 0;
+
 	/*
 	 * Since we skip ACPI_DT_NAMESPACE_HID from the modalias below, 0 should
 	 * be returned if ACPI_DT_NAMESPACE_HID is the only ACPI/PNP ID in the
Signature · 1 line
2.14.2
#1 lore raw
Quoted 5 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Quoted 7 lines

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

Quoted 21 lines
---
 drivers/acpi/device_sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/acpi/device_sysfs.c +4 -1
index 24418932612e..a041689e5701 100644
@@ -146,6 +146,10 @@ static int create_pnp_modalias(struct acpi_device *acpi_dev, char *modalias,
        int count;
        struct acpi_hardware_id *id;
 
+       /* Avoid unnecessarily loading modules for non present devices. */
+       if (!acpi_device_is_present(acpi_dev))
+               return 0;
+
        /*
         * Since we skip ACPI_DT_NAMESPACE_HID from the modalias below, 0 should
         * be returned if ACPI_DT_NAMESPACE_HID is the only ACPI/PNP ID in the
--
#2 lore raw

Hi,

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

Quoted 8 lines
Quoted 3 lines

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

A good question. I would expect a change uevent to be generated in this case and when the device has become present in this new uvent the modalias will no longer be empty and the module will get loaded, so the module will not get loaded until the actual hotplug.

The actual generation of this uevent should be done by the various subsystems based on ACPI_RECONFIG_DEVICE_ADD messages, at which point adev->status is already updated and then when the subsys calls acpi_device_uevent_modalias() for the new uevent it will return a non-empty modalias.

Regards,

Hans

Quoted 22 lines
Quoted 22 lines
---
  drivers/acpi/device_sysfs.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/acpi/device_sysfs.c +4 -1
index 24418932612e..a041689e5701 100644
@@ -146,6 +146,10 @@ static int create_pnp_modalias(struct acpi_device *acpi_dev, char *modalias,
         int count;
         struct acpi_hardware_id *id;
 
+       /* Avoid unnecessarily loading modules for non present devices. */
+       if (!acpi_device_is_present(acpi_dev))
+               return 0;
+
         /*
          * Since we skip ACPI_DT_NAMESPACE_HID from the modalias below, 0 should
          * be returned if ACPI_DT_NAMESPACE_HID is the only ACPI/PNP ID in the
--
#3 lore raw

Hi,

Quoted 27 lines · Hans de Goede

Hi,

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

Quoted 8 lines
Quoted 3 lines

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

A good question. I would expect a change uevent to be generated in this case and when the device has become present in this new uvent the modalias will no longer be empty and the module will get loaded, so the module will not get loaded until the actual hotplug.

Quoted 5 lines

The actual generation of this uevent should be done by the various subsystems based on ACPI_RECONFIG_DEVICE_ADD messages, at which point adev->status is already updated and then when the subsys calls acpi_device_uevent_modalias() for the new uevent it will return a non-empty modalias.

Rafael, how do you want to move forward with this patch ?

Regards,

Hans

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines

---
  drivers/acpi/device_sysfs.c | 4 ++++

  1 file changed, 4 insertions(+)
drivers/acpi/device_sysfs.c +4 -0
index 24418932612e..a041689e5701 100644
@@ -146,6 +146,10 @@ static int create_pnp_modalias(struct acpi_device *acpi_dev, char *modalias,
          int count;
          struct acpi_hardware_id *id;
 
+       /* Avoid unnecessarily loading modules for non present devices. */
+       if (!acpi_device_is_present(acpi_dev))
+               return 0;
+
          /*
           * Since we skip ACPI_DT_NAMESPACE_HID from the modalias below, 0 should
           * be returned if ACPI_DT_NAMESPACE_HID is the only ACPI/PNP ID in the
#4 lore raw
Quoted 39 lines · Hans de Goede

Hi,

Quoted 35 lines · Hans de Goede

Hi,

Quoted 20 lines · Rafael J. Wysocki
Quoted 7 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or
0x0f based on AML variables which describe what is actually present on the board.

Quoted 8 lines

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Quoted 4 lines

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

A good question. I would expect a change uevent to be generated in this case and when the device has become present in this new uvent the modalias will no longer be empty and the module will get loaded, so the module will not get loaded until the actual hotplug.

Quoted 8 lines
Quoted 5 lines

The actual generation of this uevent should be done by the various subsystems based on ACPI_RECONFIG_DEVICE_ADD messages, at which point adev->status is already updated and then when the subsys calls acpi_device_uevent_modalias() for the new uevent it will return a non-empty modalias.

Rafael, how do you want to move forward with this patch ?

Not sure yet, sorry.

#5 lore raw
In reply to Hans de Goede

[+Mika & Andy]

Quoted 27 lines · CET Hans de Goede

Hi,

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

Quoted 8 lines
Quoted 3 lines

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

A good question. I would expect a change uevent to be generated in this case and when the device has become present in this new uvent the modalias will no longer be empty and the module will get loaded, so the module will not get loaded until the actual hotplug.

Quoted 5 lines

The actual generation of this uevent should be done by the various subsystems based on ACPI_RECONFIG_DEVICE_ADD messages, at which point adev->status is already updated and then when the subsys calls acpi_device_uevent_modalias() for the new uevent it will return a non-empty modalias.

Mika, I need your input here.

I have to say I'm not quite sure about possible implications of this change, what do you think?

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
---
  drivers/acpi/device_sysfs.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/acpi/device_sysfs.c +0 -0
index 24418932612e..a041689e5701 100644
@@ -146,6 +146,10 @@ static int create_pnp_modalias(struct acpi_device *acpi_dev, char *modalias,
         int count;
         struct acpi_hardware_id *id;
 
Quoted 8 lines

drivers/acpi/device_sysfs.c static int create_pnp_modalias(struct acpi_device *acpi_dev, char *modalias,

Quoted 8 lines
drivers/acpi/device_sysfs.c +4 -1
+       /* Avoid unnecessarily loading modules for non present devices. */
+       if (!acpi_device_is_present(acpi_dev))
+               return 0;
+
         /*
          * Since we skip ACPI_DT_NAMESPACE_HID from the modalias below, 0 should
          * be returned if ACPI_DT_NAMESPACE_HID is the only ACPI/PNP ID in the
--

--

#6 lore raw
Quoted 36 lines · Rafael J. Wysocki

[+Mika & Andy]

Quoted 27 lines · CET Hans de Goede

Hi,

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

Quoted 8 lines
Quoted 3 lines

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

A good question. I would expect a change uevent to be generated in this case and when the device has become present in this new uvent the modalias will no longer be empty and the module will get loaded, so the module will not get loaded until the actual hotplug.

Quoted 5 lines

The actual generation of this uevent should be done by the various subsystems based on ACPI_RECONFIG_DEVICE_ADD messages, at which point adev->status is already updated and then when the subsys calls acpi_device_uevent_modalias() for the new uevent it will return a non-empty modalias.

Quoted 4 lines

Mika, I need your input here.

I have to say I'm not quite sure about possible implications of this change, what do you think?

I think this could work because we are actually interested in physical Linux devices, not the struct acpi_device things. So to my understanding whenever _STA of an ACPI device goes from 0x0 to 0xf the corresponding physical device (platform, spi, i2c) gets created. Userspace is then notified by a uevent and it then reads attributes including updated modalias of that physical device.

#7 lore raw
Quoted 42 lines · CET Mika Westerberg
Quoted 36 lines · Rafael J. Wysocki

[+Mika & Andy]

Quoted 27 lines · CET Hans de Goede

Hi,

Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines · Hans de Goede

Most Bay and Cherry Trail devices use a generic DSDT with all possible peripheral devices present in the DSDT, with their _STA returning 0x00 or 0x0f based on AML variables which describe what is actually present on the board.

Since ACPI device objects with a 0x00 status (not present) still get an entry under /sys/bus/acpi/devices, and those entry had an acpi:PNPID modalias, userspace would end up loading modules for non present hardware.

Quoted 8 lines
Quoted 3 lines

This commit fixes this by leaving the modalias empty for non present devices. This results in 10 modules less being loaded with a generic distro kernel config on my Cherry Trail test-device (a GPD pocket).

Well, what about hotplug?

On some systems _STA may change from 0 to nonzero for some devices, so what's going to happen to the modalias then?

A good question. I would expect a change uevent to be generated in this case and when the device has become present in this new uvent the modalias will no longer be empty and the module will get loaded, so the module will not get loaded until the actual hotplug.

Quoted 5 lines

The actual generation of this uevent should be done by the various subsystems based on ACPI_RECONFIG_DEVICE_ADD messages, at which point adev->status is already updated and then when the subsys calls acpi_device_uevent_modalias() for the new uevent it will return a non-empty modalias.

Quoted 4 lines

Mika, I need your input here.

I have to say I'm not quite sure about possible implications of this change, what do you think?

Quoted 6 lines

I think this could work because we are actually interested in physical Linux devices, not the struct acpi_device things. So to my understanding whenever _STA of an ACPI device goes from 0x0 to 0xf the corresponding physical device (platform, spi, i2c) gets created. Userspace is then notified by a uevent and it then reads attributes including updated modalias of that physical device.

OK, I'll queue this up, then.

Thanks,
Rafael