qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: <ankita@nvidia.com>
Cc: <jgg@nvidia.com>, <qemu-devel@nongnu.org>
Subject: Re: [RFC v1 4/4] qemu: adjust queried bar size to power-of-2
Date: Tue, 6 Jun 2023 06:54:41 -0600	[thread overview]
Message-ID: <20230606065441.170333b5.alex.williamson@redhat.com> (raw)
In-Reply-To: <20230605235005.20649-5-ankita@nvidia.com>

On Mon, 5 Jun 2023 16:50:05 -0700
<ankita@nvidia.com> wrote:

> From: Ankit Agrawal <ankita@nvidia.com>
> 
> The GPU device memory is reported to the VM as a BAR. The device memory
> may not be aligned to the power-of-2, but the QEMU expects the PCI BAR to
> be. Align the reported device memory size to the next power-of-2 before
> QEMU does an mmap.
> 
> Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
> ---
>  hw/vfio/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 4d01ea3515..bb49200458 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -2061,7 +2061,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
>  
>      region->vbasedev = vbasedev;
>      region->flags = info->flags;
> -    region->size = info->size;
> +    region->size = info->size ? pow2ceil(info->size) : info->size;
>      region->fd_offset = info->offset;
>      region->nr = index;
>  

Nak, this means our kernel emulation of the BAR is broken, a BAR that
is not naturally aligned is not a PCI BAR.  PCI BAR sizing through the
BAR register still needs to work via the kernel interface alone.  It's
clear now how the kernel resizing the vma on mmap was a hack around
userspace mangling the region size.

Maybe this needs to be exposed as a device specific region, which then
userspace emulates as a BAR for the VM facing device rather than the
kernel emulating it as a BAR.  Thanks,

Alex



  parent reply	other threads:[~2023-06-06 12:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 23:50 [RFC v1 0/4] Expose GPU memory as coherently CPU accessible ankita
2023-06-05 23:50 ` [RFC v1 1/4] qemu: add GPU memory information as object ankita
2023-06-06 15:19   ` Alex Williamson
2023-06-05 23:50 ` [RFC v1 2/4] qemu: patch guest SRAT for GPU memory ankita
2023-06-06  4:58   ` Philippe Mathieu-Daudé
2023-06-05 23:50 ` [RFC v1 3/4] qemu: patch guest DSDT " ankita
2023-06-05 23:50 ` [RFC v1 4/4] qemu: adjust queried bar size to power-of-2 ankita
2023-06-06  5:03   ` Philippe Mathieu-Daudé
2023-06-06 12:54   ` Alex Williamson [this message]
2023-06-06 14:19     ` Philippe Mathieu-Daudé
2023-06-06 14:54 ` [RFC v1 0/4] Expose GPU memory as coherently CPU accessible Cédric Le Goater

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=20230606065441.170333b5.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=ankita@nvidia.com \
    --cc=jgg@nvidia.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).