PCI: rcar: Add L1 link state fix into data abort hook
Subsystems (4)
PATCH v4 1/1 PCI: rcar: Add L1 link state fix into data abort hook
From: Marek Vasut <[email protected]>
The R-Car PCIe controller is capable of handling L0s/L1 link states. While the controller can enter and exit L0s link state, and exit L1 link state, without any additional action from the driver, to enter L1 link state, the driver must complete the link state transition by issuing additional commands to the controller.
The problem is, this transition is not atomic. The controller sets PMEL1RX bit in PMSR register upon reception of PM_ENTER_L1 DLLP from the PCIe card, but then the controller enters some sort of inbetween state. The driver must detect this condition and complete the link state transition, by setting L1IATN bit in PMCTLR and waiting for the link state transition to complete.
If a PCIe access happens inside this window, where the controller is between L0 and L1 link states, the access generates a fault and the ARM 'imprecise external abort' handler is invoked.
Just like other PCI controller drivers, here we hook the fault handler, perform the fixup to help the controller enter L1 link state, and then restart the instruction which triggered the fault. Since the controller is in L1 link state now, the link can exit from L1 link state to L0 and successfully complete the access.
Note that this fixup is applicable only to Aarch32 R-Car controllers,
the Aarch64 R-Car perform the same fixup in TFA, see TFA commit [1]0969397f2 ("rcar_gen3: plat: Prevent PCIe hang during L1X config access")
[1] https://github.com/ARM-software/arm-trusted-firmware/commit/0969397f295621aa26b3d14b76dd397d22be58bf
---
V2: - Update commit message, add link to TFA repository commit
- Handle the LPAE case as in ARM fault.c and fsr-{2,3}level.c
- Cache clock and check whether they are enabled before register access
V3: - Fix commit message according to spellchecker
- Use of_find_matching_node() to apply hook only on Gen1 and Gen2 RCar (in case the kernel is multiplatform)
V4: - Mark rcar_pcie_abort_handler_of_match with __initconst
--- drivers/pci/controller/pcie-rcar-host.c | 76 +++++++++++++++++++++++++ drivers/pci/controller/pcie-rcar.h | 7 +++ 2 files changed, 83 insertions(+)
drivers/pci/controller/pcie-rcar-host.c +76 -0
@@ -13,6 +13,7 @@#include <linux/bitops.h> #include <linux/clk.h> +#include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/irq.h>
@@ -42,6 +43,21 @@ struct rcar_msi {int irq2; }; +#ifdef CONFIG_ARM +/* +* Here we keep a static copy of the remapped PCIe controller address. +* This is only used on aarch32 systems, all of which have one single +* PCIe controller, to provide quick access to the PCIe controller in +* the L1 link state fixup function, called from the ARM fault handler. +*/ +static void __iomem *pcie_base; +/* +* Static copy of bus clock pointer, so we can check whether the clock +* is enabled or not. +*/ +static struct clk *pcie_bus_clk; +#endif +static inline struct rcar_msi *to_rcar_msi (struct msi_controller *chip) { return container_of(chip, struct rcar_msi, chip);
@@ -804,6 +820,12 @@ static int rcar_pcie_get_resources(struct rcar_pcie_host *host) } host->msi.irq2 = i; +#ifdef CONFIG_ARM +/* Cache static copy for L1 link state fixup hook on aarch32 */ + pcie_base = pcie->base; + pcie_bus_clk = host->bus_clk; +#endif +return 0 ; err_irq2:
@@ -1050,4 +1072,58 @@ static struct platform_driver rcar_pcie_driver = { }, .probe = rcar_pcie_probe, }; + +#ifdef CONFIG_ARM +static int rcar_pcie_aarch32_abort_handler (unsigned long addr, +unsigned int fsr,struct pt_regs *regs) +{ +u32 pmsr; + +if (!pcie_base || !__clk_is_enabled (pcie_bus_clk)) +return 1 ; + + pmsr =readl (pcie_base +PMSR ); + +/* +* Test if the PCIe controller received PM_ENTER_L1 DLLP and +* the PCIe controller is not in L1 link state. If true, apply +* fix, which will put the controller into L1 link state, from +* which it can return to L0s/L0 on its own. +*/ +if ((pmsr &PMEL1RX ) && ((pmsr &PMSTATE ) !=PMSTATE_L1 )) { +writel (L1IATN , pcie_base +PMCTLR ); +while (!(readl (pcie_base +PMSR ) &L1FAEG )) + ; +writel (L1FAEG |PMEL1RX , pcie_base +PMSR ); +return 0 ; + } + +return 1 ; +} + +static const struct of_device_id rcar_pcie_abort_handler_of_match[]__initconst = { + { .compatible ="renesas,pcie-r8a7779" }, + { .compatible ="renesas,pcie-r8a7790" }, + { .compatible ="renesas,pcie-r8a7791" }, + { .compatible ="renesas,pcie-rcar-gen2" }, + {}, +}; + +static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else +hook_fault_code (22 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"imprecise external abort" ); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +} +device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif
drivers/pci/controller/pcie-rcar.h +7 -0
@@ -85,6 +85,13 @@#define LTSMDIS BIT(31)#define MACCTLR_INIT_VAL (LTSMDIS | MACCTLR_NFTS_MASK)#define PMSR 0x01105c +#define L1FAEG BIT(31) +#define PMEL1RX BIT(23) +#define PMSTATE GENMASK(18, 16) +#define PMSTATE_L1 (3 << 16) +#define PMCTLR 0x011060 +#define L1IATN BIT(31) +#define MACS2R 0x011078#define MACCGSPSETR 0x011084#define SPCNGRSN BIT(31)
Signature · 1 line
2.28.0
Quoted 37 lines · On Fri, Oct 16, 2020 at 2:04 PM <[email protected]> wrote:
From: Marek Vasut <[email protected]>
The R-Car PCIe controller is capable of handling L0s/L1 link states. While the controller can enter and exit L0s link state, and exit L1 link state, without any additional action from the driver, to enter L1 link state, the driver must complete the link state transition by issuing additional commands to the controller.
The problem is, this transition is not atomic. The controller sets PMEL1RX bit in PMSR register upon reception of
PM_ENTER_L1DLLP from the PCIe card, but then the controller enters some sort of inbetween state. The driver must detect this condition and complete the link state transition, by setting L1IATN bit in PMCTLR and waiting for the link state transition to complete.If a PCIe access happens inside this window, where the controller is between L0 and L1 link states, the access generates a fault and the ARM 'imprecise external abort' handler is invoked.
Just like other PCI controller drivers, here we hook the fault handler, perform the fixup to help the controller enter L1 link state, and then restart the instruction which triggered the fault. Since the controller is in L1 link state now, the link can exit from L1 link state to L0 and successfully complete the access.
Note that this fixup is applicable only to Aarch32 R-Car controllers,
the Aarch64 R-Car perform the same fixup in TFA, see TFA commit [1]0969397f2("rcar_gen3: plat: Prevent PCIe hang during L1X config access")
[1] https://github.com/ARM-software/arm-trusted-firmware/commit/0969397f295621aa26b3d14b76dd397d22be58bfSigned-off-by Marek Vasut <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Wolfram Sang <[email protected]>Cc Yoshihiro Shimoda <[email protected]>
Quoted 9 lines
---
V2: - Update commit message, add link to TFA repository commit
- Handle the LPAE case as in ARMfault.cand fsr-{2,3}level.c
- Cache clock and check whether they are enabled before register access
V3: - Fix commit message according to spellchecker
- Useof_find_matching_node()to apply hook only on Gen1 and Gen2 RCar (in case the kernel is multiplatform)
V4: - Markrcar_pcie_abort_handler_of_matchwith__initconst
Please add tags given to the previous version:
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
On Fri, Oct 16, 2020 at 02:04:16PM +0200, [email protected] wrote:
[...]
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +4
-0+#ifdef CONFIG_ARM +/* +* Here we keep a static copy of the remapped PCIe controller address. +* This is only used on aarch32 systems, all of which have one single
drivers/pci/controller/pcie-rcar-host.c struct rcar_msi { · line 59
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+* PCIe controller, to provide quick access to the PCIe controller in +* the L1 link state fixup function, called from the ARM fault handler. +*/ +static void __iomem *pcie_base; +/* +* Static copy of bus clock pointer, so we can check whether the clock +* is enabled or not. +*/ +static struct clk *pcie_bus_clk; +#endif
Don't think you can have multiple host bridges in a given platform, if it is a possible configuration this won't work.
Quoted 35 lines
static inline struct
rcar_msi*to_rcar_msi(structmsi_controller*chip) {drivers/pci/controller/pcie-rcar-host.c +21
-0return container_of(chip, struct rcar_msi, chip);@@ -804,6 +820,12 @@ static int rcar_pcie_get_resources(struct rcar_pcie_host *host) } host->msi.irq2 = i; +#ifdef CONFIG_ARM +/* Cache static copy for L1 link state fixup hook on aarch32 */ + pcie_base = pcie->base; + pcie_bus_clk = host->bus_clk; +#endif +return 0 ; err_irq2:@@ -1050,4 +1072,58 @@ static struct platform_driver rcar_pcie_driver = { }, .probe = rcar_pcie_probe, }; + +#ifdef CONFIG_ARM +static int rcar_pcie_aarch32_abort_handler (unsigned long addr, +unsigned int fsr,struct pt_regs *regs) +{ +u32 pmsr; + +if (!pcie_base || !__clk_is_enabled (pcie_bus_clk)) +return 1 ; + + pmsr =readl (pcie_base +PMSR ); + +/* +* Test if the PCIe controller received PM_ENTER_L1 DLLP and +* the PCIe controller is not in L1 link state. If true, apply
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1099
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+* fix, which will put the controller into L1 link state, from +* which it can return to L0s/L0 on its own. +*/ +if ((pmsr &PMEL1RX ) && ((pmsr &PMSTATE ) !=PMSTATE_L1 )) { +writel (L1IATN , pcie_base +PMCTLR ); +while (!(readl (pcie_base +PMSR ) &L1FAEG )) + ; +writel (L1FAEG |PMEL1RX , pcie_base +PMSR ); +return 0 ; + }
I suppose a fault on multiple cores can happen simultaneously, if it does this may not work well either - I assume all config/io/mem would trigger a fault.
As I mentioned in my reply to v1, is there a chance we can move this quirk into config accessors (if the PM_ENTER_L1_DLLP is subsequent to a write into PMCSR to programme a D state) ?
Config access is serialized but I suspect as I said above that this triggers on config/io/mem alike.
Just asking to try to avoid a fault handler if possible.
Thanks,
Lorenzo
Quoted 51 lines
drivers/pci/controller/pcie-rcar-host.c +29
-0+ + return 1; +} + +static const struct of_device_id rcar_pcie_abort_handler_of_match[]__initconst = { + { .compatible ="renesas,pcie-r8a7779" }, + { .compatible ="renesas,pcie-r8a7790" }, + { .compatible ="renesas,pcie-r8a7791" }, + { .compatible ="renesas,pcie-rcar-gen2" }, + {}, +}; + +static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else +hook_fault_code (22 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"imprecise external abort" ); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +} +device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif drivers/pci/controller/pcie-rcar.h +7
-0@@ -85,6 +85,13 @@#define LTSMDIS BIT(31)#define MACCTLR_INIT_VAL (LTSMDIS | MACCTLR_NFTS_MASK)#define PMSR 0x01105c +#define L1FAEG BIT(31) +#define PMEL1RX BIT(23) +#define PMSTATE GENMASK(18, 16) +#define PMSTATE_L1 (3 << 16) +#define PMCTLR 0x011060 +#define L1IATN BIT(31) +#define MACS2R 0x011078#define MACCGSPSETR 0x011084#define SPCNGRSN BIT(31)Signature · 1 line
2.28.0
Quoted 9 lines · Lorenzo Pieralisi
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+#ifdef CONFIG_ARM +/* +* Here we keep a static copy of the remapped PCIe controller address. +* This is only used on aarch32 systems, all of which have one single +* PCIe controller, to provide quick access to the PCIe controller in +* the L1 link state fixup function, called from the ARM fault handler. +*/ +static void __iomem *pcie_base; +/*
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c struct rcar_msi { · line 59
Quoted 5 lines
+ * Static copy of bus clock pointer, so we can check whether the clock
+ * is enabled or not.
+ */drivers/pci/controller/pcie-rcar-host.c +2
-0+static struct clk *pcie_bus_clk; +#endif Don't think you can have multiple host bridges in a given platform, if it is a possible configuration this won't work.
Correct, all the affected platforms have only one host bridge.
Quoted 50 lines
Quoted 35 lines
static inline struct rcar_msi *to_rcar_msi(struct msi_controller *chip) { return container_of(chip, struct rcar_msi, chip);drivers/pci/controller/pcie-rcar-host.c +21
-0@@ -804,6 +820,12 @@ static int rcar_pcie_get_resources(struct rcar_pcie_host *host) } host->msi.irq2 = i; +#ifdef CONFIG_ARM +/* Cache static copy for L1 link state fixup hook on aarch32 */ + pcie_base = pcie->base; + pcie_bus_clk = host->bus_clk; +#endif +return 0 ; err_irq2:@@ -1050,4 +1072,58 @@ static struct platform_driver rcar_pcie_driver = { }, .probe = rcar_pcie_probe, }; + +#ifdef CONFIG_ARM +static int rcar_pcie_aarch32_abort_handler (unsigned long addr, +unsigned int fsr,struct pt_regs *regs) +{ +u32 pmsr; + +if (!pcie_base || !__clk_is_enabled (pcie_bus_clk)) +return 1 ; + + pmsr =readl (pcie_base +PMSR ); + +/* +* Test if the PCIe controller received PM_ENTER_L1 DLLP and +* the PCIe controller is not in L1 link state. If true, apply drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1099
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+* fix, which will put the controller into L1 link state, from +* which it can return to L0s/L0 on its own. +*/ +if ((pmsr &PMEL1RX ) && ((pmsr &PMSTATE ) !=PMSTATE_L1 )) { +writel (L1IATN , pcie_base +PMCTLR ); +while (!(readl (pcie_base +PMSR ) &L1FAEG )) + ; +writel (L1FAEG |PMEL1RX , pcie_base +PMSR ); +return 0 ; + }I suppose a fault on multiple cores can happen simultaneously, if it does this may not work well either - I assume all config/io/mem would trigger a fault.
Quoted 3 lines
As I mentioned in my reply to v1, is there a chance we can move this quirk into config accessors (if the
PM_ENTER_L1_DLLPis subsequent to a write into PMCSR to programme a D state) ?
I don't think we can, since the userspace can do such a config space write with e.g. setpci and then this fixup is still needed.
Quoted 4 lines
Config access is serialized but I suspect as I said above that this triggers on config/io/mem alike.
Just asking to try to avoid a fault handler if possible.
See above, I doubt we can fully avoid this workaround.
[...]
Quoted 69 lines · Marek Vasut
Quoted 9 lines · Lorenzo Pieralisi
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+#ifdef CONFIG_ARM +/* +* Here we keep a static copy of the remapped PCIe controller address. +* This is only used on aarch32 systems, all of which have one single +* PCIe controller, to provide quick access to the PCIe controller in +* the L1 link state fixup function, called from the ARM fault handler. +*/ +static void __iomem *pcie_base; +/* Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c struct rcar_msi { · line 59
Quoted 5 lines
+ * Static copy of bus clock pointer, so we can check whether the clock
+ * is enabled or not.
+ */drivers/pci/controller/pcie-rcar-host.c +2
-0+static struct clk *pcie_bus_clk; +#endif Don't think you can have multiple host bridges in a given platform, if it is a possible configuration this won't work.
Correct, all the affected platforms have only one host bridge.
Quoted 48 lines
Quoted 33 lines
static inline struct rcar_msi *to_rcar_msi(struct msi_controller *chip) { return container_of(chip, struct rcar_msi, chip);drivers/pci/controller/pcie-rcar-host.c +21
-0@@ -804,6 +820,12 @@ static int rcar_pcie_get_resources(struct rcar_pcie_host *host) } host->msi.irq2 = i; +#ifdef CONFIG_ARM +/* Cache static copy for L1 link state fixup hook on aarch32 */ + pcie_base = pcie->base; + pcie_bus_clk = host->bus_clk; +#endif +return 0 ; err_irq2:@@ -1050,4 +1072,58 @@ static struct platform_driver rcar_pcie_driver = { }, .probe = rcar_pcie_probe, }; + +#ifdef CONFIG_ARM +static int rcar_pcie_aarch32_abort_handler (unsigned long addr, +unsigned int fsr,struct pt_regs *regs) +{ +u32 pmsr; + +if (!pcie_base || !__clk_is_enabled (pcie_bus_clk)) +return 1 ; + + pmsr =readl (pcie_base +PMSR ); + +/* +* Test if the PCIe controller received PM_ENTER_L1 DLLP and +* the PCIe controller is not in L1 link state. If true, apply drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1099
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+* fix, which will put the controller into L1 link state, from +* which it can return to L0s/L0 on its own. +*/ +if ((pmsr &PMEL1RX ) && ((pmsr &PMSTATE ) !=PMSTATE_L1 )) { +writel (L1IATN , pcie_base +PMCTLR ); +while (!(readl (pcie_base +PMSR ) &L1FAEG )) + ; +writel (L1FAEG |PMEL1RX , pcie_base +PMSR ); +return 0 ; + }I suppose a fault on multiple cores can happen simultaneously, if it does this may not work well either - I assume all config/io/mem would trigger a fault.
Quoted 6 lines
Quoted 3 lines
As I mentioned in my reply to v1, is there a chance we can move this quirk into config accessors (if the
PM_ENTER_L1_DLLPis subsequent to a write into PMCSR to programme a D state) ?I don't think we can, since the userspace can do such a config space write with e.g. setpci and then this fixup is still needed.
Userspace goes via the kernel config accessors anyway, right ?
I would like to avoid having arch specific hooks in PCI drivers so if we can work around it somehow it is much better.
I can still merge this patch this week but I would like to explore alternatives before committing it.
Lorenzo
Quoted 9 lines
Quoted 5 lines
Config access is serialized but I suspect as I said above that this triggers on config/io/mem alike.
Just asking to try to avoid a fault handler if possible.
See above, I doubt we can fully avoid this workaround.
[...]
On 12/8/20 11:18 AM, Lorenzo Pieralisi wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
I suppose a fault on multiple cores can happen simultaneously, if it does this may not work well either - I assume all config/io/mem would trigger a fault.
As I mentioned in my reply to v1, is there a chance we can move this quirk into config accessors (if the
PM_ENTER_L1_DLLPis subsequent to a write into PMCSR to programme a D state) ?
Quoted 5 lines
Quoted 2 lines
I don't think we can, since the userspace can do such a config space write with e.g. setpci and then this fixup is still needed.
Userspace goes via the kernel config accessors anyway, right ?
As far as I can tell, you can just write the register with devmem, so no. You cannot assume everything will go through the accessors. I don't think setpci does either.
Quoted 2 lines
I would like to avoid having arch specific hooks in PCI drivers so if we can work around it somehow it is much better.
I think we had this discussion before, which ultimately led to hiding the workaround in ATF on Gen3. On Gen2, there is no ATF, so the work around must be in Linux.
Quoted 2 lines
I can still merge this patch this week but I would like to explore alternatives before committing it.
Please merge it as-is.
Quoted 22 lines · Marek Vasut
On 12/8/20 11:18 AM, Lorenzo Pieralisi wrote:
[...]Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
I suppose a fault on multiple cores can happen simultaneously, if it does this may not work well either - I assume all config/io/mem would trigger a fault.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
As I mentioned in my reply to v1, is there a chance we can move this quirk into config accessors (if the
PM_ENTER_L1_DLLPis subsequent to a write into PMCSR to programme a D state) ?I don't think we can, since the userspace can do such a config space write with e.g. setpci and then this fixup is still needed.
Userspace goes via the kernel config accessors anyway, right ?
As far as I can tell, you can just write the register with devmem, so no. You cannot assume everything will go through the accessors. I don't think setpci does either.
Quoted 2 lines
I would like to avoid having arch specific hooks in PCI drivers so if we can work around it somehow it is much better.
Quoted 8 lines
I think we had this discussion before, which ultimately led to hiding the workaround in ATF on Gen3. On Gen2, there is no ATF, so the work around must be in Linux.
Quoted 2 lines
I can still merge this patch this week but I would like to explore alternatives before committing it.
Please merge it as-is.
+1
This can be triggered easily, just insert a stock Intel Ethernet card, s2ram, and boom.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 3 lines · On Fri, Oct 16, 2020 at 02:04:16PM +0200, [email protected] wrote:
From: Marek Vasut <[email protected]>
The R-Car PCIe controller is capable of handling L0s/L1 link states.
Minor wording nit: L0s seems irrelevant to this patch.
All PCIe functions are required to support the Power Management Capability (PCIe r5.0, sec 7.5.2), and that in turn requires D0, D3hot, and D3cold support, and D3hot requires L1 (sec 5.2).
So saying this device "is capable of handling L1" really doesn't tell us anything, and it glosses over the fact that it doesn't do it *correctly* and requires help from the driver to work around this hardware defect.
Does this problem occur in both these cases?
1) When ASPM enters L1, and
2) When software writes PCI_PM_CTRL to put the device in D3hot?
IIUC both cases require the link to go to L1. I guess the same software workaround applies to both cases?
Quoted 116 lines
While the controller can enter and exit L0s link state, and exit L1 link state, without any additional action from the driver, to enter L1 link state, the driver must complete the link state transition by issuing additional commands to the controller.
The problem is, this transition is not atomic. The controller sets PMEL1RX bit in PMSR register upon reception of
PM_ENTER_L1DLLP from the PCIe card, but then the controller enters some sort of inbetween state. The driver must detect this condition and complete the link state transition, by setting L1IATN bit in PMCTLR and waiting for the link state transition to complete.If a PCIe access happens inside this window, where the controller is between L0 and L1 link states, the access generates a fault and the ARM 'imprecise external abort' handler is invoked.
Just like other PCI controller drivers, here we hook the fault handler, perform the fixup to help the controller enter L1 link state, and then restart the instruction which triggered the fault. Since the controller is in L1 link state now, the link can exit from L1 link state to L0 and successfully complete the access.
Note that this fixup is applicable only to Aarch32 R-Car controllers,
the Aarch64 R-Car perform the same fixup in TFA, see TFA commit [1]0969397f2("rcar_gen3: plat: Prevent PCIe hang during L1X config access")
[1] https://github.com/ARM-software/arm-trusted-firmware/commit/0969397f295621aa26b3d14b76dd397d22be58bfSigned-off-by Marek Vasut <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Wolfram Sang <[email protected]>Cc Yoshihiro Shimoda <[email protected]>---
V2: - Update commit message, add link to TFA repository commit
- Handle the LPAE case as in ARMfault.cand fsr-{2,3}level.c
- Cache clock and check whether they are enabled before register access
V3: - Fix commit message according to spellchecker
- Useof_find_matching_node()to apply hook only on Gen1 and Gen2 RCar (in case the kernel is multiplatform)
V4: - Markrcar_pcie_abort_handler_of_matchwith__initconst--- drivers/pci/controller/pcie-rcar-host.c | 76 +++++++++++++++++++++++++ drivers/pci/controller/pcie-rcar.h | 7 +++ 2 files changed, 83 insertions(+)drivers/pci/controller/pcie-rcar-host.c +39
-0@@ -13,6 +13,7 @@#include <linux/bitops.h> #include <linux/clk.h> +#include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/irq.h> @@ -42,6 +43,21 @@ struct rcar_msi {int irq2; }; +#ifdef CONFIG_ARM +/* +* Here we keep a static copy of the remapped PCIe controller address. +* This is only used on aarch32 systems, all of which have one single +* PCIe controller, to provide quick access to the PCIe controller in +* the L1 link state fixup function, called from the ARM fault handler. +*/ +static void __iomem *pcie_base; +/* +* Static copy of bus clock pointer, so we can check whether the clock +* is enabled or not. +*/ +static struct clk *pcie_bus_clk; +#endif +static inline struct rcar_msi *to_rcar_msi (struct msi_controller *chip) { return container_of(chip, struct rcar_msi, chip);@@ -804,6 +820,12 @@ static int rcar_pcie_get_resources(struct rcar_pcie_host *host) } host->msi.irq2 = i; +#ifdef CONFIG_ARM +/* Cache static copy for L1 link state fixup hook on aarch32 */ + pcie_base = pcie->base; + pcie_bus_clk = host->bus_clk; +#endif +return 0 ; err_irq2:@@ -1050,4 +1072,58 @@ static struct platform_driver rcar_pcie_driver = { }, .probe = rcar_pcie_probe, }; + +#ifdef CONFIG_ARM +static int rcar_pcie_aarch32_abort_handler (unsigned long addr, +unsigned int fsr,struct pt_regs *regs) +{ +u32 pmsr; + +if (!pcie_base || !__clk_is_enabled (pcie_bus_clk)) +return 1 ; + + pmsr =readl (pcie_base +PMSR ); + +/* +* Test if the PCIe controller received PM_ENTER_L1 DLLP and +* the PCIe controller is not in L1 link state. If true, apply +* fix, which will put the controller into L1 link state, from +* which it can return to L0s/L0 on its own.
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1101
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+*/ +if ((pmsr &PMEL1RX ) && ((pmsr &PMSTATE ) !=PMSTATE_L1 )) { +writel (L1IATN , pcie_base +PMCTLR ); +while (!(readl (pcie_base +PMSR ) &L1FAEG )) + ; +writel (L1FAEG |PMEL1RX , pcie_base +PMSR ); +return 0 ; + } + +return 1 ;
I have no insight into how these abort handlers work. Looks awfully kludgy to me, but if it's the only way and the ARM folks are on board with it, I can't object.
I guess the other alternative would be to have a quirk to stop advertising ASPM L1 support and D1/D2/D3hot support. Obviously that may give up some power savings.
If people aren't comfortable with the reliability or maintainability of this approach in the upstream kernel, there's always the option of the users who need it carrying this as an out-of-tree patch.
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1110
Quoted 9 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+} + +static const struct of_device_id rcar_pcie_abort_handler_of_match[]__initconst = { + { .compatible ="renesas,pcie-r8a7779" }, + { .compatible ="renesas,pcie-r8a7790" }, + { .compatible ="renesas,pcie-r8a7791" }, + { .compatible ="renesas,pcie-rcar-gen2" }, + {}, +};
Why do we need another copy of these, as opposed to doing something with of_device_get_match_data(), e.g., like brcm_pcie_probe() does?
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c +8
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else + hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+ "imprecise external abort"); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +} +device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif
Is the device_initcall() vs builtin_platform_driver() something related to the hook_fault_code()? What would break if this were always builtin_platform_driver()?
Quoted 21 lines
drivers/pci/controller/pcie-rcar.h +7
-0@@ -85,6 +85,13 @@#define LTSMDIS BIT(31)#define MACCTLR_INIT_VAL (LTSMDIS | MACCTLR_NFTS_MASK)#define PMSR 0x01105c +#define L1FAEG BIT(31) +#define PMEL1RX BIT(23) +#define PMSTATE GENMASK(18, 16) +#define PMSTATE_L1 (3 << 16) +#define PMCTLR 0x011060 +#define L1IATN BIT(31) +#define MACS2R 0x011078#define MACCGSPSETR 0x011084#define SPCNGRSN BIT(31)Signature · 1 line
2.28.0
On 12/8/20 5:40 PM, Bjorn Helgaas wrote:
[...]
Quoted 3 lines
Quoted 1 line
The R-Car PCIe controller is capable of handling L0s/L1 link states.
Minor wording nit: L0s seems irrelevant to this patch.
Of course.
Quoted 8 lines
All PCIe functions are required to support the Power Management Capability (PCIe r5.0, sec 7.5.2), and that in turn requires D0, D3hot, and D3cold support, and D3hot requires L1 (sec 5.2).
So saying this device "is capable of handling L1" really doesn't tell us anything, and it glosses over the fact that it doesn't do it *correctly* and requires help from the driver to work around this hardware defect.
I see.
Quoted 8 lines
Does this problem occur in both these cases?
1) When ASPM enters L1, and
2) When software writes
PCI_PM_CTRLto put the device in D3hot?IIUC both cases require the link to go to L1. I guess the same software workaround applies to both cases?
Yes
[...]
Quoted 31 lines
Quoted 16 lines
drivers/pci/controller/pcie-rcar-host.c +16
-0+#ifdef CONFIG_ARM +static int rcar_pcie_aarch32_abort_handler (unsigned long addr, +unsigned int fsr,struct pt_regs *regs) +{ +u32 pmsr; + +if (!pcie_base || !__clk_is_enabled (pcie_bus_clk)) +return 1 ; + + pmsr =readl (pcie_base +PMSR ); + +/* +* Test if the PCIe controller received PM_ENTER_L1 DLLP and +* the PCIe controller is not in L1 link state. If true, apply +* fix, which will put the controller into L1 link state, from +* which it can return to L0s/L0 on its own. drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1101
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +10
-0+*/ +if ((pmsr &PMEL1RX ) && ((pmsr &PMSTATE ) !=PMSTATE_L1 )) { +writel (L1IATN , pcie_base +PMCTLR ); +while (!(readl (pcie_base +PMSR ) &L1FAEG )) + ; +writel (L1FAEG |PMEL1RX , pcie_base +PMSR ); +return 0 ; + } + +return 1 ;I have no insight into how these abort handlers work. Looks awfully kludgy to me, but if it's the only way and the ARM folks are on board with it, I can't object.
Quoted 7 lines
I guess the other alternative would be to have a quirk to stop advertising ASPM L1 support and D1/D2/D3hot support. Obviously that may give up some power savings.
If people aren't comfortable with the reliability or maintainability of this approach in the upstream kernel, there's always the option of the users who need it carrying this as an out-of-tree patch.
I would highly prefer to be able to use mainline Linux as-is, without carrying any extra patches, so BSP is not an option.
Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +4
-0+} + +static const struct of_device_id rcar_pcie_abort_handler_of_match[]__initconst = { + { .compatible ="renesas,pcie-r8a7779" },
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1110
Quoted 5 lines
drivers/pci/controller/pcie-rcar-host.c +5
-0+ { .compatible = "renesas,pcie-r8a7790" }, + { .compatible = "renesas,pcie-r8a7791" }, + { .compatible = "renesas,pcie-rcar-gen2" }, + {}, +};Why do we need another copy of these, as opposed to doing something with
of_device_get_match_data(), e.g., likebrcm_pcie_probe()does?
This is not a copy, but as subset of SoCs which are affected by this problem.
Quoted 14 lines
Quoted 14 lines
drivers/pci/controller/pcie-rcar-host.c +14
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else +hook_fault_code (22 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"imprecise external abort" ); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +}
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +3
-0+device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?
rcar_pcie_init() would not be called before probe.
Quoted 13 lines · Marek Vasut
Quoted 10 lines · Bjorn Helgaas
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1110
Quoted 7 lines
drivers/pci/controller/pcie-rcar-host.c +7
-0+static const struct of_device_id rcar_pcie_abort_handler_of_match[]__initconst = { + { .compatible ="renesas,pcie-r8a7779" }, + { .compatible ="renesas,pcie-r8a7790" }, + { .compatible ="renesas,pcie-r8a7791" }, + { .compatible ="renesas,pcie-rcar-gen2" }, + {}, +};Why do we need another copy of these, as opposed to doing something with
of_device_get_match_data(), e.g., likebrcm_pcie_probe()does?
Quoted 2 lines
This is not a copy, but as subset of SoCs which are affected by this problem.
I know it's not a complete copy. Many systems include flags like "broken_l1" in their match_data. Something like this:
struct rcar_pcie_drvdata {
int (*phy_init_fn)(struct rcar_pcie_host *host);
unsigned int broken_l1:1;
};
static const struct rcar_pcie_drvdata rcar_init_h1_drvdata = {
.phy_init_fn = rcar_pcie_phy_init_h1,
.broken_l1 = 1,
};
static const struct rcar_pcie_drvdata rcar_init_gen2_drvdata = {
.phy_init_fn = rcar_pcie_phy_init_gen2,
.broken_l1 = 1,
};
static const struct rcar_pcie_drvdata rcar_init_gen3_drvdata = {
.phy_init_fn = rcar_pcie_phy_init_gen3,
}; static const struct of_device_id rcar_pcie_of_match[] = {
{ .compatible = "renesas,pcie-r8a7779", .data = rcar_init_h1_drvdata },
{ .compatible = "renesas,pcie-r8a7790", .data = rcar_init_gen2_drvdata },
{ .compatible = "renesas,pcie-r8a7791", .data = rcar_init_gen2_drvdata },
...Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/pci/controller/pcie-rcar-host.c +14
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else +hook_fault_code (22 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"imprecise external abort" ); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +}Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +3
-0+device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?
Quoted 1 line
rcar_pcie_init()would not be called before probe.
Sorry to be slow, but why does it need to be called before probe? Obviously software isn't putting the controller in D3 or enabling ASPM before probe.
Bjorn
Quoted 39 lines · Bjorn Helgaas
Quoted 13 lines · Marek Vasut
Quoted 10 lines · Bjorn Helgaas
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1110
Quoted 7 lines
drivers/pci/controller/pcie-rcar-host.c +7
-0+static const struct of_device_id rcar_pcie_abort_handler_of_match[]__initconst = { + { .compatible ="renesas,pcie-r8a7779" }, + { .compatible ="renesas,pcie-r8a7790" }, + { .compatible ="renesas,pcie-r8a7791" }, + { .compatible ="renesas,pcie-rcar-gen2" }, + {}, +};Why do we need another copy of these, as opposed to doing something with
of_device_get_match_data(), e.g., likebrcm_pcie_probe()does?Quoted 2 lines
This is not a copy, but as subset of SoCs which are affected by this problem.
I know it's not a complete copy. Many systems include flags like "
broken_l1" in theirmatch_data. Something like this:struct rcar_pcie_drvdata { int (*phy_init_fn)(struct rcar_pcie_host *host); unsigned int broken_l1:1; }; static const struct rcar_pcie_drvdata rcar_init_h1_drvdata = { .phy_init_fn = rcar_pcie_phy_init_h1, .broken_l1 = 1, }; static const struct rcar_pcie_drvdata rcar_init_gen2_drvdata = { .phy_init_fn = rcar_pcie_phy_init_gen2, .broken_l1 = 1, }; static const struct rcar_pcie_drvdata rcar_init_gen3_drvdata = { .phy_init_fn = rcar_pcie_phy_init_gen3, };
Quoted 5 lines
static const struct of_device_id rcar_pcie_of_match[] = {
{ .compatible = "renesas,pcie-r8a7779", .data = rcar_init_h1_drvdata },
{ .compatible = "renesas,pcie-r8a7790", .data = rcar_init_gen2_drvdata },
{ .compatible = "renesas,pcie-r8a7791", .data = rcar_init_gen2_drvdata },
...+1
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c +8
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else + hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+ "imprecise external abort"); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +} +device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?
Quoted 5 lines
Quoted 1 line
rcar_pcie_init()would not be called before probe.Sorry to be slow, but why does it need to be called before probe? Obviously software isn't putting the controller in D3 or enabling ASPM before probe.
I don't understand it either so it would be good to clarify.
Also, some of these platforms are SMP systems, I don't understand what prevents multiple cores to fault at once given that the faults can happen for config/io/mem accesses alike.
I understand that the immediate fix is for S2R, that is single threaded but I would like to understand how comprehensive this fix is.
Thanks,
Lorenzo
On 12/10/20 1:12 PM, Lorenzo Pieralisi wrote:
[...]
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c +8
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else + hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+ "imprecise external abort"); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +} +device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
rcar_pcie_init()would not be called before probe.Sorry to be slow, but why does it need to be called before probe? Obviously software isn't putting the controller in D3 or enabling ASPM before probe.
I don't understand it either so it would be good to clarify.
The hook_fault_code() is marked __init, so if probe() was deferred and the kernel __init memory was free'd, attempt to call hook_fault_code() from probe would lead to a crash.
Quoted 7 lines
Also, some of these platforms are SMP systems, I don't understand what prevents multiple cores to fault at once given that the faults can happen for config/io/mem accesses alike.
I understand that the immediate fix is for S2R, that is single threaded but I would like to understand how comprehensive this fix is.
Are you suggesting to add some sort of locking ?
Quoted 33 lines · Marek Vasut
On 12/10/20 1:12 PM, Lorenzo Pieralisi wrote:
[...]
Quoted 29 lines
Quoted 28 lines
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/pci/controller/pcie-rcar-host.c +14
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else +hook_fault_code (22 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"imprecise external abort" ); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +}Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 4 lines
drivers/pci/controller/pcie-rcar-host.c +3
-0+device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?Quoted 1 line
rcar_pcie_init()would not be called before probe.Sorry to be slow, but why does it need to be called before probe? Obviously software isn't putting the controller in D3 or enabling ASPM before probe.
Quoted 5 lines
Quoted 1 line
I don't understand it either so it would be good to clarify.
The
hook_fault_code()is marked__init, so ifprobe()was deferred and the kernel__initmemory was free'd, attempt to callhook_fault_code()from probe would lead to a crash.
Understood - I don't think there is a point though in keeping the builtin_platform_driver() call then, something like:
#ifdef CONFIG_ARM
...
static __init void init_platform_hook_fault(void) {
if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) {
#ifdef CONFIG_ARM_LPAE
hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
"asynchronous external abort");
#else
hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
"imprecise external abort");
#endif
}
}#else
static inline void init_platform_hook_fault(void)
{}
#endif
static int __init rcar_pcie_init(void)
{
init_platform_hook_fault();
return platform_driver_register(&rcar_pcie_driver);
}device_initcall(rcar_pcie_init);
Or we remove the __init marker from hook_fault_code().
Quoted 9 lines
Quoted 7 lines
Also, some of these platforms are SMP systems, I don't understand what prevents multiple cores to fault at once given that the faults can happen for config/io/mem accesses alike.
I understand that the immediate fix is for S2R, that is single threaded but I would like to understand how comprehensive this fix is.
Are you suggesting to add some sort of locking ?
If we merge a fix the fix has to work, by reading the code if multiple cores fault at once this fix seems to have an issue that's why I asked, you may still end up with an unhandled fault by reading the code.
Lorenzo
On 12/14/20 6:13 PM, Lorenzo Pieralisi wrote:
[...]
Quoted 37 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?
rcar_pcie_init()would not be called before probe.Sorry to be slow, but why does it need to be called before probe? Obviously software isn't putting the controller in D3 or enabling ASPM before probe.
Quoted 5 lines
Quoted 1 line
I don't understand it either so it would be good to clarify.
The
hook_fault_code()is marked__init, so ifprobe()was deferred and the kernel__initmemory was free'd, attempt to callhook_fault_code()from probe would lead to a crash.Understood - I don't think there is a point though in keeping the
builtin_platform_driver()call then, something like:#ifdef
CONFIG_ARM
...static __init void init_platform_hook_fault(void) { if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) { #ifdef CONFIG_ARM_LPAE hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0, "asynchronous external abort"); #else hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0, "imprecise external abort"); #endif } }#else
static inline voidinit_platform_hook_fault(void)
{}
#endif
Quoted 6 lines
static int
__initrcar_pcie_init(void){ init_platform_hook_fault(); return platform_driver_register(&rcar_pcie_driver); }
device_initcall(rcar_pcie_init);
Does this look simpler than the code in this patch ?
Quoted 1 line
Or we remove the
__initmarker fromhook_fault_code().
This is a bugfix, it should be possible to backport this through the stable tree easily, without changing core architecture code.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Also, some of these platforms are SMP systems, I don't understand what prevents multiple cores to fault at once given that the faults can happen for config/io/mem accesses alike.
I understand that the immediate fix is for S2R, that is single threaded but I would like to understand how comprehensive this fix is.
Quoted 5 lines
Quoted 1 line
Are you suggesting to add some sort of locking ?
If we merge a fix the fix has to work, by reading the code if multiple cores fault at once this fix seems to have an issue that's why I asked, you may still end up with an unhandled fault by reading the code.
So, are you suggesting the hook needs some locking ?
On 12/8/20 7:46 PM, Bjorn Helgaas wrote:
[...]
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
drivers/pci/controller/pcie-rcar-host.c +8
-0+static int __init rcar_pcie_init (void ) +{ +if (of_find_matching_node (NULL , rcar_pcie_abort_handler_of_match)) { +#ifdef CONFIG_ARM_LPAE +hook_fault_code (17 , rcar_pcie_aarch32_abort_handler,SIGBUS ,0 , +"asynchronous external abort" ); +#else + hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,drivers/pci/controller/pcie-rcar-host.c static struct platform_driver rcar_pcie_driver = { · line 1129
Quoted 10 lines
drivers/pci/controller/pcie-rcar-host.c +9
-0+ "imprecise external abort"); +#endif + } + +return platform_driver_register (&rcar_pcie_driver); +} +device_initcall (rcar_pcie_init); +#else builtin_platform_driver (rcar_pcie_driver); +#endif Is the
device_initcall()vsbuiltin_platform_driver()something related to thehook_fault_code()? What would break if this were alwaysbuiltin_platform_driver()?
Quoted 5 lines
Quoted 1 line
rcar_pcie_init()would not be called before probe.Sorry to be slow, but why does it need to be called before probe? Obviously software isn't putting the controller in D3 or enabling ASPM before probe.
The hook_fault_code() is marked __init, so if probe() was deferred and the kernel __init memory was free'd, attempt to call hook_fault_code() from probe would lead to a crash.
Quoted 4 lines · Marek Vasut
Quoted 2 lines · Bjorn Helgaas
Does this problem occur in both these cases?
Quoted 8 lines
Quoted 6 lines
1) When ASPM enters L1, and
2) When software writes
PCI_PM_CTRLto put the device in D3hot?IIUC both cases require the link to go to L1. I guess the same software workaround applies to both cases?
Yes
If ASPM puts the Link in L1 and the device needs to DMA, how does the Link get back to L0? Do we use the same data abort hook? If getting back to L0 requires help from software, it seems like that would invalidate the L1 exit latency advertised by the devices. Wouldn't that mean we couldn't safely enable L1 at all unless the endpoint could tolerate unlimited exit latency?
Bjorn
Quoted 9 lines · Bjorn Helgaas
Quoted 8 lines · Marek Vasut
Quoted 6 lines · Bjorn Helgaas
Does this problem occur in both these cases?
1) When ASPM enters L1, and
2) When software writes
PCI_PM_CTRLto put the device in D3hot?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
IIUC both cases require the link to go to L1. I guess the same software workaround applies to both cases?
Yes
If ASPM puts the Link in L1 and the device needs to DMA, how does the Link get back to L0?
It cannot, so I would expect the DMA access would fail.
Quoted 5 lines
Do we use the same data abort hook? If getting
back to L0 requires help from software, it seems like that would invalidate the L1 exit latency advertised by the devices. Wouldn't that mean we couldn't safely enable L1 at all unless the endpoint could tolerate unlimited exit latency?
Possibly, there could be limitations to the L1 support in some corner cases. Does that mean the L1 support should be disabled completely ?
Quoted 13 lines · Marek Vasut
Quoted 12 lines · Bjorn Helgaas
Quoted 11 lines · Marek Vasut
Quoted 8 lines · Bjorn Helgaas
Does this problem occur in both these cases?
1) When ASPM enters L1, and
2) When software writes
PCI_PM_CTRLto put the device in D3hot?IIUC both cases require the link to go to L1. I guess the same software workaround applies to both cases?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Yes
If ASPM puts the Link in L1 and the device needs to DMA, how does the Link get back to L0?
It cannot, so I would expect the DMA access would fail.
I think that means we cannot enable ASPM L1 at all on this device. I don't think devices or drivers are prepared to deal with this sort of DMA failure. At least, if there is a mechanism for dealing with it, I don't know what it is.
Preventing use of ASPM L1 probably means some sort of quirk to override whatever the controller advertises in its Link Capabilities register.
The software-controlled PCI-PM model (where software writes to the PCI_PM_CTRL register) is different, and it may still be possible to use L1 then. If software puts the device in D1, D2, or D3hot, the device cannot initiate DMA. If it needs to return to D0, it would have to use the PME mechanism, so there is an opportunity for the software workaround.
Quoted 8 lines
Quoted 5 lines
Do we use the same data abort hook? If getting
back to L0 requires help from software, it seems like that would invalidate the L1 exit latency advertised by the devices. Wouldn't that mean we couldn't safely enable L1 at all unless the endpoint could tolerate unlimited exit latency?Possibly, there could be limitations to the L1 support in some corner cases. Does that mean the L1 support should be disabled completely ?
The L1 exit latency only applies to the ASPM case. It sounds like we will have to disable L1 for ASPM. But the exit latency doesn't apply to the PCI-PM model where software will explicitly return the device to D0, and the device should not initiate a transaction until it sees the link back in L0.
Bjorn