Skip to content

Commit a9b66d6

Browse files
committed
IB/uverbs: Do not block disassociate during write()
Now that all the callbacks are safe to run concurrently with disassociation this test can be eliminated. The ufile core infrastructure becomes entirely self contained and is not sensitive to disassociation. Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e83f0ec commit a9b66d6

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

drivers/infiniband/core/uverbs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ struct ib_uverbs_file {
158158
spinlock_t uobjects_lock;
159159
struct list_head uobjects;
160160

161+
u64 uverbs_cmd_mask;
162+
u64 uverbs_ex_cmd_mask;
163+
161164
struct idr idr;
162165
/* spinlock protects write access to idr */
163166
spinlock_t idr_lock;

drivers/infiniband/core/uverbs_main.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ struct file *ib_uverbs_alloc_async_event_file(struct ib_uverbs_file *uverbs_file
646646
return filp;
647647
}
648648

649-
static bool verify_command_mask(struct ib_device *ib_dev,
650-
u32 command, bool extended)
649+
static bool verify_command_mask(struct ib_uverbs_file *ufile, u32 command,
650+
bool extended)
651651
{
652652
if (!extended)
653-
return ib_dev->uverbs_cmd_mask & BIT_ULL(command);
653+
return ufile->uverbs_cmd_mask & BIT_ULL(command);
654654

655-
return ib_dev->uverbs_ex_cmd_mask & BIT_ULL(command);
655+
return ufile->uverbs_ex_cmd_mask & BIT_ULL(command);
656656
}
657657

658658
static bool verify_command_idx(u32 command, bool extended)
@@ -722,7 +722,6 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
722722
{
723723
struct ib_uverbs_file *file = filp->private_data;
724724
struct ib_uverbs_ex_cmd_hdr ex_hdr;
725-
struct ib_device *ib_dev;
726725
struct ib_uverbs_cmd_hdr hdr;
727726
bool extended;
728727
int srcu_key;
@@ -757,14 +756,8 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
757756
return ret;
758757

759758
srcu_key = srcu_read_lock(&file->device->disassociate_srcu);
760-
ib_dev = srcu_dereference(file->device->ib_dev,
761-
&file->device->disassociate_srcu);
762-
if (!ib_dev) {
763-
ret = -EIO;
764-
goto out;
765-
}
766759

767-
if (!verify_command_mask(ib_dev, command, extended)) {
760+
if (!verify_command_mask(file, command, extended)) {
768761
ret = -EOPNOTSUPP;
769762
goto out;
770763
}
@@ -889,6 +882,9 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
889882
mutex_unlock(&dev->lists_mutex);
890883
srcu_read_unlock(&dev->disassociate_srcu, srcu_key);
891884

885+
file->uverbs_cmd_mask = ib_dev->uverbs_cmd_mask;
886+
file->uverbs_ex_cmd_mask = ib_dev->uverbs_ex_cmd_mask;
887+
892888
return nonseekable_open(inode, filp);
893889

894890
err_module:

0 commit comments

Comments
 (0)