Re: Race in removal of host class device attribute file

Christoph Hellwig
2003-10-17T12:30:13Z

On Thu, Oct 16, 2003 at 05:09:04PM -0400, Alan Stern wrote:
> I've created a class device attribute file for the hosts supported by the
> usb-storage driver, using the shost_attrs member of the host template.
> It seems to contain an intractable race condition when unregistering the
> host. There's no way for the driver to know when the scsi host's class
> device is released, so there's no way to know when it's safe to deallocate
> the host's driver-specific data structure. Waiting until
> scsi_remove_host() returns isn't good enough, because a user process might
> keep the attribute file open and thus prevent release of the class device
> indefinitely.

What's the problem with that? Yes, that means a user process can lock
the memory into core, but we do this in many places. General rule
of the thumb is that a driver may only release data after scsi_remove_host()
returns for per-host data or in ->slave_destroy() for per-device data.