gnttab: don't expose host physical address without need
PATCH v4 1/1 gnttab: don't expose host physical address without need
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when GNTMAP_device_map is not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless. (Similarly mapkind() should check only GNTMAP_device_map.)
Along these lines split the paging mode related check near the top of map_grant_ref() to handle the "external" and "translated" cases separately (GNTMAP_device_map use getting tied to being non-translated rather than non-external).
Still along these lines in the unmapping case there's no point checking ->dev_bus_addr when GNTMAP_device_map isn't set (and hence the field isn't going to be consumed).
---
v4: Re-base over dropped patches.
v3: New.
xen/common/grant_table.c +12 -5
@@ -967,10 +967,16 @@ map_grant_ref( }if (unlikely (paging_mode_external (ld) && - (op->flags & (GNTMAP_device_map|GNTMAP_application_map| - GNTMAP_contains_pte))) ) + (op->flags & (GNTMAP_application_map|GNTMAP_contains_pte))) ) { -gdprintk (XENLOG_INFO ,"No device mapping in HVM domain\n" ); +gdprintk (XENLOG_INFO ,"No app/pte mapping in HVM domain\n" ); + op->status = GNTST_general_error; +return ; + } + +if (paging_mode_translate (ld) &&unlikely (op->flags & GNTMAP_device_map) ) + { +gdprintk (XENLOG_INFO ,"No device mapping in translated domain\n" ); op->status = GNTST_general_error;return ; }
@@ -1213,7 +1219,8 @@ map_grant_ref(if ( need_iommu )double_gt_unlock (lgt, rgt); - op->dev_bus_addr =mfn_to_maddr (mfn); + op->dev_bus_addr =paging_mode_translate (ld) ? op->host_addr + :mfn_to_maddr (mfn); op->handle = handle; op->status = GNTST_okay;
@@ -1394,7 +1401,7 @@ unmap_common( op->mfn = act->mfn; -if ( op->dev_bus_addr && +if ( op->dev_bus_addr && (flags & GNTMAP_device_map) &&unlikely (op->dev_bus_addr !=mfn_to_maddr (act->mfn)) ) PIN_FAIL(act_release_out, GNTST_general_error, "Bus address doesn't match gntref (%"PRIx64" != %"PRIpaddr")\n",
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Jan Beulich
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when
GNTMAP_device_mapis not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless.
This really means that the public header needs correcting. The field may not have intended to escape out of Xen, but it is defacto part of the ABI now.
Quoted 1 line
(Similarly
mapkind()should check onlyGNTMAP_device_map.)
Is this comment stale, or have I misunderstood some of the reasoning?
Quoted 48 lines
Along these lines split the paging mode related check near the top of
map_grant_ref()to handle the "external" and "translated" cases separately (GNTMAP_device_mapuse getting tied to being non-translated rather than non-external).Still along these lines in the unmapping case there's no point checking ->dev_bus_addr when
GNTMAP_device_mapisn't set (and hence the field isn't going to be consumed).Signed-off-by Jan Beulich <[email protected]>---
v4: Re-base over dropped patches.
v3: New.xen/common/grant_table.c +11
-4@@ -967,10 +967,16 @@ map_grant_ref( }if (unlikely (paging_mode_external (ld) && - (op->flags & (GNTMAP_device_map|GNTMAP_application_map| - GNTMAP_contains_pte))) ) + (op->flags & (GNTMAP_application_map|GNTMAP_contains_pte))) ) { -gdprintk (XENLOG_INFO ,"No device mapping in HVM domain\n" ); +gdprintk (XENLOG_INFO ,"No app/pte mapping in HVM domain\n" ); + op->status = GNTST_general_error; +return ; + } + +if (paging_mode_translate (ld) &&unlikely (op->flags & GNTMAP_device_map) ) + { +gdprintk (XENLOG_INFO ,"No device mapping in translated domain\n" ); op->status = GNTST_general_error;return ; }@@ -1213,7 +1219,8 @@ map_grant_ref(if ( need_iommu )double_gt_unlock (lgt, rgt); - op->dev_bus_addr =mfn_to_maddr (mfn); + op->dev_bus_addr =paging_mode_translate (ld) ? op->host_addr + :mfn_to_maddr (mfn); op->handle = handle; op->status = GNTST_okay;
xen/common/grant_table.c unmap_common( · line 1404
Quoted 5 lines
xen/common/grant_table.c +1
-1@@ -1394,7 +1401,7 @@ unmap_common( op->mfn = act->mfn; - if ( op->dev_bus_addr && + if ( op->dev_bus_addr && (flags & GNTMAP_device_map) &&
Drop the first clause entirely? act->mfn will never be 0 so can subsume the check with one fewer branch.
~Andrew
xen/common/grant_table.c unmap_common( · line 1407
Quoted 3 lines
xen/common/grant_table.c +0
-0unlikely(op->dev_bus_addr != mfn_to_maddr(act->mfn)) ) PIN_FAIL(act_release_out, GNTST_general_error, "Bus address doesn't match gntref (%"PRIx64" != %"PRIpaddr")\n",
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Andrew Cooper
xen/common/grant_table.c unmap_common( · line 1404
Quoted 8 lines
xen/common/grant_table.c +1
-1@@ -1394,7 +1401,7 @@ unmap_common( op->mfn = act->mfn; - if ( op->dev_bus_addr && + if ( op->dev_bus_addr && (flags & GNTMAP_device_map) &&Drop the first clause entirely?
act->mfnwill never be 0 so can subsume the check with one fewer branch.
Never mind. I've just remembered why 0 is special, and the check needs to stay.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when
GNTMAP_device_mapis not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless.This really means that the public header needs correcting. The field may not have intended to escape out of Xen, but it is defacto part of the ABI now.
Well, that's one of two possible routes. The other is to have, like you did suggest earlier on, a mode in which we behave more strictly, and current Linux then wouldn't work on such a Xen until fixed.
Quoted 3 lines
Quoted 1 line
(Similarly
mapkind()should check onlyGNTMAP_device_map.)Is this comment stale, or have I misunderstood some of the reasoning?
It's certainly not stale. mapkind() is used to determine whether IOMMU mapping adjustments are needed. With this, it should in principle only consider whether the current operation would possibly alter IOMMU mapping needs. What needs doing should, according to my interpretation of the originally intended design, only depend on current and prior requests with GNTMAP_device_map set.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when
GNTMAP_device_mapis not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless.
Quoted 6 lines
Quoted 3 lines
This really means that the public header needs correcting. The field may not have intended to escape out of Xen, but it is defacto part of the ABI now.
Well, that's one of two possible routes. The other is to have, like you did suggest earlier on, a mode in which we behave more strictly, and current Linux then wouldn't work on such a Xen until fixed.
I'm sorely tempted to introduce a "fully strict mode" right now, behind a command line option, which chops off all the bits which shouldn't be usable in their current form.
However, nothing, not even dom0, will boot successfully, so it probably isn't a great idea right now. Also, we'd have an easier time starting from nothing and whitelisting ok things in, than attempt to locate everything that we should blacklist in the current configuration.
Quoted 10 lines
Quoted 3 lines
Quoted 2 lines
(Similarly
mapkind()should check onlyGNTMAP_device_map.)Is this comment stale, or have I misunderstood some of the reasoning?
It's certainly not stale.
mapkind()is used to determine whether IOMMU mapping adjustments are needed. With this, it should in principle only consider whether the current operation would possibly alter IOMMU mapping needs. What needs doing should, according to my interpretation of the originally intended design, only depend on current and prior requests withGNTMAP_device_mapset.
That's all reasonable, but there are no edits to mapkind(), so I'm confused as to why this is present in the commit message.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when
GNTMAP_device_mapis not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless.Quoted 6 lines
Quoted 3 lines
This really means that the public header needs correcting. The field may not have intended to escape out of Xen, but it is defacto part of the ABI now.
Well, that's one of two possible routes. The other is to have, like you did suggest earlier on, a mode in which we behave more strictly, and current Linux then wouldn't work on such a Xen until fixed.
Quoted 8 lines
I'm sorely tempted to introduce a "fully strict mode" right now, behind a command line option, which chops off all the bits which shouldn't be usable in their current form.
However, nothing, not even dom0, will boot successfully, so it probably isn't a great idea right now. Also, we'd have an easier time starting from nothing and whitelisting ok things in, than attempt to locate everything that we should blacklist in the current configuration.
Okay, I'll add a remark to the public header comment then for now.
Quoted 10 lines
Quoted 9 lines
Quoted 2 lines
Quoted 1 line
(Similarly
mapkind()should check onlyGNTMAP_device_map.)Is this comment stale, or have I misunderstood some of the reasoning?
It's certainly not stale.
mapkind()is used to determine whether IOMMU mapping adjustments are needed. With this, it should in principle only consider whether the current operation would possibly alter IOMMU mapping needs. What needs doing should, according to my interpretation of the originally intended design, only depend on current and prior requests withGNTMAP_device_mapset.
Quoted 2 lines
That's all reasonable, but there are no edits to
mapkind(), so I'm confused as to why this is present in the commit message.
Well, it's the same underlying problem - improper separation of host_map from device_map. I've added this just to emphasize that this likely wasn't an oversight, but intentional (yet wrong, at least afaict).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi,
Quoted 28 lines · Jan Beulich
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when
GNTMAP_device_mapis not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless. (Similarlymapkind()should check onlyGNTMAP_device_map.)Along these lines split the paging mode related check near the top of
map_grant_ref()to handle the "external" and "translated" cases separately (GNTMAP_device_mapuse getting tied to being non-translated rather than non-external).Still along these lines in the unmapping case there's no point checking ->dev_bus_addr when
GNTMAP_device_mapisn't set (and hence the field isn't going to be consumed).Signed-off-by Jan Beulich <[email protected]>---
v4: Re-base over dropped patches.
v3: New.xen/common/grant_table.c +0
-1@@ -967,10 +967,16 @@ map_grant_ref( } if ( unlikely(paging_mode_external(ld) && - (op->flags & (GNTMAP_device_map|GNTMAP_application_map|
xen/common/grant_table.c map_grant_ref( · line 977
Quoted 10 lines
xen/common/grant_table.c +7
-2- GNTMAP_contains_pte))) ) + (op->flags & (GNTMAP_application_map|GNTMAP_contains_pte))) ) { -gdprintk (XENLOG_INFO ,"No device mapping in HVM domain\n" ); +gdprintk (XENLOG_INFO ,"No app/pte mapping in HVM domain\n" ); + op->status = GNTST_general_error; +return ; + } + +if (paging_mode_translate (ld) &&unlikely (op->flags & GNTMAP_device_map) )
There is at least one instance in Linux where GNTMAP_device_map may be given regardless the type of the guest. See dmabuf_exp_from_refs() in drivers/xen/gntdev-dmabuf.c.
How are you going to deal with them?
xen/common/grant_table.c map_grant_ref( · line 1223
Quoted 12 lines
xen/common/grant_table.c +4
-1+ { +gdprintk (XENLOG_INFO ,"No device mapping in translated domain\n" ); op->status = GNTST_general_error;return ; }@@ -1213,7 +1219,8 @@ map_grant_ref(if ( need_iommu )double_gt_unlock (lgt, rgt); - op->dev_bus_addr =mfn_to_maddr (mfn); + op->dev_bus_addr =paging_mode_translate (ld) ? op->host_addr + :mfn_to_maddr (mfn);
The "host_addr" is pretty confusing. I first thought it would be a "Host Physical Address" but it seems to be a "Guest Physical address"
If so, this is going to break Linux Dom0 on Arm where it is expected to return the machine physical address to have a DMA fully working.
I don't abide with the current behavior on Arm, but I don't think we should break them when there are no replacement for it.
So it would be better if we look at a different approach (i.e a new flag or strict mode) in order to avoid breakage.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 44 lines · Julien Grall
Quoted 28 lines · Jan Beulich
Translated domains shouldn't see host physical addresses. While the address is also not supposed to be handed back even to non-translated domains when
GNTMAP_device_mapis not set (as explicitly stated by a comment in the public header), PV kernels (Linux at least) assume the field to get populated nevertheless. (Similarlymapkind()should check onlyGNTMAP_device_map.)Along these lines split the paging mode related check near the top of
map_grant_ref()to handle the "external" and "translated" cases separately (GNTMAP_device_mapuse getting tied to being non-translated rather than non-external).Still along these lines in the unmapping case there's no point checking ->dev_bus_addr when
GNTMAP_device_mapisn't set (and hence the field isn't going to be consumed).Signed-off-by Jan Beulich <[email protected]>---
v4: Re-base over dropped patches.
v3: New.xen/common/grant_table.c +0
-1@@ -967,10 +967,16 @@ map_grant_ref( } if ( unlikely(paging_mode_external(ld) && - (op->flags & (GNTMAP_device_map|GNTMAP_application_map|xen/common/grant_table.c map_grant_ref( · line 977
Quoted 10 lines
xen/common/grant_table.c +7
-2- GNTMAP_contains_pte))) ) + (op->flags & (GNTMAP_application_map|GNTMAP_contains_pte))) ) { -gdprintk (XENLOG_INFO ,"No device mapping in HVM domain\n" ); +gdprintk (XENLOG_INFO ,"No app/pte mapping in HVM domain\n" ); + op->status = GNTST_general_error; +return ; + } + +if (paging_mode_translate (ld) &&unlikely (op->flags & GNTMAP_device_map) )There is at least one instance in Linux where
GNTMAP_device_mapmay be given regardless the type of the guest. Seedmabuf_exp_from_refs()indrivers/xen/gntdev-dmabuf.c.
Quoted 1 line
How are you going to deal with them?
I didn't spot that case, nor ...
Quoted 11 lines
xen/common/grant_table.c map_grant_ref( · line 1223
Quoted 7 lines
xen/common/grant_table.c +2
-1@@ -1213,7 +1219,8 @@ map_grant_ref(if ( need_iommu )double_gt_unlock (lgt, rgt); - op->dev_bus_addr =mfn_to_maddr (mfn); + op->dev_bus_addr =paging_mode_translate (ld) ? op->host_addr + :mfn_to_maddr (mfn);The "
host_addr" is pretty confusing. I first thought it would be a "Host Physical Address" but it seems to be a "Guest Physical address"
Quoted 2 lines
If so, this is going to break Linux Dom0 on Arm where it is expected to return the machine physical address to have a DMA fully working.
... this.
Quoted 2 lines
I don't abide with the current behavior on Arm, but I don't think we should break them when there are no replacement for it.
I agree; I didn't mean to break anything here. The state of things then means that I need to withdraw this patch, ...
Quoted 2 lines
So it would be better if we look at a different approach (i.e a new flag or strict mode) in order to avoid breakage.
... without any replacement (at least for the time being).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel