From: Jan Kiszka <jan.kiszka@web.de>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm <kvm@vger.kernel.org>, Alex Williamson <alex.williamson@redhat.com>
Subject: [PATCH] pci-assign: Do not reset the device unless the kernel supports it
Date: Mon, 06 Jun 2011 23:30:55 +0200 [thread overview]
Message-ID: <4DED470F.4020203@web.de> (raw)
From: Jan Kiszka <jan.kiszka@siemens.com>
At least kernels 2.6.38 and 2.6.39 do not properly support issuing a
reset on an assigned device and corrupt its config space. Prevent
this by checking for a host kernel with the required support, tagged by
the to-be-introduced KVM_CAP_DEVICE_RESET.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
PS: What's the state of those KVM patches? Will they make it into 3.0?
hw/device-assignment.c | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 57d8dc0..97a1450 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -1689,26 +1689,31 @@ static const VMStateDescription vmstate_assigned_device = {
static void reset_assigned_device(DeviceState *dev)
{
PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev);
+#ifdef KVM_CAP_DEVICE_RESET
AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev);
char reset_file[64];
const char reset[] = "1";
int fd, ret;
- snprintf(reset_file, sizeof(reset_file),
- "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/reset",
- adev->host.seg, adev->host.bus, adev->host.dev, adev->host.func);
-
- /*
- * Issue a device reset via pci-sysfs. Note that we use write(2) here
- * and ignore the return value because some kernels have a bug that
- * returns 0 rather than bytes written on success, sending us into an
- * infinite retry loop using other write mechanisms.
- */
- fd = open(reset_file, O_WRONLY);
- if (fd != -1) {
- ret = write(fd, reset, strlen(reset));
- close(fd);
+ if (kvm_check_extension(kvm_state, KVM_CAP_DEVICE_RESET) {
+ snprintf(reset_file, sizeof(reset_file),
+ "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/reset",
+ adev->host.seg, adev->host.bus, adev->host.dev,
+ adev->host.func);
+
+ /*
+ * Issue a device reset via pci-sysfs. Note that we use write(2) here
+ * and ignore the return value because some kernels have a bug that
+ * returns 0 rather than bytes written on success, sending us into an
+ * infinite retry loop using other write mechanisms.
+ */
+ fd = open(reset_file, O_WRONLY);
+ if (fd != -1) {
+ ret = write(fd, reset, strlen(reset));
+ close(fd);
+ }
}
+#endif /* KVM_CAP_DEVICE_RESET */
/*
* When a 0 is written to the command register, the device is logically
next reply other threads:[~2011-06-06 21:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-06 21:30 Jan Kiszka [this message]
2011-06-06 21:48 ` [PATCH] pci-assign: Do not reset the device unless the kernel supports it Alex Williamson
2011-06-06 22:04 ` Jan Kiszka
2011-06-07 8:06 ` Avi Kivity
2011-06-07 8:14 ` Jan Kiszka
2011-06-07 18:46 ` Alex Williamson
2011-06-08 7:52 ` Jan Kiszka
2011-06-09 8:10 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DED470F.4020203@web.de \
--to=jan.kiszka@web.de \
--cc=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox