From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment Date: Sun, 06 May 2012 18:34:14 +0300 Message-ID: <4FA699F6.9010605@redhat.com> References: <20120506152405.GA14009@hp-xd.sh.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: mtosatti@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, xiantao.zhang@intel.com, xudong.hao@intel.com, Alex Williamson To: Xudong Hao Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44344 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753706Ab2EFPe0 (ORCPT ); Sun, 6 May 2012 11:34:26 -0400 In-Reply-To: <20120506152405.GA14009@hp-xd.sh.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On 05/06/2012 06:24 PM, Xudong Hao wrote: > Enable device LTR/OBFF capibility before do device assignment, so that guest can benefit from them. cc += Alex > @@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm, > if (pdev == NULL) > return -ENODEV; > > + /* Enable some device capibility before do device assignment, > + * so that guest can benefit from them. > + */ > + kvm_iommu_enable_dev_caps(pdev); > r = iommu_attach_device(domain, &pdev->dev); Suppose we fail here. Do we need to disable_dev_caps()? > if (r) { > printk(KERN_ERR "assign device %x:%x:%x.%x failed", > @@ -228,6 +232,7 @@ int kvm_deassign_device(struct kvm *kvm, > PCI_SLOT(assigned_dev->host_devfn), > PCI_FUNC(assigned_dev->host_devfn)); > > + kvm_iommu_disable_dev_caps(pdev); > return 0; > } > > @@ -351,3 +356,30 @@ int kvm_iommu_unmap_guest(struct kvm *kvm) > iommu_domain_free(domain); > return 0; > } > + > +static void kvm_iommu_enable_dev_caps(struct pci_dev *pdev) > +{ > + /* set default value */ > + unsigned long type = PCI_EXP_OBFF_SIGNAL_ALWAYS; > + int snoop_lat_ns = 1024, nosnoop_lat_ns = 1024; Where does this magic number come from? > + > + /* LTR(Latency tolerance reporting) allows devices to send > + * messages to the root complex indicating their latency > + * tolerance for snooped & unsnooped memory transactions. > + */ > + pci_enable_ltr(pdev); > + pci_set_ltr(pdev, snoop_lat_ns, nosnoop_lat_ns); > + > + /* OBFF (optimized buffer flush/fill), where supported, > + * can help improve energy efficiency by giving devices > + * information about when interrupts and other activity > + * will have a reduced power impact. > + */ > + pci_enable_obff(pdev, type); > +} > + > +static void kvm_iommu_disable_dev_caps(struct pci_dev *pdev) > +{ > + pci_disble_obff(pdev); > + pci_disble_ltr(pdev); > +} Do we need to communicate something about these capabilities to the guest? -- error compiling committee.c: too many arguments to function