From patchwork Thu Apr 4 15:59:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 10885863 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 08A16922 for ; Thu, 4 Apr 2019 16:00:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0BF828AF3 for ; Thu, 4 Apr 2019 16:00:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D450B28AF5; Thu, 4 Apr 2019 16:00:34 +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 6720A28AF8 for ; Thu, 4 Apr 2019 16:00:34 +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=QtlRHZJiOHecYTvbyEkaK0gAXFPCgY0NhBXkT9HSg2o=; b=tGgcNuP5Vbqq+y P1+Yjdr2gnOVWLbLLFusWQVzb++9t4gTDzA243vHF+ZWpaPvuI1YSWCaL6bxW5UgNrJeYjlWp/6hy bgyPsGTXDMgCVqH7gVIMchuSkt/YR9dSTC+wol30ZArNt4NWPv4JxK+IS4eQgbB1rSnTTtknXjdtI tSGB5hXVoidufx6age1CjOB9XdK+X1vWK0AtWV65gnBwTXGmodJDDbrxpeDimh0XViRn7ySIpWzLM TldlviFCPWXVABhs5xEzOMOJvrjovKBM+isGjOhIBXJob0S/VwpmFIrRnh5U/siJF8ns9PAiLCgBH tNp8Aoq0c1ZQapGegYRg==; 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 1hC4n2-0003YE-Sh; Thu, 04 Apr 2019 16:00:32 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hC4mz-0003Wd-SY for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 16:00:31 +0000 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D3E89F261A06665AAF7B; Fri, 5 Apr 2019 00:00:23 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Fri, 5 Apr 2019 00:00:17 +0800 From: John Garry To: , , , Subject: [PATCH v3 0/4] Fix system crash for accessing unmapped IO port regions Date: Thu, 4 Apr 2019 23:59:58 +0800 Message-ID: <1554393602-152448-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_090030_092257_5D27FFA8 X-CRM114-Status: GOOD ( 12.47 ) 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: wangkefeng.wang@huawei.com, linux-pci@vger.kernel.org, John Garry , will.deacon@arm.com, linux-kernel@vger.kernel.org, linuxarm@huawei.com, andy.shevchenko@gmail.com, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, bp@suse.de, linux@roeck-us.net 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 It was reported some time ago that arm64 systems will crash if a driver attempts to access IO port addresses when the PCI IO port region has not been mapped [1]. More recently, a similar crash is where the system PCI host probe fails, and the IPMI driver crashes the system while attempting to do some IO port accesses [2]. This patchset attempts to keep the kernel alive in such situations by 2 complementary methods: 1. Rejecting IO port resource requests until PCI IO port regions have been mapped (in a pci_remap_iospace() call). 2. Rejecting logic PIO access to PCI IO regions until, again, PCI IO port regions have been mapped About 1: Currently the PCI IO port region is initialized to the full range, {0, IO_SPACE_LIMIT}. As such, any IO port region requests would not fail because of PCI IO port regions not being mapped. Patch 1/4 looks to remedy this issue by ensuring IO port requests are made to direct children of ioport_resource (PCI host IO port regions), similar to Arnd's solution, mentioned in [1]: "I see that ioport_resource gets initialized to the {0, IO_SPACE_LIMIT} range. If we could change it so that pci_remap_iospace() hooks up to ioport_resource and extends it whenever something gets mapped there up to IO_SPACE_LIMIT, we can change the default range to {0,0}, which would fail for any request_region call before the first pci_remap_iospace." I didn't use this solution, as logical PIO space is sparse in {0, IO_SPACE_LIMIT}, so we cannot simply grow the region. *As discussed with Bjorn in v2 series, we doubt that this approach is sound, as legacy ISA devices do not necessarily reply on PCI.* However I will keep the patch in the series as a reference and as a topic of debate. It's also an RFC as the implementation solution is not idea. About 2: Some drivers - like f71805f hwmon driver - do not call request_{muxed_}region() prior to accessing IO port regions, as they should do. So patches 2-3/4 adds a safeguard against this, in that unwarranted PIO IO accesses will be discarded in the low-level accessors. About the issue of f71805f driver not requesting the IO port region - many drivers do this, and need to be fixed up separately. 1. https://lore.kernel.org/linux-pci/56F209A9.4040304@huawei.com 2. https://lore.kernel.org/linux-arm-kernel/e6995b4a-184a-d8d4-f4d4-9ce75d8f47c0@huawei.com/ Differences to v2 patchset: https://lkml.org/lkml/2019/3/20/788 - Add a patch to use logical PIO accessors for !CONFIG_INDIRECT_PIO - Some tidy-up according to Andy's review Differences to v1 patchset: https://lkml.org/lkml/2019/3/14/630 - Drop f71805f fix - it can be done in a separate patchset - Change implementation in resource.c patch to check if parent of region is ioport_resource - Add patch to fix some logic_pio.c prints John Garry (4): resource: Request IO port regions from children of ioport_resource lib: logic_pio: Use logical PIO low-level accessors for !CONFIG_INDIRECT_PIO lib: logic_pio: Reject accesses to unregistered CPU MMIO regions lib: logic_pio: Fix up some prints include/linux/ioport.h | 11 ++- include/linux/logic_pio.h | 7 +- kernel/resource.c | 28 +++++++ lib/logic_pio.c | 157 +++++++++++++++++++++++++++++--------- 4 files changed, 159 insertions(+), 44 deletions(-)