From patchwork Mon Jan 31 07:52:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francesco Dolcini X-Patchwork-Id: 12730460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 294D9C433F5 for ; Mon, 31 Jan 2022 07:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=bGT4APtAOkphLK8EqiKAIyXbxDjXtK9lv3IT9hktmbI=; b=cEAo3hvQ1rPWry 7nkNbLNvvc5VSiXx0MxXfjDzYl58jFsWGumxnJrex/1yo9BLXOf2Mu2q57wEHmZseL+qHTU1lxPbE CdzDg/OZ03Q6ztV6Je+gz0joD5EcOt2uO4TpmQTgzEbQKXW+OiQzgra7apxWJ0TG8/OIHEqa/AZO3 c3BauER27TS9cy2T7r83yUwfLjkS/rZ/nk7w3uBzTnHmD2d7kjCphdG96OaomgxMP0e7ELZjGS6Oa oDKdyjwApBHWc+ARQlgc1T2ZCvvkjGRbM17/yt+gP272BTgIlJwy1fk3tP1hX/KdAx9Nrmt7c4zu2 WB8hehuziWdapeEz1eiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nERUe-008Kg1-Do; Mon, 31 Jan 2022 07:52:57 +0000 Received: from mail-gv0che01on20724.outbound.protection.outlook.com ([2a01:111:f403:4012::724] helo=CHE01-GV0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nERUa-008KeE-59 for linux-arm-kernel@lists.infradead.org; Mon, 31 Jan 2022 07:52:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U8Mqip1x1N3ubbpUmFa3nmZ/KVElT/2lbgYcwnPrpqvsrOchMjZX4D0F5Pi5N4iEtZ3h+vmDq99/4KJ5BsiS18BneakewsExR1lgF0IrmCN6lT9utmykDYizCotwJ6yI4OMGJUajZTYT0fQvaRH2aiI4JLWVvwGl3EJ+XkRC/0TDVMiORfhIPFldxFaVl7ce8A5Cfcajyofupf4ElgO45nDwzmCvOVPEQAgTQqW/msim7NZLqmUsBxHOYzuYReDO1FPv+SrYTeWlGNAbiVSOPwQ1zG8AQ0eWU+VrVnvEziMD7iE5GPJ2qdjMVCi0buCeBmkeF2jJoBcBxWQlAAdZDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fDwr7HV6KU5Vv6PWjmcMfB64UaBmg7KXWt6gaVkEIL0=; b=CxMvUYGIPLkK3O1O7OMDN33A/GGDgh3p9nJGaKPZ+5cMG8KALwZiHe2SezbGsFNkya0ts6O+enoexeAyTeUn/JPaFSp7QfCR7hATvYShEvbzwROErgnVRfK0W2LyNwIFtEU2VVU7nJMpgO2wxloV8DNyBCfK9lrWhDkx1nCWoY+RdsHr32qm18xm91WqggAsBr8l5QqGdqD6wfWzX0rVsx40YoOV0ysMm/U10u3x6PLcv8niHHz0WHlgeNvXJXgRcWjr5OuHhAwTWcypJFK45onSz6jZWY9e9AQOhi6OCLhN+2nZXlqcB1+jU9wMZNh4e1Zm0tRUF/+aLoy1rNE8yA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toradex.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fDwr7HV6KU5Vv6PWjmcMfB64UaBmg7KXWt6gaVkEIL0=; b=cuhCzas4uCdt3Ei4/SpBbqVgwhlrtvQvg6GZ/t1U9U01GdoqK9lEwDiU8S/wBp4HYlmMdbxKgFqqmGXwCjPOYRNFrjdVkwtWHuWXGcQ4bMGlkBICcVl4ljIz/OGjs1CFEQZEVNRsbHgVeE7X/W9TNoi8V10bwfqRYh2I5mXzijA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=toradex.com; Received: from ZRAP278MB0642.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:3d::11) by GV0P278MB0436.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:2e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Mon, 31 Jan 2022 07:52:42 +0000 Received: from ZRAP278MB0642.CHEP278.PROD.OUTLOOK.COM ([fe80::fc21:519b:ba18:7676]) by ZRAP278MB0642.CHEP278.PROD.OUTLOOK.COM ([fe80::fc21:519b:ba18:7676%3]) with mapi id 15.20.4930.021; Mon, 31 Jan 2022 07:52:42 +0000 From: Francesco Dolcini To: Richard Zhu , Lucas Stach , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Jason Liu Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , Shawn Guo , Francesco Dolcini Subject: [PATCH v1] PCI: imx6: Handle the abort from user-space Date: Mon, 31 Jan 2022 08:52:35 +0100 Message-Id: <20220131075235.787432-1-francesco.dolcini@toradex.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: GVAP278CA0005.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:20::15) To ZRAP278MB0642.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:3d::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 45b91400-514d-4bf5-52c5-08d9e48ea8da X-MS-TrafficTypeDiagnostic: GV0P278MB0436:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k+eV9lj3ihEB3F38S4Hq41vLchyReyvEZchn69vUXHWwgGB397jzBrg1HRYlVEWDa8lIVW4XiWnI6w/4dvkiFfRvWqF+NiYyE66xcnVTFjIEcbsZvPkiPiTXIOPNFAFKauEL/CX3eImwlJHiqgnns1b8PNyk6ZMrfXP22CaIEEuysP2ePlfcohTnTUGyK0q8wgzOND0ePG1xRsw7JMiORUZEa5E67r4xyLeIvEleCdEIJFj+umRLavPzZrtwaJfMSvYiBVC+ml77w1u1808GobczAw9dRawXT2x60ZODuUGiHuqbdw+AiJT72V745yW0moZNXAKQF3JvPVapERovrVbSmvBO6fEZeFrdKuEj39TfiwoxgBhlQw8G4J5qBEg66Dj8SU1nmW5YipIyxhqmInz/adwhYR+KgKZ7qvmfLbCj2p+lXJe0ad/p/me9B7RbayDM/BWjqHt216eTSOtKFZNlDl7CxjXw4Ur5y5a9sprBeuNNgPHDAbMA9RJKWNrlu+9E5pFKHNRhkSuQNz0kSth+deF7TJdcA082OFO1U5Q/Av3fSOMKtjKDchYQ6j7GyaetvfejOVb5jJ4F9zu5WWCuzZRZHM+3QHcr+SpV6u1HpC5rIqGZ9aMJBJ5p0Yc0PeQW9dw7SkpOIGL0ioPEXsZPCjgd10VABei4jkGiDhIBcZz7yVsa5F1paAKi279Zr+gDZBU1WRMSBkhbkLgRNAEebYMNA6C3KzUYaXGrf+5LtYNU5UeCnqcwisznNwPwSd6peDNqZmXpLwhrQfdBU/Mip9xHTtKMUO4IXBSHynQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:ZRAP278MB0642.CHEP278.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230001)(4636009)(346002)(376002)(39840400004)(396003)(136003)(366004)(110136005)(966005)(83380400001)(6486002)(38350700002)(8936002)(36756003)(52116002)(508600001)(66556008)(66476007)(316002)(4326008)(54906003)(66946007)(8676002)(6512007)(921005)(38100700002)(86362001)(44832011)(107886003)(6666004)(26005)(186003)(1076003)(6506007)(7416002)(2616005)(2906002)(5660300002)(20210929001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: q5xudGt88kvPOnDKUjAU4Uv7ImGpJfI47K0HqsFa3mMf8C7V4YrW9SNFGIDhkCgkr9/oWFZDfLmrIj9Qp6DMqjFiGQcRJiQWBl1uWFn6SmdTFuRFGVgp5pfiIbcVJveZ1GzPw49vK8aXStDSkQlokRFImLWcFCEwhM+zPgfU6g5vJoHIxyUEI8b6Gtn1Hw0gpQi2+F5tDMVJBcHRE8prX/pG8hgbq1sc5AK/omzaQtR6IYx8blrWIFJHGMdR/ZrRH5zbwp+28cSdHolMRX/h8HeqEijBLYws/l+wv1G1mkHCCbB1ySUSOkKieV3r1I97bwYfZ8ZY1y1WQkpSbU5eHb5PIu0wT5Rwz+TMevnzI45FLd1ZYeKj3E5WOkOglOOyG2pP7Xi+2NXpvs352gSLAh7ew13qksVJYnRstRA2k7KeT5EXl7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3uiVBMo7VfZhrv+yxYw4X4/VyTn2ITaN2fpnQrZ2khdqga1asTFVSj38hQmlQBO7n8UFpgFOMZ5GDL2yO+VE2WayDa/Dsg0V/uka64Uq5HIt7lbKL/Y7R3Geze4wenBcDELO2erGy19OzfwlRCOhw3aKveD6enAFthz8Khh2Blaknb6rdTxFqGA== X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45b91400-514d-4bf5-52c5-08d9e48ea8da X-MS-Exchange-CrossTenant-AuthSource: ZRAP278MB0642.CHEP278.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2022 07:52:41.9786 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d9995866-0d9b-4251-8315-093f062abab4 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z0kjJUElJKCLduNDKJ/L4nWlxOJjv8p9D6r+pDlTHOALjukD2ixXkTXnG9HIuMVWSJIgGWqCx3qJzDYbD6OEMkoMnD51HwQBqqYt0LZgV9c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV0P278MB0436 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220130_235252_273202_54788302 X-CRM114-Status: GOOD ( 14.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jason Liu The driver install one hook to handle the external abort, but issue is that if the abort introduced from user space code, the following code unsigned long instr = *(unsigned long *)pc; which will created another data-abort(page domain fault) if CONFIG_CPU_SW_DOMAIN_PAN. The patch does not intent to use copy_from_user and then do the hack due to the security consideration. In fact, we can just return and report the external abort to user-space. Link: https://lore.kernel.org/all/20220128082920.591115-1-francesco.dolcini@toradex.com Signed-off-by: Jason Liu Reviewed-by: Richard Zhu Signed-off-by: Francesco Dolcini Acked-by: Lucas Stach --- rfc -> v1: * added Acked-by Lucas Stach * include correct header for user_mode() --- drivers/pci/controller/dwc/pci-imx6.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 6974bd5aa116..c47a05332a94 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -297,8 +298,15 @@ 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 the abort from user-space, just return and report it */ + if (user_mode(regs)) + return 1; + + instr = *(unsigned long *)pc; + reg = (instr >> 12) & 15; /* * If the instruction being executed was a read,