From 8d50d40ff8dfed121ab7db86d7c5f5acf840465d Mon Sep 17 00:00:00 2001 From: Anitha Chrisanthus Date: Tue, 12 Jun 2018 03:49:05 -0700 Subject: [PATCH] hv: More changes to enable GPU passthru Snoop control is not supported in the graphics VT-d engine and so should be disabled in the PTEs. Also enabled iommu for graphics in the dmar_drhd array. v2: removed disable iommu in handle_one_drhd and combined if cond. v3: minor code review changes v4: moved the snoop control change to ept.c to accomodate upstream changes Signed-off-by: Anitha Chrisanthus Reviewed-by: Gong Zhipeng --- hypervisor/arch/x86/ept.c | 2 +- hypervisor/arch/x86/vtd.c | 9 +++++++-- hypervisor/boot/dmar_parse.c | 7 ------- hypervisor/bsp/sbl/sbl.c | 2 +- hypervisor/bsp/uefi/include/bsp/bsp_cfg.h | 1 - hypervisor/include/arch/x86/vtd.h | 2 ++ 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index b87f98551..9ec6f6f8b 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -489,7 +489,7 @@ int ept_mmap(struct vm *vm, uint64_t hpa, * to force snooping of PCIe devices if the page * is cachable */ - if ((prot & IA32E_EPT_MT_MASK) != IA32E_EPT_UNCACHED) + if ((prot & IA32E_EPT_MT_MASK) != IA32E_EPT_UNCACHED && iommu_snoop) prot |= IA32E_EPT_SNOOP_CTRL; map_mem(&map_params, (void *)hpa, (void *)gpa, size, prot); diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index 5be872d1c..67bb19d2d 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -152,6 +152,8 @@ struct iommu_domain { uint64_t trans_table_ptr; }; +bool iommu_snoop = true; /* enable iommu snoop control */ + static struct list_head dmar_drhd_units; static uint32_t dmar_hdrh_unit_count; @@ -419,9 +421,13 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint) * How to guarantee it when EPT is used as second-level * translation paging structures? */ - if (iommu_ecap_sc(dmar_uint->ecap) == 0U) + + /* enable snoop control only if it is supported by all the VT-d engines */ + if (!iommu_ecap_sc(dmar_uint->ecap)) { dev_dbg(ACRN_DBG_IOMMU, "dmar uint doesn't support snoop control!"); + iommu_snoop = false; + } dmar_uint->max_domain_id = iommu_cap_ndoms(dmar_uint->cap) - 1; @@ -1009,7 +1015,6 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, ASSERT(false, "dmaru doesn't support trans passthrough"); } else { - /* TODO: add Device TLB support */ upper = DMAR_SET_BITSLICE(upper, CTX_ENTRY_UPPER_AW, width_to_agaw( diff --git a/hypervisor/boot/dmar_parse.c b/hypervisor/boot/dmar_parse.c index 4767dce7e..ffda5c63f 100644 --- a/hypervisor/boot/dmar_parse.c +++ b/hypervisor/boot/dmar_parse.c @@ -270,13 +270,6 @@ handle_one_drhd(struct acpi_dmar_hardware_unit *acpi_drhd, consumed = handle_dmar_devscope(dev_scope, cp, remaining); - if (((drhd->segment << 16) | - (dev_scope->bus << 8) | - dev_scope->devfun) == CONFIG_GPU_SBDF) { - ASSERT(dev_count == 1, "no dedicated iommu for gpu"); - drhd->ignore = true; - } - if (consumed <= 0) break; diff --git a/hypervisor/bsp/sbl/sbl.c b/hypervisor/bsp/sbl/sbl.c index 5b79fb977..0ccbb66b0 100644 --- a/hypervisor/bsp/sbl/sbl.c +++ b/hypervisor/bsp/sbl/sbl.c @@ -33,7 +33,7 @@ static struct dmar_drhd drhd_info_array[] = { /* Ignore the iommu for intel graphic device since GVT-g needs * vtd disabled for gpu */ - .ignore = true, + .ignore = false, .devices = default_drhd_unit_dev_scope0, }, { diff --git a/hypervisor/bsp/uefi/include/bsp/bsp_cfg.h b/hypervisor/bsp/uefi/include/bsp/bsp_cfg.h index d9e926e42..b8979969a 100644 --- a/hypervisor/bsp/uefi/include/bsp/bsp_cfg.h +++ b/hypervisor/bsp/uefi/include/bsp/bsp_cfg.h @@ -21,7 +21,6 @@ #define CONFIG_RAM_START 0x20000000 #define CONFIG_RAM_SIZE 0x02000000 /* 32M */ #define CONFIG_DMAR_PARSE_ENABLED 1 -#define CONFIG_GPU_SBDF 0x00000010 /* 0000:00:02.0 */ #define CONFIG_EFI_STUB 1 #define CONFIG_UEFI_OS_LOADER_NAME "\\EFI\\org.clearlinux\\bootloaderx64.efi" #define CONFIG_MTRR_ENABLED 1 diff --git a/hypervisor/include/arch/x86/vtd.h b/hypervisor/include/arch/x86/vtd.h index 070f048fe..8231e13ea 100644 --- a/hypervisor/include/arch/x86/vtd.h +++ b/hypervisor/include/arch/x86/vtd.h @@ -206,6 +206,8 @@ struct dmar_info { extern struct dmar_info *get_dmar_info(void); +extern bool iommu_snoop; + struct iommu_domain; /* Assign a device specified by bus & devfun to a iommu domain */