From patchwork Wed Oct 15 12:03:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 38780 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CB32420C4E for ; Wed, 15 Oct 2014 12:03:35 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id w7sf627720lbi.2 for ; Wed, 15 Oct 2014 05:03:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=JP+Yc4dp2MsSrzxZFEovLISrNrFpgCZ9NpQzOh0Snvo=; b=hy6dCdQ8l50udY9TBL1IGfQ6xEslTtuJralsugfxTfDAxw3uaIVtqZLwbrd3fZOF5f bF1VbHpV/K4GSK0NsaA3onO0KG8P3J9hbBYwlC0tCrt5p+j81OTmux3lpHhUPFbUQ3rm 8fiHbaqtRe4Kh4w2O+nVDssX3jP7JSuwqgfwfvEb+Ooqee8TnZnUQpFTgUC3CAleeU0a Uh0hF5oGYif+94kkrVGTkzcShLk/KMdcHfm/GEuHUzhec/PFXKAD89VHBc/WH0jXshZw NLo4K8F7qaU0P+NhTqGz/3OL/+FMm70j7DYhavoDAA/SsqR+YJh/JKYnwSrrLR+c4B1h QmLg== X-Gm-Message-State: ALoCoQm9Pkj+UgMtlUS71gbvF1+S0IbvhrwpwsEXDzOqET2qcr8Gwptjnf4j0cxSH8cpaR3QLC+i X-Received: by 10.180.75.83 with SMTP id a19mr2036913wiw.2.1413374614143; Wed, 15 Oct 2014 05:03:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.226 with SMTP id v2ls51552lav.50.gmail; Wed, 15 Oct 2014 05:03:33 -0700 (PDT) X-Received: by 10.112.147.199 with SMTP id tm7mr2531710lbb.92.1413374613761; Wed, 15 Oct 2014 05:03:33 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com [209.85.217.172]) by mx.google.com with ESMTPS id ti5si25959420lbb.20.2014.10.15.05.03.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Oct 2014 05:03:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id b6so881093lbj.17 for ; Wed, 15 Oct 2014 05:03:33 -0700 (PDT) X-Received: by 10.152.36.103 with SMTP id p7mr11750322laj.44.1413374613574; Wed, 15 Oct 2014 05:03:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp578926lbz; Wed, 15 Oct 2014 05:03:32 -0700 (PDT) X-Received: by 10.67.23.109 with SMTP id hz13mr12023486pad.48.1413374611999; Wed, 15 Oct 2014 05:03:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id po9si15745604pdb.3.2014.10.15.05.03.31 for ; Wed, 15 Oct 2014 05:03:31 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752532AbaJOMDP (ORCPT + 27 others); Wed, 15 Oct 2014 08:03:15 -0400 Received: from service87.mimecast.com ([91.220.42.44]:55451 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751732AbaJOMDN (ORCPT ); Wed, 15 Oct 2014 08:03:13 -0400 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Wed, 15 Oct 2014 13:03:09 +0100 Received: from red-moon.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 15 Oct 2014 13:03:06 +0100 From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: Arnd Bergmann , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , "David S. Miller" , Michal Simek , Martin Wilck , "Derrick J. Wong" , Linux PCI Subject: [PATCH RFC 1/2] drivers: pci: fix pci_mmap_fits() implementation for procfs mmap Date: Wed, 15 Oct 2014 13:03:40 +0100 Message-Id: <1413374624-30066-1-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.1.2 X-OriginalArrivalTime: 15 Oct 2014 12:03:06.0415 (UTC) FILETIME=[FAD28BF0:01CFE86F] X-MC-Unique: 114101513030901001 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lorenzo.pieralisi@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The addresses stored in PCI device resources for memory spaces correspond to CPU physical addresses, which do not necessarily map 1:1 to PCI bus addresses as programmed in PCI devices configuration spaces. Therefore, the changes applied by commits: 8c05cd08a7504b855c26526 3b519e4ea618b6943a82931 imply that the sanity checks carried out in pci_mmap_fits() to ensure that the user executes an mmap of a "real" pci resource are erroneous when executed through procfs. Some platforms (ie SPARC) expect the offset value to be passed in (procfs mapping) to be the PCI BAR configuration value as read from the PCI device configuration space, not the fixed-up CPU physical address that is present in PCI device resources. The required pgoff (offset in mmap syscall) value passed from userspace is supposed to represent the resource value exported through /proc/bus/pci/devices when the resource is mmapped though procfs (and 0 when the mapping is carried out through sysfs resource files), which corresponds to the PCI resource filtered through the pci_resource_to_user() API. This patch converts the PCI resource to the expected "user visible" value through pci_resource_to_user() before carrying out sanity checks in pci_mmap_fits() so that the check is carried out on the resource values as expected from the userspace mmap API. Cc: Arnd Bergmann Cc: Bjorn Helgaas Cc: Benjamin Herrenschmidt Cc: Russell King Cc: David S. Miller Cc: Michal Simek Cc: Martin Wilck Cc: Derrick J. Wong Signed-off-by: Lorenzo Pieralisi --- drivers/pci/pci-sysfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 92b6d9a..777d8bc 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -963,17 +963,20 @@ void pci_remove_legacy_files(struct pci_bus *b) int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma, enum pci_mmap_api mmap_api) { - unsigned long nr, start, size, pci_start; + unsigned long nr, start, size, pci_offset; + resource_size_t pci_start, pci_end; if (pci_resource_len(pdev, resno) == 0) return 0; nr = vma_pages(vma); start = vma->vm_pgoff; + pci_resource_to_user(pdev, resno, &pdev->resource[resno], + &pci_start, &pci_end); size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; - pci_start = (mmap_api == PCI_MMAP_PROCFS) ? - pci_resource_start(pdev, resno) >> PAGE_SHIFT : 0; - if (start >= pci_start && start < pci_start + size && - start + nr <= pci_start + size) + pci_offset = (mmap_api == PCI_MMAP_PROCFS) ? + pci_start >> PAGE_SHIFT : 0; + if (start >= pci_offset && start < pci_offset + size && + start + nr <= pci_offset + size) return 1; return 0; }