qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: "Alexey Kardashevskiy" <aik@ozlabs.ru>,
	qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	"Gavin Shan" <gwshan@linux.vnet.ibm.com>,
	"Sam Bobroff" <sbobroff@linux.ibm.com>,
	"Piotr Jaroszynski" <pjaroszynski@nvidia.com>,
	"Leonardo Augusto Guimarães Garcia" <lagarcia@br.ibm.com>,
	"Jose Ricardo Ziviani" <joserz@linux.ibm.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>
Subject: Re: [Qemu-devel] [PATCH qemu v4 3/3] spapr: Support NVIDIA V100 GPU with NVLink2
Date: Fri, 8 Mar 2019 15:34:56 +1100	[thread overview]
Message-ID: <20190308043456.GU7722@umbus.fritz.box> (raw)
In-Reply-To: <20190307150232.7384b7ce@w520.home>

[-- Attachment #1: Type: text/plain, Size: 3294 bytes --]

On Thu, Mar 07, 2019 at 03:02:32PM -0700, Alex Williamson wrote:
> On Thu,  7 Mar 2019 16:05:18 +1100
> Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> > diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
> > index 40a12001f580..15ec0b4c2723 100644
> > --- a/hw/vfio/pci-quirks.c
> > +++ b/hw/vfio/pci-quirks.c
> > @@ -2180,3 +2180,123 @@ int vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp)
> >  
> >      return 0;
> >  }
> > +
> > +static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
> > +                                     const char *name,
> > +                                     void *opaque, Error **errp)
> > +{
> > +    uint64_t tgt = (uint64_t) opaque;
> > +    visit_type_uint64(v, name, &tgt, errp);
> > +}
> > +
> > +static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
> > +                                                 const char *name,
> > +                                                 void *opaque, Error **errp)
> > +{
> > +    uint32_t link_speed = (uint32_t)(uint64_t) opaque;
> > +    visit_type_uint32(v, name, &link_speed, errp);
> > +}
> > +
> > +int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
> > +{
> > +    int ret;
> > +    void *p;
> > +    struct vfio_region_info *nv2region = NULL;
> > +    struct vfio_info_cap_header *hdr;
> > +    MemoryRegion *nv2mr = g_malloc0(sizeof(*nv2mr));
> 
> This is leaked in the below error paths and there's no cleanup on
> finalize.  I assume these devices don't support hotplug, but they could
> at least use the existing quirk infrastructure so as not to set a bad
> precedent. 
> 
> > +
> > +    ret = vfio_get_dev_region_info(&vdev->vbasedev,
> > +                                   VFIO_REGION_TYPE_PCI_VENDOR_TYPE |
> > +                                   PCI_VENDOR_ID_NVIDIA,
> > +                                   VFIO_REGION_SUBTYPE_NVIDIA_NVLINK2_RAM,
> > +                                   &nv2region);
> > +    if (ret) {
> > +        return ret;
> > +    }
> > +
> > +    p = mmap(NULL, nv2region->size, PROT_READ | PROT_WRITE | PROT_EXEC,
> > +             MAP_SHARED, vdev->vbasedev.fd, nv2region->offset);
> > +
> > +    if (!p) {
> > +        return -errno;
> > +    }
> 
> I think the above suggestion requires simply defining a quirk above:
> 
> VFIOQuirk *quirk;
> 
> Initializing it with one MemoryRegion here:
> 
> quirk = vfio_quirk_alloc(1);
> 
> > +
> > +    memory_region_init_ram_ptr(nv2mr, OBJECT(vdev), "nvlink2-mr",
> 
> s/nv2mr/quirk->mem/
> 
> > +                               nv2region->size, p);
> 
> Then adding it to the device, for instance assuming there's always a
> BAR0, attach it there:
> 
> QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
> 
> At least then it pretends to support cleanup.

This does simplify the cleanup of the extra MRs.  It is a bit odd to
attach it specifically to a BAR that's not otherwise tied to these
resources (both the NV2 memory and ATSD are special NVLink extensions,
not attached to a PCI BAR).


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-03-08  5:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07  5:05 [Qemu-devel] [PATCH qemu v4 0/3] spapr_pci, vfio: NVIDIA V100 + POWER9 passthrough Alexey Kardashevskiy
2019-03-07  5:05 ` [Qemu-devel] [PATCH qemu v4 1/3] spapr_iommu: Do not replay mappings from just created DMA window Alexey Kardashevskiy
2019-03-07 23:11   ` David Gibson
2019-03-07  5:05 ` [Qemu-devel] [PATCH qemu v4 2/3] vfio: Make vfio_get_region_info_cap public Alexey Kardashevskiy
2019-03-07 22:03   ` Alex Williamson
2019-03-07  5:05 ` [Qemu-devel] [PATCH qemu v4 3/3] spapr: Support NVIDIA V100 GPU with NVLink2 Alexey Kardashevskiy
2019-03-07 22:02   ` Alex Williamson
2019-03-08  4:34     ` David Gibson [this message]
2019-03-08 14:52       ` Alex Williamson

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=20190308043456.GU7722@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=alex.williamson@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=gwshan@linux.vnet.ibm.com \
    --cc=joserz@linux.ibm.com \
    --cc=lagarcia@br.ibm.com \
    --cc=pjaroszynski@nvidia.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=sbobroff@linux.ibm.com \
    /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).