kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH qemu-kvm] device-assignment: add config fd qdev property
@ 2010-05-19 19:00 Chris Wright
  2010-05-19 19:08 ` Alex Williamson
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Chris Wright @ 2010-05-19 19:00 UTC (permalink / raw)
  To: kvm; +Cc: Alex Williamson, Chris Wright

When libvirt launches a guest it first chowns the relevenat
/sys/bus/pci/.../config file for an assigned device then drops privileges.

This causes an issue for device assignment because despite being file
owner, the sysfs config space file checks for CAP_SYS_ADMIN before
allowing access to device dependent config space.

This adds a new qdev configfd property which allows libvirt to open the
sysfs config space file and give qemu an already opened file descriptor.
Along with a change pending for the 2.6.35 kernel, this allows the
capability check to compare against privileges from when the file was
opened.

Signed-off-by: Chris Wright <chrisw@redhat.com>
---
 hw/device-assignment.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index eb31c78..172f0c9 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -612,12 +612,15 @@ static int get_real_device(AssignedDevice *pci_dev, uint16_t r_seg,
 
     snprintf(name, sizeof(name), "%sconfig", dir);
 
-    fd = open(name, O_RDWR);
+    fd = dev->config_fd;
     if (fd == -1) {
-        fprintf(stderr, "%s: %s: %m\n", __func__, name);
-        return 1;
+        fd = open(name, O_RDWR);
+        if (fd == -1) {
+            fprintf(stderr, "%s: %s: %m\n", __func__, name);
+            return 1;
+        }
+        dev->config_fd = fd;
     }
-    dev->config_fd = fd;
 again:
     r = read(fd, pci_dev->dev.config, pci_config_size(&pci_dev->dev));
     if (r < 0) {
@@ -1433,6 +1436,7 @@ static PCIDeviceInfo assign_info = {
     .qdev.props   = (Property[]) {
         DEFINE_PROP("host", AssignedDevice, host, qdev_prop_hostaddr, PCIHostDevice),
         DEFINE_PROP_UINT32("iommu", AssignedDevice, use_iommu, 1),
+        DEFINE_PROP_INT32("configfd", AssignedDevice, real_device.config_fd, -1),
         DEFINE_PROP_END_OF_LIST(),
     },
 };

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

end of thread, other threads:[~2010-05-31 20:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-19 19:00 [PATCH qemu-kvm] device-assignment: add config fd qdev property Chris Wright
2010-05-19 19:08 ` Alex Williamson
2010-05-19 19:18 ` Anthony Liguori
2010-05-19 21:10   ` Chris Wright
2010-05-19 21:50     ` Anthony Liguori
2010-05-19 21:59       ` Chris Wright
2010-05-19 22:27         ` Anthony Liguori
2010-05-20 10:06   ` Daniel P. Berrange
2010-05-20 12:11   ` Markus Armbruster
2010-05-24 16:53 ` Alex Williamson
2010-05-24 18:20   ` Chris Wright
2010-05-25  6:43   ` Markus Armbruster
2010-05-25 21:14     ` Alex Williamson
2010-05-31 20:22   ` Marcelo Tosatti

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