Skip to contentSkip to conversation

Broken PCI device passthrough, after XSA-302 fix?

Xen-devel Marek Marczykowski-Górecki 3 participants 11 messages Jan 4, 2020 – Jan 20, 2020

lore
Share & tools
lore
#0 lore raw

Hi,

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

This is Xen 4.8.5 + XSA patches. It started happening after some update during last few months, not really sure which one.

I guess it is because quarantine feature, so initial ownership of 0000:05:00.0 is different than the bridge it is connected to. I'm not sure if relevant for this case, but I also set pcidev->rdm_policy = LIBXL_RDM_RESERVE_POLICY_RELAXED.

Booting with iommu=no-quarantine helps. Note I do not use xl pci-assignable-add command, only bind the device to the pciback driver in dom0.

Relevant part of lspci and lspci -t:

00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Controller (rev 06) ..
00:1c.3 PCI bridge: Intel Corporation 9 Series Chipset Family PCI Express Root Port 4 (rev d0) ..
04:00.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 41)
05:00.0 USB controller: NEC Corporation OHCI USB Controller (rev 43)
05:00.1 USB controller: NEC Corporation OHCI USB Controller (rev 43)
05:00.2 USB controller: NEC Corporation uPD72010x USB 2.0 Controller (rev 04)

-[0000:00]-+-00.0
..

           +-1c.3-[04-05]----00.0-[05]--+-00.0
           |                            +-00.1
           |                            \-00.2
Signature · 5 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#1 lore raw
Quoted 4 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Is this on the 1st attempt, or after the device had already been assigned to some (same or other) guest? After quite a bit of staring at the code I can't seem to be able to spot a difference in behavior for the 1st attempt, but you not saying explicitly that it would only happen on subsequent ones makes me assume you run into the issue right away.

Quoted 2 lines

This is Xen 4.8.5 + XSA patches. It started happening after some update during last few months, not really sure which one.

Having a smaller window would of course help, as would ...

Quoted 8 lines

I guess it is because quarantine feature, so initial ownership of 0000:05:00.0 is different than the bridge it is connected to. I'm not sure if relevant for this case, but I also set pcidev->rdm_policy = LIBXL_RDM_RESERVE_POLICY_RELAXED.

Booting with iommu=no-quarantine helps. Note I do not use xl pci-assignable-add command, only bind the device to the pciback driver in dom0.

... knowing whether behavior differs when using this preparatory step.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

Quoted 8 lines
Quoted 1 line

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Is this on the 1st attempt, or after the device had already been assigned to some (same or other) guest? After quite a bit of staring at the code I can't seem to be able to spot a difference in behavior for the 1st attempt, but you not saying explicitly that it would only happen on subsequent ones makes me assume you run into the issue right away.

Yes, it was the first try.

Quoted 4 lines
Quoted 2 lines

This is Xen 4.8.5 + XSA patches. It started happening after some update during last few months, not really sure which one.

Having a smaller window would of course help, as would ...

The working version was just before XSAs of 2019-10-31 (which include XSA-302).
But at this point, I'm not sure if no other configuration changes were made (see below).

Quoted 11 lines
Quoted 8 lines

I guess it is because quarantine feature, so initial ownership of 0000:05:00.0 is different than the bridge it is connected to. I'm not sure if relevant for this case, but I also set pcidev->rdm_policy = LIBXL_RDM_RESERVE_POLICY_RELAXED.

Booting with iommu=no-quarantine helps. Note I do not use xl pci-assignable-add command, only bind the device to the pciback driver in dom0.

... knowing whether behavior differs when using this preparatory step.

xl pci-assignable-add doesn't make a difference with XSA-306 applied. But I've tried xl pci-assignable-remove with interesting result:
It succeeded for 0000:05:00.0 and 0000:05:00.2, but failed for 0000:05:00.1 with this message:

(XEN) [VT-D]d0: 0000:05:00.1 owned by d32753!<G><0>deassign 0000:05:00.1 from dom32753 failed (-22)

Anyway, I think my previous testing was inaccurate:
Looks like the issue is caused by me failing to set rdm_policy, contrary to the above message. I get the above error only without LIBXL_RDM_RESERVE_POLICY_RELAXED set. When I set it properly, domain starts even without iommu=no-quarantine. I still have some issues with the device within the domain, but not sure if relevant to this or something else.

Does it make sense now?
Is the patch from your other message still relevant?

Signature · 5 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 38 lines · Marek Marczykowski-Górecki
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

Quoted 8 lines
Quoted 1 line

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Is this on the 1st attempt, or after the device had already been assigned to some (same or other) guest? After quite a bit of staring at the code I can't seem to be able to spot a difference in behavior for the 1st attempt, but you not saying explicitly that it would only happen on subsequent ones makes me assume you run into the issue right away.

Yes, it was the first try.

Quoted 4 lines
Quoted 2 lines

This is Xen 4.8.5 + XSA patches. It started happening after some update during last few months, not really sure which one.

Having a smaller window would of course help, as would ...

The working version was just before XSAs of 2019-10-31 (which include XSA-302).
But at this point, I'm not sure if no other configuration changes were made (see below).

Quoted 11 lines
Quoted 8 lines

I guess it is because quarantine feature, so initial ownership of 0000:05:00.0 is different than the bridge it is connected to. I'm not sure if relevant for this case, but I also set pcidev->rdm_policy = LIBXL_RDM_RESERVE_POLICY_RELAXED.

Booting with iommu=no-quarantine helps. Note I do not use xl pci-assignable-add command, only bind the device to the pciback driver in dom0.

... knowing whether behavior differs when using this preparatory step.

Quoted 7 lines

xl pci-assignable-add doesn't make a difference with XSA-306 applied. But I've tried xl pci-assignable-remove with interesting result:
It succeeded for 0000:05:00.0 and 0000:05:00.2, but failed for 0000:05:00.1 with this message:

(XEN) [VT-D]d0: 0000:05:00.1 owned by d32753!<G><0>deassign 0000:05:00.1 from dom32753 failed (-22)

And now, after this operation (failed -remove) I get the following error on domain start, even with LIBXL_RDM_RESERVE_POLICY_RELAXED properly set:

(XEN) [VT-D]d13: 0000:05:00.1 owned by d32753!<G><0>assign 0000:05:00.1 to dom13 failed (-22)

I've tried doing -add and -remove in different order and every time it fails for 0000:05:00.1, but works for other functions.
I don't see anything special about this function, compared to others.

I'll reboot the system and try again...

Signature · 5 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 51 lines · Marek Marczykowski-Górecki
Quoted 38 lines · Marek Marczykowski-Górecki
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

Quoted 8 lines
Quoted 1 line

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Is this on the 1st attempt, or after the device had already been assigned to some (same or other) guest? After quite a bit of staring at the code I can't seem to be able to spot a difference in behavior for the 1st attempt, but you not saying explicitly that it would only happen on subsequent ones makes me assume you run into the issue right away.

Yes, it was the first try.

Quoted 4 lines
Quoted 2 lines

This is Xen 4.8.5 + XSA patches. It started happening after some update during last few months, not really sure which one.

Having a smaller window would of course help, as would ...

The working version was just before XSAs of 2019-10-31 (which include XSA-302).
But at this point, I'm not sure if no other configuration changes were made (see below).

Quoted 11 lines
Quoted 8 lines

I guess it is because quarantine feature, so initial ownership of 0000:05:00.0 is different than the bridge it is connected to. I'm not sure if relevant for this case, but I also set pcidev->rdm_policy = LIBXL_RDM_RESERVE_POLICY_RELAXED.

Booting with iommu=no-quarantine helps. Note I do not use xl pci-assignable-add command, only bind the device to the pciback driver in dom0.

... knowing whether behavior differs when using this preparatory step.

Quoted 7 lines

xl pci-assignable-add doesn't make a difference with XSA-306 applied. But I've tried xl pci-assignable-remove with interesting result:
It succeeded for 0000:05:00.0 and 0000:05:00.2, but failed for 0000:05:00.1 with this message:

(XEN) [VT-D]d0: 0000:05:00.1 owned by d32753!<G><0>deassign 0000:05:00.1 from dom32753 failed (-22)

And now, after this operation (failed -remove) I get the following error on domain start, even with LIBXL_RDM_RESERVE_POLICY_RELAXED properly set:

Quoted 7 lines

(XEN) [VT-D]d13: 0000:05:00.1 owned by d32753!<G><0>assign 0000:05:00.1 to dom13 failed (-22)

I've tried doing -add and -remove in different order and every time it fails for 0000:05:00.1, but works for other functions.
I don't see anything special about this function, compared to others.

I'll reboot the system and try again...

After fresh reboot:

1. xl debug-keys Q says 0000:05:00.* are assigned to dom0.
2. xl pci-assignable-add 0000:05:00.* (in order: .0, .1, .2)
3. domain start (with LIBXL_RDM_RESERVE_POLICY_RELAXED set) fails:

(XEN) [VT-D]d5: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.2 to dom5 failed (-22)

4. xl debug-keys Q says 0000:05:00.* are assigned to d32753
5. domain start (with LIBXL_RDM_RESERVE_POLICY_RELAXED set) fails:

(XEN) [VT-D]d7: 0000:05:00.2 owned by d32753!<G><0>assign 0000:05:00.2 to dom7 failed (-22)

Signature · 5 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
In reply to Marek Marczykowski-Górecki
Quoted 54 lines · Marek Marczykowski-Górecki
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

Quoted 8 lines
Quoted 1 line

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Is this on the 1st attempt, or after the device had already been assigned to some (same or other) guest? After quite a bit of staring at the code I can't seem to be able to spot a difference in behavior for the 1st attempt, but you not saying explicitly that it would only happen on subsequent ones makes me assume you run into the issue right away.

Yes, it was the first try.

Quoted 4 lines
Quoted 2 lines

This is Xen 4.8.5 + XSA patches. It started happening after some update during last few months, not really sure which one.

Having a smaller window would of course help, as would ...

The working version was just before XSAs of 2019-10-31 (which include XSA-302).
But at this point, I'm not sure if no other configuration changes were made (see below).

Quoted 11 lines
Quoted 8 lines

I guess it is because quarantine feature, so initial ownership of 0000:05:00.0 is different than the bridge it is connected to. I'm not sure if relevant for this case, but I also set pcidev->rdm_policy = LIBXL_RDM_RESERVE_POLICY_RELAXED.

Booting with iommu=no-quarantine helps. Note I do not use xl pci-assignable-add command, only bind the device to the pciback driver in dom0.

... knowing whether behavior differs when using this preparatory step.

xl pci-assignable-add doesn't make a difference with XSA-306 applied. But I've tried xl pci-assignable-remove with interesting result:
It succeeded for 0000:05:00.0 and 0000:05:00.2, but failed for 0000:05:00.1 with this message:

(XEN) [VT-D]d0: 0000:05:00.1 owned by d32753!<G><0>deassign 0000:05:00.1 from dom32753 failed (-22)

Anyway, I think my previous testing was inaccurate:
Looks like the issue is caused by me failing to set rdm_policy, contrary to the above message. I get the above error only without LIBXL_RDM_RESERVE_POLICY_RELAXED set. When I set it properly, domain starts even without iommu=no-quarantine. I still have some issues with the device within the domain, but not sure if relevant to this or something else.

Quoted 1 line

Does it make sense now?

Well, hard to tell - I still can't see what might be wrong, beyond ...

Quoted 1 line

Is the patch from your other message still relevant?

... what this patch deals with. The answer to your question is "yes", also in light of your subsequent replies, albeit I still wouldn't be able to tell why things did work for you before.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 6 lines · Jan Beulich
Quoted 1 line · Marek Marczykowski-Górecki

Is the patch from your other message still relevant?

... what this patch deals with. The answer to your question is "yes", also in light of your subsequent replies, albeit I still wouldn't be able to tell why things did work for you before.

With your patch applied the domain starts now, regardless of LIBXL_RDM_RESERVE_POLICY_RELAXED set or not.

Signature · 5 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
In reply to Marek Marczykowski-Górecki
Quoted 4 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

I've tried this out in as close a setup as I could arrange for, but not one matching your scenario. I didn't find a system with a suitably placed (in the topology) multi-function device (had to use a single-function one), and of course I did this on (close to) master. No anomalies. Hence I wonder whether either of the two differences mentioned matters, and - if, as I suspect, it's the multi-function aspect that is relevant here - how things would have worked at all before those recent changes. This is because I think you should have hit the same error path even before, and it would seem to me that the patch below might be (and have been) needed.

Jan

xen/drivers/passthrough/vtd/iommu.c +2 -2
@@ -1505,7 +1505,7 @@ static int domain_context_mapping(struct
             break;
 
         ret = domain_context_mapping_one(domain, drhd->iommu, bus, devfn,
-                                         pci_get_pdev(seg, bus, devfn));
+                                         NULL);
 
         /*
          * Devices behind PCIe-to-PCI/PCIx bridge may generate different
@@ -1515,7 +1515,7 @@ static int domain_context_mapping(struct
         if ( !ret && pdev_type(seg, bus, devfn) == DEV_TYPE_PCIe2PCI_BRIDGE &&
              (secbus != pdev->bus || pdev->devfn != 0) )
             ret = domain_context_mapping_one(domain, drhd->iommu, secbus, 0,
-                                             pci_get_pdev(seg, secbus, 0));
+                                             NULL);
 
         break;
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

Hi,

Quoted 6 lines · Jan Beulich
Quoted 4 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Quoted 11 lines

I've tried this out in as close a setup as I could arrange for, but not one matching your scenario. I didn't find a system with a suitably placed (in the topology) multi-function device (had to use a single-function one), and of course I did this on (close to) master. No anomalies. Hence I wonder whether either of the two differences mentioned matters, and - if, as I suspect, it's the multi-function aspect that is relevant here - how things would have worked at all before those recent changes. This is because I think you should have hit the same error path even before, and it would seem to me that the patch below might be (and have been) needed.

I think Marek confirmed in the other mail that this patch fixes the issue.

Are you planning to merge this patch?

Thanks,

-- Pasi

Quoted 16 lines

Jan

xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1505,7 +1505,7 @@ static int domain_context_mapping(struct
             break;
 
         ret = domain_context_mapping_one(domain, drhd->iommu, bus, devfn,
-                                         pci_get_pdev(seg, bus, devfn));
+                                         NULL);
 
         /*
          * Devices behind PCIe-to-PCI/PCIx bridge may generate different

xen/drivers/passthrough/vtd/iommu.c static int domain_context_mapping(struct · line 1521

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1515,7 +1515,7 @@ static int domain_context_mapping(struct
         if ( !ret && pdev_type(seg, bus, devfn) == DEV_TYPE_PCIe2PCI_BRIDGE &&
              (secbus != pdev->bus || pdev->devfn != 0) )
             ret = domain_context_mapping_one(domain, drhd->iommu, secbus, 0,
-                                             pci_get_pdev(seg, secbus, 0));
+                                             NULL);
 
         break;
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw
Quoted 19 lines · Pasi Kärkkäinen
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

Quoted 11 lines

I've tried this out in as close a setup as I could arrange for, but not one matching your scenario. I didn't find a system with a suitably placed (in the topology) multi-function device (had to use a single-function one), and of course I did this on (close to) master. No anomalies. Hence I wonder whether either of the two differences mentioned matters, and - if, as I suspect, it's the multi-function aspect that is relevant here - how things would have worked at all before those recent changes. This is because I think you should have hit the same error path even before, and it would seem to me that the patch below might be (and have been) needed.

Quoted 3 lines

I think Marek confirmed in the other mail that this patch fixes the issue.

Are you planning to merge this patch?

Well, it is still pending a maintainer ack. Kevin has requested a (mechanical) change just over the weekend.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Pasi Kärkkäinen
Quoted 17 lines · Jan Beulich
Quoted 4 lines · Marek Marczykowski-Górecki

I have a multi-function PCI device, behind a PCI bridge, that normally I assign to a single domain. But now it fails with:

(XEN) [VT-D]d14: 0000:04:00.0 owned by d0!<G><0>assign 0000:05:00.0 to dom14 failed (-22)

I've tried this out in as close a setup as I could arrange for, but not one matching your scenario. I didn't find a system with a suitably placed (in the topology) multi-function device (had to use a single-function one), and of course I did this on (close to) master. No anomalies. Hence I wonder whether either of the two differences mentioned matters, and - if, as I suspect, it's the multi-function aspect that is relevant here - how things would have worked at all before those recent changes. This is because I think you should have hit the same error path even before, and it would seem to me that the patch below might be (and have been) needed.

Quoted 7 lines
Quoted 3 lines

I think Marek confirmed in the other mail that this patch fixes the issue.

Are you planning to merge this patch?

Well, it is still pending a maintainer ack. Kevin has requested a (mechanical) change just over the weekend.

Ah, sorry, I missed the other thread. The patch in question seems to be:

"[PATCH 1/2] VT-d: don't pass bridge devices to domain_context_mapping_one()", in thread: "[PATCH 0/2] VT-d: domain_context_mapping_one() adjustments".

Thanks.

-- Pasi

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel