From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752721AbcHOCx7 (ORCPT ); Sun, 14 Aug 2016 22:53:59 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:55043 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752590AbcHOCx5 (ORCPT ); Sun, 14 Aug 2016 22:53:57 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="9916522" Subject: Re: [PATCH v3] vfio : add aer process To: References: <1470110274-14585-1-git-send-email-zhoujie2011@cn.fujitsu.com> CC: , , , From: Zhou Jie Message-ID: <309e99ed-1f5a-07cd-e0b0-e314155f9fa4@cn.fujitsu.com> Date: Mon, 15 Aug 2016 10:53:44 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1470110274-14585-1-git-send-email-zhoujie2011@cn.fujitsu.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-yoursite-MailScanner-ID: 7D083429594D.AD7C4 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhoujie2011@cn.fujitsu.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ping On 2016/8/2 11:57, Zhou Jie wrote: > 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 > --- > v2-v3: > 1. Call init_completion() in vfio_pci_probe. > 2. Call reinit_completion() in vfio_pci_aer_err_detected. > 3. Remove unnecessary brackets. > > v1-v2: > 1. Add aer process to vfio driver. > > drivers/vfio/pci/vfio_pci.c | 48 +++++++++++++++++++++++++++++++++++++ > drivers/vfio/pci/vfio_pci_private.h | 2 ++ > include/uapi/linux/vfio.h | 2 ++ > 3 files changed, 52 insertions(+) > > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > index d624a52..4c246a1 100644 > --- a/drivers/vfio/pci/vfio_pci.c > +++ b/drivers/vfio/pci/vfio_pci.c > @@ -648,6 +648,15 @@ 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; > > @@ -664,6 +673,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; > > @@ -1070,6 +1083,13 @@ 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: > @@ -1228,6 +1248,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) > vdev->irq_type = VFIO_PCI_NUM_IRQS; > mutex_init(&vdev->igate); > spin_lock_init(&vdev->irqlock); > + init_completion(&vdev->aer_error_completion); > > ret = vfio_add_group_dev(&pdev->dev, &vfio_pci_ops, vdev); > if (ret) { > @@ -1300,6 +1321,11 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, > > mutex_lock(&vdev->igate); > > + vdev->aer_error_in_progress = true; > + reinit_completion(&vdev->aer_error_completion); > + 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); > > @@ -1310,8 +1336,30 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, > return PCI_ERS_RESULT_CAN_RECOVER; > } > > +static void vfio_pci_aer_resume(struct pci_dev *pdev) > +{ > + struct vfio_pci_device *vdev; > + struct vfio_device *device; > + > + device = vfio_device_get_from_dev(&pdev->dev); > + if (device == NULL) > + return; > + > + vdev = vfio_device_data(device); > + if (vdev == NULL) { > + vfio_device_put(device); > + return; > + } > + > + vdev->aer_error_in_progress = false; > + complete_all(&vdev->aer_error_completion); > + > + vfio_device_put(device); > +} > + > static const struct pci_error_handlers vfio_err_handlers = { > .error_detected = vfio_pci_aer_err_detected, > + .resume = vfio_pci_aer_resume, > }; > > static struct pci_driver vfio_pci_driver = { > diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h > index 2128de8..7430d92 100644 > --- a/drivers/vfio/pci/vfio_pci_private.h > +++ b/drivers/vfio/pci/vfio_pci_private.h > @@ -91,6 +91,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 255a211..59b9cf6 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 */ > }; > -- ------------------------------------------------ 周潔 Dept 1 No. 6 Wenzhu Road, Nanjing, 210012, China TEL:+86+25-86630566-8557 FUJITSU INTERNAL:7998-8557 E-Mail:zhoujie2011@cn.fujitsu.com ------------------------------------------------