iommu/vt-d: Fix PCI bus rescan device hot add
Subsystems (2)
PATCH 1/1 iommu/vt-d: Fix PCI bus rescan device hot add
Notifier calling chain uses priority to determine the execution order of the notifiers or listeners registered to the chain. PCI bus device hot add utilizes the notification mechanism.
The current code sets low priority (INT_MIN) to Intel dmar_pci_bus_notifier and postpones DMAR decoding after adding new device into IOMMU. The result is that struct device pointer cannot be found in DRHD search for the new device's DMAR/IOMMU. Subsequently, the device is put under the "catch-all" IOMMU instead of the correct one. This could cause system hang when device TLB invalidation is sent to the wrong IOMMU. Invalidation timeout error and hard lockup have been observed and data inconsistency/crush may occur as well.
This patch fixes the issue by setting a positive priority(1) for dmar_pci_bus_notifier while the priority of IOMMU bus notifier uses the default value(0), therefore DMAR decoding will be in advance of DRHD search for a new device to find the correct IOMMU.
Following is a 2-step example that triggers the bug by simulating PCI device hot add behavior in Intel Sapphire Rapids server.
echo 1 > /sys/bus/pci/devices/0000:6a:01.0/remove
echo 1 > /sys/bus/pci/rescan
---
This is a quick fix for the bug reported. Intel internally evaluated another redesigned solution that eliminates dmar pci bus notifier to simplify the workflow of pci hotplug and improve its runtime efficiency.
While considering the fix could apply to downstream and the complexity of pci hotplug workflow change may significantly increase the engineering effort to downstream the patch, the choice is to submit this simple patch to help the deployment of this bug fix.
---
drivers/iommu/intel/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/dmar.c +1 -1
@@ -383,7 +383,7 @@ static int dmar_pci_bus_notifier(struct notifier_block *nb,static struct notifier_block dmar_pci_bus_nb = { .notifier_call = dmar_pci_bus_notifier, - .priority =INT_MIN , + .priority =1 , }; static struct dmar_drhd_unit *
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Baolu Lu
maintainerHi Joerg,
Quoted 35 lines · Yian Chen
Notifier calling chain uses priority to determine the execution order of the notifiers or listeners registered to the chain. PCI bus device hot add utilizes the notification mechanism.
The current code sets low priority (
INT_MIN) to Inteldmar_pci_bus_notifierand postpones DMAR decoding after adding new device into IOMMU. The result is that struct device pointer cannot be found in DRHD search for the new device's DMAR/IOMMU. Subsequently, the device is put under the "catch-all" IOMMU instead of the correct one. This could cause system hang when device TLB invalidation is sent to the wrong IOMMU. Invalidation timeout error and hard lockup have been observed and data inconsistency/crush may occur as well.This patch fixes the issue by setting a positive priority(1) for
dmar_pci_bus_notifierwhile the priority of IOMMU bus notifier uses the default value(0), therefore DMAR decoding will be in advance of DRHD search for a new device to find the correct IOMMU.Following is a 2-step example that triggers the bug by simulating PCI device hot add behavior in Intel Sapphire Rapids server.
echo 1 > /sys/bus/pci/devices/0000:6a:01.0/remove
echo 1 >/sys/bus/pci/rescanFixes 59ce0515cdaf ("iommu/vt-d: Update DRHD/RMRR/ATSR device scope")Cc [email protected] # v3.15+Reported-by Zhang, Bernice <[email protected]>Signed-off-by Jacob Pan <[email protected]>Signed-off-by Yian Chen <[email protected]>---
This is a quick fix for the bug reported. Intel internally evaluated another redesigned solution that eliminates dmar pci bus notifier to simplify the workflow of pci hotplug and improve its runtime efficiency.
Quoted 4 lines
While considering the fix could apply to downstream and the complexity of pci hotplug workflow change may significantly increase the engineering effort to downstream the patch, the choice is to submit this simple patch to help the deployment of this bug fix.
Yian has been worked on using IOMMU bus notifier to solve this problem.
It turns out that due to the following facts, we need to refactor the IOMMU core and Intel DMAR Code:
- Interrupt remapping also requires Intel DMAR code. Therefore, when IOMMU is not enabled, the PCI bus notifier in DMAR is still required.
- The IOMMU PCI bus notifier calls .probe_device() which lacks of the information about hot-add or static boot.
Considering that the problem described here is a serious problem, because users can easily damage the system by writing sysfs files on some platforms, we need a quick fix for both upstream and stable kernels. The refactoring code will be discussed in a separate series.
How do you like it? If you agree, I can queue it in my next pull request for fixes.
Best regards,
baolu
Quoted 10 lines
---
drivers/iommu/intel/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/intel/dmar.c +0
-0
drivers/iommu/intel/dmar.c static int dmar_pci_bus_notifier(struct notifier_block *nb, · line 389
Quoted 8 lines
drivers/iommu/intel/dmar.c +1
-1@@ -383,7 +383,7 @@ static int dmar_pci_bus_notifier(struct notifier_block *nb,static struct notifier_block dmar_pci_bus_nb = { .notifier_call = dmar_pci_bus_notifier, - .priority =INT_MIN , + .priority =1 , }; static struct dmar_drhd_unit *
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerHi Baolu,
Quoted 2 lines · Baolu Lu
How do you like it? If you agree, I can queue it in my next pull request for fixes.
Would it help to tie DMAR and IOMMU components together, so that selecting DMAR for IRQ remapping also selects IOMMU? The IOMMU can be in PT mode and I think it would simplify a lot of things.
Regards,
Joerg
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Baolu Lu
maintainerHi Joerg,
Quoted 9 lines · Joerg Roedel
Hi Baolu,
Quoted 2 lines · Baolu Lu
How do you like it? If you agree, I can queue it in my next pull request for fixes.
Would it help to tie DMAR and IOMMU components together, so that selecting DMAR for IRQ remapping also selects IOMMU? The IOMMU can be in PT mode and I think it would simplify a lot of things.
It makes sense as far as I am aware. By putting IOMMUs in pass-through mode, there will be no run-time costs and things could be simplified a lot.
Besides the refactoring efforts, we still need this quick fix so that the fix could be propagated to various stable and vendors' downstream trees.
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 6 lines · Baolu Lu
It makes sense as far as I am aware. By putting IOMMUs in pass-through mode, there will be no run-time costs and things could be simplified a lot.
Besides the refactoring efforts, we still need this quick fix so that the fix could be propagated to various stable and vendors' downstream trees.
Patch is applied now for 5.19.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu