All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Patrick Mansfield <patmans@us.ibm.com>
Cc: SCSI development list <linux-scsi@vger.kernel.org>,
	USB development list <linux-usb-devel@lists.sourceforge.net>
Subject: Unaligned scatter-gather buffers and usb-storage
Date: Tue, 18 Nov 2003 10:20:17 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.0311181001030.735-100000@ida.rowland.org> (raw)
In-Reply-To: <20031110095914.B22518@beaverton.ibm.com>

Although most scatter-gather buffers are page aligned, occasionally one of 
them isn't.  This can happen when the sg and st drivers use direct I/O and 
the user's buffer doesn't start on a page boundary; the first s-g buffer 
in the list will coincide with the start of the user buffer even though 
all the later ones will start at page boundaries.

The usb-storage driver has trouble with unaligned buffers.  More 
accurately, it has trouble with s-g entries having bad lengths.  A buffer 
that occupies an entire page or is the _last_ entry in the s-g list is 
okay, but if the _first_ entry isn't aligned properly it is likely to have 
a bad length.

[For linux-scsi readers: This has to do with the way USB works.  Data
transfers are divided up into packets, and packets have a maximum size
(typically 64 or 512 bytes).  A packet can't span two s-g entries; hence
if an s-g entry's length isn't divisible by the maxpacket size then one of
the packets for that entry must be short, i.e., smaller than the maximum
size.  But USB specifies that short packets always indicate the end of a
transfer.  Thus if any s-g entry but the last has a bad length, the data
transfer will terminate prematurely.]

Alignment to a 512-byte boundary would suffice and page alignment would be
more than enough.  The cleanest way to fix the problem would be to have st
and sg refuse to do direct I/O when the user's buffer isn't page aligned.  
That's probably too draconian (but it would allow us to give the user
process an appropriate error code right away).

So instead I'm going to change the usb-storage driver to make it reject
any s-g transfer that doesn't meet the entry length requirements.  My
question is this: What's the best way to inform the SCSI midlayer about
what went wrong?  Return a DID_ABORT code?  Or would something else be
better?

Alan Stern


  parent reply	other threads:[~2003-11-18 15:20 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1068207145.3fab8c2988d43@webmail.netregistry.net>
2003-11-07 16:21 ` usb-storage and Sony Handycam Alan Stern
2003-11-07 17:29   ` Patrick Mansfield
2003-11-07 19:49     ` Alan Stern
2003-11-08  2:54       ` Dmitri Katchalov
2003-11-08  6:34         ` Patrick Mansfield
2003-11-08 13:29           ` Dmitri Katchalov
2003-11-08 16:28           ` Alan Stern
2003-11-08 20:37             ` Patrick Mansfield
2003-11-09  3:47               ` [linux-usb-devel] " Alan Stern
2003-11-09  8:45                 ` Dmitri Katchalov
2003-11-10 20:45                   ` Patrick Mansfield
2003-11-10 17:59                 ` Patrick Mansfield
2003-11-10 18:46                   ` Alan Stern
2003-11-10 19:04                     ` [linux-usb-devel] " Patrick Mansfield
2003-11-10 19:57                       ` Alan Stern
2003-11-10 22:46                     ` Sancho Dauskardt
2003-11-18 15:20                   ` Alan Stern [this message]
2003-11-18 22:37                     ` Unaligned scatter-gather buffers and usb-storage Patrick Mansfield
2003-11-19  8:47                       ` Jens Axboe
2003-11-19 13:01                         ` [linux-usb-devel] " Oliver Neukum
2003-11-19 13:04                           ` Jens Axboe
2003-11-19 14:37                             ` James Bottomley
2003-11-19 14:39                               ` Jens Axboe
2003-11-19 14:58                                 ` James Bottomley
2003-11-19 15:00                                   ` [linux-usb-devel] " Jens Axboe
2003-11-19 16:56                                     ` Kai Makisara
2003-11-19 20:19                                       ` Jens Axboe
2003-11-19 22:06                                         ` Kai Makisara
2003-11-20  6:53                                           ` Jens Axboe
2003-11-20 15:20                                             ` Alan Stern
2003-11-20 15:30                                               ` Jens Axboe
2003-11-20 16:09                                                 ` Alan Stern
2003-11-20 16:24                                                   ` Jens Axboe
2003-11-20 16:28                                                 ` [linux-usb-devel] " Oliver Neukum
2003-11-20 19:23                                                   ` Kai Makisara
2003-11-20 17:18                                               ` Kai Makisara
2003-11-20 19:18                                                 ` [linux-usb-devel] " Kai Mäkisara
2003-11-21 18:03                                                   ` PATCH: (as141) " Alan Stern
2003-11-21 20:07                                                     ` Kai Makisara
2003-12-01  1:30                                                     ` Matthew Dharm
2004-01-05  0:41                                                     ` Matthew Dharm
2004-01-05 10:08                                                       ` Jens Axboe
2004-01-05 21:58                                                         ` PATCH: (as141b) " Alan Stern
2004-01-06 11:28                                                           ` Oliver Neukum
2004-01-06 16:10                                                             ` Alan Stern
2004-02-02 15:51                                                           ` James Bottomley
2004-02-03 15:47                                                             ` Alan Stern
2004-02-03 15:55                                                               ` James Bottomley
2004-02-03 16:02                                                               ` Matthew Wilcox
2003-11-19 15:44                         ` Alan Stern
2003-11-19 15:49                           ` Jens Axboe
2003-11-19 16:58                             ` Alan Stern
2003-11-19 17:03                               ` Jens Axboe
2003-11-07 22:09     ` usb-storage and Sony Handycam Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44L0.0311181001030.735-100000@ida.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=patmans@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.