mbox series

[0/2] vfio: Align mmaps

Message ID 20241022200830.4129598-1-alex.williamson@redhat.com (mailing list archive)
Headers show
Series vfio: Align mmaps | expand

Message

Alex Williamson Oct. 22, 2024, 8:08 p.m. UTC
As described in patch /2, newer kernels may support pfnmap with PMD or
PUD sized mappings.  Mappings must be aligned in order to see the full
benefit of this support.  We're largely able to get PMD alignment for
free from mmap, but PUD alignment requires some effort.  Further, we
don't actually have an easy way to determine PMD or PUD alignment,
therefore we align all mmaps to the nearest power-of-two relative to the
region size, up to the maximum PUD size known the be currently available.

Enabling debug prints in the kernel shows that this exclusively enables
1GiB mappings for a GPU with a multi-gigabyte BAR whereas previously the
BAR is mapped with a combination of 2MiB and 1GiB mappings, only using
1GiB when opportunistically crossing an alignment boundary.

If there are ways to determine discrete alignment intervals or better
ways to generate a properly aligned address value for mmap, please share.
Thanks,

Alex

Alex Williamson (2):
  vfio/helpers: Refactor vfio_region_mmap() error handling
  vfio/helpers: Align mmaps

 hw/vfio/helpers.c | 66 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 47 insertions(+), 19 deletions(-)

Comments

Cédric Le Goater Oct. 23, 2024, 3:08 p.m. UTC | #1
On 10/22/24 22:08, Alex Williamson wrote:
> As described in patch /2, newer kernels may support pfnmap with PMD or
> PUD sized mappings.  Mappings must be aligned in order to see the full
> benefit of this support.  We're largely able to get PMD alignment for
> free from mmap, but PUD alignment requires some effort.  Further, we
> don't actually have an easy way to determine PMD or PUD alignment,
> therefore we align all mmaps to the nearest power-of-two relative to the
> region size, up to the maximum PUD size known the be currently available.
> 
> Enabling debug prints in the kernel shows that this exclusively enables
> 1GiB mappings for a GPU with a multi-gigabyte BAR whereas previously the
> BAR is mapped with a combination of 2MiB and 1GiB mappings, only using
> 1GiB when opportunistically crossing an alignment boundary.
> 
> If there are ways to determine discrete alignment intervals or better
> ways to generate a properly aligned address value for mmap, please share.
> Thanks,
> 
> Alex
> 
> Alex Williamson (2):
>    vfio/helpers: Refactor vfio_region_mmap() error handling
>    vfio/helpers: Align mmaps
> 
>   hw/vfio/helpers.c | 66 +++++++++++++++++++++++++++++++++--------------
>   1 file changed, 47 insertions(+), 19 deletions(-)
> 


Applied to vfio-next.

Thanks,

C.