* [Qemu-devel] [PATCH] device-assignment: register a reset function
[not found] <1284740181.14301.15.camel@x201>
@ 2010-11-15 11:33 ` Bernhard Kohl
2010-11-15 12:08 ` [Qemu-devel] " Jan Kiszka
0 siblings, 1 reply; 2+ messages in thread
From: Bernhard Kohl @ 2010-11-15 11:33 UTC (permalink / raw)
To: qemu-devel; +Cc: Bernhard Kohl, alex.williamson, 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>
---
Sorry for for the long delay. Finally we added Alex' suggestions
and rebased the patch.
Thanks
Bernhard
---
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..3f8de66 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);
+ uint32_t conf;
+
+ /* reset the bus master bit to avoid further DMA transfers */
+ conf = assigned_dev_pci_read_config(d, PCI_COMMAND, 2);
+ conf &= ~PCI_COMMAND_MASTER;
+ assigned_dev_pci_write_config(d, PCI_COMMAND, conf, 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] 2+ messages in thread
* [Qemu-devel] Re: [PATCH] device-assignment: register a reset function
2010-11-15 11:33 ` [Qemu-devel] [PATCH] device-assignment: register a reset function Bernhard Kohl
@ 2010-11-15 12:08 ` Jan Kiszka
0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2010-11-15 12:08 UTC (permalink / raw)
To: Bernhard Kohl; +Cc: alex.williamson, Thomas Ostler, kvm, Michael S. Tsirkin
[Wrong list, it's not upstream yet. I'm migrating the thread to kvm.]
Am 15.11.2010 12:33, 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>
> ---
> Sorry for for the long delay. Finally we added Alex' suggestions
> and rebased the patch.
>
> Thanks
> Bernhard
> ---
> 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..3f8de66 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);
> + uint32_t conf;
> +
> + /* reset the bus master bit to avoid further DMA transfers */
> + conf = assigned_dev_pci_read_config(d, PCI_COMMAND, 2);
> + conf &= ~PCI_COMMAND_MASTER;
> + assigned_dev_pci_write_config(d, PCI_COMMAND, conf, 2);
What about writing to /sys/bus/pci/devices/$DEVICE/reset? You probably
still need to put the command word into the reset state (ie. no RMW in
any case, just write 0), but the hardware should receive a reset as well
- if it is capable of doing a function-level reset, but we should at
least try.
> +}
> +
> 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,
Jan
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-11-15 12:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1284740181.14301.15.camel@x201>
2010-11-15 11:33 ` [Qemu-devel] [PATCH] device-assignment: register a reset function Bernhard Kohl
2010-11-15 12:08 ` [Qemu-devel] " Jan Kiszka
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).