From patchwork Mon May 7 08:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie Yisheng X-Patchwork-Id: 10383403 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D8FA60159 for ; Mon, 7 May 2018 08:06:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91E0B2891F for ; Mon, 7 May 2018 08:06:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8633828B2C; Mon, 7 May 2018 08:06:44 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24EC22891F for ; Mon, 7 May 2018 08:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751983AbeEGIGm (ORCPT ); Mon, 7 May 2018 04:06:42 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:45768 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751937AbeEGIGk (ORCPT ); Mon, 7 May 2018 04:06:40 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A89E6245F6A91; Mon, 7 May 2018 16:06:35 +0800 (CST) Received: from [127.0.0.1] (10.177.29.40) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Mon, 7 May 2018 16:06:31 +0800 Subject: Re: [PATCH v2 1/2] PCI ACPI: Avoid panic when PCI IO resource's size is not page aligned To: "Rafael J. Wysocki" References: <1522480343-37669-1-git-send-email-xieyisheng1@huawei.com> <3699960.UXjPS91TgB@aspire.rjw.lan> CC: , , , , , , , , , , Lorenzo Pieralisi , Sudeep Holla , Hanjun Guo From: Yisheng Xie Message-ID: Date: Mon, 7 May 2018 16:06:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <3699960.UXjPS91TgB@aspire.rjw.lan> X-Originating-IP: [10.177.29.40] X-CFilter-Loop: Reflected Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 2018/5/1 17:28, Rafael J. Wysocki wrote: >> 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? Yeah, I thought that pci_remap_iospace() will be called at many place, and presently I had not seen any problem at other place except acpi_pci_root_remap_iospace(). Anyway, sanitize arguments in pci_remap_iospace() can resolve the problem more thoroughly, but should more common, right? Therefore, is the follow change ok from your point of view? Thanks Yisheng > >> > entry->offset = port - pci_addr; >> > >> > if (pci_remap_iospace(res, cpu_addr) < 0) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e597655..8607298 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3527,6 +3527,9 @@ int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr) if (res->end > IO_SPACE_LIMIT) return -EINVAL; + if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res))) + return -EINVAL; + return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr, pgprot_device(PAGE_KERNEL)); #else