Skip to contentSkip to conversation

vt-d: Fixpanic in msi_msg_read_remap_rte with acpi=off

Xen-changelog Miroslav Rezanina 2 participants 2 messages Oct 16, 2009 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

Xen kernel panics when "acpi=off" is set. Problem is caused by dereferncing NULL pointer in drhd after calling acpi_find_matched_drhd_unit. As acpi_find_matched_drhd_unit can return NULL, checks has to be done before returned value is used.

Quoted 11 lines · ----- "Dexuan Cui

But when I use c/s 20330 and use "iommu=1 acpi=off", I still get the the panic:

(XEN) Xen call trace:

(XEN)    [<ffff82c4801401b5>] ats_device+0x53/0x10e
(XEN)    [<ffff82c48013c8e5>] intel_iommu_domain_init+0xa8/0x200
(XEN)    [<ffff82c4801379dd>] iommu_domain_init+0x74/0x76
(XEN)    [<ffff82c48014c437>] arch_domain_create+0x544/0x94a
(XEN)    [<ffff82c48010676a>] domain_create+0x26c/0x3fd
(XEN)    [<ffff82c48024cdb5>] __start_xen+0x5264/0x557f
Quoted 8 lines

Actually when iommu=1 and acpi=off, in __start_xen() -> acpi_boot_init(), acpi_dmar_init() can't be invoked at all and hence parse_dmar_table() can't be invoked, as a result, we should not try to use VT-d at all, however, the global variable iommu_enabled is left set to 1.

So I don't think this changeset is the right fix. I think the correct one should be: in disable_acpi(), we force iommu_enabled to 0.

To prevent this problem, disable iommu if acpi is disabled.

Patch
---

xen/drivers/passthrough/iommu.c +6 -0
diff -r 97684ba1303e xen/drivers/passthrough/iommu.c
@@ -39,6 +39,7 @@
  *   no-intremap                Disable VT-d Interrupt Remapping
  */
 custom_param("iommu", parse_iommu_param);
+extern int acpi_disabled;
 int iommu_enabled = 0;
 int iommu_pv_enabled = 0;
 int force_iommu = 0;
@@ -266,6 +267,11 @@
     if ( !iommu_enabled )
         goto out;
 
+    if ( !acpi_disabled ) {
+	iommu_enabled = 0;
+	goto out;
+    }
+
     rc = iommu_hardware_setup();
 
     iommu_enabled = (rc == 0);
xen/drivers/passthrough/vtd/intremap.c +4 -0
diff -r 97684ba1303e xen/drivers/passthrough/vtd/intremap.c
@@ -461,6 +461,8 @@
     struct ir_ctrl *ir_ctrl;
 
     drhd = acpi_find_matched_drhd_unit(pdev);
+    if (!drhd)
+	return;
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
@@ -479,6 +481,8 @@
     struct ir_ctrl *ir_ctrl;
 
     drhd = acpi_find_matched_drhd_unit(pdev);
+    if (!drhd)
+	return;
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
xen/drivers/passthrough/vtd/iommu.c +3 -1
diff -r 97684ba1303e xen/drivers/passthrough/vtd/iommu.c
@@ -1412,6 +1412,8 @@
         return -ENODEV;
 
     drhd = acpi_find_matched_drhd_unit(pdev);
+    if (!drhd)
+	return -ENODEV;
     pdev_iommu = drhd->iommu;
     domain_context_unmap(source, bus, devfn);
 
@@ -1425,7 +1427,7 @@
     for_each_pdev ( source, pdev )
     {
         drhd = acpi_find_matched_drhd_unit(pdev);
-        if ( drhd->iommu == pdev_iommu )
+        if ( drhd && drhd->iommu == pdev_iommu )
         {
             found = 1;
             break;

---
Miroslav Rezanina
Software Engineer - Virtualization Team - XEN kernel

#2 lore raw

Hi Miroslav and Keir,
When acpi=off and we set iommu_enabled=0, the execution of xen can't reach the acpi_find_matched_drhd_unit Miroslav explicitly points out one by one. I think I can give a cleaner fix. Please see the attached patch.

Thanks,
-- Dexuan

-----Original Message-----
From: Miroslav Rezanina [mailto:[email protected]]
Sent: 2009年10月16日 19:16
To: Cui, Dexuan
Cc: Keir Fraser; [email protected]
Subject: Re: [Xen-changelog] [xen-unstable]vt-d: Fixpanic in msi_msg_read_remap_rte with acpi=off

Xen kernel panics when "acpi=off" is set. Problem is caused by dereferncing NULL pointer in drhd after calling acpi_find_matched_drhd_unit. As acpi_find_matched_drhd_unit can return NULL, checks has to be done before returned value is used.

Quoted 11 lines · ----- "Dexuan Cui

But when I use c/s 20330 and use "iommu=1 acpi=off", I still get the the panic:

(XEN) Xen call trace:

(XEN)    [<ffff82c4801401b5>] ats_device+0x53/0x10e
(XEN)    [<ffff82c48013c8e5>] intel_iommu_domain_init+0xa8/0x200
(XEN)    [<ffff82c4801379dd>] iommu_domain_init+0x74/0x76
(XEN)    [<ffff82c48014c437>] arch_domain_create+0x544/0x94a
(XEN)    [<ffff82c48010676a>] domain_create+0x26c/0x3fd
(XEN)    [<ffff82c48024cdb5>] __start_xen+0x5264/0x557f
Quoted 8 lines

Actually when iommu=1 and acpi=off, in __start_xen() -> acpi_boot_init(), acpi_dmar_init() can't be invoked at all and hence parse_dmar_table() can't be invoked, as a result, we should not try to use VT-d at all, however, the global variable iommu_enabled is left set to 1.

So I don't think this changeset is the right fix. I think the correct one should be: in disable_acpi(), we force iommu_enabled to 0.

To prevent this problem, disable iommu if acpi is disabled.

Patch
---

xen/drivers/passthrough/iommu.c +6 -0
diff -r 97684ba1303e xen/drivers/passthrough/iommu.c
@@ -39,6 +39,7 @@
  *   no-intremap                Disable VT-d Interrupt Remapping
  */
 custom_param("iommu", parse_iommu_param);
+extern int acpi_disabled;
 int iommu_enabled = 0;
 int iommu_pv_enabled = 0;
 int force_iommu = 0;
@@ -266,6 +267,11 @@
     if ( !iommu_enabled )
         goto out;
 
+    if ( !acpi_disabled ) {
+	iommu_enabled = 0;
+	goto out;
+    }
+
     rc = iommu_hardware_setup();
 
     iommu_enabled = (rc == 0);
xen/drivers/passthrough/vtd/intremap.c +4 -0
diff -r 97684ba1303e xen/drivers/passthrough/vtd/intremap.c
@@ -461,6 +461,8 @@
     struct ir_ctrl *ir_ctrl;
 
     drhd = acpi_find_matched_drhd_unit(pdev);
+    if (!drhd)
+	return;
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
@@ -479,6 +481,8 @@
     struct ir_ctrl *ir_ctrl;
 
     drhd = acpi_find_matched_drhd_unit(pdev);
+    if (!drhd)
+	return;
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
xen/drivers/passthrough/vtd/iommu.c +3 -1
diff -r 97684ba1303e xen/drivers/passthrough/vtd/iommu.c
@@ -1412,6 +1412,8 @@
         return -ENODEV;
 
     drhd = acpi_find_matched_drhd_unit(pdev);
+    if (!drhd)
+	return -ENODEV;
     pdev_iommu = drhd->iommu;
     domain_context_unmap(source, bus, devfn);
 
@@ -1425,7 +1427,7 @@
     for_each_pdev ( source, pdev )
     {
         drhd = acpi_find_matched_drhd_unit(pdev);
-        if ( drhd->iommu == pdev_iommu )
+        if ( drhd && drhd->iommu == pdev_iommu )
         {
             found = 1;
             break;

---
Miroslav Rezanina
Software Engineer - Virtualization Team - XEN kernel

vt-d: do not enable VT-d on acpi=off

This reverts changeset 20323: 2370e16ab6d3 and adds a small checking in iommu_setup().

xen/drivers/passthrough/iommu.c +7 -3
diff -r 0705efd9c69e xen/drivers/passthrough/iommu.c
@@ -266,9 +266,13 @@ int iommu_setup(void)
 {
     int rc = -ENODEV;
 
-    rc = iommu_hardware_setup();
-
-    iommu_enabled = (rc == 0);
+    if ( acpi_disabled )
+        iommu_enabled = 0;
+    else
+    {
+        rc = iommu_hardware_setup();
+        iommu_enabled = (rc == 0);
+    }
 
     if ( force_iommu && !iommu_enabled )
         panic("IOMMU setup failed, crash Xen for security purpose!\n");
xen/drivers/passthrough/vtd/intremap.c +2 -4
diff -r 0705efd9c69e xen/drivers/passthrough/vtd/intremap.c
@@ -563,8 +563,7 @@ void msi_msg_read_remap_rte(
     struct iommu *iommu = NULL;
     struct ir_ctrl *ir_ctrl;
 
-    if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
-        return;
+    drhd = acpi_find_matched_drhd_unit(pdev);
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
@@ -582,8 +581,7 @@ void msi_msg_write_remap_rte(
     struct iommu *iommu = NULL;
     struct ir_ctrl *ir_ctrl;
 
-    if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
-        return;
+    drhd = acpi_find_matched_drhd_unit(pdev);
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
xen/drivers/passthrough/vtd/iommu.c +2 -3
diff -r 0705efd9c69e xen/drivers/passthrough/vtd/iommu.c
@@ -1343,8 +1343,7 @@ static int reassign_device_ownership(
     if (!pdev)
         return -ENODEV;
 
-    if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
-        return -ENODEV;
+    drhd = acpi_find_matched_drhd_unit(pdev);
     pdev_iommu = drhd->iommu;
     domain_context_unmap(source, bus, devfn);
 
@@ -1358,7 +1357,7 @@ static int reassign_device_ownership(
     for_each_pdev ( source, pdev )
     {
         drhd = acpi_find_matched_drhd_unit(pdev);
-        if ( drhd && drhd->iommu == pdev_iommu )
+        if ( drhd->iommu == pdev_iommu )
         {
             found = 1;
             break;

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