mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Beckett <bob.beckett@collabora.com>
To: "\"Paweł Anikiel\"" <panikiel@google.com>
Cc: "axboe" <axboe@kernel.dk>, "hch" <hch@lst.de>,
	"kbusch" <kbusch@kernel.org>, "kernel" <kernel@collabora.com>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	"linux-nvme" <linux-nvme@lists.infradead.org>,
	"sagi" <sagi@grimberg.me>
Subject: Re: [PATCH] nvme-pci: 512 byte aligned dma pool segment quirk
Date: Thu, 14 Nov 2024 13:24:08 +0000	[thread overview]
Message-ID: <1932ad8722a.102613bdb3737.769617317074446742@collabora.com> (raw)
In-Reply-To: <20241114113803.3571128-1-panikiel@google.com>






 ---- On Thu, 14 Nov 2024 11:38:03 +0000  Paweł Anikiel  wrote --- 
 > Hi all,
 > 
 > I've been tracking down an issue that seems to be related (identical?) to
 > this one, and I would like to propose a different fix.
 > 
 > I have a device with the aforementioned NVMe-eMMC bridge, and I was
 > experiencing nvme read timeouts after updating the kernel from 5.15 to
 > 6.6. Doing a kernel bisect, I arrived at the same dma pool commit as
 > Robert in the original thread.
 > 
 > After trying out some changes in the nvme-pci driver, I came up with the
 > same fix as in this thread: change the alignment of the small pool to
 > 512. However, I wanted to get a deeper understanding of what's going on.
 > 
 > After a lot of analysis, I found out why the nvme timeouts were happening:
 > The bridge incorrectly implements PRP list chaining.
 > 
 > When doing a read of exactly 264 sectors, and allocating a PRP list with
 > offset 0xf00, the last PRP entry in that list lies right before a page
 > boundary.  The bridge incorrectly (?) assumes that it's a pointer to a
 > chained PRP list, tries to do a DMA to address 0x0, gets a bus error,
 > and crashes.
 > 
 > When doing a write of 264 sectors with PRP list offset of 0xf00,
 > the bridge treats data as a pointer, and writes incorrect data to
 > the drive. This might be why Robert is experiencing fs corruption.
 > 
 > So if my findings are right, the correct quirk would be "don't make PRP
 > lists ending on a page boundary".

This is interesting.
I had the same idea previously. I initially just changed the hard coded 256 / 8 to use 31 instead, which should have ensured the last entry of each segment never gets used.
When I tested that, it not longer failed, which was a good sign. So then I modified it to only do that on the last 256 byte segment of a page, but then is started failing again.
This lead me to believe it was not a chaining issue specifically, so I went looking for other hypotheses, eventually setting on 512 byte alignment.
I never saw any bus error during my testing, just wrong data read, which then fails image verification. I was expecting iommu error logs if it was trying to access a chain in to nowhere if it always interpreted last entry in page as a link. I never saw any iommu errors.

 > 
 > Changing the small dma pool alignment to 512 happens to fix the issue
 > because it never allocates a PRP list with offset 0xf00. Theoretically,
 > the issue could still happen with the page pool, but this bridge has
 > a max transfer size of 64 pages, which is not enough to fill an entire
 > page-sized PRP list.
 > 
 > Robert, could you check that the fs corruption happens only after
 > transfers of size 257-264 and PRP list offset of 0xf00? This would
 > confirm my theory.

I'd be glad to if you could share your testing method.
Currently I use a desync image verification which does lots of reads in parallel and is the only method I've found so far that can repro in a reasonable amount of time.

 > 



  parent reply	other threads:[~2024-11-14 13:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-12 19:50 Bob Beckett
2024-11-12 20:47 ` Keith Busch
2024-11-13  4:31 ` Christoph Hellwig
2024-11-13 18:05   ` Keith Busch
2024-11-13 20:08     ` Robert Beckett
2024-11-14  5:55     ` Christoph Hellwig
2024-11-14 13:10       ` Robert Beckett
2024-11-14 11:38 ` Paweł Anikiel
2024-11-14 12:17   ` Christoph Hellwig
2024-11-14 15:37     ` Keith Busch
2024-11-14 13:24   ` Robert Beckett [this message]
2024-11-14 14:13     ` Paweł Anikiel
2024-11-14 16:28       ` Robert Beckett
2024-11-22 19:36         ` Keith Busch
2024-12-09 12:32           ` Robert Beckett
2024-12-09 15:33             ` Paweł Anikiel
2024-12-10 21:36               ` Keith Busch
2024-12-11 10:55                 ` Robert Beckett
2024-12-17 11:18                   ` Paweł Anikiel
2024-11-14 15:46   ` Keith Busch
2024-11-14 16:47     ` Robert Beckett
2024-11-14 18:00 ` Keith Busch
2024-11-14 18:01   ` Jens Axboe
2024-11-25 11:01 ` Niklas Cassel

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=1932ad8722a.102613bdb3737.769617317074446742@collabora.com \
    --to=bob.beckett@collabora.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=panikiel@google.com \
    --cc=sagi@grimberg.me \
    /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

all inboxes | Powered by JetHome®