mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: Greg KH <greg@kroah.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dave Jones <davej@redhat.com>
Subject: Re: lp: hung task in lp_open
Date: Thu, 7 Jun 2012 23:59:43 +0000	[thread overview]
Message-ID: <201206072359.43707.arnd@arndb.de> (raw)
In-Reply-To: <1339075302.3279.14.camel@lappy>

On Thursday 07 June 2012, Sasha Levin wrote:
> This appears to be happening since we can block on port open, which
> is done within the mutex lock, so that any further lp_open calls with
> appear to be "hung" on that mutex.
> 
> That mutex was added there as part of BKL cleanup.
> 
> I'm not sure whether the solution here is to get the lock just on the
> parts which need locking, or add it as an exception to the hung task monitor.

Hmm, does the hung task detector only trigger because this is an
uninterruptible sleep? Does this fix it?

8<------
lp: use only one per-port mutex

Different stages of the BKL removal in the lp driver have taken different
approaches: the earlier read/write conversion used a new per-port mutex,
while the later open and ioctl conversion used a global mutex and
did an uninterruptible sleep, which causes tasks to hang when multiple
ones try to open any device. Using mutex_lock_interruptible lets the
user stop waiting for a device that is already open and decouples the
devices from one another.

Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index a741e41..0fcb197 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -493,11 +493,12 @@ static int lp_open(struct inode * inode, struct file * file)
 	unsigned int minor = iminor(inode);
 	int ret = 0;
 
-	mutex_lock(&lp_mutex);
-	if (minor >= LP_NO) {
-		ret = -ENXIO;
-		goto out;
-	}
+	if (minor >= LP_NO)
+		return -ENXIO;
+
+	if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
+		return -ERESTARTSYS;
+
 	if ((LP_F(minor) & LP_EXIST) == 0) {
 		ret = -ENXIO;
 		goto out;
@@ -554,7 +555,7 @@ static int lp_open(struct inode * inode, struct file * file)
 	lp_release_parport (&lp_table[minor]);
 	lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
 out:
-	mutex_unlock(&lp_mutex);
+	mutex_unlock(&lp_table[minor].port_mutex);
 	return ret;
 }
 
@@ -680,7 +681,8 @@ static long lp_ioctl(struct file *file, unsigned int cmd,
 	int ret;
 
 	minor = iminor(file->f_path.dentry->d_inode);
-	mutex_lock(&lp_mutex);
+	if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
+		return -ERESTARTSYS;
 	switch (cmd) {
 	case LPSETTIMEOUT:
 		if (copy_from_user(&par_timeout, (void __user *)arg,
@@ -694,7 +696,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd,
 		ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
 		break;
 	}
-	mutex_unlock(&lp_mutex);
+	mutex_unlock(&lp_table[minor].port_mutex);
 
 	return ret;
 }
@@ -708,7 +710,8 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
 	int ret;
 
 	minor = iminor(file->f_path.dentry->d_inode);
-	mutex_lock(&lp_mutex);
+	if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
+		return -ERESTARTSYS;
 	switch (cmd) {
 	case LPSETTIMEOUT:
 		if (compat_get_timeval(&par_timeout, compat_ptr(arg))) {
@@ -727,7 +730,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
 		ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg));
 		break;
 	}
-	mutex_unlock(&lp_mutex);
+	mutex_unlock(&lp_table[minor].port_mutex);
 
 	return ret;
 }

  reply	other threads:[~2012-06-08  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-07 13:21 Sasha Levin
2012-06-07 23:59 ` Arnd Bergmann [this message]
2012-06-28 18:16   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201206072359.43707.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=davej@redhat.com \
    --cc=greg@kroah.com \
    --cc=levinsasha928@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome