View | Details | Raw Unified | Return to bug 42679 | Differences between
and this patch

Collapse All | Expand All

(-)a/drivers/iommu/amd_iommu_init.c (+58 lines)
Lines 1023-1028 static void __init free_iommu_all(void) Link Here
1023
	}
1023
	}
1024
}
1024
}
1025
1025
1026
static void quirk_map_multi_requester_ids(struct pci_dev *pdev)
1027
{
1028
	int fn;
1029
	u16 devid = PCI_DEVID(pdev->bus->number,
1030
			      pdev->devfn);
1031
	u8 fn_map = pci_multi_requesters(pdev);
1032
1033
	/* this is the common case; a non-quirky device. */
1034
	if (!fn_map)
1035
		return;
1036
1037
	/* Skip the known, already mapped func */
1038
	fn_map &= ~(1<<PCI_FUNC(pdev->devfn));
1039
1040
	for (fn = 0; fn_map >> fn; fn++) {
1041
		if (fn_map & (1<<fn)) {
1042
			u8 quirk_devfn = PCI_DEVFN(PCI_SLOT(devid), fn);
1043
			u16 quirk_devid = PCI_DEVID(pdev->bus->number,
1044
						    quirk_devfn);
1045
			amd_iommu_alias_table[devid] = quirk_devid;
1046
			set_dev_entry_from_acpi(amd_iommu_rlookup_table[devid],
1047
						quirk_devid, 0, 0);
1048
			dev_dbg(&pdev->dev,
1049
				"requester id quirk; ghost func %d mapped", fn);
1050
		}
1051
	}
1052
}
1053
1054
static void quirk_map_requester_id(struct pci_dev *pdev)
1055
{
1056
	u8 quirk_devfn = pci_requester(pdev);
1057
	u16 devid = PCI_DEVID(pdev->bus->number, pdev->devfn);
1058
	u16 quirk_devid = PCI_DEVID(pdev->bus->number, quirk_devfn);
1059
1060
	dev_dbg(&pdev->dev, "checking for incorrect pci requester id quirk..");
1061
1062
	if (pdev->devfn == quirk_devfn)
1063
		return;
1064
1065
	amd_iommu_alias_table[devid] = quirk_devid;
1066
	set_dev_entry_from_acpi(amd_iommu_rlookup_table[devid],
1067
				quirk_devid, 0, 0);
1068
}
1069
1070
static void amd_iommu_pci_quirks(void)
1071
{
1072
	struct pci_dev *pdev = NULL;
1073
1074
	for_each_pci_dev(pdev) {
1075
		/* Check for devices that use multiple requester IDs */
1076
		quirk_map_multi_requester_ids(pdev);
1077
1078
		quirk_map_requester_id(pdev);
1079
	}
1080
}
1081
1026
/*
1082
/*
1027
 * Family15h Model 10h-1fh erratum 746 (IOMMU Logging May Stall Translations)
1083
 * Family15h Model 10h-1fh erratum 746 (IOMMU Logging May Stall Translations)
1028
 * Workaround:
1084
 * Workaround:
Lines 1336-1341 static int __init amd_iommu_init_pci(void) Link Here
1336
			break;
1392
			break;
1337
	}
1393
	}
1338
1394
1395
	amd_iommu_pci_quirks();
1396
1339
	ret = amd_iommu_init_devices();
1397
	ret = amd_iommu_init_devices();
1340
1398
1341
	print_iommu_info();
1399
	print_iommu_info();
(-)a/drivers/iommu/intel-iommu.c (+115 lines)
Lines 1649-1654 static int domain_context_mapping_one(struct dmar_domain *domain, int segment, Link Here
1649
	return 0;
1649
	return 0;
1650
}
1650
}
1651
1651
1652
static void iommu_detach_dev(struct intel_iommu *iommu, u8 bus, u8 devfn);
1653
1654
static void quirk_unmap_multi_requesters(struct pci_dev *pdev, u8 fn_map)
1655
{
1656
	int fn;
1657
	struct intel_iommu *iommu = device_to_iommu(pci_domain_nr(pdev->bus),
1658
						pdev->bus->number, pdev->devfn);
1659
1660
	/* Skip the known, already mapped func */
1661
	fn_map &= ~(1<<PCI_FUNC(pdev->devfn));
1662
1663
	for (fn = 0; fn_map >> fn; fn++) {
1664
		if (fn_map & (1<<fn)) {
1665
			iommu_detach_dev(iommu,
1666
					 pdev->bus->number,
1667
					 PCI_DEVFN(PCI_SLOT(pdev->devfn), fn));
1668
			dev_dbg(&pdev->dev,
1669
				"requester id quirk; ghost func %d unmapped",
1670
				fn);
1671
		}
1672
	}
1673
}
1674
1675
/* For quirky devices that use multiple requester ids. */
1676
static int quirk_map_multi_requester_ids(struct dmar_domain *domain,
1677
		struct pci_dev *pdev,
1678
		int translation)
1679
{
1680
	int fn, err = 0;
1681
	u8 fn_map = pci_multi_requesters(pdev);
1682
1683
	/* this is the common case; a non-quirky device. */
1684
	if (!fn_map)
1685
		return 0;
1686
1687
	/* Skip the known, already mapped func */
1688
	fn_map &= ~(1<<PCI_FUNC(pdev->devfn));
1689
1690
	for (fn = 0; fn_map >> fn; fn++) {
1691
		if (fn_map & (1<<fn)) {
1692
			err = domain_context_mapping_one(domain,
1693
					pci_domain_nr(pdev->bus),
1694
					pdev->bus->number,
1695
					PCI_DEVFN(PCI_SLOT(pdev->devfn), fn),
1696
					translation);
1697
			if (err) {
1698
				dev_err(&pdev->dev,
1699
					"mapping ghost func %d failed", fn);
1700
				quirk_unmap_multi_requesters(pdev,
1701
					fn_map & ((1<<fn)-1));
1702
				return err;
1703
			}
1704
			dev_dbg(&pdev->dev,
1705
				"requester id quirk; ghost func %d mapped", fn);
1706
		}
1707
	}
1708
	return 0;
1709
}
1710
1711
static void quirk_unmap_requester_id(struct pci_dev *pdev)
1712
{
1713
	u8 devfn = pci_requester(pdev);
1714
	struct intel_iommu *iommu = device_to_iommu(pci_domain_nr(pdev->bus),
1715
						pdev->bus->number, pdev->devfn);
1716
1717
	if (pdev->devfn == devfn)
1718
		return;
1719
1720
	iommu_detach_dev(iommu,	pdev->bus->number, devfn);
1721
	dev_dbg(&pdev->dev, "requester id quirk; bugged device unmapped");
1722
}
1723
1724
static int quirk_map_requester_id(struct dmar_domain *domain,
1725
		struct pci_dev *pdev,
1726
		int translation)
1727
{
1728
	u8 devfn = pci_requester(pdev);
1729
	int err;
1730
1731
	dev_dbg(&pdev->dev,
1732
		"checking for incorrect pci requester id quirk...");
1733
1734
	if (pdev->devfn == devfn)
1735
		return 0;
1736
1737
	err = domain_context_mapping_one(domain,
1738
			pci_domain_nr(pdev->bus),
1739
			pdev->bus->number,
1740
			devfn,
1741
			translation);
1742
	if (err) {
1743
		dev_err(&pdev->dev,
1744
			"requester id quirk: mapping dev %02x:%02x.%d failed",
1745
			pdev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
1746
		return err;
1747
	}
1748
	dev_dbg(&pdev->dev,
1749
		"requester id quirk; dmar context entry added: %02x:%02x.%d",
1750
		pdev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
1751
	return 0;
1752
}
1753
1652
static int
1754
static int
1653
domain_context_mapping(struct dmar_domain *domain, struct pci_dev *pdev,
1755
domain_context_mapping(struct dmar_domain *domain, struct pci_dev *pdev,
1654
			int translation)
1756
			int translation)
Lines 1662-1667 domain_context_mapping(struct dmar_domain *domain, struct pci_dev *pdev, Link Here
1662
	if (ret)
1764
	if (ret)
1663
		return ret;
1765
		return ret;
1664
1766
1767
	/* quirk for devices using multiple pci requester ids */
1768
	ret = quirk_map_multi_requester_ids(domain, pdev, translation);
1769
	if (ret)
1770
		return ret;
1771
1772
	/* quirk for devices using single incorrect pci requester id */
1773
	ret = quirk_map_requester_id(domain, pdev, translation);
1774
	if (ret)
1775
		return ret;
1776
1665
	/* dependent device mapping */
1777
	/* dependent device mapping */
1666
	tmp = pci_find_upstream_pcie_bridge(pdev);
1778
	tmp = pci_find_upstream_pcie_bridge(pdev);
1667
	if (!tmp)
1779
	if (!tmp)
Lines 3766-3771 static void domain_remove_one_dev_info(struct dmar_domain *domain, Link Here
3766
			iommu_disable_dev_iotlb(info);
3878
			iommu_disable_dev_iotlb(info);
3767
			iommu_detach_dev(iommu, info->bus, info->devfn);
3879
			iommu_detach_dev(iommu, info->bus, info->devfn);
3768
			iommu_detach_dependent_devices(iommu, pdev);
3880
			iommu_detach_dependent_devices(iommu, pdev);
3881
			quirk_unmap_multi_requesters(pdev,
3882
						pci_multi_requesters(pdev));
3883
			quirk_unmap_requester_id(pdev);
3769
			free_devinfo_mem(info);
3884
			free_devinfo_mem(info);
3770
3885
3771
			spin_lock_irqsave(&device_domain_lock, flags);
3886
			spin_lock_irqsave(&device_domain_lock, flags);
(-)a/drivers/pci/quirks.c (-1 / +148 lines)
Lines 3336-3341 static struct pci_dev *pci_func_0_dma_source(struct pci_dev *dev) Link Here
3336
	return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
3336
	return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
3337
}
3337
}
3338
3338
3339
/* Table of source functions for real devices. The DMA requests for the
3340
 * device are tagged with a different real function as source. This is
3341
 * relevant to multifunction devices.
3342
 */
3339
static const struct pci_dev_dma_source {
3343
static const struct pci_dev_dma_source {
3340
	u16 vendor;
3344
	u16 vendor;
3341
	u16 device;
3345
	u16 device;
Lines 3362-3368 static const struct pci_dev_dma_source { Link Here
3362
 * the device doing the DMA, but sometimes hardware is broken and will
3366
 * the device doing the DMA, but sometimes hardware is broken and will
3363
 * tag the DMA as being sourced from a different device.  This function
3367
 * tag the DMA as being sourced from a different device.  This function
3364
 * allows that translation.  Note that the reference count of the
3368
 * allows that translation.  Note that the reference count of the
3365
 * returned device is incremented on all paths.
3369
 * returned device is incremented on all paths. Translation is done when
3370
 * the device is added to an IOMMU group.
3366
 */
3371
 */
3367
struct pci_dev *pci_get_dma_source(struct pci_dev *dev)
3372
struct pci_dev *pci_get_dma_source(struct pci_dev *dev)
3368
{
3373
{
Lines 3423-3428 static int pci_quirk_amd_sb_acs(struct pci_dev *dev, u16 acs_flags) Link Here
3423
#endif
3428
#endif
3424
}
3429
}
3425
3430
3431
/* Table of multiple requester IDs, aka ghost DMA source functions.
3432
 * Devices that may need this quirk show the following behaviour:
3433
 * 1. the device may use multiple PCI requester IDs during operation,
3434
 *     (eg. one pci transaction uses xx:yy.0, the next uses xx:yy.1)
3435
 * 2. the requester ID may point to an absent/ghost device.
3436
 *     (eg. lspci does not show xx:yy.1 to be present)
3437
 *
3438
 * The bitmap contains ALL of the functions used as requester IDs by the
3439
 * device, including the one known to 'lspci'. If the func is known to 'lspci',
3440
 * but not used for DMA, don't include it.
3441
 * See  https://bugzilla.redhat.com/show_bug.cgi?id=757166,
3442
 * https://bugzilla.kernel.org/show_bug.cgi?id=42679
3443
 * https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1089768
3444
 */
3445
static const struct pci_dev_dma_multi_source_map {
3446
	u16 vendor;
3447
	u16 device;
3448
	u8 func_map;	/* bit map. lsb is fn 0. */
3449
} pci_dev_dma_multi_source_map[] = {
3450
	 /* Reported by Patrick Bregman
3451
	  * https://bugzilla.redhat.com/show_bug.cgi?id=863653 */
3452
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9120, (1<<0)|(1<<1)},
3453
3454
	/* Reported by  Paweł Żak, Korneliusz Jarzębski, Daniel Mayer
3455
	 * https://bugzilla.kernel.org/show_bug.cgi?id=42679 and by
3456
	 * Justin Piszcz  https://lkml.org/lkml/2012/11/24/94 */
3457
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9123, (1<<0)|(1<<1)},
3458
3459
	/* Used in a patch by Ying Chu
3460
	 * https://bugzilla.redhat.com/show_bug.cgi?id=757166 */
3461
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9125, (1<<0)|(1<<1)},
3462
3463
	/* Reported by Robert Cicconetti
3464
	 * https://bugzilla.kernel.org/show_bug.cgi?id=42679 and by
3465
	 * Fernando https://bugzilla.redhat.com/show_bug.cgi?id=757166 */
3466
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9128, (1<<0)|(1<<1)},
3467
3468
	/* Reported by Stijn Tintel
3469
	 * https://bugzilla.kernel.org/show_bug.cgi?id=42679 */
3470
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9130, (1<<0)|(1<<1)},
3471
3472
	/* Reported by Gaudenz Steinlin
3473
	 * https://lkml.org/lkml/2013/3/5/288 */
3474
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9143, (1<<0)|(1<<1)},
3475
3476
	/* Reported by Andrew Cooks
3477
	 * https://bugzilla.kernel.org/show_bug.cgi?id=42679 */
3478
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9172, (1<<0)|(1<<1)},
3479
3480
	/* Reported by Martin Öhrling
3481
	 * https://bugzilla.kernel.org/show_bug.cgi?id=42679#c28 */
3482
	{ PCI_VENDOR_ID_MARVELL_EXT, 0x9230, (1<<0)|(1<<1)},
3483
3484
	{ 0 }
3485
};
3486
3487
/*
3488
 * The mapping of quirky requester ids is used when the device driver sets up
3489
 * dma, if iommu is enabled.
3490
 */
3491
u8 pci_multi_requesters(struct pci_dev *dev)
3492
{
3493
	const struct pci_dev_dma_multi_source_map *i;
3494
3495
	for (i = pci_dev_dma_multi_source_map; i->func_map; i++) {
3496
		if ((i->vendor == dev->vendor ||
3497
		     i->vendor == (u16)PCI_ANY_ID) &&
3498
		    (i->device == dev->device ||
3499
		     i->device == (u16)PCI_ANY_ID)) {
3500
			return i->func_map;
3501
		}
3502
	}
3503
	return 0;
3504
}
3505
3506
/* These are one-to-one translations for devices that use a single incorrect
3507
 * requester ID. The requester id may not be the BDF of a real device.
3508
 */
3509
static const struct pci_dev_dma_source_map {
3510
	u16 vendor;
3511
	u16 device;
3512
	u8  devfn;
3513
	u8  dma_devfn;
3514
} pci_dev_dma_source_map[] = {
3515
	/* Ricoh IEEE 1394 Controller */
3516
	{
3517
		PCI_VENDOR_ID_RICOH,
3518
		0xe832,
3519
		PCI_DEVFN(0x00, 3),
3520
		PCI_DEVFN(0x00, 0)
3521
	},
3522
3523
	/* Nils Caspar - Adaptec 3405
3524
	 * http://www.mail-archive.com/centos@centos.org/msg90986.html
3525
	 * Jonathan McCune
3526
	 * http://old-list-archives.xen.org/archives/html/xen-users/2010-04/msg00535.html */
3527
	{
3528
		PCI_VENDOR_ID_ADAPTEC2,
3529
		0x028b,
3530
		PCI_DEVFN(0x0e, 0),
3531
		PCI_DEVFN(0x01, 0)
3532
	},
3533
3534
	/* Mateusz Murawski - LSI SAS based MegaRAID
3535
	 * https://lkml.org/lkml/2011/9/12/104
3536
	 * M. Nunberg - Dell PERC 5/i Integrated RAID Controller
3537
	 * http://lists.xen.org/archives/html/xen-devel/2010-05/msg01563.html */
3538
	{
3539
		PCI_VENDOR_ID_LSI_LOGIC,
3540
		0x0411,
3541
		PCI_DEVFN(0x0e, 0),
3542
		PCI_DEVFN(0x08, 0)
3543
	},
3544
3545
	/* Steven Dake, Markus Stockhausen - Mellanox 26428
3546
	 * https://bugzilla.redhat.com/show_bug.cgi?id=713774
3547
	 * Note: mellanox uses decimal product numbers, convert to hex for PCI
3548
	 * device ID. ie. 26428 == 0x673c */
3549
	{
3550
		PCI_VENDOR_ID_MELLANOX,
3551
		0x673c,
3552
		PCI_DEVFN(0x00, 0),
3553
		PCI_DEVFN(0x00, 6)
3554
	},
3555
3556
	{ 0 }
3557
};
3558
3559
u8 pci_requester(struct pci_dev *dev)
3560
{
3561
	const struct pci_dev_dma_source_map *i;
3562
3563
	for (i = pci_dev_dma_source_map; i->vendor; i++) {
3564
		if ((i->vendor == dev->vendor) &&
3565
		    (i->device == dev->device) &&
3566
		    (i->devfn == dev->devfn)) {
3567
			return i->dma_devfn;
3568
		}
3569
	}
3570
	return dev->devfn;
3571
}
3572
3426
static const struct pci_dev_acs_enabled {
3573
static const struct pci_dev_acs_enabled {
3427
	u16 vendor;
3574
	u16 vendor;
3428
	u16 device;
3575
	u16 device;
(-)a/include/linux/pci.h (+10 lines)
Lines 1509-1514 enum pci_fixup_pass { Link Here
1509
#ifdef CONFIG_PCI_QUIRKS
1509
#ifdef CONFIG_PCI_QUIRKS
1510
void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
1510
void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
1511
struct pci_dev *pci_get_dma_source(struct pci_dev *dev);
1511
struct pci_dev *pci_get_dma_source(struct pci_dev *dev);
1512
u8 pci_multi_requesters(struct pci_dev *dev);
1513
u8 pci_requester(struct pci_dev *dev);
1512
int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
1514
int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
1513
#else
1515
#else
1514
static inline void pci_fixup_device(enum pci_fixup_pass pass,
1516
static inline void pci_fixup_device(enum pci_fixup_pass pass,
Lines 1517-1522 static inline struct pci_dev *pci_get_dma_source(struct pci_dev *dev) Link Here
1517
{
1519
{
1518
	return pci_dev_get(dev);
1520
	return pci_dev_get(dev);
1519
}
1521
}
1522
u8 pci_multi_requesters(struct pci_dev *dev)
1523
{
1524
	return 0;
1525
}
1526
u8 pci_requester(struct pci_dev *dev)
1527
{
1528
	return dev->devfn;
1529
}
1520
static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
1530
static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
1521
					       u16 acs_flags)
1531
					       u16 acs_flags)
1522
{
1532
{

Return to bug 42679