public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Badari Pulavarty <pbadari@us.ibm.com>
To: "Justin T. Gibbs" <gibbs@scsiguy.com>,
	Kernel Mailinglist <linux-kernel@vger.kernel.org>,
	linux-scsi@vger.kernel.org
Cc: Berkley Shands <berkley@cs.wustl.edu>
Subject: Re: [BUG] x86_64 pci_map_sg modifies sg list - fails multiple map/unmaps
Date: Mon, 5 Jan 2004 11:41:52 -0800	[thread overview]
Message-ID: <200401051141.52236.pbadari@us.ibm.com> (raw)
In-Reply-To: <2938942704.1073325455@aslan.btc.adaptec.com>

On Monday 05 January 2004 09:57 am, Justin T. Gibbs wrote:
> Berkley Shands recently tripped over this problem.  The 2.6.X pci_map_sg
> code for x86_64 modifies the passed in S/G list to compact it for mapping
> by the GART.  This modification is not reversed when pci_unmap_sg is
> called.  In the case of a retried SCSI command, this causes any attempt
> to map the command a second time to fail with a BUG assertion since the
> nseg parameter passed into the second map call is state.  nseg comes from
> the "use_sg" field in the SCSI command structure which is never touched
> by the HBA drivers invoking pci_map_sg.
>
> DMA-API.txt doesn't seem to cover this issue.  Should the low-level DMA
> code restore the S/G list to its original state on unmap or should the
> SCSI HBA drivers be changed to update "use_sg" with the segment count
> reported by the pci_map_sg() API?  If the latter, this seems to contradict
> the mandate in DMA-API that the nseg parameter passed into the unmap call
> be the same as that passed into the map call.  Most of the kernel assumes
> that an S/G list can be mapped an unmapped multiple times using the same
> arguments.  This doesn't seem to me to be an unreasonable expectation.

Hi,

I ran into the same thing a month ago. I talked to Andi Kleen about this.
He seems to think that, it is okay to modify the sg-list in pci_map_sg().
pci_unmap_sg() can't restore it back, since we lost lot of information.
One option is to recreate entire sg-list in case of a retry. I used a patch 
similar to following to do this. Is this acceptable ?

Thanks,
Badari

--- scsi_lib.c  2004-01-04 19:53:56.000000000 -0800
+++ scsi_lib.c.new      2004-01-04 19:57:35.000000000 -0800
@@ -308,6 +308,13 @@ void scsi_setup_cmd_retry(struct scsi_cm
        cmd->cmd_len = cmd->old_cmd_len;
        cmd->sc_data_direction = cmd->sc_old_data_direction;
        cmd->underflow = cmd->old_underflow;
+       if (cmd->use_sg) {
+               struct request     *req = cmd->request;
+               int count;
+
+               count = blk_rq_map_sg(req->q, req, cmd->request_buffer);
+               BUG_ON(count != cmd->use_sg);
+       }
 }



  parent reply	other threads:[~2004-01-05 20:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-05 17:57 [BUG] x86_64 pci_map_sg modifies sg list - fails multiple map/unmaps Justin T. Gibbs
2004-01-05 19:22 ` David S. Miller
2004-01-05 19:41 ` Badari Pulavarty [this message]
2004-01-05 19:47 ` Andi Kleen
2004-01-05 20:04   ` Justin T. Gibbs
2004-01-05 20:35   ` David S. Miller
2004-01-05 21:10     ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2004-01-05 19:29 Berkley Shands
2004-01-05 19:28 ` David S. Miller
2004-01-05 20:00 Berkley Shands
     [not found] <2938942704.1073325455@aslan.btc.adaptec.com.suse.lists.linux.kernel>
     [not found] ` <m3brpi41q0.fsf@averell.firstfloor.org.suse.lists.linux.kernel>
     [not found]   ` <2997092704.1073333041@aslan.btc.adaptec.com.suse.lists.linux.kernel>
2004-01-05 20:58     ` Andi Kleen
     [not found] <200401051929.i05JTsM0000014248@mudpuddle.cs.wustl.edu.suse.lists.linux.kernel>
     [not found] ` <20040105112800.7a9f240b.davem@redhat.com.suse.lists.linux.kernel>
2004-01-05 21:02   ` Andi Kleen
2004-01-05 21:01     ` David S. Miller
2004-01-05 21:31       ` Andi Kleen
2004-01-06  0:05         ` James Bottomley
2004-01-06  3:06           ` Andi Kleen
2004-01-06  3:04             ` David S. Miller
2004-01-06  3:14               ` James Bottomley
2004-01-07 15:35 Berkley Shands
2004-01-07 19:19 ` badari
2004-01-07 16:33 Berkley Shands

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=200401051141.52236.pbadari@us.ibm.com \
    --to=pbadari@us.ibm.com \
    --cc=berkley@cs.wustl.edu \
    --cc=gibbs@scsiguy.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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