Skip to contentSkip to conversation

PM: dpm_watchdog: Improve DPM watchdog configurability

PATCH Superseded Tzung-Bi Shih 3 participants 10 messages Jul 1 – Jul 6

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover PM: dpm_watchdog: Improve DPM watchdog configurability

This series improves the configurability of the DPM watchdog.

Currently, the DPM watchdog timeouts are fixed at compile time, and the watchdog is always enabled if compiled in. Also, the module parameters defined in drivers/base/power/main.c use the generic and non-descriptive "main" prefix.

This series addresses these limitations.

Patch 1 renames the module parameter prefix for drivers/base/power/main.c from "main" to "pm_sleep".

Patch 2 introduces the "dpm_watchdog_enabled" module parameter to allow enabling/disabling the watchdog at boot time and runtime. It also adds CONFIG_DPM_WATCHDOG_ENABLED to set default value of the module parameter at compile time.

---
v5:
- Rebase to v7.2-rc1.
- Fix Signed-off-by lines.

v4: https://lore.kernel.org/all/[email protected]
- Address review comments.
- Patch 3 in v3 has applied separately.

v3: https://lore.kernel.org/all/[email protected]
- Address review comments on patch 2.

v2: https://lore.kernel.org/all/[email protected]
- Form a new series.

v1: Doesn't exist.

Tzung-Bi Shih (2):
PM: sleep: Rename module parameters prefix to "pm_sleep"
PM: dpm_watchdog: Allow disabling DPM watchdog by default

 Documentation/admin-guide/kernel-parameters.txt |  7 +++++++
 drivers/base/power/main.c                       | 14 ++++++++++++++
 kernel/power/Kconfig                            | 10 ++++++++++
 3 files changed, 31 insertions(+)
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
#1 lore raw

PATCH v5 1/2 PM: sleep: Rename module parameters prefix to "pm_sleep"

Currently, the module parameters defined in drivers/base/power/main.c use the default prefix "main" (derived from the filename). The prefix is too generic and non-descriptive.

Redefine MODULE_PARAM_PREFIX to "pm_sleep." to group the module parameters under the namespace instead. This makes the parameters more descriptive.

---
v5:
- No changes.

v4: https://lore.kernel.org/all/[email protected]
- "power" -> "pm_sleep".

v3: https://lore.kernel.org/all/[email protected]
- No changes.

v2: https://lore.kernel.org/all/[email protected]
- New to the series.

v1: Doesn't exist.

---
 drivers/base/power/main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/power/main.c +3 -0
index f71467f6ada4..c6a3300cfb7a 100644
@@ -41,6 +41,9 @@
 #include "../base.h"
 #include "power.h"
 
+#undef MODULE_PARAM_PREFIX
+#define MODULE_PARAM_PREFIX "pm_sleep."
+
 typedef int (*pm_callback_t)(struct device *);
 
 /*
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
#5 lore raw

PATCH v5 2/2 PM: dpm_watchdog: Allow disabling DPM watchdog by default

In reply to Tzung-Bi Shih

Introduce the "dpm_watchdog_enabled" module parameter to allow the DPM watchdog to be enabled or disabled at boot time and runtime.

Additionally, introduce the CONFIG_DPM_WATCHDOG_ENABLED Kconfig option to set default value of the module parameter at compile time.

This provides flexibility for systems that want the watchdog code compiled in but inactive by default, allowing it to be enabled only when needed.

---
v5: No changes.

v4: https://lore.kernel.org/all/[email protected]
- Rewrite the commit message to indicate the module parameter is the main change in the patch.
- DPM_WATCHDOG_DEFAULT_ENABLED -> DPM_WATCHDOG_ENABLED.

v3: https://lore.kernel.org/all/[email protected]
- Add "PM" tag (was missing).
- Update the format and specify dependencies in kernel-parameters.txt.
- Update the help message in Kconfig to reflect that dpm_watchdog_enabled can be set at runtime as well.

v2: https://lore.kernel.org/all/[email protected]
- Use module parameter and bool for dpm_watchdog_enabled.
- Use IS_ENABLED().

v1: https://lore.kernel.org/all/[email protected]

---
 Documentation/admin-guide/kernel-parameters.txt |  7 +++++++
 drivers/base/power/main.c                       | 11 +++++++++++
 kernel/power/Kconfig                            | 10 ++++++++++
 3 files changed, 28 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index b5493a7f8f22..46c20e1b5f05 100644
@@ -47,6 +47,7 @@
 	PCI	PCI bus support is enabled.
 	PCIE	PCI Express support is enabled.
 	PCMCIA	The PCMCIA subsystem is enabled.
+	PM	Power Management support is enabled.
 	PNP	Plug & Play support is enabled.
 	PPC	PowerPC architecture is enabled.
 	PPT	Parallel port support is enabled.
@@ -5354,6 +5355,12 @@ Kernel parameters
 	pm_debug_messages	[SUSPEND,KNL]
 			Enable suspend/resume debug messages during boot up.
 
+	pm_sleep.dpm_watchdog_enabled=
+			[PM] Enable or disable the DPM watchdog.  Requires
+			CONFIG_PM_SLEEP and CONFIG_DPM_WATCHDOG enabled.
+			Format: <bool>
+			Default value is set by CONFIG_DPM_WATCHDOG_ENABLED.
+
 	pnp.debug=1	[PNP]
 			Enable PNP debug messages (depends on the
 			CONFIG_PNP_DEBUG_MESSAGES option).  Change at run-time
drivers/base/power/main.c +11 -0
index c6a3300cfb7a..f58945758868 100644
@@ -535,6 +535,11 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
 		 "Backtrace all CPUs on DPM watchdog timeout");
 
+static bool __read_mostly dpm_watchdog_enabled =
+				IS_ENABLED(CONFIG_DPM_WATCHDOG_ENABLED);
+module_param(dpm_watchdog_enabled, bool, 0644);
+MODULE_PARM_DESC(dpm_watchdog_enabled, "Enable DPM watchdog");
+
 static unsigned int __read_mostly dpm_watchdog_timeout = CONFIG_DPM_WATCHDOG_TIMEOUT;
 static unsigned int __read_mostly dpm_watchdog_warning_timeout =
 						CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -630,6 +635,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
 	struct timer_list *timer = &wd->timer;
 
+	if (!dpm_watchdog_enabled)
+		return;
+
 	wd->dev = dev;
 	wd->tsk = current;
 	wd->fatal = dpm_watchdog_timeout == dpm_watchdog_warning_timeout;
@@ -648,6 +656,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
 	struct timer_list *timer = &wd->timer;
 
+	if (!dpm_watchdog_enabled)
+		return;
+
 	timer_delete_sync(timer);
 	timer_destroy_on_stack(timer);
 }
kernel/power/Kconfig +10 -0
index 530c897311d4..508ceabc4d2e 100644
@@ -268,6 +268,16 @@ config DPM_WATCHDOG
 	  captured in pstore device for inspection in subsequent
 	  boot session.
 
+config DPM_WATCHDOG_ENABLED
+	bool "Enable DPM watchdog by default"
+	depends on DPM_WATCHDOG
+	default y
+	help
+	  If you say Y here, the DPM watchdog will be enabled by default.
+	  If you say N, it will be compiled in but disabled.  It can be
+	  enabled at boot time via the "pm_sleep.dpm_watchdog_enabled"
+	  kernel parameter or at runtime via sysfs.
+
 config DPM_WATCHDOG_TIMEOUT
 	int "Watchdog timeout to panic in seconds"
 	range 1 120
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
#2 lore raw

Re: [PATCH v5 1/2] PM: sleep: Rename module parameters prefix to "pm_sleep"

In reply to Tzung-Bi Shih
Quoted 7 lines · Tzung-Bi Shih

Currently, the module parameters defined in drivers/base/power/main.c use the default prefix "main" (derived from the filename). The prefix is too generic and non-descriptive.

Redefine MODULE_PARAM_PREFIX to "pm_sleep." to group the module parameters under the namespace instead. This makes the parameters more descriptive.

You just changed the user/kernel api, right? That will break things...

#6 lore raw

Re: [PATCH v5 2/2] PM: dpm_watchdog: Allow disabling DPM watchdog by default

In reply to Tzung-Bi Shih
Quoted 2 lines · Tzung-Bi Shih

Introduce the "dpm_watchdog_enabled" module parameter to allow the DPM watchdog to be enabled or disabled at boot time and runtime.

As I say all the time, this isn't the 1990's, please don't add new module parameters as they are a pain to manage and maintain over time (as you found out with my rejection of patch 1/2 here...)

Quoted 99 lines

Additionally, introduce the CONFIG_DPM_WATCHDOG_ENABLED Kconfig option to set default value of the module parameter at compile time.

This provides flexibility for systems that want the watchdog code compiled in but inactive by default, allowing it to be enabled only when needed.

---
v5: No changes.

v4: https://lore.kernel.org/all/[email protected]
- Rewrite the commit message to indicate the module parameter is the main change in the patch.
- DPM_WATCHDOG_DEFAULT_ENABLED -> DPM_WATCHDOG_ENABLED.

v3: https://lore.kernel.org/all/[email protected]
- Add "PM" tag (was missing).
- Update the format and specify dependencies in kernel-parameters.txt.
- Update the help message in Kconfig to reflect that dpm_watchdog_enabled can be set at runtime as well.

v2: https://lore.kernel.org/all/[email protected]
- Use module parameter and bool for dpm_watchdog_enabled.
- Use IS_ENABLED().

v1: https://lore.kernel.org/all/[email protected]

---
 Documentation/admin-guide/kernel-parameters.txt |  7 +++++++
 drivers/base/power/main.c                       | 11 +++++++++++
 kernel/power/Kconfig                            | 10 ++++++++++
 3 files changed, 28 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index b5493a7f8f22..46c20e1b5f05 100644
@@ -47,6 +47,7 @@
 	PCI	PCI bus support is enabled.
 	PCIE	PCI Express support is enabled.
 	PCMCIA	The PCMCIA subsystem is enabled.
+	PM	Power Management support is enabled.
 	PNP	Plug & Play support is enabled.
 	PPC	PowerPC architecture is enabled.
 	PPT	Parallel port support is enabled.
@@ -5354,6 +5355,12 @@ Kernel parameters
 	pm_debug_messages	[SUSPEND,KNL]
 			Enable suspend/resume debug messages during boot up.
 
+	pm_sleep.dpm_watchdog_enabled=
+			[PM] Enable or disable the DPM watchdog.  Requires
+			CONFIG_PM_SLEEP and CONFIG_DPM_WATCHDOG enabled.
+			Format: <bool>
+			Default value is set by CONFIG_DPM_WATCHDOG_ENABLED.
+
 	pnp.debug=1	[PNP]
 			Enable PNP debug messages (depends on the
 			CONFIG_PNP_DEBUG_MESSAGES option).  Change at run-time
drivers/base/power/main.c +11 -0
index c6a3300cfb7a..f58945758868 100644
@@ -535,6 +535,11 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
 		 "Backtrace all CPUs on DPM watchdog timeout");
 
+static bool __read_mostly dpm_watchdog_enabled =
+				IS_ENABLED(CONFIG_DPM_WATCHDOG_ENABLED);
+module_param(dpm_watchdog_enabled, bool, 0644);
+MODULE_PARM_DESC(dpm_watchdog_enabled, "Enable DPM watchdog");
+
 static unsigned int __read_mostly dpm_watchdog_timeout = CONFIG_DPM_WATCHDOG_TIMEOUT;
 static unsigned int __read_mostly dpm_watchdog_warning_timeout =
 						CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -630,6 +635,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
 	struct timer_list *timer = &wd->timer;
 
+	if (!dpm_watchdog_enabled)
+		return;
+
 	wd->dev = dev;
 	wd->tsk = current;
 	wd->fatal = dpm_watchdog_timeout == dpm_watchdog_warning_timeout;
@@ -648,6 +656,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
 	struct timer_list *timer = &wd->timer;
 
+	if (!dpm_watchdog_enabled)
+		return;
+
 	timer_delete_sync(timer);
 	timer_destroy_on_stack(timer);
 }
kernel/power/Kconfig +0 -0
index 530c897311d4..508ceabc4d2e 100644

kernel/power/Kconfig config DPM_WATCHDOG · line 274

Quoted 7 lines
kernel/power/Kconfig +4 -0
@@ -268,6 +268,16 @@ config DPM_WATCHDOG
 	  captured in pstore device for inspection in subsequent
 	  boot session.
 
+config DPM_WATCHDOG_ENABLED
+	bool "Enable DPM watchdog by default"
+	depends on DPM_WATCHDOG
+	default y

Only do this if you can not boot without the option enabled, which I do not think is the case here.

thanks,

greg k-h

#3 lore raw

Re: [PATCH v5 1/2] PM: sleep: Rename module parameters prefix to "pm_sleep"

In reply to Greg Kroah-Hartman
Quoted 11 lines · Greg Kroah-Hartman
Quoted 7 lines · Tzung-Bi Shih

Currently, the module parameters defined in drivers/base/power/main.c use the default prefix "main" (derived from the filename). The prefix is too generic and non-descriptive.

Redefine MODULE_PARAM_PREFIX to "pm_sleep." to group the module parameters under the namespace instead. This makes the parameters more descriptive.

You just changed the user/kernel api, right? That will break things...

Or not, if that part of the ABI is not really used or the users of it can live with the change.

This actually is an attempt to correct a mistake in the ABI and only one module parameter is affected by this change (dpm_watchdog_all_cpu_backtrace). I'm not expecting the people using
it to get a particular heartburn about the change. Or if they do,
we'll back off.

I'm now thinking though that using "pm" as the new prefix might be better.

#7 lore raw

Re: [PATCH v5 2/2] PM: dpm_watchdog: Allow disabling DPM watchdog by default

In reply to Greg Kroah-Hartman
Quoted 8 lines · Greg Kroah-Hartman
Quoted 2 lines · Tzung-Bi Shih

Introduce the "dpm_watchdog_enabled" module parameter to allow the DPM watchdog to be enabled or disabled at boot time and runtime.

As I say all the time, this isn't the 1990's, please don't add new module parameters as they are a pain to manage and maintain over time (as you found out with my rejection of patch 1/2 here...)

Let me challenge this though because there are use cases for something like module parameters AFAICS.

There are things that are "on" by default that people want to turn "off" and ideally at init time. If that happens in a loadable module, the only way to do so I'm aware of is using a module parameter.

There are also diagnostic features that are generally "off", but it is useful to turn them "on" occasionally, both at run time and at init time. Adding a special kernel command line option and a separate special sysfs switch (for example) for that is kind of a pain and using a module parameter in such cases appears to be more straightforward to me, so what really is the problem with that?

Moreover, there are those cases in which updating the kernel command line is more straightforward than updating user space to write into a specific file in sysfs after boot, so using a module parameter helps.

So in general, assuming that the underlying use case is good enough, is a module parameter really worse than a combination of a special sysfs file and a special kernel command line argument and if so, then why?

Of course, whether or not the underlying use case is good enough is a different matter.

Quoted 102 lines
Quoted 102 lines

Additionally, introduce the CONFIG_DPM_WATCHDOG_ENABLED Kconfig option to set default value of the module parameter at compile time.

This provides flexibility for systems that want the watchdog code compiled in but inactive by default, allowing it to be enabled only when needed.

---
v5: No changes.

v4: https://lore.kernel.org/all/[email protected]
- Rewrite the commit message to indicate the module parameter is the main change in the patch.
- DPM_WATCHDOG_DEFAULT_ENABLED -> DPM_WATCHDOG_ENABLED.

v3: https://lore.kernel.org/all/[email protected]
- Add "PM" tag (was missing).
- Update the format and specify dependencies in kernel-parameters.txt.
- Update the help message in Kconfig to reflect that dpm_watchdog_enabled can be set at runtime as well.

v2: https://lore.kernel.org/all/[email protected]
- Use module parameter and bool for dpm_watchdog_enabled.
- Use IS_ENABLED().

v1: https://lore.kernel.org/all/[email protected]

---
 Documentation/admin-guide/kernel-parameters.txt |  7 +++++++
 drivers/base/power/main.c                       | 11 +++++++++++
 kernel/power/Kconfig                            | 10 ++++++++++
 3 files changed, 28 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index b5493a7f8f22..46c20e1b5f05 100644
@@ -47,6 +47,7 @@
      PCI     PCI bus support is enabled.
      PCIE    PCI Express support is enabled.
      PCMCIA  The PCMCIA subsystem is enabled.
+     PM      Power Management support is enabled.
      PNP     Plug & Play support is enabled.
      PPC     PowerPC architecture is enabled.
      PPT     Parallel port support is enabled.
@@ -5354,6 +5355,12 @@ Kernel parameters
      pm_debug_messages       [SUSPEND,KNL]
                      Enable suspend/resume debug messages during boot up.
 
+     pm_sleep.dpm_watchdog_enabled=
+                     [PM] Enable or disable the DPM watchdog.  Requires
+                     CONFIG_PM_SLEEP and CONFIG_DPM_WATCHDOG enabled.
+                     Format: <bool>
+                     Default value is set by CONFIG_DPM_WATCHDOG_ENABLED.
+
      pnp.debug=1     [PNP]
                      Enable PNP debug messages (depends on the
                      CONFIG_PNP_DEBUG_MESSAGES option).  Change at run-time
drivers/base/power/main.c +11 -0
index c6a3300cfb7a..f58945758868 100644
@@ -535,6 +535,11 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
               "Backtrace all CPUs on DPM watchdog timeout");
 
+static bool __read_mostly dpm_watchdog_enabled =
+                             IS_ENABLED(CONFIG_DPM_WATCHDOG_ENABLED);
+module_param(dpm_watchdog_enabled, bool, 0644);
+MODULE_PARM_DESC(dpm_watchdog_enabled, "Enable DPM watchdog");
+
 static unsigned int __read_mostly dpm_watchdog_timeout = CONFIG_DPM_WATCHDOG_TIMEOUT;
 static unsigned int __read_mostly dpm_watchdog_warning_timeout =
                                              CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -630,6 +635,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
      struct timer_list *timer = &wd->timer;
 
+     if (!dpm_watchdog_enabled)
+             return;
+
      wd->dev = dev;
      wd->tsk = current;
      wd->fatal = dpm_watchdog_timeout == dpm_watchdog_warning_timeout;
@@ -648,6 +656,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
      struct timer_list *timer = &wd->timer;
 
+     if (!dpm_watchdog_enabled)
+             return;
+
      timer_delete_sync(timer);
      timer_destroy_on_stack(timer);
 }
kernel/power/Kconfig +0 -0
index 530c897311d4..508ceabc4d2e 100644
@@ -268,6 +268,16 @@ config DPM_WATCHDOG
        captured in pstore device for inspection in subsequent
        boot session.
 
Quoted 7 lines

kernel/power/Kconfig config DPM_WATCHDOG · line 274

Quoted 4 lines
kernel/power/Kconfig +4 -0
+config DPM_WATCHDOG_ENABLED
+     bool "Enable DPM watchdog by default"
+     depends on DPM_WATCHDOG
+     default y

Only do this if you can not boot without the option enabled, which I do not think is the case here.

So in this particular case, there is a way to adjust the watchdog timeout and if it is set to a very large value, the watchdog gets effectively disabled for all purposes.

I'm not entirely sure if another switch to disable/enable it is needed in addition to that TBH.

#4 lore raw

Re: [PATCH v5 1/2] PM: sleep: Rename module parameters prefix to "pm_sleep"

In reply to Rafael J. Wysocki (Intel)
Quoted 14 lines · Rafael J. Wysocki (Intel)
Quoted 11 lines · Greg Kroah-Hartman
Quoted 7 lines · Tzung-Bi Shih

Currently, the module parameters defined in drivers/base/power/main.c use the default prefix "main" (derived from the filename). The prefix is too generic and non-descriptive.

Redefine MODULE_PARAM_PREFIX to "pm_sleep." to group the module parameters under the namespace instead. This makes the parameters more descriptive.

You just changed the user/kernel api, right? That will break things...

Quoted 8 lines

Or not, if that part of the ABI is not really used or the users of it can live with the change.

This actually is an attempt to correct a mistake in the ABI and only one module parameter is affected by this change (dpm_watchdog_all_cpu_backtrace). I'm not expecting the people using
it to get a particular heartburn about the change. Or if they do,
we'll back off.

To provide a bit more context (also discussed previously in v3 [1][2]):
The dpm_watchdog_all_cpu_backtrace parameter is relatively new. It was introduced in v6.19 (Oct 2025) via commit a67818f74512 ("PM: dpm_watchdog:
add module param to backtrace all CPUs"). Because of its recent introduction, it shouldn't have many users in the wild yet. The flag was originally introduced for ChromeOS [3], which doesn't actually rely on this module parameter in its production configuration yet [4].

Given the limited known usage, this is likely the best window to correct the prefix before it gains wider adoption.

[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/CAJZ5v0gQTx_k9j2pGha7NKxAjdPS1J_ySZNYiL1=_+_M9znQ_g@mail.gmail.com
[3] https://crrev.com/c/7414781
[4] https://crrev.com/c/7414721

Quoted 2 lines

I'm now thinking though that using "pm" as the new prefix might be better.

Ack, we can change it back to "pm." in the next version.

#8 lore raw

Re: [PATCH v5 2/2] PM: dpm_watchdog: Allow disabling DPM watchdog by default

In reply to Rafael J. Wysocki (Intel)
Quoted 147 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines · Greg Kroah-Hartman
Quoted 2 lines · Tzung-Bi Shih

Introduce the "dpm_watchdog_enabled" module parameter to allow the DPM watchdog to be enabled or disabled at boot time and runtime.

As I say all the time, this isn't the 1990's, please don't add new module parameters as they are a pain to manage and maintain over time (as you found out with my rejection of patch 1/2 here...)

Let me challenge this though because there are use cases for something like module parameters AFAICS.

There are things that are "on" by default that people want to turn "off" and ideally at init time. If that happens in a loadable module, the only way to do so I'm aware of is using a module parameter.

There are also diagnostic features that are generally "off", but it is useful to turn them "on" occasionally, both at run time and at init time. Adding a special kernel command line option and a separate special sysfs switch (for example) for that is kind of a pain and using a module parameter in such cases appears to be more straightforward to me, so what really is the problem with that?

Moreover, there are those cases in which updating the kernel command line is more straightforward than updating user space to write into a specific file in sysfs after boot, so using a module parameter helps.

So in general, assuming that the underlying use case is good enough, is a module parameter really worse than a combination of a special sysfs file and a special kernel command line argument and if so, then why?

Of course, whether or not the underlying use case is good enough is a different matter.

Quoted 102 lines
Quoted 102 lines

Additionally, introduce the CONFIG_DPM_WATCHDOG_ENABLED Kconfig option to set default value of the module parameter at compile time.

This provides flexibility for systems that want the watchdog code compiled in but inactive by default, allowing it to be enabled only when needed.

---
v5: No changes.

v4: https://lore.kernel.org/all/[email protected]
- Rewrite the commit message to indicate the module parameter is the main change in the patch.
- DPM_WATCHDOG_DEFAULT_ENABLED -> DPM_WATCHDOG_ENABLED.

v3: https://lore.kernel.org/all/[email protected]
- Add "PM" tag (was missing).
- Update the format and specify dependencies in kernel-parameters.txt.
- Update the help message in Kconfig to reflect that dpm_watchdog_enabled can be set at runtime as well.

v2: https://lore.kernel.org/all/[email protected]
- Use module parameter and bool for dpm_watchdog_enabled.
- Use IS_ENABLED().

v1: https://lore.kernel.org/all/[email protected]

---
 Documentation/admin-guide/kernel-parameters.txt |  7 +++++++
 drivers/base/power/main.c                       | 11 +++++++++++
 kernel/power/Kconfig                            | 10 ++++++++++
 3 files changed, 28 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index b5493a7f8f22..46c20e1b5f05 100644
@@ -47,6 +47,7 @@
      PCI     PCI bus support is enabled.
      PCIE    PCI Express support is enabled.
      PCMCIA  The PCMCIA subsystem is enabled.
+     PM      Power Management support is enabled.
      PNP     Plug & Play support is enabled.
      PPC     PowerPC architecture is enabled.
      PPT     Parallel port support is enabled.
@@ -5354,6 +5355,12 @@ Kernel parameters
      pm_debug_messages       [SUSPEND,KNL]
                      Enable suspend/resume debug messages during boot up.
 
+     pm_sleep.dpm_watchdog_enabled=
+                     [PM] Enable or disable the DPM watchdog.  Requires
+                     CONFIG_PM_SLEEP and CONFIG_DPM_WATCHDOG enabled.
+                     Format: <bool>
+                     Default value is set by CONFIG_DPM_WATCHDOG_ENABLED.
+
      pnp.debug=1     [PNP]
                      Enable PNP debug messages (depends on the
                      CONFIG_PNP_DEBUG_MESSAGES option).  Change at run-time
drivers/base/power/main.c +11 -0
index c6a3300cfb7a..f58945758868 100644
@@ -535,6 +535,11 @@ module_param(dpm_watchdog_all_cpu_backtrace, bool, 0644);
 MODULE_PARM_DESC(dpm_watchdog_all_cpu_backtrace,
               "Backtrace all CPUs on DPM watchdog timeout");
 
+static bool __read_mostly dpm_watchdog_enabled =
+                             IS_ENABLED(CONFIG_DPM_WATCHDOG_ENABLED);
+module_param(dpm_watchdog_enabled, bool, 0644);
+MODULE_PARM_DESC(dpm_watchdog_enabled, "Enable DPM watchdog");
+
 static unsigned int __read_mostly dpm_watchdog_timeout = CONFIG_DPM_WATCHDOG_TIMEOUT;
 static unsigned int __read_mostly dpm_watchdog_warning_timeout =
                                              CONFIG_DPM_WATCHDOG_WARNING_TIMEOUT;
@@ -630,6 +635,9 @@ static void dpm_watchdog_set(struct dpm_watchdog *wd, struct device *dev)
 {
      struct timer_list *timer = &wd->timer;
 
+     if (!dpm_watchdog_enabled)
+             return;
+
      wd->dev = dev;
      wd->tsk = current;
      wd->fatal = dpm_watchdog_timeout == dpm_watchdog_warning_timeout;
@@ -648,6 +656,9 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
 {
      struct timer_list *timer = &wd->timer;
 
+     if (!dpm_watchdog_enabled)
+             return;
+
      timer_delete_sync(timer);
      timer_destroy_on_stack(timer);
 }
kernel/power/Kconfig +0 -0
index 530c897311d4..508ceabc4d2e 100644
@@ -268,6 +268,16 @@ config DPM_WATCHDOG
        captured in pstore device for inspection in subsequent
        boot session.
 
Quoted 7 lines

kernel/power/Kconfig config DPM_WATCHDOG · line 274

Quoted 4 lines
kernel/power/Kconfig +4 -0
+config DPM_WATCHDOG_ENABLED
+     bool "Enable DPM watchdog by default"
+     depends on DPM_WATCHDOG
+     default y

Only do this if you can not boot without the option enabled, which I do not think is the case here.

Quoted 6 lines

So in this particular case, there is a way to adjust the watchdog timeout and if it is set to a very large value, the watchdog gets effectively disabled for all purposes.

I'm not entirely sure if another switch to disable/enable it is needed in addition to that TBH.

They are still different. Setting a very large timeout effectively delays the timeout, but doesn't disable the DPM watchdog.

For devices that are unaware of the watchdog, a long suspend/resume cycle might still eventually reach that large timeout and trigger unexpectedly.

More importantly, the timeout currently has a strict upper bound of 120 seconds. Setting it to a "very large value" is infeasible without changing the Kconfig:

        config DPM_WATCHDOG_TIMEOUT
                int "Watchdog timeout to panic in seconds"
                range 1 120
                default 120

To provide a bit more context on our use case:
Our primary intent here revolves around Android GKI (Generic Kernel Image). We want to enable CONFIG_DPM_WATCHDOG in the GKI so the feature is available. However, because the GKI is shared across many different devices, we don't want to affect devices that are unaware of this feature. We need a way to compile it in, but keep it disabled by default for those devices.

#9 lore raw

Re: [PATCH v5 2/2] PM: dpm_watchdog: Allow disabling DPM watchdog by default

In reply to Greg Kroah-Hartman
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Tzung-Bi Shih
kernel/power/Kconfig +0 -0
index 530c897311d4..508ceabc4d2e 100644
@@ -268,6 +268,16 @@ config DPM_WATCHDOG
 	  captured in pstore device for inspection in subsequent
 	  boot session.
 
Quoted 7 lines

kernel/power/Kconfig config DPM_WATCHDOG · line 274

Quoted 4 lines
kernel/power/Kconfig +4 -0
+config DPM_WATCHDOG_ENABLED
+	bool "Enable DPM watchdog by default"
+	depends on DPM_WATCHDOG
+	default y

Only do this if you can not boot without the option enabled, which I do not think is the case here.

I assume you are referring to the default y?

The reason for adding default y here is to maintain backward compatibility. Previously, the DPM watchdog was always active if CONFIG_DPM_WATCHDOG was set. By defaulting this new option to 'y', we ensure that the behavior remains unchanged for existing users and defconfigs when they upgrade.

At the same time, this new option provides the flexibility for systems (like Android GKI) that want to compile the watchdog code in, but keep it disabled by default.