Skip to contentSkip to conversation

x86/CPUID: suppress IOMMU related hypervisor leaf data

PATCH In review Jan Beulich 3 participants 9 messages Nov 9, 2020 – Jan 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/CPUID: suppress IOMMU related hypervisor leaf data

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

xen/arch/x86/traps.c +2 -1
@@ -1050,7 +1050,8 @@ void cpuid_hypervisor_leaves(const struc
          * Indicate that memory mapped from other domains (either grants or
          * foreign pages) has valid IOMMU entries.
          */
-        res->a |= XEN_HVM_CPUID_IOMMU_MAPPINGS;
+        if ( is_iommu_enabled(d) )
+            res->a |= XEN_HVM_CPUID_IOMMU_MAPPINGS;
 
         /* Indicate presence of vcpu id and set it in ebx */
         res->a |= XEN_HVM_CPUID_VCPU_ID_PRESENT;
#2 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

Roger.

#3 lore raw
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Quoted 6 lines

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

I'm afraid I don't understand your concern and/or description of the scenario. Prior to the change, the bit was set unconditionally. To me, _that_ was making the bit useless - no point in checking something which is always set anyway (leaving aside old Xen versions). I also don't follow how presence / absence of a passed through device mattering (or not) would have changed with this patch.

Jan

#4 lore raw
Quoted 20 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Quoted 6 lines

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

Quoted 5 lines

I'm afraid I don't understand your concern and/or description of the scenario. Prior to the change, the bit was set unconditionally. To me, _that_ was making the bit useless - no point in checking something which is always set anyway (leaving aside old Xen versions).

This bit was used to differentiate between versions of Xen that don't create IOMMU mappings for grants/foreign maps (and so are broken) vs versions of Xen that do create such mappings. If the bit is not set HVM domains need a bounce buffer in blkback/netback in order to avoid sending grants to devices.

Now it's my understand that with this change sometimes the bit might not be set not because we are running on an unfixed Xen version, but because there's no IOMMU assigned to the domain, so the guest will fallback to use a bounce buffer.

Thanks, Roger.

#5 lore raw
Quoted 24 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich
Quoted 11 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Quoted 6 lines

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

Quoted 5 lines

I'm afraid I don't understand your concern and/or description of the scenario. Prior to the change, the bit was set unconditionally. To me, _that_ was making the bit useless - no point in checking something which is always set anyway (leaving aside old Xen versions).

Quoted 5 lines

This bit was used to differentiate between versions of Xen that don't create IOMMU mappings for grants/foreign maps (and so are broken) vs versions of Xen that do create such mappings. If the bit is not set HVM domains need a bounce buffer in blkback/netback in order to avoid sending grants to devices.

And remember that "send to devices" != "has an IOMMU".

An HVM backend would need to bounce buffer to use an emulated NVME device, because there is no distinction between emulated and real DMA from the guest kernels point of view.

The bit actually means "Xen doesn't screw up grant maps which requested a DMA mapping any more".

~Andrew

P.S. If you wonder why I picked the NVME example, its because it turns out that NVME emulated by Qemu has better performance than the PV blk protocol.

#6 lore raw
In reply to Roger Pau Monné
Quoted 27 lines · Roger Pau Monné
Quoted 20 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Quoted 6 lines

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

Quoted 5 lines

I'm afraid I don't understand your concern and/or description of the scenario. Prior to the change, the bit was set unconditionally. To me, _that_ was making the bit useless - no point in checking something which is always set anyway (leaving aside old Xen versions).

Quoted 5 lines

This bit was used to differentiate between versions of Xen that don't create IOMMU mappings for grants/foreign maps (and so are broken) vs versions of Xen that do create such mappings. If the bit is not set HVM domains need a bounce buffer in blkback/netback in order to avoid sending grants to devices.

Neither the comment in cpuid.h nor that in traps.c have any mention of this, and the constant's name also doesn't imply such.

Quoted 4 lines

Now it's my understand that with this change sometimes the bit might not be set not because we are running on an unfixed Xen version, but because there's no IOMMU assigned to the domain, so the guest will fallback to use a bounce buffer.

... if it expects to ever map a foreign domain's pages.

I can see that reverting the change is one way to address the issue. Such a revert shouldn't be a plain one then, but one adjusting one or both of the the comments to indicate the _real_ purpose of this flag. (We probably better don't rename the constant, as we can't easily drop the old name from the public interface anyway.)

This said, I wonder though what the scenario is where the difference
matters: Dom0 will get the IOMMU enabled whenever Xen has it enabled. And I'm not sure how useful a driver domain would be without passed through device(s), implying an enabled IOMMU. IOW I'm not really certain there's any change in behavior for any sensible setup (and hence there wouldn't be any need to extend any logic, to e.g. figure out whether there are passed through devices). (Yes, a backend could sit on top of another frontend, acting in a proxy-like fashion. In this case the double buffering would indeed be unnecessary.)

Jan

#7 lore raw
Quoted 42 lines · Jan Beulich
Quoted 27 lines · Roger Pau Monné
Quoted 20 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Quoted 6 lines

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

Quoted 5 lines

I'm afraid I don't understand your concern and/or description of the scenario. Prior to the change, the bit was set unconditionally. To me, _that_ was making the bit useless - no point in checking something which is always set anyway (leaving aside old Xen versions).

Quoted 5 lines

This bit was used to differentiate between versions of Xen that don't create IOMMU mappings for grants/foreign maps (and so are broken) vs versions of Xen that do create such mappings. If the bit is not set HVM domains need a bounce buffer in blkback/netback in order to avoid sending grants to devices.

Neither the comment in cpuid.h nor that in traps.c have any mention of this, and the constant's name also doesn't imply such.

Quoted 4 lines

Now it's my understand that with this change sometimes the bit might not be set not because we are running on an unfixed Xen version, but because there's no IOMMU assigned to the domain, so the guest will fallback to use a bounce buffer.

Quoted 7 lines

... if it expects to ever map a foreign domain's pages.

I can see that reverting the change is one way to address the issue. Such a revert shouldn't be a plain one then, but one adjusting one or both of the the comments to indicate the _real_ purpose of this flag. (We probably better don't rename the constant, as we can't easily drop the old name from the public interface anyway.)

I'm happy to send the revert, but do you have any suggestion about the fixed comments?

Maybe adding something like:

/*
* Unditionally set the flag to notice this version of Xen has been
* fixed to create IOMMU mappings for grant/foreign maps. */

Thanks, Roger.

#8 lore raw
Quoted 54 lines · Roger Pau Monné
Quoted 42 lines · Jan Beulich
Quoted 27 lines · Roger Pau Monné
Quoted 20 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich

Now that the IOMMU for guests can't be enabled "on demand" anymore, there's also no reason to expose the related CPUID bit "just in case".

I'm not sure this is helpful from a guest PoV.

How does the guest know whether it has pass through devices, and thus whether it needs to check if this flag is present or not in order to safely pass foreign mapped pages (or grants) to the underlying devices?

Quoted 6 lines

Ie: prior to this change I would just check whether the flag is present in CPUID to know whether FreeBSD needs to use a bounce buffer in blkback and netback when running as a domU. If this is now conditionally set only when the IOMMU is enabled for the guest I also need to figure a way to know whether the domU has any passed through device or not, which doesn't seem trivial.

Quoted 5 lines

I'm afraid I don't understand your concern and/or description of the scenario. Prior to the change, the bit was set unconditionally. To me, _that_ was making the bit useless - no point in checking something which is always set anyway (leaving aside old Xen versions).

Quoted 5 lines

This bit was used to differentiate between versions of Xen that don't create IOMMU mappings for grants/foreign maps (and so are broken) vs versions of Xen that do create such mappings. If the bit is not set HVM domains need a bounce buffer in blkback/netback in order to avoid sending grants to devices.

Neither the comment in cpuid.h nor that in traps.c have any mention of this, and the constant's name also doesn't imply such.

Quoted 4 lines

Now it's my understand that with this change sometimes the bit might not be set not because we are running on an unfixed Xen version, but because there's no IOMMU assigned to the domain, so the guest will fallback to use a bounce buffer.

Quoted 7 lines

... if it expects to ever map a foreign domain's pages.

I can see that reverting the change is one way to address the issue. Such a revert shouldn't be a plain one then, but one adjusting one or both of the the comments to indicate the _real_ purpose of this flag. (We probably better don't rename the constant, as we can't easily drop the old name from the public interface anyway.)

I'm happy to send the revert, but do you have any suggestion about the fixed comments?

Quoted 6 lines

Maybe adding something like:

/*
* Unditionally set the flag to notice this version of Xen has been
* fixed to create IOMMU mappings for grant/foreign maps. */

Sounds reasonable. I assume you mean "Unconditionally". And my English isn't sufficient to tell whether "notice" is suitable here; I would have used e.g. "indicate".

Jan