kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pci-assign: Fix multifunction support
@ 2012-01-16 17:11 Alex Williamson
  2012-01-17 13:08 ` Jan Kiszka
  2012-01-18 10:17 ` Marcelo Tosatti
  0 siblings, 2 replies; 5+ messages in thread
From: Alex Williamson @ 2012-01-16 17:11 UTC (permalink / raw)
  To: kvm; +Cc: alex.williamson, jan.kiszka, mtosatti

The core PCI code sets the multifunction bit in the header before
calling the device initfn.  For device assignment, we're blasting
that value with the actual hardware value, so nobody sees the
additional functions if the devices isn't physically multifunction.
Switch the HEADER_TYPE to a fully emulated field (all read-only
anyway) and add setting and clearing of the multifunction bit to
match qemu directive.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 hw/device-assignment.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 2a9e66d..7f4a5ec 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -540,6 +540,13 @@ again:
         fprintf(stderr, "%s: read failed, errno = %d\n", __func__, errno);
     }
 
+    /* Restore or clear multifunction, this is always controlled by qemu */
+    if (pci_dev->dev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+        pci_dev->dev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
+    } else {
+        pci_dev->dev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+    }
+
     /* Clear host resource mapping info.  If we choose not to register a
      * BAR, such as might be the case with the option ROM, we can get
      * confusing, unwritable, residual addresses from the host here. */
@@ -1575,7 +1582,6 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
     assigned_dev_direct_config_read(dev, PCI_CLASS_PROG, 3);
     assigned_dev_direct_config_read(dev, PCI_CACHE_LINE_SIZE, 1);
     assigned_dev_direct_config_read(dev, PCI_LATENCY_TIMER, 1);
-    assigned_dev_direct_config_read(dev, PCI_HEADER_TYPE, 1);
     assigned_dev_direct_config_read(dev, PCI_BIST, 1);
     assigned_dev_direct_config_read(dev, PCI_CARDBUS_CIS, 4);
     assigned_dev_direct_config_read(dev, PCI_SUBSYSTEM_VENDOR_ID, 2);


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] pci-assign: Fix multifunction support
  2012-01-16 17:11 [PATCH] pci-assign: Fix multifunction support Alex Williamson
@ 2012-01-17 13:08 ` Jan Kiszka
  2012-01-17 13:23   ` Alex Williamson
  2012-01-18 10:17 ` Marcelo Tosatti
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2012-01-17 13:08 UTC (permalink / raw)
  To: Alex Williamson; +Cc: kvm@vger.kernel.org, mtosatti@redhat.com

On 2012-01-16 18:11, Alex Williamson wrote:
> The core PCI code sets the multifunction bit in the header before
> calling the device initfn.  For device assignment, we're blasting
> that value with the actual hardware value, so nobody sees the
> additional functions if the devices isn't physically multifunction.
> Switch the HEADER_TYPE to a fully emulated field (all read-only
> anyway) and add setting and clearing of the multifunction bit to
> match qemu directive.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
> 
>  hw/device-assignment.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> index 2a9e66d..7f4a5ec 100644
> --- a/hw/device-assignment.c
> +++ b/hw/device-assignment.c
> @@ -540,6 +540,13 @@ again:
>          fprintf(stderr, "%s: read failed, errno = %d\n", __func__, errno);
>      }
>  
> +    /* Restore or clear multifunction, this is always controlled by qemu */
> +    if (pci_dev->dev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
> +        pci_dev->dev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
> +    } else {
> +        pci_dev->dev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
> +    }
> +

Why have this in get_*real*_device? Why not fix this up at the caller
site, i.e. in assigned_initfn? Just for consistency, not a functional issue.

>      /* Clear host resource mapping info.  If we choose not to register a
>       * BAR, such as might be the case with the option ROM, we can get
>       * confusing, unwritable, residual addresses from the host here. */
> @@ -1575,7 +1582,6 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
>      assigned_dev_direct_config_read(dev, PCI_CLASS_PROG, 3);
>      assigned_dev_direct_config_read(dev, PCI_CACHE_LINE_SIZE, 1);
>      assigned_dev_direct_config_read(dev, PCI_LATENCY_TIMER, 1);
> -    assigned_dev_direct_config_read(dev, PCI_HEADER_TYPE, 1);
>      assigned_dev_direct_config_read(dev, PCI_BIST, 1);
>      assigned_dev_direct_config_read(dev, PCI_CARDBUS_CIS, 4);
>      assigned_dev_direct_config_read(dev, PCI_SUBSYSTEM_VENDOR_ID, 2);
> 

Looks good otherwise. Is it a regression of the access control refactoring?

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pci-assign: Fix multifunction support
  2012-01-17 13:08 ` Jan Kiszka
@ 2012-01-17 13:23   ` Alex Williamson
  2012-01-17 14:28     ` Jan Kiszka
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Williamson @ 2012-01-17 13:23 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: kvm, mtosatti



----- Original Message -----
> On 2012-01-16 18:11, Alex Williamson wrote:
> > The core PCI code sets the multifunction bit in the header before
> > calling the device initfn.  For device assignment, we're blasting
> > that value with the actual hardware value, so nobody sees the
> > additional functions if the devices isn't physically multifunction.
> > Switch the HEADER_TYPE to a fully emulated field (all read-only
> > anyway) and add setting and clearing of the multifunction bit to
> > match qemu directive.
> > 
> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> > ---
> > 
> >  hw/device-assignment.c |    8 +++++++-
> >  1 files changed, 7 insertions(+), 1 deletions(-)
> > 
> > diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> > index 2a9e66d..7f4a5ec 100644
> > --- a/hw/device-assignment.c
> > +++ b/hw/device-assignment.c
> > @@ -540,6 +540,13 @@ again:
> >          fprintf(stderr, "%s: read failed, errno = %d\n", __func__,
> >          errno);
> >      }
> >  
> > +    /* Restore or clear multifunction, this is always controlled
> > by qemu */
> > +    if (pci_dev->dev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
> > +        pci_dev->dev.config[PCI_HEADER_TYPE] |=
> > PCI_HEADER_TYPE_MULTI_FUNCTION;
> > +    } else {
> > +        pci_dev->dev.config[PCI_HEADER_TYPE] &=
> > ~PCI_HEADER_TYPE_MULTI_FUNCTION;
> > +    }
> > +
> 
> Why have this in get_*real*_device? Why not fix this up at the caller
> site, i.e. in assigned_initfn? Just for consistency, not a functional
> issue.

I chose here because we've just overwritten the emulated config space and we then proceed to clean out the BAR registers.  As this is close to the point where it gets trashed and we're doing other fixup, it seems appropriate.

> >      /* Clear host resource mapping info.  If we choose not to
> >      register a
> >       * BAR, such as might be the case with the option ROM, we can
> >       get
> >       * confusing, unwritable, residual addresses from the host
> >       here. */
> > @@ -1575,7 +1582,6 @@ static int assigned_initfn(struct PCIDevice
> > *pci_dev)
> >      assigned_dev_direct_config_read(dev, PCI_CLASS_PROG, 3);
> >      assigned_dev_direct_config_read(dev, PCI_CACHE_LINE_SIZE, 1);
> >      assigned_dev_direct_config_read(dev, PCI_LATENCY_TIMER, 1);
> > -    assigned_dev_direct_config_read(dev, PCI_HEADER_TYPE, 1);
> >      assigned_dev_direct_config_read(dev, PCI_BIST, 1);
> >      assigned_dev_direct_config_read(dev, PCI_CARDBUS_CIS, 4);
> >      assigned_dev_direct_config_read(dev, PCI_SUBSYSTEM_VENDOR_ID,
> >      2);
> > 
> 
> Looks good otherwise. Is it a regression of the access control
> refactoring?

I believe it's been a latent issue since before the refactoring.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pci-assign: Fix multifunction support
  2012-01-17 13:23   ` Alex Williamson
@ 2012-01-17 14:28     ` Jan Kiszka
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2012-01-17 14:28 UTC (permalink / raw)
  To: Alex Williamson; +Cc: kvm@vger.kernel.org, mtosatti@redhat.com

On 2012-01-17 14:23, Alex Williamson wrote:
> 
> 
> ----- Original Message -----
>> On 2012-01-16 18:11, Alex Williamson wrote:
>>> The core PCI code sets the multifunction bit in the header before
>>> calling the device initfn.  For device assignment, we're blasting
>>> that value with the actual hardware value, so nobody sees the
>>> additional functions if the devices isn't physically multifunction.
>>> Switch the HEADER_TYPE to a fully emulated field (all read-only
>>> anyway) and add setting and clearing of the multifunction bit to
>>> match qemu directive.
>>>
>>> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>>> ---
>>>
>>>  hw/device-assignment.c |    8 +++++++-
>>>  1 files changed, 7 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
>>> index 2a9e66d..7f4a5ec 100644
>>> --- a/hw/device-assignment.c
>>> +++ b/hw/device-assignment.c
>>> @@ -540,6 +540,13 @@ again:
>>>          fprintf(stderr, "%s: read failed, errno = %d\n", __func__,
>>>          errno);
>>>      }
>>>  
>>> +    /* Restore or clear multifunction, this is always controlled
>>> by qemu */
>>> +    if (pci_dev->dev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>> +        pci_dev->dev.config[PCI_HEADER_TYPE] |=
>>> PCI_HEADER_TYPE_MULTI_FUNCTION;
>>> +    } else {
>>> +        pci_dev->dev.config[PCI_HEADER_TYPE] &=
>>> ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>>> +    }
>>> +
>>
>> Why have this in get_*real*_device? Why not fix this up at the caller
>> site, i.e. in assigned_initfn? Just for consistency, not a functional
>> issue.
> 
> I chose here because we've just overwritten the emulated config space and we then proceed to clean out the BAR registers.  As this is close to the point where it gets trashed and we're doing other fixup, it seems appropriate.

OK.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pci-assign: Fix multifunction support
  2012-01-16 17:11 [PATCH] pci-assign: Fix multifunction support Alex Williamson
  2012-01-17 13:08 ` Jan Kiszka
@ 2012-01-18 10:17 ` Marcelo Tosatti
  1 sibling, 0 replies; 5+ messages in thread
From: Marcelo Tosatti @ 2012-01-18 10:17 UTC (permalink / raw)
  To: Alex Williamson; +Cc: kvm, jan.kiszka

On Mon, Jan 16, 2012 at 10:11:51AM -0700, Alex Williamson wrote:
> The core PCI code sets the multifunction bit in the header before
> calling the device initfn.  For device assignment, we're blasting
> that value with the actual hardware value, so nobody sees the
> additional functions if the devices isn't physically multifunction.
> Switch the HEADER_TYPE to a fully emulated field (all read-only
> anyway) and add setting and clearing of the multifunction bit to
> match qemu directive.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Applied, thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-18 13:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-16 17:11 [PATCH] pci-assign: Fix multifunction support Alex Williamson
2012-01-17 13:08 ` Jan Kiszka
2012-01-17 13:23   ` Alex Williamson
2012-01-17 14:28     ` Jan Kiszka
2012-01-18 10:17 ` Marcelo Tosatti

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).