From patchwork Tue Jul 19 07:32:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhou Jie X-Patchwork-Id: 649962 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rtsPq5X6pz9sBM for ; Tue, 19 Jul 2016 17:39:43 +1000 (AEST) Received: from localhost ([::1]:53310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPPcz-00079D-GD for incoming@patchwork.ozlabs.org; Tue, 19 Jul 2016 03:39:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPPYc-00025e-Q0 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 03:35:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPPYX-0006rA-0w for qemu-devel@nongnu.org; Tue, 19 Jul 2016 03:35:10 -0400 Received: from [59.151.112.132] (port=52891 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPPYV-0006q2-N4 for qemu-devel@nongnu.org; Tue, 19 Jul 2016 03:35:04 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="8850646" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 19 Jul 2016 15:35:01 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id BA06B42B87C1; Tue, 19 Jul 2016 15:34:57 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.226.45) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Tue, 19 Jul 2016 15:34:57 +0800 From: Zhou Jie To: Date: Tue, 19 Jul 2016 15:32:43 +0800 Message-ID: <1468913563-21456-3-git-send-email-zhoujie2011@cn.fujitsu.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468913563-21456-1-git-send-email-zhoujie2011@cn.fujitsu.com> References: <1468913563-21456-1-git-send-email-zhoujie2011@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.45] X-yoursite-MailScanner-ID: BA06B42B87C1.A95D5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhoujie2011@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH v2 2/2] vfio : add aer process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fan.chen@easystack.cn, Zhou Jie , linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, Chen Fan , izumi.taku@jp.fujitsu.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Chen Fan During aer err occurs and resume do following to protect device from being accessed. 1. Make config space read only. 2. Disable INTx/MSI Interrupt. 3. Do nothing for bar regions. Signed-off-by: Zhou Jie --- drivers/vfio/pci/vfio_pci.c | 30 ++++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_private.h | 2 ++ include/uapi/linux/vfio.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 2d12b03..dd96b60 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -318,6 +318,7 @@ static int vfio_pci_open(void *device_data) return -ENODEV; mutex_lock(&driver_lock); + init_completion(&vdev->aer_error_completion); if (!vdev->refcnt) { ret = vfio_pci_enable(vdev); @@ -571,6 +572,16 @@ static long vfio_pci_ioctl(void *device_data, struct vfio_pci_device *vdev = device_data; unsigned long minsz; + if (vdev->aer_error_in_progress && (cmd == VFIO_DEVICE_SET_IRQS || + cmd == VFIO_DEVICE_RESET || cmd == VFIO_DEVICE_PCI_HOT_RESET)) { + int ret; + ret = wait_for_completion_interruptible( + &vdev->aer_error_completion); + if (ret) { + return ret; + } + } + if (cmd == VFIO_DEVICE_GET_INFO) { struct vfio_device_info info; @@ -587,6 +598,10 @@ static long vfio_pci_ioctl(void *device_data, if (vdev->reset_works) info.flags |= VFIO_DEVICE_FLAGS_RESET; + info.flags |= VFIO_DEVICE_FLAGS_AERPROCESS; + if (vdev->aer_error_in_progress) + info.flags |= VFIO_DEVICE_FLAGS_INAERPROCESS; + info.num_regions = VFIO_PCI_NUM_REGIONS + vdev->num_regions; info.num_irqs = VFIO_PCI_NUM_IRQS; @@ -996,6 +1011,14 @@ static ssize_t vfio_pci_rw(void *device_data, char __user *buf, switch (index) { case VFIO_PCI_CONFIG_REGION_INDEX: + if (vdev->aer_error_in_progress && iswrite) { + int ret; + ret = wait_for_completion_interruptible( + &vdev->aer_error_completion); + if (ret) { + return ret; + } + } return vfio_pci_config_rw(vdev, buf, count, ppos, iswrite); case VFIO_PCI_ROM_REGION_INDEX: @@ -1226,6 +1249,10 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, mutex_lock(&vdev->igate); + vdev->aer_error_in_progress = true; + vfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE | + VFIO_IRQ_SET_ACTION_TRIGGER, + vdev->irq_type, 0, 0, NULL); if (vdev->err_trigger) eventfd_signal(vdev->err_trigger, 1); @@ -1252,6 +1279,9 @@ static void vfio_pci_aer_resume(struct pci_dev *pdev) } mutex_lock(&vdev->igate); + + vdev->aer_error_in_progress = false; + complete_all(&vdev->aer_error_completion); if (vdev->resume_trigger) eventfd_signal(vdev->resume_trigger, 1); diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 80d4ddd..2f151f5 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -84,6 +84,8 @@ struct vfio_pci_device { bool has_vga; bool needs_reset; bool nointx; + bool aer_error_in_progress; + struct completion aer_error_completion; struct pci_saved_state *pci_saved_state; int refcnt; struct eventfd_ctx *err_trigger; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 34ab138..276ce50 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -198,6 +198,8 @@ struct vfio_device_info { #define VFIO_DEVICE_FLAGS_PCI (1 << 1) /* vfio-pci device */ #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2) /* vfio-platform device */ #define VFIO_DEVICE_FLAGS_AMBA (1 << 3) /* vfio-amba device */ +#define VFIO_DEVICE_FLAGS_AERPROCESS (1 << 4) /* support aer error progress */ +#define VFIO_DEVICE_FLAGS_INAERPROCESS (1 << 5)/* status in aer error progress */ __u32 num_regions; /* Max region index + 1 */ __u32 num_irqs; /* Max IRQ index + 1 */ };