pci-assign: Fix multifunction support
PATCH 1/1 pci-assign: Fix multifunction support
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.
---
hw/device-assignment.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
hw/device-assignment.c +7 -1
@@ -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 );
Quoted 19 lines · Alex Williamson
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_TYPEto 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 <[email protected]>---
hw/device-assignment.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)hw/device-assignment.c +0
-0
hw/device-assignment.c again: · line 549
Quoted 10 lines
hw/device-assignment.c +7
-0@@ -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.
hw/device-assignment.c static int assigned_initfn(struct PCIDevice *pci_dev) · line 1587
Quoted 12 lines
hw/device-assignment.c +0
-1/* 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
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
----- Original Message -----
Quoted 24 lines · Alex Williamson
Quoted 23 lines
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_TYPEto 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 <[email protected]>---
hw/device-assignment.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)hw/device-assignment.c +0
-0@@ -540,6 +540,13 @@ again:fprintf (stderr,"%s: read failed, errno = %d\n" , __func__, errno); }
Quoted 14 lines
hw/device-assignment.c again: · line 549
Quoted 10 lines
hw/device-assignment.c +1
-0+/* Restore or clear multifunction, this is always controlled by qemu */
hw/device-assignment.c +2
-0+if (pci_dev->dev.cap_present &QEMU_PCI_CAP_MULTIFUNCTION ) { + pci_dev->dev.config[PCI_HEADER_TYPE] |=
PCI_HEADER_TYPE_MULTI_FUNCTION;hw/device-assignment.c +2
-0+ }else { + pci_dev->dev.config[PCI_HEADER_TYPE] &=~PCI_HEADER_TYPE_MULTI_FUNCTION;
hw/device-assignment.c +2
-0+ } +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.
Quoted 12 lines
Quoted 12 lines
/* 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. */hw/device-assignment.c +0
-1@@ -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 );
Quoted 8 lines
Quoted 5 lines
hw/device-assignment.c +0
-0assigned_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
Quoted 42 lines · Alex Williamson
----- Original Message -----
Quoted 24 lines · Alex Williamson
Quoted 23 lines
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_TYPEto 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 <[email protected]>---
hw/device-assignment.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)hw/device-assignment.c +0
-0@@ -540,6 +540,13 @@ again:fprintf (stderr,"%s: read failed, errno = %d\n" , __func__, errno); }Quoted 14 lines
hw/device-assignment.c again: · line 549
Quoted 10 lines
hw/device-assignment.c +1
-0+/* Restore or clear multifunction, this is always controlled by qemu */
hw/device-assignment.c +2
-0+if (pci_dev->dev.cap_present &QEMU_PCI_CAP_MULTIFUNCTION ) { + pci_dev->dev.config[PCI_HEADER_TYPE] |=
PCI_HEADER_TYPE_MULTI_FUNCTION;hw/device-assignment.c +2
-0+ }else { + pci_dev->dev.config[PCI_HEADER_TYPE] &=~PCI_HEADER_TYPE_MULTI_FUNCTION;
hw/device-assignment.c +2
-0+ } +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.
Quoted 1 line
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
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Marcelo Tosatti
AppliedQuoted 9 lines · Alex Williamson
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_TYPEto 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 <[email protected]>
Applied, thanks.