From patchwork Tue Dec 4 13:27:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 10711753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 112E614BD for ; Tue, 4 Dec 2018 13:28:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1C7629E06 for ; Tue, 4 Dec 2018 13:27:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFD1E2AA55; Tue, 4 Dec 2018 13:27:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7127629E06 for ; Tue, 4 Dec 2018 13:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=5vF2iYK/tei3m0DnbZy9vdyI5omyWOV6G6yljvsdZe0=; b=APlfUtWY0nLE6Q QJD6uYJuQcZhWotK+FpX/QurV7cW1RR3jwEhCuE/6xbKy9SYvDkkBTLC35hUlEjEWBGGkuCaJDPOX njVB1+zLsvHura71ocPaTsOisN00VQzhIs3r235dYzbI3FEuDjda520aivgpWk4zjP+RqoEjOGAg8 xr3+XA1dTmuvIvt2r7usp0TuO2CSBg3qCCeZKUvhqTAz2zkLfKa6VMyvFs8ixU3nuRzavK5MBPwVm RuueR3+hPc0RkWj0W4AFtHgrbaVVWf37K/ZTt90dVW/pgOGmWku9uIwCdN25awgSbyfPk375OPlzH 5Z0iEfw8aw8Fss70tDmA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUAjz-0006Rp-89; Tue, 04 Dec 2018 13:27:55 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUAjw-0006Po-0v for linux-arm-kernel@lists.infradead.org; Tue, 04 Dec 2018 13:27:53 +0000 Received: from trochilidae.toradex.int (unknown [46.140.72.82]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 841245C03A3; Tue, 4 Dec 2018 14:27:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1543930056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=l/NqMlMJK6NCuID2vd75UkjcijsChz0PXtxpAkinb6A=; b=Z3VQ61CdqWFgxFzEkOjzTmIHpJ5Jv61kLXyp523WCTiAT2fVLCgnemUzqQIYMSf+Amqhfy 7wEWsStTzS9y4ABLxwtVEPxzx8FobRfn6j0WjCGSbwERljOgkaPhpkmtMJMzBQeRmP3o2Z 4QT3l+tHjscUfGZwK35zGspSrtLyZRE= From: Stefan Agner To: hongxing.zhu@nxp.com, l.stach@pengutronix.de Subject: [PATCH v2 1/2] pci: imx6: avoid dereferencing program counter from user mode Date: Tue, 4 Dec 2018 14:27:32 +0100 Message-Id: <20181204132733.14422-1-stefan@agner.ch> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181204_052752_216999_BB4461BD X-CRM114-Status: GOOD ( 13.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, andrew.smirnov@gmail.com, robin.murphy@arm.com, linux@armlinux.org.uk, stefan@agner.ch, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com, leonard.crestez@nxp.com, festevam@gmail.com, linux-arm-kernel@lists.infradead.org, tpiepho@impinj.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The custom fault handler is currently only meant to handle kernel mode bus faults. Exit in case the abort happened in user mode. Signed-off-by: Stefan Agner Reviewed-by: Lucas Stach --- drivers/pci/controller/dwc/pci-imx6.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 69f86234f7c0..54a29e441303 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -270,8 +270,14 @@ static int imx6q_pcie_abort_handler(unsigned long addr, unsigned int fsr, struct pt_regs *regs) { unsigned long pc = instruction_pointer(regs); - unsigned long instr = *(unsigned long *)pc; - int reg = (instr >> 12) & 15; + unsigned long instr; + int reg; + + if (user_mode(regs)) + return 1; + + instr = *(unsigned long *)pc; + reg = (instr >> 12) & 15; /* * If the instruction being executed was a read, From patchwork Tue Dec 4 13:27:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 10711755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87C0616B1 for ; Tue, 4 Dec 2018 13:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7734529E06 for ; Tue, 4 Dec 2018 13:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A47D2AA55; Tue, 4 Dec 2018 13:28:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 144DF29E06 for ; Tue, 4 Dec 2018 13:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wXJ9XROemhTX8tpfRFPtOGZ37OjJndszTZl6QsVOm8I=; b=YtbiyaA2V7Bm5H gks3JHVtfeBKmoZ+cmMLYUc1UFdyY8aDsZ9zT4Vx/CnTnS95Ab/n07GinvfDiTAzK+NxZOi9YPSOq eM50rQBopgPicAXjtk3PjlMYPOsK3sDcA1X0a8+YMnDjfb5G98+JD4YVra3AGOaYX3/DxDI5jFbZ+ Bjq5CSk+Ti6HxcNgFIWpX9audvBkqvOIHsehASRcjE4WNcfSptySQ0VmCA7gQLqrt4YyrkgOIZBzp YTBQHjqayHr6Kasxcu1CZc64jYnmZi2iNCFjTL28Il2S00Mu9fWyfabjEAZqrZQxkjpwFuFeryisZ gvUk8ABWM8FnKpqDtzIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUAk7-0006Zq-79; Tue, 04 Dec 2018 13:28:03 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUAjw-0006Pn-0u for linux-arm-kernel@lists.infradead.org; Tue, 04 Dec 2018 13:27:54 +0000 Received: from trochilidae.toradex.int (unknown [46.140.72.82]) by mail.kmu-office.ch (Postfix) with ESMTPSA id D19835C07AA; Tue, 4 Dec 2018 14:27:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1543930057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FZDGS75OY2CnEYwbJ8d7y7z0pz7Qa2SwVyeltfytdi8=; b=Ci0lrkr4aqCtef7L1CtxiosDjlYrUy0H51byEx/rOkxq1VwGHJ6bzhKWtOzUTXy6yHErtJ 80oh/dKBlJ6xJJmX34bD3C7z4ygG3saA5susUUjyTF+KEks0lTDPWpjTUiX+NVeMXG7GtL tRVfNilHAztXOFC4ljlYOLjroUnzLbg= From: Stefan Agner To: hongxing.zhu@nxp.com, l.stach@pengutronix.de Subject: [PATCH v2 2/2] pci: imx6: support kernels built in Thumb-2 mode Date: Tue, 4 Dec 2018 14:27:33 +0100 Message-Id: <20181204132733.14422-2-stefan@agner.ch> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181204132733.14422-1-stefan@agner.ch> References: <20181204132733.14422-1-stefan@agner.ch> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181204_052752_549427_1932373C X-CRM114-Status: GOOD ( 16.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, andrew.smirnov@gmail.com, robin.murphy@arm.com, linux@armlinux.org.uk, stefan@agner.ch, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com, leonard.crestez@nxp.com, festevam@gmail.com, linux-arm-kernel@lists.infradead.org, tpiepho@impinj.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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);