From patchwork Wed Apr 12 12:25:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 9677343 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 122D760384 for ; Wed, 12 Apr 2017 12:26:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00D0E2866A for ; Wed, 12 Apr 2017 12:26:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E812E2866D; Wed, 12 Apr 2017 12:26:54 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 A04A728669 for ; Wed, 12 Apr 2017 12:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753734AbdDLM0W (ORCPT ); Wed, 12 Apr 2017 08:26:22 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38092 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753373AbdDLM0S (ORCPT ); Wed, 12 Apr 2017 08:26:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Sender:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QNXa1mzepJFN1++LjX02M0sda6FiHHcXR6WuFkVLsCY=; b=yAwsktjHgRk25lcdp96ky9BLA 2VlJVON0MylZSPKRtf7Ij+EZgw8bbVm/5pAeYKfJTJWILMt8QvoI6ogctTAl83XRpi7ExQd+mmzLQ OH4HXR0azvU+FLd5d0CFDL2pqC8JvUumQKi0rPTiBAe+U+cVYNm8sZE3itjUZMbFZ5kDirZ14rNo1 kqutGV7EcdDf03NMGlOU4CUa+gof96jbQK3pIaKIUfOfSfZ1OK6Mlj6kAInOkiUyJ5AqtLkTZiFh3 7AeVXXEZ0ZeEJvLTd2G1/7B5pCeUGVcf22k9ejMfbLms899pCrYKtdFylQLB1hIndcJ9yejHnpMhq Tgrcw/ckA==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by merlin.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1cyHLl-00018f-L3; Wed, 12 Apr 2017 12:26:17 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1cyHLk-000bYd-AW; Wed, 12 Apr 2017 13:26:16 +0100 From: David Woodhouse To: linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/27] pci: Fix pci_mmap_fits() for HAVE_PCI_RESOURCE_TO_USER platforms Date: Wed, 12 Apr 2017 13:25:50 +0100 Message-Id: <0d7c284a997414d7e9a264e21f316ca1ac673277.1491999859.git.dwmw2@infradead.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html 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 From: David Woodhouse In the PCI_MMAP_PROCFS case when the address being passed by the user is a 'user visible' resource address based on the bus window, and not the actual contents of the resource, that's what we need to be checking it against. Signed-off-by: David Woodhouse Cc: stable@vger.kernel.org --- drivers/pci/pci-sysfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 25d010d..7ac258f 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -985,15 +985,19 @@ 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; + resource_size_t pci_start = 0, pci_end; if (pci_resource_len(pdev, resno) == 0) return 0; nr = vma_pages(vma); start = vma->vm_pgoff; 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 (mmap_api == PCI_MMAP_PROCFS) { + pci_resource_to_user(pdev, resno, &pdev->resource[resno], + &pci_start, &pci_end); + pci_start >>= PAGE_SHIFT; + } if (start >= pci_start && start < pci_start + size && start + nr <= pci_start + size) return 1;