Unverified Commit 2b71d62e authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14567 vfio/pci: Properly hide first-in-list PCIe extended capability

parents 11e4defb 547af316
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -315,6 +315,10 @@ static int vfio_virt_config_read(struct vfio_pci_device *vdev, int pos,
	return count;
}

static struct perm_bits direct_ro_perms = {
	.readfn = vfio_direct_config_read,
};

/* Default capability regions to read-only, no-virtualization */
static struct perm_bits cap_perms[PCI_CAP_ID_MAX + 1] = {
	[0 ... PCI_CAP_ID_MAX] = { .readfn = vfio_direct_config_read }
@@ -1837,9 +1841,17 @@ static ssize_t vfio_config_do_rw(struct vfio_pci_device *vdev, char __user *buf,
		cap_start = *ppos;
	} else {
		if (*ppos >= PCI_CFG_SPACE_SIZE) {
			WARN_ON(cap_id > PCI_EXT_CAP_ID_MAX);

			/*
			 * We can get a cap_id that exceeds PCI_EXT_CAP_ID_MAX
			 * if we're hiding an unknown capability at the start
			 * of the extended capability list.  Use default, ro
			 * access, which will virtualize the id and next values.
			 */
			if (cap_id > PCI_EXT_CAP_ID_MAX)
				perm = &direct_ro_perms;
			else
				perm = &ecap_perms[cap_id];

			cap_start = vfio_find_cap_start(vdev, *ppos);
		} else {
			WARN_ON(cap_id > PCI_CAP_ID_MAX);