From: Lucas Meneghel Rodrigues Subject: Re: [Autotest] [PATCH] KVM test: Add PCI pass through test Date: Wed, 14 Oct 2009 11:45:12 -0300 Message-ID: <6ac58f4f0910140745n3cbdf294qb36dd5cb19cab7ae@mail.gmail.com> References: <1255522080-10570-1-git-send-email-lmr@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: autotest@test.kernel.org Return-path: Received: from mail-pz0-f188.google.com ([209.85.222.188]:58332 "EHLO mail-pz0-f188.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933416AbZJNOpu convert rfc822-to-8bit (ORCPT ); Wed, 14 Oct 2009 10:45:50 -0400 Received: by pzk26 with SMTP id 26so10008944pzk.4 for ; Wed, 14 Oct 2009 07:45:13 -0700 (PDT) In-Reply-To: <1255522080-10570-1-git-send-email-lmr@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: =46YI, Amit pointed out that the correct name for this test would be PC= I device assignment, so the final version of this patch will be called PCI device assignment instead. On Wed, Oct 14, 2009 at 9:08 AM, Lucas Meneghel Rodrigues wrote: > Add a new PCI pass trough test. It supports both SR-IOV virtual > functions and physical NIC card pass through. > > Single Root I/O Virtualization (SR-IOV) allows a single PCI device to > be shared amongst multiple virtual machines while retaining the > performance benefit of assigning a PCI device to a virtual machine. > A common example is where a single SR-IOV capable NIC - with perhaps > only a single physical network port - might be shared with multiple > virtual machines by assigning a virtual function to each VM. > > SR-IOV support is implemented in the kernel. The core implementation = is > contained in the PCI subsystem, but there must also be driver support > for both the Physical Function (PF) and Virtual Function (VF) devices= =2E > With an SR-IOV capable device one can allocate VFs from a PF. The VFs > surface as PCI devices which are backed on the physical PCI device by > resources (queues, and register sets). > > Device support: > > In 2.6.30, the Intel=AE 82576 Gigabit Ethernet Controller is the only > SR-IOV capable device supported. The igb driver has PF support and th= e > igbvf has VF support. > > In 2.6.31 the Neterion=AE X3100=99 is supported as well. This device = uses > the same vxge driver for the PF as well as the VFs. > > In order to configure the test: > > =A0* For SR-IOV virtual functions passthrough, we could specify the > =A0 =A0module parameter 'max_vfs' in config file. > =A0* For physical NIC card pass through, we should specify the device > =A0 =A0name(s). > > Signed-off-by: Yolkfull Chow > --- > =A0client/tests/kvm/kvm_tests.cfg.sample | =A0 11 ++- > =A0client/tests/kvm/kvm_utils.py =A0 =A0 =A0 =A0 | =A0278 +++++++++++= ++++++++++++++++++++++ > =A0client/tests/kvm/kvm_vm.py =A0 =A0 =A0 =A0 =A0 =A0| =A0 72 +++++++= ++ > =A03 files changed, 360 insertions(+), 1 deletions(-) > > diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm= /kvm_tests.cfg.sample > index cc3228a..1dad188 100644 > --- a/client/tests/kvm/kvm_tests.cfg.sample > +++ b/client/tests/kvm/kvm_tests.cfg.sample > @@ -786,13 +786,22 @@ variants: > =A0 =A0 =A0 =A0 only default > =A0 =A0 =A0 =A0 image_format =3D raw > > - > =A0variants: > =A0 =A0 - @smallpages: > =A0 =A0 - hugepages: > =A0 =A0 =A0 =A0 pre_command =3D "/usr/bin/python scripts/hugepage.py = /mnt/kvm_hugepage" > =A0 =A0 =A0 =A0 extra_params +=3D " -mem-path /mnt/kvm_hugepage" > > +variants: > + =A0 =A0- @no_passthrough: > + =A0 =A0 =A0 =A0pass_through =3D no > + =A0 =A0- nic_passthrough: > + =A0 =A0 =A0 =A0pass_through =3D pf > + =A0 =A0 =A0 =A0passthrough_devs =3D eth1 > + =A0 =A0- vfs_passthrough: > + =A0 =A0 =A0 =A0pass_through =3D vf > + =A0 =A0 =A0 =A0max_vfs =3D 7 > + =A0 =A0 =A0 =A0vfs_count =3D 7 > > =A0variants: > =A0 =A0 - @basic: > diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_uti= ls.py > index 53b664a..0e3398c 100644 > --- a/client/tests/kvm/kvm_utils.py > +++ b/client/tests/kvm/kvm_utils.py > @@ -788,3 +788,281 @@ def md5sum_file(filename, size=3DNone): > =A0 =A0 =A0 =A0 size -=3D len(data) > =A0 =A0 f.close() > =A0 =A0 return o.hexdigest() > + > + > +def get_full_id(pci_id): > + =A0 =A0""" > + =A0 =A0Get full PCI ID of pci_id. > + =A0 =A0""" > + =A0 =A0cmd =3D "lspci -D | awk '/%s/ {print $1}'" % pci_id > + =A0 =A0status, full_id =3D commands.getstatusoutput(cmd) > + =A0 =A0if status !=3D 0: > + =A0 =A0 =A0 =A0return None > + =A0 =A0return full_id > + > + > +def get_vendor_id(pci_id): > + =A0 =A0""" > + =A0 =A0Check out the device vendor ID according to PCI ID. > + =A0 =A0""" > + =A0 =A0cmd =3D "lspci -n | awk '/%s/ {print $3}'" % pci_id > + =A0 =A0return re.sub(":", " ", commands.getoutput(cmd)) > + > + > +def release_dev(pci_id, pci_dict): > + =A0 =A0""" > + =A0 =A0Release a single PCI device. > + > + =A0 =A0@param pci_id: PCI ID of a given PCI device > + =A0 =A0@param pci_dict: Dictionary with information about PCI devic= es > + =A0 =A0""" > + =A0 =A0base_dir =3D "/sys/bus/pci" > + =A0 =A0full_id =3D get_full_id(pci_id) > + =A0 =A0vendor_id =3D get_vendor_id(pci_id) > + =A0 =A0drv_path =3D os.path.join(base_dir, "devices/%s/driver" % fu= ll_id) > + =A0 =A0if 'pci-stub' in os.readlink(drv_path): > + =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/new_id" % (vendor_id, drv_pa= th) > + =A0 =A0 =A0 =A0if os.system(cmd): > + =A0 =A0 =A0 =A0 =A0 =A0return False > + > + =A0 =A0 =A0 =A0stub_path =3D os.path.join(base_dir, "drivers/pci-st= ub") > + =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/unbind" % (full_id, stub_pat= h) > + =A0 =A0 =A0 =A0if os.system(cmd): > + =A0 =A0 =A0 =A0 =A0 =A0return False > + > + =A0 =A0 =A0 =A0prev_driver =3D pci_dict[pci_id] > + =A0 =A0 =A0 =A0cmd =3D "echo '%s' > %s/bind" % (full_id, prev_drive= r) > + =A0 =A0 =A0 =A0if os.system(cmd): > + =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0return True > + > + > +def release_pci_devs(pci_dict): > + =A0 =A0""" > + =A0 =A0Release all PCI devices assigned to host. > + > + =A0 =A0@param pci_dict: Dictionary with information about PCI devic= es > + =A0 =A0""" > + =A0 =A0for pci_id in pci_dict: > + =A0 =A0 =A0 =A0if not release_dev(pci_id, pci_dict): > + =A0 =A0 =A0 =A0 =A0 =A0logging.error("Failed to release device [%s]= to host" % pci_id) > + =A0 =A0 =A0 =A0else: > + =A0 =A0 =A0 =A0 =A0 =A0logging.info("Release device [%s] successful= ly" % pci_id) > + > + > +class PassThrough(object): > + =A0 =A0""" > + =A0 =A0Request passthroughable devices on host. It will check wheth= er to request > + =A0 =A0PF (physical NIC cards) or VF (Virtual Functions). > + =A0 =A0""" > + =A0 =A0def __init__(self, type=3D"nic_vf", max_vfs=3DNone, names=3D= None): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Initialize parameter 'type' which could be: > + =A0 =A0 =A0 =A0nic_vf: Virtual Functions > + =A0 =A0 =A0 =A0nic_pf: Physical NIC card > + =A0 =A0 =A0 =A0mixed: =A0Both includes VFs and PFs > + > + =A0 =A0 =A0 =A0If pass through Physical NIC cards, we need to speci= fy which devices > + =A0 =A0 =A0 =A0to be assigned, e.g. 'eth1 eth2'. > + > + =A0 =A0 =A0 =A0If pass through Virtual Functions, we need to specif= y how many vfs > + =A0 =A0 =A0 =A0are going to be assigned, e.g. passthrough_count =3D= 8 and max_vfs in > + =A0 =A0 =A0 =A0config file. > + > + =A0 =A0 =A0 =A0@param type: Pass through device's type > + =A0 =A0 =A0 =A0@param max_vfs: parameter of module 'igb' > + =A0 =A0 =A0 =A0@param names: Physical NIC cards' names, e.g.'eth1 e= th2 ...' > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0self.type =3D type > + =A0 =A0 =A0 =A0if max_vfs: > + =A0 =A0 =A0 =A0 =A0 =A0self.max_vfs =3D int(max_vfs) > + =A0 =A0 =A0 =A0if names: > + =A0 =A0 =A0 =A0 =A0 =A0self.name_list =3D names.split() > + > + > + =A0 =A0def sr_iov_setup(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Setup SR-IOV environment, check if module 'igb' is l= oaded with > + =A0 =A0 =A0 =A0parameter 'max_vfs'. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0re_probe =3D False > + =A0 =A0 =A0 =A0# Check whether the module 'igb' is loaded > + =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput('lsmod | grep igb'= ) > + =A0 =A0 =A0 =A0if s: > + =A0 =A0 =A0 =A0 =A0 =A0re_probe =3D True > + =A0 =A0 =A0 =A0elif not self.chk_vfs_count(): > + =A0 =A0 =A0 =A0 =A0 =A0os.system("modprobe -r igb") > + =A0 =A0 =A0 =A0 =A0 =A0re_probe =3D True > + > + =A0 =A0 =A0 =A0# Re-probe module 'igb' > + =A0 =A0 =A0 =A0if re_probe: > + =A0 =A0 =A0 =A0 =A0 =A0cmd =3D "modprobe igb max_vfs=3D%d" % self.m= ax_vfs > + =A0 =A0 =A0 =A0 =A0 =A0s, o =3D commands.getstatusoutput(cmd) > + =A0 =A0 =A0 =A0 =A0 =A0if s: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0 =A0 =A0if not self.chk_vfs_count(): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0return True > + > + > + =A0 =A0def get_vfs_count(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Get Vfs count number according to 'max_vfs' > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0cmd =3D "lspci | grep 'Virtual Function' | wc -l" > + =A0 =A0 =A0 =A0return int(commands.getoutput(cmd)) > + > + > + =A0 =A0def chk_vfs_count(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Check VFs count number according to parameter 'max_v= fs'. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0if self.get_vfs_count() !=3D (self.max_vfs * 2): > + =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0return True > + > + > + =A0 =A0def _get_pci_id(self, name, search_str): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Get the device's PCI ID according to name. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0cmd =3D "ethtool -i %s | awk '/bus-info/ {print $2}'= " % name > + =A0 =A0 =A0 =A0s, pci_id =3D commands.getstatusoutput(cmd) > + =A0 =A0 =A0 =A0if not (s or "Cannot get driver information" in pci_= id): > + =A0 =A0 =A0 =A0 =A0 =A0return pci_id[5:] > + > + =A0 =A0 =A0 =A0cmd =3D "lspci | awk '/%s/ {print $1}'" % search_str > + =A0 =A0 =A0 =A0pci_ids =3D [id for id in commands.getoutput(cmd).sp= litlines()] > + =A0 =A0 =A0 =A0nic_id =3D int(re.search('[0-9]+', name).group(0)) > + =A0 =A0 =A0 =A0if (len(pci_ids) - 1) < nic_id: > + =A0 =A0 =A0 =A0 =A0 =A0return None > + =A0 =A0 =A0 =A0return pci_ids[nic_id] > + > + > + =A0 =A0def _write_to_file(self, content, file_path): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Write some content to a file. > + > + =A0 =A0 =A0 =A0@param content: Content to be written. > + =A0 =A0 =A0 =A0@param file_path: Path for the file. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0success =3D False > + =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0file =3D open(file_path, 'w') > + =A0 =A0 =A0 =A0except IOError: > + =A0 =A0 =A0 =A0 =A0 =A0return success > + > + =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0file.write(content) > + =A0 =A0 =A0 =A0 =A0 =A0success =3D True > + =A0 =A0 =A0 =A0except IOError: > + =A0 =A0 =A0 =A0 =A0 =A0pass > + =A0 =A0 =A0 =A0finally: > + =A0 =A0 =A0 =A0 =A0 =A0file.close() > + > + =A0 =A0 =A0 =A0return success > + > + > + =A0 =A0def is_binded_to_stub(self, full_id): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Verify whether the device with full_id is already bi= nded to pci-stub. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0base_dir =3D "/sys/bus/pci" > + =A0 =A0 =A0 =A0stub_path =3D os.path.join(base_dir, "drivers/pci-st= ub") > + =A0 =A0 =A0 =A0if os.path.exists(os.path.join(stub_path, full_id)): > + =A0 =A0 =A0 =A0 =A0 =A0return True > + =A0 =A0 =A0 =A0return False > + > + > + =A0 =A0def request_devs(self, count, pt_file, setup=3DTrue): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Implement setup process: unbind the PCI device and t= hen bind it > + =A0 =A0 =A0 =A0to pci-stub driver. > + > + =A0 =A0 =A0 =A0@return: a list of successfully requested devices' P= CI IDs. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0base_dir =3D "/sys/bus/pci" > + =A0 =A0 =A0 =A0stub_path =3D os.path.join(base_dir, "drivers/pci-st= ub") > + > + =A0 =A0 =A0 =A0self.pci_ids =3D self.catch_devs(int(count)) > + =A0 =A0 =A0 =A0logging.debug("Catch_devs has found pci_ids: %s" % s= elf.pci_ids) > + > + =A0 =A0 =A0 =A0if setup: > + =A0 =A0 =A0 =A0 =A0 =A0requested_pci_ids =3D [] > + =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Going to setup devices: %s" %= self.pci_ids) > + =A0 =A0 =A0 =A0 =A0 =A0dev_prev_drivers =3D {} > + > + =A0 =A0 =A0 =A0 =A0 =A0# Setup all devices specified for passthroug= h to guest > + =A0 =A0 =A0 =A0 =A0 =A0for pci_id in self.pci_ids: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0full_id =3D get_full_id(pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not full_id: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0drv_path =3D os.path.join(base_dir, = "devices/%s/driver" % full_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev_prev_driver=3D os.path.realpath(= os.path.join(drv_path, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0os.readlink(drv_path))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev_prev_drivers[pci_id] =3D dev_pre= v_driver > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Judge whether the device driver ha= s been binded to stub > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.is_binded_to_stub(full_i= d): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Setting up de= vice: %s" % full_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_new_id =3D os.path.join= (stub_path, 'new_id') > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unbind_dev =3D os.path.join(= drv_path, 'unbind') > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stub_bind =3D os.path.join(s= tub_path, 'bind') > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vendor_id =3D get_vendor_id(= pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._write_to_file(v= endor_id, stub_new_id): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._write_to_file(f= ull_id, unbind_dev): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self._write_to_file(f= ull_id, stub_bind): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.is_binded_to_stu= b(full_id): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Reque= st device failed: %s" % pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Device [%s] a= lready binded to stub" % pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0requested_pci_ids.append(pci_id) > + =A0 =A0 =A0 =A0 =A0 =A0cPickle.dump(dev_prev_drivers, pt_file) > + =A0 =A0 =A0 =A0 =A0 =A0self.pci_ids =3D requested_pci_ids > + =A0 =A0 =A0 =A0return self.pci_ids > + > + > + =A0 =A0def catch_vf_devs(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Catch all VFs PCI IDs and return as a list. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0if not self.sr_iov_setup(): > + =A0 =A0 =A0 =A0 =A0 =A0return [] > + > + =A0 =A0 =A0 =A0cmd =3D "lspci | awk '/Virtual Function/ {print $1}'= " > + =A0 =A0 =A0 =A0return commands.getoutput(cmd).split() > + > + > + =A0 =A0def catch_pf_devs(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Catch all PFs PCI IDs. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0pf_ids =3D [] > + =A0 =A0 =A0 =A0for name in self.name_list: > + =A0 =A0 =A0 =A0 =A0 =A0pf_id =3D self._get_pci_id(name, "Ethernet") > + =A0 =A0 =A0 =A0 =A0 =A0if not pf_id: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + =A0 =A0 =A0 =A0 =A0 =A0pf_ids.append(pf_id) > + =A0 =A0 =A0 =A0return pf_ids > + > + > + =A0 =A0def catch_devs(self, count): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Check out all devices' PCI IDs according to their na= me. > + > + =A0 =A0 =A0 =A0@param count: count number of PCI devices needed for= pass through > + =A0 =A0 =A0 =A0@return: a list of all devices' PCI IDs > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0if self.type =3D=3D "nic_vf": > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.catch_vf_devs() > + =A0 =A0 =A0 =A0elif self.type =3D=3D "nic_pf": > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.catch_pf_devs() > + =A0 =A0 =A0 =A0elif self.type =3D=3D "mixed": > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids =3D self.catch_vf_devs() > + =A0 =A0 =A0 =A0 =A0 =A0vf_ids.extend(self.catch_pf_devs()) > + =A0 =A0 =A0 =A0return vf_ids[0:count] > diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py > index 82f1eb4..a0b01fe 100755 > --- a/client/tests/kvm/kvm_vm.py > +++ b/client/tests/kvm/kvm_vm.py > @@ -298,6 +298,30 @@ class VM: > =A0 =A0 =A0 =A0 elif params.get("uuid"): > =A0 =A0 =A0 =A0 =A0 =A0 qemu_cmd +=3D " -uuid %s" % params.get("uuid"= ) > > + =A0 =A0 =A0 =A0# Check whether pci_passthrough is turned on > + =A0 =A0 =A0 =A0if not params.get("pass_through") =3D=3D "no": > + =A0 =A0 =A0 =A0 =A0 =A0pt_type =3D params.get("pass_through") > + > + =A0 =A0 =A0 =A0 =A0 =A0# Virtual Functions pass through > + =A0 =A0 =A0 =A0 =A0 =A0if params.get("pass_through") =3D=3D "nic_vf= ": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough(type=3D= pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 max_vfs=3Dparams.get("max_vfs")) > + =A0 =A0 =A0 =A0 =A0 =A0# Physical NIC card pass through > + =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D "nic_= pf": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough(type=3D= pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 names=3Dparams.get("passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D "mixe= d": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough(type=3D= pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 max_vfs=3Dparams.get("max_vfs"), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 names=3Dparams.get("passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0pt_count =3D params.get("passthrough_count") > + =A0 =A0 =A0 =A0 =A0 =A0pt_db_file =3D open("/tmp/passthrough_db", "= w") > + =A0 =A0 =A0 =A0 =A0 =A0self.pt_pci_ids =3D pt.request_devs(pt_count= , pt_file=3Dpt_db_file, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0setup=3DFalse) > + =A0 =A0 =A0 =A0 =A0 =A0pt_db_file.close() > + =A0 =A0 =A0 =A0 =A0 =A0for pci_id in self.pt_pci_ids: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0qemu_cmd +=3D " -pcidevice host=3D%s= " % pci_id > + > =A0 =A0 =A0 =A0 return qemu_cmd > > > @@ -380,6 +404,37 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.uuid =3D f.read().strip() > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 f.close() > > + =A0 =A0 =A0 =A0 =A0 =A0# Request specified PCI devices for assignme= nt > + =A0 =A0 =A0 =A0 =A0 =A0if not params.get("pass_through") =3D=3D "no= ": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_type =3D params.get("pass_through= ") > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Virtual Functions pass through > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if params.get("pass_through") =3D=3D= "nic_vf": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Going to assi= gn VFs to guest") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough= (type=3Dpt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 max_vfs =3D params.get("max_vfs")) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Physical NIC card pass through > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D= "nic_pf": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Going to assi= gn physical NICs to guest") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough= (type=3Dpt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 names=3Dparams.get("passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0elif params.get("pass_through") =3D=3D= "mixed": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Assigned NICs= may contain both VFs and PFs") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt =3D kvm_utils.PassThrough= (type =3D pt_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 max_vfs =3D params.get("max_vfs"), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 names =3D params.get("passthrough_devs")) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_count =3D params.get("passthrough= _count") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_db_file =3D open('/tmp/passthroug= h_db', 'w') > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pt_pci_ids =3D pt.request_devs(= pt_count, pt_file=3Dpt_db_file, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0setup=3DTrue) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pt_db_file.close() > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not self.pt_pci_ids: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.error("Request speci= fied PCI device(s) failed;" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= " pt_pci_ids are: %s", self.pt_pci_ids) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return False > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Requested host PCI de= vice(s): %s", > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.pt_= pci_ids) > + > =A0 =A0 =A0 =A0 =A0 =A0 # Make qemu command > =A0 =A0 =A0 =A0 =A0 =A0 qemu_command =3D self.make_qemu_command() > > @@ -504,6 +559,19 @@ class VM: > =A0 =A0 =A0 =A0 return (0, data) > > > + =A0 =A0def _release_pt_devs(self): > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0Release the assigned passthrough PCI devices or VFs = to host. > + =A0 =A0 =A0 =A0""" > + =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0db_file =3D open('/tmp/passthrough_db', 'r') > + =A0 =A0 =A0 =A0 =A0 =A0pt_db =3D cPickle.load(db_file) > + =A0 =A0 =A0 =A0 =A0 =A0kvm_utils.release_pci_devs(pt_db) > + =A0 =A0 =A0 =A0 =A0 =A0db_file.close() > + =A0 =A0 =A0 =A0except: > + =A0 =A0 =A0 =A0 =A0 =A0return > + > + > =A0 =A0 def destroy(self, gracefully=3DTrue): > =A0 =A0 =A0 =A0 """ > =A0 =A0 =A0 =A0 Destroy the VM. > @@ -520,6 +588,7 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 # Is it already dead? > =A0 =A0 =A0 =A0 =A0 =A0 if self.is_dead(): > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("VM is already down") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self._release_pt_devs() > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return > > =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("Destroying VM with PID %d..." = % > @@ -540,6 +609,7 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 finally: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 session.close() > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self._release_pt_dev= s() > > =A0 =A0 =A0 =A0 =A0 =A0 # Try to destroy with a monitor command > =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("Trying to kill VM with monitor= command...") > @@ -549,6 +619,7 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Wait for the VM to be really dead > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if kvm_utils.wait_for(self.is_dead, 5= , 0.5, 0.5): > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("VM is down") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self._release_pt_devs() > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return > > =A0 =A0 =A0 =A0 =A0 =A0 # If the VM isn't dead yet... > @@ -558,6 +629,7 @@ class VM: > =A0 =A0 =A0 =A0 =A0 =A0 # Wait for the VM to be really dead > =A0 =A0 =A0 =A0 =A0 =A0 if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0= =2E5): > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 logging.debug("VM is down") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self._release_pt_devs() > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return > > =A0 =A0 =A0 =A0 =A0 =A0 logging.error("Process %s is a zombie!" % sel= f.process.get_pid()) > -- > 1.6.2.5 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > --=20 Lucas