| From 03fa230e5757a28980ddf95725a32c55b6b80de3 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Wed, 8 Apr 2020 11:45:28 -0600 |
| Subject: vfio-pci: Mask cap zero |
| |
| From: Alex Williamson <alex.williamson@redhat.com> |
| |
| [ Upstream commit bc138db1b96264b9c1779cf18d5a3b186aa90066 ] |
| |
| The PCI Code and ID Assignment Specification changed capability ID 0 |
| from reserved to a NULL capability in the v1.1 revision. The NULL |
| capability is defined to include only the 16-bit capability header, |
| ie. only the ID and next pointer. Unfortunately vfio-pci creates a |
| map of config space, where ID 0 is used to reserve the standard type |
| 0 header. Finding an actual capability with this ID therefore results |
| in a bogus range marked in that map and conflicts with subsequent |
| capabilities. As this seems to be a dummy capability anyway and we |
| already support dropping capabilities, let's hide this one rather than |
| delving into the potentially subtle dependencies within our map. |
| |
| Seen on an NVIDIA Tesla T4. |
| |
| Reviewed-by: Cornelia Huck <cohuck@redhat.com> |
| Signed-off-by: Alex Williamson <alex.williamson@redhat.com> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/vfio/pci/vfio_pci_config.c | 7 ++++++- |
| 1 file changed, 6 insertions(+), 1 deletion(-) |
| |
| diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c |
| index 608b94a0ee0e0..ef45b8f5bf510 100644 |
| --- a/drivers/vfio/pci/vfio_pci_config.c |
| +++ b/drivers/vfio/pci/vfio_pci_config.c |
| @@ -1461,7 +1461,12 @@ static int vfio_cap_init(struct vfio_pci_device *vdev) |
| if (ret) |
| return ret; |
| |
| - if (cap <= PCI_CAP_ID_MAX) { |
| + /* |
| + * ID 0 is a NULL capability, conflicting with our fake |
| + * PCI_CAP_ID_BASIC. As it has no content, consider it |
| + * hidden for now. |
| + */ |
| + if (cap && cap <= PCI_CAP_ID_MAX) { |
| len = pci_cap_length[cap]; |
| if (len == 0xFF) { /* Variable length */ |
| len = vfio_cap_len(vdev, cap, pos); |
| -- |
| 2.25.1 |
| |