From: James Bottomley <James.Bottomley@steeleye.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: SCSI development list <linux-scsi@vger.kernel.org>
Subject: Re: Is it safe to do DMA directly into scmd->sense_buffer?
Date: 22 Jun 2003 12:06:24 -0500 [thread overview]
Message-ID: <1056301585.1979.58.camel@mulgrave> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0306221200050.434-100000@netrider.rowland.org>
On Sun, 2003-06-22 at 11:09, Alan Stern wrote:
> When retrieving sense data for a failed command, is it safe to transfer
> the data by DMA directly into scmd->sense_buffer? My guess is that on
> architectures that have non-cache-coherent DMA, it's _not_.
>
> The reason is that there is no guarantee the SCSI core won't touch the
> scmd structure while the I/O is taking place. For instance, should the
> abort timer expire, the error-handler thread might very well end up
> reading or writing data falling in the same cache line as the
> sense_buffer. That would corrupt the CPU's view of data transferred from
> the device.
>
> But maybe there's some provision for taking care of this I'm not aware of.
> If anyone can supply the correct answer, my sense-bounce-buffer and I
> would appreciate it.
The answer's yes, it is safe. This is how it works:
The only way you could get the scenario you describe is if the command
times out while the driver is doing an auto request sense. This would
be highly unlikely, because usually either we lose the command or we get
sense back quickly (remember, the entire device suspends normal
operations on a contingent allegiance condition, so all it has to do is
service our sense request).
Now, even assuming the above happens, the only problem would be that the
sense data itself could be corrupted by an interfering cache line (since
the DMA direction is to the sense buffer, the current model holds that
you flush and invalidate the cache line before beginning the dma. Thus,
if the CPU brings the cache line in again the only thing it may miss is
the fact that DMA has altered data it has cached).
This was argued about a long time ago, the upshot being that the pain of
doing it correctly was offset by the fact that it didn't seem to have
any observable consequences.
James
next prev parent reply other threads:[~2003-06-22 16:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-22 16:09 Is it safe to do DMA directly into scmd->sense_buffer? Alan Stern
2003-06-22 17:06 ` James Bottomley [this message]
2003-07-17 14:50 ` Comments about the __scsi_mode_sense() routine Alan Stern
2003-07-17 15:47 ` James Bottomley
2003-07-17 19:51 ` Alan Stern
2003-07-30 20:36 ` PATCH: (as73) Do a minimal transfer for disk-cache mode-sense page Alan Stern
2003-07-30 21:04 ` James Bottomley
2003-07-31 15:12 ` Revised PATCH: (as73b) " Alan Stern
2003-07-31 19:53 ` PATCH: (as70b) Update request_bufflen to match this_count 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=1056301585.1979.58.camel@mulgrave \
--to=james.bottomley@steeleye.com \
--cc=linux-scsi@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox