Received: by 10.192.165.148 with SMTP id m20csp4720236imm; Tue, 1 May 2018 02:29:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpefs//xbjJ/r4GghxJysdFAJJgte6Rkt1DZASeoiv6AK9VTlAnBLw3X3Y/14my05+1jlPE X-Received: by 2002:a65:4102:: with SMTP id w2-v6mr11609430pgp.31.1525166956849; Tue, 01 May 2018 02:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525166956; cv=none; d=google.com; s=arc-20160816; b=xDqlggd49XsZDcHGsihuVZcrkJS2AEXbwP4uNrn8TbToKh/Qpf1lLNvhG0JB+XZFGM c4gWmKHHeNexBLgMC78Aun5lNodzcIPGWnBFPvvK7OmJLy7G03z95ZRcsdMCoL6k5dBi rXOMLUYfCigkrLbOiwYKnNgNsXAyX+n/tv7hqUkf74EesZV3W1OnXp54OXYIS7zjVKP0 UI73hlBYjamI/aKkdOVL6B3jd9fMs/VlxtncXEVSXwiOljZ7uHXssyQB2O4FDxmtxzOb huJvhPO2PXmLdNXebUkVyaGJIWuBaG4TVps3TDdQlaRo6vdgO4Dmum+jCqGpFnBZfZP9 IfGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=95X0M4S4lcQeCJbqh32DDoRziEkwEN+TnIE5q4o0gLo=; b=CY2WnINWwpMhlS2wMSb8QANGjsEraoTqP85PHb3IQmOlXYXjb4vOF7Bdr7Ry7tsw24 9GNjDUHrp2ZgNmcbNxnb/75xosxG7BB3MlK6CI4QZ1f66DA5d+XPh32WZ2qjy+bp13uM /E7mVd5NhtaScPvbrY2dfK6YSx/jNvpz+x7NGAnCkpm6wpBFOEXbdI44v6VJHxS1/41a iCmmjhTOGwrhyclSwElix2yOe3oaCtw/zMSdfZvXY+0sA2xB+bdMSSZsQjMhtgKBmaWu tx4jz0ZfssVeOF2nS8nXt2BbmDoBj0rra9hXdfeCQQAocs0nIfDNVSpsALW4QyN1vvoD Ou1Q== 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 w61-v6si9089994plb.155.2018.05.01.02.29.02; Tue, 01 May 2018 02:29:16 -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 S1753909AbeEAJ2u (ORCPT + 99 others); Tue, 1 May 2018 05:28:50 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:52793 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071AbeEAJ2s (ORCPT ); Tue, 1 May 2018 05:28:48 -0400 Received: from 79.184.254.189.ipv4.supernova.orange.pl (79.184.254.189) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 60e898c9cc5ed7d2; Tue, 1 May 2018 11:28:46 +0200 From: "Rafael J. Wysocki" To: Yisheng Xie Cc: bhelgaas@google.com, lenb@kernel.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, guohanjun@huawei.com, jcm@redhat.com, toshi.kani@hpe.com, tanxiaojun@huawei.com, wangzhou1@hisilicon.com, Lorenzo Pieralisi , Sudeep Holla , Hanjun Guo Subject: Re: [PATCH v2 1/2] PCI ACPI: Avoid panic when PCI IO resource's size is not page aligned Date: Tue, 01 May 2018 11:28:31 +0200 Message-ID: <3699960.UXjPS91TgB@aspire.rjw.lan> In-Reply-To: <1522480343-37669-1-git-send-email-xieyisheng1@huawei.com> References: <1522480343-37669-1-git-send-email-xieyisheng1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Saturday, March 31, 2018 9:12:22 AM CEST Yisheng Xie wrote: > 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; Shouldn't pci_remap_iospace() sanitize its arguments instead? > entry->offset = port - pci_addr; > > if (pci_remap_iospace(res, cpu_addr) < 0) >