From: Xudong Hao <xudong.hao@linux.intel.com>
To: avi@redhat.com, mtosatti@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
xiantao.zhang@intel.com, xudong.hao@intel.com
Subject: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment
Date: Sun, 6 May 2012 23:24:05 +0800 [thread overview]
Message-ID: <20120506152405.GA14009@hp-xd.sh.intel.com> (raw)
Enable device LTR/OBFF capibility before do device assignment, so that guest can benefit from them.
Signed-off-by: Xudong Hao <xudong.hao@intel.com>
---
virt/kvm/iommu.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index e9fff98..5139f2d 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -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);
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;
+
+ /* 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);
+}
--
1.6.0.rc1
next reply other threads:[~2012-05-06 15:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-06 15:24 Xudong Hao [this message]
2012-05-06 15:34 ` [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment Avi Kivity
2012-05-07 7:58 ` Hao, Xudong
2012-05-07 16:16 ` Alex Williamson
2012-05-08 9:16 ` Hao, Xudong
2012-05-08 9:16 ` Hao, Xudong
2012-05-08 15:18 ` Alex Williamson
2012-05-09 1:18 ` Hao, Xudong
2012-05-09 1:18 ` Hao, Xudong
2012-05-09 2:34 ` Alex Williamson
2012-05-13 7:04 ` Hao, Xudong
2012-05-13 7:04 ` Hao, Xudong
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=20120506152405.GA14009@hp-xd.sh.intel.com \
--to=xudong.hao@linux.intel.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=xiantao.zhang@intel.com \
--cc=xudong.hao@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.