All of lore.kernel.org
 help / color / mirror / Atom feed
* SCSI kobject unregistration ordering problem
@ 2003-10-13 22:12 Andrew Morton
  2003-10-13 23:01 ` Mike Anderson
  2003-10-17 12:34 ` Christoph Hellwig
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2003-10-13 22:12 UTC (permalink / raw)
  To: linux-scsi; +Cc: Patrick Mochel, Greg KH, Andrey Borzenkov


Guys,

I have the below patch queued, but Greg and Pat don't like it because

> > For one, the fact a parent is unregistered before its children violates
> > the intended semantics of the interface. #$^!@#$ SCSI. They know this, and
> > they should not be doing it.
>
> Exactly, that's why I do not want this patch applied.  The SCSI people
> have said they would fix this problem, as they should.  Let's not paper
> over the issue with this kobject patch.

So it looks like SCSI needs fixing.  Could someone please take care of this?
Thanks.




From: Andrey Borzenkov <arvidjaar@mail.ru>

It is possible that parent is removed before child when child is in use. 
Trivial example is mounted USB storage when you unplug it. The kobject for 
USB device is removed but subordinate SCSI device remains. Then kernel oopses 
on attempt to release child e.g. umount removed USB storage. This patch fixes 
two problems:

- kset_hotplug.  It oopses in get_kobj_path_length because child->parent
  points to nowhere - even if parent has not yet been overwritten, its name
  is already freed.

  The patch moves kobject_put for parent from unlink() into
  kobject_cleanup for child making sure reference to parents exists for as
  long as child is there and may use it.

- after this oops has been fixed I got next one now in sysfs.  The
  problem is sysfs_remove_dir would unlink all children including
  directories for subordinate kobjects.  Resulting in dget/dput mismatch. 
  I usually got oops due to the fact that d_delete in remove_dir would free
  inode and then simple_rmdir would try to access it.

  The patch avoids calling extra d_delete/unlink on already-deleted
  dentry.  I hate this patch but anything better apparently requires
  complete redesign of sysfs implementation.  Unlinking busy directory is
  otherwise impossible and I am afraid it will show itself somewhere else.



 25-akpm/fs/sysfs/dir.c |   12 ++++++++++--
 25-akpm/lib/kobject.c  |    4 ++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff -puN fs/sysfs/dir.c~kobject-oops-fixes fs/sysfs/dir.c
--- 25/fs/sysfs/dir.c~kobject-oops-fixes	Thu Oct  9 01:46:51 2003
+++ 25-akpm/fs/sysfs/dir.c	Thu Oct  9 01:46:51 2003
@@ -82,8 +82,16 @@ static void remove_dir(struct dentry * d
 {
 	struct dentry * parent = dget(d->d_parent);
 	down(&parent->d_inode->i_sem);
-	d_delete(d);
-	simple_rmdir(parent->d_inode,d);
+	/*
+	 * It is possible that parent has already been removed, in which
+	 * case directory is already unhashed and dput.
+	 * Note that this won't update parent->d_inode->i_nlink; OTOH
+	 * parent should already be dead
+	 */
+	if (!d_unhashed(d)) {
+		d_delete(d);
+		simple_rmdir(parent->d_inode,d);
+	}
 
 	pr_debug(" o %s removing done (%d)\n",d->d_name.name,
 		 atomic_read(&d->d_count));
diff -puN lib/kobject.c~kobject-oops-fixes lib/kobject.c
--- 25/lib/kobject.c~kobject-oops-fixes	Thu Oct  9 01:46:51 2003
+++ 25-akpm/lib/kobject.c	Thu Oct  9 01:46:51 2003
@@ -236,8 +236,6 @@ static void unlink(struct kobject * kobj
 		list_del_init(&kobj->entry);
 		up_write(&kobj->kset->subsys->rwsem);
 	}
-	if (kobj->parent) 
-		kobject_put(kobj->parent);
 	kobject_put(kobj);
 }
 
@@ -457,6 +455,8 @@ void kobject_cleanup(struct kobject * ko
 	if (kobj->k_name != kobj->name)
 		kfree(kobj->k_name);
 	kobj->k_name = NULL;
+	if (kobj->parent)
+		kobject_put(kobj->parent);
 	if (t && t->release)
 		t->release(kobj);
 	if (s)

_


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SCSI kobject unregistration ordering problem
  2003-10-13 22:12 SCSI kobject unregistration ordering problem Andrew Morton
@ 2003-10-13 23:01 ` Mike Anderson
  2003-10-17 12:34 ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Anderson @ 2003-10-13 23:01 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-scsi, Patrick Mochel, Greg KH, Andrey Borzenkov, viro

Andrew Morton [akpm@osdl.org] wrote:
> 
> Guys,
> 
> I have the below patch queued, but Greg and Pat don't like it because
> 
> > > For one, the fact a parent is unregistered before its children violates
> > > the intended semantics of the interface. #$^!@#$ SCSI. They know this, and
> > > they should not be doing it.
> >
> > Exactly, that's why I do not want this patch applied.  The SCSI people
> > have said they would fix this problem, as they should.  Let's not paper
> > over the issue with this kobject patch.
> 
> So it looks like SCSI needs fixing.  Could someone please take care of this?
> Thanks.
> 

I will get back on this. As I previously stated in the thread below the
patch makes the problem go away, but is not the right fix for the "real"
problem. The issues of the delayed call to device_del causes other get /
put issues for changes Christoph is trying to do. I thought there was a
need for another release function in the block layer for cases of
surprise disconnect, but I will get more current data by changing a view
to not delay the call to device_del.

http://marc.theaimsgroup.com/?l=linux-kernel&m=106401215205983&w=2

-andmike
--
Michael Anderson
andmike@us.ibm.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SCSI kobject unregistration ordering problem
  2003-10-13 22:12 SCSI kobject unregistration ordering problem Andrew Morton
  2003-10-13 23:01 ` Mike Anderson
@ 2003-10-17 12:34 ` Christoph Hellwig
  2003-10-17 15:50   ` Mike Anderson
  1 sibling, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2003-10-17 12:34 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-scsi, Patrick Mochel, Greg KH, Andrey Borzenkov

On Mon, Oct 13, 2003 at 03:12:54PM -0700, Andrew Morton wrote:
> So it looks like SCSI needs fixing.  Could someone please take care of this?
> Thanks.

This needs fixing deeper down in the block layer and Al is working on
that.  Once the block layer has sane semantics for device_del vs partitions
scsi can be fixed trivially.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SCSI kobject unregistration ordering problem
  2003-10-17 12:34 ` Christoph Hellwig
@ 2003-10-17 15:50   ` Mike Anderson
  2003-10-20 17:07     ` Mike Anderson
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Anderson @ 2003-10-17 15:50 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, linux-scsi, Patrick Mochel, Greg KH, Andrey Borzenkov

Christoph Hellwig [hch@infradead.org] wrote:
> On Mon, Oct 13, 2003 at 03:12:54PM -0700, Andrew Morton wrote:
> > So it looks like SCSI needs fixing.  Could someone please take care of this?
> > Thanks.
> 
> This needs fixing deeper down in the block layer and Al is working on
> that.  Once the block layer has sane semantics for device_del vs partitions
> scsi can be fixed trivially.

While I have it working now without the block layer changes (i.e., no
delayed device_del call in SCSI). I also thought there was something
needed in the block layer, there may still need to be block layer
updates for other issues but I am currently not seeing them in my
testing. The issue scsi was having is related to sd_remove freeing the
scsi_disk structure to early in some cases. Since sd passed the
scsi_disk structure to the block layer subsystem in a gendisk private
data pointer sd needs to use a ref count / release function model to
know when to free scsi_disk. I am almost done with a few surprise
removal test cases and will post the patch for review today.

-andmike
--
Michael Anderson
andmike@us.ibm.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SCSI kobject unregistration ordering problem
  2003-10-17 15:50   ` Mike Anderson
@ 2003-10-20 17:07     ` Mike Anderson
  2003-11-02  9:08       ` Andrey Borzenkov
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Anderson @ 2003-10-20 17:07 UTC (permalink / raw)
  To: Christoph Hellwig, Andrew Morton, linux-scsi, Patrick Mochel,
	Greg KH, Andrey Borzenkov

Mike Anderson [andmike@us.ibm.com] wrote:
> 
> While I have it working now without the block layer changes (i.e., no
> delayed device_del call in SCSI). I also thought there was something
> needed in the block layer, there may still need to be block layer
> updates for other issues but I am currently not seeing them in my
> testing. The issue scsi was having is related to sd_remove freeing the
> scsi_disk structure to early in some cases. Since sd passed the
> scsi_disk structure to the block layer subsystem in a gendisk private
> data pointer sd needs to use a ref count / release function model to
> know when to free scsi_disk. I am almost done with a few surprise
> removal test cases and will post the patch for review today.
> 

I posted Friday adding a release call to the scsi_disk structure and
removing the delay call to device_del. On test8 this corrected the
problem I was seeing of surprise removal with a mounted device. A pointer
to the patch in the archive is below.

http://marc.theaimsgroup.com/?l=linux-scsi&m=106646263401437&w=2

I will work today to send this patch to others that have posted bugzilla
bugs related to this same failure mode and see if this patch corrects
there problem.

Based on feedback I will update the patch and repost to linux-scsi and
lkml.

-andmike
--
Michael Anderson
andmike@us.ibm.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SCSI kobject unregistration ordering problem
  2003-10-20 17:07     ` Mike Anderson
@ 2003-11-02  9:08       ` Andrey Borzenkov
  0 siblings, 0 replies; 6+ messages in thread
From: Andrey Borzenkov @ 2003-11-02  9:08 UTC (permalink / raw)
  To: Mike Anderson, Christoph Hellwig, Andrew Morton, linux-scsi,
	Patrick Mochel, Greg KH

On Monday 20 October 2003 21:07, Mike Anderson wrote:
[...]
>
> I posted Friday adding a release call to the scsi_disk structure and
> removing the delay call to device_del. On test8 this corrected the
> problem I was seeing of surprise removal with a mounted device. A pointer
> to the patch in the archive is below.
>
> http://marc.theaimsgroup.com/?l=linux-scsi&m=106646263401437&w=2
>

sorry for late answer, I did not realize patch was already in kernel till I 
attempted to apply it.

This fixed the problem just fine, thank you.

-andrey


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-11-02  9:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-13 22:12 SCSI kobject unregistration ordering problem Andrew Morton
2003-10-13 23:01 ` Mike Anderson
2003-10-17 12:34 ` Christoph Hellwig
2003-10-17 15:50   ` Mike Anderson
2003-10-20 17:07     ` Mike Anderson
2003-11-02  9:08       ` Andrey Borzenkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.