* [PATCH] iommu/dmar: ignore devices with out-of-spec domain number
@ 2020-02-11 9:03 Daniel Drake
2020-02-21 13:19 ` Lu Baolu
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Drake @ 2020-02-11 9:03 UTC (permalink / raw)
To: dwmw2, baolu.lu, joro; +Cc: iommu, linux
VMD subdevices are created with a PCI domain ID of 0x10000 or
higher.
These subdevices are also handled like all other PCI devices by
dmar_pci_bus_notifier().
However, when dmar_alloc_pci_notify_info() take records of such devices,
it will truncate the domain ID to a u16 value (in info->seg).
The device at (e.g.) 10000:00:02.0 is then treated by the DMAR code as if
it is 0000:00:02.0.
In the unlucky event that a real device also exists at 0000:00:02.0 and
also has a device-specific entry in the DMAR table,
dmar_insert_dev_scope() will crash on:
BUG_ON(i >= devices_cnt);
That's basically a sanity check that only one PCI device matches a
single DMAR entry; in this case we seem to have two matching devices.
Fix this by ignoring devices that have a domain number higher than
what can be looked up in the DMAR table.
This problem was carefully diagnosed by Jian-Hong Pan.
Signed-off-by: Daniel Drake <drake@endlessm.com>
---
Notes:
This problem was detected with a non-upstream patch
"PCI: Add Intel remapped NVMe device support"
(https://marc.info/?l=linux-ide&m=156015271021615&w=2)
This patch creates PCI devices in the same way as VMD, and hence
I believe VMD would hit the same problem that we encountered here, when
a VMD-using product comes along that meets the mentioned conditions.
However this hasn't actually been tested on VMD (don't have the hardware)
so if I've missed anything and/or it's not a real issue then feel free to
drop this patch.
drivers/iommu/dmar.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 071bb42bbbc5..8f94c817a7b5 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -28,6 +28,7 @@
#include <linux/slab.h>
#include <linux/iommu.h>
#include <linux/numa.h>
+#include <linux/limits.h>
#include <asm/irq_remapping.h>
#include <asm/iommu_table.h>
@@ -128,6 +129,13 @@ dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigned long event)
BUG_ON(dev->is_virtfn);
+ /*
+ * Ignore devices that have a domain number higher than what can
+ * be looked up in DMAR, e.g. VMD subdevices with domain 0x10000
+ */
+ if (pci_domain_nr(dev->bus) > U16_MAX)
+ return NULL;
+
/* Only generate path[] for device addition event */
if (event == BUS_NOTIFY_ADD_DEVICE)
for (tmp = dev; tmp; tmp = tmp->bus->self)
--
2.20.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iommu/dmar: ignore devices with out-of-spec domain number
2020-02-11 9:03 [PATCH] iommu/dmar: ignore devices with out-of-spec domain number Daniel Drake
@ 2020-02-21 13:19 ` Lu Baolu
0 siblings, 0 replies; 2+ messages in thread
From: Lu Baolu @ 2020-02-21 13:19 UTC (permalink / raw)
To: Daniel Drake, dwmw2, joro; +Cc: iommu, linux
Hi,
On 2020/2/11 17:03, Daniel Drake wrote:
> VMD subdevices are created with a PCI domain ID of 0x10000 or
> higher.
>
> These subdevices are also handled like all other PCI devices by
> dmar_pci_bus_notifier().
>
> However, when dmar_alloc_pci_notify_info() take records of such devices,
> it will truncate the domain ID to a u16 value (in info->seg).
> The device at (e.g.) 10000:00:02.0 is then treated by the DMAR code as if
> it is 0000:00:02.0.
>
> In the unlucky event that a real device also exists at 0000:00:02.0 and
> also has a device-specific entry in the DMAR table,
> dmar_insert_dev_scope() will crash on:
> BUG_ON(i >= devices_cnt);
>
> That's basically a sanity check that only one PCI device matches a
> single DMAR entry; in this case we seem to have two matching devices.
>
> Fix this by ignoring devices that have a domain number higher than
> what can be looked up in the DMAR table.
>
> This problem was carefully diagnosed by Jian-Hong Pan.
>
> Signed-off-by: Daniel Drake<drake@endlessm.com>
Queued for v5.7. Thanks!
Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-21 13:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11 9:03 [PATCH] iommu/dmar: ignore devices with out-of-spec domain number Daniel Drake
2020-02-21 13:19 ` Lu Baolu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).