Received: by 10.213.65.68 with SMTP id h4csp404009imn; Sat, 31 Mar 2018 00:25:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/pHhrx8HKEvKJwg0+WpgZvLW4VQe8wjCK9B6AkZHY/dEoIq7ksPeuhYMDs3Yc0TRl4A++E X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr2166385plk.200.1522481134888; Sat, 31 Mar 2018 00:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522481134; cv=none; d=google.com; s=arc-20160816; b=bKqhUSR+Rne2iPxIG/m9rAQheYBD5tF9Ouiw0qkdg7mmMkpdDPAVy7gGyxuT13ClJT WwEY2LZpFFOpdwUIAKKKUC+Js7qYtqpy6OQM8RXS+Lvuh9fTSqL8ZMpDjBqCtLXee5s5 Vc3M98Na+2+ieddT6KHAcAuLTTSN/uzwppHJFMh4rkMW55caZajHNdqe5Qx2zMzEDxtF mOxEaZO4E06Ox6F0O0wqCkNApkLdgSy+XcGHJLJoZTB3LZAnf8CmeRiHzWXisOhyeyMy g5r2GFTd7HtyUFBfTNKLuxoN4fkSXVapytxB59biy5G3k/tLU8q1fvm07TuoBCLMavSd sCrA== 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=vAxnYpAVIyT+nbdeXmAA1P19r3hm80jcRA0chHBECsA=; b=ozojpdwAo2Dzrn/aFF+Gt0uq6qUZBTks72zJPwNrO8SA6uUowNnAEZlANu/17dGcRu J5rZGTBgFLuWWbS4VL26W7wFpjPWjUfy0VH8svpJ3sLj1FB+hrdqbk7vXMiSyPqc8SeP W2v2ZJqYg52rJKTXW1MBGRmIfsQJrXs1Twxejg6dIWqaNqCEtdKo+mTnLgBo34uInoaR 4yUuhE0neouHf/fsTpOhcl0AV/BX0iJV2GLy1XqJQRjGhsaMjVgQMRXGpqjwVtwBdFc8 rVDYbA6UfyzcspMYlSioaHJb6S/pWsDtHJ6DLxHY8Rm0oe1aHQu8qvo6bSKj+XNikZkM iSPA== 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 bd7-v6si9745985plb.404.2018.03.31.00.25.20; Sat, 31 Mar 2018 00:25:34 -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 S1752850AbeCaHXa (ORCPT + 99 others); Sat, 31 Mar 2018 03:23:30 -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 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 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 -- 1.7.12.4