dm: vpci: restrict SOS access assigned PCI device

SOS should not access the physical PCI device which is assigned to other guest.

Tracked-On: #4371
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Li Fei1 2020-01-17 18:39:07 +08:00 committed by wenlingz
parent e8479f84cd
commit 9d3d9c3d1e

View File

@ -395,6 +395,7 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
bool keep_gsi = false;
bool need_reset = true;
struct acrn_assign_pcidev pcidev = {};
uint16_t vendor = 0, device = 0;
ptdev = NULL;
error = -EINVAL;
@ -467,12 +468,20 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
pci_set_cfgdata16(dev, PCIR_MINGNT,
read_config(ptdev->phys_dev, PCIR_MINGNT, 2));
/* Once this device is assigned to other guest, the original guest can't access it again
* So we need to cache verdor and device for filling DSDT.
*/
vendor = read_config(ptdev->phys_dev, PCIR_VENDOR, 2);
device = read_config(ptdev->phys_dev, PCIR_DEVICE, 2);
pci_set_cfgdata16(dev, PCIR_VENDOR, vendor);
pci_set_cfgdata16(dev, PCIR_DEVICE, device);
#if AUDIO_NHLT_HACK
/* device specific handling:
* audio: enable NHLT ACPI table
*/
if (read_config(ptdev->phys_dev, PCIR_VENDOR, 2) == 0x8086 &&
read_config(ptdev->phys_dev, PCIR_DEVICE, 2) == 0x5a98)
if (vendor == 0x8086 && device == 0x5a98)
acpi_table_enable(NHLT_ENTRY_NO);
#endif
@ -1284,15 +1293,14 @@ write_dsdt_sdc(struct pci_vdev *dev)
static void
passthru_write_dsdt(struct pci_vdev *dev)
{
struct passthru_dev *ptdev = (struct passthru_dev *) dev->arg;
uint32_t vendor = 0, device = 0;
uint16_t vendor = 0, device = 0;
vendor = read_config(ptdev->phys_dev, PCIR_VENDOR, 2);
vendor = pci_get_cfgdata16(dev, PCIR_VENDOR);
if (vendor != 0x8086)
return;
device = read_config(ptdev->phys_dev, PCIR_DEVICE, 2);
device = pci_get_cfgdata16(dev, PCIR_DEVICE);
/* Provides ACPI extra info */
if (device == 0x5aaa)