Add driver for PAPR watchdog timers
Subsystems (2)
v2 cover Add driver for PAPR watchdog timers
This second RFC incorporates feedback from the previous RFC:
https://lore.kernel.org/linux-watchdog/[email protected]/
v2 changes of note:
- Add a firmware feature flag for the H_WATCHDOG feature, FW_FEATURE_WATCHDOG.
- Register a platform_device for the first watchdog timer during a pseries initcall if we have FW_FEATURE_WATCHDOG. Use id zero, as there could be more than one timer in the future.
- Alphabetize Makefile changes.
- Add missing copyright information to pseries-wdt.c.
- Add an 'action' module parameter that configures how the guest is terminated on watchdog expiration.
- Use dev_*() for logging critical errors instead of pr_*().
- Handle the H_NOOP case when trying to stop the watchdog. If the given watchdog is not actually running, H_WATCHDOG returns H_NOOP. This is harmless, so we should treat it as a success.
- We don't need pseries_wdt_remove() at all.
- Check watchdog_active() before stopping/starting the timer across suspend/resume.
- Consolidate all code from pseries_wdt_module_init() into pseries_wdt_probe(). We can then use module_platform_driver().
I have one lingering question:
- The pseries-wdt module is not "automatically" loaded during boot.
When I do
# modprobe pseries-wdt
the driver attaches to the platform bus as expected and the /dev/watchdog* devices for the pseries-wdt.0 platform device are created.
I was under the impression that driver/device matching for the platform bus was simple string comparison.
... what am I doing wrong? Is this expected behavior? Do I need to do additional configuration to get the module to load automatically at boot time?
RFC v2 1/2 powerpc/pseries: hvcall.h: add H_WATCHDOG opcode, H_NOOP return code
PAPR v2.12 defines a new hypercall, H_WATCHDOG. The hypercall permits guest control of one or more virtual watchdog timers.
This patch adds the opcode for the H_WATCHDOG hypercall. It also defines H_NOOP, a possible return code for H_WATCHDOG.
--- arch/powerpc/include/asm/hvcall.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/hvcall.h +3 -1
@@ -87,6 +87,7 @@#define H_P7 -60#define H_P8 -61#define H_P9 -62 +#define H_NOOP -63#define H_TOO_BIG -64#define H_UNSUPPORTED -67#define H_OVERLAP -68
@@ -324,7 +325,8 @@#define H_RPT_INVALIDATE 0x448#define H_SCM_FLUSH 0x44C#define H_GET_ENERGY_SCALE_INFO 0x450 -#define MAX_HCALL_OPCODE H_GET_ENERGY_SCALE_INFO +#define H_WATCHDOG 0x45C +#define MAX_HCALL_OPCODE H_WATCHDOG/* Scope args for H_SCM_UNBIND_ALL */ #define H_UNBIND_SCOPE_ALL (0x1)
Signature · 1 line
2.27.0
RFC v2 2/2 watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
In reply to Scott ChelohaPAPR v2.12 defines a new hypercall, H_WATCHDOG. It permits guest control of one or more virtual watchdog timers. The timers have millisecond granularity and terminate the guest upon expiration.
This patch adds a new driver for these timers, "pseries-wdt".
Unfortunately, these timers defy PowerPC device conventions. They are not affixed to any bus, nor do they have full representation in the device tree. As a workaround, we represent them as platform devices. A platform device corresponding to a given timer is registered with the platform bus via a machine_subsys_initcall() if firmware support for the H_WATCHDOG hypercall is detected early in boot.
For now, only a single timer is registered with the platform bus and exposed to userspace. In the future we could expose additional timers if there is good reason to do so.
--- arch/powerpc/include/asm/firmware.h | 3 +- arch/powerpc/platforms/pseries/firmware.c | 1 + arch/powerpc/platforms/pseries/setup.c | 17 ++ drivers/watchdog/Kconfig | 8 + drivers/watchdog/Makefile | 1 + drivers/watchdog/pseries-wdt.c | 300 ++++++++++++++++++++++ 6 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 drivers/watchdog/pseries-wdt.c
arch/powerpc/include/asm/firmware.h +2 -1
@@ -55,6 +55,7 @@#define FW_FEATURE_RPT_INVALIDATE ASM_CONST(0x0000010000000000)#define FW_FEATURE_FORM2_AFFINITY ASM_CONST(0x0000020000000000)#define FW_FEATURE_ENERGY_SCALE_INFO ASM_CONST(0x0000040000000000) +#define FW_FEATURE_WATCHDOG ASM_CONST(0x0000080000000000)#ifndef __ASSEMBLY__
@@ -76,7 +77,7 @@ enum {FW_FEATURE_DRC_INFO |FW_FEATURE_BLOCK_REMOVE |FW_FEATURE_PAPR_SCM |FW_FEATURE_ULTRAVISOR |FW_FEATURE_RPT_INVALIDATE |FW_FEATURE_FORM2_AFFINITY | -FW_FEATURE_ENERGY_SCALE_INFO , +FW_FEATURE_ENERGY_SCALE_INFO |FW_FEATURE_WATCHDOG ,FW_FEATURE_PSERIES_ALWAYS =0 ,FW_FEATURE_POWERNV_POSSIBLE =FW_FEATURE_OPAL |FW_FEATURE_ULTRAVISOR , FW_FEATURE_POWERNV_ALWAYS = 0,
arch/powerpc/platforms/pseries/firmware.c +1 -0
@@ -67,6 +67,7 @@ hypertas_fw_features_table[] = { {FW_FEATURE_PAPR_SCM, "hcall-scm"}, {FW_FEATURE_RPT_INVALIDATE, "hcall-rpt-invalidate"}, {FW_FEATURE_ENERGY_SCALE_INFO, "hcall-energy-scale-info"}, + {FW_FEATURE_WATCHDOG, "hcall-watchdog"}, };/* Build up the firmware features bitmask using the contents of
arch/powerpc/platforms/pseries/setup.c +17 -0
@@ -14,6 +14,7 @@#include <linux/cpu.h> #include <linux/errno.h> +#include <linux/platform_device.h> #include <linux/sched.h> #include <linux/kernel.h> #include <linux/mm.h>
@@ -169,6 +170,22 @@ static void __init fwnmi_init(void)#endif } +/* +* Affix a device for the first timer to the platform bus if +* we have firmware support for the H_WATCHDOG hypercall. +*/ +static struct platform_device *pseries_wdt_pdev; + +static __init int pseries_wdt_init (void ) +{ +if (!firmware_has_feature (FW_FEATURE_WATCHDOG )) +return 0 ; + pseries_wdt_pdev =platform_device_register_simple ("pseries-wdt" , +0 ,NULL ,0 ); +return 0 ; +} +machine_subsys_initcall (pseries, pseries_wdt_init); +static void pseries_8259_cascade (struct irq_desc *desc) {struct irq_chip *chip =irq_desc_get_chip (desc);
drivers/watchdog/Kconfig +8 -0
@@ -1932,6 +1932,14 @@ config MEN_A21_WDT # PPC64 Architecture +config PSERIES_WDT + tristate "POWER Architecture Platform Watchdog Timer" + depends on PPC_PSERIES + select WATCHDOG_CORE + help + Driver for virtual watchdog timers provided by PAPR + hypervisors (e.g. pHyp, KVM). + config WATCHDOG_RTAS tristate "RTAS watchdog" depends on PPC_RTAS
drivers/watchdog/Makefile +1 -0
@@ -184,6 +184,7 @@ obj-$(CONFIG_BOOKE_WDT) += booke_wdt.o obj-$(CONFIG_MEN_A21_WDT) += mena21_wdt.o # PPC64 Architecture +obj-$(CONFIG_PSERIES_WDT) += pseries-wdt.o obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o # S390 Architecture
drivers/watchdog/pseries-wdt.c new file +300 -0
300 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
drivers/watchdog/pseries-wdt.c line 25
Quoted 4 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))
From ./scripts/checkpatch.pl --strict:
WARNING: please, no spaces at the start of a line
Quoted 1 line
+#define
PSERIES_WDTQL_MUST_STOP1
From ./scripts/checkpatch.pl --strict:
WARNING: please, no space before tabs
drivers/watchdog/pseries-wdt.c line 160
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );
From ./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
The line exceeds 100 columns.
drivers/watchdog/pseries-wdt.c line 164
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO );
From ./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
Quoted 1 line
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT)")");
From ./scripts/checkpatch.pl --strict, the line exceeds 100 columns.
drivers/watchdog/pseries-wdt.c line 169
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+#define WATCHDOG_TIMEOUT 60 +static unsigned int timeout =WATCHDOG_TIMEOUT ; +module_param (timeout, uint,S_IRUGO );
From ./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
Quoted 1 line
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds (default="
__MODULE_STRING(WATCHDOG_TIMEOUT)")");
From ./scripts/checkpatch.pl --strict, the line exceeds 100 columns.
drivers/watchdog/pseries-wdt.c line 174
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+struct pseries_wdt { +struct watchdog_device wd; +unsigned long num;/* NB: Watchdog numbers are 1-based */
What does NB stand for? Could it be removed from the comment?
Does timer_id or some other equivalent names make more sense for the variable?
Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_start(struct watchdog_device *wdd) +{
[...]
drivers/watchdog/pseries-wdt.c line 190
Quoted 5 lines
drivers/watchdog/pseries-wdt.c new file +5
-0+ rc =plpar_hcall_norets (H_WATCHDOG , flags, pw->num, msecs); +if (rc !=H_SUCCESS ) { +dev_crit (dev,"H_WATCHDOG: %ld: failed to start timer %lu" , + rc, pw->num); +return -EIO ;
From ./scripts/checkpatch.pl --strict:
ERROR: code indent should use tabs where possible
WARNING: please, no space before tabs
drivers/watchdog/pseries-wdt.c line 213
Quoted 4 lines
drivers/watchdog/pseries-wdt.c new file +4
-0+static struct watchdog_info pseries_wdt_info = { + .identity =DRV_NAME , + .options =WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE |WDIOF_SETTIMEOUT \ + |WDIOF_PRETIMEOUT ,
From ./scripts/checkpatch.pl --strict:
WARNING: Avoid unnecessary line continuations
drivers/watchdog/pseries-wdt.c line 218
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+static const struct watchdog_ops pseries_wdt_ops = { + .owner =THIS_MODULE , + .ping = pseries_wdt_start,
Does this mean: it needs hard restart for every ping?
Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_probe(struct platform_device *pdev) +{
[...]
drivers/watchdog/pseries-wdt.c line 233
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+ rc =plpar_hcall (H_WATCHDOG , ret,PSERIES_WDTF_OP_QUERY ); +if (rc !=H_SUCCESS ) +return (rc ==H_FUNCTION ) ? -ENODEV : -EIO ;
The parentheses can be dropped.
drivers/watchdog/pseries-wdt.c line 244
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+ pw =devm_kzalloc (&pdev->dev,sizeof *pw,GFP_KERNEL ); +if (pw ==NULL )
From ./scripts/checkpatch.pl --strict:
CHECK: Comparison to NULL could be written "!pw"
drivers/watchdog/pseries-wdt.c line 246
Quoted 1 line
drivers/watchdog/pseries-wdt.c new file +1
-0+ pw->num = pdev->id +1 ;/* 0-based -> 1-based */
Didn't see where the platform device was registered but using the pdev->id as the timer id could be unreliable (e.g. from auto increment).
Guenter Roeck
maintainerRe: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
Quoted 46 lines · Tzung-Bi Shih
Quoted 6 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:WARNING: please, no spaces at the start of a line
Quoted 3 lines
+#define
PSERIES_WDTQL_MUST_STOP1From
./scripts/checkpatch.pl --strict:WARNING: please, no space before tabs
Quoted 4 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
The line exceeds 100 columns.
Quoted 4 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 9 lines
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT)")");From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c new file +3
-0+#define WATCHDOG_TIMEOUT 60 +static unsigned int timeout =WATCHDOG_TIMEOUT ; +module_param (timeout, uint,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds (default="
__MODULE_STRING(WATCHDOG_TIMEOUT)")");
Quoted 8 lines
drivers/watchdog/pseries-wdt.c line 174
Quoted 5 lines
From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c new file +3
-0+struct pseries_wdt { +struct watchdog_device wd; +unsigned long num;/* NB: Watchdog numbers are 1-based */ What does NB stand for? Could it be removed from the comment?
Latin "Nota Bene", for "This is important".
All comments should be important, so I agree, this has little if any value.
Quoted 21 lines
Does
timer_idor some other equivalent names make more sense for the variable?Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_start(struct watchdog_device *wdd) +{[...]
Quoted 7 lines
drivers/watchdog/pseries-wdt.c new file +5
-0+ rc =plpar_hcall_norets (H_WATCHDOG , flags, pw->num, msecs); +if (rc !=H_SUCCESS ) { +dev_crit (dev,"H_WATCHDOG: %ld: failed to start timer %lu" , + rc, pw->num); +return -EIO ;From
./scripts/checkpatch.pl --strict:ERROR: code indent should use tabs where possible
WARNING: please, no space before tabsQuoted 4 lines
drivers/watchdog/pseries-wdt.c new file +4
-0+static struct watchdog_info pseries_wdt_info = { + .identity =DRV_NAME , + .options =WDIOF_KEEPALIVEPING |WDIOF_MAGICCLOSE |WDIOF_SETTIMEOUT \ + |WDIOF_PRETIMEOUT ,
Quoted 9 lines
Quoted 1 line
From
./scripts/checkpatch.pl --strict:WARNING: Avoid unnecessary line continuations
drivers/watchdog/pseries-wdt.c line 218
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+static const struct watchdog_ops pseries_wdt_ops = { + .owner =THIS_MODULE , + .ping = pseries_wdt_start,Does this mean: it needs hard restart for every ping?
If there is no separate ping function, there is no need to point the ping function to the start function. The watchdog core uses the start function automatically in this case.
Quoted 12 lines
Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_probe(struct platform_device *pdev) +{[...]
drivers/watchdog/pseries-wdt.c line 233
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+ rc =plpar_hcall (H_WATCHDOG , ret,PSERIES_WDTF_OP_QUERY ); +if (rc !=H_SUCCESS ) +return (rc ==H_FUNCTION ) ? -ENODEV : -EIO ;The parentheses can be dropped.
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+ pw =devm_kzalloc (&pdev->dev,sizeof *pw,GFP_KERNEL ); +if (pw ==NULL )
Quoted 7 lines
Quoted 1 line
From
./scripts/checkpatch.pl --strict:CHECK: Comparison to NULL could be written "!pw"
drivers/watchdog/pseries-wdt.c line 246
Quoted 1 line
drivers/watchdog/pseries-wdt.c new file +1
-0+ pw->num = pdev->id +1 ;/* 0-based -> 1-based */ Didn't see where the platform device was registered but using the
pdev->idas the timer id could be unreliable (e.g. from auto increment).
That is at the beginning of the patch, in arch/powerpc/platforms/pseries/setup.c, which calls platform_device_register_simple() with an explicit device ID.
I agree, though, that it is fragile: The code in the probe function explicitly checks for a negative ID, which would only be provided if platform_device_register() explicitly declares that (ie if it provides PLATFORM_DEVID_NONE as device ID). But if that is a concern, there might as well be code registering a platform device with PLATFORM_DEVID_AUTO as device ID, and then th device id would be automatic and more or less random. I think the instantiation code should be more
explicit: Either assume that PLATFORM_DEVID_NONE or PLATFORM_DEVID_AUTO will never be used to register the watchdog devices, or provide other information such as platform data to make it explicit.
Also, the changes in arch code need to be made in separate patches.
Thanks,
Guenter
Re: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
In reply to Tzung-Bi ShihQuoted 23 lines · Tzung-Bi Shih
drivers/watchdog/pseries-wdt.c line 25
Quoted 4 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:
WARNING: please, no spaces at the start of a lineQuoted 1 line
+#define
PSERIES_WDTQL_MUST_STOP1From
./scripts/checkpatch.pl --strict:
WARNING: please, no space before tabsdrivers/watchdog/pseries-wdt.c line 160
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
Quoted 3 lines
Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
The line exceeds 100 columns.
I was under the impression that strings were an exception to the line-length rule. Is that not the case?
scripts/checkpatch.pl --strict complains if I break the string up:
WARNING: quoted string split across lines
#162: FILE: drivers/watchdog/pseries-wdt.c:162:
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: "
+ "\"hard-poweroff\", \"hard-restart\", or \"dump-restart\" "
WARNING: quoted string split across lines
#163: FILE: drivers/watchdog/pseries-wdt.c:163:
+ "\"hard-poweroff\", \"hard-restart\", or \"dump-restart\" "
+ "(default=\"hard-restart\")");
Quoted 22 lines
drivers/watchdog/pseries-wdt.c line 164
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT)")");From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c line 169
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+#define WATCHDOG_TIMEOUT 60 +static unsigned int timeout =WATCHDOG_TIMEOUT ; +module_param (timeout, uint,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds (default="
__MODULE_STRING(WATCHDOG_TIMEOUT)")");
Quoted 7 lines
From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c line 174
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+struct pseries_wdt { +struct watchdog_device wd; +unsigned long num;/* NB: Watchdog numbers are 1-based */ What does NB stand for? Could it be removed from the comment?
Sure, removed.
Quoted 2 lines
Does
timer_idor some other equivalent names make more sense for the variable?
The hardware documentation calls the parameter "watchdogNumber", so I think "num" is better than "id" in this case.
Guenter Roeck
maintainerRe: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
Quoted 23 lines · Scott Cheloha
Quoted 23 lines · Tzung-Bi Shih
drivers/watchdog/pseries-wdt.c line 25
Quoted 4 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:
WARNING: please, no spaces at the start of a lineQuoted 1 line
+#define
PSERIES_WDTQL_MUST_STOP1From
./scripts/checkpatch.pl --strict:
WARNING: please, no space before tabsdrivers/watchdog/pseries-wdt.c line 160
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
The line exceeds 100 columns.
I was under the impression that strings were an exception to the line-length rule. Is that not the case?
You can use
MODULE_PARM_DESC(action,
"Some text");
Quoted 50 lines
scripts/checkpatch.pl --strictcomplains if I break the string up:WARNING: quoted string split across lines
#162: FILE:drivers/watchdog/pseries-wdt.c:162:(quoted diff) +2
-0+MODULE_PARM_DESC(action, "Action taken when watchdog expires: " + "\"hard-poweroff\", \"hard-restart\", or \"dump-restart\" "WARNING: quoted string split across lines
#163: FILE:drivers/watchdog/pseries-wdt.c:163:(quoted diff) +2
-0+ "\"hard-poweroff\", \"hard-restart\", or \"dump-restart\" " + "(default=\"hard-restart\")");Quoted 23 lines
drivers/watchdog/pseries-wdt.c line 164
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT)")");From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c line 169
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+#define WATCHDOG_TIMEOUT 60 +static unsigned int timeout =WATCHDOG_TIMEOUT ; +module_param (timeout, uint,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds (default="
__MODULE_STRING(WATCHDOG_TIMEOUT)")");Quoted 7 lines
From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c line 174
Quoted 3 lines
drivers/watchdog/pseries-wdt.c new file +3
-0+struct pseries_wdt { +struct watchdog_device wd; +unsigned long num;/* NB: Watchdog numbers are 1-based */ What does NB stand for? Could it be removed from the comment?
Sure, removed.
Quoted 2 lines
Does
timer_idor some other equivalent names make more sense for the variable?The hardware documentation calls the parameter "watchdogNumber", so I think "num" is better than "id" in this case.
Re: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
Quoted 30 lines · Guenter Roeck
Quoted 25 lines · Scott Cheloha
Quoted 25 lines · Tzung-Bi Shih
drivers/watchdog/pseries-wdt.c line 25
Quoted 4 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:
WARNING: please, no spaces at the start of a lineQuoted 1 line
+#define
PSERIES_WDTQL_MUST_STOP1From
./scripts/checkpatch.pl --strict:
WARNING: please, no space before tabsdrivers/watchdog/pseries-wdt.c line 160
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
The line exceeds 100 columns.
I was under the impression that strings were an exception to the line-length rule. Is that not the case?
You can use
MODULE_PARM_DESC(action,
"Some text");
The line is still over 100 columns if I do this.
I can shrink the line by removing the valid inputs from the string if 100 columns is a hard rule.
If so, where should I document the valid inputs instead?
Is Documentation/watchdog/watchdog-parameters.rst a better place for them?
Guenter Roeck
maintainerRe: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
Quoted 31 lines · Scott Cheloha
Quoted 31 lines · Guenter Roeck
Quoted 26 lines · Scott Cheloha
Quoted 26 lines · Tzung-Bi Shih
drivers/watchdog/pseries-wdt.c line 25
Quoted 4 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:
WARNING: please, no spaces at the start of a lineQuoted 1 line
+#define
PSERIES_WDTQL_MUST_STOP1From
./scripts/checkpatch.pl --strict:
WARNING: please, no space before tabsdrivers/watchdog/pseries-wdt.c line 160
Quoted 2 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );From
./scripts/checkpatch.pl --strict:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
The line exceeds 100 columns.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I was under the impression that strings were an exception to the line-length rule. Is that not the case?
You can use
MODULE_PARM_DESC(action,
"Some text");The line is still over 100 columns if I do this.
You might consider using shorter strings, such as "poweroff", "restart", "dump". The meaning needs to be documented anyway. You could also drop "or" because it doesn't add value in this context, and the '"' don't really add value either.
On a side note, personally I don't like textual module parameters because they make the command line extremely long and add complexity to decoding it, but that is your call and responsibility (and you are not the only one using strings).
Guenter
Quoted 7 lines
I can shrink the line by removing the valid inputs from the string if 100 columns is a hard rule.
If so, where should I document the valid inputs instead?
Is
Documentation/watchdog/watchdog-parameters.rsta better place for them?
Re: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
In reply to Guenter RoeckQuoted 136 lines · Guenter Roeck
Quoted 52 lines · Tzung-Bi Shih
Quoted 8 lines · Scott Cheloha
+#define
SETFIELD(_v, _b, _e)\
+ (((unsigned long)(_v) <<PPC_BITLSHIFT(_e)) &PPC_BITMASK((_b), (_e)))
+#defineGETFIELD(_v, _b, _e)\
+ (((unsigned long)(_v) &PPC_BITMASK((_b), (_e))) >>PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:WARNING: please, no spaces at the start of a line
Quoted 3 lines
+#define PSERIES_WDTQL_MUST_STOP 1
From
./scripts/checkpatch.pl --strict:WARNING: please, no space before tabs
Quoted 5 lines
+static const struct
kernel_param_opsaction_ops= { .set =action_set};
+module_param_cb(action,&action_ops, NULL,S_IRUGO);From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 2 lines
+MODULE_PARM_DESC(action, "Action taken when watchdog expires:
\"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");The line exceeds 100 columns.
Quoted 4 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 10 lines
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT)")");From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c new file +3
-0+#define WATCHDOG_TIMEOUT 60 +static unsigned int timeout =WATCHDOG_TIMEOUT ; +module_param (timeout, uint,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 2 lines
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds (default="
__MODULE_STRING(WATCHDOG_TIMEOUT)")");Quoted 8 lines
Quoted 5 lines
From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.+struct
pseries_wdt{
+ structwatchdog_devicewd;
+ unsigned long num; /* NB: Watchdog numbers are 1-based */What does NB stand for? Could it be removed from the comment?
Latin "Nota Bene", for "This is important".
All comments should be important, so I agree, this has little if any value.Quoted 22 lines
Does
timer_idor some other equivalent names make more sense for the variable?Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_start(struct watchdog_device *wdd) +{[...]
Quoted 7 lines
+ rc =
plpar_hcall_norets(H_WATCHDOG, flags, pw->num, msecs); + if (rc !=H_SUCCESS) {
+dev_crit(dev, "H_WATCHDOG: %ld: failed to start timer %lu", + rc, pw->num);
+ return-EIO;From
./scripts/checkpatch.pl --strict:ERROR: code indent should use tabs where possible
WARNING: please, no space before tabsQuoted 5 lines
+static struct
watchdog_infopseries_wdt_info= { + .identity =DRV_NAME,
+ .options =WDIOF_KEEPALIVEPING|WDIOF_MAGICCLOSE|WDIOF_SETTIMEOUT\
+ |WDIOF_PRETIMEOUT,Quoted 9 lines
Quoted 1 line
From
./scripts/checkpatch.pl --strict:WARNING: Avoid unnecessary line continuations
Quoted 3 lines
+static const struct
watchdog_opspseries_wdt_ops= { + .owner =THIS_MODULE,
+ .ping =pseries_wdt_start,Does this mean: it needs hard restart for every ping?
If there is no separate ping function, there is no need to point the ping function to the start function. The watchdog core uses the start function automatically in this case.
Quoted 12 lines
Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_probe(struct platform_device *pdev) +{[...]
Quoted 3 lines
+ rc =
plpar_hcall(H_WATCHDOG, ret, PSERIES_WDTF_OP_QUERY); + if (rc !=H_SUCCESS)
+ return (rc ==H_FUNCTION) ?-ENODEV:-EIO;The parentheses can be dropped.
Quoted 2 lines
+ pw =
devm_kzalloc(&pdev->dev, sizeof *pw, GFP_KERNEL); + if (pw == NULL)Quoted 7 lines
Quoted 1 line
From
./scripts/checkpatch.pl --strict:CHECK: Comparison to NULL could be written "!pw"
Quoted 1 line
+
pw->num=pdev->id+ 1; /* 0-based -> 1-based */Didn't see where the platform device was registered but using the
pdev->idas the timer id could be unreliable (e.g. from auto increment).That is at the beginning of the patch, in
arch/powerpc/platforms/pseries/setup.c, which callsplatform_device_register_simple()with an explicit device ID.I agree, though, that it is fragile: The code in the probe function explicitly checks for a negative ID, which would only be provided if
platform_device_register()explicitly declares that (ie if it providesPLATFORM_DEVID_NONEas device ID). But if that is a concern, there might as well be code registering a platform device withPLATFORM_DEVID_AUTOas device ID, and then th device id would be automatic and more or less random. I think the instantiation code should be more
explicit: Either assume thatPLATFORM_DEVID_NONEorPLATFORM_DEVID_AUTOwill never be used to register the watchdog devices, or provide other information such as platform data to make it explicit.
Quoted 1 line
Also, the changes in arch code need to be made in separate patches.
Often this is true but in case like this - the driver itself is dead code until the platform enables it and if there is a problem with the driver - bisect will point to the device enablement commit. Backporting becomes a problem as it is going to be 3 apart patches vs. one:
1) define hypercall
2) implement the driver
3) enable the driver + device FW feature flag.
Instead, either maintainer (powerpc or watchdog) says "ack" and the other one puts it in the tree, I saw this in practice. Thanks,
Quoted 2 lines
Thanks,
Guenter
Signature · 1 line
Alexey
Guenter Roeck
maintainerRe: [RFC v2 2/2] watchdog: pseries-wdt: initial support for PAPR virtual watchdog timers
Quoted 135 lines · Alexey Kardashevskiy
Quoted 129 lines · Guenter Roeck
Quoted 46 lines · Tzung-Bi Shih
Quoted 6 lines · Scott Cheloha
drivers/watchdog/pseries-wdt.c new file +4
-0+#define SETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) << PPC_BITLSHIFT(_e)) & PPC_BITMASK((_b), (_e))) +#define GETFIELD (_v, _b, _e) \ + (((unsigned long)(_v) & PPC_BITMASK((_b), (_e))) >> PPC_BITLSHIFT(_e))From
./scripts/checkpatch.pl --strict:WARNING: please, no spaces at the start of a line
Quoted 3 lines
+#define PSERIES_WDTQL_MUST_STOP 1
From
./scripts/checkpatch.pl --strict:WARNING: please, no space before tabs
Quoted 4 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static const struct kernel_param_ops action_ops = { .set = action_set }; +module_param_cb (action, &action_ops,NULL ,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(action, "Action taken when watchdog expires: \"hard-poweroff\", \"hard-restart\", or \"dump-restart\" (default=\"hard-restart\")");
The line exceeds 100 columns.
Quoted 4 lines
drivers/watchdog/pseries-wdt.c new file +2
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 9 lines
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT)")");From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.drivers/watchdog/pseries-wdt.c new file +3
-0+#define WATCHDOG_TIMEOUT 60 +static unsigned int timeout =WATCHDOG_TIMEOUT ; +module_param (timeout, uint,S_IRUGO );From
./scripts/checkpatch.pl --strict:WARNING: Symbolic permissions '
S_IRUGO' are not preferred. Consider using octal permissions '0444'.Quoted 1 line
+MODULE_PARM_DESC(timeout, "Initial watchdog timeout in seconds (default="
__MODULE_STRING(WATCHDOG_TIMEOUT)")");Quoted 8 lines
Quoted 5 lines
From
./scripts/checkpatch.pl --strict, the line exceeds 100 columns.+struct
pseries_wdt{
+ structwatchdog_devicewd;
+ unsigned long num; /* NB: Watchdog numbers are 1-based */What does NB stand for? Could it be removed from the comment?
Latin "Nota Bene", for "This is important".
All comments should be important, so I agree, this has little if any value.Quoted 21 lines
Does
timer_idor some other equivalent names make more sense for the variable?Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_start(struct watchdog_device *wdd) +{[...]
Quoted 7 lines
+ rc =
plpar_hcall_norets(H_WATCHDOG, flags, pw->num, msecs); + if (rc !=H_SUCCESS) {
+dev_crit(dev, "H_WATCHDOG: %ld: failed to start timer %lu", + rc, pw->num);
+ return-EIO;From
./scripts/checkpatch.pl --strict:ERROR: code indent should use tabs where possible
WARNING: please, no space before tabsQuoted 4 lines
+static struct
watchdog_infopseries_wdt_info= {
+ .identity =DRV_NAME,
+ .options =WDIOF_KEEPALIVEPING|WDIOF_MAGICCLOSE|WDIOF_SETTIMEOUT\
+ |WDIOF_PRETIMEOUT,Quoted 9 lines
Quoted 1 line
From
./scripts/checkpatch.pl --strict:WARNING: Avoid unnecessary line continuations
Quoted 3 lines
+static const struct
watchdog_opspseries_wdt_ops= { + .owner =THIS_MODULE,
+ .ping =pseries_wdt_start,Does this mean: it needs hard restart for every ping?
If there is no separate ping function, there is no need to point the ping function to the start function. The watchdog core uses the start function automatically in this case.
Quoted 12 lines
Quoted 2 lines
(quoted diff) +2
-0+static int pseries_wdt_probe(struct platform_device *pdev) +{[...]
Quoted 3 lines
+ rc =
plpar_hcall(H_WATCHDOG, ret, PSERIES_WDTF_OP_QUERY); + if (rc !=H_SUCCESS)
+ return (rc ==H_FUNCTION) ?-ENODEV:-EIO;The parentheses can be dropped.
Quoted 2 lines
+ pw =
devm_kzalloc(&pdev->dev, sizeof *pw, GFP_KERNEL); + if (pw == NULL)Quoted 7 lines
Quoted 1 line
From
./scripts/checkpatch.pl --strict:CHECK: Comparison to NULL could be written "!pw"
Quoted 1 line
+
pw->num=pdev->id+ 1; /* 0-based -> 1-based */Didn't see where the platform device was registered but using the
pdev->idas the timer id could be unreliable (e.g. from auto increment).That is at the beginning of the patch, in
arch/powerpc/platforms/pseries/setup.c, which callsplatform_device_register_simple()with an explicit device ID.I agree, though, that it is fragile: The code in the probe function explicitly checks for a negative ID, which would only be provided if
platform_device_register()explicitly declares that (ie if it providesPLATFORM_DEVID_NONEas device ID). But if that is a concern, there might as well be code registering a platform device withPLATFORM_DEVID_AUTOas device ID, and then th device id would be automatic and more or less random. I think the instantiation code should be more
explicit: Either assume thatPLATFORM_DEVID_NONEorPLATFORM_DEVID_AUTOwill never be used to register the watchdog devices, or provide other information such as platform data to make it explicit.Quoted 1 line
Also, the changes in arch code need to be made in separate patches.
Quoted 7 lines
Often this is true but in case like this - the driver itself is dead code until the platform enables it and if there is a problem with the driver - bisect will point to the device enablement commit. Backporting becomes a problem as it is going to be 3 apart patches vs. one:
1) define hypercall
2) implement the driver
3) enable the driver + device FW feature flag.Instead, either maintainer (powerpc or watchdog) says "ack" and the other one puts it in the tree, I saw this in practice. Thanks,
I won't accept this. I don't mind giving an Ack to a patch applied elsewhere, and I don't mind applying patches from another subsystem if Acked by affected maintainers, but I strongly believe that there should be no cross-subsystem patches. Also, I don't consider 2) and 3) to be a single logical change, and the rule for patches is "one logical change per patch".
Other maintainers may handle this differently, but that is their call and responsibility.
Guenter
You should cc: [email protected] this. Thanks,
Quoted 53 lines · Scott Cheloha
This second RFC incorporates feedback from the previous RFC:
https://lore.kernel.org/linux-watchdog/[email protected]/
v2 changes of note:
- Add a firmware feature flag for the
H_WATCHDOGfeature,FW_FEATURE_WATCHDOG.- Register a
platform_devicefor the first watchdog timer during a pseries initcall if we haveFW_FEATURE_WATCHDOG. Use id zero, as there could be more than one timer in the future.- Alphabetize
Makefilechanges.- Add missing copyright information to
pseries-wdt.c.- Add an 'action' module parameter that configures how the guest is terminated on watchdog expiration.
- Use dev_*() for logging critical errors instead of pr_*().
- Handle the
H_NOOPcase when trying to stop the watchdog. If the given watchdog is not actually running,H_WATCHDOGreturnsH_NOOP. This is harmless, so we should treat it as a success.- We don't need
pseries_wdt_remove()at all.- Check
watchdog_active()before stopping/starting the timer across suspend/resume.- Consolidate all code from
pseries_wdt_module_init()intopseries_wdt_probe(). We can then usemodule_platform_driver().I have one lingering question:
- The pseries-wdt module is not "automatically" loaded during boot.
When I do
# modprobe pseries-wdtthe driver attaches to the platform bus as expected and the
/dev/watchdog*devices for the pseries-wdt.0 platform device are created.I was under the impression that driver/device matching for the platform bus was simple string comparison.
... what am I doing wrong? Is this expected behavior? Do I need to do additional configuration to get the module to load automatically at boot time?
Signature · 1 line
Alexey