Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3893080pxb; Tue, 26 Jan 2021 07:21:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNaslatcDY9n4aCwKXAAwdmOVHmGpOqJPTPrT+waTl/szW6f8GX21zTO6fqeOjLKe2oaz8 X-Received: by 2002:a17:907:3f9e:: with SMTP id hr30mr3702644ejc.445.1611674487293; Tue, 26 Jan 2021 07:21:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611674487; cv=none; d=google.com; s=arc-20160816; b=HYKqEoD2Wh6HJvsxnKD026Lx4sBfC9P79riJBB+0IGUsM14awW90O7/OP1fjmQSN4Q tD1em0nhHqla/tDrGDWwa/7C3O1bsjM8a+oaaRbLDWrNJwnss7jHOuAqzM0o2GKejnyy 4Jh34OERRJmzWXMwNXc+ExZZSa9r8HkRbF6dpJzc0C4gc50J/ATqU6kD57ASJpigk2eH samHLZRtws1MS+VhZFvydrJhDM3yyiuvdoTqo2Ryu5blA0FyFSyCAcDpEy3FDQmG80fN HUoFLGUa7/3Nn4fmMklJDOvrQ6TxL0eC1+yFetNG3w+W9dnlZ7nmACe9zaVVdHqzqnxn +3xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6epRq4YmylhWzvwxcgiJbS/QIdQMGZoiOt4lwxowru8=; b=Sf0zPKP0XsrM2t//EIUGOgdtavDMCtpEYC1nFgSdnWNEWUG7Fb+wchWWzfkzcYVFLr UjPcy1BFlxqfWRwQ2JM4Zy/Qm877RB2k2mora4BQpNtuqqMN6uRDqaXCUNTAQfLNbr5/ 5eaTsNTTyybwoIslu6QIXX0nhDmDoUKp2JeZmX0T4Ax77eS5t3orQOQIJR0hyZlCUjOC LymQp6EjpwR24ePjxEtVHsgXcBfrOs5tIIp/SVLDY+Gb0dHLmHC2S4+jKf6XBT8Kxgmc +sY59+tJSqjZACWE65UPyr9gJhMw+6SyiL5Vdg3db0gsChO7r0u/qTpg7oV3RCopp0Ee Mupg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bse7wsbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yw7si7041568ejb.453.2021.01.26.07.21.01; Tue, 26 Jan 2021 07:21:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bse7wsbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406224AbhAZPRy (ORCPT + 99 others); Tue, 26 Jan 2021 10:17:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:40524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406165AbhAZPRt (ORCPT ); Tue, 26 Jan 2021 10:17:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3452023125; Tue, 26 Jan 2021 15:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611674229; bh=jQUlNAmaG/JIlfb8wj1P0QU7PlzvHrMjBt0DjW3UBfQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Bse7wsbZ4WVfRFS7M6zYsvz61/gsg2IADS3AYZUKCyQl67/RBZHesYz30LfB5DwgG U+P0lYcLi+mkaKFCcoYhq7wXMemGr2O+3NJuQnGEJqaOBpQr8pmqHAARSguolW8TW+ RrKLJp9zyMMphbZg2qtcugYXTmXp405TmGnMM6ZMB+z51Y/vFWx79NTXJBfFPFn9ak ry+BSaAz4/K9SCfaoHYG07170FVnp4HvQ4tHvNjjtqkHip5psrx8gvAstS3PaQKbTO 6PsSQzQo0KwVpaggBh1Y3dQkfWeTNUTqPpjbKYVGV7xbAmtvMVphH9HgTeYSPYjXut jKWqVZcxGodeg== Received: by mail-oi1-f180.google.com with SMTP id i25so7387178oie.10; Tue, 26 Jan 2021 07:17:09 -0800 (PST) X-Gm-Message-State: AOAM5333uZIMqhBhlYMD0VfjFJx9OBG8Mv7Dan7L/zVPvS/81Apdq14r R1LKVt1n18C2ZBErbDBAjGlb17slvpy1In2NA6U= X-Received: by 2002:aca:eb0a:: with SMTP id j10mr121687oih.4.1611674228434; Tue, 26 Jan 2021 07:17:08 -0800 (PST) MIME-Version: 1.0 References: <1610729929-188490-1-git-send-email-john.garry@huawei.com> In-Reply-To: <1610729929-188490-1-git-send-email-john.garry@huawei.com> From: Arnd Bergmann Date: Tue, 26 Jan 2021 16:16:51 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC 0/4] Fix arm64 crash for accessing unmapped IO port regions (reboot) To: John Garry Cc: Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Wei Xu , Lorenzo Pieralisi , Bjorn Helgaas , Jiaxun Yang , Barry Song , Linux ARM , "linux-kernel@vger.kernel.org" , linux-arch , "open list:BROADCOM NVRAM DRIVER" , linux-pci , linuxarm@openeuler.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 5:58 PM John Garry wrote: > > This is a reboot of my original series to address the problem of drivers > for legacy ISA devices accessing unmapped IO port regions on arm64 systems > and causing the system to crash. > > There was another recent report of such an issue [0], and some old ones > [1] and [2] for reference. > > The background is that many systems do not include PCI host controllers, > or they do and controller probe may have failed. For these cases, no IO > ports are mapped. However, loading drivers for legacy ISA devices can > crash the system as there is nothing to stop them accessing those IO > ports (which have not been io remap'ed). > > My original solution tried to keep the kernel alive in these situations by > rejecting logical PIO access to PCI IO regions until PCI IO port regions > have been mapped. > > This series goes one step further, by just reserving the complete legacy > IO port range in 0x0--0xffff for arm64. The motivation for doing this is > to make the request_region() calls for those drivers fail, like this: > > root@ubuntu:/home/john# insmod mk712.ko > [ 3415.575800] mk712: unable to get IO region > insmod: ERROR: could not insert module mk712.ko: No such device > > Otherwise, in theory, those drivers could initiate rogue accesses to > mapped IO port regions for other devices and cause corruptions or > side-effects. Indeed, those drivers should not be allowed to access > IO ports at all in such a system. > > As a secondary defence, for broken drivers who do not call > request_region(), IO port accesses in range 0--0xffff will be ignored, > again preserving the system. > > I am sending as an RFC as I am not sure of any problem with reserving > first 0x10000 of IO space like this. There is reserve= commandline > argument, which does allow this already. > > For reference, here's how /proc/ioports looks on my arm64 system with > this change: > > root@ubuntu:/home/john# more /proc/ioports > 00010000-0001ffff : PCI Bus 0002:f8 > 00010000-00010fff : PCI Bus 0002:f9 > 00010000-00010007 : 0002:f9:00.0 > 00010000-00010007 : serial > 00010008-0001000f : 0002:f9:00.1 > 00010008-0001000f : serial > 00010010-00010017 : 0002:f9:00.2 > 00010018-0001001f : 0002:f9:00.2 > 00020000-0002ffff : PCI Bus 0004:88 > 00030000-0003ffff : PCI Bus 0005:78 > 00040000-0004ffff : PCI Bus 0006:c0 > 00050000-0005ffff : PCI Bus 0007:90 > 00060000-0006ffff : PCI Bus 000a:10 > 00070000-0007ffff : PCI Bus 000c:20 > 00080000-0008ffff : PCI Bus 000d:30 Doesn't this mean we lose the ability to access PCI devices with legacy ISA compatibility? Most importantly, any GPU today should in theory still support VGA frame buffer mode or text console, but both of these stop working if the low I/O ports are not mapped to the corresponding PCI bus. There is of course already a problem if you have multiple PCI host bridges, and each one gets its own PIO range, which means that only one of them can have an ISA bridge with working PIO behind it. Another such case would be a BMC that has legacy ISA devices behind a (real or emulated) LPC bus, e.g. a 8250 UART, ps2 keyboard, RTC, or an ATA CDROM. Not sure if any of those are ever used on Arm machines. Regarding the size of the reservation, does this actually need to cover the 0x0fff...0xffff range or just 0x0000...0x0fff? I don't think there are any drivers that hardcode I/O ports beyond 0x0fff because those would not work on ISA buses but require PCI assigned BARs. One more thought: There are two common ways in which PCI host bridges map their PIO ports: either each host bridge has its own 0x0...0xffff BAR range but gets remapped to an arbitrary range of port numbers in the kernel, or each host bridge uses a distinct range of port numbers, and the kernel can use a 1:1 mapping between hardware and software port numbers, i.e. the number in the BAR is the same as in the kernel. If all numbers are shifted by 0x10000, that second case no longer works, and there is always an offset. Arnd