Skip to contentSkip to conversation

AMD IOMMU: Parse IVRS table early to prevent iommu_enabled from being disabled

PATCH In review Wei Wang2 2 participants 5 messages Oct 28, 2009 – Oct 29, 2009

lore
Share & tools
lore

Wei Wang2

author
#0 lore raw

PATCH 1/1 AMD IOMMU: Parse IVRS table early to prevent iommu_enabled from being disabled

This patch moves IVRS table parsing functions into an early position, which prevent iommu_enabled from being disabled by failure dmar table detection. Thanks,
Wei

Signature · 11 lines
AMD GmbH, Germany
Operating System Research Center

Legal Information:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34
85609 Dornach b. München

Geschäftsführer: Andrew Bowd, Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis München
Registergericht München, HRB Nr. 43632
xen/arch/x86/acpi/boot.c +2 -0
diff -r 42e9682e4b61 xen/arch/x86/acpi/boot.c
@@ -936,6 +936,8 @@ int __init acpi_boot_init(void)
 
 	acpi_dmar_init();
 
+	acpi_ivrs_init();
+
 	acpi_mmcfg_init();
 
 	return 0;
xen/drivers/passthrough/amd/iommu_acpi.c +18 -3
diff -r 42e9682e4b61 xen/drivers/passthrough/amd/iommu_acpi.c
@@ -863,6 +863,7 @@ static int __init detect_iommu_acpi(stru
         return -ENODEV;
     }
 
+    INIT_LIST_HEAD(&amd_iommu_head);
     while ( table->length > (length + sizeof(*ivrs_block)) )
     {
         ivrs_block = (struct acpi_ivrs_block_header *) ((u8 *)table + length);
@@ -972,9 +973,23 @@ static int __init get_last_bdf_acpi(stru
    return 0;
 }
 
-int __init amd_iommu_detect_acpi(void)
-{
-    return acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, detect_iommu_acpi);
+int __init acpi_ivrs_init(void)
+{
+    int rt;
+
+    /* to make sure this flag has not been cleared after vtd detection */
+    iommu_enabled = 1;
+
+    rt = acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, detect_iommu_acpi);
+
+    if ( (rt != 0) || (iommu_found() == 0) )
+    {
+        printk("AMD-Vi: IOMMU not found!\n");
+        iommu_enabled = 0;
+        return -ENODEV;
+    }
+
+    return 0;
 }
 
 int __init amd_iommu_get_ivrs_dev_entries(void)
xen/drivers/passthrough/amd/iommu_init.c +3 -2
diff -r 42e9682e4b61 xen/drivers/passthrough/amd/iommu_init.c
@@ -628,7 +628,7 @@ error_out:
     return -ENODEV;
 }
 
-static void __init amd_iommu_init_cleanup(void)
+void __init amd_iommu_init_cleanup(void)
 {
     struct amd_iommu *iommu, *next;
     int bdf;
@@ -718,7 +718,7 @@ static int __init amd_iommu_setup_device
     int sys_mgt, dev_ex, lint1_pass, lint0_pass,
        nmi_pass, ext_int_pass, init_pass;
 
-    BUG_ON( (ivrs_bdf_entries == 0) || (iommu_enabled) );
+    BUG_ON( (ivrs_bdf_entries == 0) );
 
     /* allocate 'device table' on a 4K boundary */
     device_table.alloc_size = PAGE_SIZE <<
@@ -805,6 +805,7 @@ int __init amd_iommu_init(void)
 
 error_out:
     amd_iommu_init_cleanup();
+    printk("AMD-Vi: Error initialization!\n");
     return -ENODEV;
 }
 
xen/drivers/passthrough/amd/pci_amd_iommu.c +0 -18
diff -r 42e9682e4b61 xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -158,24 +158,6 @@ static void amd_iommu_setup_dom0_devices
     spin_unlock(&pcidevs_lock);
 }
 
-int amd_iov_detect(void)
-{
-    INIT_LIST_HEAD(&amd_iommu_head);
-
-    if ( (amd_iommu_detect_acpi() !=0) || (iommu_found() == 0) )
-    {
-        printk("AMD-Vi: IOMMU not found!\n");
-        return -ENODEV;
-    }
-
-    if ( amd_iommu_init() != 0 )
-    {
-        printk("Error initialization\n");
-        return -ENODEV;
-    }
-    return 0;
-}
-
 static int allocate_domain_resources(struct hvm_iommu *hd)
 {
     /* allocate root table */
xen/include/asm-x86/acpi.h +1 -0
diff -r 42e9682e4b61 xen/include/asm-x86/acpi.h
@@ -154,6 +154,7 @@ extern u8 x86_acpiid_to_apicid[];
 #define MAX_LOCAL_APIC 256
 
 int acpi_dmar_init(void);
+int acpi_ivrs_init(void);
 void acpi_mmcfg_init(void);
 
 /* Incremented whenever we transition through S3. Value is 1 during boot. */
xen/include/asm-x86/hvm/iommu.h +2 -2
diff -r 42e9682e4b61 xen/include/asm-x86/hvm/iommu.h
@@ -5,7 +5,7 @@ extern struct iommu_ops intel_iommu_ops;
 extern struct iommu_ops intel_iommu_ops;
 extern struct iommu_ops amd_iommu_ops;
 extern int intel_vtd_setup(void);
-extern int amd_iov_detect(void);
+extern int amd_iommu_init(void);
 
 static inline struct iommu_ops *iommu_get_ops(void)
 {   
@@ -29,7 +29,7 @@ static inline int iommu_hardware_setup(v
     case X86_VENDOR_INTEL:
         return intel_vtd_setup();
     case X86_VENDOR_AMD:
-        return amd_iov_detect();
+        return amd_iommu_init();
     default:
         BUG();
     }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 2 lines · On 28/10/2009 16:31, "Wei Wang2" <[email protected]> wrote:

This patch moves IVRS table parsing functions into an early position, which prevent iommu_enabled from being disabled by failure dmar table detection.

Not nice. See if c/s 20381 fixes your problem. It's justa cleanup of some VT-d code which should avoid the problem altogether.

-- Keir

author
#2 lore raw
Quoted 9 lines · On Wednesday 28 October 2009 18:30:31 Keir Fraser wrote:
Quoted 3 lines · On 28/10/2009 16:31, "Wei Wang2" <[email protected]> wrote:

This patch moves IVRS table parsing functions into an early position, which prevent iommu_enabled from being disabled by failure dmar table detection.

Not nice. See if c/s 20381 fixes your problem. It's justa cleanup of some VT-d code which should avoid the problem altogether.

-- Keir

Thanks, I have not checked 20381 while creating this patch. I will test it again and send something new if necessary.
-Wei

#3 lore raw
Quoted 6 lines · On 28/10/2009 17:46, "Wei Wang2" <[email protected]> wrote:
Quoted 4 lines

Not nice. See if c/s 20381 fixes your problem. It's justa cleanup of some VT-d code which should avoid the problem altogether.

-- Keir

Thanks, I have not checked 20381 while creating this patch.

That's because I created it in response to your patch! :-)

K.

Quoted 1 line

I will test it again and send something new if necessary.

author
#4 lore raw
Quoted 4 lines · On Wednesday 28 October 2009 19:03:17 Keir Fraser wrote:
Quoted 3 lines · On 28/10/2009 17:46, "Wei Wang2" <[email protected]> wrote:
Quoted 3 lines

Not nice. See if c/s 20381 fixes your problem. It's justa cleanup of some VT-d code which should avoid the problem altogether.

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

-- Keir

Thanks, I have not checked 20381 while creating this patch.

That's because I created it in response to your patch! :-)

K.

Quoted 1 line

I will test it again and send something new if necessary.

Keir,
Attached patch removes a BUG_ON condition, to boot amd iommu system correctly. Thanks,
Wei

Signature · 11 lines
AMD GmbH, Germany
Operating System Research Center

Legal Information:
Advanced Micro Devices GmbH
Karl-Hammerschmidt-Str. 34
85609 Dornach b. München

Geschäftsführer: Andrew Bowd, Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis München
Registergericht München, HRB Nr. 43632
xen/drivers/passthrough/amd/iommu_init.c +1 -1
diff -r c1f2b68b6dca xen/drivers/passthrough/amd/iommu_init.c
@@ -719,7 +719,7 @@ static int __init amd_iommu_setup_device
     int sys_mgt, dev_ex, lint1_pass, lint0_pass,
        nmi_pass, ext_int_pass, init_pass;
 
-    BUG_ON( (ivrs_bdf_entries == 0) || (iommu_enabled) );
+    BUG_ON( (ivrs_bdf_entries == 0) );
 
     /* allocate 'device table' on a 4K boundary */
     device_table.alloc_size = PAGE_SIZE <<

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel