Skip to contentSkip to conversation

kvm: Enable device LTR/OBFF capibility before doing guest device assignment

PATCH In review Xudong Hao 4 participants 9 messages May 6, 2012 – May 13, 2012 KVM

lore
Share & tools
lore

Xudong Hao

author
#0 lore raw

PATCH 1/1 kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Enable device LTR/OBFF capibility before do device assignment, so that guest can benefit from them.

---
 virt/kvm/iommu.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
virt/kvm/iommu.c +32 -0
index e9fff98..5139f2d 100644
@@ -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

#1 lore raw
Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that guest can benefit from them.

cc += Alex

virt/kvm/iommu.c int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 9 lines
virt/kvm/iommu.c +4 -0
@@ -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()?

Quoted 11 lines
virt/kvm/iommu.c +1 -0
    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;
 }
 

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 364

Quoted 9 lines
virt/kvm/iommu.c +6 -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?

Quoted 11 lines
virt/kvm/iommu.c +11 -0
+
+   /* 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

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 385

Quoted 10 lines
virt/kvm/iommu.c +10 -0
+    * 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?

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 19 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected]; [email protected]; Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that guest

can benefit from them.

cc += Alex

Quoted 4 lines
virt/kvm/iommu.c +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines

virt/kvm/iommu.c int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
virt/kvm/iommu.c +4 -0
+   /* 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()?

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Quoted 10 lines
Quoted 10 lines
virt/kvm/iommu.c +1 -0
    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;
 }
 
Quoted 13 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 364

Quoted 10 lines
virt/kvm/iommu.c +6 -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?

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

Quoted 15 lines
Quoted 15 lines
virt/kvm/iommu.c +15 -0
+
+   /* 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);
+}
Quoted 9 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 385

Quoted 6 lines
virt/kvm/iommu.c +6 -0
+
+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?

I guess you means that here host don't know if guest want to enable them, right? The ltr/obff new feature are supposed to enabled by guest if platform and device supported.

Quoted 2 lines

--
error compiling committee.c: too many arguments to function

#3 lore raw
Quoted 19 lines · Xudong
Quoted 19 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected]; [email protected]; Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that guest

can benefit from them.

cc += Alex

Quoted 4 lines
virt/kvm/iommu.c +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
virt/kvm/iommu.c +4 -0
+   /* 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 kvm_assign_device() fails we'll try to restore the state we saved in kvm_vm_ioctl_assign_device(), so ltr/obff should be brought back to initial state.

Quoted 4 lines

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Why is device assignment unique here? If there's a default value that's known to be safe, why doesn't pci_enable_device set it for everyone? Host drivers can fine tune the value later if they want.

Quoted 23 lines
Quoted 10 lines
Quoted 10 lines
virt/kvm/iommu.c +1 -0
    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;
 }
 
Quoted 13 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 364

Quoted 10 lines
virt/kvm/iommu.c +6 -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?

Quoted 3 lines

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

The register is composed of latency scale and latency value fields. 1024 is simply the largest value the latency value can hold (+1). The scale field allows latencies up to 34,326,183,936ns to be specified, so please explain how 1024 is a universal default.

Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
virt/kvm/iommu.c +15 -0
+
+   /* 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);
+}
Quoted 9 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 385

Quoted 6 lines
virt/kvm/iommu.c +6 -0
+
+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?

Quoted 2 lines

I guess you means that here host don't know if guest want to enable them, right? The ltr/obff new feature are supposed to enabled by guest if platform and device supported.

It looks like ltr is a two part mechanism, the capability and enable lives in the pci express capability, but the tuning registers live in extended capability space. The guest doesn't yet have access to the latter since we don't have an express chipset. The capability and enable are read-only to the guest currently, same for obff. Thanks,

Alex

#4 lore raw
Quoted 41 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 12:16 AM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Quoted 5 lines · Xudong
Quoted 5 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 4 lines
Quoted 4 lines

device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that

guest

Quoted 8 lines
Quoted 8 lines

can benefit from them.

cc += Alex

Quoted 4 lines
virt/kvm/iommu.c +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
virt/kvm/iommu.c +4 -0
+   /* 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()?

Quoted 4 lines

If kvm_assign_device() fails we'll try to restore the state we saved in kvm_vm_ioctl_assign_device(), so ltr/obff should be brought back to initial state.

Right, more clear.

Quoted 32 lines
Quoted 4 lines

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Why is device assignment unique here? If there's a default value that's known to be safe, why doesn't pci_enable_device set it for everyone? Host drivers can fine tune the value later if they want.

Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
virt/kvm/iommu.c +1 -0
    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;
 }
 

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 364

Quoted 9 lines
virt/kvm/iommu.c +6 -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?

Quoted 9 lines
Quoted 3 lines

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

The register is composed of latency scale and latency value fields. 1024 is simply the largest value the latency value can hold (+1). The scale field allows latencies up to 34,326,183,936ns to be specified, so please explain how 1024 is a universal default.

Since each platform will have its own max supported latency, I think the best way is setting the value to 0 because we have such a device now.

Quoted 38 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
virt/kvm/iommu.c +15 -0
+
+   /* 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);
+}
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 385

Quoted 6 lines
virt/kvm/iommu.c +6 -0
+
+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?

Quoted 3 lines
Quoted 1 line

I guess you means that here host don't know if guest want to enable them,

right?

Quoted 1 line

The ltr/obff new feature are supposed to enabled by guest if platform and

device supported.

It looks like ltr is a two part mechanism, the capability and enable lives in the pci express capability, but the tuning registers live in extended capability space. The guest doesn't yet have access to the latter since we don't have an express chipset. The capability and enable are read-only to the guest currently, same for obff. Thanks,

Alex

#5 lore raw
Quoted 89 lines · Xudong
Quoted 41 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 12:16 AM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Quoted 5 lines · Xudong
Quoted 5 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 4 lines
Quoted 4 lines

device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that

guest

Quoted 8 lines
Quoted 8 lines

can benefit from them.

cc += Alex

Quoted 4 lines
virt/kvm/iommu.c +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
virt/kvm/iommu.c +4 -0
+   /* 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()?

Quoted 4 lines

If kvm_assign_device() fails we'll try to restore the state we saved in kvm_vm_ioctl_assign_device(), so ltr/obff should be brought back to initial state.

Right, more clear.

Quoted 32 lines
Quoted 4 lines

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Why is device assignment unique here? If there's a default value that's known to be safe, why doesn't pci_enable_device set it for everyone? Host drivers can fine tune the value later if they want.

Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
virt/kvm/iommu.c +1 -0
    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;
 }
 

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 364

Quoted 9 lines
virt/kvm/iommu.c +6 -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?

Quoted 9 lines
Quoted 3 lines

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

The register is composed of latency scale and latency value fields. 1024 is simply the largest value the latency value can hold (+1). The scale field allows latencies up to 34,326,183,936ns to be specified, so please explain how 1024 is a universal default.

Quoted 3 lines

Since each platform will have its own max supported latency, I think the best way is setting the value to 0 because we have such a device now.

What's the benefit to that device vs the risk to other devices? Again, if there's a safe default value for both LTR and OBFF, why isn't PCI core setting it for everyone? I'm inclined to wait for qemu express support and expose LTR/OBFF control to the guest if and only if we can enable it on the root complex and intermediate switches. Thanks,

Alex

Quoted 39 lines
Quoted 38 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
virt/kvm/iommu.c +15 -0
+
+   /* 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);
+}
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 385

Quoted 6 lines
virt/kvm/iommu.c +6 -0
+
+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?

Quoted 3 lines
Quoted 1 line

I guess you means that here host don't know if guest want to enable them,

right?

Quoted 1 line

The ltr/obff new feature are supposed to enabled by guest if platform and

device supported.

It looks like ltr is a two part mechanism, the capability and enable lives in the pci express capability, but the tuning registers live in extended capability space. The guest doesn't yet have access to the latter since we don't have an express chipset. The capability and enable are read-only to the guest currently, same for obff. Thanks,

Alex

#6 lore raw
Quoted 10 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 11:18 PM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

On Tue, 2012-05-08 at 09:16 +0000, Hao, Xudong wrote:

Quoted 57 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 12:16 AM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 49 lines
Quoted 34 lines

device assignment

Quoted 5 lines · Xudong
Quoted 5 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 4 lines
Quoted 4 lines

device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that

guest

Quoted 8 lines
Quoted 8 lines

can benefit from them.

cc += Alex

Quoted 4 lines
virt/kvm/iommu.c +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines
Quoted 8 lines

virt/kvm/iommu.c int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
virt/kvm/iommu.c +4 -0
+   /* 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()?

Quoted 4 lines

If kvm_assign_device() fails we'll try to restore the state we saved in kvm_vm_ioctl_assign_device(), so ltr/obff should be brought back to initial state.

Right, more clear.

Quoted 9 lines
Quoted 4 lines

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Why is device assignment unique here? If there's a default value that's known to be safe, why doesn't pci_enable_device set it for everyone? Host drivers can fine tune the value later if they want.

If host did not have this device driver or host did not load the driver, who will enable them? Guest? But in guest, it really need qemu PCIe support.

Quoted 34 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm

Quoted 11 lines
virt/kvm/iommu.c +1 -0
    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)

Quoted 22 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines

virt/kvm/iommu.c int kvm_iommu_unmap_guest(struct kvm *kvm) · line 364

Quoted 9 lines
virt/kvm/iommu.c +6 -0
    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?

Quoted 3 lines

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

The register is composed of latency scale and latency value fields. 1024 is simply the largest value the latency value can hold (+1). The scale field allows latencies up to 34,326,183,936ns to be specified, so please explain how 1024 is a universal default.

Quoted 5 lines
Quoted 3 lines

Since each platform will have its own max supported latency, I think the best way is setting the value to 0 because we have such a device now.

What's the benefit to that device vs the risk to other devices?

Default value 0 does not affect any device, right?

Quoted 6 lines

Again,
if there's a safe default value for both LTR and OBFF, why isn't PCI core setting it for everyone? I'm inclined to wait for qemu express support and expose LTR/OBFF control to the guest if and only if we can enable it on the root complex and intermediate switches. Thanks,

Alex, do you means you're working on the qemu express support and ltr/obff exposing? If so, when will this support finish?

Thanks
Xudong

#7 lore raw
Quoted 63 lines · Xudong
Quoted 63 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 11:18 PM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Quoted 7 lines · Xudong
Quoted 7 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 12:16 AM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 45 lines
Quoted 34 lines

device assignment

Quoted 5 lines · Xudong
Quoted 5 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 4 lines
Quoted 4 lines

device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so that

guest

Quoted 8 lines
Quoted 8 lines

can benefit from them.

cc += Alex

Quoted 4 lines
(quoted diff) +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines
Quoted 8 lines

Review int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
(quoted diff) +4 -0
+   /* 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()?

Quoted 4 lines

If kvm_assign_device() fails we'll try to restore the state we saved in kvm_vm_ioctl_assign_device(), so ltr/obff should be brought back to initial state.

Right, more clear.

Quoted 5 lines
Quoted 4 lines

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Why is device assignment unique here? If there's a default value that's known to be safe, why doesn't pci_enable_device set it for everyone? Host drivers can fine tune the value later if they want.

If host did not have this device driver or host did not load the driver, who will enable them? Guest? But in guest, it really need qemu PCIe support.

The kvm driver does pci_enable_device(), just like any other PCI driver. If there's a safe default value, why isn't it set there?

Quoted 34 lines
Quoted 34 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Review int kvm_iommu_unmap_guest(struct kvm

Quoted 11 lines
(quoted diff) +1 -0
    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)

Quoted 22 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines

Review int kvm_iommu_unmap_guest(struct kvm · line 364

Quoted 9 lines
(quoted diff) +6 -0
    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?

Quoted 3 lines

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

The register is composed of latency scale and latency value fields. 1024 is simply the largest value the latency value can hold (+1). The scale field allows latencies up to 34,326,183,936ns to be specified, so please explain how 1024 is a universal default.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Since each platform will have its own max supported latency, I think the best way is setting the value to 0 because we have such a device now.

What's the benefit to that device vs the risk to other devices?

Default value 0 does not affect any device, right?

I don't know, but if it doesn't affect any device, why bother? On the risk side we have to question whether the device ltr/obff support works, whether the values we use are appropriate, whether the upstream interconnects support the same, and work, and whether the guest driver will behave appropriately with these enabled versus a gain of what? So far it looks like we're turning it on simply because it's there.

Quoted 9 lines
Quoted 6 lines

Again,
if there's a safe default value for both LTR and OBFF, why isn't PCI core setting it for everyone? I'm inclined to wait for qemu express support and expose LTR/OBFF control to the guest if and only if we can enable it on the root complex and intermediate switches. Thanks,

Alex, do you means you're working on the qemu express support and ltr/obff exposing? If so, when will this support finish?

Qemu express support is being worked on by the community, once available, it may be simple to expose these register if we determine it's safe for the guest to manipulate them. I think there's a goal of incorporating express support by qemu 1.2, but I'm not driving it. Thanks,

Alex

#8 lore raw
Quoted 82 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, May 09, 2012 10:34 AM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing guest device assignment

Quoted 7 lines · Xudong
Quoted 7 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 11:18 PM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected]; [email protected]; [email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 8 lines
Quoted 8 lines

device assignment

Quoted 5 lines · Xudong
Quoted 5 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, May 08, 2012 12:16 AM
To: Hao, Xudong
Cc: Avi Kivity; Xudong Hao; [email protected];

[email protected];

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

[email protected]; Zhang, Xiantao
Subject: RE: [PATCH] kvm: Enable device LTR/OBFF capibility before doing

guest

Quoted 3 lines
Quoted 3 lines

device assignment

On Mon, 2012-05-07 at 07:58 +0000, Hao, Xudong wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

-----Original Message-----
From: Avi Kivity [mailto:[email protected]]
Sent: Sunday, May 06, 2012 11:34 PM
To: Xudong Hao
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

Zhang, Xiantao; Hao, Xudong; Alex Williamson
Subject: Re: [PATCH] kvm: Enable device LTR/OBFF capibility before

doing

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

guest

Quoted 4 lines
Quoted 4 lines

device assignment

Quoted 1 line · Xudong Hao

Enable device LTR/OBFF capibility before do device assignment, so

that

Quoted 34 lines
Quoted 33 lines
Quoted 33 lines
Quoted 18 lines

guest

Quoted 8 lines
Quoted 8 lines

can benefit from them.

cc += Alex

Quoted 4 lines
(quoted diff) +0 -0
@@ -166,6 +166,10 @@ int kvm_assign_device(struct kvm *kvm,
    if (pdev == NULL)
        return -ENODEV;
 
Quoted 8 lines
Quoted 8 lines

Review int kvm_assign_device(struct kvm *kvm, · line 173

Quoted 5 lines
(quoted diff) +4 -0
+   /* 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()?

Quoted 4 lines

If kvm_assign_device() fails we'll try to restore the state we saved in kvm_vm_ioctl_assign_device(), so ltr/obff should be brought back to initial state.

Right, more clear.

Quoted 9 lines
Quoted 4 lines

I don't think so. When a device will be assigned to guest, it's be owned by a pci-stub driver, attach_device fail here do not affect everything. If host want to use it, host device driver has its own enable/disable dev_caps.

Why is device assignment unique here? If there's a default value that's known to be safe, why doesn't pci_enable_device set it for everyone? Host drivers can fine tune the value later if they want.

Quoted 7 lines
Quoted 3 lines

If host did not have this device driver or host did not load the driver, who will enable them? Guest? But in guest, it really need qemu PCIe support.

The kvm driver does pci_enable_device(), just like any other PCI driver. If there's a safe default value, why isn't it set there?

OK, I saw it. Seems it's reasonable to enable them in pci_enable_device(). I'll re-write patches there.

Quoted 68 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review int kvm_deassign_device(struct kvm

Quoted 3 lines
(quoted diff) +0 -0
    if (r) {
        printk(KERN_ERR "assign device %x:%x:%x.%x failed",
@@ -228,6 +232,7 @@ int kvm_deassign_device(struct kvm

*kvm,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review int kvm_iommu_unmap_guest(struct

Quoted 8 lines
(quoted diff) +1 -0
        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

Quoted 23 lines
Quoted 23 lines

*kvm)

Quoted 22 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines

Review int kvm_iommu_unmap_guest(struct · line 364

Quoted 9 lines
(quoted diff) +6 -0
    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?

Quoted 3 lines

The number is the max value that register support, set it as default here, we did not have any device here, and we do not know what's the proper value, so it set a default value firstly.

The register is composed of latency scale and latency value fields. 1024 is simply the largest value the latency value can hold (+1). The scale field allows latencies up to 34,326,183,936ns to be specified, so please explain how 1024 is a universal default.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Since each platform will have its own max supported latency, I think the best way is setting the value to 0 because we have such a device now.

What's the benefit to that device vs the risk to other devices?

Default value 0 does not affect any device, right?

I don't know, but if it doesn't affect any device, why bother? On the risk side we have to question whether the device ltr/obff support works, whether the values we use are appropriate, whether the upstream interconnects support the same, and work, and whether the guest driver will behave appropriately with these enabled versus a gain of what? So far it looks like we're turning it on simply because it's there.

Quoted 9 lines
Quoted 6 lines

Again,
if there's a safe default value for both LTR and OBFF, why isn't PCI core setting it for everyone? I'm inclined to wait for qemu express support and expose LTR/OBFF control to the guest if and only if we can enable it on the root complex and intermediate switches. Thanks,

Alex, do you means you're working on the qemu express support and ltr/obff exposing? If so, when will this support finish?

Qemu express support is being worked on by the community, once available, it may be simple to expose these register if we determine it's safe for the guest to manipulate them. I think there's a goal of incorporating express support by qemu 1.2, but I'm not driving it. Thanks,

Alex