From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH qemu-kvm] device-assignment: add config fd qdev property Date: Wed, 19 May 2010 14:18:35 -0500 Message-ID: <4BF4398B.50902@codemonkey.ws> References: <20100519190041.GK28275@x200.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Alex Williamson To: Chris Wright Return-path: Received: from mail-pv0-f174.google.com ([74.125.83.174]:63677 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991Ab0ESTSo (ORCPT ); Wed, 19 May 2010 15:18:44 -0400 Received: by pva18 with SMTP id 18so1131659pva.19 for ; Wed, 19 May 2010 12:18:43 -0700 (PDT) In-Reply-To: <20100519190041.GK28275@x200.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On 05/19/2010 02:00 PM, Chris Wright wrote: > 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 > An fd as a qdev property seems like a bad idea to me. I'm not sure I have a better suggestion though. Regards, Anthony Liguori > --- > 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(), > }, > }; > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >