Skip to contentSkip to conversation

: xl: pci multi-function passthrough v2

PATCH Applied Gianni Tedesco 3 participants 8 messages Aug 9, 2010 – Aug 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : xl: pci multi-function passthrough v2

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Letting qemu automatically select the virtual slot is not supported in multi-function passthrough since the qemu-dm protocol can not actually handle that case.

Also fix format error in xl pci-list-assignable.

tools/libxl/libxl.h +2 -0
diff -r 8992134dcfd0 tools/libxl/libxl.h
@@ -310,6 +310,8 @@ typedef struct {
     };
     unsigned int domain;
     unsigned int vdevfn;
+#define LIBXL_PCI_FUNC_ALL (~0U)
+    unsigned int vfunc_mask;
     bool msitranslate;
     bool power_mgmt;
 } libxl_device_pci;
tools/libxl/libxl_pci.c +138 -11

200 lines not on this page · raw message

tools/libxl/xl_cmdimpl.c +1 -1
diff -r 8992134dcfd0 tools/libxl/xl_cmdimpl.c
@@ -1923,7 +1923,7 @@ void pcilist_assignable(void)
     if ( libxl_device_pci_list_assignable(&ctx, &pcidevs, &num) )
         return;
     for (i = 0; i < num; i++) {
-        printf("%04x:%02x:%02x:%01x\n",
+        printf("%04x:%02x:%02x.%01x\n",
                 pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func);
     }
     free(pcidevs);
#1 lore raw
Quoted 41 lines · Gianni Tedesco
tools/libxl/libxl_pci.c +27 -2
@@ -652,8 +705,9 @@ out:
 
 int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev)
 {
+    unsigned int orig_vdev, pfunc_mask;
     libxl_device_pci *assigned;
-    int num_assigned, rc;
+    int num_assigned, rc, i;
     int stubdomid = 0;
 
     rc = get_all_assigned_devices(ctx, &assigned, &num_assigned);
@@ -679,10 +733,43 @@ int libxl_device_pci_add(libxl_ctx *ctx,
             return rc;
     }
 
-    return do_pci_add(ctx, domid, pcidev);
+    orig_vdev = pcidev->vdevfn & ~7U;
+
+    if ( pcidev->vfunc_mask == LIBXL_PCI_FUNC_ALL ) {
+        if ( !(pcidev->vdevfn >> 3) ) {
+            XL_LOG(ctx, XL_LOG_ERROR, "Must specify a v-slot for multi-function devices");
+            return ERROR_INVAL;
+        }
+        if ( pci_multifunction_check(ctx, pcidev, &pfunc_mask) ) {
+            return ERROR_FAIL;
+        }
+        pcidev->vfunc_mask &= pfunc_mask;
+        /* so now vfunc_mask == pfunc_mask */
+    }else{
+        pfunc_mask = (1 << pcidev->func);
+    }
+
+    for(i = 7; i >= 0; --i) {
+        if ( (1 << i) & pfunc_mask ) {
+            if ( pcidev->vfunc_mask == pfunc_mask ) {
+                pcidev->func = i;
+                pcidev->vdevfn = orig_vdev | i;
+            }else{
+                /* if not passing through multiple devices in a block make
+                 * sure that virtual function number 0 is always used otherwise
+                 * guest won't see the device

tools/libxl/libxl_pci.c int libxl_device_pci_add(libxl_ctx *ctx, · line 770

Quoted 10 lines
tools/libxl/libxl_pci.c +9 -0
+                 */
+                pcidev->vdevfn = orig_vdev;
+            }
+            if ( do_pci_add(ctx, domid, pcidev) )
+                rc = ERROR_FAIL;
+        }
+    }
+
+    return rc;
 }

Not sure that this bit is right for stubdoms, I haven't tested...

#2 lore raw
In reply to Gianni Tedesco
Quoted 16 lines · On Mon, 9 Aug 2010, Gianni Tedesco (3P) wrote:

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Quoted 8 lines

Letting qemu automatically select the virtual slot is not supported in multi-function passthrough since the qemu-dm protocol can not actually handle that case.

Also fix format error in xl pci-list-assignable.

applied, thanks

#3 lore raw
In reply to Gianni Tedesco
Quoted 11 lines · Gianni Tedesco

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Quoted 4 lines

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Is there any plan to extend this to allow for re-mapping and the like. When I worked on the original multi-function support (last year) this seemed to be a requirement of some people.

#4 lore raw
Quoted 12 lines · Simon Horman
Quoted 11 lines · Gianni Tedesco

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Quoted 8 lines
Quoted 4 lines

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Is there any plan to extend this to allow for re-mapping and the like. When I worked on the original multi-function support (last year) this seemed to be a requirement of some people.

I am glad you asked

I initially planned to support this but it seemed like a nightmare:
1. The BDF notation practically becomes a regex language ;)
2. For HVM, if a function 0 is not passed through then you don't generate an SCI interrupt for PCI hotplug.
3. I couldn't imagine a scenario where this wasn't erroneous thing to do

But if someone can convince me that this is a worth-while thing to do
(3) then (1) and (2) are just technical problems which can be overcome...

Gianni

#5 lore raw
Quoted 18 lines · Gianni Tedesco
Quoted 17 lines · Simon Horman
Quoted 15 lines · Gianni Tedesco

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Quoted 8 lines
Quoted 3 lines

Is there any plan to extend this to allow for re-mapping and the like. When I worked on the original multi-function support (last year) this seemed to be a requirement of some people.

I am glad you asked

I initially planned to support this but it seemed like a nightmare:
1. The BDF notation practically becomes a regex language ;)

I don't think its reasonable to say it becomes a regex language. But I do agree that it becomes more complex.

Quoted 2 lines

2. For HVM, if a function 0 is not passed through then you don't generate an SCI interrupt for PCI hotplug.

Isn't it sufficient to make sure that the guest sees a function 0, regardless of what the physical function number is? Or am I missing something?

Quoted 1 line

3. I couldn't imagine a scenario where this wasn't erroneous thing to do

I'm not sure that I understand this point.
I agree that your system should always produce a valid result. But I think that there are other configurations that are both valid and useful.

Quoted 3 lines

But if someone can convince me that this is a worth-while thing to do
(3) then (1) and (2) are just technical problems which can be overcome...

People convinced me that it was worthwhile, but I'm not those people.

#6 lore raw
Quoted 23 lines · Simon Horman
Quoted 22 lines · Gianni Tedesco
Quoted 20 lines · Simon Horman
Quoted 11 lines · Gianni Tedesco

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Quoted 4 lines

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Is there any plan to extend this to allow for re-mapping and the like. When I worked on the original multi-function support (last year) this seemed to be a requirement of some people.

Quoted 7 lines
Quoted 4 lines

I am glad you asked

I initially planned to support this but it seemed like a nightmare:
1. The BDF notation practically becomes a regex language ;)

I don't think its reasonable to say it becomes a regex language. But I do agree that it becomes more complex.

Well, for example BB:DD.0=7-7=0 is supposed to reverse the assignments.... but why? :)

Quoted 6 lines
Quoted 2 lines

2. For HVM, if a function 0 is not passed through then you don't generate an SCI interrupt for PCI hotplug.

Isn't it sufficient to make sure that the guest sees a function 0, regardless of what the physical function number is? Or am I missing something?

Yes that's all that's required.

Quoted 6 lines
Quoted 1 line

3. I couldn't imagine a scenario where this wasn't erroneous thing to do

I'm not sure that I understand this point.
I agree that your system should always produce a valid result. But I think that there are other configurations that are both valid and useful.

Passing various functions in to different VM's and/or re-mapping the function numbers may produce a totally invalid configuration that isn't useful (AFAICT). That may be paranoia but I just want to be convinced that this is actually useful for something.

Quoted 5 lines
Quoted 3 lines

But if someone can convince me that this is a worth-while thing to do
(3) then (1) and (2) are just technical problems which can be overcome...

People convinced me that it was worthwhile, but I'm not those people.

Well, please put them in touch or maybe forward the relevant discussions? (off-list is OK, if the discussions are private)

Like I say, I am not dead against the idea, I am just loathe to implement it until I can see what the point of it is.

#7 lore raw
Quoted 26 lines · Gianni Tedesco
Quoted 25 lines · Simon Horman
Quoted 24 lines · Gianni Tedesco
Quoted 12 lines · Simon Horman
Quoted 11 lines · Gianni Tedesco

Changes since last time:
1. Incorporate Stefanos feedback wrt. coding style, commenting non-obvious code and making single-function a special-case of multi-function
2. Also fix the case for passing through a single sub-function and re-mapping it as a single-function virtual device. (ie: pfunc = non-zero, vfunc = zero). Apparently needed for SR-IOV.
3. One-liner format change in xl pci-list-assignable to make it print a copy-and-pasteable BDF.
8<----------------------------------------

Quoted 8 lines
Quoted 4 lines

Implement PCI pass-through for multi-function devices. The supported BDF notation is: BB:DD.* - therefore passing-through a subset of functions or remapping the function numbers is not supported except for when passing through a single function which will be a virtual function 0.

Is there any plan to extend this to allow for re-mapping and the like. When I worked on the original multi-function support (last year) this seemed to be a requirement of some people.

I am glad you asked

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I initially planned to support this but it seemed like a nightmare:
1. The BDF notation practically becomes a regex language ;)

I don't think its reasonable to say it becomes a regex language. But I do agree that it becomes more complex.

Well, for example BB:DD.0=7-7=0 is supposed to reverse the assignments.... but why? :)

Because 0 maps to 7, 7 maps to 0 and everything in between is implied. I don't dispute that this is complex. And actually this mapping bit really pushes the extension of the notation further than I initially envisaged.

So yes, I think that it is complex. But I don't think its a regex language.

Quoted 17 lines
Quoted 7 lines
Quoted 3 lines

2. For HVM, if a function 0 is not passed through then you don't generate an SCI interrupt for PCI hotplug.

Isn't it sufficient to make sure that the guest sees a function 0, regardless of what the physical function number is? Or am I missing something?

Yes that's all that's required.

Quoted 6 lines
Quoted 1 line

3. I couldn't imagine a scenario where this wasn't erroneous thing to do

I'm not sure that I understand this point.
I agree that your system should always produce a valid result. But I think that there are other configurations that are both valid and useful.

Quoted 4 lines

Passing various functions in to different VM's and/or re-mapping the function numbers may produce a totally invalid configuration that isn't useful (AFAICT). That may be paranoia but I just want to be convinced that this is actually useful for something.

Yes, I agree that the scheme that I implemented can produce invalid results. I was concerned about that too. And initially I resisted allowing arbitrary mappings for that reason. But I was convinced/requested to allow them.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

But if someone can convince me that this is a worth-while thing to do
(3) then (1) and (2) are just technical problems which can be overcome...

People convinced me that it was worthwhile, but I'm not those people.

Well, please put them in touch or maybe forward the relevant discussions? (off-list is OK, if the discussions are private)

Like I say, I am not dead against the idea, I am just loathe to implement it until I can see what the point of it is.

I think that its a wise position for you to take.