Skip to contentSkip to conversation

device core: Add flag to autoremove device link on supplier unbind

PATCH In review Vivek Gautam 3 participants 6 messages May 30, 2018 – Jun 26, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device core: Add flag to autoremove device link on supplier unbind

When using the device links without the consumers or suppliers maintaining pointers to these links, a flag can help in autoremoving the links on supplier driver unbind. We remove these links only when the supplier's link to its consumers has gone in DL_STATE_SUPPLIER_UNBIND state.

---

Lukas, as suggested in the thread [1] this change adds additional flag to autoremove device links on supplier unbind.
For arm-smmu, we want to _not_ keep references to the device links added between arm-smmu, and consumer devices.
Robin also pointed to [2] the need to autoremove the device link on supplier unbind rather than consumer unbind.

[1] https://lkml.org/lkml/2018/3/14/390
[2] https://lkml.org/lkml/2018/5/21/381

 drivers/base/core.c    | 10 ++++++++++
 include/linux/device.h |  2 ++
 2 files changed, 12 insertions(+)
drivers/base/core.c +10 -0
index b610816eb887..52c7222bb3c4 100644
@@ -490,6 +490,16 @@ void device_links_driver_cleanup(struct device *dev)
 
 		WARN_ON(link->flags & DL_FLAG_AUTOREMOVE);
 		WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
+
+		/*
+		 * autoremove the links between this @dev and its consumer
+		 * devices that are not active, i.e. where the link state
+		 * has moved to DL_STATE_SUPPLIER_UNBIND.
+		 */
+		if (link->status == DL_STATE_SUPPLIER_UNBIND &&
+		    link->flags & DL_FLAG_AUTOREMOVE_S)
+			kref_put(&link->kref, __device_link_del);
+
 		WRITE_ONCE(link->status, DL_STATE_DORMANT);
 	}
 
include/linux/device.h +2 -0
index 477956990f5e..6033bf58453d 100644
@@ -779,11 +779,13 @@ enum device_link_state {
  * AUTOREMOVE: Remove this link automatically on consumer driver unbind.
  * PM_RUNTIME: If set, the runtime PM framework will use this link.
  * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation.
+ * AUTOREMOVE_S: Remove this link automatically on supplier driver unbind.
  */
 #define DL_FLAG_STATELESS	BIT(0)
 #define DL_FLAG_AUTOREMOVE	BIT(1)
 #define DL_FLAG_PM_RUNTIME	BIT(2)
 #define DL_FLAG_RPM_ACTIVE	BIT(3)
+#define DL_FLAG_AUTOREMOVE_S	BIT(4)
 
 /**
  * struct device_link - Device link representation.
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw
Quoted 8 lines · Vivek Gautam

When using the device links without the consumers or suppliers maintaining pointers to these links, a flag can help in autoremoving the links on supplier driver unbind. We remove these links only when the supplier's link to its consumers has gone in DL_STATE_SUPPLIER_UNBIND state.

Quoted 8 lines

---

Lukas, as suggested in the thread [1] this change adds additional flag to autoremove device links on supplier unbind.
For arm-smmu, we want to _not_ keep references to the device links added between arm-smmu, and consumer devices.
Robin also pointed to [2] the need to autoremove the device link on supplier unbind rather than consumer unbind.

Please CC device links patches to linux-pm.

Quoted 33 lines

[1] https://lkml.org/lkml/2018/3/14/390
[2] https://lkml.org/lkml/2018/5/21/381

  drivers/base/core.c    | 10 ++++++++++
  include/linux/device.h |  2 ++
  2 files changed, 12 insertions(+)
drivers/base/core.c +10 -0
index b610816eb887..52c7222bb3c4 100644
@@ -490,6 +490,16 @@ void device_links_driver_cleanup(struct device *dev)
 
  		WARN_ON(link->flags & DL_FLAG_AUTOREMOVE);
  		WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
+
+		/*
+		 * autoremove the links between this @dev and its consumer
+		 * devices that are not active, i.e. where the link state
+		 * has moved to DL_STATE_SUPPLIER_UNBIND.
+		 */
+		if (link->status == DL_STATE_SUPPLIER_UNBIND &&
+		    link->flags & DL_FLAG_AUTOREMOVE_S)
+			kref_put(&link->kref, __device_link_del);
+
  		WRITE_ONCE(link->status, DL_STATE_DORMANT);
  	}
 
include/linux/device.h +0 -0
index 477956990f5e..6033bf58453d 100644

include/linux/device.h enum device_link_state { · line 788

Quoted 10 lines
include/linux/device.h +2 -0
@@ -779,11 +779,13 @@ enum device_link_state {
   * AUTOREMOVE: Remove this link automatically on consumer driver unbind.
   * PM_RUNTIME: If set, the runtime PM framework will use this link.
   * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation.
+ * AUTOREMOVE_S: Remove this link automatically on supplier driver unbind.
   */
  #define DL_FLAG_STATELESS	BIT(0)
  #define DL_FLAG_AUTOREMOVE	BIT(1)
  #define DL_FLAG_PM_RUNTIME	BIT(2)
  #define DL_FLAG_RPM_ACTIVE	BIT(3)
+#define DL_FLAG_AUTOREMOVE_S	BIT(4)

Couldn't you invent a better name for this one?

Quoted 3 lines
include/linux/device.h +0 -0
  /**
   * struct device_link - Device link representation.
#2 lore raw

Hi Rafael,

Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Vivek Gautam

When using the device links without the consumers or suppliers maintaining pointers to these links, a flag can help in autoremoving the links on supplier driver unbind. We remove these links only when the supplier's link to its consumers has gone in DL_STATE_SUPPLIER_UNBIND state.

---

Quoted 8 lines
Quoted 6 lines

Lukas, as suggested in the thread [1] this change adds additional flag to autoremove device links on supplier unbind.
For arm-smmu, we want to _not_ keep references to the device links added between arm-smmu, and consumer devices.
Robin also pointed to [2] the need to autoremove the device link on supplier unbind rather than consumer unbind.

Please CC device links patches to linux-pm.

Thanks for the quick review. Sure, will keep this noted from now on.

Quoted 38 lines
Quoted 38 lines

[1] https://lkml.org/lkml/2018/3/14/390
[2] https://lkml.org/lkml/2018/5/21/381

  drivers/base/core.c    | 10 ++++++++++
  include/linux/device.h |  2 ++

  2 files changed, 12 insertions(+)
drivers/base/core.c +10 -0
index b610816eb887..52c7222bb3c4 100644
@@ -490,6 +490,16 @@ void device_links_driver_cleanup(struct device 
 *dev)
             WARN_ON(link->flags & DL_FLAG_AUTOREMOVE);
           WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
+
+        /*
+         * autoremove the links between this @dev and its consumer
+         * devices that are not active, i.e. where the link state
+         * has moved to DL_STATE_SUPPLIER_UNBIND.
+         */
+        if (link->status == DL_STATE_SUPPLIER_UNBIND &&
+            link->flags & DL_FLAG_AUTOREMOVE_S)
+            kref_put(&link->kref, __device_link_del);
+
           WRITE_ONCE(link->status, DL_STATE_DORMANT);
       }

  diff --git a/include/linux/device.h b/include/linux/device.h index 477956990f5e..6033bf58453d 100644

include/linux/device.h +1 -0
@@ -779,11 +779,13 @@ enum device_link_state {
    * AUTOREMOVE: Remove this link automatically on consumer driver unbind.
    * PM_RUNTIME: If set, the runtime PM framework will use this link.
    * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation.
+ * AUTOREMOVE_S: Remove this link automatically on supplier driver 

unbind.

Quoted 8 lines
Quoted 6 lines

   */
  #define DL_FLAG_STATELESS    BIT(0)
  #define DL_FLAG_AUTOREMOVE    BIT(1)
  #define DL_FLAG_PM_RUNTIME    BIT(2)
  #define DL_FLAG_RPM_ACTIVE    BIT(3)
+#define DL_FLAG_AUTOREMOVE_S    BIT(4)

Couldn't you invent a better name for this one?

Frankly, I wanted to have something like DL_FLAG_AUTOREMOVE_SUPPLIER, but that felt a bit too long considering other flags.
Can you please consider suggesting a concise name?

Regards
Vivek

Quoted 5 lines
Quoted 3 lines

    /**
   * struct device_link - Device link representation.

#3 lore raw

On Wed, May 30, 2018 at 6:21 PM, Vivek Gautam
<[email protected]> wrote:

Adding Ulf and Marek for their side of comments.
In summary, we do not want to not maintain a device link pointer when adding a device link in supplier's driver, to delete the link later. An autoremove flag from the suppliers side (similar to what we already have for consumer side) can help autoremove the device link when supplier driver goes away.

Hi Rafael, Lukas,
Gentle ping. Can you please consider reviewing this patch.

Best regards
Vivek

Quoted 96 lines

Hi Rafael,

Quoted 21 lines · Rafael J. Wysocki
Quoted 9 lines · Vivek Gautam

When using the device links without the consumers or suppliers maintaining pointers to these links, a flag can help in autoremoving the links on supplier driver unbind. We remove these links only when the supplier's link to its consumers has gone in DL_STATE_SUPPLIER_UNBIND state.

Quoted 8 lines

---

Lukas, as suggested in the thread [1] this change adds additional flag to autoremove device links on supplier unbind.
For arm-smmu, we want to _not_ keep references to the device links added between arm-smmu, and consumer devices.
Robin also pointed to [2] the need to autoremove the device link on supplier unbind rather than consumer unbind.

Quoted 1 line

Please CC device links patches to linux-pm.

Thanks for the quick review. Sure, will keep this noted from now on.

Quoted 40 lines
Quoted 40 lines

[1] https://lkml.org/lkml/2018/3/14/390
[2] https://lkml.org/lkml/2018/5/21/381

  drivers/base/core.c    | 10 ++++++++++
  include/linux/device.h |  2 ++
  2 files changed, 12 insertions(+)
drivers/base/core.c +10 -0
index b610816eb887..52c7222bb3c4 100644
@@ -490,6 +490,16 @@ void device_links_driver_cleanup(struct device *dev)
            WARN_ON(link->flags & DL_FLAG_AUTOREMOVE);
          WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
+
+        /*
+         * autoremove the links between this @dev and its consumer
+         * devices that are not active, i.e. where the link state
+         * has moved to DL_STATE_SUPPLIER_UNBIND.
+         */
+        if (link->status == DL_STATE_SUPPLIER_UNBIND &&
+            link->flags & DL_FLAG_AUTOREMOVE_S)
+            kref_put(&link->kref, __device_link_del);
+
          WRITE_ONCE(link->status, DL_STATE_DORMANT);
      }
  diff --git a/include/linux/device.h b/include/linux/device.h

index 477956990f5e..6033bf58453d 100644

include/linux/device.h +0 -0
@@ -779,11 +779,13 @@ enum device_link_state {
   * AUTOREMOVE: Remove this link automatically on consumer driver

unbind.
* PM_RUNTIME: If set, the runtime PM framework will use this link.
* RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link
creation.
+ * AUTOREMOVE_S: Remove this link automatically on supplier driver unbind.
*/

Quoted 8 lines
Quoted 5 lines

#define DL_FLAG_STATELESS BIT(0)

  #define DL_FLAG_AUTOREMOVE    BIT(1)
  #define DL_FLAG_PM_RUNTIME    BIT(2)
  #define DL_FLAG_RPM_ACTIVE    BIT(3)

+#define DL_FLAG_AUTOREMOVE_S BIT(4)

Couldn't you invent a better name for this one?

Frankly, I wanted to have something like DL_FLAG_AUTOREMOVE_SUPPLIER, but that
felt a bit too long considering other flags.
Can you please consider suggesting a concise name?

Regards
Vivek

Quoted 6 lines
Quoted 3 lines
    /**

* struct device_link - Device link representation.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#4 lore raw
Quoted 10 lines · CEST Vivek Gautam

On Wed, May 30, 2018 at 6:21 PM, Vivek Gautam
<[email protected]> wrote:

Adding Ulf and Marek for their side of comments.
In summary, we do not want to not maintain a device link pointer when adding a device link in supplier's driver, to delete the link later. An autoremove flag from the suppliers side (similar to what we already have for consumer side) can help autoremove the device link when supplier driver goes away.

Quoted 2 lines

Hi Rafael, Lukas,
Gentle ping. Can you please consider reviewing this patch.

ISTR telling you that I didn't like the DL_FLAG_AUTOREMOVE_S name as it is too similar to another existing flag. That hasn't changed.

BTW, please CC the patch to linux-pm when you resend it.

Thanks,
Rafael

#5 lore raw

Hi Rafael,

Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · CEST Vivek Gautam

On Wed, May 30, 2018 at 6:21 PM, Vivek Gautam
<[email protected]> wrote:

Adding Ulf and Marek for their side of comments.
In summary, we do not want to not maintain a device link pointer when adding a device link in supplier's driver, to delete the link later. An autoremove flag from the suppliers side (similar to what we already have for consumer side) can help autoremove the device link when supplier driver goes away.

Quoted 5 lines
Quoted 2 lines

Hi Rafael, Lukas,
Gentle ping. Can you please consider reviewing this patch.

ISTR telling you that I didn't like the DL_FLAG_AUTOREMOVE_S name as it is too similar to another existing flag. That hasn't changed.

Right. I thought to gather more comments about the patch overall before attempting to respin with the changed name.
I will send the next version.

Quoted 2 lines

BTW, please CC the patch to linux-pm when you resend it.

Sure. I will do that. Thanks.

Best regards
Vivek

Quoted 4 lines

Thanks,
Rafael

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation