public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Munzert <frankm@linux.vnet.ibm.com>
To: mingo@elte.hu
Cc: linux-kernel@vger.kernel.org
Subject: BUG: lock held when returning to user space
Date: Wed, 12 Mar 2008 16:45:36 +0100	[thread overview]
Message-ID: <47D7FAA0.1090802@linux.vnet.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]

Hi Ingo,

we provided a device driver vmur dealing with z/VM virtual unit record 
devices (reader, punch, printer). A corresponding user space tool 
provides functions similar to the CMS commands RECEIVE, PUNCH, PRINT.  
Unit record devices are not meant for concurrent read or write by 
multiple users, that's why we need to serialize access. The driver's 
open method uses  mutex_trylock or  mutex_lock_interruptible  to  ensure 
exclusive access to the device, while its  release method  uses 
mutex_unlock.

As a consequence, lockdep complains about locks being held when 
returning to user space. We used a very simple char device driver 
(appended below) to produce this message: 
================================================
[ BUG: lock held when returning to user space! ]
------------------------------------------------
testapp/2683 is leaving the kernel with locks still held!
1 lock held by testapp/2683:
 #0:  (&test_mutex){--..}, at: [<000003e00003316c>] test_open+0x30/0x64 
[test]

For the vmur device driver it is crucial to have only one process access 
a given unit record device node at a given time. So having open hold the 
mutex and return to user space is exactly what we want. Is  there any 
annotation  to tell lockdep to suppress or bypass this kind of warning?

Thanks in advance,

Frank


[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 1930 bytes --]

#include  <linux/module.h>
#include  <linux/init.h>
#include  <linux/fs.h>
#include  <linux/types.h>
#include  <linux/cdev.h>

#define  DEVICE_NAME  "test"
#define  MODULE_NAME  "test"

static dev_t Devno;
static struct cdev test_cdev;
static struct mutex test_mutex;

static ssize_t test_read(struct file *filp, char *buff, size_t len,
			 loff_t *whence)
{
	return 1;
}

static ssize_t test_write(struct file *filp, const char *buff,
			  size_t len, loff_t *whence)
{
	return 1;
}

static int test_open(struct inode *ino, struct file *filp)
{
	if (mutex_lock_interruptible(&test_mutex))
		return -ERESTARTSYS;
	printk("%s: test device is open.\n", MODULE_NAME);
	return 0;
}

static int test_close(struct inode *ino, struct file *filp)
{
	printk("%s: test device is closed.\n", MODULE_NAME);
	mutex_unlock(&test_mutex);
	return 0;
}

static struct file_operations Fops  =  { .owner   = THIS_MODULE,
				         .read    = test_read,
				         .write   = test_write,
				         .open    = test_open,
				         .release = test_close    };

static int __init test_init(void)
{
	int rc;
	rc = alloc_chrdev_region(&Devno, 0, 1, DEVICE_NAME);
	if (rc < 0)
	{
		printk("%s: Registration failed...\n",MODULE_NAME);
		return rc;
	}
	printk("%s: Registration %s at major number %d\n", MODULE_NAME,
				DEVICE_NAME, MAJOR(Devno));
	cdev_init(&test_cdev, &Fops);
	test_cdev.owner = THIS_MODULE;
	rc = cdev_add(&test_cdev, Devno, 1);
	if (rc < 0) {
		printk("%s: Device object not added!\n", MODULE_NAME);
		unregister_chrdev_region(Devno, 1);
		return rc;
	}
	printk("%s: Device added.\n", MODULE_NAME);
	mutex_init(&test_mutex);
	return 0;
}

static void __exit test_exit(void)
{
	cdev_del(&test_cdev);
	unregister_chrdev_region(Devno, 1);
	printk("%s: Module removed.\n", MODULE_NAME);
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Frank");
MODULE_DESCRIPTION("Simple char driver.");

             reply	other threads:[~2008-03-12 15:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 15:45 Frank Munzert [this message]
2008-03-12 16:29 ` BUG: lock held when returning to user space Vegard Nossum
2008-03-12 21:40 ` Jiri Kosina
2008-03-13 15:43   ` Daniel Walker
2008-03-13 17:39     ` Peter Zijlstra
2008-03-13 17:56       ` Daniel Walker
  -- strict thread matches above, loose matches on Subject: below --
2008-03-13 16:49 J.C. Pizarro
2007-10-27 14:19 Gabriel C
2007-10-27 15:12 ` Jiri Kosina
2007-10-27 15:28   ` Peter Zijlstra
2007-10-27 15:46     ` Andrew Morton
2007-10-28 11:12       ` Jiri Kosina
2007-10-29 12:20         ` Alessandro Zummo
2007-10-27 16:35     ` Linus Torvalds
2007-10-27 22:47     ` Jiri Kosina
2007-10-27 15:47   ` Arjan van de Ven
2007-10-27 16:09     ` Peter Zijlstra
2007-10-27 17:05       ` Arjan van de Ven

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=47D7FAA0.1090802@linux.vnet.ibm.com \
    --to=frankm@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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