From patchwork Tue Apr 19 20:32:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 719671 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3JKXUDZ027691 for ; Tue, 19 Apr 2011 20:33:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754687Ab1DSUdT (ORCPT ); Tue, 19 Apr 2011 16:33:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59027 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754434Ab1DSUdQ (ORCPT ); Tue, 19 Apr 2011 16:33:16 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3JKX1OP020639 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 19 Apr 2011 16:33:01 -0400 Received: from s20.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p3JKWxWu014442; Tue, 19 Apr 2011 16:33:00 -0400 From: Alex Williamson Subject: [PATCH] vfio: Add an ioctl to reset the device To: pugs@ieee.org Cc: alex.williamson@redhat.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, qemu-devel@nongnu.org, chrisw@redhat.com, aafabbri@cisco.com, dwang2@cisco.com, benve@cisco.com Date: Tue, 19 Apr 2011 14:32:59 -0600 Message-ID: <20110419203234.4254.94914.stgit@s20.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 19 Apr 2011 20:33:31 +0000 (UTC) When using VFIO to assign a device to a guest, we want to make sure the device is quiesced on VM reset to stop all DMA within the guest mapped memory. Add an ioctl which just calls pci_reset_function() and returns whether it succeeds. Signed-off-by: Alex Williamson --- We've recently needed to add this functionality for current KVM based device assignment, VFIO should provide a way to do this too. An example of it being used in the Qemu VFIO driver can be found here: https://github.com/awilliam/qemu-vfio/blob/vfio/hw/vfio.c drivers/vfio/vfio_main.c | 4 ++++ include/linux/vfio.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 7e427fc..b9bb692 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -490,6 +490,10 @@ static long vfio_unl_ioctl(struct file *filep, ret = vfio_irq_eoi_eventfd(vdev, fd); break; + case VFIO_RESET_FUNCTION: + ret = pci_reset_function(vdev->pdev); + break; + default: return -EINVAL; } diff --git a/include/linux/vfio.h b/include/linux/vfio.h index f07d8fe..47d9bb9 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -215,6 +215,9 @@ struct vfio_dma_map { /* Re-enable INTx via eventfd */ #define VFIO_IRQ_EOI_EVENTFD _IOW(';', 110, int) +/* Reset PCI function */ +#define VFIO_RESET_FUNCTION _IO(';', 111) + /* * Reads, writes, and mmaps determine which PCI BAR (or config space) * from the high level bits of the file offset