PCI: Workaround hardware bugs in ACS functionality by implementing it as a quirk
PATCH 1/2 PCI: Workaround hardware bugs in ACS functionality by implementing it as a quirk
There are bugs in ACS implementations by certain switch vendors that cause ACS violations in perfectly normal accesses. This patch provides the framework for enabling and disabling the functionality at certain points during endpoint bringup in the form of a quirk.
--
-v2: move workaround to pci_bus_read_dev_vendor_id() from pci_bus_check_dev()
and move enable_acs_sv to drivers/pci/pci.c -- by Yinghai
-v3: add bus->self check for root bus and virtual bus for sriov vfs. -v4: only do workaround for IDT switches
-v5: tweak pci_std_enable_acs_sv to deal with unimplemented SV -v6: Added errata verbiage verbatim and resolved patch format issues -v7: changed int to bool for found and idt_workaround declarations. Also
added bugzilla https://bugzilla.kernel.org/show_bug.cgi?id=196979
-v8: Rewrote the patch by adding a new acs quirk to keep the workaround
out of the main code path
-v9: changed function name from pci_dev_specific_fixup_acs_quirk to
pci_bus_acs_quirk. Also, tested for FLR and hot reset scenarios
and did
not see issues where workaround was required. The issue seems to be related only to cold reset/power on situation.
-v10: Moved the contents of pci_bus_read_vendor_id into an internal function
__pci_bus_read_vendor_id
-v11: Split the patch into two patches. The first a general quirk framework.
---
drivers/pci/pci.h | 7 +++++++ drivers/pci/probe.c | 33 ++++++++++++++++++++++++++++----- drivers/pci/quirks.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-)
drivers/pci/pci.h +7 -0
@@ -387,11 +387,18 @@ struct pci_dev_reset_methods {#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_reset (struct pci_dev *dev,int probe); +int pci_bus_specific_acs_quirk (struct pci_bus *bus ,int devfn, +int enable,bool found);#else static inline int pci_dev_specific_reset (struct pci_dev *dev,int probe) {return -ENOTTY ; } +static inline int pci_bus_specific_acs_quirk (struct pc_bus *bus, +int devfn,int enable,bool found) +{ +return -ENOTTY ; +}#endif #if defined(CONFIG_PCI_QUIRKS ) && defined(CONFIG_ARM64 )
drivers/pci/probe.c +28 -5
@@ -2097,21 +2097,44 @@ static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l,return true; } -bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +static bool __pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l,int timeout) { + +int found = false; +if (pci_bus_read_config_dword (bus, devfn,PCI_VENDOR_ID , l)) -return false; + goto out;/* Some broken boards return 0 or ~0 if a slot is empty: */ if (*l ==0xffffffff || *l ==0x00000000 || *l ==0x0000ffff || *l ==0xffff0000 ) -return false; + goto out; + found = true;if (pci_bus_crs_vendor_id (*l)) -return pci_bus_wait_crs (bus, devfn, l, timeout); + found =pci_bus_wait_crs (bus, devfn, l, timeout); -return true; +out: +return found; + +} + + +bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +int timeout) +{ +bool ret; +int enable =-1 ; + + enable =pci_bus_specific_acs_quirk (bus, devfn, false, false); + + ret =__pci_bus_read_dev_vendor_id (bus, devfn, l, timeout); + +if (enable >0 ) +pci_bus_specific_acs_quirk (bus, devfn, enable, ret); + +return ret; }EXPORT_SYMBOL (pci_bus_read_dev_vendor_id);
drivers/pci/quirks.c +41 -0
44 lines not on this page · raw message
Quoted 4 lines · James Puthukattukaran
There are bugs in ACS implementations by certain switch vendors that cause ACS violations in perfectly normal accesses. This patch provides the framework for enabling and disabling the functionality at certain points during endpoint bringup in the form of a quirk.
Signed-off-by James Puthukattukaran <[email protected]>
Small nits below. Need to see what Bjorn and Alex to say about this.
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, · line 2102
Quoted 13 lines
#if
defined(CONFIG_PCI_QUIRKS)&&defined(CONFIG_ARM64)drivers/pci/probe.c +1
-1@@ -2097,21 +2097,44 @@ static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, return true; } -bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +static bool __pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, int timeout) {
There is no point in changing this function contents now. Just change the header in this code. Please revert your other changes in this function.
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, · line 2128
Quoted 7 lines
drivers/pci/probe.c +7
-0+ + +bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, + int timeout) +{ + bool ret; + int enable = -1;
no need for initialization.
Quoted 10 lines
drivers/pci/probe.c +9
-0+ + enable = pci_bus_specific_acs_quirk(bus, devfn, false, false); + + ret = __pci_bus_read_dev_vendor_id(bus, devfn, l, timeout); + + if (enable > 0) + pci_bus_specific_acs_quirk(bus, devfn, enable, ret); + + return ret; }
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 86 lines · On Wed, 11 Apr 2018 11:58:43 -0400 James Puthukattukaran…
There are bugs in ACS implementations by certain switch vendors that cause ACS violations in perfectly normal accesses. This patch provides the framework for enabling and disabling the functionality at certain points during endpoint bringup in the form of a quirk.
Signed-off-by James Puthukattukaran <[email protected]>--
-v2: move workaround to
pci_bus_read_dev_vendor_id()frompci_bus_check_dev()
and moveenable_acs_svtodrivers/pci/pci.c-- by Yinghai(quoted diff) +0
-7-v3: add bus->self check for root bus and virtual bus for sriov vfs. -v4: only do workaround for IDT switches -v5: tweak pci_std_enable_acs_sv to deal with unimplemented SV -v6: Added errata verbiage verbatim and resolved patch format issues -v7: changed int to bool for found and idt_workaround declarations. Also added bugzilla https://bugzilla.kernel.org/show_bug.cgi?id=196979 -v8: Rewrote the patch by adding a new acs quirk to keep the workaround out of the main code path -v9: changed function name from pci_dev_specific_fixup_acs_quirk to pci_bus_acs_quirk. Also, tested for FLR and hot reset scenariosand did
not see issues where workaround was required. The issue seems to be related only to cold reset/power on situation.(quoted diff) +0
-3-v10: Moved the contents of pci_bus_read_vendor_id into an internal function __pci_bus_read_vendor_id -v11: Split the patch into two patches. The first a general quirk framework. --- drivers/pci/pci.h | 7 +++++++ drivers/pci/probe.c | 33 ++++++++++++++++++++++++++++----- drivers/pci/quirks.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-)drivers/pci/pci.h +7
-0@@ -387,11 +387,18 @@ struct pci_dev_reset_methods {#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_reset (struct pci_dev *dev,int probe); +int pci_bus_specific_acs_quirk (struct pci_bus *bus ,int devfn, +int enable,bool found);#else static inline int pci_dev_specific_reset (struct pci_dev *dev,int probe) {return -ENOTTY ; } +static inline int pci_bus_specific_acs_quirk (struct pc_bus *bus, +int devfn,int enable,bool found) +{ +return -ENOTTY ; +}#endif #if defined(CONFIG_PCI_QUIRKS ) && defined(CONFIG_ARM64 )drivers/pci/probe.c +6
-3@@ -2097,21 +2097,44 @@ static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, return true; } -bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +static bool __pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l,int timeout) { + +int found = false; +if (pci_bus_read_config_dword (bus, devfn,PCI_VENDOR_ID , l)) -return false; + goto out;/* Some broken boards return 0 or ~0 if a slot is empty: */ if (*l ==0xffffffff || *l ==0x00000000 || *l ==0x0000ffff || *l ==0xffff0000 ) -return false; + goto out;
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus · line 2123
Quoted 10 lines
drivers/pci/probe.c +6
-2+ found = true;if (pci_bus_crs_vendor_id (*l)) -return pci_bus_wait_crs (bus, devfn, l, timeout); + found =pci_bus_wait_crs (bus, devfn, l, timeout); -return true; +out: +return found; + +}
The changes to the above function do not change the behavior and are not an improvement to the function, imo. There are no locks to be released, there's no resources to free, there's no reason to have a goto and common exit point.
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, · line 2128
Quoted 7 lines
drivers/pci/probe.c +7
-0+ + +bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +int timeout) +{ +bool ret; +int enable =-1 ;
Unnecessary initialization.
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus · line 2132
Quoted 2 lines
drivers/pci/probe.c +2
-0+ + enable =pci_bus_specific_acs_quirk (bus, devfn, false, false);
The prototype specifies the 3rd arg is an int, not bool. The args are pretty cryptic regardless though, can we rename or create wrappers to make their usage better? This looks like a test_and_clear sort of function and the below looks like a restore (if found?).
Quoted 49 lines
drivers/pci/probe.c +7
-0+ + ret =__pci_bus_read_dev_vendor_id (bus, devfn, l, timeout); + +if (enable >0 ) +pci_bus_specific_acs_quirk (bus, devfn, enable, ret); + +return ret; }EXPORT_SYMBOL(pci_bus_read_dev_vendor_id);drivers/pci/quirks.c +31
-0@@ -4737,3 +4737,44 @@ static void quirk_gpu_hda(struct pci_dev *hda) PCI_CLASS_MULTIMEDIA_HD_AUDIO, 8, quirk_gpu_hda);DECLARE_PCI_FIXUP_CLASS_FINAL (PCI_VENDOR_ID_NVIDIA ,PCI_ANY_ID ,PCI_CLASS_MULTIMEDIA_HD_AUDIO ,8 , quirk_gpu_hda); + + + +static const struct pci_dev_acs_quirk { +u16 vendor; +u16 device; +int (*acs_quirk)(struct pci_bus *bus,int devfn,int enable,bool found); +} pci_dev_acs_quirks[] = { + {0 } +}; + +int pci_bus_specific_acs_quirk (struct pci_bus *bus,int devfn,int enable, +bool found) +{ +const struct pci_dev_acs_quirk *i; +struct pci_dev *dev; +int ret; + +if (!bus || !bus->self) +return -ENOTTY ; + + dev = bus->self; + +/* +* Allow devices that have HW bugs in the ACS implementations to +* control enabling or disabling that ACS feature here. +*/ +for (i = pci_dev_acs_quirks; i->acs_quirk; i++) { + if ((i->vendor == dev->vendor || + i->vendor == (u16)PCI_ANY_ID) && + (i->device == dev->device ||
drivers/pci/quirks.c static void quirk_gpu_hda(struct pci_dev *hda) · line 4780
Quoted 10 lines
drivers/pci/quirks.c +10
-0+ i->device == (u16)PCI_ANY_ID)) { + ret = i->acs_quirk (bus, devfn, enable, found); +if (ret >=0 ) +return ret; + } + } + +return -ENOTTY ; +} +
What about a "pci_bus_specific_acs_quirk()" would make something think they need to call it in the presented use case above? The commit log really doesn't shed any light on why it's used here and not elsewhere or specifically what condition this is meant to trap. Should we instead be looking at a pci_bus_specific_read_dev_vendor_id() function? For example:
bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, int timeout)
{
int ret = pci_bus_specific_read_dev_vendor_id(...);
if (ret >= 0)
return ret > 0;
return pci_bus_generic_read_dev_vendor_id(...);
}That makes the purpose and call point of the quirk function very well defined and you can reuse the generic code within your quirk without creating obscure calling conventions.
Please also fix your sending of patch series, there should be a cover letter with patches referencing the message id for threading. Thanks,
Alex
Alex -
I have taken your suggestion at the end of to re-architect using a bus specific quirk and will be re-submitting the two patches with the rewrite. thanks
James
Quoted 209 lines · Alex Williamson
Quoted 86 lines · On Wed, 11 Apr 2018 11:58:43 -0400 James Puthukattukaran…
There are bugs in ACS implementations by certain switch vendors that cause ACS violations in perfectly normal accesses. This patch provides the framework for enabling and disabling the functionality at certain points during endpoint bringup in the form of a quirk.
Signed-off-by James Puthukattukaran <[email protected]>--
-v2: move workaround to
pci_bus_read_dev_vendor_id()frompci_bus_check_dev()
and moveenable_acs_svtodrivers/pci/pci.c-- by Yinghai(quoted diff) +0
-7-v3: add bus->self check for root bus and virtual bus for sriov vfs. -v4: only do workaround for IDT switches -v5: tweak pci_std_enable_acs_sv to deal with unimplemented SV -v6: Added errata verbiage verbatim and resolved patch format issues -v7: changed int to bool for found and idt_workaround declarations. Also added bugzilla https://bugzilla.kernel.org/show_bug.cgi?id=196979 -v8: Rewrote the patch by adding a new acs quirk to keep the workaround out of the main code path -v9: changed function name from pci_dev_specific_fixup_acs_quirk to pci_bus_acs_quirk. Also, tested for FLR and hot reset scenariosand did
not see issues where workaround was required. The issue seems to be related only to cold reset/power on situation.(quoted diff) +0
-3-v10: Moved the contents of pci_bus_read_vendor_id into an internal function __pci_bus_read_vendor_id -v11: Split the patch into two patches. The first a general quirk framework. --- drivers/pci/pci.h | 7 +++++++ drivers/pci/probe.c | 33 ++++++++++++++++++++++++++++----- drivers/pci/quirks.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-)drivers/pci/pci.h +7
-0@@ -387,11 +387,18 @@ struct pci_dev_reset_methods {#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_reset (struct pci_dev *dev,int probe); +int pci_bus_specific_acs_quirk (struct pci_bus *bus ,int devfn, +int enable,bool found);#else static inline int pci_dev_specific_reset (struct pci_dev *dev,int probe) {return -ENOTTY ; } +static inline int pci_bus_specific_acs_quirk (struct pc_bus *bus, +int devfn,int enable,bool found) +{ +return -ENOTTY ; +}#endif #if defined(CONFIG_PCI_QUIRKS ) && defined(CONFIG_ARM64 )drivers/pci/probe.c +6
-3@@ -2097,21 +2097,44 @@ static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, return true; } -bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +static bool __pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l,int timeout) { + +int found = false; +if (pci_bus_read_config_dword (bus, devfn,PCI_VENDOR_ID , l)) -return false; + goto out;/* Some broken boards return 0 or ~0 if a slot is empty: */ if (*l ==0xffffffff || *l ==0x00000000 || *l ==0x0000ffff || *l ==0xffff0000 ) -return false; + goto out;drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus · line 2123
Quoted 10 lines
drivers/pci/probe.c +6
-2+ found = true;if (pci_bus_crs_vendor_id (*l)) -return pci_bus_wait_crs (bus, devfn, l, timeout); + found =pci_bus_wait_crs (bus, devfn, l, timeout); -return true; +out: +return found; + +}The changes to the above function do not change the behavior and are not an improvement to the function, imo. There are no locks to be released, there's no resources to free, there's no reason to have a goto and common exit point.
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l, · line 2128
Quoted 7 lines
drivers/pci/probe.c +7
-0+ + +bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l, +int timeout) +{ +bool ret; +int enable =-1 ;Unnecessary initialization.
drivers/pci/probe.c static bool pci_bus_wait_crs(struct pci_bus · line 2132
Quoted 2 lines
drivers/pci/probe.c +2
-0+ + enable =pci_bus_specific_acs_quirk (bus, devfn, false, false);The prototype specifies the 3rd arg is an int, not bool. The args are pretty cryptic regardless though, can we rename or create wrappers to make their usage better? This looks like a
test_and_clearsort of function and the below looks like a restore (if found?).Quoted 49 lines
drivers/pci/probe.c +7
-0+ + ret =__pci_bus_read_dev_vendor_id (bus, devfn, l, timeout); + +if (enable >0 ) +pci_bus_specific_acs_quirk (bus, devfn, enable, ret); + +return ret; }EXPORT_SYMBOL(pci_bus_read_dev_vendor_id);drivers/pci/quirks.c +31
-0@@ -4737,3 +4737,44 @@ static void quirk_gpu_hda(struct pci_dev *hda) PCI_CLASS_MULTIMEDIA_HD_AUDIO, 8, quirk_gpu_hda);DECLARE_PCI_FIXUP_CLASS_FINAL (PCI_VENDOR_ID_NVIDIA ,PCI_ANY_ID ,PCI_CLASS_MULTIMEDIA_HD_AUDIO ,8 , quirk_gpu_hda); + + + +static const struct pci_dev_acs_quirk { +u16 vendor; +u16 device; +int (*acs_quirk)(struct pci_bus *bus,int devfn,int enable,bool found); +} pci_dev_acs_quirks[] = { + {0 } +}; + +int pci_bus_specific_acs_quirk (struct pci_bus *bus,int devfn,int enable, +bool found) +{ +const struct pci_dev_acs_quirk *i; +struct pci_dev *dev; +int ret; + +if (!bus || !bus->self) +return -ENOTTY ; + + dev = bus->self; + +/* +* Allow devices that have HW bugs in the ACS implementations to +* control enabling or disabling that ACS feature here. +*/ +for (i = pci_dev_acs_quirks; i->acs_quirk; i++) { + if ((i->vendor == dev->vendor || + i->vendor == (u16)PCI_ANY_ID) && + (i->device == dev->device ||drivers/pci/quirks.c static void quirk_gpu_hda(struct pci_dev *hda) · line 4780
Quoted 10 lines
drivers/pci/quirks.c +10
-0+ i->device == (u16)PCI_ANY_ID)) { + ret = i->acs_quirk (bus, devfn, enable, found); +if (ret >=0 ) +return ret; + } + } + +return -ENOTTY ; +} +What about a "
pci_bus_specific_acs_quirk()" would make something think they need to call it in the presented use case above? The commit log really doesn't shed any light on why it's used here and not elsewhere or specifically what condition this is meant to trap. Should we instead be looking at apci_bus_specific_read_dev_vendor_id()function? For example:bool
pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, int timeout){ int ret = pci_bus_specific_read_dev_vendor_id(...); if (ret >= 0) return ret > 0; return pci_bus_generic_read_dev_vendor_id(...); }That makes the purpose and call point of the quirk function very well defined and you can reuse the generic code within your quirk without creating obscure calling conventions.
Please also fix your sending of patch series, there should be a cover letter with patches referencing the message id for threading. Thanks,
Alex