libxl: disallow PCI device assignment for HVM guest when PoD is enabled
PATCH 1/1 libxl: disallow PCI device assignment for HVM guest when PoD is enabled
This replicates a Xend behavior, see ec789523749 ("xend: Dis-allow device assignment if PoD is enabled.").
This change is restricted to HVM guest, as only VT-d is relevant in the counterpart in Xend. We're late in release cycle so the change should only do what's necessary. Probably we can revisit it if we need to do the same thing for PV guest in the future.
--- tools/libxl/libxl_create.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/libxl/libxl_create.c +22 -0
@@ -706,6 +706,7 @@ static void initiate_domain_create(libxl__egc *egc,libxl_ctx *ctx =libxl__gc_owner (gc);uint32_t domid;int i, ret; +bool pod_enabled = false;/* convenience aliases */ libxl_domain_config *const d_config = dcs->guest_config;
@@ -714,6 +715,27 @@ static void initiate_domain_create(libxl__egc *egc, domid =0 ; +/* If target_memkb is smaller than max_memkb, the subsequent call +* to libxc when building HVM domain will enable PoD mode. +*/ + pod_enabled = (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM ) && + (d_config->b_info.target_memkb < d_config->b_info.max_memkb); + +/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot +* work with PoD enabled because it needs to populated entire page +* table for guest. Also a quick grep through AMD IOMMU related +* code suggests it has not coped with PoD as well. Just to stay +* on the safe side, we disable PCI device assignment with PoD all +* together, regardless of the underlying IOMMU in use. +*/ +if (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM && + d_config->num_pcidevs && pod_enabled) { + ret =ERROR_INVAL ; +LOG (ERROR ,"PCI device assignment for HVM guest failed due to PoD enabled" ); + goto error_out; + } + ret =libxl__domain_create_info_setdefault (gc, &d_config->c_info);if (ret) goto error_out;
Signature · 1 line
1.7.10.4
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot
There's still a "VT-d" left in here...
Jan
Quoted 6 lines
tools/libxl/libxl_create.c +6
-0+* work with PoD enabled because it needs to populated entire page +* table for guest. Also a quick grep through AMD IOMMU related +* code suggests it has not coped with PoD as well. Just to stay +* on the safe side, we disable PCI device assignment with PoD all +* together, regardless of the underlying IOMMU in use. +*/
Quoted 6 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
I mentioned AMD as well. Was trying to clarify things a bit more...
Wei.
Quoted 10 lines
Jan
Quoted 6 lines
tools/libxl/libxl_create.c +6
-0+* work with PoD enabled because it needs to populated entire page +* table for guest. Also a quick grep through AMD IOMMU related +* code suggests it has not coped with PoD as well. Just to stay +* on the safe side, we disable PCI device assignment with PoD all +* together, regardless of the underlying IOMMU in use. +*/
Quoted 9 lines · Wei Liu
Quoted 5 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
I mentioned AMD as well. Was trying to clarify things a bit more...
Wei.
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
~Andrew
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Wei Liu
Quoted 5 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
I mentioned AMD as well. Was trying to clarify things a bit more...
Quoted 8 lines
Quoted 1 line
Wei.
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
Thanks for clarification. I will fix this comment.
Wei.
Quoted 1 line
~Andrew
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
Quoted 7 lines
Quoted 1 line
I mentioned AMD as well. Was trying to clarify things a bit more...
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
That's going a little too far: If IOMMU faults were recoverable, dealing with non-present pages would become possible (with other caveats of course). So this is not a fundamental attribute of IOMMUs, but there doesn't seem to be any reason to believe that the current model would change any time soon for either of the vendors.
Jan
Quoted 16 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
Quoted 7 lines
Quoted 1 line
I mentioned AMD as well. Was trying to clarify things a bit more...
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
Quoted 6 lines
That's going a little too far: If IOMMU faults were recoverable, dealing with non-present pages would become possible (with other caveats of course). So this is not a fundamental attribute of IOMMUs, but there doesn't seem to be any reason to believe that the current model would change any time soon for either of the vendors.
Do you have suggestion on how this comment should be phrased?
Wei.
Quoted 1 line
Jan
Quoted 17 lines · Wei Liu
Quoted 16 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 7 lines · Wei Liu
Quoted 5 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
I mentioned AMD as well. Was trying to clarify things a bit more...
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
Quoted 8 lines
Quoted 6 lines
That's going a little too far: If IOMMU faults were recoverable, dealing with non-present pages would become possible (with other caveats of course). So this is not a fundamental attribute of IOMMUs, but there doesn't seem to be any reason to believe that the current model would change any time soon for either of the vendors.
Do you have suggestion on how this comment should be phrased?
We cannot have PoD and PCI device assignment at the same to for HVM guests. This is because the IOMMU support in Xen cannot currently cope with faults due to pages which are not present.
?
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 22 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
(quoted diff) +2
-0+ /* We cannot have PoD and PCI device assignment at the same time + * for HVM guest. It was reported that VT-d engine cannotThere's still a "VT-d" left in here...
Quoted 7 lines
Quoted 1 line
I mentioned AMD as well. Was trying to clarify things a bit more...
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
That's going a little too far: If IOMMU faults were recoverable, dealing with non-present pages would become possible (with other caveats of course). So this is not a fundamental attribute of IOMMUs, but there doesn't seem to be any reason to believe that the current model would change any time soon for either of the vendors.
Quoted 4 lines
Quoted 1 line
Do you have suggestion on how this comment should be phrased?
Just say "IOMMU" or "DMA remapping" instead of "VT-d".
OK, like this:
/* We cannot have PoD and PCI device assignment at the same time for HVM
* guest. It was reported that IOMMU cannot work with PoD enabled
* because it needs to populated entire page table for guest. To stay on
* the safe side, we disable PCI device assignment when PoD is enabled. */
Wei.
Quoted 1 line
Jan
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 16 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 7 lines · Wei Liu
Quoted 5 lines · Jan Beulich
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 725
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
tools/libxl/libxl_create.c +2
-0+/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot There's still a "VT-d" left in here...
I mentioned AMD as well. Was trying to clarify things a bit more...
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor neutral.
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
Quoted 8 lines
Quoted 6 lines
That's going a little too far: If IOMMU faults were recoverable, dealing with non-present pages would become possible (with other caveats of course). So this is not a fundamental attribute of IOMMUs, but there doesn't seem to be any reason to believe that the current model would change any time soon for either of the vendors.
Do you have suggestion on how this comment should be phrased?
Just say "IOMMU" or "DMA remapping" instead of "VT-d".
Jan
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 1 line · Wei Liu
On Fri, Jan 10, 2014 at 11:39:51AM +0000, Jan Beulich wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Liu
(quoted diff) +2
-0+ /* We cannot have PoD and PCI device assignment at the same time + * for HVM guest. It was reported that VT-d engine cannotThere's still a "VT-d" left in here...
I mentioned AMD as well. Was trying to clarify things a bit more...
Use "IOMMU"/"PCI Passthrough"/etc as appropriate, which are vendor
neutral.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
There is no way for for PoD (or Paging for that matter) to work in combination with PCIPassthrough, as you need all the backing RAM for all gfns to exist to receive DMA.
That's going a little too far: If IOMMU faults were recoverable, dealing with non-present pages would become possible (with other caveats of course). So this is not a fundamental attribute of IOMMUs, but there doesn't seem to be any reason to believe that the current model would change any time soon for either of the vendors.
Quoted 4 lines
Quoted 1 line
Do you have suggestion on how this comment should be phrased?
Just say "IOMMU" or "DMA remapping" instead of "VT-d".
Quoted 7 lines
OK, like this:
/* We cannot have PoD and PCI device assignment at the same time for HVM
* guest. It was reported that IOMMU cannot work with PoD enabled
* because it needs to populated entire page table for guest. To stay on
* the safe side, we disable PCI device assignment when PoD is enabled. */
Sound fine to me. As does Ian's suggestion.
Jan
Any more comments on code logic and / or the location of the new snippet? Should I send a new version with code comment fixed?
Thanks
Wei.
Quoted 59 lines · Wei Liu
This replicates a Xend behavior, see
ec789523749("xend: Dis-allow device assignment if PoD is enabled.").This change is restricted to HVM guest, as only VT-d is relevant in the counterpart in Xend. We're late in release cycle so the change should only do what's necessary. Probably we can revisit it if we need to do the same thing for PV guest in the future.
Signed-off-by Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Xiantao Zhang <[email protected]>--- tools/libxl/libxl_create.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)tools/libxl/libxl_create.c +22
-0@@ -706,6 +706,7 @@ static void initiate_domain_create(libxl__egc *egc,libxl_ctx *ctx =libxl__gc_owner (gc);uint32_t domid;int i, ret; +bool pod_enabled = false;/* convenience aliases */ libxl_domain_config *const d_config = dcs->guest_config;@@ -714,6 +715,27 @@ static void initiate_domain_create(libxl__egc *egc, domid =0 ; +/* If target_memkb is smaller than max_memkb, the subsequent call +* to libxc when building HVM domain will enable PoD mode. +*/ + pod_enabled = (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM ) && + (d_config->b_info.target_memkb < d_config->b_info.max_memkb); + +/* We cannot have PoD and PCI device assignment at the same time +* for HVM guest. It was reported that VT-d engine cannot +* work with PoD enabled because it needs to populated entire page +* table for guest. Also a quick grep through AMD IOMMU related +* code suggests it has not coped with PoD as well. Just to stay +* on the safe side, we disable PCI device assignment with PoD all +* together, regardless of the underlying IOMMU in use. +*/ +if (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM && + d_config->num_pcidevs && pod_enabled) { + ret =ERROR_INVAL ; +LOG (ERROR ,"PCI device assignment for HVM guest failed due to PoD enabled" ); + goto error_out; + } + ret =libxl__domain_create_info_setdefault (gc, &d_config->c_info);if (ret) goto error_out;Signature · 1 line
1.7.10.4
Quoted 8 lines · Wei Liu
Any more comments on code logic and / or the location of the new snippet? Should I send a new version with code comment fixed? [...]
Quoted 5 lines
tools/libxl/libxl_create.c +5
-0+/* If target_memkb is smaller than max_memkb, the subsequent call +* to libxc when building HVM domain will enable PoD mode. +*/ + pod_enabled = (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM ) && + (d_config->b_info.target_memkb < d_config->b_info.max_memkb);
I suppose this corresponds to exactly when PoD would be enabled?
I'm happy with the patch, and it would be better to go ahead now than to wait for George (with his PoD hat in place) to confirm/deny, so please resend with the improved comment.
Ian.
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Wei Liu
Any more comments on code logic and / or the location of the new snippet? Should I send a new version with code comment fixed? [...]
Quoted 8 lines
Quoted 5 lines
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 722
Quoted 5 lines
tools/libxl/libxl_create.c +5
-0+/* If target_memkb is smaller than max_memkb, the subsequent call +* to libxc when building HVM domain will enable PoD mode. +*/ + pod_enabled = (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM ) && + (d_config->b_info.target_memkb < d_config->b_info.max_memkb);I suppose this corresponds to exactly when PoD would be enabled?
Yes. In libxc if maxmem > target_mem then pod_mode is set. See tools/libxc/xc_hvm_build_x86.c:setup_guest.
Quoted 3 lines
I'm happy with the patch, and it would be better to go ahead now than to wait for George (with his PoD hat in place) to confirm/deny, so please resend with the improved comment.
Will do.
Wei.
Quoted 3 lines
Ian.
Quoted 11 lines · Wei Liu
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Wei Liu
Any more comments on code logic and / or the location of the new snippet? Should I send a new version with code comment fixed? [...]
Quoted 5 lines
tools/libxl/libxl_create.c +5
-0+/* If target_memkb is smaller than max_memkb, the subsequent call +* to libxc when building HVM domain will enable PoD mode. +*/ + pod_enabled = (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_HVM ) && + (d_config->b_info.target_memkb < d_config->b_info.max_memkb);
Quoted 5 lines
Quoted 2 lines
I suppose this corresponds to exactly when PoD would be enabled?
Yes. In libxc if maxmem >
target_memthenpod_modeis set. See tools/libxc/xc_hvm_build_x86.c:setup_guest.
Putting this into a common place might be a nice future cleanup...
Ian.