Skip to contentSkip to conversation

PATCH: add watchdog support to the fschmd driver [0/2]

lm-sensors Hans de Goede 2 participants 4 messages Nov 11, 2008 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

Hi Jean (and all),

Here is a new version of the fschmd watchdog patch, intended for 2.6.29, learning from my just too late experience with my 2.6.28 patches I'm trying to get this one queued in plenty og time for 2.6.29, Jean can you re-review it please.

All issues from the review of the previous version have either been commented upon why I didn't fix them (see reply to the review) or have been fixed.

In addition I've added reference counting for the data-structure, as it can still be used by the watchdog driver after the i2c-client has been removed (when some process still has /dev/watchdogX open)

I've split this into 2 patches, 1 with some small cleanups and 1 with the actual new watchdog code.

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

[lm-sensors] PATCH: add watchdog support to the fschmd driver [2/2]

Hi Jean (and all),

This patch adds support for the watchdog part found in _all_ supported FSC sensor chips.

Regards,

Hans

This patch adds support for the watchdog part found in _all_ supported FSC sensor chips.

drivers/hwmon/Kconfig renamed from drivers/hwmon/Kconfig.wtd +3 -2
diff -up linux-2.6.28-rc4/drivers/hwmon/Kconfig.wtd linux-2.6.28-rc4/drivers/hwmon/Kconfig
@@ -318,10 +318,11 @@ config SENSORS_FSCHMD
 	depends on X86 && I2C && EXPERIMENTAL
 	help
 	  If you say yes here you get support for various Fujitsu Siemens
-	  Computers sensor chips.
+	  Computers sensor chips, including support for the integrated
+	  watchdog.
 
 	  This is a new merged driver for FSC sensor chips which is intended
-	  as a replacment for the fscpos, fscscy and fscher drivers and adds
+	  as a replacement for the fscpos, fscscy and fscher drivers and adds
 	  support for several other FCS sensor chips.
 
 	  This driver can also be built as a module.  If so, the module
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.wtd +389 -18

503 lines not on this page · raw message

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw

Re: [lm-sensors] PATCH: add watchdog support to the fschmd driver

In reply to Hans de Goede

Hi Hans,

Quoted 4 lines · Hans de Goede

This patch adds support for the watchdog part found in _all_ supported FSC sensor chips.

Looks OK to me except for two remaining issues:

Quoted 18 lines
(quoted diff) +18 -0
+static int watchdog_open(struct inode *inode, struct file *filp)
+{
+	int ret = 0;
+	struct fschmd_data *pos, *data = NULL;
+
+	/* We get called from drivers/char/misc.c with misc_mtx hold, and we
+	   call misc_register() from fschmd_probe() with watchdog_data_mutex
+	   hold, as misc_register() takes the misc_mtx lock, this is a possible
+	   deadlock, so we use mutex_trylock here. */
+	if (!mutex_trylock(&watchdog_data_mutex))
+		return -ERESTARTSYS;
+	list_for_each_entry(pos, &watchdog_data_list, list) {
+		if (pos->watchdog_miscdev.minor = iminor(inode)) {
+			data = pos;
+			break;
+		}
+	}
+	/* Note we can never not have found data, so we don't check for this */

Review

Quoted 10 lines
(quoted diff) +10 -0
+	kref_get(&data->kref);
+	mutex_unlock(&watchdog_data_mutex);
+
+	mutex_lock(&data->watchdog_lock);
+	if (data->watchdog_open_count)
+		ret = -EBUSY;
+	data->watchdog_open_count++;
+	mutex_unlock(&data->watchdog_lock);
+	if (ret)
+		return ret;

This looks wrong to me. Did you test concurrent open? If you return -EBUSY then caller will see its attempt to open the device node fail, so it will never get to close it. That means that you've incremented data->watchdog_open_count but it will never get decremented so it will be >= 1 forever and the watchdog device is no longer usable. I think this should be:

	if (data->watchdog_open_count)
		ret = -EBUSY;
	else
		data->watchdog_open_count++;

Or am I missing something? You may want to use test_and_set_bit()/clear_bit() as many other watchdog drivers are doing.

Quoted 47 lines
(quoted diff) +45 -0
+
+	/* Start the watchdog */
+	watchdog_trigger(data);
+	filp->private_data = data;
+
+	return nonseekable_open(inode, filp);
+}
 
(...)
+static int watchdog_ioctl(struct inode *inode, struct file *filp,
+	unsigned int cmd, unsigned long arg)
+{
+	static struct watchdog_info ident = {
+		.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
+				WDIOF_CARDRESET,
+		.identity = "FSC watchdog"
+	};
+	int i, ret = 0;
+	struct fschmd_data *data = filp->private_data;
+
+	switch (cmd) {
+	case WDIOC_GETSUPPORT:
+		ident.firmware_version = data->revision;
+		if (!nowayout)
+			ident.options |= WDIOF_MAGICCLOSE;
+		if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
+			ret = -EFAULT;
+		break;
+
+	case WDIOC_GETSTATUS:
+		ret = put_user(0, (int __user *)arg);
+		break;
+
+	case WDIOC_GETBOOTSTATUS:
+		if (data->watchdog_state & FSCHMD_WDOG_STATE_CARDRESET)
+			ret = put_user(WDIOF_CARDRESET, (int __user *)arg);
+		else
+			ret = put_user(0, (int __user *)arg);
+		break;
+
+	case WDIOC_KEEPALIVE:
+		ret = watchdog_trigger(data);
+		break;
+
+	case WDIOC_GETTIMEOUT:
+		i = watchdog_get_timeout(data);
+		ret = put_user(i, (int __user *)arg);

Review

Quoted 10 lines
(quoted diff) +10 -0
+		break;
+
+	case WDIOC_SETTIMEOUT:
+		if (get_user(i, (int __user *)arg)) {
+			ret = -EFAULT;
+			break;
+		}
+		ret = watchdog_set_timeout(data, i);
+		if (ret > 0)
+			ret = put_user(i, (int __user *)arg);

Shouldn't you push "ret" rather than "i" back to the caller? As I understand it, "i" is what the user asked for, while "ret" is what the watchdog will actually do.

Quoted 12 lines
(quoted diff) +12 -0
+		break;
+
+	case WDIOC_SETOPTIONS:
+		if (get_user(i, (int __user *)arg)) {
+			ret = -EFAULT;
+			break;
+		}
+
+		if (i & WDIOS_DISABLECARD)
+			ret = watchdog_stop(data);
+		else if (i & WDIOS_ENABLECARD)
+			ret = watchdog_trigger(data);

Review

Quoted 10 lines
(quoted diff) +10 -0
+		else
+			ret = -EINVAL;
+
+		break;
+	default:
+		ret = -ENOTTY;
+	}
+
+	return ret;
+}

Other than that, it looks OK to me (but remember I am no watchdog expert, and getting Wim Van Sebroeck to review your patch would make sense.)

Can you please:
* Address the remaining issues.
* Test again.
* Send an updated version of the patch.

And finally:

* Send a 3rd patch deprecating the fscher and fscpos drivers, planing them for removal in, say, 6 months?

Thanks,

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw

Re: [lm-sensors] PATCH: add watchdog support to the fschmd driver

In reply to Hans de Goede
Quoted 32 lines · Jean Delvare

Hi Hans,

Quoted 4 lines · Hans de Goede

This patch adds support for the watchdog part found in _all_ supported FSC sensor chips.

Looks OK to me except for two remaining issues:

Quoted 22 lines
(quoted diff) +22 -0
+static int watchdog_open(struct inode *inode, struct file *filp)
+{
+	int ret = 0;
+	struct fschmd_data *pos, *data = NULL;
+
+	/* We get called from drivers/char/misc.c with misc_mtx hold, and we
+	   call misc_register() from fschmd_probe() with watchdog_data_mutex
+	   hold, as misc_register() takes the misc_mtx lock, this is a possible
+	   deadlock, so we use mutex_trylock here. */
+	if (!mutex_trylock(&watchdog_data_mutex))
+		return -ERESTARTSYS;
+	list_for_each_entry(pos, &watchdog_data_list, list) {
+		if (pos->watchdog_miscdev.minor = iminor(inode)) {
+			data = pos;
+			break;
+		}
+	}
+	/* Note we can never not have found data, so we don't check for this */
+	kref_get(&data->kref);
+	mutex_unlock(&watchdog_data_mutex);
+
+	mutex_lock(&data->watchdog_lock);
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	if (data->watchdog_open_count)
+		ret = -EBUSY;
+	data->watchdog_open_count++;
+	mutex_unlock(&data->watchdog_lock);
+	if (ret)
+		return ret;

This looks wrong to me. Did you test concurrent open?

No

Quoted 7 lines

If you return
-EBUSY then caller will see its attempt to open the device node fail, so it will never get to close it. That means that you've incremented data->watchdog_open_count but it will never get decremented so it will be >= 1 forever and the watchdog device is no longer usable. I think this should be:

Quoted 5 lines
	if (data->watchdog_open_count)
		ret = -EBUSY;
	else
		data->watchdog_open_count++;

Agreed, will fix.

Quoted 3 lines

Or am I missing something? You may want to use test_and_set_bit()/clear_bit() as many other watchdog drivers are doing.

Yes even better will do.

Quoted 53 lines
Quoted 53 lines
(quoted diff) +51 -0
+
+	/* Start the watchdog */
+	watchdog_trigger(data);
+	filp->private_data = data;
+
+	return nonseekable_open(inode, filp);
+}
 
(...)
+static int watchdog_ioctl(struct inode *inode, struct file *filp,
+	unsigned int cmd, unsigned long arg)
+{
+	static struct watchdog_info ident = {
+		.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
+				WDIOF_CARDRESET,
+		.identity = "FSC watchdog"
+	};
+	int i, ret = 0;
+	struct fschmd_data *data = filp->private_data;
+
+	switch (cmd) {
+	case WDIOC_GETSUPPORT:
+		ident.firmware_version = data->revision;
+		if (!nowayout)
+			ident.options |= WDIOF_MAGICCLOSE;
+		if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
+			ret = -EFAULT;
+		break;
+
+	case WDIOC_GETSTATUS:
+		ret = put_user(0, (int __user *)arg);
+		break;
+
+	case WDIOC_GETBOOTSTATUS:
+		if (data->watchdog_state & FSCHMD_WDOG_STATE_CARDRESET)
+			ret = put_user(WDIOF_CARDRESET, (int __user *)arg);
+		else
+			ret = put_user(0, (int __user *)arg);
+		break;
+
+	case WDIOC_KEEPALIVE:
+		ret = watchdog_trigger(data);
+		break;
+
+	case WDIOC_GETTIMEOUT:
+		i = watchdog_get_timeout(data);
+		ret = put_user(i, (int __user *)arg);
+		break;
+
+	case WDIOC_SETTIMEOUT:
+		if (get_user(i, (int __user *)arg)) {
+			ret = -EFAULT;
+			break;
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+		}
+		ret = watchdog_set_timeout(data, i);
+		if (ret > 0)
+			ret = put_user(i, (int __user *)arg);

Shouldn't you push "ret" rather than "i" back to the caller? As I understand it, "i" is what the user asked for, while "ret" is what the watchdog will actually do.

And another good catch!

Quoted 17 lines
Quoted 17 lines
(quoted diff) +17 -0
+		break;
+
+	case WDIOC_SETOPTIONS:
+		if (get_user(i, (int __user *)arg)) {
+			ret = -EFAULT;
+			break;
+		}
+
+		if (i & WDIOS_DISABLECARD)
+			ret = watchdog_stop(data);
+		else if (i & WDIOS_ENABLECARD)
+			ret = watchdog_trigger(data);
+		else
+			ret = -EINVAL;
+
+		break;
+	default:
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		ret = -ENOTTY;
+	}
+
+	return ret;
+}

Other than that, it looks OK to me (but remember I am no watchdog expert,

Well you seem to be doing a good job!

Quoted 2 lines

and getting Wim Van Sebroeck to review your patch would make sense.

Ok I'll fix the 2 things you've found and then send an updated patch to Wim Van Sebroeck for checking.

Quoted 2 lines

Can you please:
* Address the remaining issues.

Will do asap and then send the patch to Wim Van Sebroeck

Quoted 1 line

* Test again.

That will take some day (I won't have access to the hw till next friday).

Quoted 1 line

* Send an updated version of the patch.

Will do once tested.

Quoted 5 lines

And finally:

* Send a 3rd patch deprecating the fscher and fscpos drivers, planing them for removal in, say, 6 months?

Ah yes, will do also (gladly even) :)

Thans & Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors