qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Andrew Barnes <umbramalison@gmail.com>
Cc: jike.song@intel.com, intel-gfx@lists.freedesktop.org,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [IGDVFIO] [PATCH 4/8] RFC and help completing: Intel IGD Direct Assignment with VFIO
Date: Wed, 24 Sep 2014 13:52:57 -0600	[thread overview]
Message-ID: <1411588377.24563.158.camel@ul30vt.home> (raw)
In-Reply-To: <CAKJ_wKRHumym1twh+KRu3xGULAuayPuHwxaajqAmRLvLMMDyaw@mail.gmail.com>

On Wed, 2014-09-24 at 14:20 +0100, Andrew Barnes wrote:
> hw/pci/pci.c
> 
> this patch adds:
> * read / write host PCI config space
> 
> patch
> ---------------------
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 42995e6..041f6f1 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -2,6 +2,8 @@
>   * QEMU PCI bus manager
>   *
>   * Copyright (c) 2004 Fabrice Bellard
> + *    2014 Andrew Barnes <andy@outsideglobe.com> IGD Support
> + *        Temporarily extended to provide host config read/write.
>   *
>   * Permission is hereby granted, free of charge, to any person obtaining a
> copy
>   * of this software and associated documentation files (the "Software"),
> to deal
> @@ -37,9 +39,9 @@
>  #include "exec/address-spaces.h"
>  #include "hw/hotplug.h"
> 
> -//#define DEBUG_PCI
> +/* #define DEBUG_PCI */
>  #ifdef DEBUG_PCI
> -# define PCI_DPRINTF(format, ...)       printf(format, ## __VA_ARGS__)
> +# define PCI_DPRINTF(format, ...)       printf("pci:" format, ##
> __VA_ARGS__)
>  #else
>  # define PCI_DPRINTF(format, ...)       do { } while (0)
>  #endif
> @@ -60,6 +62,81 @@ static Property pci_props[] = {
>      DEFINE_PROP_END_OF_LIST()
>  };
> 
> +/* Provides config reads from the host */
> +uint32_t host_pci_read_config(int bus, int slot, int fn, uint32_t address,
> int len)
> +{
> +    uint32_t val = 0;
> +    int fd;
> +    int domain = 0;
> +    ssize_t ret;
> +    char dir[128], name[128];
> +
> +    snprintf(dir, sizeof(dir), "/sys/bus/pci/devices/%04x:%02x:%02x.%x/",
> +             domain, bus, slot, fn);
> +    snprintf(name, sizeof(name), "%sconfig", dir);
> +
> +    fd = open(name, O_RDONLY);
> +
> +    if (fd >= 0)
> +    {
> +        do
> +        {
> +            ret = pread(fd,&val,len,address);
> +        } while ((ret < 0) && (errno == EINTR || errno == EAGAIN));
> +
> +        if (ret != len)
> +        {
> +            PCI_DPRINTF("%s(%04x:%02x:%02x.%x, @0x%x, len=0x%x) %s ret=%zd
> error=%d\n",
> +                 __func__, 0000, bus, slot, fn, address, len, "pread
> Failed",ret,errno);
> +            val = (1UL << (len * 8)) - 1;
> +        }
> +    }
> +    else
> +    {
> +        PCI_DPRINTF("%s(%04x:%02x:%02x.%x, @0x%x, len=0x%x) %s\n",
> +                 __func__, 0000, bus, slot, fn, address, len, "Open
> Failed");
> +    }
> +
> +    PCI_DPRINTF("%s(%04x:%02x:%02x.%x, @0x%x, len=0x%x) %x\n",
> +                 __func__, 0000, bus, slot, fn, address, len, val);
> +    return val;
> +}
> +
> +/* Provides config writes to the host*/
> +void host_pci_write_config(int bus, int slot, int fn, uint32_t address,
> int len, uint32_t val)
> +{
> +    int fd;
> +    int domain = 0;
> +    ssize_t ret;
> +    char dir[128], name[128];
> +
> +    snprintf(dir, sizeof(dir), "/sys/bus/pci/devices/%04x:%02x:%02x.%x/",
> +             domain, bus, slot, fn);
> +    snprintf(name, sizeof(name), "%sconfig", dir);
> +
> +    fd = open(name, O_RDWR);
> +
> +    if (fd >= 0)
> +    {
> +        do
> +        {
> +            ret = pwrite(fd,&val,len,address);
> +        } while ((ret < 0) && (errno == EINTR || errno == EAGAIN));
> +
> +
> +        if (ret != len)
> +        {
> +            PCI_DPRINTF("%s(%04x:%02x:%02x.%x, @0x%x, len=0x%x) %x %s
> ret=%zd error=%d\n",
> +                 __func__, 0000, bus, slot, fn, address, len, val, "pread
> Failed",ret,errno);
> +        }
> +    }
> +    else
> +    {
> +        PCI_DPRINTF("%s(%04x:%02x:%02x.%x, @0x%x, len=0x%x) %s\n",
> +                 __func__, 0000, bus, slot, fn, address, len, "Open
> Failed");
> +    }
> +}
> +
>  static const VMStateDescription vmstate_pcibus = {
>      .name = "PCIBUS",
>      .version_id = 1,

I expect a huge NAK on this one.  When run from libvirt and with any
sort of process containment, QEMU won't have access to these.  Not to
mention that many of the uses of these break migration.

In the case of things like stolen memory, GTT stolen memory, and tseg,
we shouldn't need to use these accessors because we shouldn't really
care what the host value is.  We only care currently because we need the
offset into /dev/mem.  We should consider that in designing the vfio
interface.

      reply	other threads:[~2014-09-24 19:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-24 13:20 [Qemu-devel] [IGDVFIO] [PATCH 4/8] RFC and help completing: Intel IGD Direct Assignment with VFIO Andrew Barnes
2014-09-24 19:52 ` Alex Williamson [this message]

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=1411588377.24563.158.camel@ul30vt.home \
    --to=alex.williamson@redhat.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jike.song@intel.com \
    --cc=qemu-devel@nongnu.org \
    --cc=umbramalison@gmail.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).