Skip to contentSkip to conversation

2.6.11 - NMI lockup with CFQ scheduler

OOPS Chris Rankin 4 participants 18 messages Mar 29, 2005 – Apr 8, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I have one IDE hard disc, but I was using a USB memory stick at one point. (Notice the usb-storage and vfat modules in my list.) Could that be the troublesome SCSI device?

Quoted 49 lines · --- Jens Axboe
Quoted 4 lines · Chris Rankin

[gcc-3.4.3, Linux-2.6.11-SMP, Dual P4 Xeon with HT enabled]

Hi,

Quoted 8 lines

My Linux 2.6.11 box oopsed when I tried to logout. I have switched to using the anticipatory scheduler instead.

Cheers,
Chris

NMI Watchdog detected LOCKUP on CPU1, eip c0275cc7, registers:

Modules linked in: snd_pcm_oss snd_mixer_oss snd_usb_audio snd_usb_lib snd_intel8x0

snd_seq_oss

Quoted 1 line

snd_seq_midi snd_emu10k1_synth snd_emu10k1 snd_ac97_codec snd_pcm snd_page_alloc

snd_emux_synth

Quoted 1 line

snd_seq_virmidi snd_rawmidi snd_seq_midi_event snd_seq_midi_emul snd_hwdep snd_util_mem

snd_seq

Quoted 1 line

snd_seq_device snd_rtctimer snd_timer snd nls_iso8859_1 nls_cp437 vfat fat usb_storage radeon

drm

Quoted 3 lines

i2c_algo_bit emu10k1_gp gameport deflate zlib_deflate zlib_inflate twofish serpent aes_i586 blowfish des sha256 crypto_null af_key binfmt_misc eeprom i2c_sensor button processor psmouse pcspkr p4_clockmod speedstep_lib usbserial lp nfsd exportfs md5 ipv6 sd_mod scsi_mod autofs

nfs

Quoted 2 lines

lockd sunrpc af_packet ohci_hcd parport_pc parport e1000 video1394 raw1394 i2c_i801 i2c_core ohci1394 ieee1394 ehci_hcd soundcore pwc videodev uhci_hcd usbcore intel_agp agpgart ide_cd

cdrom

Quoted 9 lines

ext3 jbd

CPU:    1
EIP:    0060:[<c0275cc7>]    Not tainted VLI
EFLAGS: 00200086   (2.6.11) 

EIP is at _spin_lock+0x7/0xf
eax: f7b8b01c ebx: f7c82b88 ecx: f7c82b94 edx: f6c33714
esi: eb68ad88 edi: f6c33708 ebp: f6c33714 esp: f5b32f70
ds: 007b es: 007b ss: 0068
Process nautilus (pid: 5757, threadinfo=f5b32000 task=f7518020)

Quoted 10 lines
Stack: c01f7f79 00200282 f76bda24 f6c323e4 f7518020 00000000 00000000 c01f1d0c 
       f5b32000 c011d7b3 00000001 00000000 b65ffa40 00000000 f5b32fac 00000000 
       00000000 00000000 f5b32000 c011d8d6 c0102e7f 00000000 b65ffbf0 b6640bf0 
Call Trace:
 [<c01f7f79>] cfq_exit_io_context+0x54/0xb3
 [<c01f1d0c>] exit_io_context+0x45/0x51
 [<c011d7b3>] do_exit+0x205/0x308
 [<c011d8d6>] next_thread+0x0/0xc
 [<c0102e7f>] syscall_call+0x7/0xb
Code: 05 e8 3a e6 ff ff c3 ba 00 f0 ff ff 21 e2 81 42 14 00 01 00 00 f0 81 28 00 00 00 01 74

05 e8

Quoted 1 line

1d e6 ff ff c3 f0 fe 08 79 09 f3 90 <80> 38 00 7e f9 eb f2 c3 f0 81 28 00 00 00 01 74 05 e8 ff

e5

Quoted 13 lines
Quoted 2 lines

ff
console shuts up ...

The queue was gone by the time the process exited. What type of storage do you have attached to the box? At least with SCSI, it has some problems in this area - it will glady free the scsi device structure (where the queue lock is located) while the queue reference count still hasn't dropped to zero.

Signature · 1 line
Jens Axboe

Send instant messages to your online friends http://uk.messenger.yahoo.com

#1 lore raw

On Tue, Mar 29 2005, Chris Rankin wrote:

(please don't top post)

Quoted 59 lines
Quoted 49 lines · --- Jens Axboe
Quoted 4 lines · Chris Rankin

[gcc-3.4.3, Linux-2.6.11-SMP, Dual P4 Xeon with HT enabled]

Hi,

Quoted 8 lines

My Linux 2.6.11 box oopsed when I tried to logout. I have switched to using the anticipatory scheduler instead.

Cheers,
Chris

NMI Watchdog detected LOCKUP on CPU1, eip c0275cc7, registers:

Modules linked in: snd_pcm_oss snd_mixer_oss snd_usb_audio snd_usb_lib snd_intel8x0

snd_seq_oss

Quoted 1 line

snd_seq_midi snd_emu10k1_synth snd_emu10k1 snd_ac97_codec snd_pcm snd_page_alloc

snd_emux_synth

Quoted 1 line

snd_seq_virmidi snd_rawmidi snd_seq_midi_event snd_seq_midi_emul snd_hwdep snd_util_mem

snd_seq

Quoted 1 line

snd_seq_device snd_rtctimer snd_timer snd nls_iso8859_1 nls_cp437 vfat fat usb_storage radeon

drm

Quoted 3 lines

i2c_algo_bit emu10k1_gp gameport deflate zlib_deflate zlib_inflate twofish serpent aes_i586 blowfish des sha256 crypto_null af_key binfmt_misc eeprom i2c_sensor button processor psmouse pcspkr p4_clockmod speedstep_lib usbserial lp nfsd exportfs md5 ipv6 sd_mod scsi_mod autofs

nfs

Quoted 2 lines

lockd sunrpc af_packet ohci_hcd parport_pc parport e1000 video1394 raw1394 i2c_i801 i2c_core ohci1394 ieee1394 ehci_hcd soundcore pwc videodev uhci_hcd usbcore intel_agp agpgart ide_cd

cdrom

Quoted 9 lines

ext3 jbd

CPU:    1
EIP:    0060:[<c0275cc7>]    Not tainted VLI
EFLAGS: 00200086   (2.6.11) 

EIP is at _spin_lock+0x7/0xf
eax: f7b8b01c ebx: f7c82b88 ecx: f7c82b94 edx: f6c33714
esi: eb68ad88 edi: f6c33708 ebp: f6c33714 esp: f5b32f70
ds: 007b es: 007b ss: 0068
Process nautilus (pid: 5757, threadinfo=f5b32000 task=f7518020)

Quoted 10 lines
Stack: c01f7f79 00200282 f76bda24 f6c323e4 f7518020 00000000 00000000 c01f1d0c 
       f5b32000 c011d7b3 00000001 00000000 b65ffa40 00000000 f5b32fac 00000000 
       00000000 00000000 f5b32000 c011d8d6 c0102e7f 00000000 b65ffbf0 b6640bf0 
Call Trace:
 [<c01f7f79>] cfq_exit_io_context+0x54/0xb3
 [<c01f1d0c>] exit_io_context+0x45/0x51
 [<c011d7b3>] do_exit+0x205/0x308
 [<c011d8d6>] next_thread+0x0/0xc
 [<c0102e7f>] syscall_call+0x7/0xb
Code: 05 e8 3a e6 ff ff c3 ba 00 f0 ff ff 21 e2 81 42 14 00 01 00 00 f0 81 28 00 00 00 01 74

05 e8

Quoted 1 line

1d e6 ff ff c3 f0 fe 08 79 09 f3 90 <80> 38 00 7e f9 eb f2 c3 f0 81 28 00 00 00 01 74 05 e8 ff

e5

Quoted 8 lines
Quoted 2 lines

ff
console shuts up ...

The queue was gone by the time the process exited. What type of storage do you have attached to the box? At least with SCSI, it has some problems in this area - it will glady free the scsi device structure (where the queue lock is located) while the queue reference count still hasn't dropped to zero.

Quoted 3 lines

I have one IDE hard disc, but I was using a USB memory stick at one point. (Notice the usb-storage and vfat modules in my list.) Could that be the troublesome SCSI device?

Yes, it probably is. What happens is that you insert the stick and do io against it, which sets up a process io context for that device. That context persists until the process exits (or later, if someone still holds a reference to it), but the queue_lock will be dead when you yank the usb device.

It is quite a serious problem, not just for CFQ. SCSI referencing is badly broken there.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 2 lines · Jens Axboe

It is quite a serious problem, not just for CFQ. SCSI referencing is badly broken there.

OK ... I accept that with regard to the queue lock.

However, rather than trying to work out a way to tie all the refcounted objects together, what about the simpler solution of making the lock bound to the lifetime of the queue?

As far as SCSI is concerned, we could simply move the lock into the request_queue structure and everything would work since the device holds a reference to the queue. The way it would work is that we'd simply have a lock in the request_queue structure, but it would be up to the device to pass it in in blk_init_queue. Then we'd alter the scsi_device sdev_lock to be a pointer to the queue lock? This scheme would also work for the current users who have a global lock (they simply wouldn't use the lock int the request_queue).

The only could on the horizon with this scheme is that there may genuinely be places where we want multiple queues to share a non-global
lock: situations where we have shared issue queues (like IDE), or shared tag resources are a possibility. To cope with those, we'd probably have to have a separately allocated, reference counted lock.

However, I'm happy to implement the simpler solution (lock in requuest_queue) if you agree.

James

James

#3 lore raw
Quoted 5 lines · James Bottomley
Quoted 2 lines · Jens Axboe

It is quite a serious problem, not just for CFQ. SCSI referencing is badly broken there.

OK ... I accept that with regard to the queue lock.

It is much deeper than that. The recent hack to kill requests is yet another example of that. At least this work-around makes it a little better, but the mid layer assumption that sdev going to zero implies the queue going away at the same time is inherently broken.

Quoted 3 lines

However, rather than trying to work out a way to tie all the refcounted objects together, what about the simpler solution of making the lock bound to the lifetime of the queue?

That's essentially what the work-around does.

Quoted 9 lines

As far as SCSI is concerned, we could simply move the lock into the request_queue structure and everything would work since the device holds a reference to the queue. The way it would work is that we'd simply have a lock in the request_queue structure, but it would be up to the device to pass it in in blk_init_queue. Then we'd alter the scsi_device sdev_lock to be a pointer to the queue lock? This scheme would also work for the current users who have a global lock (they simply wouldn't use the lock int the request_queue).

Quoted 8 lines

The only could on the horizon with this scheme is that there may genuinely be places where we want multiple queues to share a non-global
lock: situations where we have shared issue queues (like IDE), or shared tag resources are a possibility. To cope with those, we'd probably have to have a separately allocated, reference counted lock.

However, I'm happy to implement the simpler solution (lock in requuest_queue) if you agree.

I rather like the queue lock being a pointer, so you can share at whatever level you want. Lets not grow the request_queue a full lock just to work around a bug elsewhere.

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 3 lines · Jens Axboe

I rather like the queue lock being a pointer, so you can share at whatever level you want. Lets not grow the request_queue a full lock just to work around a bug elsewhere.

I'm not proposing that it not be a pointer, merely that it could be intialiased to point to a lock structure within the request queue.

Doing this looks much simpler than your current patch ... one of the problems with which looks to be that removing the scsi_driver module is in trouble because we currently have the queue_release in the sdev release (which won't get called while the queue holds a reference).

I think the correct model for all of this is that the block driver shouldn't care (or be tied to) the scsi one. Thus, as long as SCSI can reject requests from a queue whose device has been released (without checking the device) then everything is fine as long as we sort out the lock lifetime problem.

James

#5 lore raw
Quoted 7 lines · James Bottomley
Quoted 3 lines · Jens Axboe

I rather like the queue lock being a pointer, so you can share at whatever level you want. Lets not grow the request_queue a full lock just to work around a bug elsewhere.

I'm not proposing that it not be a pointer, merely that it could be intialiased to point to a lock structure within the request queue.

Sorry that's what I meant, you are adding a lock inside the queue. I didn't mean removing q->queue_lock or making it a non-pointer.

Quoted 4 lines

Doing this looks much simpler than your current patch ... one of the problems with which looks to be that removing the scsi_driver module is in trouble because we currently have the queue_release in the sdev release (which won't get called while the queue holds a reference).

It is simpler, but it only solves this particular problem of the lock going away.

Quoted 5 lines

I think the correct model for all of this is that the block driver shouldn't care (or be tied to) the scsi one. Thus, as long as SCSI can reject requests from a queue whose device has been released (without checking the device) then everything is fine as long as we sort out the lock lifetime problem.

But you are tying it completely to the SCSI problem, since we have no locking problems of this sort elsewhere. At least the notified could potentially be used for something else. The lock is just hack number two to work around the problem.

Signature · 1 line
Jens Axboe
#6 lore raw
Quoted 10 lines · Jens Axboe
Quoted 5 lines

I think the correct model for all of this is that the block driver shouldn't care (or be tied to) the scsi one. Thus, as long as SCSI can reject requests from a queue whose device has been released (without checking the device) then everything is fine as long as we sort out the lock lifetime problem.

But you are tying it completely to the SCSI problem, since we have no locking problems of this sort elsewhere. At least the notified could potentially be used for something else. The lock is just hack number two to work around the problem.

Then help me understand the problem as you see it.

My current understanding is that these problems occur because we've mixed data in two objects of different lifetimes. So far, this is stack independent.

My proposal is to correct this by moving the data back to the correct object, and make any object using it hold a reference, so this would make the provider of the block request_fn hold a reference to the queue and initialise the queue lock pointer with the lock currently in the queue. Drivers that still use a global lock would be unaffected. This also means that any provider of a request_fn may expect to process (and reject) requests for a period of time after blk_cleanup_queue(). Really, this refcounting is inherent in blk_init_queue(), blk_cleanup_queue() so the only additional requirement is sanely processing queue requests after you think it's been cleaned up. This is request_fn() provider independent, I think (providers who currently don't violate the lifetime rules don't need fixing).

I claim that this proposal solves the current problem, and any other ones we run across that occur because of data mixing.

Your current patch tries to solve the problem by tying the two objects together; unifying the lifetimes. I agree this can be done (it was how the sd/sr close race was fixed). But the current way the freeing functions thread across the subsystems doesn't look nice and I don't currently see a way to get the queue freed: We free the queue on scsi device release; if the queue holds a reference to the scsi_device, the release function will never be called. Our only other choice is to try to free the queue on device_del instead, but that's too early, I think.

James

#7 lore raw
Quoted 12 lines · James Bottomley
Quoted 10 lines · Jens Axboe
Quoted 5 lines

I think the correct model for all of this is that the block driver shouldn't care (or be tied to) the scsi one. Thus, as long as SCSI can reject requests from a queue whose device has been released (without checking the device) then everything is fine as long as we sort out the lock lifetime problem.

But you are tying it completely to the SCSI problem, since we have no locking problems of this sort elsewhere. At least the notified could potentially be used for something else. The lock is just hack number two to work around the problem.

Quoted 5 lines

Then help me understand the problem as you see it.

My current understanding is that these problems occur because we've mixed data in two objects of different lifetimes. So far, this is stack independent.

Correct.

Quoted 5 lines

My proposal is to correct this by moving the data back to the correct object, and make any object using it hold a reference, so this would make the provider of the block request_fn hold a reference to the queue and initialise the queue lock pointer with the lock currently in the queue. Drivers that still use a global lock would be unaffected. This

But this is the current requirement, as long as you use the queue you must hold a reference to it.

Quoted 10 lines

also means that any provider of a request_fn may expect to process (and reject) requests for a period of time after blk_cleanup_queue(). Really, this refcounting is inherent in blk_init_queue(), blk_cleanup_queue() so the only additional requirement is sanely processing queue requests after you think it's been cleaned up. This is request_fn() provider independent, I think (providers who currently don't violate the lifetime rules don't need fixing).

I claim that this proposal solves the current problem, and any other ones we run across that occur because of data mixing.

The lock is just one piece, but I guess it is the only remaining after the ->request_fn switchover killing requests. So perhaps it is just easier to embed the lock to kill off that problem.

What do you think of the attached, then? Allow NULL lock to be passed in, in which case we use the queue private lock (that no one should ever ever touch). It looks a little confusing that sdev->request_queue->queue_lock now protects some sdev structures, if you want we can retain ->sdev_lock but as a pointer to the queue lock instead.

Quoted 8 lines

Your current patch tries to solve the problem by tying the two objects together; unifying the lifetimes. I agree this can be done (it was how the sd/sr close race was fixed). But the current way the freeing functions thread across the subsystems doesn't look nice and I don't currently see a way to get the queue freed: We free the queue on scsi device release; if the queue holds a reference to the scsi_device, the release function will never be called. Our only other choice is to try to free the queue on device_del instead, but that's too early, I think.

Hmm yes, it probably doesn't work. Unless we properly embed the affected structures, I don't think it can work.

===== drivers/block/ll_rw_blk.c 1.288 vs edited =====

drivers/block/ll_rw_blk.c +9 -0
@@ -1714,6 +1711,15 @@ request_queue_t *blk_init_queue(request_
 	if (blk_init_free_list(q))
 		goto out_init;
 
+	/*
+	 * if caller didn't supply a lock, they get per-queue locking with
+	 * our embedded lock
+	 */
+	if (!lock) {
+		spin_lock_init(&q->__queue_lock);
+		lock = &q->__queue_lock;
+	}
+
 	q->request_fn		= rfn;
 	q->back_merge_fn       	= ll_back_merge_fn;
 	q->front_merge_fn      	= ll_front_merge_fn;

===== drivers/scsi/scsi_lib.c 1.153 vs edited =====

drivers/scsi/scsi_lib.c +3 -3
@@ -360,9 +360,9 @@ void scsi_device_unbusy(struct scsi_devi
 		     shost->host_failed))
 		scsi_eh_wakeup(shost);
 	spin_unlock(shost->host_lock);
-	spin_lock(&sdev->sdev_lock);
+	spin_lock(sdev->request_queue->queue_lock);
 	sdev->device_busy--;
-	spin_unlock_irqrestore(&sdev->sdev_lock, flags);
+	spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
 }
 
 /*
@@ -1425,7 +1425,7 @@ struct request_queue *scsi_alloc_queue(s
 	struct Scsi_Host *shost = sdev->host;
 	struct request_queue *q;
 
-	q = blk_init_queue(scsi_request_fn, &sdev->sdev_lock);
+	q = blk_init_queue(scsi_request_fn, NULL);
 	if (!q)
 		return NULL;
 

===== drivers/scsi/scsi_scan.c 1.143 vs edited =====

drivers/scsi/scsi_scan.c +0 -1
@@ -249,7 +249,6 @@ static struct scsi_device *scsi_alloc_sd
 	 */
 	sdev->borken = 1;
 
-	spin_lock_init(&sdev->sdev_lock);
 	sdev->request_queue = scsi_alloc_queue(sdev);
 	if (!sdev->request_queue) {
 		/* release fn is set up in scsi_sysfs_device_initialise, so

===== include/linux/blkdev.h 1.162 vs edited =====

include/linux/blkdev.h +4 -1
@@ -355,8 +364,11 @@ struct request_queue
 	unsigned long		queue_flags;
 
 	/*
-	 * protects queue structures from reentrancy
+	 * protects queue structures from reentrancy. ->__queue_lock should
+	 * _never_ be used directly, it is queue private. always use
+	 * ->queue_lock.
 	 */
+	spinlock_t		__queue_lock;
 	spinlock_t		*queue_lock;
 
 	/*

===== include/scsi/scsi_device.h 1.33 vs edited =====

include/scsi/scsi_device.h +0 -1
@@ -44,7 +44,6 @@ struct scsi_device {
 	struct list_head    same_target_siblings; /* just the devices sharing same target id */
 
 	volatile unsigned short device_busy;	/* commands actually active on low-level */
-	spinlock_t sdev_lock;           /* also the request queue_lock */
 	spinlock_t list_lock;
 	struct list_head cmd_list;	/* queue of in use SCSI Command structures */
 	struct list_head starved_entry;
Signature · 1 line
Jens Axboe
#8 lore raw
Quoted 9 lines · Jens Axboe
Quoted 5 lines · James Bottomley

My proposal is to correct this by moving the data back to the correct object, and make any object using it hold a reference, so this would make the provider of the block request_fn hold a reference to the queue and initialise the queue lock pointer with the lock currently in the queue. Drivers that still use a global lock would be unaffected. This

But this is the current requirement, as long as you use the queue you must hold a reference to it.

Exactly! that's why I think this solution must work independently of subsystem.

Quoted 6 lines

What do you think of the attached, then? Allow NULL lock to be passed in, in which case we use the queue private lock (that no one should ever ever touch). It looks a little confusing that sdev->request_queue->queue_lock now protects some sdev structures, if you want we can retain ->sdev_lock but as a pointer to the queue lock instead.

Looks good. How about the attached modification? It makes sdev_lock a pointer that uses the queue lock which we null out when we release it (not that I don't trust SCSI or anything ;-)

James

===== drivers/block/ll_rw_blk.c 1.287 vs edited =====

drivers/block/ll_rw_blk.c +9 -0
@@ -1714,6 +1714,15 @@
 	if (blk_init_free_list(q))
 		goto out_init;
 
+	/*
+	 * if caller didn't supply a lock, they get per-queue locking with
+	 * our embedded lock
+	 */
+	if (!lock) {
+		spin_lock_init(&q->__queue_lock);
+		lock = &q->__queue_lock;
+	}
+
 	q->request_fn		= rfn;
 	q->back_merge_fn       	= ll_back_merge_fn;
 	q->front_merge_fn      	= ll_front_merge_fn;

===== drivers/scsi/scsi_lib.c 1.151 vs edited =====

drivers/scsi/scsi_lib.c +3 -3
@@ -349,9 +349,9 @@
 		     shost->host_failed))
 		scsi_eh_wakeup(shost);
 	spin_unlock(shost->host_lock);
-	spin_lock(&sdev->sdev_lock);
+	spin_lock(sdev->sdev_lock);
 	sdev->device_busy--;
-	spin_unlock_irqrestore(&sdev->sdev_lock, flags);
+	spin_unlock_irqrestore(sdev->sdev_lock, flags);
 }
 
 /*
@@ -1391,7 +1391,7 @@
 	struct Scsi_Host *shost = sdev->host;
 	struct request_queue *q;
 
-	q = blk_init_queue(scsi_request_fn, &sdev->sdev_lock);
+	q = blk_init_queue(scsi_request_fn, NULL);
 	if (!q)
 		return NULL;
 

===== drivers/scsi/scsi_scan.c 1.142 vs edited =====

drivers/scsi/scsi_scan.c +2 -2
@@ -249,7 +249,6 @@
 	 */
 	sdev->borken = 1;
 
-	spin_lock_init(&sdev->sdev_lock);
 	sdev->request_queue = scsi_alloc_queue(sdev);
 	if (!sdev->request_queue) {
 		/* release fn is set up in scsi_sysfs_device_initialise, so
@@ -257,7 +256,8 @@
 		put_device(&starget->dev);
 		goto out;
 	}
-
+	/* Now make the sdev_lock point to the request queue lock */
+	sdev->sdev_lock = q->queue_lock;
 	sdev->request_queue->queuedata = sdev;
 	scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
 

===== drivers/scsi/scsi_sysfs.c 1.69 vs edited =====

drivers/scsi/scsi_sysfs.c +3 -0
@@ -168,6 +168,9 @@
 	list_del(&sdev->starved_entry);
 	spin_unlock_irqrestore(sdev->host->host_lock, flags);
 
+	/* After releasing the queue we may no longer access its lock */
+	BUG_ON(spin_is_locked(sdev->sdev_lock));
+	sdev->sdev_lock = NULL;
 	if (sdev->request_queue)
 		scsi_free_queue(sdev->request_queue);
 

===== include/linux/blkdev.h 1.161 vs edited =====

include/linux/blkdev.h +4 -1
@@ -355,8 +355,11 @@
 	unsigned long		queue_flags;
 
 	/*
-	 * protects queue structures from reentrancy
+	 * protects queue structures from reentrancy. ->__queue_lock should
+	 * _never_ be used directly, it is queue private. always use
+	 * ->queue_lock.
 	 */
+	spinlock_t		__queue_lock;
 	spinlock_t		*queue_lock;
 
 	/*

===== include/scsi/scsi_device.h 1.32 vs edited =====

include/scsi/scsi_device.h +1 -1
@@ -44,7 +44,7 @@
 	struct list_head    same_target_siblings; /* just the devices sharing same target id */
 
 	volatile unsigned short device_busy;	/* commands actually active on low-level */
-	spinlock_t sdev_lock;           /* also the request queue_lock */
+	spinlock_t *sdev_lock;           /* pointer to the request queue_lock */
 	spinlock_t list_lock;
 	struct list_head cmd_list;	/* queue of in use SCSI Command structures */
 	struct list_head starved_entry;
#9 lore raw
Quoted 21 lines · James Bottomley
Quoted 9 lines · Jens Axboe
Quoted 5 lines · James Bottomley

My proposal is to correct this by moving the data back to the correct object, and make any object using it hold a reference, so this would make the provider of the block request_fn hold a reference to the queue and initialise the queue lock pointer with the lock currently in the queue. Drivers that still use a global lock would be unaffected. This

But this is the current requirement, as long as you use the queue you must hold a reference to it.

Exactly! that's why I think this solution must work independently of subsystem.

Quoted 6 lines

What do you think of the attached, then? Allow NULL lock to be passed in, in which case we use the queue private lock (that no one should ever ever touch). It looks a little confusing that sdev->request_queue->queue_lock now protects some sdev structures, if you want we can retain ->sdev_lock but as a pointer to the queue lock instead.

Quoted 3 lines

Looks good. How about the attached modification? It makes sdev_lock a pointer that uses the queue lock which we null out when we release it (not that I don't trust SCSI or anything ;-)

Do we really need the sdev_lock pointer? There's just a single place where we're using it and the code would be much more clear if it had just one name.

#10 lore raw
Quoted 22 lines · Christoph Hellwig
Quoted 21 lines · James Bottomley
Quoted 9 lines · Jens Axboe
Quoted 5 lines · James Bottomley

My proposal is to correct this by moving the data back to the correct object, and make any object using it hold a reference, so this would make the provider of the block request_fn hold a reference to the queue and initialise the queue lock pointer with the lock currently in the queue. Drivers that still use a global lock would be unaffected. This

But this is the current requirement, as long as you use the queue you must hold a reference to it.

Exactly! that's why I think this solution must work independently of subsystem.

Quoted 6 lines

What do you think of the attached, then? Allow NULL lock to be passed in, in which case we use the queue private lock (that no one should ever ever touch). It looks a little confusing that sdev->request_queue->queue_lock now protects some sdev structures, if you want we can retain ->sdev_lock but as a pointer to the queue lock instead.

Quoted 7 lines
Quoted 3 lines

Looks good. How about the attached modification? It makes sdev_lock a pointer that uses the queue lock which we null out when we release it (not that I don't trust SCSI or anything ;-)

Do we really need the sdev_lock pointer? There's just a single place where we're using it and the code would be much more clear if it had just one name.

A comment would work equally well, and save space of course :-)

Signature · 1 line
Jens Axboe
#17 lore raw
In reply to James Bottomley
Quoted 21 lines · James Bottomley
Quoted 9 lines · Jens Axboe
Quoted 5 lines · James Bottomley

My proposal is to correct this by moving the data back to the correct object, and make any object using it hold a reference, so this would make the provider of the block request_fn hold a reference to the queue and initialise the queue lock pointer with the lock currently in the queue. Drivers that still use a global lock would be unaffected. This

But this is the current requirement, as long as you use the queue you must hold a reference to it.

Exactly! that's why I think this solution must work independently of subsystem.

Quoted 6 lines

What do you think of the attached, then? Allow NULL lock to be passed in, in which case we use the queue private lock (that no one should ever ever touch). It looks a little confusing that sdev->request_queue->queue_lock now protects some sdev structures, if you want we can retain ->sdev_lock but as a pointer to the queue lock instead.

Quoted 3 lines

Looks good. How about the attached modification? It makes sdev_lock a pointer that uses the queue lock which we null out when we release it (not that I don't trust SCSI or anything ;-)

That's fine with me, up to you. As I mentioned, it does look less confusing to have the lock associated with sdev still.

Signature · 1 line
Jens Axboe
#11 lore raw
In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

Do we really need the sdev_lock pointer? There's just a single place where we're using it and the code would be much more clear if it had just one name.

Humour me for a while. I don't believe we have any way the lock can be used after calling queue free, but nulling the sdev_lock pointer will surely catch them. If nothing turns up after a few kernel revisions, feel free to kill it.

James

#12 lore raw
Quoted 9 lines · James Bottomley
Quoted 3 lines · Christoph Hellwig

Do we really need the sdev_lock pointer? There's just a single place where we're using it and the code would be much more clear if it had just one name.

Humour me for a while. I don't believe we have any way the lock can be used after calling queue free, but nulling the sdev_lock pointer will surely catch them. If nothing turns up after a few kernel revisions, feel free to kill it.

I think Christophs point is that why add sdev_lock as a pointer, instead of just killing it? It's only used in one location, so it's not really that confusing (and a comment could fix that).

Signature · 1 line
Jens Axboe
#13 lore raw
Quoted 3 lines · Jens Axboe

I think Christophs point is that why add sdev_lock as a pointer, instead of just killing it? It's only used in one location, so it's not really that confusing (and a comment could fix that).

Because any use of sdev->request_queue->queue_lock would likely succeed even after we've freed the device and released the queue. If it's a pointer and we null it after free and release, then any later use will trigger an immediate NULL deref oops.

Since we've had so many nasty problems around refcounting, I just would like to assure myself that we're doing everything correctly (I really believe we are, but empirical evidence is also nice).

James

#14 lore raw
Quoted 9 lines · James Bottomley
Quoted 3 lines · Jens Axboe

I think Christophs point is that why add sdev_lock as a pointer, instead of just killing it? It's only used in one location, so it's not really that confusing (and a comment could fix that).

Because any use of sdev->request_queue->queue_lock would likely succeed even after we've freed the device and released the queue. If it's a pointer and we null it after free and release, then any later use will trigger an immediate NULL deref oops.

So clear ->request_queue instead.

Signature · 1 line
Jens Axboe
#15 lore raw
Quoted 1 line · Jens Axboe

So clear ->request_queue instead.

Will do. Did you want me to look after your patch and add this, or do you want to send it to Linus (after the purdah is over)?

James

#16 lore raw
Quoted 6 lines · James Bottomley
Quoted 1 line · Jens Axboe

So clear ->request_queue instead.

Will do. Did you want me to look after your patch and add this, or do you want to send it to Linus (after the purdah is over)?

Just queue it with the rest of your changes, that is fine with me.

Signature · 1 line
Jens Axboe