Skip to contentSkip to conversation

Install kernel module for active watchdog

PATCH Superseded Pratyush Anand 3 participants 11 messages Mar 8, 2016 – Mar 11, 2016 6 messages not in the archive

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Install kernel module for active watchdog

Changes since V3:
-- Incorporated changes suggested by Harald for V2 patches

Changes since V2:
-- Added one more patch to update rd.driver.pre with watchdog module name, so that they are loaded into kernel as early as possible.
-- Removed creation of tmp/active-watchdogs. modinfo will be helpful for kexec-tools.
-- Now we add modules for active watchdog in hostonly mode and modules for all watchdog in no-hostonly mode.

Changes since RFC:
-- Added one more patch to take care that dracut does not add watchdog hooks when systemd module is included. In that case systemd daemon will manage watchdog for kicking.
-- Removed --nowdt argument. User can use -o or --omit when wathdog module is not needed. Thanks Harald for this suggestion.
-- Now I also do not check for "hostonly" to add modules for active watchdog. It seems reasonable to add kernel watchdog modules whenever, dracut watchdog module has been added.

Pratyush Anand (3):
watchdog: Do not add hooks if systemd module is included
watchdog: install module for active watchdog
watchdog: ensure that module is loaded as early as possible

Cc Dave Young <[email protected]>
Cc Don Zickus <[email protected]>
Cc Harald Hoyer <[email protected]>
 modules.d/04watchdog/module-setup.sh | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
Signature · 1 line
2.5.0

A message that is not in the archive (sent off-list or not yet received): cover.1457425628.git.panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH v4 1/3 watchdog: Do not add hooks if systemd module is included

When systemd is present, let it manage watchdog feed.

Cc Dave Young <[email protected]>
Cc Don Zickus <[email protected]>
Cc Harald Hoyer <[email protected]>
---
 modules.d/04watchdog/module-setup.sh | 5 +++++
 1 file changed, 5 insertions(+)
modules.d/04watchdog/module-setup.sh +5 -0
index 576c589c198d..7ec757aec032 100755
@@ -12,6 +12,11 @@ depends() {
 
 # called by dracut
 install() {
+    # Do not add watchdog hooks if systemd module is included
+    # In that case, systemd will manage watchdog kick
+    if dracut_module_included "systemd"; then
+	    return
+    fi
     inst_hook cmdline   00 "$moddir/watchdog.sh"
     inst_hook cmdline   50 "$moddir/watchdog.sh"
     inst_hook pre-trigger 00 "$moddir/watchdog.sh"
Signature · 1 line
2.5.0
#3 lore raw

PATCH v4 2/3 watchdog: install module for active watchdog

In reply to a message not in the archive

Recently following patches have been added in upstream Linux kernel, which
(1) fixes parent of watchdog_device so that /sys/class/watchdog/watchdogn/device is populated. (2) adds some sysfs device attributes so that different watchdog status can be read.

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6551881c86c791237a3bebf11eb3bd70b60ea782
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=906d7a5cfeda508e7361f021605579a00cd82815
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=33b711269ade3f6bc9d9d15e4343e6fa922d999b

With the above support, now we can find out whether a watchdog is active or not. We can also find out the driver/module responsible for that watchdog device.

Proposed patch uses above support and then adds module of active watchdog in initramfs generated by dracut for hostonly mode. Kernel module for inactive watchdog will be added as well for none hostonly mode.

When an user does not want to add kernel module, then one should exclude complete dracut watchdog module with --omit.

Testing:
-- When watchdog is active watchdog modules were added

	# cat /sys/class/watchdog/watchdog0/identity
	iTCO_wdt
	# cat /sys/class/watchdog/watchdog0/state
	active
	# dracut --hostonly initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko

-- When watchdog is inactive then watchdog modules were not added

	# cat /sys/class/watchdog/watchdog0/state
	inactive
	# dracut --hostonly initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO

-- When watchdog is inactive, but no hostonly mode, watchdog modules were added

	# cat /sys/class/watchdog/watchdog0/state
	inactive
	# dracut --no-hostonly initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko
Cc Dave Young <[email protected]>
Cc Don Zickus <[email protected]>
Cc Harald Hoyer <[email protected]>
---
 modules.d/04watchdog/module-setup.sh | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
modules.d/04watchdog/module-setup.sh +28 -0
index 7ec757aec032..0ffaa9658502 100755
@@ -32,3 +32,31 @@ install() {
     inst_multiple -o wdctl
 }
 
+installkernel() {
+    [[ -d /sys/class/watchdog/ ]] || return
+    for dir in /sys/class/watchdog/*; do
+	    [[ -d "$dir" ]] || continue
+	    [[ -f "$dir/state" ]] || continue
+	    active=$(< "$dir/state")
+	    ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue
+	    # device/modalias will return driver of this device
+	    wdtdrv=$(< "$dir/device/modalias")
+	    # There can be more than one module represented by same
+	    # modalias. Currently load all of them.
+	    # TODO: Need to find a way to avoid any unwanted module
+	    # represented by modalias
+	    wdtdrv=$(modprobe -R $wdtdrv)
+	    instmods $wdtdrv
+	    # however in some cases, we also need to check that if there is
+	    # a specific driver for the parent bus/device.  In such cases
+	    # we also need to enable driver for parent bus/device.
+	    wdtppath=$(readlink -f "$dir/device/..")
+	    while [ -f "$wdtppath/modalias" ]
+	    do
+		    wdtpdrv=$(< "$wdtppath/modalias")
+		    wdtpdrv=$(modprobe -R $wdtpdrv)
+		    instmods $wdtpdrv
+		    wdtppath=$(readlink -f "$wdtppath/..")
+	    done
+    done
+}
Signature · 1 line
2.5.0

A message that is not in the archive (sent off-list or not yet received): 0c1909217f5714663d1fd1841c19b00dc68031b2.1457425628.git.panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#5 lore raw

Re: [PATCH V4 dracut 2/3] watchdog: install module for active watchdog

Hi, Pratyush

Quoted 58 lines · Pratyush Anand

Recently following patches have been added in upstream Linux kernel, which
(1) fixes parent of watchdog_device so that /sys/class/watchdog/watchdogn/device is populated. (2) adds some sysfs device attributes so that different watchdog status can be read.

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6551881c86c791237a3bebf11eb3bd70b60ea782
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=906d7a5cfeda508e7361f021605579a00cd82815
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=33b711269ade3f6bc9d9d15e4343e6fa922d999b

With the above support, now we can find out whether a watchdog is active or not. We can also find out the driver/module responsible for that watchdog device.

Proposed patch uses above support and then adds module of active watchdog in initramfs generated by dracut for hostonly mode. Kernel module for inactive watchdog will be added as well for none hostonly mode.

When an user does not want to add kernel module, then one should exclude complete dracut watchdog module with --omit.

Testing:
-- When watchdog is active watchdog modules were added

	# cat /sys/class/watchdog/watchdog0/identity
	iTCO_wdt
	# cat /sys/class/watchdog/watchdog0/state
	active
	# dracut --hostonly initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko

-- When watchdog is inactive then watchdog modules were not added

	# cat /sys/class/watchdog/watchdog0/state
	inactive
	# dracut --hostonly initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO

-- When watchdog is inactive, but no hostonly mode, watchdog modules were added

	# cat /sys/class/watchdog/watchdog0/state
	inactive
	# dracut --no-hostonly initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko
Cc Dave Young <[email protected]>
Cc Don Zickus <[email protected]>
Cc Harald Hoyer <[email protected]>
---
 modules.d/04watchdog/module-setup.sh | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
modules.d/04watchdog/module-setup.sh +0 -0
index 7ec757aec032..0ffaa9658502 100755

modules.d/04watchdog/module-setup.sh install() { · line 41

Quoted 10 lines
modules.d/04watchdog/module-setup.sh +7 -0
@@ -32,3 +32,31 @@ install() {
     inst_multiple -o wdctl
 }
 
+installkernel() {
+    [[ -d /sys/class/watchdog/ ]] || return
+    for dir in /sys/class/watchdog/*; do
+	    [[ -d "$dir" ]] || continue
+	    [[ -f "$dir/state" ]] || continue
+	    active=$(< "$dir/state")
+	    ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue

Even if for devices which is not active it is still a hostonly device because it being detected by kernel running on the host?

But I will not stick to this issue, I'm fine if Harald is ok with it because I do not know how to handle non hostonly in a proper way ..

Thanks
Dave

A message that is not in the archive (sent off-list or not yet received): 20160308092912.GA8155-0VdLhd/A9Pl+NNSt+8eSiB/[email protected]

#7 lore raw

Re: [PATCH V4 dracut 2/3] watchdog: install module for active watchdog

Hi Harald,

Quoted 9 lines · Dave Young

modules.d/04watchdog/module-setup.sh install() { · line 41

Quoted 2 lines · Pratyush Anand
modules.d/04watchdog/module-setup.sh +2 -0
+	    active=$(< "$dir/state")
+	    ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue

Even if for devices which is not active it is still a hostonly device because it being detected by kernel running on the host?

But I will not stick to this issue, I'm fine if Harald is ok with it because I do not know how to handle non hostonly in a proper way ..

Please let me know if you have any further input for these patches. Otherwise, I will send a V5 with the update in patch 3/3 incorporating Dave's comment for change in Watchdog command line file name.

~Pratyush

#8 lore raw

PATCH v4 3/3 watchdog: ensure that module is loaded as early as possible

In reply to a message not in the archive

It is expected that a watchdog module will disable an active watchdog when its probe is called ie, when it is loaded. So an early load of the module will help to disable it earlier.
This can be helpful in some corner cases where kdump and watchdog daemon both are active.

Testing:
-- When watchdog kernel modules were added
# dracut --no-hostonly initramfs-test.img -a watchdog # lsinitrd initramfs-test.img -f etc/cmdline.d/04-watchdog.conf rd.driver.pre=iTCO_wdt,lpc_ich,

Cc Dave Young <[email protected]>
Cc Don Zickus <[email protected]>
Cc Harald Hoyer <[email protected]>
---
 modules.d/04watchdog/module-setup.sh | 5 +++++
 1 file changed, 5 insertions(+)
modules.d/04watchdog/module-setup.sh +5 -0
index 0ffaa9658502..d99e5b33de44 100755
@@ -34,6 +34,7 @@ install() {
 
 installkernel() {
     [[ -d /sys/class/watchdog/ ]] || return
+    wdtcmdline=""
     for dir in /sys/class/watchdog/*; do
 	    [[ -d "$dir" ]] || continue
 	    [[ -f "$dir/state" ]] || continue
@@ -47,6 +48,7 @@ installkernel() {
 	    # represented by modalias
 	    wdtdrv=$(modprobe -R $wdtdrv)
 	    instmods $wdtdrv
+	    wdtcmdline="$wdtcmdline$(echo $wdtdrv | tr " " ","),"
 	    # however in some cases, we also need to check that if there is
 	    # a specific driver for the parent bus/device.  In such cases
 	    # we also need to enable driver for parent bus/device.
@@ -56,7 +58,10 @@ installkernel() {
 		    wdtpdrv=$(< "$wdtppath/modalias")
 		    wdtpdrv=$(modprobe -R $wdtpdrv)
 		    instmods $wdtpdrv
+		    wdtcmdline="$wdtcmdline$(echo $wdtpdrv | tr " " ","),"
 		    wdtppath=$(readlink -f "$wdtppath/..")
 	    done
     done
+    # ensure that watchdog module is loaded as early as possible
+    [[ $wdtcmdline = "" ]] || echo "rd.driver.pre=$wdtcmdline" > ${initdir}/etc/cmdline.d/04-watchdog.conf
 }
Signature · 1 line
2.5.0

A message that is not in the archive (sent off-list or not yet received): e63d322e2cc3081a616f14f5586998811145931d.1457425628.git.panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#11 lore raw

Re: [PATCH V4 dracut 3/3] watchdog: ensure that module is loaded as early as possible

In reply to a message not in the archive

Hi, Pratyush

Quoted 41 lines · Pratyush Anand

It is expected that a watchdog module will disable an active watchdog when its probe is called ie, when it is loaded. So an early load of the module will help to disable it earlier.
This can be helpful in some corner cases where kdump and watchdog daemon both are active.

Testing:
-- When watchdog kernel modules were added
# dracut --no-hostonly initramfs-test.img -a watchdog # lsinitrd initramfs-test.img -f etc/cmdline.d/04-watchdog.conf rd.driver.pre=iTCO_wdt,lpc_ich,

Cc Dave Young <[email protected]>
Cc Don Zickus <[email protected]>
Cc Harald Hoyer <[email protected]>
---
 modules.d/04watchdog/module-setup.sh | 5 +++++
 1 file changed, 5 insertions(+)
modules.d/04watchdog/module-setup.sh +2 -0
index 0ffaa9658502..d99e5b33de44 100755
@@ -34,6 +34,7 @@ install() {
 
 installkernel() {
     [[ -d /sys/class/watchdog/ ]] || return
+    wdtcmdline=""
     for dir in /sys/class/watchdog/*; do
 	    [[ -d "$dir" ]] || continue
 	    [[ -f "$dir/state" ]] || continue
@@ -47,6 +48,7 @@ installkernel() {
 	    # represented by modalias
 	    wdtdrv=$(modprobe -R $wdtdrv)
 	    instmods $wdtdrv
+	    wdtcmdline="$wdtcmdline$(echo $wdtdrv | tr " " ","),"
 	    # however in some cases, we also need to check that if there is
 	    # a specific driver for the parent bus/device.  In such cases
 	    # we also need to enable driver for parent bus/device.

modules.d/04watchdog/module-setup.sh installkernel() { · line 66

Quoted 9 lines
modules.d/04watchdog/module-setup.sh +3 -0
@@ -56,7 +58,10 @@ installkernel() {
 		    wdtpdrv=$(< "$wdtppath/modalias")
 		    wdtpdrv=$(modprobe -R $wdtpdrv)
 		    instmods $wdtpdrv
+		    wdtcmdline="$wdtcmdline$(echo $wdtpdrv | tr " " ","),"
 		    wdtppath=$(readlink -f "$wdtppath/..")
 	    done
     done
+    # ensure that watchdog module is loaded as early as possible
+    [[ $wdtcmdline = "" ]] || echo "rd.driver.pre=$wdtcmdline" > ${initdir}/etc/cmdline.d/04-watchdog.conf

It is not necessary to use same number as the dracut module "04".
Since it is special we want it being loaded as soon as possible move it to 00-watchdog.conf sound better.

Thanks
Dave

A message that is not in the archive (sent off-list or not yet received): 20160308093738.GC8155-0VdLhd/A9Pl+NNSt+8eSiB/[email protected]

#13 lore raw

Re: [PATCH V4 dracut 3/3] watchdog: ensure that module is loaded as early as possible

Hi Dave,

Quoted 4 lines · Dave Young
Quoted 1 line

+ [[ $wdtcmdline = "" ]] || echo "rd.driver.pre=$wdtcmdline" > ${initdir}/etc/cmdline.d/04-watchdog.conf

It is not necessary to use same number as the dracut module "04".
Since it is special we want it being loaded as soon as possible move it to 00-watchdog.conf sound better.

OK. Will change.

~Pratyush

#14 lore raw
In reply to a message not in the archive

Hi, Pratyush

Quoted 8 lines · Pratyush Anand

Changes since V3:
-- Incorporated changes suggested by Harald for V2 patches

Changes since V2:
-- Added one more patch to update rd.driver.pre with watchdog module name, so that they are loaded into kernel as early as possible.
-- Removed creation of tmp/active-watchdogs. modinfo will be helpful for kexec-tools.

Kdump still need save a previous added wdt somewhere so that it can rebuild initrd if necessary. I'm not sure where can we store the state, do you have some thoughts about it?

Thanks
Dave

A message that is not in the archive (sent off-list or not yet received): 20160308093400.GB8155-0VdLhd/A9Pl+NNSt+8eSiB/[email protected]

#16 lore raw

Hi Dave,

Quoted 7 lines · Dave Young
Quoted 2 lines · Pratyush Anand

-- Removed creation of tmp/active-watchdogs. modinfo will be helpful for kexec-tools.

Kdump still need save a previous added wdt somewhere so that it can rebuild initrd if necessary. I'm not sure where can we store the state, do you have some thoughts about it?

modinfo is able to help out here. See following kexec implementation, which I still need to cleanup (as per coding style feedback received for dracut patches), But I have tested it and it works.

https://github.com/pratyushanand/kexec-tools/blob/watchdog_fmaster/kdumpctl#L341

~Pratyush