Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3329866imm; Tue, 29 May 2018 05:30:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpW3auGvnj+AlOhr9ObewZPGddP7Fb8WhHxpDBRcvoxucC4GE3mVCx5WZ6mE1mGtCUzpQob X-Received: by 2002:a63:a513:: with SMTP id n19-v6mr13556766pgf.381.1527597031738; Tue, 29 May 2018 05:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527597031; cv=none; d=google.com; s=arc-20160816; b=UJxBaOF3gHA/UzZTpKsgV5JiCjAf5sbXvArecB+eTpX1Ykz59JtiVCUO+kcJAhIxHh WcJoe2AWot8C57bdm0IQZR6FcuHMLjWLtlFD3vZ0Pv/OFT42czqgHqKW15pH4YKR9KiR rZ0obXv1ChRr+b+DA3ee0CnxBroqAbqiwQeWpI+cC6BErKYPyhDjUg041+fxHHEJNfXA qVshVXf4yHVRaEbRJcqLGYU7WHmZkpU6hz/l87No9goSSnNd54CjkwdIJPs/VBbUM9eI BpayQ6ZKmeGVXH/7LH3Sk4TjOr257i/dh3p5A38FtV6QcMtRMSb56GLDwfZ9jPiLH5Ay Kvaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=15ED+w2WAEkDENQi97N6GTjjZepVlfotzb+GL1la/xw=; b=acQaGMbx1gNTH7DvNV87e9vLVOnSLAPHmzaHrQChKN9g02HwFUSE8BXAEM6+tQ+j/8 Ai8WEkBgekAuigMyYdzSwRilJLv24NyxAjc+Gf1la8I5LjAE+qH7t8ZA6Jy8qwgMbeLx Fsim9IqPY+mp83pUPCAbdqLbouY1tZ3m4b8MCsuKdXEDmzJnCcTqtqRbCD6aU8QwNXTx xuED07wVPz5YD/wi6WI6llLw51x4FXCVMdxbXOAkmADpzIJpxJLqOJWvHQw//52Vtei1 okuScVri95MXuZ/K95aqwP67JHKqkddgF4Ze17hl7tnxwylwUzctoyMq2kiDmJfee9E5 VVJA== 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 q1-v6si32316079plb.549.2018.05.29.05.30.17; Tue, 29 May 2018 05:30:31 -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 S933730AbeE2M3Q (ORCPT + 99 others); Tue, 29 May 2018 08:29:16 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8203 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933652AbeE2M3N (ORCPT ); Tue, 29 May 2018 08:29:13 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id BBA345BC4E542; Tue, 29 May 2018 20:28:59 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Tue, 29 May 2018 20:28:55 +0800 From: Yisheng Xie To: , , , , , , , CC: , , , Yisheng Xie Subject: [PATCH v3 2/2] PCI: Check phys_addr for pci_remap_iospace Date: Tue, 29 May 2018 20:18:19 +0800 Message-ID: <1527596299-57567-2-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1527596299-57567-1-git-send-email-xieyisheng1@huawei.com> References: <1527596299-57567-1-git-send-email-xieyisheng1@huawei.com> 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 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 0eb0381..117ca6a 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3547,6 +3547,9 @@ int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr) if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res))) 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 -- 1.7.12.4