From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: [RFC patch 1/3] ieee1394: raw1394: replace BKL by local mutex, make ioctl() and mmap() thread-safe
Date: Sat, 16 Aug 2008 00:11:48 +0200 (CEST) [thread overview]
Message-ID: <tkrat.0df9cff587ba5fed@s5r6.in-berlin.de> (raw)
This removes the last usage of the Big Kernel Lock from the ieee1394
stack, i.e. from raw1394's (unlocked_)ioctl and compat_ioctl.
The ioctl()s don't need to take the BKL, but they need to be serialized
per struct file *. In particular, accesses to ->iso_state need to be
serial. We simply use a blocking mutex for this purpose because
libraw1394 does not use O_NONBLOCK. In practice, there is no lock
contention anyway because most if not all libraw1394 clients use a
libraw1394 handle only in a single thread.
mmap() also accesses ->iso_state. Until now this was unprotected
against concurrent changes by ioctls. Fix this bug while we are at it.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
drivers/ieee1394/raw1394-private.h | 1 +
drivers/ieee1394/raw1394.c | 23 +++++++++++++++++------
2 files changed, 18 insertions(+), 6 deletions(-)
Index: linux/drivers/ieee1394/raw1394-private.h
===================================================================
--- linux.orig/drivers/ieee1394/raw1394-private.h
+++ linux/drivers/ieee1394/raw1394-private.h
@@ -22,6 +22,7 @@ enum raw1394_iso_state { RAW1394_ISO_INA
struct file_info {
struct list_head list;
+ struct mutex state_mutex;
enum { opened, initialized, connected } state;
unsigned int protocol_version;
Index: linux/drivers/ieee1394/raw1394.c
===================================================================
--- linux.orig/drivers/ieee1394/raw1394.c
+++ linux/drivers/ieee1394/raw1394.c
@@ -34,6 +34,7 @@
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>
@@ -2541,11 +2542,18 @@ static int raw1394_read_cycle_timer(stru
static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
{
struct file_info *fi = file->private_data;
+ int ret;
+
+ mutex_lock(&fi->state_mutex);
if (fi->iso_state == RAW1394_ISO_INACTIVE)
- return -EINVAL;
+ ret = -EINVAL;
+ else
+ ret = dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
+
+ mutex_unlock(&fi->state_mutex);
- return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
+ return ret;
}
/* ioctl is only used for rawiso operations */
@@ -2659,10 +2667,12 @@ static long do_raw1394_ioctl(struct file
static long raw1394_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
+ struct file_info *fi = file->private_data;
long ret;
- lock_kernel();
+
+ mutex_lock(&fi->state_mutex);
ret = do_raw1394_ioctl(file, cmd, arg);
- unlock_kernel();
+ mutex_unlock(&fi->state_mutex);
return ret;
}
@@ -2724,7 +2734,7 @@ static long raw1394_compat_ioctl(struct
void __user *argp = (void __user *)arg;
long err;
- lock_kernel();
+ mutex_lock(&fi->state_mutex);
switch (cmd) {
/* These requests have same format as long as 'int' has same size. */
case RAW1394_IOC_ISO_RECV_INIT:
@@ -2757,7 +2767,7 @@ static long raw1394_compat_ioctl(struct
err = -EINVAL;
break;
}
- unlock_kernel();
+ mutex_unlock(&fi->state_mutex);
return err;
}
@@ -2791,6 +2801,7 @@ static int raw1394_open(struct inode *in
fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
INIT_LIST_HEAD(&fi->list);
+ mutex_init(&fi->state_mutex);
fi->state = opened;
INIT_LIST_HEAD(&fi->req_pending);
INIT_LIST_HEAD(&fi->req_complete);
--
Stefan Richter
-=====-==--- =--- =----
http://arcgraph.de/sr/
next reply other threads:[~2008-08-15 22:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-15 22:11 Stefan Richter [this message]
2008-08-15 22:12 ` [RFC patch 2/3] ieee1394: raw1394: narrow down the state_mutex protected region Stefan Richter
2008-08-15 22:15 ` [RFC patch 3/3] ieee1394: raw1394: make write() thread-safe Stefan Richter
2008-08-16 15:52 ` [RFC patch 2/3] ieee1394: raw1394: narrow down the state_mutex protected region Stefan Richter
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=tkrat.0df9cff587ba5fed@s5r6.in-berlin.de \
--to=stefanr@s5r6.in-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
/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
all inboxes | Powered by JetHome®