From: Bjorn Helgaas <helgaas@kernel.org>
To: marek.vasut@gmail.com
Cc: linux-pci@vger.kernel.org,
"Marek Vasut" <marek.vasut+renesas@gmail.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Wolfram Sang" <wsa@the-dreams.de>,
"Yoshihiro Shimoda" <yoshihiro.shimoda.uh@renesas.com>,
linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v3 2/2] PCI: rcar: Return all Fs from read which triggered an exception
Date: Sun, 23 Jan 2022 09:39:49 -0600 [thread overview]
Message-ID: <20220123153949.GA1458406@bhelgaas> (raw)
In-Reply-To: <20220122221554.196311-2-marek.vasut@gmail.com>
On Sat, Jan 22, 2022 at 11:15:54PM +0100, marek.vasut@gmail.com wrote:
> From: Marek Vasut <marek.vasut+renesas@gmail.com>
>
> In case the controller is transitioning to L1 in rcar_pcie_config_access(),
> any read/write access to PCIECDR triggers asynchronous external abort. This
> is because the transition to L1 link state must be manually finished by the
> driver. The PCIe IP can transition back from L1 state to L0 on its own.
>
> The current asynchronous external abort hook implementation restarts
> the instruction which finally triggered the fault, which can be a
> different instruction than the read/write instruction which started
> the faulting access. Usually the instruction which finally triggers
> the fault is one which has some data dependency on the result of the
> read/write. In case of read, the read value after fixup is undefined,
> while a read value of faulting read should be all Fs.
>
> It is possible to enforce the fault using 'isb' instruction placed
> right after the read/write instruction which started the faulting
> access. Add custom register accessors which perform the read/write
> followed immediately by 'isb'.
>
> This way, the fault always happens on the 'isb' and in case of read,
> which is located one instruction before the 'isb', it is now possible
> to fix up the return value of the read in the asynchronous external
> abort hook and make that read return all Fs.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Krzysztof Wilczyński <kw@linux.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Cc: linux-renesas-soc@vger.kernel.org
> ---
> V2: Rebase on 1/2
> V3: - Add .text.fixup on all three ldr/str/isb instructions and call
> fixup_exception() in the abort handler to trigger the fixup.
> - Propagate return value from read/write accessors, in case the
> access fails, return PCIBIOS_SET_FAILED, else PCIBIOS_SUCCESSFUL.
> ---
> drivers/pci/controller/pcie-rcar-host.c | 53 +++++++++++++++++++++++--
> 1 file changed, 49 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/controller/pcie-rcar-host.c b/drivers/pci/controller/pcie-rcar-host.c
> index 7d38a9c50093..b2e521ee95eb 100644
> --- a/drivers/pci/controller/pcie-rcar-host.c
> +++ b/drivers/pci/controller/pcie-rcar-host.c
> @@ -114,6 +114,51 @@ static u32 rcar_read_conf(struct rcar_pcie *pcie, int where)
> return val >> shift;
> }
>
> +#ifdef CONFIG_ARM
> +#define __rcar_pci_rw_reg_workaround(instr) \
> + "1: " instr " %1, [%2]\n" \
> + "2: isb\n" \
> + "3: .pushsection .text.fixup,\"ax\"\n" \
> + " .align 2\n" \
> + "4: mov %0, #" __stringify(PCIBIOS_SET_FAILED) "\n" \
> + " b 3b\n" \
> + " .popsection\n" \
> + " .pushsection __ex_table,\"a\"\n" \
> + " .align 3\n" \
> + " .long 1b, 4b\n" \
> + " .long 1b, 4b\n" \
> + " .popsection\n"
> +#endif
> +
> +int rcar_pci_write_reg_workaround(struct rcar_pcie *pcie, u32 val, unsigned int reg)
> +{
> + int error = PCIBIOS_SUCCESSFUL;
> +#ifdef CONFIG_ARM
> + asm volatile(
> + __rcar_pci_rw_reg_workaround("str")
> + : "+r"(error):"r"(val), "r"(pcie->base + reg) : "memory");
> +#else
> + rcar_pci_write_reg(pcie, val, reg);
> +#endif
> + return error;
> +}
> +
> +int rcar_pci_read_reg_workaround(struct rcar_pcie *pcie, u32 *val, unsigned int reg)
> +{
> + int error = PCIBIOS_SUCCESSFUL;
> +#ifdef CONFIG_ARM
> + asm volatile(
> + __rcar_pci_rw_reg_workaround("ldr")
> + : "+r"(error), "=r"(*val) : "r"(pcie->base + reg) : "memory");
> +
> + if (error != PCIBIOS_SUCCESSFUL)
> + *val = 0xffffffff;
PCI_SET_ERROR_RESPONSE()?
Maybe also use PCI_ERROR_RESPONSE in the subject and commit log
instead of "all Fs" to make it more greppable.
> +#else
> + *val = rcar_pci_read_reg(pcie, reg);
> +#endif
> + return error;
> +}
> +
> /* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
> static int rcar_pcie_config_access(struct rcar_pcie_host *host,
> unsigned char access_type, struct pci_bus *bus,
> @@ -185,14 +230,14 @@ static int rcar_pcie_config_access(struct rcar_pcie_host *host,
> return PCIBIOS_DEVICE_NOT_FOUND;
>
> if (access_type == RCAR_PCI_ACCESS_READ)
> - *data = rcar_pci_read_reg(pcie, PCIECDR);
> + ret = rcar_pci_read_reg_workaround(pcie, data, PCIECDR);
> else
> - rcar_pci_write_reg(pcie, *data, PCIECDR);
> + ret = rcar_pci_write_reg_workaround(pcie, *data, PCIECDR);
>
> /* Disable the configuration access */
> rcar_pci_write_reg(pcie, 0, PCIECCTLR);
>
> - return PCIBIOS_SUCCESSFUL;
> + return ret;
> }
>
> static int rcar_pcie_read_conf(struct pci_bus *bus, unsigned int devfn,
> @@ -1097,7 +1142,7 @@ static struct platform_driver rcar_pcie_driver = {
> static int rcar_pcie_aarch32_abort_handler(unsigned long addr,
> unsigned int fsr, struct pt_regs *regs)
> {
> - return !!rcar_pcie_wakeup(pcie_dev, pcie_base);
> + return !fixup_exception(regs);
> }
>
> static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst = {
> --
> 2.34.1
>
next prev parent reply other threads:[~2022-01-23 15:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-22 22:15 [PATCH v3 1/2] PCI: rcar: Finish transition to L1 state in rcar_pcie_config_access() marek.vasut
2022-01-22 22:15 ` [PATCH v3 2/2] PCI: rcar: Return all Fs from read which triggered an exception marek.vasut
2022-01-23 14:12 ` Arnd Bergmann
2022-01-23 16:02 ` Marek Vasut
2022-01-23 15:31 ` Pali Rohár
2022-01-23 16:31 ` Marek Vasut
2022-01-23 16:49 ` Pali Rohár
2022-01-24 5:46 ` Marek Vasut
2022-01-24 9:37 ` Pali Rohár
2022-01-29 4:39 ` Marek Vasut
2022-01-31 12:53 ` Pali Rohár
2022-02-17 11:29 ` Pali Rohár
2022-02-17 12:59 ` Marek Vasut
2022-02-17 13:04 ` Pali Rohár
2022-02-18 1:53 ` Marek Vasut
2022-02-18 16:17 ` Pali Rohár
2022-01-23 15:39 ` Bjorn Helgaas [this message]
2022-01-28 2:47 ` kernel test robot
2022-02-16 11:50 ` Pali Rohár
2022-02-17 3:24 ` Marek Vasut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220123153949.GA1458406@bhelgaas \
--to=helgaas@kernel.org \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=geert+renesas@glider.be \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=marek.vasut+renesas@gmail.com \
--cc=marek.vasut@gmail.com \
--cc=wsa@the-dreams.de \
--cc=yoshihiro.shimoda.uh@renesas.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).