[haiku-development] Re: fstrim: Call for testing

Hi Axel,

On Mon, Oct 28, 2013 at 7:15 PM, Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> wrote:
> 9) Report back to me.
>

Some further information:

After digging a little further, a few problems became clear. Not
directly relevant to this issue, but needing to be fixed nonetheless,
copy_trim_data_from_user() leaks the malloc'd buffer in the error case
where the final memcpy fails.

The bad address error I was encountering comes from the same function,
but for a different reason. The BFS block allocator ultimately calls
the B_TRIM_DEVICE ioctl in order to send the command over to the disk
driver. However, the latter currently assumes that the passed in
buffer is always from userland and calls copy_trim_data_from_user(),
which immediately bails out since it was passed a kernel address
rather than a user one as a source[1]. I added a quick test to that to
see if it is in fact a user address and if not, to simply
allocate/memcpy it directly rather than call
copy_trim_data_from_user(). This gets us further, but then fails as
follows:

KERN: bfs: mounted "HaikuTest" (root node at 49152, device =
/dev/disk/scsi/0/0/0/3)
KERN: _TrimNext(index 0, offset 4814848, size 28739584)
KERN: _TrimNext(index 1, offset 33576960, size 33531904)
KERN: _TrimNext(index 2, offset 68388864, size 32274432)
KERN: _TrimNext(index 3, offset 100669440, size 33548288)
KERN: _TrimNext(index 4, offset 134238208, size 4075520)
KERN: SCSI -- scsi_async_io: Asynchronous SCSI I/O requires S/G list
(data is 88 bytes)
KERN: periph_check_error: Data transmission failed
KERN: SCSI -- scsi_async_io: Asynchronous SCSI I/O requires S/G list
(data is 88 bytes)
KERN: periph_check_error: Data transmission failed
KERN: SCSI -- scsi_async_io: Asynchronous SCSI I/O requires S/G list
(data is 88 bytes)
KERN: periph_check_error: Data transmission failed
KERN: SCSI -- scsi_async_io: Asynchronous SCSI I/O requires S/G list
(data is 88 bytes)
KERN: periph_check_error: Data transmission failed

Unfortunately, at this point I'm completely clueless as far as the
SCSI layer goes, and have no idea what's needed/wrong as relates to
the above. Any thoughts?

Regards,

Rene

[1] 
https://github.com/axeld/haiku/blob/trim/src/add-ons/kernel/drivers/disk/scsi/scsi_disk/scsi_disk.cpp#L419

Other related posts: