Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3024072imj; Mon, 11 Feb 2019 12:29:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IYkENXTnn4DG3moGYBveAYcVwxVwVLCDbQQqRuGvV9zTuCPzuODbuKS7EiZKwQozGd6ixeE X-Received: by 2002:a63:9751:: with SMTP id d17mr57574pgo.392.1549916968634; Mon, 11 Feb 2019 12:29:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549916968; cv=none; d=google.com; s=arc-20160816; b=jJwc6kVoqp4is+STM9xSV5TV3URV7e6la3kYWZJAvCz6ldtPY+4+p63xHnCDTtmmU4 sbxPn3bEnZhlklTN3rP6p8k0fLbBVRKQ6EYGRmBtDrWkh9kASWVI3w1WNwuxWx4N8cLy XgtXEiW3xnJcP0v9h0hm7mORCD+O/PdTVuRTQcZD75X3Ea9/JLAPtxn551nS4e7QX9CK 9ZOqoheUbnLA4oVCgXhgyEmI87ZqrNSdbfIRynPHEu5o+BEa+GMnJgxuITqATmhrD1b9 gTLR0NzuPaKRL1wxlL4eIIhj3qlrp6ubL2fSD0wruPKOGBNtyeuXa5rHfDKaz9vOnZZ5 ZXsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=T7yPkggHpam8nIuJNBLD7lJXRy9wBPC9D0JXLPbpxuE=; b=liFxWEOWkfiFBnqi4rQYJs48aJg5VcOE+/SBjcR2EYL7T3WjYtEZnqPL5EY0YuP2Z+ I/vKWnUvpMkRbEGWueFx+cXX+rKfn+9Fx0t7CWlfzdykE7Oron5Sn/YTkMZ5GpSDYUYT EZekcYaV1XAZiZFoLNckeEAE/ENKidHTT1J+bL/3GEA2lsGeM3FckPBVsmon+sHPaDZC 3jyiCLFRcI3UcVyGNfZ9DV0ZoBPzO726EHnTj9GsL6/upH+uAFSjahatPu3wW04Ctq6H dA3rrk1bkG7fDrD0zfJanp7Dn3gqbHuRa1zjB0BGZseeDnWIDMbRbmFe/wA1XBVjOMp6 x9SQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b61si11443951plb.70.2019.02.11.12.29.13; Mon, 11 Feb 2019 12:29:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728272AbfBKQ6C (ORCPT + 99 others); Mon, 11 Feb 2019 11:58:02 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:47291 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbfBKQ6C (ORCPT ); Mon, 11 Feb 2019 11:58:02 -0500 Received: from kresse.hi.pengutronix.de ([2001:67c:670:100:1d::2a]) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1gtEu1-0001Y3-N8; Mon, 11 Feb 2019 17:57:53 +0100 Message-ID: <1549904273.2546.16.camel@pengutronix.de> Subject: Re: [PATCH v2 2/2] pci: imx6: support kernels built in Thumb-2 mode From: Lucas Stach To: Stefan Agner , hongxing.zhu@nxp.com Cc: robin.murphy@arm.com, tpiepho@impinj.com, linux@armlinux.org.uk, leonard.crestez@nxp.com, andrew.smirnov@gmail.com, festevam@gmail.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Mon, 11 Feb 2019 17:57:53 +0100 In-Reply-To: <20181204132733.14422-2-stefan@agner.ch> References: <20181204132733.14422-1-stefan@agner.ch> <20181204132733.14422-2-stefan@agner.ch> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::2a X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Dienstag, den 04.12.2018, 14:27 +0100 schrieb Stefan Agner: > Add a fault handler which handles immediate reads in Thumb-2 > mode. Install the appropriate handler depending on which mode > the kernel has been built. This avoids an "Unhandled fault: > external abort on non-linefetch (0x1008) at 0xf0a80000" > during boot on a device with a PCIe switch connected. > > Link: https://lore.kernel.org/linux-pci/20181126161645.8177-1-stefan@agner.ch/ > Signed-off-by: Stefan Agner Acked-by: Lucas Stach > --- > Changes since v1: > - Added Thumb-2 32-bit instruction support (tested by inserting .w >   instructions in arch/arm/include/asm/io.h) > - Avoid dereferencing if fault happened in user mode > >  drivers/pci/controller/dwc/pci-imx6.c | 59 ++++++++++++++++++++++++++- >  1 file changed, 58 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 54a29e441303..a9bbbf176c4a 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -29,6 +29,7 @@ >  #include >  #include >  #include > +#include >   >  #include "pcie-designware.h" >   > @@ -305,6 +306,59 @@ static int imx6q_pcie_abort_handler(unsigned long addr, >   return 1; >  } >   > +static int imx6q_pcie_abort_handler_thumb2(unsigned long addr, > + unsigned int fsr, struct pt_regs *regs) > +{ > + unsigned long pc = instruction_pointer(regs); > + unsigned long instr; > + > + if (user_mode(regs)) > + return 1; > + > + instr = __mem_to_opcode_thumb32(*(unsigned long *)pc); > + > + if (__opcode_is_thumb32(instr)) { > + /* Load word/byte and halfword immediate offset */ > + if ((instr & 0xff100000UL) == 0xf8100000UL) { > + int reg = (instr >> 12) & 0xf; > + unsigned long val; > + > + if ((instr & 0x00700000UL) == 0x00100000UL) > + val = 0xff; > + else if ((instr & 0x00700000UL) == 0x00300000UL) > + val = 0xffff; > + else > + val = 0xffffffffUL; > + > + regs->uregs[reg] = val; > + regs->ARM_pc += 4; > + return 0; > + } > + } else { > + instr = __mem_to_opcode_thumb16(*(unsigned long *)pc); > + > + /* Load word/byte and halfword immediate offset */ > + if (((instr & 0xe800) == 0x6800) || > +     ((instr & 0xf800) == 0x8800)) { > + int reg = instr & 0x7; > + unsigned long val; > + > + if (instr & 0x1000) > + val = 0xff; > + else if (instr & 0x8000) > + val = 0xffff; > + else > + val = 0xffffffffUL; > + > + regs->uregs[reg] = val; > + regs->ARM_pc += 2; > + return 0; > + } > + } > + > + return 1; > +} > + >  static int imx6_pcie_attach_pd(struct device *dev) >  { >   struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); > @@ -1075,6 +1129,8 @@ static struct platform_driver imx6_pcie_driver = { >   >  static int __init imx6_pcie_init(void) >  { > + bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL); > + >   /* >    * Since probe() can be deferred we need to make sure that >    * hook_fault_code is not called after __init memory is freed > @@ -1082,7 +1138,8 @@ static int __init imx6_pcie_init(void) >    * we can install the handler here without risking it >    * accessing some uninitialized driver state. >    */ > - hook_fault_code(8, imx6q_pcie_abort_handler, SIGBUS, 0, > + hook_fault_code(8, thumb2 ? imx6q_pcie_abort_handler_thumb2 : > + imx6q_pcie_abort_handler, SIGBUS, 0, >   "external abort on non-linefetch"); >   >   return platform_driver_register(&imx6_pcie_driver);