From patchwork Wed Apr 12 12:25:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 9677413 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 0CE9F60384 for ; Wed, 12 Apr 2017 12:32:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3FCC28113 for ; Wed, 12 Apr 2017 12:32:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8E192865B; Wed, 12 Apr 2017 12:32:15 +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 74B822860C for ; Wed, 12 Apr 2017 12:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754291AbdDLMb0 (ORCPT ); Wed, 12 Apr 2017 08:31:26 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38094 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753379AbdDLM0S (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=T08K9Negj7jK8j7nOCKU2r6021gyC6pHvGPkcqohx0w=; b=oiCIJsaUxl3m3PD08gokrXz0R DwCATVI9R7QWi1mex24iFUDN7C1lQUGyyOwhr1VAmMSkmv+fEgkczEmAM7UbjXhY1oEKlNoKd4rWu sRux7a7u+mEmO6iAXgE+7yYoyXRkt9LA6luwFR9aXo2xzoWjZOfeqBbs8wIPaI6+mUQ93y0vIfXmj iObF5b7OhE/XRINTT8edZkKpJO26FEubS8AEnbXOE4cm9c2UFOgRTi7Gr51ltMaUlBXU8FW/Yr1z4 DXszJ+lUJysdpM/f17rNkpEN6RiXgyJlzS641vvpjnDGJRDlTBlzIiJujzWGij4B9JmWaayKJV2hZ 3IJR17B2Q==; 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-00018h-MC; 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-000bYl-CB; 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 03/27] pci: Only allow WC mmap on prefetchable resources Date: Wed, 12 Apr 2017 13:25:52 +0100 Message-Id: <7a91b25e609ef31ca984370dc08158ece3784f79.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 The /proc/bus/pci mmap interface allows the user to specify whether they want WC or not. Don't let them do so on non-prefetchable BARs. Signed-off-by: David Woodhouse Cc: stable@vger.kernel.org --- drivers/pci/proc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index 62a0c3e..dc8912e 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c @@ -231,7 +231,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) { struct pci_dev *dev = PDE_DATA(file_inode(file)); struct pci_filp_private *fpriv = file->private_data; - int i, ret, write_combine, res_bit; + int i, ret, write_combine = 0, res_bit; if (!capable(CAP_SYS_RAWIO)) return -EPERM; @@ -251,10 +251,13 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) if (i >= PCI_ROM_RESOURCE) return -ENODEV; - if (fpriv->mmap_state == pci_mmap_mem) - write_combine = fpriv->write_combine; - else - write_combine = 0; + if (fpriv->mmap_state == pci_mmap_mem && + fpriv->write_combine) { + if (dev->resource[i].flags & IORESOURCE_PREFETCH) + write_combine = 1; + else + return -EINVAL; + } ret = pci_mmap_page_range(dev, vma, fpriv->mmap_state, write_combine); if (ret < 0)