From patchwork Mon Oct 9 02:50:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 9992117 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 A238A60231 for ; Mon, 9 Oct 2017 02:50:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AA6627FB0 for ; Mon, 9 Oct 2017 02:50:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E3D628694; Mon, 9 Oct 2017 02:50:09 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 04A6D27FB0 for ; Mon, 9 Oct 2017 02:50:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753791AbdJICuG (ORCPT ); Sun, 8 Oct 2017 22:50:06 -0400 Received: from ozlabs.ru ([107.173.13.209]:35416 "EHLO ozlabs.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753866AbdJICuF (ORCPT ); Sun, 8 Oct 2017 22:50:05 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 78E4E3A60023; Sun, 8 Oct 2017 22:48:48 -0400 (EDT) From: Alexey Kardashevskiy To: kvm@vger.kernel.org Cc: Alexey Kardashevskiy , David Gibson , Eric Auger , Benjamin Herrenschmidt , Alex Williamson Subject: [RFC PATCH kernel] vfio-pci: Allow write combining Date: Mon, 9 Oct 2017 13:50:00 +1100 Message-Id: <20171009025000.39435-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP At the moment the protection in VFIO MMIO mappings is forced to _PAGE_NON_IDEMPOTENT which means that write combining is not really available to the userspace even for prefetchable 64bit MMIO BARs. This replaces pgprot_noncached() with a platform specific phys_mem_access_prot() when available and depending on the platform the vm_page_prot may be set to _PAGE_TOLERANT allowing to exploit the write combining feature. The guest drivers still have to use _wc versions of the ioremap/pci_ioremap API to get write combininig working. Signed-off-by: Alexey Kardashevskiy --- This should allow DPDK and radix guests (x86, POWERPC, etc) to do write combining. POWERPC hash guests should not be affected by this change, it should work even without this. --- drivers/vfio/pci/vfio_pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index f041b1a6cf66..014192b42724 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1156,8 +1156,13 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) } vma->vm_private_data = vdev; - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_pgoff = (pci_resource_start(pdev, index) >> PAGE_SHIFT) + pgoff; +#ifdef __HAVE_PHYS_MEM_ACCESS_PROT + vma->vm_page_prot = phys_mem_access_prot(NULL, vma->vm_pgoff, + req_len, vma->vm_page_prot); +#else + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); +#endif return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, req_len, vma->vm_page_prot);