qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
@ 2011-04-19 20:32 Alex Williamson
  2011-04-19 21:40 ` Randy Dunlap
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alex Williamson @ 2011-04-19 20:32 UTC (permalink / raw)
  To: pugs
  Cc: chrisw, linux-pci, linux-kernel, qemu-devel, aafabbri,
	alex.williamson, dwang2, benve

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 <alex.williamson@redhat.com>
---

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(-)

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 20:32 [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device Alex Williamson
@ 2011-04-19 21:40 ` Randy Dunlap
  2011-04-19 21:43   ` Chris Wright
  2011-04-19 22:07 ` Chris Wright
  2011-04-19 23:23 ` Tom Lyon
  2 siblings, 1 reply; 9+ messages in thread
From: Randy Dunlap @ 2011-04-19 21:40 UTC (permalink / raw)
  To: Alex Williamson
  Cc: chrisw, linux-pci, linux-kernel, qemu-devel, aafabbri, dwang2,
	pugs, benve

On Tue, 19 Apr 2011 14:32:59 -0600 Alex Williamson wrote:

> 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 <alex.williamson@redhat.com>
> ---
> 
> 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(-)
> 
> 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

I can't find include/linux/vfio.h in linux-next or mainline git, but
ioctls need to be documented in Documentation/ioctl/ioctl-number.txt....

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 21:40 ` Randy Dunlap
@ 2011-04-19 21:43   ` Chris Wright
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Wright @ 2011-04-19 21:43 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: chrisw, linux-pci, linux-kernel, qemu-devel, aafabbri,
	Alex Williamson, dwang2, pugs, benve

* Randy Dunlap (rdunlap@xenotime.net) wrote:
> I can't find include/linux/vfio.h in linux-next or mainline git, but
> ioctls need to be documented in Documentation/ioctl/ioctl-number.txt....

It is in the full patchset: https://github.com/pugs/vfio-linux-2.6

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 20:32 [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device Alex Williamson
  2011-04-19 21:40 ` Randy Dunlap
@ 2011-04-19 22:07 ` Chris Wright
  2011-04-19 22:22   ` Alex Williamson
  2011-04-19 23:23 ` Tom Lyon
  2 siblings, 1 reply; 9+ messages in thread
From: Chris Wright @ 2011-04-19 22:07 UTC (permalink / raw)
  To: Alex Williamson
  Cc: chrisw, linux-pci, linux-kernel, qemu-devel, aafabbri, dwang2,
	pugs, benve

* Alex Williamson (alex.williamson@redhat.com) wrote:
> 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.

Shouldn't there be a reset when binding/unbinding vfio to/from a pci
device?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 22:07 ` Chris Wright
@ 2011-04-19 22:22   ` Alex Williamson
  2011-04-19 22:26     ` Chris Wright
  0 siblings, 1 reply; 9+ messages in thread
From: Alex Williamson @ 2011-04-19 22:22 UTC (permalink / raw)
  To: Chris Wright
  Cc: linux-pci, linux-kernel, qemu-devel, aafabbri, dwang2, pugs,
	benve

On Tue, 2011-04-19 at 15:07 -0700, Chris Wright wrote:
> * Alex Williamson (alex.williamson@redhat.com) wrote:
> > 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.
> 
> Shouldn't there be a reset when binding/unbinding vfio to/from a pci
> device?

There's already one when the /dev/vfioX file is opened, we should add
another on release, and probably add the same PCI save state store/load
that I'm proposing for KVM across those.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 22:22   ` Alex Williamson
@ 2011-04-19 22:26     ` Chris Wright
  2011-04-19 22:30       ` Alex Williamson
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Wright @ 2011-04-19 22:26 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Chris Wright, linux-pci, linux-kernel, qemu-devel, aafabbri,
	dwang2, pugs, benve

* Alex Williamson (alex.williamson@redhat.com) wrote:
> On Tue, 2011-04-19 at 15:07 -0700, Chris Wright wrote:
> > * Alex Williamson (alex.williamson@redhat.com) wrote:
> > > 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.
> > 
> > Shouldn't there be a reset when binding/unbinding vfio to/from a pci
> > device?
> 
> There's already one when the /dev/vfioX file is opened, we should add
> another on release, and probably add the same PCI save state store/load
> that I'm proposing for KVM across those.  Thanks,

Hmm, I looked and didn't see it, hence the question.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 22:26     ` Chris Wright
@ 2011-04-19 22:30       ` Alex Williamson
  2011-04-19 22:37         ` Chris Wright
  0 siblings, 1 reply; 9+ messages in thread
From: Alex Williamson @ 2011-04-19 22:30 UTC (permalink / raw)
  To: Chris Wright
  Cc: linux-pci, linux-kernel, qemu-devel, aafabbri, dwang2, pugs,
	benve

On Tue, 2011-04-19 at 15:26 -0700, Chris Wright wrote:
> * Alex Williamson (alex.williamson@redhat.com) wrote:
> > On Tue, 2011-04-19 at 15:07 -0700, Chris Wright wrote:
> > > * Alex Williamson (alex.williamson@redhat.com) wrote:
> > > > 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.
> > > 
> > > Shouldn't there be a reset when binding/unbinding vfio to/from a pci
> > > device?
> > 
> > There's already one when the /dev/vfioX file is opened, we should add
> > another on release, and probably add the same PCI save state store/load
> > that I'm proposing for KVM across those.  Thanks,
> 
> Hmm, I looked and didn't see it, hence the question.

vfio_open() -> pci_reset_function()
https://github.com/pugs/vfio-linux-2.6/blob/vfio/drivers/vfio/vfio_main.c

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 22:30       ` Alex Williamson
@ 2011-04-19 22:37         ` Chris Wright
  0 siblings, 0 replies; 9+ messages in thread
From: Chris Wright @ 2011-04-19 22:37 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Chris Wright, linux-pci, linux-kernel, qemu-devel, aafabbri,
	dwang2, pugs, benve

* Alex Williamson (alex.williamson@redhat.com) wrote:
> On Tue, 2011-04-19 at 15:26 -0700, Chris Wright wrote:
> > * Alex Williamson (alex.williamson@redhat.com) wrote:
> > > On Tue, 2011-04-19 at 15:07 -0700, Chris Wright wrote:
> > > > * Alex Williamson (alex.williamson@redhat.com) wrote:
> > > > > 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.
> > > > 
> > > > Shouldn't there be a reset when binding/unbinding vfio to/from a pci
> > > > device?
> > > 
> > > There's already one when the /dev/vfioX file is opened, we should add
> > > another on release, and probably add the same PCI save state store/load
> > > that I'm proposing for KVM across those.  Thanks,
> > 
> > Hmm, I looked and didn't see it, hence the question.
> 
> vfio_open() -> pci_reset_function()
> https://github.com/pugs/vfio-linux-2.6/blob/vfio/drivers/vfio/vfio_main.c

Got it, thanks Alex.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device
  2011-04-19 20:32 [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device Alex Williamson
  2011-04-19 21:40 ` Randy Dunlap
  2011-04-19 22:07 ` Chris Wright
@ 2011-04-19 23:23 ` Tom Lyon
  2 siblings, 0 replies; 9+ messages in thread
From: Tom Lyon @ 2011-04-19 23:23 UTC (permalink / raw)
  To: Alex Williamson
  Cc: chrisw, linux-pci, linux-kernel, qemu-devel, aafabbri, dwang2,
	pugs, benve

On Tuesday, April 19, 2011 01:32:59 pm Alex Williamson wrote:
> 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 <alex.williamson@redhat.com>
> ---
> 
> 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(-)
> 
> 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

Applied.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-04-19 23:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-19 20:32 [Qemu-devel] [PATCH] vfio: Add an ioctl to reset the device Alex Williamson
2011-04-19 21:40 ` Randy Dunlap
2011-04-19 21:43   ` Chris Wright
2011-04-19 22:07 ` Chris Wright
2011-04-19 22:22   ` Alex Williamson
2011-04-19 22:26     ` Chris Wright
2011-04-19 22:30       ` Alex Williamson
2011-04-19 22:37         ` Chris Wright
2011-04-19 23:23 ` Tom Lyon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).