From patchwork Fri Dec 11 08:53:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 7827411 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 17F64BEEE1 for ; Fri, 11 Dec 2015 08:56:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D16720570 for ; Fri, 11 Dec 2015 08:56:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23E9A204AF for ; Fri, 11 Dec 2015 08:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754534AbbLKI4l (ORCPT ); Fri, 11 Dec 2015 03:56:41 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:43198 "EHLO e23smtp03.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754132AbbLKI4k (ORCPT ); Fri, 11 Dec 2015 03:56:40 -0500 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 Dec 2015 18:56:38 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 11 Dec 2015 18:56:36 +1000 X-IBM-Helo: d23dlp01.au.ibm.com X-IBM-MailFrom: xyjxie@linux.vnet.ibm.com X-IBM-RcptTo: kvm@vger.kernel.org; linux-api@vger.kernel.org; linux-kernel@vger.kernel.org Received: from d23relay08.au.ibm.com (d23relay08.au.ibm.com [9.185.71.33]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 4F4492CE8050; Fri, 11 Dec 2015 19:56:36 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBB8uAn523396604; Fri, 11 Dec 2015 19:56:18 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tBB8u2Pv018104; Fri, 11 Dec 2015 19:56:04 +1100 Received: from localhost (commit.cn.ibm.com [9.123.229.41]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tBB8u2vh017483; Fri, 11 Dec 2015 19:56:02 +1100 From: Yongji Xie To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: aik@ozlabs.ru, alex.williamson@redhat.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, warrier@linux.vnet.ibm.com, zhong@linux.vnet.ibm.com, nikunj@linux.vnet.ibm.com, Yongji Xie Subject: [RFC PATCH 3/3] vfio-pci: Allow to mmap MSI-X table if EEH is supported Date: Fri, 11 Dec 2015 16:53:14 +0800 Message-Id: <1449823994-3356-4-git-send-email-xyjxie@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1449823994-3356-1-git-send-email-xyjxie@linux.vnet.ibm.com> References: <1449823994-3356-1-git-send-email-xyjxie@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15121108-0009-0000-0000-00000283FBCD Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current vfio-pci implementation disallows to mmap MSI-X table in case that user get to touch this directly. However, EEH mechanism could ensure that a given pci device can only shoot the MSIs assigned for its PE and guest kernel also would not write to MSI-X table in pci_enable_msix() because para-virtualization on PPC64 platform. So MSI-X table is safe to access directly from the guest with EEH mechanism enabled. This patch adds support for this case and allow to mmap MSI-X table if EEH is supported on PPC64 platform. And we also add a VFIO_DEVICE_FLAGS_PCI_MSIX_MMAP flag to notify userspace that it's safe to mmap MSI-X table. Signed-off-by: Yongji Xie --- drivers/vfio/pci/vfio_pci.c | 5 ++++- drivers/vfio/pci/vfio_pci_private.h | 5 +++++ include/uapi/linux/vfio.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index dbcad99..85d9980 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -446,6 +446,9 @@ static long vfio_pci_ioctl(void *device_data, if (vfio_pci_bar_page_aligned()) info.flags |= VFIO_DEVICE_FLAGS_PCI_PAGE_ALIGNED; + if (vfio_msix_table_mmap_enabled()) + info.flags |= VFIO_DEVICE_FLAGS_PCI_MSIX_MMAP; + info.num_regions = VFIO_PCI_NUM_REGIONS; info.num_irqs = VFIO_PCI_NUM_IRQS; @@ -871,7 +874,7 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) if (phys_len < PAGE_SIZE || req_start + req_len > phys_len) return -EINVAL; - if (index == vdev->msix_bar) { + if (index == vdev->msix_bar && !vfio_msix_table_mmap_enabled()) { /* * Disallow mmaps overlapping the MSI-X table; users don't * get to touch this directly. We could find somewhere diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 319352a..835619e 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -74,6 +74,11 @@ static inline bool vfio_pci_bar_page_aligned(void) return IS_ENABLED(CONFIG_PPC64); } +static inline bool vfio_msix_table_mmap_enabled(void) +{ + return IS_ENABLED(CONFIG_EEH); +} + extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev); extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 1fc8066..289e662 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -173,6 +173,8 @@ struct vfio_device_info { #define VFIO_DEVICE_FLAGS_AMBA (1 << 3) /* vfio-amba device */ /* Platform support all PCI MMIO BARs to be page aligned */ #define VFIO_DEVICE_FLAGS_PCI_PAGE_ALIGNED (1 << 4) +/* Platform support mmapping PCI MSI-X vector table */ +#define VFIO_DEVICE_FLAGS_PCI_MSIX_MMAP (1 << 5) __u32 num_regions; /* Max region index + 1 */ __u32 num_irqs; /* Max IRQ index + 1 */ };