xen: arm: process XENMEM_add_to_physmap_range forwards not backwards.
PATCH 1/1 xen: arm: process XENMEM_add_to_physmap_range forwards not backwards.
Jan points out that processing the list backwards is rather counter intuitive and that the effect of the hypercall can differ between forwards and backwards processing (e.g. in the presence of duplicate idx or gpfn, which would be unusualy but as Jan says, users are a creative bunch)
---
Release: subtle ABI change, should go in to 4.4 before people rely on it (they are not relying on it today TTBOMK and it seems unlikely but lets not risk it)
--- xen/arch/arm/mm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
xen/arch/arm/mm.c +5 -7
@@ -1062,21 +1062,18 @@ static int xenmem_add_to_physmap_range(struct domain *d, {int rc; -/* Process entries in reverse order to allow continuations */ while ( xatpr->size >0 ) {xen_ulong_t idx;xen_pfn_t gpfn; -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs, - xatpr->size-1 ,1 )) ) +if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) { rc = -EFAULT ; goto out; } -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns, - xatpr->size-1 ,1 )) ) +if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) { rc = -EFAULT ; goto out;
@@ -1086,8 +1083,7 @@ static int xenmem_add_to_physmap_range(struct domain *d, xatpr->foreign_domid, idx, gpfn); -if (unlikely (copy_to_guest_offset (xatpr->errs, - xatpr->size-1 , &rc,1 )) ) +if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) { rc = -EFAULT ; goto out;
@@ -1096,6 +1092,8 @@ static int xenmem_add_to_physmap_range(struct domain *d,if ( rc <0 ) goto out; +guest_handle_add_offset (xatpr->idxs,1 ); +guest_handle_add_offset (xatpr->gpfns,1 ); xatpr->size--;/* Check for continuation if it's not the last interation */
Signature · 1 line
1.7.10.4
Quoted 60 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Jan points out that processing the list backwards is rather counter intuitive and that the effect of the hypercall can differ between forwards and backwards
processing (e.g. in the presence of duplicate idx or gpfn, which would be unusualy but as Jan says, users are a creative bunch)Signed-off-by Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>Cc Mukesh Rathor <[email protected]>---
Release: subtle ABI change, should go in to 4.4 before people rely on it (they
are not relying on it today TTBOMK and it seems unlikely but lets not risk it)--- xen/arch/arm/mm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)xen/arch/arm/mm.c +2
-5@@ -1062,21 +1062,18 @@ static int xenmem_add_to_physmap_range(struct domain *d, {int rc; -/* Process entries in reverse order to allow continuations */ while ( xatpr->size >0 ) {xen_ulong_t idx;xen_pfn_t gpfn; -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs, - xatpr->size-1 ,1 )) ) +if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) { rc = -EFAULT ; goto out; } -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns, - xatpr->size-1 ,1 )) ) +if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) { rc = -EFAULT ;goto out;xen/arch/arm/mm.c +1
-2@@ -1086,8 +1083,7 @@ static int xenmem_add_to_physmap_range(struct domain *d, xatpr->foreign_domid, idx, gpfn); -if (unlikely (copy_to_guest_offset (xatpr->errs, - xatpr->size-1 , &rc,1 )) ) +if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) { rc = -EFAULT ;goto out;
xen/arch/arm/mm.c static int xenmem_add_to_physmap_range(struct domain *d, · line 1096
Quoted 5 lines
xen/arch/arm/mm.c +2
-0@@ -1096,6 +1092,8 @@ static int xenmem_add_to_physmap_range(struct domain *d,if ( rc <0 ) goto out; +guest_handle_add_offset (xatpr->idxs,1 ); +guest_handle_add_offset (xatpr->gpfns,1 );
What about ->errs?
And anyway - as I said in an earlier response to the original thread, _if_ we want to stay with modifying the interface structure here, we need to document that in the public header. Personally I'd favor this inconsistent behavior to get fixed.
Jan
Quoted 63 lines · Jan Beulich
Quoted 63 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Jan points out that processing the list backwards is rather counter intuitive and that the effect of the hypercall can differ between forwards and backwards
processing (e.g. in the presence of duplicate idx or gpfn, which would be unusualy but as Jan says, users are a creative bunch)Signed-off-by Ian Campbell <[email protected]>Cc Jan Beulich <[email protected]>Cc Mukesh Rathor <[email protected]>---
Release: subtle ABI change, should go in to 4.4 before people rely on it (they
are not relying on it today TTBOMK and it seems unlikely but lets not risk it)--- xen/arch/arm/mm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)xen/arch/arm/mm.c +2
-5@@ -1062,21 +1062,18 @@ static int xenmem_add_to_physmap_range(struct domain *d, {int rc; -/* Process entries in reverse order to allow continuations */ while ( xatpr->size >0 ) {xen_ulong_t idx;xen_pfn_t gpfn; -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs, - xatpr->size-1 ,1 )) ) +if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) { rc = -EFAULT ; goto out; } -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns, - xatpr->size-1 ,1 )) ) +if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) { rc = -EFAULT ;goto out;xen/arch/arm/mm.c +1
-2@@ -1086,8 +1083,7 @@ static int xenmem_add_to_physmap_range(struct domain *d, xatpr->foreign_domid, idx, gpfn); -if (unlikely (copy_to_guest_offset (xatpr->errs, - xatpr->size-1 , &rc,1 )) ) +if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) { rc = -EFAULT ;goto out;xen/arch/arm/mm.c +0
-0@@ -1096,6 +1092,8 @@ static int xenmem_add_to_physmap_range(struct domain *d,if ( rc <0 ) goto out;
Quoted 4 lines
xen/arch/arm/mm.c static int xenmem_add_to_physmap_range(struct domain *d, · line 1096
Quoted 2 lines
xen/arch/arm/mm.c +2
-0+guest_handle_add_offset (xatpr->idxs,1 ); +guest_handle_add_offset (xatpr->gpfns,1 );What about ->errs?
Oops! Well spotted. I'll hold of on v2 until:
Quoted 4 lines
And anyway - as I said in an earlier response to the original thread, _if_ we want to stay with modifying the interface structure here, we need to document that in the public header. Personally I'd favor this inconsistent behavior to get fixed.
I've only just seen that comment, I replied there...
By "fixed" you mean the API doc updated or using the upper bits?
Ian.
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 4 lines · Jan Beulich
And anyway - as I said in an earlier response to the original thread, _if_ we want to stay with modifying the interface structure here, we need to document that in the public header. Personally I'd favor this inconsistent behavior to get fixed.
I've only just seen that comment, I replied there...
By "fixed" you mean the API doc updated or using the upper bits?
The latter. But as just said on the other thread - we first need to settle on which route to go here (since if we allow this here, there's no reason why the same shouldn't be done elsewhere).
Jan