lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 15 Feb 2024 16:26:23 -0800
From: Nicolin Chen <nicolinc@...dia.com>
To: Will Deacon <will@...nel.org>
CC: <sagi@...mberg.me>, <hch@....de>, <axboe@...nel.dk>, <kbusch@...nel.org>,
	<joro@...tes.org>, <robin.murphy@....com>, <jgg@...dia.com>,
	<linux-nvme@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
	<iommu@...ts.linux.dev>, <murphyt7@....ie>, <baolu.lu@...ux.intel.com>
Subject: Re: [PATCH v1 0/2] nvme-pci: Fix dma-iommu mapping failures when
 PAGE_SIZE=64KB

On Thu, Feb 15, 2024 at 04:35:45PM +0000, Will Deacon wrote:
> On Thu, Feb 15, 2024 at 02:22:09PM +0000, Will Deacon wrote:
> > On Wed, Feb 14, 2024 at 11:57:32AM -0800, Nicolin Chen wrote:
> > > On Wed, Feb 14, 2024 at 04:41:38PM +0000, Will Deacon wrote:
> > > > On Tue, Feb 13, 2024 at 01:53:55PM -0800, Nicolin Chen wrote:
> > > And it seems to get worse, as even a 64KB mapping is failing:
> > > [    0.239821] nvme 0000:00:01.0: swiotlb buffer is full (sz: 65536 bytes), total 32768 (slots), used 0 (slots)
> > >
> > > With a printk, I found the iotlb_align_mask isn't correct:
> > >    swiotlb_area_find_slots:alloc_align_mask 0xffff, iotlb_align_mask 0x800
> > >
> > > But fixing the iotlb_align_mask to 0x7ff still fails the 64KB
> > > mapping..
> >
> > Hmm. A mask of 0x7ff doesn't make a lot of sense given that the slabs
> > are 2KiB aligned. I'll try plugging in some of the constants you have
> > here, as something definitely isn't right...
> 
> Sorry, another ask: please can you print 'orig_addr' in the case of the
> failing allocation?

I added nvme_print_sgl() in the nvme-pci driver before its
dma_map_sgtable() call, so the orig_addr isn't aligned with
PAGE_SIZE=64K or NVME_CTRL_PAGE_SIZE=4K:
 sg[0] phys_addr:0x0000000105774600 offset:17920 length:512 dma_address:0x0000000000000000 dma_length:0

Also attaching some verbose logs, in case you'd like to check:
   nvme 0000:00:01.0: swiotlb_area_find_slots: dma_get_min_align_mask 0xfff, IO_TLB_SIZE 0xfffff7ff
   nvme 0000:00:01.0: swiotlb_area_find_slots: alloc_align_mask 0xffff, iotlb_align_mask 0x7ff
   nvme 0000:00:01.0: swiotlb_area_find_slots: stride 0x20, max 0xffff
   nvme 0000:00:01.0: swiotlb_area_find_slots: tlb_addr=0xbd830000, iotlb_align_mask=0x7ff, alloc_align_mask=0xffff
=> nvme 0000:00:01.0: swiotlb_area_find_slots: orig_addr=0x105774600, iotlb_align_mask=0x7ff
   ...
   nvme 0000:00:01.0: swiotlb buffer is full (sz: 65536 bytes), total 32768 (slots), used 0 (slots)
   ...

Call trace:
 swiotlb_tbl_map_single+0x1c8/0x210
 iommu_dma_map_page+0x1ec/0x280
 iommu_dma_map_sg+0x1ec/0x570
 __dma_map_sg_attrs+0x98/0xa8
 dma_map_sgtable+0x30/0x58
 nvme_prep_rq.part.0+0x1e4/0x7b8

Then, I tried this experiment:
------------------------------------------------------
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index b32e3cff37b1..1c988493d3bf 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1879,3 +1879,3 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
        blk_queue_virt_boundary(q, NVME_CTRL_PAGE_SIZE - 1);
-       blk_queue_dma_alignment(q, 3);
+       blk_queue_dma_alignment(q, NVME_CTRL_PAGE_SIZE - 1);
        blk_queue_write_cache(q, vwc, vwc);
------------------------------------------------------

Then, all the SGs seem to be aligned properly, yet some offset
passed in to a dma_map_page_attrs() is still misaligned:
   sg[0] phys_addr:0x0000000145140000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[1] phys_addr:0x0000000145130000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[2] phys_addr:0x0000000145120000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[0] phys_addr:0x0000000145110000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[1] phys_addr:0x0000000145100000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[2] phys_addr:0x00000001450f0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[3] phys_addr:0x00000001450e0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[0] phys_addr:0x00000001450d0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[1] phys_addr:0x00000001450c0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[0] phys_addr:0x00000001451b0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[1] phys_addr:0x0000000145140000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[2] phys_addr:0x0000000145130000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[0] phys_addr:0x0000000145120000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[1] phys_addr:0x00000001451a0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[2] phys_addr:0x0000000145190000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[3] phys_addr:0x0000000145160000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[0] phys_addr:0x0000000145000000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[1] phys_addr:0x0000000144fd0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[2] phys_addr:0x0000000144ff0000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[3] phys_addr:0x0000000144f60000 offset:0 length:65536 dma_address:0x0000000000000000 dma_length:0
   sg[0] phys_addr:0x0000000145730000 offset:0 length:4096 dma_address:0x0000000000000000 dma_length:0
   nvme 0000:00:01.0: swiotlb_area_find_slots: tlb_addr=0xbf020000, iotlb_align_mask=0x7ff, alloc_align_mask=0xffff
=> nvme 0000:00:01.0: swiotlb_area_find_slots: orig_addr=0x145700600, iotlb_align_mask=0x7ff
   ...
   nvme 0000:00:01.0: swiotlb buffer is full (sz: 65536 bytes), total 32768 (slots), used 0 (slots)

Call trace:
  swiotlb_tbl_map_single+0x1c8/0x210
  iommu_dma_map_page+0x1ec/0x280
  dma_map_page_attrs+0x238/0x2d8
  nvme_prep_rq.part.0+0xec/0x7b8
  nvme_queue_rqs+0xb8/0x290

FWIW, with your patch, it seems to crash for me every time I
boot the system (PAGE_SIZE=64KB). I guess it somehow exposes
an underlying bug.

Attaching my .config file also.

Thanks
Nicolin

View attachment "nvme_test_config" of type "text/plain" (323359 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ