PCI/ASPM: Allow ASPM enablement for devices behind Intel VMD
Subsystems (3)
PATCH 1/1 PCI/ASPM: Allow ASPM enablement for devices behind Intel VMD
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the ACPI_FADT_NO_ASPM flag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.
Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global ACPI_FADT_NO_ASPM restriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.
--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)
drivers/pci/controller/vmd.c +26 -2
@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4
@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {
@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus; + +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + } + +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;
@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/*
@@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));
drivers/pci/pci.h +8 -0
@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);
@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }
@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC
drivers/pci/pcie/aspm.c +35 -1
@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;
@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */
@@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM +* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;
base-commit: d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af
Signature · 1 line
2.43.0
(Resending; for some reason VGER thinks the Thunderbird MUA is "Spammy", but doesn't think as badly of "Alpine")
Testing now; so far, results look quite promising!
-K
Quoted 192 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.Signed-off-by David E. Box <[email protected]>--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +26
-2@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus; + +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + } + +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/* @@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));drivers/pci/pci.h +8
-0@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC drivers/pci/pcie/aspm.c +35
-1@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */ @@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM +* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af
Signature · 1 line
Kenneth R. Crudup / Sr. SW Engineer, Scott County Consulting, Orange County CA
Quoted 12 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.
Quoted 7 lines
Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.
First of all, thanks for doing this work, much appreciated!
Quoted 29 lines
--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +3
-1@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {
drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 773
Quoted 4 lines
drivers/pci/controller/vmd.c +0
-1@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );
Do I think correctly that this doesn't work because of the aspm_disabled check in __pci_enable_link_state()?
Quoted 7 lines
drivers/pci/controller/vmd.c +4
-0return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus;
drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 791
Quoted 10 lines
drivers/pci/controller/vmd.c +10
-0+ +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + }
If I'm not mistaken, it would be sufficient to do a check like
if (pci_dev->bus->ops == &vmd_ops)
return PCIE_LINK_STATE_ALL;instead of the above, or if not then why not?
Quoted 108 lines
drivers/pci/controller/vmd.c +9
-0+ +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/* @@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));drivers/pci/pci.h +8
-0@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC drivers/pci/pcie/aspm.c +27
-0@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */ @@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM
drivers/pci/pcie/aspm.c static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) · line 903
Quoted 10 lines
drivers/pci/pcie/aspm.c +8
-1+* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;
Well, this is not nice.
First off, it adds VMD-specific stuff to otherwise generic ASPM code. Second, it doesn't actually do anything about the aspm_disabled checks all over the place, so they will still trigger even though ASPM will be effectively enabled for devices on the VMD bus.
Quoted 6 lines
drivers/pci/pcie/aspm.c +0
-0/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af--
It appears to me that the underlying problem is that aspm_disabled is global and it is set during PCI root bus creation in acpi_pci_root_add(). Thus it affects all of the PCI buses even though the BIOS says that it wants to control ASPM for this particular PCIe hierarchy. If there were another PCI root enumerated by ACPI where the OS would be allowed to control ASPM, it would not work just like the VMD case.
To me, this suggests an approach based on moving the "ASPM disabled because the BIOS wants to control it" setting to pci_bus_flags_t and setting it on a per-hierarchy basis. Since the VMD bus is a separate PCIe hierarchy from the kernel perspective, it will not have this flag set and the OS should be able to configure ASPM for devices on that bus.
Do I think correctly or am I overlooking something here?
Hey Rafael,
Quoted 46 lines · Rafael J. Wysocki
Quoted 12 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.Quoted 7 lines
Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.First of all, thanks for doing this work, much appreciated!
Quoted 22 lines
--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +2
-0@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }
Quoted 14 lines
drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 773
Quoted 11 lines
drivers/pci/controller/vmd.c +1
-2/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );Do I think correctly that this doesn't work because of the
aspm_disabledcheck in__pci_enable_link_state()?
Yes.
Quoted 21 lines
Quoted 8 lines
drivers/pci/controller/vmd.c +4
-0return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus;drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 791
Quoted 10 lines
drivers/pci/controller/vmd.c +10
-0+ +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + }If I'm not mistaken, it would be sufficient to do a check like
Quoted 4 lines
if (pci_dev->bus->ops == &vmd_ops) return PCIE_LINK_STATE_ALL;instead of the above, or if not then why not?
As a replacement in the loop, that does look sufficient. I'm not sure if you're also suggesting replacing the loop itself.
Quoted 122 lines
Quoted 109 lines
drivers/pci/controller/vmd.c +9
-0+ +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/* @@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));drivers/pci/pci.h +8
-0@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC drivers/pci/pcie/aspm.c +27
-0@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */ @@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM drivers/pci/pcie/aspm.c static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) · line 903
Quoted 10 lines
drivers/pci/pcie/aspm.c +8
-1+* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;Well, this is not nice.
Quoted 4 lines
First off, it adds VMD-specific stuff to otherwise generic ASPM code. Second, it doesn't actually do anything about the
aspm_disabledchecks all over the place, so they will still trigger even though ASPM will be effectively enabled for devices on the VMD bus.
I agree that it's not nice to be mixing VMD specific code here. It's a working bad solution to come up with a working good solution :)
The reason this patch works is that the aspm_disabled checks only gate OS-controlled ASPM configuration. They don't affect the BIOS default values, which are what we're setting in link->aspm_default. The ASPM code uses link->aspm_default as the fallback when ASPM is globally disabled, which is exactly what we want for devices behind VMD where the driver, not BIOS, effectively is the platform provider of the defaults.
I put it here using a callback value because this where the BIOS defaults are saved for each device.
Quoted 8 lines
Quoted 7 lines
drivers/pci/pcie/aspm.c +0
-0/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af--
Quoted 7 lines
It appears to me that the underlying problem is that
aspm_disabledis global and it is set during PCI root bus creation inacpi_pci_root_add(). Thus it affects all of the PCI buses even though the BIOS says that it wants to control ASPM for this particular PCIe hierarchy. If there were another PCI root enumerated by ACPI where the OS would be allowed to control ASPM, it would not work just like the VMD case.
It would work in the non-VMD case because it has the BIOS default to use. VMD does not.
Quoted 9 lines
To me, this suggests an approach based on moving the "ASPM disabled because the BIOS wants to control it" setting to
pci_bus_flags_tand setting it on a per-hierarchy basis. Since the VMD bus is a separate PCIe hierarchy from the kernel perspective, it will not have this flag set and the OS should be able to configure ASPM for devices on that bus.Do I think correctly or am I overlooking something here?
It’s definitely along those lines. The issue is really caused by two things:
1. aspm_disabled global prevents OS control of ASPM
2. For VMD, there’s no BIOS provided link->aspm_default
The solution I proposed addresses the problem by having a mechanism for the VMD driver to supply its own defaults in place of the missing BIOS configuration.
Using pci_bus_flags_t could work as well, but would rather just say that aspm_disabled doesn't apply to the bus hierarchy, allowing the current pci_enable_link_state_locked() solution to work all the time. Either way, I'm definitely looking for a cleaner solution. The above hopefully clarifies the situation.
David
Quoted 225 lines · David Box
Hey Rafael,
Quoted 46 lines · Rafael J. Wysocki
Quoted 12 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.Quoted 7 lines
Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.First of all, thanks for doing this work, much appreciated!
Quoted 22 lines
--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +2
-0@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }Quoted 14 lines
drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 773
Quoted 11 lines
drivers/pci/controller/vmd.c +1
-2/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );Do I think correctly that this doesn't work because of the
aspm_disabledcheck in__pci_enable_link_state()?Yes.
Quoted 21 lines
Quoted 8 lines
drivers/pci/controller/vmd.c +4
-0return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus;drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 791
Quoted 10 lines
drivers/pci/controller/vmd.c +10
-0+ +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + }If I'm not mistaken, it would be sufficient to do a check like
Quoted 4 lines
if (pci_dev->bus->ops == &vmd_ops) return PCIE_LINK_STATE_ALL;instead of the above, or if not then why not?
As a replacement in the loop, that does look sufficient. I'm not sure if you're also suggesting replacing the loop itself.
Quoted 122 lines
Quoted 109 lines
drivers/pci/controller/vmd.c +9
-0+ +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/* @@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));drivers/pci/pci.h +8
-0@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC drivers/pci/pcie/aspm.c +27
-0@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */ @@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM drivers/pci/pcie/aspm.c static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) · line 903
Quoted 10 lines
drivers/pci/pcie/aspm.c +8
-1+* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;Well, this is not nice.
Quoted 4 lines
First off, it adds VMD-specific stuff to otherwise generic ASPM code. Second, it doesn't actually do anything about the
aspm_disabledchecks all over the place, so they will still trigger even though ASPM will be effectively enabled for devices on the VMD bus.I agree that it's not nice to be mixing VMD specific code here. It's a working bad solution to come up with a working good solution :)
Quoted 6 lines
The reason this patch works is that the
aspm_disabledchecks only gate OS-controlled ASPM configuration. They don't affect the BIOS default values, which are what we're setting inlink->aspm_default. The ASPM code useslink->aspm_defaultas the fallback when ASPM is globally disabled, which is exactly what we want for devices behind VMD where the driver, not BIOS, effectively is the platform provider of the defaults.
Oh, this was a big news to me.
So what you're saying is that if aspm_disabled is set, ->aspm_disable cannot be set and thus pcie_config_aspm_link() that is not gated by aspm_disabled can alter ASPM state despite OS not having ASPM control???
...That's really odd logic which the ASPM driver seems to be full of.
Signature · 1 line
i.
Quoted 50 lines
I put it here using a callback value because this where the BIOS defaults are saved for each device.
Quoted 8 lines
Quoted 7 lines
drivers/pci/pcie/aspm.c +0
-0/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af--Quoted 7 lines
It appears to me that the underlying problem is that
aspm_disabledis global and it is set during PCI root bus creation inacpi_pci_root_add(). Thus it affects all of the PCI buses even though the BIOS says that it wants to control ASPM for this particular PCIe hierarchy. If there were another PCI root enumerated by ACPI where the OS would be allowed to control ASPM, it would not work just like the VMD case.It would work in the non-VMD case because it has the BIOS default to use. VMD does not.
Quoted 9 lines
To me, this suggests an approach based on moving the "ASPM disabled because the BIOS wants to control it" setting to
pci_bus_flags_tand setting it on a per-hierarchy basis. Since the VMD bus is a separate PCIe hierarchy from the kernel perspective, it will not have this flag set and the OS should be able to configure ASPM for devices on that bus.Do I think correctly or am I overlooking something here?
It’s definitely along those lines. The issue is really caused by two things:
1.
aspm_disabledglobal prevents OS control of ASPM
2. For VMD, there’s no BIOS providedlink->aspm_defaultThe solution I proposed addresses the problem by having a mechanism for the VMD driver to supply its own defaults in place of the missing BIOS configuration.
Using
pci_bus_flags_tcould work as well, but would rather just say thataspm_disableddoesn't apply to the bus hierarchy, allowing the currentpci_enable_link_state_locked()solution to work all the time. Either way, I'm definitely looking for a cleaner solution. The above hopefully clarifies the situation.David
Quoted 234 lines · Ilpo Järvinen
Quoted 225 lines · David Box
Hey Rafael,
Quoted 46 lines · Rafael J. Wysocki
Quoted 12 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.Quoted 7 lines
Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.First of all, thanks for doing this work, much appreciated!
Quoted 22 lines
--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +2
-0@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }Quoted 14 lines
drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 773
Quoted 11 lines
drivers/pci/controller/vmd.c +1
-2/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );Do I think correctly that this doesn't work because of the
aspm_disabledcheck in__pci_enable_link_state()?Yes.
Quoted 21 lines
Quoted 8 lines
drivers/pci/controller/vmd.c +4
-0return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus;drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 791
Quoted 10 lines
drivers/pci/controller/vmd.c +10
-0+ +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + }If I'm not mistaken, it would be sufficient to do a check like
Quoted 4 lines
if (pci_dev->bus->ops == &vmd_ops) return PCIE_LINK_STATE_ALL;instead of the above, or if not then why not?
As a replacement in the loop, that does look sufficient. I'm not sure if you're also suggesting replacing the loop itself.
Quoted 122 lines
Quoted 109 lines
drivers/pci/controller/vmd.c +9
-0+ +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/* @@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));drivers/pci/pci.h +8
-0@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC drivers/pci/pcie/aspm.c +27
-0@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */ @@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM drivers/pci/pcie/aspm.c static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) · line 903
Quoted 10 lines
drivers/pci/pcie/aspm.c +8
-1+* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;Well, this is not nice.
Quoted 4 lines
First off, it adds VMD-specific stuff to otherwise generic ASPM code. Second, it doesn't actually do anything about the
aspm_disabledchecks all over the place, so they will still trigger even though ASPM will be effectively enabled for devices on the VMD bus.I agree that it's not nice to be mixing VMD specific code here. It's a working bad solution to come up with a working good solution :)
Quoted 6 lines
The reason this patch works is that the
aspm_disabledchecks only gate OS-controlled ASPM configuration. They don't affect the BIOS default values, which are what we're setting inlink->aspm_default. The ASPM code useslink->aspm_defaultas the fallback when ASPM is globally disabled, which is exactly what we want for devices behind VMD where the driver, not BIOS, effectively is the platform provider of the defaults.
Quoted 5 lines
Oh, this was a big news to me.
So what you're saying is that if
aspm_disabledis set, ->aspm_disable cannot be set and thuspcie_config_aspm_link()that is not gated byaspm_disabledcan alter ASPM state despite OS not having ASPM control???
Yes, that’s correct. Bjorn can confirm, but I believe this is by design. The aspm_disabled flag is really a bit of a misnomer. It probably should have been called something like os_aspm_disabled. The intent as I understand it is that, when disallowed, the OS cannot select or manage the active ASPM policy, but it can still configure the link to match the BIOS provided policy.
In other words, ASPM isn’t fully disabled. It’s just not under OS control. The BIOS values, reflected in link->aspm_default, remain valid and pcie_config_aspm_link() can apply them regardless of the aspm_disabled setting.
David
Quoted 56 lines
...That's really odd logic which the ASPM driver seems to be full of.
Signature · 1 line
i.Quoted 50 lines
I put it here using a callback value because this where the BIOS defaults are saved for each device.
Quoted 8 lines
Quoted 7 lines
drivers/pci/pcie/aspm.c +0
-0/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af--Quoted 7 lines
It appears to me that the underlying problem is that
aspm_disabledis global and it is set during PCI root bus creation inacpi_pci_root_add(). Thus it affects all of the PCI buses even though the BIOS says that it wants to control ASPM for this particular PCIe hierarchy. If there were another PCI root enumerated by ACPI where the OS would be allowed to control ASPM, it would not work just like the VMD case.It would work in the non-VMD case because it has the BIOS default to use. VMD does not.
Quoted 9 lines
To me, this suggests an approach based on moving the "ASPM disabled because the BIOS wants to control it" setting to
pci_bus_flags_tand setting it on a per-hierarchy basis. Since the VMD bus is a separate PCIe hierarchy from the kernel perspective, it will not have this flag set and the OS should be able to configure ASPM for devices on that bus.Do I think correctly or am I overlooking something here?
It’s definitely along those lines. The issue is really caused by two things:
1.
aspm_disabledglobal prevents OS control of ASPM
2. For VMD, there’s no BIOS providedlink->aspm_defaultThe solution I proposed addresses the problem by having a mechanism for the VMD driver to supply its own defaults in place of the missing BIOS configuration.
Using
pci_bus_flags_tcould work as well, but would rather just say thataspm_disableddoesn't apply to the bus hierarchy, allowing the currentpci_enable_link_state_locked()solution to work all the time. Either way, I'm definitely looking for a cleaner solution. The above hopefully clarifies the situation.David
Quoted 66 lines · David Box
Quoted 20 lines · Ilpo Järvinen
Quoted 19 lines · David Box
Quoted 18 lines · Rafael J. Wysocki
Quoted 16 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended....
Quoted 36 lines
Quoted 28 lines
Quoted 16 lines
Quoted 5 lines
drivers/pci/pcie/aspm.c +5
-0+/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM drivers/pci/pcie/aspm.c static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) · line 903
Quoted 10 lines
drivers/pci/pcie/aspm.c +8
-1+* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;Quoted 7 lines
Well, this is not nice.
First off, it adds VMD-specific stuff to otherwise generic ASPM code. Second, it doesn't actually do anything about the
aspm_disabledchecks all over the place, so they will still trigger even though ASPM will be effectively enabled for devices on the VMD bus.I agree that it's not nice to be mixing VMD specific code here. It's a working bad solution to come up with a working good solution :)
Quoted 7 lines
The reason this patch works is that the
aspm_disabledchecks only gate OS-controlled ASPM configuration. They don't affect the BIOS default values, which are what we're setting inlink->aspm_default. The ASPM code useslink->aspm_defaultas the fallback when ASPM is globally disabled, which is exactly what we want for devices behind VMD where the driver, not BIOS, effectively is the platform provider of the defaults.Quoted 6 lines
Oh, this was a big news to me.
So what you're saying is that if
aspm_disabledis set, ->aspm_disable cannot be set and thuspcie_config_aspm_link()that is not gated byaspm_disabledcan alter ASPM state despite OS not having ASPM control???
Quoted 6 lines
Yes, that’s correct. Bjorn can confirm, but I believe this is by design. The
aspm_disabledflag is really a bit of a misnomer. It probably should have been called something likeos_aspm_disabled. The intent as I understand it is that, when disallowed, the OS cannot select or manage the active ASPM policy, but it can still configure the link to match the BIOS provided policy.
Right, there's a long ugly history of this, here's the pcie_no_aspm() comment:
/*
* Disabling ASPM is intended to prevent the kernel from modifying
* existing hardware state, not to clear existing state. To that end:
* (a) set policy to POLICY_DEFAULT in order to avoid changing state
* (b) prevent userspace from changing policy
*/
if (!aspm_force) {
aspm_policy = POLICY_DEFAULT;
aspm_disabled = 1;}
which came from 3c076351c402 ("PCI: Rework ASPM disable code"). All the ASPM disable, force, support_enabled, policy, etc flags make this ugly and impossible to read. I guess renaming might help a little.
Quoted 6 lines
In other words, ASPM isn’t fully disabled. It’s just not under OS control. The BIOS values, reflected in
link->aspm_default, remain valid andpcie_config_aspm_link()can apply them regardless of theaspm_disabledsetting.Quoted 1 line
...That's really odd logic which the ASPM driver seems to be full of.
+10
Also the ugliness of pcie_aspm_init_link_state() being called completely out of the usual enumeration flow. And the parallel device hierarchy maintained in struct pcie_link_state. And config options to set the default policy. Ugh.
I hope we can avoid adding VMD-specific code in aspm.c.
Bjorn
Quoted 251 lines · David Box
Hey Rafael,
Quoted 46 lines · Rafael J. Wysocki
Quoted 12 lines · David E. Box
Devices behind Intel's Volume Management Device (VMD) controller reside on a synthetic PCI hierarchy that is intentionally hidden from ACPI and firmware. As such, BIOS does not configure ASPM for these devices, and the responsibility for link power management, including ASPM and LTR, falls entirely to the VMD driver.
However, the current PCIe ASPM code prevents ASPM configuration when the
ACPI_FADT_NO_ASPMflag is set, disallowing OS management. This leaves ASPM permanently disabled for these devices, contrary to the platform's design intent.Quoted 7 lines
Introduce a callback mechanism that allows the VMD driver to enable ASPM for its domain, bypassing the global
ACPI_FADT_NO_ASPMrestriction that is not applicable in this context. This ensures that devices behind VMD can benefit from ASPM savings as originally intended.First of all, thanks for doing this work, much appreciated!
Quoted 22 lines
--- drivers/pci/controller/vmd.c | 28 ++++++++++++++++++++++++++-- drivers/pci/pci.h | 8 ++++++++ drivers/pci/pcie/aspm.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +2
-0@@ -21,6 +21,8 @@#include <asm/irqdomain.h> +#include "../pci.h" +#define VMD_CFGBAR 0#define VMD_MEMBAR1 2#define VMD_MEMBAR2 4@@ -730,7 +732,7 @@ static void vmd_copy_host_bridge_flags(struct pci_host_bridge *root_bridge, }Quoted 14 lines
drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 773
Quoted 11 lines
drivers/pci/controller/vmd.c +1
-2/* -* Enable ASPM and LTR settings on devices that aren't configured by BIOS. +* Enable LTR settings on devices that aren't configured by BIOS. */ static int vmd_pm_enable_quirk (struct pci_dev *pdev,void *userdata) {@@ -770,10 +772,27 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata)* PCIe r6.0, sec 5.5.4. */ pci_set_power_state_locked (pdev,PCI_D0 ); -pci_enable_link_state_locked (pdev,PCIE_LINK_STATE_ALL );Do I think correctly that this doesn't work because of the
aspm_disabledcheck in__pci_enable_link_state()?Yes.
Quoted 21 lines
Quoted 8 lines
drivers/pci/controller/vmd.c +4
-0return 0 ; } +static long vmd_get_link_state (struct pci_dev *pdev,void *data) +{ +struct pci_bus *vmd_bus = data; +struct pci_bus *bus = pdev->bus;drivers/pci/controller/vmd.c static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) · line 791
Quoted 10 lines
drivers/pci/controller/vmd.c +10
-0+ +while (bus) { +if (bus == vmd_bus) +return PCIE_LINK_STATE_ALL ; + +if (!bus->self) +break ; + + bus = bus->self->bus; + }If I'm not mistaken, it would be sufficient to do a check like
Quoted 4 lines
if (pci_dev->bus->ops == &vmd_ops) return PCIE_LINK_STATE_ALL;instead of the above, or if not then why not?
As a replacement in the loop, that does look sufficient. I'm not sure if you're also suggesting replacing the loop itself.
Quoted 122 lines
Quoted 109 lines
drivers/pci/controller/vmd.c +9
-0+ +return -ENODEV ; +} +static int vmd_enable_domain (struct vmd_dev *vmd,unsigned long features) {struct pci_sysdata *sd = &vmd->sysdata;@@ -785,6 +804,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)resource_size_t membar2_offset =0x2000 ;struct pci_bus *child;struct pci_dev *dev; +struct pcie_aspm_vmd_link_state vmd_link_state;int ret;/* @@ -911,6 +931,10 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)return -ENODEV ; } + vmd_link_state.cb = vmd_get_link_state; + vmd_link_state.data = vmd->bus; +pci_register_vmd_link_state_cb (&vmd_link_state); +vmd_copy_host_bridge_flags (pci_find_host_bridge (vmd->dev->bus),to_pci_host_bridge (vmd->bus->bridge));drivers/pci/pci.h +8
-0@@ -821,6 +821,12 @@ void pci_configure_aspm_l1ss(struct pci_dev *dev);void pci_save_aspm_l1ss_state (struct pci_dev *dev);void pci_restore_aspm_l1ss_state (struct pci_dev *dev); + +struct pcie_aspm_vmd_link_state { +long (*cb)(struct pci_dev *pdev,void *data); +void *data; +}; +#ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state (struct pci_dev *pdev);void pcie_aspm_exit_link_state (struct pci_dev *pdev);@@ -828,6 +834,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);void pcie_aspm_powersave_config_link (struct pci_dev *pdev);void pci_configure_ltr (struct pci_dev *pdev);void pci_bridge_reconfigure_ltr (struct pci_dev *pdev); +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state);#else static inline void pcie_aspm_init_link_state (struct pci_dev *pdev) { }static inline void pcie_aspm_exit_link_state (struct pci_dev *pdev) { }@@ -835,6 +842,7 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)static inline void pcie_aspm_powersave_config_link (struct pci_dev *pdev) { }static inline void pci_configure_ltr (struct pci_dev *pdev) { }static inline void pci_bridge_reconfigure_ltr (struct pci_dev *pdev) { } +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) { }#endif #ifdef CONFIG_PCIE_ECRC drivers/pci/pcie/aspm.c +27
-0@@ -320,6 +320,27 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)return 0 ; } +static struct pcie_aspm_vmd_link_state vmd_state; + +void pci_register_vmd_link_state_cb (struct pcie_aspm_vmd_link_state *state) +{ +mutex_lock (&aspm_lock); + vmd_state.cb = state->cb; + vmd_state.data = state->data; +mutex_unlock (&aspm_lock); +} +EXPORT_SYMBOL_GPL (pci_register_vmd_link_state_cb); + +static long pci_get_vmd_link_state (struct pci_dev *pdev) +{ +int state = -ENODEV ; + +if (vmd_state.cb) + state = vmd_state.cb (pdev, vmd_state.data); + +return state; +} +static void pci_update_aspm_saved_state (struct pci_dev *dev) {struct pci_cap_saved_state *save_state;@@ -794,6 +815,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)u32 parent_lnkcap, child_lnkcap;u16 parent_lnkctl, child_lnkctl;struct pci_bus *linkbus = parent->subordinate; +int vmd_aspm_default;if (blacklist) {/* Set enabled/disable so that we will disable ASPM later */ @@ -865,8 +887,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)pcie_capability_write_word (child,PCI_EXP_LNKCTL , child_lnkctl); } +/* +* Devices behind Intel VMD operate on a synthetic PCI bus that BIOS +* and ACPI do not enumerate or configure. ASPM for these devices must +* be managed by the VMD driver itself, independent of global ACPI ASPM +* constraints. This callback mechanism allows selective ASPM drivers/pci/pcie/aspm.c static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) · line 903
Quoted 10 lines
drivers/pci/pcie/aspm.c +8
-1+* enablement for such domains. +*/ + vmd_aspm_default =pci_get_vmd_link_state (parent); +/* Save default state */ - link->aspm_default = link->aspm_enabled; +if (vmd_aspm_default <0 ) + link->aspm_default = link->aspm_enabled; +else + link->aspm_default = vmd_aspm_default;Well, this is not nice.
Quoted 4 lines
First off, it adds VMD-specific stuff to otherwise generic ASPM code. Second, it doesn't actually do anything about the
aspm_disabledchecks all over the place, so they will still trigger even though ASPM will be effectively enabled for devices on the VMD bus.I agree that it's not nice to be mixing VMD specific code here. It's a working bad solution to come up with a working good solution :)
The reason this patch works is that the
aspm_disabledchecks only gate OS-controlled ASPM configuration. They don't affect the BIOS default values, which are what we're setting inlink->aspm_default. The ASPM code useslink->aspm_defaultas the fallback when ASPM is globally disabled, which is exactly what we want for devices behind VMD where the driver, not BIOS, effectively is the platform provider of the defaults.I put it here using a callback value because this where the BIOS defaults are saved for each device.
Quoted 8 lines
Quoted 7 lines
drivers/pci/pcie/aspm.c +0
-0/* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support;base-commit:
d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af--Quoted 7 lines
It appears to me that the underlying problem is that
aspm_disabledis global and it is set during PCI root bus creation inacpi_pci_root_add(). Thus it affects all of the PCI buses even though the BIOS says that it wants to control ASPM for this particular PCIe hierarchy. If there were another PCI root enumerated by ACPI where the OS would be allowed to control ASPM, it would not work just like the VMD case.
Quoted 7 lines
It would work in the non-VMD case because it has the BIOS default to use. VMD does not.
Quoted 4 lines
To me, this suggests an approach based on moving the "ASPM disabled because the BIOS wants to control it" setting to
pci_bus_flags_tand setting it on a per-hierarchy basis.
A bus flag would address the need to bypass aspm_disabled for a given hierarchy, but it doesn’t solve the second part of the problem, providing the policy to apply in place of the missing BIOS defaults.
Ideally, policy should be determined within pcie_aspm_cap_init(), rather than requiring a separate walk, which the VMD driver does now (but only works when aspm_disabled is not set).
To support this cleanly, what if we added a pm_ops pointer to struct pci_bus?
This pci_bus_pm_ops struct could include a method, like get_aspm_default(), that aspm.c would query to retrieve the appropriate default policy if present. The presence of this pm_ops interface would also indicate that aspm_disabled should not apply to that bus, avoiding the need for an additional flag.
The relevant logic in pcie_aspm_cap_init() would look like this:
struct pci_bus_pm_ops *pm_ops = parent->bus->pm_ops;
...
if (pm_ops && pm_ops->get_aspm_default)
link->aspm_default = pm_ops->get_aspm_default(parent);
else
link->aspm_default = link->aspm_enabled;Would this be a more acceptable direction?
David