From: Roland Dreier <rdreier@cisco.com>
To: Jonathan Corbet <corbet@lwn.net>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Arnd Bergmann <arnd@arndb.de>, Andi Kleen <andi@firstfloor.org>,
general@lists.openfabrics.org
Subject: [PATCH] IB/uverbs: BKL is not needed for ib_uverbs_open()
Date: Fri, 27 Jun 2008 14:43:20 -0700 [thread overview]
Message-ID: <adaskuylfk7.fsf@cisco.com> (raw)
In-Reply-To: <20080627095418.2353267d@bike.lwn.net> (Jonathan Corbet's message of "Fri, 27 Jun 2008 09:54:18 -0600")
Remove explicit lock_kernel() calls and document why the code is safe.
Signed-off-by: Roland Dreier <rolandd@cisco.com>
---
Hi Jon,
Is this sort of patch the next step in the BKL-removal plan? Is now an
appropriate time to send such things?
If this looks good to you I will do a careful audit of the rest of
drivers/infiniband/core and send you a few more similar patches.
Thanks,
Roland
drivers/infiniband/core/uverbs_main.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index f839dde..661b3f8 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -45,7 +45,6 @@
#include <linux/file.h>
#include <linux/mount.h>
#include <linux/cdev.h>
-#include <linux/smp_lock.h>
#include <asm/uaccess.h>
@@ -611,23 +610,32 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
return file->device->ib_dev->mmap(file->ucontext, vma);
}
+/*
+ * ib_uverbs_open() does not need the BKL:
+ *
+ * - dev_table[] accesses are protected by map_lock, the
+ * ib_uverbs_device structures are properly reference counted, and
+ * everything else is purely local to the file being created, so
+ * races against other open calls are not a proble;
+ * - there is no ioctl method to race against;
+ * - the device is added to dev_table[] as the last part of module
+ * initialization, the open method will either immediately run
+ * -ENXIO, or all required initialization will be done.
+ */
static int ib_uverbs_open(struct inode *inode, struct file *filp)
{
struct ib_uverbs_device *dev;
struct ib_uverbs_file *file;
int ret;
- lock_kernel();
spin_lock(&map_lock);
dev = dev_table[iminor(inode) - IB_UVERBS_BASE_MINOR];
if (dev)
kref_get(&dev->ref);
spin_unlock(&map_lock);
- if (!dev) {
- unlock_kernel();
+ if (!dev)
return -ENXIO;
- }
if (!try_module_get(dev->ib_dev->owner)) {
ret = -ENODEV;
@@ -648,7 +656,6 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
filp->private_data = file;
- unlock_kernel();
return 0;
err_module:
@@ -656,7 +663,6 @@ err_module:
err:
kref_put(&dev->ref, ib_uverbs_release_dev);
- unlock_kernel();
return ret;
}
--
1.5.6
next prev parent reply other threads:[~2008-06-27 21:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-27 15:54 The state of the BKL-removal tree Jonathan Corbet
2008-06-27 15:56 ` Mike Frysinger
2008-06-27 21:43 ` Roland Dreier [this message]
2008-06-30 22:55 ` [PATCH] IB/uverbs: BKL is not needed for ib_uverbs_open() Jonathan Corbet
2008-07-01 0:15 ` [ofa-general] " Roland Dreier
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=adaskuylfk7.fsf@cisco.com \
--to=rdreier@cisco.com \
--cc=andi@firstfloor.org \
--cc=arnd@arndb.de \
--cc=corbet@lwn.net \
--cc=general@lists.openfabrics.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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