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]
Message-ID: <20260108143804.GD545276@ziepe.ca>
Date: Thu, 8 Jan 2026 10:38:04 -0400
From: Jason Gunthorpe <jgg@...pe.ca>
To: Alex Mastro <amastro@...com>
Cc: David Matlack <dmatlack@...gle.com>, Alex Williamson <alex@...zbot.org>,
	Shuah Khan <shuah@...nel.org>, Peter Xu <peterx@...hat.com>,
	linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
	linux-kselftest@...r.kernel.org
Subject: Re: [PATCH] vfio: selftests: Add vfio_dma_mapping_mmio_test

On Wed, Jan 07, 2026 at 07:36:44PM -0800, Alex Mastro wrote:
> This was inspired by QEMU's hw/vfio/region.c which also does this rounding up
> of size to the next power of two [1].
> 
> I'm now realizing that's only necessary for regions with
> VFIO_REGION_INFO_CAP_SPARSE_MMAP where there are multiple mmaps per region, and
> each mmap's size is less than the size of the BAR. Here, since we're mapping the
> entire BAR which must be pow2, it shouldn't be necessary.

You only need to do this dance if you care about having large PTEs
under the VMAs, which is probably something worth testing both
scenarios.

> The intent of QEMU's mmap alignment code is imperfect in the SPARE_MMAP case?
> After a hole, the next mmap'able range could be some arbitrary page-aligned
> offset into the region. It's not helpful mmap some region offset which is
> maximally 4K-aligned at a 1G-aligned vaddr.
> 
> I think to be optimal, QEMU should be attempting to align the vaddr for bar
> mmaps such that
> 
> vaddr % {2M,1G} == region_offset % {2M,1G}
> 
> Would love someone to sanity check me on this. Kind of a diversion.

What you write is correct. Ankit recently discovered this bug in
qemu. It happens not just with SPARSE_MMAP but also when mmmaping
around the MSI-X hole..

I also advocated for what you write here that qemu should ensure:

  vaddr % region_size == region_offset % region_size

Until VFIO learns to align its VMAs on its own via Peter's work.

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ