iommu/vt-d: Make RMRR matching compatible with older kernels
Joerg Roedel
maintainercover iommu/vt-d: Make RMRR matching compatible with older kernels
Hi,
here is a patch-set to make RMRR matching in the Intel IOMMU driver compatible with older kernels. This is needed because some BIOS vendors build RMRR entries to work with older kernels, but that will break on newer ones that implement the correct PCI device scope matching scheme defined in the VT-d specification.
Make the current Intel IOMMU driver work with the old RMRR entries too.
These patches have been tested in an affected system and fix the issue seen there (newer kernel did not setup RMRR entries for a plugged in device).
Regards,
Joerg
Joerg Roedel (2):
iommu/vt-d: Store bus information in RMRR PCI device path iommu/vt-d: Work around broken RMRR firmware entries
drivers/iommu/dmar.c | 23 ++++++++++++++++++++--- include/linux/dmar.h | 8 +++++++- 2 files changed, 27 insertions(+), 4 deletions(-)
Signature · 1 line
1.9.1
Joerg Roedel
maintainerPATCH 1/2 iommu/vt-d: Store bus information in RMRR PCI device path
From: Joerg Roedel <[email protected]>
This will be used later to match broken RMRR entries.
--- drivers/iommu/dmar.c | 1 + include/linux/dmar.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/iommu/dmar.c +1 -0
@@ -155,6 +155,7 @@ dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigned long event)if (event ==BUS_NOTIFY_ADD_DEVICE ) {for (tmp = dev; tmp; tmp = tmp->bus->self) { level--; + info->path[level].bus = tmp->bus->number; info->path[level].device =PCI_SLOT (tmp->devfn); info->path[level].function =PCI_FUNC (tmp->devfn);if (pci_is_root_bus (tmp->bus))
include/linux/dmar.h +7 -1
@@ -56,13 +56,19 @@ struct dmar_drhd_unit {struct intel_iommu *iommu; }; +struct dmar_pci_path { +u8 bus; +u8 device; +u8 function; +}; +struct dmar_pci_notify_info {struct pci_dev *dev;unsigned long event;int bus;u16 seg;u16 level; -struct acpi_dmar_pci_path path[]; +struct dmar_pci_path path[]; } __attribute__((packed));extern struct rw_semaphore dmar_global_lock;
Signature · 1 line
1.9.1
Joerg Roedel
maintainerPATCH 2/2 iommu/vt-d: Work around broken RMRR firmware entries
In reply to Joerg RoedelFrom: Joerg Roedel <[email protected]>
The VT-d specification states that an RMRR entry in the DMAR table needs to specify the full path to the device. This is also how newer Linux kernels implement it.
Unfortunatly older drivers just match for the target device and not the full path to the device, so that BIOS vendors implement that behavior into their BIOSes to make them work with older Linux kernels. But those RMRR entries break on newer Linux kernels.
Work around this issue by adding a fall-back into the RMRR matching code to match those old RMRR entries too.
--- drivers/iommu/dmar.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/iommu/dmar.c +19 -3
@@ -178,17 +178,33 @@ static bool dmar_match_pci_path(struct dmar_pci_notify_info *info, int bus,int i;if (info->bus != bus) -return false; + goto fallback;if (info->level != count) -return false; + goto fallback;for (i =0 ; i < count; i++) {if (path[i].device != info->path[i].device || path[i].function != info->path[i].function) -return false; + goto fallback; }return true; + +fallback: + +if (count !=1 ) +return false; + + i = info->level -1 ; +if (bus == info->path[i].bus && + path[0 ].device == info->path[i].device && + path[0 ].function == info->path[i].function) { +pr_info (FW_BUG "RMRR entry for device %02x:%02x.%x is broken - applying workaround\n" , + bus, path[0 ].device, path[0 ].function); +return true; + } + +return false; }/* Return: > 0 if match found, 0 if no match found, < 0 if error happens */
Signature · 1 line
1.9.1
Re: [PATCH 2/2] iommu/vt-d: Work around broken RMRR firmware entries
Quoted 52 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
The VT-d specification states that an RMRR entry in the DMAR table needs to specify the full path to the device. This is also how newer Linux kernels implement it.
Unfortunatly older drivers just match for the target device and not the full path to the device, so that BIOS vendors implement that behavior into their BIOSes to make them work with older Linux kernels. But those RMRR entries break on newer Linux kernels.
Work around this issue by adding a fall-back into the RMRR matching code to match those old RMRR entries too.
Signed-off-by Joerg Roedel <[email protected]>--- drivers/iommu/dmar.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)drivers/iommu/dmar.c +12
-3@@ -178,17 +178,33 @@ static bool dmar_match_pci_path(struct dmar_pci_notify_info *info, int bus,int i;if (info->bus != bus) -return false; + goto fallback;if (info->level != count) -return false; + goto fallback;for (i =0 ; i < count; i++) {if (path[i].device != info->path[i].device || path[i].function != info->path[i].function) -return false; + goto fallback; }return true; + +fallback: + +if (count !=1 ) +return false; + + i = info->level -1 ; + if (bus == info->path[i].bus && + path[0].device == info->path[i].device &&
drivers/iommu/dmar.c static bool dmar_match_pci_path(struct dmar_pci_notify_info *info, int bus, · line 210
Quoted 10 lines
drivers/iommu/dmar.c +7
-0+ path[0].function == info->path[i].function) { +pr_info (FW_BUG "RMRR entry for device %02x:%02x.%x is broken - applying workaround\n" , + bus, path[0 ].device, path[0 ].function); +return true; + } + +return false; }/* Return: > 0 if match found, 0 if no match found, < 0 if error happens */
Hi Joerg,
Thanks for fixing this:)
Regards!
Gerry