Skip to content

Commit c0d3b9c

Browse files
James BottomleyJames Bottomley
James Bottomley
authored and
James Bottomley
committed
[SCSI] Revert "sg: push file descriptor list locking down to per-device locking"
This reverts commit 1f962eb. This is one of four patches that was causing this bug [ 205.372823] ================================================ [ 205.372901] [ BUG: lock held when returning to user space! ] [ 205.372979] 3.12.0-rc6-hw-debug-pagealloc+ #67 Not tainted [ 205.373055] ------------------------------------------------ [ 205.373132] megarc.bin/5283 is leaving the kernel with locks still held! [ 205.373212] 1 lock held by megarc.bin/5283: [ 205.373285] #0: (&sdp->o_sem){.+.+..}, at: [<ffffffff8161e650>] sg_open+0x3a0/0x4d0 Cc: Vaughan Cao <[email protected]> Acked-by: Douglas Gilbert <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent 10c580e commit c0d3b9c

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

drivers/scsi/sg.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static int sg_add(struct device *, struct class_interface *);
106106
static void sg_remove(struct device *, struct class_interface *);
107107

108108
static DEFINE_IDR(sg_index_idr);
109-
static DEFINE_RWLOCK(sg_index_lock);
109+
static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock
110+
file descriptor list for device */
110111

111112
static struct class_interface sg_interface = {
112113
.add_dev = sg_add,
@@ -143,7 +144,8 @@ typedef struct sg_request { /* SG_MAX_QUEUE requests outstanding per file */
143144
} Sg_request;
144145

145146
typedef struct sg_fd { /* holds the state of a file descriptor */
146-
struct list_head sfd_siblings; /* protected by sfd_lock of device */
147+
/* sfd_siblings is protected by sg_index_lock */
148+
struct list_head sfd_siblings;
147149
struct sg_device *parentdp; /* owning device */
148150
wait_queue_head_t read_wait; /* queue read until command done */
149151
rwlock_t rq_list_lock; /* protect access to list in req_arr */
@@ -168,7 +170,7 @@ typedef struct sg_device { /* holds the state of each scsi generic device */
168170
struct scsi_device *device;
169171
int sg_tablesize; /* adapter's max scatter-gather table size */
170172
u32 index; /* device index number */
171-
spinlock_t sfd_lock; /* protect file descriptor list for device */
173+
/* sfds is protected by sg_index_lock */
172174
struct list_head sfds;
173175
struct rw_semaphore o_sem; /* exclude open should hold this rwsem */
174176
volatile char detached; /* 0->attached, 1->detached pending removal */
@@ -225,9 +227,9 @@ static int sfds_list_empty(Sg_device *sdp)
225227
unsigned long flags;
226228
int ret;
227229

228-
spin_lock_irqsave(&sdp->sfd_lock, flags);
230+
read_lock_irqsave(&sg_index_lock, flags);
229231
ret = list_empty(&sdp->sfds);
230-
spin_unlock_irqrestore(&sdp->sfd_lock, flags);
232+
read_unlock_irqrestore(&sg_index_lock, flags);
231233
return ret;
232234
}
233235

@@ -1391,7 +1393,6 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
13911393
disk->first_minor = k;
13921394
sdp->disk = disk;
13931395
sdp->device = scsidp;
1394-
spin_lock_init(&sdp->sfd_lock);
13951396
INIT_LIST_HEAD(&sdp->sfds);
13961397
init_rwsem(&sdp->o_sem);
13971398
sdp->sg_tablesize = queue_max_segments(q);
@@ -1526,13 +1527,11 @@ static void sg_remove(struct device *cl_dev, struct class_interface *cl_intf)
15261527

15271528
/* Need a write lock to set sdp->detached. */
15281529
write_lock_irqsave(&sg_index_lock, iflags);
1529-
spin_lock(&sdp->sfd_lock);
15301530
sdp->detached = 1;
15311531
list_for_each_entry(sfp, &sdp->sfds, sfd_siblings) {
15321532
wake_up_interruptible(&sfp->read_wait);
15331533
kill_fasync(&sfp->async_qp, SIGPOLL, POLL_HUP);
15341534
}
1535-
spin_unlock(&sdp->sfd_lock);
15361535
write_unlock_irqrestore(&sg_index_lock, iflags);
15371536

15381537
sysfs_remove_link(&scsidp->sdev_gendev.kobj, "generic");
@@ -2057,13 +2056,13 @@ sg_add_sfp(Sg_device * sdp, int dev)
20572056
sfp->cmd_q = SG_DEF_COMMAND_Q;
20582057
sfp->keep_orphan = SG_DEF_KEEP_ORPHAN;
20592058
sfp->parentdp = sdp;
2060-
spin_lock_irqsave(&sdp->sfd_lock, iflags);
2059+
write_lock_irqsave(&sg_index_lock, iflags);
20612060
if (sdp->detached) {
2062-
spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
2061+
write_unlock_irqrestore(&sg_index_lock, iflags);
20632062
return ERR_PTR(-ENODEV);
20642063
}
20652064
list_add_tail(&sfp->sfd_siblings, &sdp->sfds);
2066-
spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
2065+
write_unlock_irqrestore(&sg_index_lock, iflags);
20672066
SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: sfp=0x%p\n", sfp));
20682067
if (unlikely(sg_big_buff != def_reserved_size))
20692068
sg_big_buff = def_reserved_size;
@@ -2110,12 +2109,11 @@ static void sg_remove_sfp_usercontext(struct work_struct *work)
21102109
static void sg_remove_sfp(struct kref *kref)
21112110
{
21122111
struct sg_fd *sfp = container_of(kref, struct sg_fd, f_ref);
2113-
struct sg_device *sdp = sfp->parentdp;
21142112
unsigned long iflags;
21152113

2116-
spin_lock_irqsave(&sdp->sfd_lock, iflags);
2114+
write_lock_irqsave(&sg_index_lock, iflags);
21172115
list_del(&sfp->sfd_siblings);
2118-
spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
2116+
write_unlock_irqrestore(&sg_index_lock, iflags);
21192117

21202118
INIT_WORK(&sfp->ew.work, sg_remove_sfp_usercontext);
21212119
schedule_work(&sfp->ew.work);
@@ -2502,7 +2500,7 @@ static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
25022500
return 0;
25032501
}
25042502

2505-
/* must be called while holding sg_index_lock and sfd_lock */
2503+
/* must be called while holding sg_index_lock */
25062504
static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
25072505
{
25082506
int k, m, new_interface, blen, usg;
@@ -2587,26 +2585,22 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
25872585

25882586
read_lock_irqsave(&sg_index_lock, iflags);
25892587
sdp = it ? sg_lookup_dev(it->index) : NULL;
2590-
if (sdp) {
2591-
spin_lock(&sdp->sfd_lock);
2592-
if (!list_empty(&sdp->sfds)) {
2593-
struct scsi_device *scsidp = sdp->device;
2588+
if (sdp && !list_empty(&sdp->sfds)) {
2589+
struct scsi_device *scsidp = sdp->device;
25942590

2595-
seq_printf(s, " >>> device=%s ", sdp->disk->disk_name);
2596-
if (sdp->detached)
2597-
seq_printf(s, "detached pending close ");
2598-
else
2599-
seq_printf
2600-
(s, "scsi%d chan=%d id=%d lun=%d em=%d",
2601-
scsidp->host->host_no,
2602-
scsidp->channel, scsidp->id,
2603-
scsidp->lun,
2604-
scsidp->host->hostt->emulated);
2605-
seq_printf(s, " sg_tablesize=%d excl=%d\n",
2606-
sdp->sg_tablesize, sdp->exclude);
2607-
sg_proc_debug_helper(s, sdp);
2608-
}
2609-
spin_unlock(&sdp->sfd_lock);
2591+
seq_printf(s, " >>> device=%s ", sdp->disk->disk_name);
2592+
if (sdp->detached)
2593+
seq_printf(s, "detached pending close ");
2594+
else
2595+
seq_printf
2596+
(s, "scsi%d chan=%d id=%d lun=%d em=%d",
2597+
scsidp->host->host_no,
2598+
scsidp->channel, scsidp->id,
2599+
scsidp->lun,
2600+
scsidp->host->hostt->emulated);
2601+
seq_printf(s, " sg_tablesize=%d excl=%d\n",
2602+
sdp->sg_tablesize, sdp->exclude);
2603+
sg_proc_debug_helper(s, sdp);
26102604
}
26112605
read_unlock_irqrestore(&sg_index_lock, iflags);
26122606
return 0;

0 commit comments

Comments
 (0)