Received: by 10.213.65.68 with SMTP id h4csp403771imn; Sat, 31 Mar 2018 00:25:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+FcPWAOrO+V9+uLFHA7e5kYMZ8HQCtt/97DItp4QNQKZVuzrx5jWXzvjM2D/RRToz8mDcL X-Received: by 2002:a17:902:728f:: with SMTP id d15-v6mr2026713pll.227.1522481108274; Sat, 31 Mar 2018 00:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522481108; cv=none; d=google.com; s=arc-20160816; b=e0Vqo6qpH5IaPBnqO7JFj7j1RtzWGageXXTmj/ojzSnhOtN6mePIsLvqvw4U2IvJSP 0YGc1d6XOUPyuOWLDbeS8aQ27VmaX88fKqfKoWDCYJ6WdYU49H/dblLbzlrVADNYViZN HikZWQaKC88cZK6ian0L0rZBJt/26Nwu9UwcFTODz+kwXmY+JJCztBOf0RnGNywCX7N0 K/O0SIWqHymxvzyQYgFbMf3j84IxN6LyPkaLri7zgdGIu0vaj0u66M9evbavleC5eE1D 5hk2/Eoy3/L9STQEbe2Qoo+ebBLaJtYmVt/cGdoCm4TAG7mOhJiwGLI4/cfZrv3UGsOT OAIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=TIMH9rUVbsoC1ss7usjUOCUGF+oNSuOPeHR1hmk7zWc=; b=ulyZtbPajJHPj1HGV5e2GbTCohpQJCWodST3/0MH+svOix16QKFull+Km4c4q/kSrV TdZwb45WYI0PkPred6OzpNo4XCIIldWCtzDs3rHiO5sia8kHVpQKUrZoX9wDVr/F1LzX 16hJjM3j7V5YnzVnMfsg7JK2llW6/sw1E/z1rwI0dMv+pMorn+mT9Hl76kojpnR2iybn cca0PT9Rc/56PMhnrgl1+rMl+Efh3m0Z5YC4Vjo9g9yUAd9+zwIOFhTEZQ/U7GRm/RQb +ElBEYkZ4hTn+umTd0M+ynjtsZu+ZZX+UovOfXbmqEsj+Mc6NQnq8sJD9LoxKqHYQj26 ZVbw== 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 o65si7745611pfj.144.2018.03.31.00.24.53; Sat, 31 Mar 2018 00:25:08 -0700 (PDT) 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 S1752885AbeCaHXb (ORCPT + 99 others); Sat, 31 Mar 2018 03:23:31 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6716 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752460AbeCaHX2 (ORCPT ); Sat, 31 Mar 2018 03:23:28 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6241745B86772; Sat, 31 Mar 2018 15:23:14 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Sat, 31 Mar 2018 15:23:05 +0800 From: Yisheng Xie To: , , CC: , , , , , , , , Yisheng Xie Subject: [PATCH v2 1/2] PCI ACPI: Avoid panic when PCI IO resource's size is not page aligned Date: Sat, 31 Mar 2018 15:12:22 +0800 Message-ID: <1522480343-37669-1-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Zhou reported a bug on Hisilicon arm64 D06 platform with 64KB page size: [ 2.470908] kernel BUG at lib/ioremap.c:72! [ 2.475079] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 2.480551] Modules linked in: [ 2.483594] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.16.0-rc7-00062-g0b41260-dirty #23 [ 2.491756] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 UEFI Nemo 2.0 RC0 - B120 03/23/2018 [ 2.500614] pstate: 80c00009 (Nzcv daif +PAN +UAO) [ 2.505395] pc : ioremap_page_range+0x268/0x36c [ 2.509912] lr : pci_remap_iospace+0xe4/0x100 [...] [ 2.603733] Call trace: [ 2.606168] ioremap_page_range+0x268/0x36c [ 2.610337] pci_remap_iospace+0xe4/0x100 [ 2.614334] acpi_pci_probe_root_resources+0x1d4/0x214 [ 2.619460] pci_acpi_root_prepare_resources+0x18/0xa8 [ 2.624585] acpi_pci_root_create+0x98/0x214 [ 2.628843] pci_acpi_scan_root+0x124/0x20c [ 2.633013] acpi_pci_root_add+0x224/0x494 [ 2.637096] acpi_bus_attach+0xf8/0x200 [ 2.640918] acpi_bus_attach+0x98/0x200 [ 2.644740] acpi_bus_attach+0x98/0x200 [ 2.648562] acpi_bus_scan+0x48/0x9c [ 2.652125] acpi_scan_init+0x104/0x268 [ 2.655948] acpi_init+0x308/0x374 [ 2.659337] do_one_initcall+0x48/0x14c [ 2.663160] kernel_init_freeable+0x19c/0x250 [ 2.667504] kernel_init+0x10/0x100 [ 2.670979] ret_from_fork+0x10/0x18 The cause is the size of PCI IO resource is 32KB, which is 4K aligned but not 64KB aligned, however, ioremap_page_range() request the range as page aligned or it will trigger a BUG_ON() on ioremap_pte_range() it calls, as ioremap_pte_range increase the addr by PAGE_SIZE, which makes addr != end until trigger BUG_ON, if its incoming end is not page aligned. More detail trace is as following: ioremap_page_range -> ioremap_p4d_range -> ioremap_p4d_range -> ioremap_pud_range -> ioremap_pmd_range -> ioremap_pte_range This patch fix the bug by align the size of PCI IO resource to PAGE_SIZE. Reported-by: Zhou Wang Tested-by: Xiaojun Tan Signed-off-by: Yisheng Xie --- I mark this as v2 for I have post a RFC version: https://lkml.org/lkml/2018/3/30/8 v2: * Let the caller of ioremap_page_range() align the request by PAGE_SIZE - per Toshi Thanks Yisheng drivers/acpi/pci_root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 6fc204a..b758ca3 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -746,7 +746,7 @@ static void acpi_pci_root_remap_iospace(struct resource_entry *entry) goto err; res->start = port; - res->end = port + length - 1; + res->end = PAGE_ALIGN(port + length) - 1; entry->offset = port - pci_addr; if (pci_remap_iospace(res, cpu_addr) < 0) -- 1.7.12.4