mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] vfio/pci: Add extra test for extended capabilities
@ 2014-06-12 16:44 Alex Williamson
  2014-06-12 20:12 ` Bandan Das
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2014-06-12 16:44 UTC (permalink / raw)
  To: alex.williamson; +Cc: linux-kernel, kvm

If the PCI core set cfg_size isn't large enough for extended
capabilities, then they're not there.  Extended config space may be
inaccessible due to a PCI bridge, in which case cfg_size may be cut
short.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/pci/vfio_pci_config.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index 83cd157..4a62a37 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -1027,8 +1027,11 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
 
 		if (PCI_X_CMD_VERSION(word)) {
 			/* Test for extended capabilities */
-			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
-			vdev->extended_caps = (dword != 0);
+			if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
+				pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE,
+						      &dword);
+				vdev->extended_caps = (dword != 0);
+			}
 			return PCI_CAP_PCIX_SIZEOF_V2;
 		} else
 			return PCI_CAP_PCIX_SIZEOF_V0;
@@ -1041,8 +1044,10 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
 		return byte;
 	case PCI_CAP_ID_EXP:
 		/* Test for extended capabilities */
-		pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
-		vdev->extended_caps = (dword != 0);
+		if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
+			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
+			vdev->extended_caps = (dword != 0);
+		}
 
 		/* length based on version */
 		if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)


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

* Re: [PATCH] vfio/pci: Add extra test for extended capabilities
  2014-06-12 16:44 [PATCH] vfio/pci: Add extra test for extended capabilities Alex Williamson
@ 2014-06-12 20:12 ` Bandan Das
  2014-06-12 20:29   ` Alex Williamson
  0 siblings, 1 reply; 4+ messages in thread
From: Bandan Das @ 2014-06-12 20:12 UTC (permalink / raw)
  To: Alex Williamson; +Cc: linux-kernel, kvm

Alex Williamson <alex.williamson@redhat.com> writes:

> If the PCI core set cfg_size isn't large enough for extended
> capabilities, then they're not there.  Extended config space may be
> inaccessible due to a PCI bridge, in which case cfg_size may be cut
> short.

Just curious, is this part of the spec or just a convention ? I mean
could there be devices with quirks ?

> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>  drivers/vfio/pci/vfio_pci_config.c |   13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index 83cd157..4a62a37 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1027,8 +1027,11 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
>  
>  		if (PCI_X_CMD_VERSION(word)) {
>  			/* Test for extended capabilities */
> -			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
> -			vdev->extended_caps = (dword != 0);
> +			if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
> +				pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE,
> +						      &dword);
> +				vdev->extended_caps = (dword != 0);
> +			}
>  			return PCI_CAP_PCIX_SIZEOF_V2;
>  		} else
>  			return PCI_CAP_PCIX_SIZEOF_V0;
> @@ -1041,8 +1044,10 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
>  		return byte;
>  	case PCI_CAP_ID_EXP:
>  		/* Test for extended capabilities */
> -		pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
> -		vdev->extended_caps = (dword != 0);
> +		if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
> +			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
> +			vdev->extended_caps = (dword != 0);
> +		}
>  
>  		/* length based on version */
>  		if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] vfio/pci: Add extra test for extended capabilities
  2014-06-12 20:12 ` Bandan Das
@ 2014-06-12 20:29   ` Alex Williamson
  2014-06-12 20:39     ` Bandan Das
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2014-06-12 20:29 UTC (permalink / raw)
  To: Bandan Das; +Cc: linux-kernel, kvm

On Thu, 2014-06-12 at 16:12 -0400, Bandan Das wrote:
> Alex Williamson <alex.williamson@redhat.com> writes:
> 
> > If the PCI core set cfg_size isn't large enough for extended
> > capabilities, then they're not there.  Extended config space may be
> > inaccessible due to a PCI bridge, in which case cfg_size may be cut
> > short.
> 
> Just curious, is this part of the spec or just a convention ? I mean
> could there be devices with quirks ?

The PCIe bridge spec indicates that PCIe-to-PCI bridges should handle
extended config accesses as an unsupported request.  But as in 78916b00,
we've seen that's not always the case.  This just makes us trust
PCI-core before the capabilities we find on the device.  The current
quirk in the referenced commit is for a relatively uncommon topology,
but never rule out that we couldn't have a device quirked to avoid
touching extended config space too.  Thanks,

Alex 

> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> > ---
> >  drivers/vfio/pci/vfio_pci_config.c |   13 +++++++++----
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> > index 83cd157..4a62a37 100644
> > --- a/drivers/vfio/pci/vfio_pci_config.c
> > +++ b/drivers/vfio/pci/vfio_pci_config.c
> > @@ -1027,8 +1027,11 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
> >  
> >  		if (PCI_X_CMD_VERSION(word)) {
> >  			/* Test for extended capabilities */
> > -			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
> > -			vdev->extended_caps = (dword != 0);
> > +			if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
> > +				pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE,
> > +						      &dword);
> > +				vdev->extended_caps = (dword != 0);
> > +			}
> >  			return PCI_CAP_PCIX_SIZEOF_V2;
> >  		} else
> >  			return PCI_CAP_PCIX_SIZEOF_V0;
> > @@ -1041,8 +1044,10 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
> >  		return byte;
> >  	case PCI_CAP_ID_EXP:
> >  		/* Test for extended capabilities */
> > -		pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
> > -		vdev->extended_caps = (dword != 0);
> > +		if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
> > +			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
> > +			vdev->extended_caps = (dword != 0);
> > +		}
> >  
> >  		/* length based on version */
> >  		if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html




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

* Re: [PATCH] vfio/pci: Add extra test for extended capabilities
  2014-06-12 20:29   ` Alex Williamson
@ 2014-06-12 20:39     ` Bandan Das
  0 siblings, 0 replies; 4+ messages in thread
From: Bandan Das @ 2014-06-12 20:39 UTC (permalink / raw)
  To: Alex Williamson; +Cc: linux-kernel, kvm

Alex Williamson <alex.williamson@redhat.com> writes:

> On Thu, 2014-06-12 at 16:12 -0400, Bandan Das wrote:
>> Alex Williamson <alex.williamson@redhat.com> writes:
>> 
>> > If the PCI core set cfg_size isn't large enough for extended
>> > capabilities, then they're not there.  Extended config space may be
>> > inaccessible due to a PCI bridge, in which case cfg_size may be cut
>> > short.
>> 
>> Just curious, is this part of the spec or just a convention ? I mean
>> could there be devices with quirks ?
>
> The PCIe bridge spec indicates that PCIe-to-PCI bridges should handle
> extended config accesses as an unsupported request.  But as in 78916b00,
> we've seen that's not always the case.  This just makes us trust
> PCI-core before the capabilities we find on the device.  The current
> quirk in the referenced commit is for a relatively uncommon topology,
> but never rule out that we couldn't have a device quirked to avoid
> touching extended config space too.  Thanks,

Ok, Understood, Thanks!

> Alex 
>
>> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>> > ---
>> >  drivers/vfio/pci/vfio_pci_config.c |   13 +++++++++----
>> >  1 file changed, 9 insertions(+), 4 deletions(-)
>> >
>> > diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
>> > index 83cd157..4a62a37 100644
>> > --- a/drivers/vfio/pci/vfio_pci_config.c
>> > +++ b/drivers/vfio/pci/vfio_pci_config.c
>> > @@ -1027,8 +1027,11 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
>> >  
>> >  		if (PCI_X_CMD_VERSION(word)) {
>> >  			/* Test for extended capabilities */
>> > -			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
>> > -			vdev->extended_caps = (dword != 0);
>> > +			if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
>> > +				pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE,
>> > +						      &dword);
>> > +				vdev->extended_caps = (dword != 0);
>> > +			}
>> >  			return PCI_CAP_PCIX_SIZEOF_V2;
>> >  		} else
>> >  			return PCI_CAP_PCIX_SIZEOF_V0;
>> > @@ -1041,8 +1044,10 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
>> >  		return byte;
>> >  	case PCI_CAP_ID_EXP:
>> >  		/* Test for extended capabilities */
>> > -		pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
>> > -		vdev->extended_caps = (dword != 0);
>> > +		if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) {
>> > +			pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &dword);
>> > +			vdev->extended_caps = (dword != 0);
>> > +		}
>> >  
>> >  		/* length based on version */
>> >  		if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)
>> >
>> > --
>> > To unsubscribe from this list: send the line "unsubscribe kvm" in
>> > the body of a message to majordomo@vger.kernel.org
>> > More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2014-06-12 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-12 16:44 [PATCH] vfio/pci: Add extra test for extended capabilities Alex Williamson
2014-06-12 20:12 ` Bandan Das
2014-06-12 20:29   ` Alex Williamson
2014-06-12 20:39     ` Bandan Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®