Skip to content

Commit 2095b9d

Browse files
committed
Merge branch 'pci/virtualization'
- Mark ASM1164 SATA controller to avoid bus reset since it fails to train the Link after reset (Alex Williamson) - Mark Nvidia GB10 Root Ports to avoid bus reset since they may fail to retrain the link after reset (Johnny-CC Chang) - Add lockdep and other lock assertions (Ilpo Järvinen) - Add ACS quirk for Qualcomm Hamoa & Glymur, which provides ACS-like features but doesn't advertise an ACS Capability (Krishna Chaitanya Chundru) - Add ACS quirk for Pericom PI7C9X2G404 switches, which fail under load when P2P Redirect Request is enabled (Nicolas Cavallari) - Remove an incorrect unlock in pci_slot_trylock() error handling (Jinhui Guo) - Lock the bridge device for slot reset (Keith Busch) - Enable ACS after IOMMU configuration on OF platforms so ACS is enabled an all devices; previously the first device enumeration (typically a Root Port) was omitted (Manivannan Sadhasivam) - Disable ACS Source Validation for IDT 0x80b5 and 0x8090 switches to work around hardware erratum; previously ACS SV was temporarily disabled, which worked for enumeration but not after reset (Manivannan Sadhasivam) * pci/virtualization: PCI: Disable ACS SV for IDT 0x8090 switch PCI: Disable ACS SV for IDT 0x80b5 switch PCI: Cache ACS Capabilities register PCI: Enable ACS after configuring IOMMU for OF platforms PCI: Add ACS quirk for Pericom PI7C9X2G404 switches [12d8:b404] PCI: Add ACS quirk for Qualcomm Hamoa & Glymur PCI: Use device_lock_assert() to verify device lock is held PCI: Use lockdep_assert_held(pci_bus_sem) to verify lock is held PCI: Fix pci_slot_lock () device locking PCI: Fix pci_slot_trylock() error handling PCI: Mark Nvidia GB10 to avoid bus reset PCI: Mark ASM1164 SATA controller to avoid bus reset
2 parents 401b356 + b5f88a3 commit 2095b9d

6 files changed

Lines changed: 95 additions & 77 deletions

File tree

drivers/pci/pci-driver.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,14 @@ static int pci_dma_configure(struct device *dev)
16501650
ret = acpi_dma_configure(dev, acpi_get_dma_attr(adev));
16511651
}
16521652

1653+
/*
1654+
* Attempt to enable ACS regardless of capability because some Root
1655+
* Ports (e.g. those quirked with *_intel_pch_acs_*) do not have
1656+
* the standard ACS capability but still support ACS via those
1657+
* quirks.
1658+
*/
1659+
pci_enable_acs(to_pci_dev(dev));
1660+
16531661
pci_put_host_bridge_device(bridge);
16541662

16551663
/* @drv may not be valid when we're called from the IOMMU layer */

drivers/pci/pci.c

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/delay.h>
1414
#include <linux/dmi.h>
1515
#include <linux/init.h>
16+
#include <linux/lockdep.h>
1617
#include <linux/msi.h>
1718
#include <linux/of.h>
1819
#include <linux/pci.h>
@@ -886,7 +887,6 @@ static const char *disable_acs_redir_param;
886887
static const char *config_acs_param;
887888

888889
struct pci_acs {
889-
u16 cap;
890890
u16 ctrl;
891891
u16 fw_ctrl;
892892
};
@@ -989,27 +989,27 @@ static void __pci_config_acs(struct pci_dev *dev, struct pci_acs *caps,
989989
static void pci_std_enable_acs(struct pci_dev *dev, struct pci_acs *caps)
990990
{
991991
/* Source Validation */
992-
caps->ctrl |= (caps->cap & PCI_ACS_SV);
992+
caps->ctrl |= (dev->acs_capabilities & PCI_ACS_SV);
993993

994994
/* P2P Request Redirect */
995-
caps->ctrl |= (caps->cap & PCI_ACS_RR);
995+
caps->ctrl |= (dev->acs_capabilities & PCI_ACS_RR);
996996

997997
/* P2P Completion Redirect */
998-
caps->ctrl |= (caps->cap & PCI_ACS_CR);
998+
caps->ctrl |= (dev->acs_capabilities & PCI_ACS_CR);
999999

10001000
/* Upstream Forwarding */
1001-
caps->ctrl |= (caps->cap & PCI_ACS_UF);
1001+
caps->ctrl |= (dev->acs_capabilities & PCI_ACS_UF);
10021002

10031003
/* Enable Translation Blocking for external devices and noats */
10041004
if (pci_ats_disabled() || dev->external_facing || dev->untrusted)
1005-
caps->ctrl |= (caps->cap & PCI_ACS_TB);
1005+
caps->ctrl |= (dev->acs_capabilities & PCI_ACS_TB);
10061006
}
10071007

10081008
/**
10091009
* pci_enable_acs - enable ACS if hardware support it
10101010
* @dev: the PCI device
10111011
*/
1012-
static void pci_enable_acs(struct pci_dev *dev)
1012+
void pci_enable_acs(struct pci_dev *dev)
10131013
{
10141014
struct pci_acs caps;
10151015
bool enable_acs = false;
@@ -1025,7 +1025,6 @@ static void pci_enable_acs(struct pci_dev *dev)
10251025
if (!pos)
10261026
return;
10271027

1028-
pci_read_config_word(dev, pos + PCI_ACS_CAP, &caps.cap);
10291028
pci_read_config_word(dev, pos + PCI_ACS_CTRL, &caps.ctrl);
10301029
caps.fw_ctrl = caps.ctrl;
10311030

@@ -3517,7 +3516,7 @@ void pci_configure_ari(struct pci_dev *dev)
35173516
static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
35183517
{
35193518
int pos;
3520-
u16 cap, ctrl;
3519+
u16 ctrl;
35213520

35223521
pos = pdev->acs_cap;
35233522
if (!pos)
@@ -3528,8 +3527,7 @@ static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
35283527
* or only required if controllable. Features missing from the
35293528
* capability field can therefore be assumed as hard-wired enabled.
35303529
*/
3531-
pci_read_config_word(pdev, pos + PCI_ACS_CAP, &cap);
3532-
acs_flags &= (cap | PCI_ACS_EC);
3530+
acs_flags &= (pdev->acs_capabilities | PCI_ACS_EC);
35333531

35343532
pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
35353533
return (ctrl & acs_flags) == acs_flags;
@@ -3650,15 +3648,15 @@ bool pci_acs_path_enabled(struct pci_dev *start,
36503648
*/
36513649
void pci_acs_init(struct pci_dev *dev)
36523650
{
3651+
int pos;
3652+
36533653
dev->acs_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
3654+
pos = dev->acs_cap;
3655+
if (!pos)
3656+
return;
36543657

3655-
/*
3656-
* Attempt to enable ACS regardless of capability because some Root
3657-
* Ports (e.g. those quirked with *_intel_pch_acs_*) do not have
3658-
* the standard ACS capability but still support ACS via those
3659-
* quirks.
3660-
*/
3661-
pci_enable_acs(dev);
3658+
pci_read_config_word(dev, pos + PCI_ACS_CAP, &dev->acs_capabilities);
3659+
pci_disable_broken_acs_cap(dev);
36623660
}
36633661

36643662
/**
@@ -4625,14 +4623,16 @@ bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
46254623
* spec says 100 ms, but firmware can lower it and we allow drivers to
46264624
* increase it as well.
46274625
*
4628-
* Called with @pci_bus_sem locked for reading.
4626+
* Context: Called with @pci_bus_sem locked for reading.
46294627
*/
46304628
static int pci_bus_max_d3cold_delay(const struct pci_bus *bus)
46314629
{
46324630
const struct pci_dev *pdev;
46334631
int min_delay = 100;
46344632
int max_delay = 0;
46354633

4634+
lockdep_assert_held(&pci_bus_sem);
4635+
46364636
list_for_each_entry(pdev, &bus->devices, bus_list) {
46374637
if (pdev->d3cold_delay < min_delay)
46384638
min_delay = pdev->d3cold_delay;
@@ -4970,6 +4970,7 @@ static void pci_dev_save_and_disable(struct pci_dev *dev)
49704970
* races with ->remove() by the device lock, which must be held by
49714971
* the caller.
49724972
*/
4973+
device_lock_assert(&dev->dev);
49734974
if (err_handler && err_handler->reset_prepare)
49744975
err_handler->reset_prepare(dev);
49754976
else if (dev->driver)
@@ -5040,7 +5041,9 @@ const struct pci_reset_fn_method pci_reset_fn_methods[] = {
50405041
* device including MSI, bus mastering, BARs, decoding IO and memory spaces,
50415042
* etc.
50425043
*
5043-
* Returns 0 if the device function was successfully reset or negative if the
5044+
* Context: The caller must hold the device lock.
5045+
*
5046+
* Return: 0 if the device function was successfully reset or negative if the
50445047
* device doesn't support resetting a single function.
50455048
*/
50465049
int __pci_reset_function_locked(struct pci_dev *dev)
@@ -5049,6 +5052,7 @@ int __pci_reset_function_locked(struct pci_dev *dev)
50495052
const struct pci_reset_fn_method *method;
50505053

50515054
might_sleep();
5055+
device_lock_assert(&dev->dev);
50525056

50535057
/*
50545058
* A reset method returns -ENOTTY if it doesn't support this device and
@@ -5171,13 +5175,17 @@ EXPORT_SYMBOL_GPL(pci_reset_function);
51715175
* over the reset. It also differs from pci_reset_function() in that it
51725176
* requires the PCI device lock to be held.
51735177
*
5174-
* Returns 0 if the device function was successfully reset or negative if the
5178+
* Context: The caller must hold the device lock.
5179+
*
5180+
* Return: 0 if the device function was successfully reset or negative if the
51755181
* device doesn't support resetting a single function.
51765182
*/
51775183
int pci_reset_function_locked(struct pci_dev *dev)
51785184
{
51795185
int rc;
51805186

5187+
device_lock_assert(&dev->dev);
5188+
51815189
if (!pci_reset_supported(dev))
51825190
return -ENOTTY;
51835191

@@ -5293,10 +5301,9 @@ static int pci_bus_trylock(struct pci_bus *bus)
52935301
/* Do any devices on or below this slot prevent a bus reset? */
52945302
static bool pci_slot_resettable(struct pci_slot *slot)
52955303
{
5296-
struct pci_dev *dev;
5304+
struct pci_dev *dev, *bridge = slot->bus->self;
52975305

5298-
if (slot->bus->self &&
5299-
(slot->bus->self->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET))
5306+
if (bridge && (bridge->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET))
53005307
return false;
53015308

53025309
list_for_each_entry(dev, &slot->bus->devices, bus_list) {
@@ -5313,7 +5320,10 @@ static bool pci_slot_resettable(struct pci_slot *slot)
53135320
/* Lock devices from the top of the tree down */
53145321
static void pci_slot_lock(struct pci_slot *slot)
53155322
{
5316-
struct pci_dev *dev;
5323+
struct pci_dev *dev, *bridge = slot->bus->self;
5324+
5325+
if (bridge)
5326+
pci_dev_lock(bridge);
53175327

53185328
list_for_each_entry(dev, &slot->bus->devices, bus_list) {
53195329
if (!dev->slot || dev->slot != slot)
@@ -5328,7 +5338,7 @@ static void pci_slot_lock(struct pci_slot *slot)
53285338
/* Unlock devices from the bottom of the tree up */
53295339
static void pci_slot_unlock(struct pci_slot *slot)
53305340
{
5331-
struct pci_dev *dev;
5341+
struct pci_dev *dev, *bridge = slot->bus->self;
53325342

53335343
list_for_each_entry(dev, &slot->bus->devices, bus_list) {
53345344
if (!dev->slot || dev->slot != slot)
@@ -5338,21 +5348,25 @@ static void pci_slot_unlock(struct pci_slot *slot)
53385348
else
53395349
pci_dev_unlock(dev);
53405350
}
5351+
5352+
if (bridge)
5353+
pci_dev_unlock(bridge);
53415354
}
53425355

53435356
/* Return 1 on successful lock, 0 on contention */
53445357
static int pci_slot_trylock(struct pci_slot *slot)
53455358
{
5346-
struct pci_dev *dev;
5359+
struct pci_dev *dev, *bridge = slot->bus->self;
5360+
5361+
if (bridge && !pci_dev_trylock(bridge))
5362+
return 0;
53475363

53485364
list_for_each_entry(dev, &slot->bus->devices, bus_list) {
53495365
if (!dev->slot || dev->slot != slot)
53505366
continue;
53515367
if (dev->subordinate) {
5352-
if (!pci_bus_trylock(dev->subordinate)) {
5353-
pci_dev_unlock(dev);
5368+
if (!pci_bus_trylock(dev->subordinate))
53545369
goto unlock;
5355-
}
53565370
} else if (!pci_dev_trylock(dev))
53575371
goto unlock;
53585372
}
@@ -5368,6 +5382,9 @@ static int pci_slot_trylock(struct pci_slot *slot)
53685382
else
53695383
pci_dev_unlock(dev);
53705384
}
5385+
5386+
if (bridge)
5387+
pci_dev_unlock(bridge);
53715388
return 0;
53725389
}
53735390

drivers/pci/pci.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
469469
int rrs_timeout);
470470
bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
471471
int rrs_timeout);
472-
int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int rrs_timeout);
473472

474473
int pci_setup_device(struct pci_dev *dev);
475474
void __pci_size_stdbars(struct pci_dev *dev, int count,
@@ -1000,10 +999,12 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
1000999
}
10011000

10021001
void pci_acs_init(struct pci_dev *dev);
1002+
void pci_enable_acs(struct pci_dev *dev);
10031003
#ifdef CONFIG_PCI_QUIRKS
10041004
int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
10051005
int pci_dev_specific_enable_acs(struct pci_dev *dev);
10061006
int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
1007+
void pci_disable_broken_acs_cap(struct pci_dev *pdev);
10071008
int pcie_failed_link_retrain(struct pci_dev *dev);
10081009
#else
10091010
static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
@@ -1019,6 +1020,7 @@ static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
10191020
{
10201021
return -ENOTTY;
10211022
}
1023+
static inline void pci_disable_broken_acs_cap(struct pci_dev *dev) { }
10221024
static inline int pcie_failed_link_retrain(struct pci_dev *dev)
10231025
{
10241026
return -ENOTTY;

drivers/pci/probe.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,18 +2549,6 @@ bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
25492549
bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
25502550
int timeout)
25512551
{
2552-
#ifdef CONFIG_PCI_QUIRKS
2553-
struct pci_dev *bridge = bus->self;
2554-
2555-
/*
2556-
* Certain IDT switches have an issue where they improperly trigger
2557-
* ACS Source Validation errors on completions for config reads.
2558-
*/
2559-
if (bridge && bridge->vendor == PCI_VENDOR_ID_IDT &&
2560-
bridge->device == 0x80b5)
2561-
return pci_idt_bus_quirk(bus, devfn, l, timeout);
2562-
#endif
2563-
25642552
return pci_bus_generic_read_dev_vendor_id(bus, devfn, l, timeout);
25652553
}
25662554
EXPORT_SYMBOL(pci_bus_read_dev_vendor_id);

0 commit comments

Comments
 (0)