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 – Oct 19, 2009 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 6 lines · ---- "Dexuan Cui

From: "Dexuan Cui" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: "Keir Fraser" <[email protected]>, [email protected]
Sent: Friday, October 16, 2009 4:16:55 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: RE: [Xen-changelog] [xen-unstable]vt-d: Fixpanic in msi_msg_read_remap_rte with acpi=off

Quoted 9 lines

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

Hi Dexuan,
acpi_find_matched_drhd_unit can theoretically return NULL. Is one check so big overhead to risk segmentation fault?

Quoted 11 lines

diff -r 0705efd9c69e xen/drivers/passthrough/iommu.c

xen/drivers/passthrough/iommu.c Fri Oct 16 18:41:46 2009 +0800 renamed from xen/drivers/passthrough/iommu.c Fri Oct 16 09:04:53 2009 +0100 +0 -3
@@ -266,9 +266,13 @@ int iommu_setup(void)
 {
     int rc = -ENODEV;
 
-    rc = iommu_hardware_setup();
-
-     iommu_enabled = (rc == 0);

xen/drivers/passthrough/iommu.c Fri Oct 16 18:41:46 2009 +0800 int iommu_setup(void) · line 278

Quoted 10 lines
xen/drivers/passthrough/iommu.c Fri Oct 16 18:41:46 2009 +0800 renamed from xen/drivers/passthrough/iommu.c Fri Oct 16 09:04:53 2009 +0100 +7 -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");

I miss this part, so this one should be add. However, I would leave checks when calling acpi_find_matched_drhd_unit.

Signature · 6 lines
Miroslav Rezanina
Software Engineer - Virtualization Team - XEN kernel

-- 
Miroslav Rezanina
Software Engineer - Virtualization Team - XEN kernel
#2 lore raw

Hi Miroslav,
I agree we should program defensively.
However, here when acpi=off and iommu=1, or when iommu=0, with my "if ( acpi_disabled ) iommu_enabled = 0" checking, I believe xen's execution can't reach the places you pointed out.
And when (by default acpi=on and ) iommu=1, normally the places can't return NULL either, otherwise the BIOS is buggy or Xen has a bug; in these cases, we can't simply ignore it silently -- I think we should at least print a warning message. So how about my attached new patch?

Thanks,
-- Dexuan

-----Original Message-----
From: Miroslav Rezanina [mailto:[email protected]]
Sent: 2009年10月17日 1:40
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

Quoted 6 lines · ---- "Dexuan Cui

From: "Dexuan Cui" <[email protected]>
To: "Miroslav Rezanina" <[email protected]>
Cc: "Keir Fraser" <[email protected]>, [email protected]
Sent: Friday, October 16, 2009 4:16:55 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: RE: [Xen-changelog] [xen-unstable]vt-d: Fixpanic in msi_msg_read_remap_rte with acpi=off

Quoted 9 lines

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

Hi Dexuan,
acpi_find_matched_drhd_unit can theoretically return NULL. Is one check so big overhead to risk segmentation fault?

Quoted 11 lines

diff -r 0705efd9c69e xen/drivers/passthrough/iommu.c

xen/drivers/passthrough/iommu.c Fri Oct 16 18:41:46 2009 +0800 renamed from xen/drivers/passthrough/iommu.c Fri Oct 16 09:04:53 2009 +0100 +0 -3
@@ -266,9 +266,13 @@ int iommu_setup(void)
 {
     int rc = -ENODEV;
 
-    rc = iommu_hardware_setup();
-
-     iommu_enabled = (rc == 0);

xen/drivers/passthrough/iommu.c Fri Oct 16 18:41:46 2009 +0800 int iommu_setup(void) · line 278

Quoted 10 lines
xen/drivers/passthrough/iommu.c Fri Oct 16 18:41:46 2009 +0800 renamed from xen/drivers/passthrough/iommu.c Fri Oct 16 09:04:53 2009 +0100 +7 -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");

I miss this part, so this one should be add. However, I would leave checks when calling acpi_find_matched_drhd_unit.

Signature · 6 lines
Miroslav Rezanina
Software Engineer - Virtualization Team - XEN kernel

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

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

Also add some debug messages.

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 +14 -2
diff -r 0705efd9c69e xen/drivers/passthrough/vtd/intremap.c
@@ -564,7 +564,13 @@ void msi_msg_read_remap_rte(
     struct ir_ctrl *ir_ctrl;
 
     if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
-        return;
+    {
+        if ( iommu_intremap )
+            dprintk(XENLOG_WARNING VTDPREFIX,
+                    "Cannot acpi_find_matched_drhd_unit!\n");
+        return;
+    }
+
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
@@ -583,7 +589,13 @@ void msi_msg_write_remap_rte(
     struct ir_ctrl *ir_ctrl;
 
     if ( (drhd = acpi_find_matched_drhd_unit(pdev)) == NULL )
-        return;
+    {
+        if ( iommu_intremap )
+            dprintk(XENLOG_WARNING VTDPREFIX,
+                    "Cannot acpi_find_matched_drhd_unit!\n");
+        return;
+    }
+
     iommu = drhd->iommu;
 
     ir_ctrl = iommu_ir_ctrl(iommu);
xen/drivers/passthrough/vtd/iommu.c +9 -1
diff -r 0705efd9c69e xen/drivers/passthrough/vtd/iommu.c
@@ -1570,7 +1570,15 @@ static void setup_dom0_devices(struct do
 
             pdev->domain = d;
             list_add(&pdev->domain_list, &d->arch.pdev_list);
-            domain_context_mapping(d, pdev->bus, pdev->devfn);
+
+            if ( domain_context_mapping(d, pdev->bus, pdev->devfn) != 0 )
+            {
+                dprintk(XENLOG_WARNING VTDPREFIX,
+                    "domain_context_mapping failed for %02x:%02x:%x!\n",
+                    pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+                continue;
+            }
+
             if ( ats_device(0, pdev->bus, pdev->devfn) )
                 enable_ats_device(0, pdev->bus, pdev->devfn);
         }

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