From patchwork Sat Mar 31 07:12:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie Yisheng X-Patchwork-Id: 10318875 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 A7B3560212 for ; Sat, 31 Mar 2018 07:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 921BE2A09B for ; Sat, 31 Mar 2018 07:23:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86F652A09E; Sat, 31 Mar 2018 07:23:56 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 49F9E2A09B for ; Sat, 31 Mar 2018 07:23:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752501AbeCaHX3 (ORCPT ); Sat, 31 Mar 2018 03:23:29 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6715 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752466AbeCaHX2 (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 5221275D26792; 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 2/2] PCI: Check phys_addr for pci_remap_iospace Date: Sat, 31 Mar 2018 15:12:23 +0800 Message-ID: <1522480343-37669-2-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 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 X-Originating-IP: [10.175.102.37] 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 If phys_addr is not page aligned, ioremap_page_range() will align down it when get pfn by phys_addr >> PAGE_SHIFT. An example in arm64 system with 64KB page size: phys_addr: 0xefff8000 res->start: 0x0 res->end: 0x0ffff PCI_IOBASE: 0xffff7fdffee00000 This will remap virtual address 0xffff7fdffee00000 to phys_addr 0xefff0000, but what we really want is 0xefff8000, which makes later IO access to a mess. And users may even donot know this until find some odd phenemenon. This patch checks whether phys_addr is PAGE_ALIGNED or not to find the primary scene. Signed-off-by: Zhou Wang Signed-off-by: Yisheng Xie --- drivers/pci/pci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index f6a4dd1..deb91f0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3576,6 +3576,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(phys_addr)) + return -EINVAL; + return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr, pgprot_device(PAGE_KERNEL)); #else