public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] device-assignment: register a reset function
@ 2010-11-16 14:05 Bernhard Kohl
  2010-11-16 14:37 ` Alex Williamson
  2010-11-17 14:09 ` Marcelo Tosatti
  0 siblings, 2 replies; 4+ messages in thread
From: Bernhard Kohl @ 2010-11-16 14:05 UTC (permalink / raw)
  To: kvm; +Cc: alex.williamson, jan.kiszka, Bernhard Kohl, Thomas Ostler

This is necessary because during reboot of a VM the assigned devices
continue DMA transfers which causes memory corruption.

Signed-off-by: Thomas Ostler <thomas.ostler@nsn.com>
Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
---
Changes v1 -> v2:
- use defined macros, e.g. PCI_COMMAND
- write all zero to the command register to disconnect the device logically
---
 hw/device-assignment.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 5f5bde1..8d5a609 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -1434,6 +1434,17 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
     dev->msix_table_page = NULL;
 }
 
+static void reset_assigned_device(DeviceState *dev)
+{
+    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev);
+
+    /*
+     * When a 0 is written to the command register, the device is logically
+     * disconnected from the PCI bus. This avoids further DMA transfers.
+     */
+    assigned_dev_pci_write_config(d, PCI_COMMAND, 0, 2);
+}
+
 static int assigned_initfn(struct PCIDevice *pci_dev)
 {
     AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
@@ -1544,6 +1555,7 @@ static PCIDeviceInfo assign_info = {
     .qdev.name    = "pci-assign",
     .qdev.desc    = "pass through host pci devices to the guest",
     .qdev.size    = sizeof(AssignedDevice),
+    .qdev.reset   = reset_assigned_device,
     .init         = assigned_initfn,
     .exit         = assigned_exitfn,
     .config_read  = assigned_dev_pci_read_config,
-- 
1.7.2.3


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

* Re: [PATCH v2] device-assignment: register a reset function
  2010-11-16 14:05 [PATCH v2] device-assignment: register a reset function Bernhard Kohl
@ 2010-11-16 14:37 ` Alex Williamson
  2010-11-16 14:49   ` Jan Kiszka
  2010-11-17 14:09 ` Marcelo Tosatti
  1 sibling, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2010-11-16 14:37 UTC (permalink / raw)
  To: Bernhard Kohl; +Cc: kvm, jan.kiszka, Thomas Ostler

On Tue, 2010-11-16 at 15:05 +0100, Bernhard Kohl wrote:
> This is necessary because during reboot of a VM the assigned devices
> continue DMA transfers which causes memory corruption.
> 
> Signed-off-by: Thomas Ostler <thomas.ostler@nsn.com>
> Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
> ---
> Changes v1 -> v2:
> - use defined macros, e.g. PCI_COMMAND
> - write all zero to the command register to disconnect the device logically
> ---
>  hw/device-assignment.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)

Looks good to me.

Acked-by: Alex Williamson <alex.williamson@redhat.com>

> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> index 5f5bde1..8d5a609 100644
> --- a/hw/device-assignment.c
> +++ b/hw/device-assignment.c
> @@ -1434,6 +1434,17 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
>      dev->msix_table_page = NULL;
>  }
>  
> +static void reset_assigned_device(DeviceState *dev)
> +{
> +    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev);
> +
> +    /*
> +     * When a 0 is written to the command register, the device is logically
> +     * disconnected from the PCI bus. This avoids further DMA transfers.
> +     */
> +    assigned_dev_pci_write_config(d, PCI_COMMAND, 0, 2);
> +}
> +
>  static int assigned_initfn(struct PCIDevice *pci_dev)
>  {
>      AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
> @@ -1544,6 +1555,7 @@ static PCIDeviceInfo assign_info = {
>      .qdev.name    = "pci-assign",
>      .qdev.desc    = "pass through host pci devices to the guest",
>      .qdev.size    = sizeof(AssignedDevice),
> +    .qdev.reset   = reset_assigned_device,
>      .init         = assigned_initfn,
>      .exit         = assigned_exitfn,
>      .config_read  = assigned_dev_pci_read_config,




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

* Re: [PATCH v2] device-assignment: register a reset function
  2010-11-16 14:37 ` Alex Williamson
@ 2010-11-16 14:49   ` Jan Kiszka
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2010-11-16 14:49 UTC (permalink / raw)
  To: Alex Williamson; +Cc: Bernhard Kohl, kvm, Thomas Ostler

Am 16.11.2010 15:37, Alex Williamson wrote:
> On Tue, 2010-11-16 at 15:05 +0100, Bernhard Kohl wrote:
>> This is necessary because during reboot of a VM the assigned devices
>> continue DMA transfers which causes memory corruption.
>>
>> Signed-off-by: Thomas Ostler <thomas.ostler@nsn.com>
>> Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
>> ---
>> Changes v1 -> v2:
>> - use defined macros, e.g. PCI_COMMAND
>> - write all zero to the command register to disconnect the device logically
>> ---
>>  hw/device-assignment.c |   12 ++++++++++++
>>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> Looks good to me.
> 
> Acked-by: Alex Williamson <alex.williamson@redhat.com>

Acked-by: Jan Kiszka <jan.kiszka@siemens.com>

> 
>> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
>> index 5f5bde1..8d5a609 100644
>> --- a/hw/device-assignment.c
>> +++ b/hw/device-assignment.c
>> @@ -1434,6 +1434,17 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
>>      dev->msix_table_page = NULL;
>>  }
>>  
>> +static void reset_assigned_device(DeviceState *dev)
>> +{
>> +    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev);
>> +
>> +    /*
>> +     * When a 0 is written to the command register, the device is logically
>> +     * disconnected from the PCI bus. This avoids further DMA transfers.
>> +     */
>> +    assigned_dev_pci_write_config(d, PCI_COMMAND, 0, 2);
>> +}
>> +
>>  static int assigned_initfn(struct PCIDevice *pci_dev)
>>  {
>>      AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
>> @@ -1544,6 +1555,7 @@ static PCIDeviceInfo assign_info = {
>>      .qdev.name    = "pci-assign",
>>      .qdev.desc    = "pass through host pci devices to the guest",
>>      .qdev.size    = sizeof(AssignedDevice),
>> +    .qdev.reset   = reset_assigned_device,
>>      .init         = assigned_initfn,
>>      .exit         = assigned_exitfn,
>>      .config_read  = assigned_dev_pci_read_config,

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

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

* Re: [PATCH v2] device-assignment: register a reset function
  2010-11-16 14:05 [PATCH v2] device-assignment: register a reset function Bernhard Kohl
  2010-11-16 14:37 ` Alex Williamson
@ 2010-11-17 14:09 ` Marcelo Tosatti
  1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2010-11-17 14:09 UTC (permalink / raw)
  To: Bernhard Kohl; +Cc: kvm, alex.williamson, jan.kiszka, Thomas Ostler

On Tue, Nov 16, 2010 at 03:05:29PM +0100, Bernhard Kohl wrote:
> This is necessary because during reboot of a VM the assigned devices
> continue DMA transfers which causes memory corruption.
> 
> Signed-off-by: Thomas Ostler <thomas.ostler@nsn.com>
> Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
> ---
> Changes v1 -> v2:
> - use defined macros, e.g. PCI_COMMAND
> - write all zero to the command register to disconnect the device logically
> ---
>  hw/device-assignment.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)

Applied, thanks.


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

end of thread, other threads:[~2010-11-17 14:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-16 14:05 [PATCH v2] device-assignment: register a reset function Bernhard Kohl
2010-11-16 14:37 ` Alex Williamson
2010-11-16 14:49   ` Jan Kiszka
2010-11-17 14:09 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox