fix preemption handling for XENMEM_add_to_physmap_range{, _range}
cover fix preemption handling for XENMEM_add_to_physmap_range{, _range}
The hypervisor isn't supposed to use the input structures for storing continuation information - only fields explicitly used as hypercall outputs should ever be updated.
Obviously this implies an ABI change, but since the previous behavior was not intended to be that way I don't think we should stick to the old behavior.
There's one caveat though - with the previous model, the caller could - upon failure - use the updated structure to find out how by progress was made. However, that wasn't intended afaict, largely supported by this information depending on hypervisor internals (i.e. the caller would have to know the order of request processing and the meaning of the respective size fields, which aren't simply saying "this much was processed").
Consequently, as a follow-up we may want to consider making explicit (and straight forward) this progress indication on error.
1: move XENMEM_add_to_physmap handling framework to common code 2: fix XENMEM_add_to_physmap preemption handling
3: move XENMEM_add_to_physmap_range handling framework to common code 4: fix XENMEM_add_to_physmap_range preemption handling
PATCH 1/4 move XENMEM_add_to_physmap handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
Note that ARM's restriction of XENMAPSPACE_gmfn_foreign only being supported through XENMEM_add_to_physmap_range is being dropped as being pointless.
xen/arch/arm/mm.c +1 -32
@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,
@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;
xen/arch/x86/mm.c +24 -103
193 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +0 -28
@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;
xen/common/compat/memory.c +20 -0
@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );
@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ; + +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;
xen/common/memory.c +81 -0
93 lines not on this page · raw message
xen/include/xen/mm.h +4 -0
@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
move XENMEM_add_to_physmap handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
Note that ARM's restriction of XENMAPSPACE_gmfn_foreign only being supported through XENMEM_add_to_physmap_range is being dropped as being pointless.
xen/arch/arm/mm.c +1 -32
@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,
@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;
xen/arch/x86/mm.c +24 -103
193 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +0 -28
@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;
xen/common/compat/memory.c +20 -0
@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );
@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ; + +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;
xen/common/memory.c +81 -0
93 lines not on this page · raw message
xen/include/xen/mm.h +4 -0
@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/4] move XENMEM_add_to_physmap handling framework to common code
Quoted 7 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note that ARM's restriction of
XENMAPSPACE_gmfn_foreignonly being supported throughXENMEM_add_to_physmap_rangeis being dropped as being pointless.
It's not pointless, dropping this restriction turns a comprehensible EINVAL result into an incorrect ESRCH result. Which is incorrect because no domain was specified so how can it not exist.
I'd also rather avoid introducing unnecessary/legacy hypercalls to ARM if possible.
Quoted 67 lines
Signed-off-by Jan Beulich <[email protected]>xen/arch/arm/mm.c +1
-32@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;xen/common/memory.c +10
-0@@ -542,6 +542,53 @@ static long memory_exchange(XEN_GUEST_HAreturn rc; } +static int xenmem_add_to_physmap (struct domain *d, +struct xen_add_to_physmap *xatp) +{ +struct xen_add_to_physmap start_xatp; +int rc =0 ; + +if ( xatp->space != XENMAPSPACE_gmfn_range ) +return xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn); +
xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 564
Quoted 10 lines
xen/common/memory.c +10
-0+#ifdef HAS_PASSTHROUGH +if (need_iommu (d) ) +this_cpu (iommu_dont_flush_iotlb) =1 ; +#endif + + start_xatp = *xatp; +while ( xatp->size >0 ) + { + rc =xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn);
ARM's xenmem_add_to_physmap_one does not support XENMAPSPACE_gmfn_range, so it will return ENOSYS and fail out. I suppose that is ok. But it makes the bulk of this function pointless.
How about pulling the != XENMAPSPACE_gmfn_range check into do_memory_op either calling xenmem_add_to_phymap_one or a per arch gmfn_range function?
xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 572
Quoted 8 lines
xen/common/memory.c +8
-0+if ( rc <0 ) +break ; + + xatp->idx++; + xatp->gpfn++; + xatp->size--; + +/* Check for continuation if it's not the last interation. */
That's the second or third time this "interation" typo has got copied ;-)
Quoted 63 lines
xen/common/memory.c +53
-0+if ( xatp->size >0 &&hypercall_preempt_check () ) + { + rc = -EAGAIN ; +break ; + } + } + +#ifdef HAS_PASSTHROUGH +if (need_iommu (d) ) + { +this_cpu (iommu_dont_flush_iotlb) =0 ; +iommu_iotlb_flush (d, start_xatp.idx, start_xatp.size - xatp->size); +iommu_iotlb_flush (d, start_xatp.gpfn, start_xatp.size - xatp->size); + } +#endif + +return rc; +} +long do_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d;@@ -673,6 +720,40 @@ long do_memory_op(unsigned long cmd, XENbreak ; +case XENMEM_add_to_physmap: + { +struct xen_add_to_physmap xatp; + +if (copy_from_guest (&xatp, arg,1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (xatp.domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); +if ( rc ) + { +rcu_unlock_domain (d); +return rc; + } + + rc =xenmem_add_to_physmap (d, &xatp); + +rcu_unlock_domain (d); + +if ( xatp.space == XENMAPSPACE_gmfn_range && rc == -EAGAIN ) + { +if ( !__copy_to_guest (arg, &xatp,1 ) ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"ih" , op, arg); +else + rc = -EFAULT ; + } + +return rc; + } +case XENMEM_remove_from_physmap: {struct xen_remove_from_physmap xrfp;
Re: [PATCH 1/4] move XENMEM_add_to_physmap handling framework to common code
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 4 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().
Quoted 7 lines
Quoted 3 lines
Note that ARM's restriction of
XENMAPSPACE_gmfn_foreignonly being supported throughXENMEM_add_to_physmap_rangeis being dropped as being pointless.It's not pointless, dropping this restriction turns a comprehensible EINVAL result into an incorrect ESRCH result. Which is incorrect because no domain was specified so how can it not exist.
How can there have been no domain specified for a XENMAPSPACE_gmfn_foreign? If the field was left uninitialized, -ESRCH would be as valid as -EINVAL, and I don't think we specify for any hypercall that between multiple applicable error code a specific one would be preferred over others.
Quoted 2 lines
I'd also rather avoid introducing unnecessary/legacy hypercalls to ARM if possible.
I can understand that, but please also take the perspective that moving the architecture independent bits out should have been done much earlier, and (see below) adding a conditional here doesn't seem too attractive to me.
Quoted 25 lines
Quoted 10 lines
xen/common/memory.c +10
-0+static int xenmem_add_to_physmap (struct domain *d, +struct xen_add_to_physmap *xatp) +{ +struct xen_add_to_physmap start_xatp; +int rc =0 ; + +if ( xatp->space != XENMAPSPACE_gmfn_range ) +return xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn); +xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 564
Quoted 10 lines
xen/common/memory.c +10
-0+#ifdef HAS_PASSTHROUGH +if (need_iommu (d) ) +this_cpu (iommu_dont_flush_iotlb) =1 ; +#endif + + start_xatp = *xatp; +while ( xatp->size >0 ) + { + rc =xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn);ARM's
xenmem_add_to_physmap_onedoes not supportXENMAPSPACE_gmfn_range, so it will return ENOSYS and fail out. I suppose that is ok. But it makes the bulk of this function pointless.
Quoted 3 lines
How about pulling the !=
XENMAPSPACE_gmfn_rangecheck intodo_memory_opeither callingxenmem_add_to_phymap_oneor a per archgmfn_rangefunction?
No, I think having just one arch specific function dealing with everything, and having the common code really take care of as much as is common is the right thing (and considering the review by Tim and the ack from Keir, I think others agree).
Which would leave the option of adding a #ifdef CONFIG_ARM (or #ifndef CONFIG_X86) in the common code - not really nice.
Quoted 11 lines
xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 572
Quoted 8 lines
xen/common/memory.c +8
-0+if ( rc <0 ) +break ; + + xatp->idx++; + xatp->gpfn++; + xatp->size--; + +/* Check for continuation if it's not the last interation. */ That's the second or third time this "interation" typo has got copied ;-)
Fixed - I didn't look that closely at the comments I was moving around. Albeit I had noticed and fixed the missing stops...
Jan
Re: [PATCH 1/4] move XENMEM_add_to_physmap handling framework to common code
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 7 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note that ARM's restriction of
XENMAPSPACE_gmfn_foreignonly being supported throughXENMEM_add_to_physmap_rangeis being dropped as being pointless.
Quoted 6 lines
Quoted 3 lines
It's not pointless, dropping this restriction turns a comprehensible EINVAL result into an incorrect ESRCH result. Which is incorrect because no domain was specified so how can it not exist.
How can there have been no domain specified for a
XENMAPSPACE_gmfn_foreign?
The arguments to XENMEM_add_to_physmap have no field which specifies a foreign domain. (this is one of the reasons we added the _range version with the field in the first place).
The domid parameter to add_to_physmap one is why hardcoded to DOMID_INVALID in all the add_to_physmap (!range) cases.
Quoted 4 lines
If the field was left uninitialized,
-ESRCHwould be as valid as-EINVAL, and I don't think we specify for any hypercall that between multiple applicable error code a specific one would be preferred over others.
I think given the above -ESRCH is invalid, since there is no field to have been left uninitialised.
Quoted 7 lines
Quoted 2 lines
I'd also rather avoid introducing unnecessary/legacy hypercalls to ARM if possible.
I can understand that, but please also take the perspective that moving the architecture independent bits out should have been done much earlier, and (see below) adding a conditional here doesn't seem too attractive to me.
I don't think this should be a per arch conditional, if that's what you mean, just a blanket if ( ) return ENOSYS.
Quoted 29 lines
Quoted 25 lines
Quoted 10 lines
xen/common/memory.c +10
-0+static int xenmem_add_to_physmap (struct domain *d, +struct xen_add_to_physmap *xatp) +{ +struct xen_add_to_physmap start_xatp; +int rc =0 ; + +if ( xatp->space != XENMAPSPACE_gmfn_range ) +return xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn); +xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 564
Quoted 10 lines
xen/common/memory.c +10
-0+#ifdef HAS_PASSTHROUGH +if (need_iommu (d) ) +this_cpu (iommu_dont_flush_iotlb) =1 ; +#endif + + start_xatp = *xatp; +while ( xatp->size >0 ) + { + rc =xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn);ARM's
xenmem_add_to_physmap_onedoes not supportXENMAPSPACE_gmfn_range, so it will return ENOSYS and fail out. I suppose that is ok. But it makes the bulk of this function pointless.Quoted 3 lines
How about pulling the !=
XENMAPSPACE_gmfn_rangecheck intodo_memory_opeither callingxenmem_add_to_phymap_oneor a per archgmfn_rangefunction?
Quoted 7 lines
No, I think having just one arch specific function dealing with everything, and having the common code really take care of as much as is common is the right thing (and considering the review by Tim and the ack from Keir, I think others agree).
Which would leave the option of adding a #ifdef
CONFIG_ARM(or #ifndefCONFIG_X86) in the common code - not really nice.
(note that this is a different case to the above gmfn_range here vs gmfn_foreign there)
The #ifndef would be the better of those two, since I'd expect no other port to be added with this legacy interface. Another option would be HAVE_FOO.
But in any case leaving this is not too harmful since the end result is correct -ENOSYS anyway.
Ian.
Re: [PATCH 1/4] move XENMEM_add_to_physmap handling framework to common code
Quoted 26 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 7 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note that ARM's restriction of
XENMAPSPACE_gmfn_foreignonly being supported throughXENMEM_add_to_physmap_rangeis being dropped as being pointless.Quoted 6 lines
Quoted 3 lines
It's not pointless, dropping this restriction turns a comprehensible EINVAL result into an incorrect ESRCH result. Which is incorrect because no domain was specified so how can it not exist.
How can there have been no domain specified for a
XENMAPSPACE_gmfn_foreign?The arguments to
XENMEM_add_to_physmaphave no field which specifies a foreign domain. (this is one of the reasons we added the_rangeversion with the field in the first place).The domid parameter to
add_to_physmapone is why hardcoded toDOMID_INVALIDin all theadd_to_physmap(!range) cases.
Quoted 7 lines
Quoted 4 lines
If the field was left uninitialized,
-ESRCHwould be as valid as-EINVAL, and I don't think we specify for any hypercall that between multiple applicable error code a specific one would be preferred over others.I think given the above
-ESRCHis invalid, since there is no field to have been left uninitialised.
Oh, I finally understand. The thing that mainly confused me here is the wording of the original comment: "Foreign mapping is only supported by add_to_physmap_range". Whereas it should have said "Foreign mapping is only possible through add_to_physmap_range". I'll re-add that with the adjusted comment.
Will that make the patch acceptable to you?
Jan
Re: [PATCH 1/4] move XENMEM_add_to_physmap handling framework to common code
Quoted 34 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 7 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note that ARM's restriction of
XENMAPSPACE_gmfn_foreignonly being supported throughXENMEM_add_to_physmap_rangeis being dropped as being pointless.Quoted 6 lines
Quoted 3 lines
It's not pointless, dropping this restriction turns a comprehensible EINVAL result into an incorrect ESRCH result. Which is incorrect because no domain was specified so how can it not exist.
How can there have been no domain specified for a
XENMAPSPACE_gmfn_foreign?The arguments to
XENMEM_add_to_physmaphave no field which specifies a foreign domain. (this is one of the reasons we added the_rangeversion with the field in the first place).The domid parameter to
add_to_physmapone is why hardcoded toDOMID_INVALIDin all theadd_to_physmap(!range) cases.Quoted 7 lines
Quoted 4 lines
If the field was left uninitialized,
-ESRCHwould be as valid as-EINVAL, and I don't think we specify for any hypercall that between multiple applicable error code a specific one would be preferred over others.I think given the above
-ESRCHis invalid, since there is no field to have been left uninitialised.
Quoted 6 lines
Oh, I finally understand. The thing that mainly confused me here is the wording of the original comment: "Foreign mapping is only supported by
add_to_physmap_range". Whereas it should have said "Foreign mapping is only possible throughadd_to_physmap_range". I'll re-add that with the adjusted comment.
Yes, thanks.
Quoted 1 line
Will that make the patch acceptable to you?
I believe so, yes, I'll look at v3 ASAP.
Ian.
PATCH 2/4 fix XENMEM_add_to_physmap preemption handling
In reply to Jan BeulichJust like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
xen/common/compat/memory.c +4 -10
@@ -190,6 +190,9 @@ int compat_memory_op(unsigned int cmd, Xbreak ;case XENMEM_add_to_physmap: +BUILD_BUG_ON ((typeof (cmp.atp.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); +if (copy_from_guest (&cmp.atp, compat,1 ) )return -EFAULT ;
@@ -322,17 +325,8 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_current_reservation:case XENMEM_maximum_reservation:case XENMEM_maximum_gpfn: -case XENMEM_remove_from_physmap: -break ; -case XENMEM_add_to_physmap: -if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp.atp, nat.atp); -if (__copy_to_guest (compat, &cmp.atp,1 ) ) - rc = -EFAULT ; - +case XENMEM_remove_from_physmap:break ;default :
xen/common/memory.c +31 -22
115 lines not on this page · raw message
fix XENMEM_add_to_physmap preemption handling
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
xen/common/compat/memory.c +4 -10
@@ -190,6 +190,9 @@ int compat_memory_op(unsigned int cmd, Xbreak ;case XENMEM_add_to_physmap: +BUILD_BUG_ON ((typeof (cmp.atp.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); +if (copy_from_guest (&cmp.atp, compat,1 ) )return -EFAULT ;
@@ -322,17 +325,8 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_current_reservation:case XENMEM_maximum_reservation:case XENMEM_maximum_gpfn: -case XENMEM_remove_from_physmap: -break ; -case XENMEM_add_to_physmap: -if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp.atp, nat.atp); -if (__copy_to_guest (compat, &cmp.atp,1 ) ) - rc = -EFAULT ; - +case XENMEM_remove_from_physmap:break ;default :
xen/common/memory.c +31 -22
115 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
Quoted 12 lines · Jan Beulich
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
Signed-off-by Jan Beulich <[email protected]>xen/common/memory.c +1
-1@@ -543,22 +543,32 @@ static long memory_exchange(XEN_GUEST_HA } static int xenmem_add_to_physmap(struct domain *d, -struct xen_add_to_physmap *xatp) + struct xen_add_to_physmap *xatp,
xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 554
Quoted 10 lines
xen/common/memory.c +5
-2+ unsigned int start) { -struct xen_add_to_physmap start_xatp; -int rc =0 ; +unsigned int done =0 ; +long rc =0 ;if ( xatp->space != XENMAPSPACE_gmfn_range ) + { +ASSERT (!start);
I don't think you've enforced this in the caller; you only check that the guest hasn't supplied an over-sized start-extent. I think it's fine just to ignore start for singleton operations anyway.
Cheers,
Tim.
Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 19 lines · Jan Beulich
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
Signed-off-by Jan Beulich <[email protected]>xen/common/memory.c +4
-3@@ -543,22 +543,32 @@ static long memory_exchange(XEN_GUEST_HA }static int xenmem_add_to_physmap (struct domain *d, -struct xen_add_to_physmap *xatp) +struct xen_add_to_physmap *xatp, +unsigned int start) { -struct xen_add_to_physmap start_xatp; -int rc =0 ; +unsigned int done =0 ; +long rc =0 ;
Quoted 7 lines
xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 554
Quoted 3 lines
xen/common/memory.c +2
-0if ( xatp->space != XENMAPSPACE_gmfn_range ) + { +ASSERT (!start);I don't think you've enforced this in the caller; you only check that the guest hasn't supplied an over-sized start-extent. I think it's fine just to ignore start for singleton operations anyway.
Right, if at all I should be returning an error here. But that should perhaps either done uniformly at once for all mem ops, or not at all.
I'll just drop that change - makes the patch smaller :-)
Jan
Tim Deegan
Reviewed-byRe: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
Quoted 29 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 19 lines · Jan Beulich
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
Signed-off-by Jan Beulich <[email protected]>xen/common/memory.c +4
-3@@ -543,22 +543,32 @@ static long memory_exchange(XEN_GUEST_HA }static int xenmem_add_to_physmap (struct domain *d, -struct xen_add_to_physmap *xatp) +struct xen_add_to_physmap *xatp, +unsigned int start) { -struct xen_add_to_physmap start_xatp; -int rc =0 ; +unsigned int done =0 ; +long rc =0 ;Quoted 7 lines
xen/common/memory.c static long memory_exchange(XEN_GUEST_HA · line 554
Quoted 3 lines
xen/common/memory.c +2
-0if ( xatp->space != XENMAPSPACE_gmfn_range ) + { +ASSERT (!start);I don't think you've enforced this in the caller; you only check that the guest hasn't supplied an over-sized start-extent. I think it's fine just to ignore start for singleton operations anyway.
Quoted 5 lines
Right, if at all I should be returning an error here. But that should perhaps either done uniformly at once for all mem ops, or not at all.
I'll just drop that change - makes the patch smaller :-)
Grand so. :) With that dropped, 1/4 and 2/4 are
Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
In reply to Jan BeulichReview
Quoted 4 lines · Jan Beulich
J
/* Check for continuation if it's not the last interation. */(quoted diff) +1
-1- if ( xatp->size > 0 && hypercall_preempt_check() ) + if ( xatp->size > ++done && hypercall_preempt_check() )
Hiding the loop increment inside the preemption checking is a bit subtle (it took me a while to find it). Can't it go either before or after this loop? With a suitable +/- 1 to the rc below if necessary.
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN · line 734
Quoted 5 lines
xen/common/memory.c +1
-0@@ -724,6 +731,12 @@ long do_memory_op(unsigned long cmd, XEN {struct xen_add_to_physmap xatp; +BUILD_BUG_ON ((typeof (xatp.size))-1 > (UINT_MAX >>MEMOP_EXTENT_SHIFT ));
What does "typeof(xatp.size)-1" evaluate to? typeof can't return an int, cant it?
Review long do_memory_op(unsigned long cmd, XEN · line 736
Quoted 2 lines
(quoted diff) +2
-0+ + /* Check for faked input. */
Faked as in "malicious" or faked as in "something we made up for continuation purposes" ?
Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Review
Quoted 4 lines · Jan Beulich
J
/* Check for continuation if it's not the last interation. */(quoted diff) +1
-1- if ( xatp->size > 0 && hypercall_preempt_check() ) + if ( xatp->size > ++done && hypercall_preempt_check() )Hiding the loop increment inside the preemption checking is a bit subtle (it took me a while to find it). Can't it go either before or after this loop? With a suitable +/- 1 to the rc below if necessary.
It could, but I find it quite natural to be together with the check.
Quoted 8 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN · line 734
Quoted 5 lines
xen/common/memory.c +1
-0@@ -724,6 +731,12 @@ long do_memory_op(unsigned long cmd, XEN {struct xen_add_to_physmap xatp; +BUILD_BUG_ON ((typeof (xatp.size))-1 > (UINT_MAX >>MEMOP_EXTENT_SHIFT ));What does "typeof(xatp.size)-1" evaluate to? typeof can't return an int, cant it?
Properly parenthesized this is ((uint16_t)-1), i.e. 0xffff (typeof() doesn't produce a value, but a type).
Quoted 5 lines
Review long do_memory_op(unsigned long cmd, XEN · line 736
Quoted 2 lines
(quoted diff) +2
-0+ + /* Check for faked input. */Faked as in "malicious" or faked as in "something we made up for continuation purposes" ?
As in "malicious" (or buggy), i.e. the caller passing an out of range "cmd" to HYPERVISOR_memory_op. Do you have any better wording in mind?
Jan
Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 4 lines · Jan Beulich
J
/* Check for continuation if it's not the last interation. */(quoted diff) +1
-1- if ( xatp->size > 0 && hypercall_preempt_check() ) + if ( xatp->size > ++done && hypercall_preempt_check() )
Quoted 5 lines
Quoted 3 lines
Hiding the loop increment inside the preemption checking is a bit subtle (it took me a while to find it). Can't it go either before or after this loop? With a suitable +/- 1 to the rc below if necessary.
It could, but I find it quite natural to be together with the check.
If it were the loop termination check or something then I would agree, but this is effectively some other arbitrary check within the loop (even if it does happen to exit, it's not the primary loop termination condition).
Quoted 10 lines
Quoted 8 lines
xen/common/memory.c long do_memory_op(unsigned long cmd, XEN · line 734
Quoted 5 lines
xen/common/memory.c +1
-0@@ -724,6 +731,12 @@ long do_memory_op(unsigned long cmd, XEN {struct xen_add_to_physmap xatp; +BUILD_BUG_ON ((typeof (xatp.size))-1 > (UINT_MAX >>MEMOP_EXTENT_SHIFT ));What does "typeof(xatp.size)-1" evaluate to? typeof can't return an int, cant it?
Properly parenthesized this is ((uint16_t)-1), i.e.
0xffff
Ah! Yes, I misread that rather badly.
Quoted 1 line
(
typeof()doesn't produce a value, but a type).
I know, that's why I was so confused when it looked like it was being treated as a value!
Quoted 9 lines
Quoted 5 lines
Review long do_memory_op(unsigned long cmd, XEN · line 736
Quoted 2 lines
(quoted diff) +2
-0+ + /* Check for faked input. */Faked as in "malicious" or faked as in "something we made up for continuation purposes" ?
As in "malicious" (or buggy), i.e. the caller passing an out of range "cmd" to
HYPERVISOR_memory_op. Do you have any better wording in mind?
"Check for malicious or buggy input" would do the job. (with or without "or buggy")
Ian.
Re: [PATCH 2/4] fix XENMEM_add_to_physmap preemption handling
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Review
Quoted 2 lines · Jan Beulich
(quoted diff) +2
-0+ + /* Check for faked input. */Faked as in "malicious" or faked as in "something we made up for continuation purposes" ?
Quoted 6 lines
Quoted 3 lines
As in "malicious" (or buggy), i.e. the caller passing an out of range "cmd" to
HYPERVISOR_memory_op. Do you have any better wording in mind?"Check for malicious or buggy input" would do the job. (with or without "or buggy")
Fine with me - changed that way.
Jan
PATCH 3/4 move XENMEM_add_to_physmap_range handling framework to common code
In reply to Jan BeulichThere's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
Note the restriction of XENMAPSPACE_gmfn_range only being supported through XENMEM_add_to_physmap is being dropped as being pointless.
This further eliminates the erroneous bailing from xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
xen/arch/arm/mm.c +0 -93
@@ -1056,103 +1056,10 @@ int xenmem_add_to_physmap_one(return rc; } -static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) -{ -int rc; - -while ( xatpr->size >0 ) - { -xen_ulong_t idx; -xen_pfn_t gpfn; - -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - - rc =xenmem_add_to_physmap_one (d, xatpr->space, - xatpr->foreign_domid, - idx, gpfn); - -if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if ( rc <0 ) - goto out; - -guest_handle_add_offset (xatpr->idxs,1 ); -guest_handle_add_offset (xatpr->gpfns,1 ); -guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--; - -/* Check for continuation if it's not the last interation */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) - { - rc = -EAGAIN ; - goto out; - } - } - - rc =0 ; - -out: -return rc; - -} -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) { -int rc; -switch ( op ) { -case XENMEM_add_to_physmap_range: - { -struct xen_add_to_physmap_range xatpr; -struct domain *d; - -if (copy_from_guest (&xatpr, arg,1 ) ) -return -EFAULT ; - -/* This mapspace is redundant for this hypercall */ -if ( xatpr.space == XENMAPSPACE_gmfn_range ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatpr.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_range (d, &xatpr); - -rcu_unlock_domain (d); - -if ( rc &©_to_guest (arg, &xatpr,1 ) ) - rc = -EFAULT ; - -if ( rc == -EAGAIN ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); - -return rc; - }/* XXX: memsharing not working yet */ case XENMEM_get_sharing_shared_pages:case XENMEM_get_sharing_freed_pages:
xen/common/memory.c +89 -0
101 lines not on this page · raw message
move XENMEM_add_to_physmap_range handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
Note the restriction of XENMAPSPACE_gmfn_range only being supported through XENMEM_add_to_physmap is being dropped as being pointless.
This further eliminates the erroneous bailing from xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
xen/arch/arm/mm.c +0 -93
103 lines not on this page · raw message
xen/common/memory.c +89 -0
101 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 6 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note the restriction of
XENMAPSPACE_gmfn_rangeonly being supported throughXENMEM_add_to_physmapis being dropped as being pointless.
Hmmm. With that restriction removed, this:
Quoted 11 lines
xen/common/memory.c +11
-0+ rc =xenmem_add_to_physmap_one (d, xatpr->space, + xatpr->foreign_domid, + idx, gpfn); + +if (unlikely (__copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) + { + rc = -EFAULT ; + goto out; + } + +guest_handle_add_offset (xatpr->idxs,1 );
xen/common/memory.c static int xenmem_add_to_physmap(struct · line 643
Quoted 10 lines
xen/common/memory.c +10
-0+guest_handle_add_offset (xatpr->gpfns,1 ); +guest_handle_add_offset (xatpr->errs,1 ); + xatpr->size--; + +/* Check for continuation if it's not the last interation. */ +if ( xatpr->size >0 &&hypercall_preempt_check () ) + { + rc = -EAGAIN ; + goto out; + }
will save the partial result of a preempted XENMAPSPACE_gmfn_range sub-op into the errors array, and then the whole operation may or may not return -EAGAIN.
I guess the caller now has enough information to figure out what happened and restart, but given that the rest of this interface nicely hides preemption from the caller, it's a bit of an ugly corner case.
Tim.
Re: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 6 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note the restriction of
XENMAPSPACE_gmfn_rangeonly being supported throughXENMEM_add_to_physmapis being dropped as being pointless.Hmmm. With that restriction removed, this:
Quoted 11 lines
xen/common/memory.c +11
-0+ rc =xenmem_add_to_physmap_one (d, xatpr->space, + xatpr->foreign_domid, + idx, gpfn); + +if (unlikely (__copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) + { + rc = -EFAULT ; + goto out; + } + +guest_handle_add_offset (xatpr->idxs,1 );xen/common/memory.c static int xenmem_add_to_physmap(struct · line 643
Quoted 10 lines
xen/common/memory.c +10
-0+guest_handle_add_offset (xatpr->gpfns,1 ); +guest_handle_add_offset (xatpr->errs,1 ); + xatpr->size--; + +/* Check for continuation if it's not the last interation. */ +if ( xatpr->size >0 &&hypercall_preempt_check () ) + { + rc = -EAGAIN ; + goto out; + }will save the partial result of a preempted
XENMAPSPACE_gmfn_rangesub-op into the errors array, and then the whole operation may or may not return-EAGAIN.
Quoted 3 lines
I guess the caller now has enough information to figure out what happened and restart, but given that the rest of this interface nicely hides preemption from the caller, it's a bit of an ugly corner case.
I'm afraid I don't follow: XENMAPSPACE_gmfn_range and XENMAPSPACE_gmfn will be treated equally now - there simply is no range being specified for the individual add_to_physmap_range elements. After all, xenmem_add_to_physmap_one() - as its name says - really only processes a single page.
Jan
Tim Deegan
Reviewed-byRe: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 6 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note the restriction of
XENMAPSPACE_gmfn_rangeonly being supported throughXENMEM_add_to_physmapis being dropped as being pointless.Hmmm. With that restriction removed, this:
Quoted 11 lines
xen/common/memory.c +11
-0+ rc =xenmem_add_to_physmap_one (d, xatpr->space, + xatpr->foreign_domid, + idx, gpfn); + +if (unlikely (__copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) + { + rc = -EFAULT ; + goto out; + } + +guest_handle_add_offset (xatpr->idxs,1 );xen/common/memory.c static int xenmem_add_to_physmap(struct · line 643
Quoted 10 lines
xen/common/memory.c +10
-0+guest_handle_add_offset (xatpr->gpfns,1 ); +guest_handle_add_offset (xatpr->errs,1 ); + xatpr->size--; + +/* Check for continuation if it's not the last interation. */ +if ( xatpr->size >0 &&hypercall_preempt_check () ) + { + rc = -EAGAIN ; + goto out; + }will save the partial result of a preempted
XENMAPSPACE_gmfn_rangesub-op into the errors array, and then the whole operation may or may not return-EAGAIN.
Quoted 8 lines
Quoted 3 lines
I guess the caller now has enough information to figure out what happened and restart, but given that the rest of this interface nicely hides preemption from the caller, it's a bit of an ugly corner case.
I'm afraid I don't follow:
XENMAPSPACE_gmfn_rangeandXENMAPSPACE_gmfnwill be treated equally now - there simply is no range being specified for the individualadd_to_physmap_rangeelements.
Oh of course. Then it's just a slightly odd API, but I guess no odder this way than before, and with slightly less code. :) So
Cheers,
Tim.
Re: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Note the restriction of
XENMAPSPACE_gmfn_rangeonly being supported throughXENMEM_add_to_physmapis being dropped as being pointless.
Note that this will still not work on ARM where add_to_physmap_one() does not support the gmfn_range and will still return ENOSYS.
If you are dropping this restriction then xen/include/public/memory.h will need updating (likewise the first patch).
Personally I think that having two redundant ways of doing the same thing is the more pointless of the two. Especially given the need to think a bit carefully about what XENMEM_add_to_physmap_range XENMAPSPACE_gmfn_range might mean...
Quoted 222 lines
This further eliminates the erroneous bailing from
xenmem_add_to_physmap_range()ifxenmem_add_to_physmap_one()fails.Signed-off-by Jan Beulich <[email protected]>xen/arch/arm/mm.c +0
-93@@ -1056,103 +1056,10 @@ int xenmem_add_to_physmap_one(return rc; } -static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) -{ -int rc; - -while ( xatpr->size >0 ) - { -xen_ulong_t idx; -xen_pfn_t gpfn; - -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - - rc =xenmem_add_to_physmap_one (d, xatpr->space, - xatpr->foreign_domid, - idx, gpfn); - -if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if ( rc <0 ) - goto out; - -guest_handle_add_offset (xatpr->idxs,1 ); -guest_handle_add_offset (xatpr->gpfns,1 ); -guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--; - -/* Check for continuation if it's not the last interation */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) - { - rc = -EAGAIN ; - goto out; - } - } - - rc =0 ; - -out: -return rc; - -} -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) { -int rc; -switch ( op ) { -case XENMEM_add_to_physmap_range: - { -struct xen_add_to_physmap_range xatpr; -struct domain *d; - -if (copy_from_guest (&xatpr, arg,1 ) ) -return -EFAULT ; - -/* This mapspace is redundant for this hypercall */ -if ( xatpr.space == XENMAPSPACE_gmfn_range ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatpr.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_range (d, &xatpr); - -rcu_unlock_domain (d); - -if ( rc &©_to_guest (arg, &xatpr,1 ) ) - rc = -EFAULT ; - -if ( rc == -EAGAIN ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); - -return rc; - }/* XXX: memsharing not working yet */ case XENMEM_get_sharing_shared_pages:case XENMEM_get_sharing_freed_pages:xen/common/memory.c +89
-0@@ -598,6 +598,57 @@ static int xenmem_add_to_physmap(structreturn rc; } +static int xenmem_add_to_physmap_range (struct domain *d, +struct xen_add_to_physmap_range *xatpr) +{ +int rc; + +while ( xatpr->size >0 ) + { +xen_ulong_t idx; +xen_pfn_t gpfn; + +if (unlikely (__copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) + { + rc = -EFAULT ; + goto out; + } + +if (unlikely (__copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) + { + rc = -EFAULT ; + goto out; + } + + rc =xenmem_add_to_physmap_one (d, xatpr->space, + xatpr->foreign_domid, + idx, gpfn); + +if (unlikely (__copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) + { + rc = -EFAULT ; + goto out; + } + +guest_handle_add_offset (xatpr->idxs,1 ); +guest_handle_add_offset (xatpr->gpfns,1 ); +guest_handle_add_offset (xatpr->errs,1 ); + xatpr->size--; + +/* Check for continuation if it's not the last interation. */ +if ( xatpr->size >0 &&hypercall_preempt_check () ) + { + rc = -EAGAIN ; + goto out; + } + } + + rc =0 ; + +out: +return rc; +} +long do_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d;@@ -763,6 +814,44 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } +case XENMEM_add_to_physmap_range: + { +struct xen_add_to_physmap_range xatpr; +struct domain *d; + +if (copy_from_guest (&xatpr, arg,1 ) || + !guest_handle_okay (xatpr.idxs, xatpr.size) || + !guest_handle_okay (xatpr.gpfns, xatpr.size) || + !guest_handle_okay (xatpr.errs, xatpr.size) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (xatpr.domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); +if ( rc ) + { +rcu_unlock_domain (d); +return rc; + } + + rc =xenmem_add_to_physmap_range (d, &xatpr); + +rcu_unlock_domain (d); + +if ( rc == -EAGAIN ) + { +if ( !__copy_to_guest (arg, &xatpr,1 ) ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"ih" , op, arg); +else + rc = -EFAULT ; + } + +return rc; + } +case XENMEM_remove_from_physmap: {struct xen_remove_from_physmap xrfp;_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 4 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().
Quoted 8 lines
Quoted 2 lines
Note the restriction of
XENMAPSPACE_gmfn_rangeonly being supported throughXENMEM_add_to_physmapis being dropped as being pointless.Note that this will still not work on ARM where
add_to_physmap_one()does not support thegmfn_rangeand will still return ENOSYS.If you are dropping this restriction then
xen/include/public/memory.hwill need updating (likewise the first patch).
I don't think so - we can very well say certain combination are unsupported even if they happen to work. That leaves us with the option of dropping back to the earlier state should there be a need.
Quoted 4 lines
Personally I think that having two redundant ways of doing the same thing is the more pointless of the two. Especially given the need to think a bit carefully about what
XENMEM_add_to_physmap_rangeXENMAPSPACE_gmfn_rangemight mean...
Yes, that combination is bogus whichever perspective you take. To some degree also because "range" in the former name is really wrong - the operation doesn't deal with a range, but with a group (batch) of individual pages.
However, I meanwhile realized that from an interface perspective (I'm not proposing to implement this right now!) the combination could actually be made work - the errs array (being an output only at present) could be re-used to serve as input to pass the sizes. The main issue of implementing this would be how to deal with the two necessary layers of preemption.
So I'm going to re-add the check.
Jan
Re: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Personally I think that having two redundant ways of doing the same thing is the more pointless of the two. Especially given the need to think a bit carefully about what
XENMEM_add_to_physmap_rangeXENMAPSPACE_gmfn_rangemight mean...Yes, that combination is bogus whichever perspective you take. To some degree also because "range" in the former name is really wrong - the operation doesn't deal with a range, but with a group (batch) of individual pages.
That's true. I suppose there would be no harm in #define XENMEM_add_to_physmap_batch 23
#if __XEN_INTERFACE_VERSION__ < xxx
#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch. #endif
Quoted 6 lines
However, I meanwhile realized that from an interface perspective (I'm not proposing to implement this right now!) the combination could actually be made work - the errs array (being an output only at present) could be re-used to serve as input to pass the sizes. The main issue of implementing this would be how to deal with the two necessary layers of preemption.
That's pretty cunning!
Quoted 1 line
So I'm going to re-add the check.
Given the above I'm doubly in favour of doing so.
Ian.
Re: [PATCH 3/4] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Personally I think that having two redundant ways of doing the same thing is the more pointless of the two. Especially given the need to think a bit carefully about what
XENMEM_add_to_physmap_rangeXENMAPSPACE_gmfn_rangemight mean...Yes, that combination is bogus whichever perspective you take. To some degree also because "range" in the former name is really wrong - the operation doesn't deal with a range, but with a group (batch) of individual pages.
Quoted 5 lines
That's true. I suppose there would be no harm in #define
XENMEM_add_to_physmap_batch23
#if__XEN_INTERFACE_VERSION__< xxx
#defineXENMEM_add_to_physmap_rangeXENMEM_add_to_physmap_batch. #endif
Indeed - patch being prepared.
Jan
PATCH 4/4 fix XENMEM_add_to_physmap_range preemption handling
In reply to Jan BeulichJust like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
xen/common/memory.c +26 -14
@@ -599,11 +599,21 @@ static int xenmem_add_to_physmap(struct }static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) +struct xen_add_to_physmap_range *xatpr, +unsigned int start) { +unsigned int done =0 ;int rc; -while ( xatpr->size >0 ) +if ( xatpr->size < start ) +return -EILSEQ ; + +guest_handle_add_offset (xatpr->idxs, start); +guest_handle_add_offset (xatpr->gpfns, start); +guest_handle_add_offset (xatpr->errs, start); + xatpr->size -= start; + +while ( xatpr->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn;
@@ -633,12 +643,11 @@ static int xenmem_add_to_physmap_range(sguest_handle_add_offset (xatpr->idxs,1 );guest_handle_add_offset (xatpr->gpfns,1 );guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--;/* Check for continuation if it's not the last interation. */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) +if ( xatpr->size > ++done &&hypercall_preempt_check () ) { - rc = -EAGAIN ; + rc = start + done; goto out; } }
@@ -819,6 +828,13 @@ long do_memory_op(unsigned long cmd, XENstruct xen_add_to_physmap_range xatpr;struct domain *d; +BUILD_BUG_ON ((typeof (xatpr.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); + +/* Check for faked input. */ + if ( start_extent != (typeof(xatpr.size))start_extent ) +return -EDOM ; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
@@ -836,18 +852,14 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr); + rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent);rcu_unlock_domain (d); -if ( rc == -EAGAIN ) - { -if ( !__copy_to_guest (arg, &xatpr,1 ) ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); -else - rc = -EFAULT ; - } +if ( rc >0 ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"lh" , + op | (rc <<MEMOP_EXTENT_SHIFT ), arg);return rc; }
fix XENMEM_add_to_physmap_range preemption handling
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
xen/common/memory.c +26 -14
@@ -599,11 +599,21 @@ static int xenmem_add_to_physmap(struct }static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) +struct xen_add_to_physmap_range *xatpr, +unsigned int start) { +unsigned int done =0 ;int rc; -while ( xatpr->size >0 ) +if ( xatpr->size < start ) +return -EILSEQ ; + +guest_handle_add_offset (xatpr->idxs, start); +guest_handle_add_offset (xatpr->gpfns, start); +guest_handle_add_offset (xatpr->errs, start); + xatpr->size -= start; + +while ( xatpr->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn;
@@ -633,12 +643,11 @@ static int xenmem_add_to_physmap_range(sguest_handle_add_offset (xatpr->idxs,1 );guest_handle_add_offset (xatpr->gpfns,1 );guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--;/* Check for continuation if it's not the last interation. */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) +if ( xatpr->size > ++done &&hypercall_preempt_check () ) { - rc = -EAGAIN ; + rc = start + done; goto out; } }
@@ -819,6 +828,13 @@ long do_memory_op(unsigned long cmd, XENstruct xen_add_to_physmap_range xatpr;struct domain *d; +BUILD_BUG_ON ((typeof (xatpr.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); + +/* Check for faked input. */ + if ( start_extent != (typeof(xatpr.size))start_extent ) +return -EDOM ; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
@@ -836,18 +852,14 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr); + rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent);rcu_unlock_domain (d); -if ( rc == -EAGAIN ) - { -if ( !__copy_to_guest (arg, &xatpr,1 ) ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); -else - rc = -EFAULT ; - } +if ( rc >0 ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"lh" , + op | (rc <<MEMOP_EXTENT_SHIFT ), arg);return rc; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 7 lines · Jan Beulich
The hypervisor isn't supposed to use the input structures for storing continuation information - only fields explicitly used as hypercall outputs should ever be updated.
Obviously this implies an ABI change, but since the previous behavior was not intended to be that way I don't think we should stick to the old behavior.
FWIW I don't think adding const to a function parameter (which is kinda-sorta what we are doing here) constitutes a change to the ABI as such (or not a meaningful one), since a non-const can always be const'ed on call.
Quoted 7 lines
There's one caveat though - with the previous model, the caller could - upon failure - use the updated structure to find out how by progress was made. However, that wasn't intended afaict, largely supported by this information depending on hypervisor internals (i.e. the caller would have to know the order of request processing and the meaning of the respective size fields, which aren't simply saying "this much was processed").
IIRC the long standing user of the original physmap range functionality was hvmloader (something to do with batching IOMMU TLB flushes?). If hvmloader isn't introspecting hypervisor internals in this way I doubt anyone else is.
I suppose this series is proposed for 4.5 rather than 4.4 since you didn't say otherwise?
Quoted 11 lines
Consequently, as a follow-up we may want to consider making explicit (and straight forward) this progress indication on error.
1: move
XENMEM_add_to_physmaphandling framework to common code 2: fixXENMEM_add_to_physmappreemption handling
3: moveXENMEM_add_to_physmap_rangehandling framework to common code 4: fixXENMEM_add_to_physmap_rangepreemption handlingSigned-off-by Jan Beulich <[email protected]>
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
I suppose this series is proposed for 4.5 rather than 4.4 since you didn't say otherwise?
Actually I'd be wanting this in 4.4 (and applicable parts even backported) since it's a bug fix (and as such I didn't think I'd need to say this explicitly).
Jan
Quoted 19 lines · Jan Beulich
The hypervisor isn't supposed to use the input structures for storing continuation information - only fields explicitly used as hypercall outputs should ever be updated.
Obviously this implies an ABI change, but since the previous behavior was not intended to be that way I don't think we should stick to the old behavior.
There's one caveat though - with the previous model, the caller could - upon failure - use the updated structure to find out how by progress was made. However, that wasn't intended afaict, largely supported by this information depending on hypervisor internals (i.e. the caller would have to know the order of request processing and the meaning of the respective size fields, which aren't simply saying "this much was processed").
Consequently, as a follow-up we may want to consider making explicit (and straight forward) this progress indication on error.
Quoted 6 lines
1: move
XENMEM_add_to_physmaphandling framework to common code 2: fixXENMEM_add_to_physmappreemption handling
3: moveXENMEM_add_to_physmap_rangehandling framework to common code 4: fixXENMEM_add_to_physmap_rangepreemption handlingSigned-off-by Jan Beulich <[email protected]>
Nice to have this fixed!
v2 cover fix preemption handling for XENMEM_add_to_physmap_range{, _range}
In reply to Jan BeulichQuoted 1 line
Quoted 1 line
Quoted 1 line · Jan Beulich
The hypervisor isn't supposed to use the input structures for storing continuation information - only fields explicitly used as hypercall outputs should ever be updated.
Obviously this implies an ABI change, but since the previous behavior was not intended to be that way I don't think we should stick to the old behavior.
There's one caveat though - with the previous model, the caller could - upon failure - use the updated structure to find out how by progress was made. However, that wasn't intended afaict, largely supported by this information depending on hypervisor internals (i.e. the caller would have to know the order of request processing and the meaning of the respective size fields, which aren't simply saying "this much was processed").
Consequently, as a follow-up we may want to consider making explicit (and straight forward) this progress indication on error.
1: move XENMEM_add_to_physmap handling framework to common code 2: fix XENMEM_add_to_physmap preemption handling
3: move XENMEM_add_to_physmap_range handling framework to common code 4: fix XENMEM_add_to_physmap_range preemption handling
---
v2: Apart from the removal of a bogus ASSERT() as requested
by Tim, only a couple minor/cosmetic changes (see individual patches), hence I'm retaining the tags that were already given for v1.
PATCH v2 1/4 move XENMEM_add_to_physmap handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
Note that ARM's restriction of XENMAPSPACE_gmfn_foreign only being supported through XENMEM_add_to_physmap_range is being dropped as being pointless.
xen/arch/arm/mm.c +1 -32
@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,
@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;
xen/arch/x86/mm.c +24 -103
193 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +0 -28
@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;
xen/common/compat/memory.c +20 -0
@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );
@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ; + +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;
xen/common/memory.c +81 -0
93 lines not on this page · raw message
xen/include/xen/mm.h +4 -0
@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
move XENMEM_add_to_physmap handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
Note that ARM's restriction of XENMAPSPACE_gmfn_foreign only being supported through XENMEM_add_to_physmap_range is being dropped as being pointless.
xen/arch/arm/mm.c +1 -32
@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,
@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;
xen/arch/x86/mm.c +24 -103
193 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +0 -28
@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;
xen/common/compat/memory.c +20 -0
@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );
@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ; + +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;
xen/common/memory.c +81 -0
93 lines not on this page · raw message
xen/include/xen/mm.h +4 -0
@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 2/4 fix XENMEM_add_to_physmap preemption handling
In reply to Jan BeulichJust like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
---
v2: drop bogus ASSERT()
xen/common/compat/memory.c +4 -10
@@ -190,6 +190,9 @@ int compat_memory_op(unsigned int cmd, Xbreak ;case XENMEM_add_to_physmap: +BUILD_BUG_ON ((typeof (cmp.atp.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); +if (copy_from_guest (&cmp.atp, compat,1 ) )return -EFAULT ;
@@ -322,17 +325,8 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_current_reservation:case XENMEM_maximum_reservation:case XENMEM_maximum_gpfn: -case XENMEM_remove_from_physmap: -break ; -case XENMEM_add_to_physmap: -if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp.atp, nat.atp); -if (__copy_to_guest (compat, &cmp.atp,1 ) ) - rc = -EFAULT ; - +case XENMEM_remove_from_physmap:break ;default :
xen/common/memory.c +28 -22
112 lines not on this page · raw message
fix XENMEM_add_to_physmap preemption handling
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
---
v2: drop bogus ASSERT()
xen/common/compat/memory.c +4 -10
@@ -190,6 +190,9 @@ int compat_memory_op(unsigned int cmd, Xbreak ;case XENMEM_add_to_physmap: +BUILD_BUG_ON ((typeof (cmp.atp.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); +if (copy_from_guest (&cmp.atp, compat,1 ) )return -EFAULT ;
@@ -322,17 +325,8 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_current_reservation:case XENMEM_maximum_reservation:case XENMEM_maximum_gpfn: -case XENMEM_remove_from_physmap: -break ; -case XENMEM_add_to_physmap: -if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp.atp, nat.atp); -if (__copy_to_guest (compat, &cmp.atp,1 ) ) - rc = -EFAULT ; - +case XENMEM_remove_from_physmap:break ;default :
xen/common/memory.c +28 -22
112 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 3/4 move XENMEM_add_to_physmap_range handling framework to common code
In reply to Jan BeulichThere's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
This further eliminates the erroneous bailing from xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
---
v2: Restore restriction of XENMAPSPACE_gmfn_range only being supported
through XENMEM_add_to_physmap.
xen/arch/arm/mm.c +0 -93
@@ -1057,103 +1057,10 @@ int xenmem_add_to_physmap_one(return rc; } -static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) -{ -int rc; - -while ( xatpr->size >0 ) - { -xen_ulong_t idx; -xen_pfn_t gpfn; - -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - - rc =xenmem_add_to_physmap_one (d, xatpr->space, - xatpr->foreign_domid, - idx, gpfn); - -if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if ( rc <0 ) - goto out; - -guest_handle_add_offset (xatpr->idxs,1 ); -guest_handle_add_offset (xatpr->gpfns,1 ); -guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--; - -/* Check for continuation if it's not the last interation */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) - { - rc = -EAGAIN ; - goto out; - } - } - - rc =0 ; - -out: -return rc; - -} -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) { -int rc; -switch ( op ) { -case XENMEM_add_to_physmap_range: - { -struct xen_add_to_physmap_range xatpr; -struct domain *d; - -if (copy_from_guest (&xatpr, arg,1 ) ) -return -EFAULT ; - -/* This mapspace is redundant for this hypercall */ -if ( xatpr.space == XENMAPSPACE_gmfn_range ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatpr.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_range (d, &xatpr); - -rcu_unlock_domain (d); - -if ( rc &©_to_guest (arg, &xatpr,1 ) ) - rc = -EFAULT ; - -if ( rc == -EAGAIN ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); - -return rc; - }/* XXX: memsharing not working yet */ case XENMEM_get_sharing_shared_pages:case XENMEM_get_sharing_freed_pages:
xen/common/memory.c +93 -0
105 lines not on this page · raw message
move XENMEM_add_to_physmap_range handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
This further eliminates the erroneous bailing from xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
---
v2: Restore restriction of XENMAPSPACE_gmfn_range only being supported
through XENMEM_add_to_physmap.
xen/arch/arm/mm.c +0 -93
103 lines not on this page · raw message
xen/common/memory.c +93 -0
105 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 4/4 fix XENMEM_add_to_physmap_range preemption handling
In reply to Jan BeulichJust like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
xen/common/memory.c +26 -14
@@ -596,11 +596,21 @@ static int xenmem_add_to_physmap(struct }static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) +struct xen_add_to_physmap_range *xatpr, +unsigned int start) { +unsigned int done =0 ;int rc; -while ( xatpr->size >0 ) +if ( xatpr->size < start ) +return -EILSEQ ; + +guest_handle_add_offset (xatpr->idxs, start); +guest_handle_add_offset (xatpr->gpfns, start); +guest_handle_add_offset (xatpr->errs, start); + xatpr->size -= start; + +while ( xatpr->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn;
@@ -630,12 +640,11 @@ static int xenmem_add_to_physmap_range(sguest_handle_add_offset (xatpr->idxs,1 );guest_handle_add_offset (xatpr->gpfns,1 );guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--;/* Check for continuation if it's not the last iteration. */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) +if ( xatpr->size > ++done &&hypercall_preempt_check () ) { - rc = -EAGAIN ; + rc = start + done; goto out; } }
@@ -816,6 +825,13 @@ long do_memory_op(unsigned long cmd, XENstruct xen_add_to_physmap_range xatpr;struct domain *d; +BUILD_BUG_ON ((typeof (xatpr.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); + +/* Check for faked input. */ + if ( start_extent != (typeof(xatpr.size))start_extent ) +return -EDOM ; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
@@ -837,18 +853,14 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr); + rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent);rcu_unlock_domain (d); -if ( rc == -EAGAIN ) - { -if ( !__copy_to_guest (arg, &xatpr,1 ) ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); -else - rc = -EFAULT ; - } +if ( rc >0 ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"lh" , + op | (rc <<MEMOP_EXTENT_SHIFT ), arg);return rc; }
fix XENMEM_add_to_physmap_range preemption handling
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
xen/common/memory.c +26 -14
@@ -596,11 +596,21 @@ static int xenmem_add_to_physmap(struct }static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) +struct xen_add_to_physmap_range *xatpr, +unsigned int start) { +unsigned int done =0 ;int rc; -while ( xatpr->size >0 ) +if ( xatpr->size < start ) +return -EILSEQ ; + +guest_handle_add_offset (xatpr->idxs, start); +guest_handle_add_offset (xatpr->gpfns, start); +guest_handle_add_offset (xatpr->errs, start); + xatpr->size -= start; + +while ( xatpr->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn;
@@ -630,12 +640,11 @@ static int xenmem_add_to_physmap_range(sguest_handle_add_offset (xatpr->idxs,1 );guest_handle_add_offset (xatpr->gpfns,1 );guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--;/* Check for continuation if it's not the last iteration. */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) +if ( xatpr->size > ++done &&hypercall_preempt_check () ) { - rc = -EAGAIN ; + rc = start + done; goto out; } }
@@ -816,6 +825,13 @@ long do_memory_op(unsigned long cmd, XENstruct xen_add_to_physmap_range xatpr;struct domain *d; +BUILD_BUG_ON ((typeof (xatpr.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); + +/* Check for faked input. */ + if ( start_extent != (typeof(xatpr.size))start_extent ) +return -EDOM ; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
@@ -837,18 +853,14 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr); + rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent);rcu_unlock_domain (d); -if ( rc == -EAGAIN ) - { -if ( !__copy_to_guest (arg, &xatpr,1 ) ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); -else - rc = -EFAULT ; - } +if ( rc >0 ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"lh" , + op | (rc <<MEMOP_EXTENT_SHIFT ), arg);return rc; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
v3 cover fix preemption handling for XENMEM_add_to_physmap_range{, _range}
In reply to Jan BeulichThe hypervisor isn't supposed to use the input structures for storing continuation information - only fields explicitly used as hypercall outputs should ever be updated.
Obviously this implies an ABI change, but since the previous behavior was not intended to be that way I don't think we should stick to the old behavior.
There's one caveat though - with the previous model, the caller could - upon failure - use the updated structure to find out how by progress was made. However, that wasn't intended afaict, largely supported by this information depending on hypervisor internals (i.e. the caller would have to know the order of request processing and the meaning of the respective size fields, which aren't simply saying "this much was processed").
Consequently, as a follow-up we may want to consider making explicit (and straight forward) this progress indication on error.
1: move XENMEM_add_to_physmap handling framework to common code 2: fix XENMEM_add_to_physmap preemption handling
3: move XENMEM_add_to_physmap_range handling framework to common code 4: fix XENMEM_add_to_physmap_range preemption handling
5: rename XENMEM_add_to_physmap_{range => batch}
---
v3: Retain restriction of XENMAPSPACE_gmfn_foreign not being
possible via XENMEM_add_to_physmap (patch 1). Apart from patch 5 being new, other patches unchanged .
v2: Apart from the removal of a bogus ASSERT() as requested
by Tim, only a couple minor/cosmetic changes (see individual patches), hence I'm retaining the tags that were already given for v1.
PATCH v3 1/5 move XENMEM_add_to_physmap handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
---
v3: Restriction of XENMAPSPACE_gmfn_foreign only being possible via
XENMEM_add_to_physmap_range no longer being dropped.
xen/arch/arm/mm.c +1 -32
@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,
@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;
xen/arch/x86/mm.c +24 -103
193 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +0 -28
@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;
xen/common/compat/memory.c +20 -0
@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );
@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ; + +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;
xen/common/memory.c +85 -0
97 lines not on this page · raw message
xen/include/xen/mm.h +4 -0
@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
move XENMEM_add_to_physmap handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
---
v3: Restriction of XENMAPSPACE_gmfn_foreign only being possible via
XENMEM_add_to_physmap_range no longer being dropped.
xen/arch/arm/mm.c +1 -32
@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,
@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;
xen/arch/x86/mm.c +24 -103
193 lines not on this page · raw message
xen/arch/x86/x86_64/compat/mm.c +0 -28
@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;
xen/common/compat/memory.c +20 -0
@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );
@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ; + +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;
xen/common/memory.c +85 -0
97 lines not on this page · raw message
xen/include/xen/mm.h +4 -0
@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 1/5] move XENMEM_add_to_physmap handling framework to common code
Quoted 7 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Signed-off-by Jan Beulich <[email protected]>Reviewed-by Tim Deegan <[email protected]>Acked-by Keir Fraser <[email protected]>
(nb: I didn't look at the x86 bits at all...)
Quoted 3 lines
---
v3: Restriction ofXENMAPSPACE_gmfn_foreignonly being possible via
XENMEM_add_to_physmap_rangeno longer being dropped.
Thanks.
Ian.
Re: [PATCH v3 1/5] move XENMEM_add_to_physmap handling framework to common code
In reply to Jan BeulichQuoted 329 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().Signed-off-by Jan Beulich <[email protected]>Reviewed-by Tim Deegan <[email protected]>Acked-by Keir Fraser <[email protected]>---
v3: Restriction ofXENMAPSPACE_gmfn_foreignonly being possible via
XENMEM_add_to_physmap_rangeno longer being dropped.xen/arch/arm/mm.c +1
-32@@ -968,7 +968,7 @@ void share_xen_page_with_privileged_guesshare_xen_page_with_guest (page, dom_xen, readonly); } -static int xenmem_add_to_physmap_one( +int xenmem_add_to_physmap_one( struct domain *d, uint16_t space, domid_t foreign_domid,@@ -1118,37 +1118,6 @@ long arch_memory_op(int op, XEN_GUEST_HAswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - -/* Foreign mapping is only supported by add_to_physmap_range */ -if ( xatp.space == XENMAPSPACE_gmfn_foreign ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_one (d, xatp.space,DOMID_INVALID , - xatp.idx, xatp.gpfn); - -rcu_unlock_domain (d); - -return rc; - } -case XENMEM_add_to_physmap_range: {struct xen_add_to_physmap_range xatpr;xen/arch/x86/mm.c +24
-103@@ -4520,20 +4520,23 @@ static int handle_iomem_range(unsigned lreturn 0 ; } -static int xenmem_add_to_physmap_once ( +int xenmem_add_to_physmap_one (struct domain *d, -const struct xen_add_to_physmap *xatp) +uint16_t space, +domid_t foreign_domid, +unsigned long idx, +xen_pfn_t gpfn) {struct page_info *page =NULL ;unsigned long gfn =0 ;/* gcc ... */ -unsigned long prev_mfn, mfn =0 , gpfn, idx; +unsigned long prev_mfn, mfn =0 , old_gpfn;int rc;p2m_type_t p2mt; -switch ( xatp->space ) +switch ( space ) {case XENMAPSPACE_shared_info: -if ( xatp->idx ==0 ) +if ( idx ==0 ) mfn =virt_to_mfn (d->shared_info);break ;case XENMAPSPACE_grant_table:@@ -4542,9 +4545,8 @@ static int xenmem_add_to_physmap_once(if ( d->grant_table->gt_version ==0 ) d->grant_table->gt_version =1 ; - idx = xatp->idx;if ( d->grant_table->gt_version ==2 && - (xatp->idx & XENMAPIDX_grant_table_status) ) + (idx & XENMAPIDX_grant_table_status) ) { idx &= ~XENMAPIDX_grant_table_status;if ( idx <nr_status_frames (d->grant_table) )@@ -4566,9 +4568,9 @@ static int xenmem_add_to_physmap_once(case XENMAPSPACE_gmfn: {p2m_type_t p2mt; - gfn = xatp->idx; - idx =mfn_x (get_gfn_unshare (d, xatp->idx, &p2mt)); + gfn = idx; + idx =mfn_x (get_gfn_unshare (d, idx, &p2mt));/* If the page is still shared, exit early */ if (p2m_is_shared (p2mt) ) {@@ -4589,41 +4591,38 @@ static int xenmem_add_to_physmap_once( {if ( page )put_page (page); -if ( xatp->space == XENMAPSPACE_gmfn || - xatp->space == XENMAPSPACE_gmfn_range ) +if ( space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range )put_gfn (d, gfn);return -EINVAL ; }/* Remove previously mapped page if it was present. */ - prev_mfn =mfn_x (get_gfn (d, xatp->gpfn, &p2mt)); + prev_mfn =mfn_x (get_gfn (d, gpfn, &p2mt));if (mfn_valid (prev_mfn) ) {if (is_xen_heap_mfn (prev_mfn) )/* Xen heap frames are simply unhooked from this phys slot. */ -guest_physmap_remove_page (d, xatp->gpfn, prev_mfn,PAGE_ORDER_4K ); +guest_physmap_remove_page (d, gpfn, prev_mfn,PAGE_ORDER_4K );else /* Normal domain memory is freed, to avoid leaking memory. */ -guest_remove_page (d, xatp->gpfn); +guest_remove_page (d, gpfn); }/* In the XENMAPSPACE_gmfn case we still hold a ref on the old page. */ -put_gfn (d, xatp->gpfn); +put_gfn (d, gpfn);/* Unmap from old location, if any. */ - gpfn =get_gpfn_from_mfn (mfn); -ASSERT ( gpfn !=SHARED_M2P_ENTRY ); -if ( xatp->space == XENMAPSPACE_gmfn || - xatp->space == XENMAPSPACE_gmfn_range ) -ASSERT ( gpfn == gfn ); -if ( gpfn !=INVALID_M2P_ENTRY ) -guest_physmap_remove_page (d, gpfn, mfn,PAGE_ORDER_4K ); + old_gpfn =get_gpfn_from_mfn (mfn); +ASSERT ( old_gpfn !=SHARED_M2P_ENTRY ); +if ( space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range ) +ASSERT ( old_gpfn == gfn ); +if ( old_gpfn !=INVALID_M2P_ENTRY ) +guest_physmap_remove_page (d, old_gpfn, mfn,PAGE_ORDER_4K );/* Map at new location. */ - rc =guest_physmap_add_page (d, xatp->gpfn, mfn,PAGE_ORDER_4K ); + rc =guest_physmap_add_page (d, gpfn, mfn,PAGE_ORDER_4K );/* In the XENMAPSPACE_gmfn, we took a ref of the gfn at the top */ -if ( xatp->space == XENMAPSPACE_gmfn || - xatp->space == XENMAPSPACE_gmfn_range ) +if ( space == XENMAPSPACE_gmfn || space == XENMAPSPACE_gmfn_range )put_gfn (d, gfn);if ( page )@@ -4632,90 +4631,12 @@ static int xenmem_add_to_physmap_once(return rc; } -static int xenmem_add_to_physmap (struct domain *d, -struct xen_add_to_physmap *xatp) -{ -struct xen_add_to_physmap start_xatp; -int rc =0 ; - -if ( xatp->space == XENMAPSPACE_gmfn_range ) - { -if (need_iommu (d) ) -this_cpu (iommu_dont_flush_iotlb) =1 ; - - start_xatp = *xatp; -while ( xatp->size >0 ) - { - rc =xenmem_add_to_physmap_once (d, xatp); -if ( rc <0 ) -break ; - - xatp->idx++; - xatp->gpfn++; - xatp->size--; - -/* Check for continuation if it's not the last interation */ -if ( xatp->size >0 &&hypercall_preempt_check () ) - { - rc = -EAGAIN ; -break ; - } - } - -if (need_iommu (d) ) - { -this_cpu (iommu_dont_flush_iotlb) =0 ; -iommu_iotlb_flush (d, start_xatp.idx, start_xatp.size - xatp->size); -iommu_iotlb_flush (d, start_xatp.gpfn, start_xatp.size - xatp->size); - } - -return rc; - } - -return xenmem_add_to_physmap_once (d, xatp); -} -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) {int rc;switch ( op ) { -case XENMEM_add_to_physmap: - { -struct xen_add_to_physmap xatp; -struct domain *d; - -if (copy_from_guest (&xatp, arg,1 ) ) -return -EFAULT ; - - d =rcu_lock_domain_by_any_id (xatp.domid); -if ( d ==NULL ) -return -ESRCH ; - -if (xsm_add_to_physmap (XSM_TARGET , current->domain, d) ) - { -rcu_unlock_domain (d); -return -EPERM ; - } - - rc =xenmem_add_to_physmap (d, &xatp); - -rcu_unlock_domain (d); - -if ( xatp.space == XENMAPSPACE_gmfn_range ) - { -if ( rc &&__copy_to_guest (arg, &xatp,1 ) ) - rc = -EFAULT ; - -if ( rc == -EAGAIN ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); - } - -return rc; - } -case XENMEM_set_memory_map: {struct xen_foreign_memory_map fmap;xen/arch/x86/x86_64/compat/mm.c +0
-28@@ -55,34 +55,6 @@ int compat_arch_memory_op(int op, XEN_GUswitch ( op ) { -case XENMEM_add_to_physmap: - { -struct compat_add_to_physmap cmp; -struct xen_add_to_physmap *nat =COMPAT_ARG_XLAT_VIRT_BASE ; - -if (copy_from_guest (&cmp, arg,1 ) ) -return -EFAULT ; - -XLAT_add_to_physmap (nat, &cmp); - rc =arch_memory_op (op,guest_handle_from_ptr (nat, void)); - -if ( !rc || cmp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp, nat); -if (__copy_to_guest (arg, &cmp,1 ) ) - { -if ( rc == __HYPERVISOR_memory_op ) -hypercall_cancel_continuation (); -return -EFAULT ; - } - -if ( rc == __HYPERVISOR_memory_op ) -hypercall_xlat_continuation (NULL ,0x2 , nat, arg); - -break ; - } -case XENMEM_set_memory_map: {struct compat_foreign_memory_map cmp;xen/common/compat/memory.c +10
-0@@ -26,11 +26,13 @@ int compat_memory_op(unsigned int cmd, XXEN_GUEST_HANDLE_PARAM (void ) hnd;struct xen_memory_reservation *rsrv;struct xen_memory_exchange *xchg; +struct xen_add_to_physmap *atp;struct xen_remove_from_physmap *xrfp; } nat;union {struct compat_memory_reservation rsrv;struct compat_memory_exchange xchg; +struct compat_add_to_physmap atp; } cmp;set_xen_guest_handle (nat.hnd,COMPAT_ARG_XLAT_VIRT_BASE );@@ -187,6 +189,14 @@ int compat_memory_op(unsigned int cmd, X nat.hnd = compat;break ; +case XENMEM_add_to_physmap: +if (copy_from_guest (&cmp.atp, compat,1 ) ) +return -EFAULT ; + +XLAT_add_to_physmap (nat.atp, &cmp.atp); + +break ; +case XENMEM_remove_from_physmap: {struct compat_remove_from_physmap cmp;
xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, X · line 330
Quoted 6 lines
xen/common/compat/memory.c +3
-0@@ -315,6 +325,16 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_remove_from_physmap:break ; +case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ;
Why is this check here in the compat layer? Surely the -ENOSYS from do_memory_op is sufficient to be included in the !rc check ?
Quoted 128 lines
xen/common/compat/memory.c +7
-0+ +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ; +default :domain_crash (current->domain); split =0 ;xen/common/memory.c +85
-0@@ -542,6 +542,53 @@ static long memory_exchange(XEN_GUEST_HAreturn rc; } +static int xenmem_add_to_physmap (struct domain *d, +struct xen_add_to_physmap *xatp) +{ +struct xen_add_to_physmap start_xatp; +int rc =0 ; + +if ( xatp->space != XENMAPSPACE_gmfn_range ) +return xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn); + +#ifdef HAS_PASSTHROUGH +if (need_iommu (d) ) +this_cpu (iommu_dont_flush_iotlb) =1 ; +#endif + + start_xatp = *xatp; +while ( xatp->size >0 ) + { + rc =xenmem_add_to_physmap_one (d, xatp->space,DOMID_INVALID , + xatp->idx, xatp->gpfn); +if ( rc <0 ) +break ; + + xatp->idx++; + xatp->gpfn++; + xatp->size--; + +/* Check for continuation if it's not the last iteration. */ +if ( xatp->size >0 &&hypercall_preempt_check () ) + { + rc = -EAGAIN ; +break ; + } + } + +#ifdef HAS_PASSTHROUGH +if (need_iommu (d) ) + { +this_cpu (iommu_dont_flush_iotlb) =0 ; +iommu_iotlb_flush (d, start_xatp.idx, start_xatp.size - xatp->size); +iommu_iotlb_flush (d, start_xatp.gpfn, start_xatp.size - xatp->size); + } +#endif + +return rc; +} +long do_memory_op (unsigned long cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {struct domain *d;@@ -673,6 +720,44 @@ long do_memory_op(unsigned long cmd, XENbreak ; +case XENMEM_add_to_physmap: + { +struct xen_add_to_physmap xatp; + +if (copy_from_guest (&xatp, arg,1 ) ) +return -EFAULT ; + +/* Foreign mapping is only possible via add_to_physmap_range. */ +if ( xatp.space == XENMAPSPACE_gmfn_foreign ) +return -ENOSYS ; + + d =rcu_lock_domain_by_any_id (xatp.domid); +if ( d ==NULL ) +return -ESRCH ; + + rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); +if ( rc ) + { +rcu_unlock_domain (d); +return rc; + } + + rc =xenmem_add_to_physmap (d, &xatp); + +rcu_unlock_domain (d); + +if ( xatp.space == XENMAPSPACE_gmfn_range && rc == -EAGAIN ) + { +if ( !__copy_to_guest (arg, &xatp,1 ) ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"ih" , op, arg); +else + rc = -EFAULT ; + } + +return rc; + } +case XENMEM_remove_from_physmap: {struct xen_remove_from_physmap xrfp;xen/include/xen/mm.h +4
-0@@ -356,6 +356,10 @@ static inline unsigned int get_order_frovoid scrub_one_page (struct page_info *); +int xenmem_add_to_physmap_one (struct domain *d,uint16_t space, +domid_t foreign_domid, +unsigned long idx,xen_pfn_t gpfn); +/* Returns 1 on success, 0 on error, negative if the ring * for event propagation is full in the presence of paging */ int guest_remove_page (struct domain *d,unsigned long gmfn);
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 1/5] move XENMEM_add_to_physmap handling framework to common code
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, X · line 330
Quoted 3 lines · Jan Beulich
xen/common/compat/memory.c +3
-0+case XENMEM_add_to_physmap: +if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) +break ;Why is this check here in the compat layer? Surely the
-ENOSYSfromdo_memory_opis sufficient to be included in the !rc check ?
Quoted 6 lines
xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, X · line 336
Quoted 6 lines
xen/common/compat/memory.c +6
-0+ +XLAT_add_to_physmap (&cmp.atp, nat.atp); +if (__copy_to_guest (compat, &cmp.atp,1 ) ) + rc = -EFAULT ; + +break ;
You mis-read the meaning of the check: The reverse translation was necessary (it's gone with patch 2 anyway) only when wanting to copy back into the interface structure. Since that code is gone with us no longer doing these invalid modifications, any possible incorrectness here is moot now anyway.
Jan
PATCH v3 2/5 fix XENMEM_add_to_physmap preemption handling
In reply to Jan BeulichJust like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
---
v2: drop bogus ASSERT()
xen/common/compat/memory.c +4 -10
@@ -190,6 +190,9 @@ int compat_memory_op(unsigned int cmd, Xbreak ;case XENMEM_add_to_physmap: +BUILD_BUG_ON ((typeof (cmp.atp.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); +if (copy_from_guest (&cmp.atp, compat,1 ) )return -EFAULT ;
@@ -322,17 +325,8 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_current_reservation:case XENMEM_maximum_reservation:case XENMEM_maximum_gpfn: -case XENMEM_remove_from_physmap: -break ; -case XENMEM_add_to_physmap: -if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp.atp, nat.atp); -if (__copy_to_guest (compat, &cmp.atp,1 ) ) - rc = -EFAULT ; - +case XENMEM_remove_from_physmap:break ;default :
xen/common/memory.c +28 -22
112 lines not on this page · raw message
fix XENMEM_add_to_physmap preemption handling
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
---
v2: drop bogus ASSERT()
xen/common/compat/memory.c +4 -10
@@ -190,6 +190,9 @@ int compat_memory_op(unsigned int cmd, Xbreak ;case XENMEM_add_to_physmap: +BUILD_BUG_ON ((typeof (cmp.atp.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); +if (copy_from_guest (&cmp.atp, compat,1 ) )return -EFAULT ;
@@ -322,17 +325,8 @@ int compat_memory_op(unsigned int cmd, Xcase XENMEM_current_reservation:case XENMEM_maximum_reservation:case XENMEM_maximum_gpfn: -case XENMEM_remove_from_physmap: -break ; -case XENMEM_add_to_physmap: -if ( !rc || cmp.atp.space != XENMAPSPACE_gmfn_range ) -break ; - -XLAT_add_to_physmap (&cmp.atp, nat.atp); -if (__copy_to_guest (compat, &cmp.atp,1 ) ) - rc = -EFAULT ; - +case XENMEM_remove_from_physmap:break ;default :
xen/common/memory.c +28 -22
112 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 2/5] fix XENMEM_add_to_physmap preemption handling
Quoted 7 lines · Jan Beulich
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs.
Signed-off-by Jan Beulich <[email protected]>Reviewed-by Tim Deegan <[email protected]>Acked-by Keir Fraser <[email protected]>
PATCH v3 3/5 move XENMEM_add_to_physmap_range handling framework to common code
In reply to Jan BeulichThere's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
This further eliminates the erroneous bailing from xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
---
v2: Restore restriction of XENMAPSPACE_gmfn_range only being supported
through XENMEM_add_to_physmap.
xen/arch/arm/mm.c +0 -93
@@ -1057,103 +1057,10 @@ int xenmem_add_to_physmap_one(return rc; } -static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) -{ -int rc; - -while ( xatpr->size >0 ) - { -xen_ulong_t idx; -xen_pfn_t gpfn; - -if (unlikely (copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if (unlikely (copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) - { - rc = -EFAULT ; - goto out; - } - - rc =xenmem_add_to_physmap_one (d, xatpr->space, - xatpr->foreign_domid, - idx, gpfn); - -if (unlikely (copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) - { - rc = -EFAULT ; - goto out; - } - -if ( rc <0 ) - goto out; - -guest_handle_add_offset (xatpr->idxs,1 ); -guest_handle_add_offset (xatpr->gpfns,1 ); -guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--; - -/* Check for continuation if it's not the last interation */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) - { - rc = -EAGAIN ; - goto out; - } - } - - rc =0 ; - -out: -return rc; - -} -long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) { -int rc; -switch ( op ) { -case XENMEM_add_to_physmap_range: - { -struct xen_add_to_physmap_range xatpr; -struct domain *d; - -if (copy_from_guest (&xatpr, arg,1 ) ) -return -EFAULT ; - -/* This mapspace is redundant for this hypercall */ -if ( xatpr.space == XENMAPSPACE_gmfn_range ) -return -EINVAL ; - - d =rcu_lock_domain_by_any_id (xatpr.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc =xsm_add_to_physmap (XSM_TARGET , current->domain, d); -if ( rc ) - { -rcu_unlock_domain (d); -return rc; - } - - rc =xenmem_add_to_physmap_range (d, &xatpr); - -rcu_unlock_domain (d); - -if ( rc &©_to_guest (arg, &xatpr,1 ) ) - rc = -EFAULT ; - -if ( rc == -EAGAIN ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); - -return rc; - }/* XXX: memsharing not working yet */ case XENMEM_get_sharing_shared_pages:case XENMEM_get_sharing_freed_pages:
xen/common/memory.c +93 -0
105 lines not on this page · raw message
move XENMEM_add_to_physmap_range handling framework to common code
There's really nothing really architecture specific here; the architecture specific handling is limited to xenmem_add_to_physmap_one().
This further eliminates the erroneous bailing from xenmem_add_to_physmap_range() if xenmem_add_to_physmap_one() fails.
---
v2: Restore restriction of XENMAPSPACE_gmfn_range only being supported
through XENMEM_add_to_physmap.
xen/arch/arm/mm.c +0 -93
103 lines not on this page · raw message
xen/common/memory.c +93 -0
105 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 3/5] move XENMEM_add_to_physmap_range handling framework to common code
Quoted 10 lines · Jan Beulich
There's really nothing really architecture specific here; the architecture specific handling is limited to
xenmem_add_to_physmap_one().This further eliminates the erroneous bailing from
xenmem_add_to_physmap_range()ifxenmem_add_to_physmap_one()fails.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Tim Deegan <[email protected]>Acked-by Keir Fraser <[email protected]>
PATCH v3 4/5 fix XENMEM_add_to_physmap_range preemption handling
In reply to Jan BeulichJust like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
xen/common/memory.c +26 -14
@@ -596,11 +596,21 @@ static int xenmem_add_to_physmap(struct }static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) +struct xen_add_to_physmap_range *xatpr, +unsigned int start) { +unsigned int done =0 ;int rc; -while ( xatpr->size >0 ) +if ( xatpr->size < start ) +return -EILSEQ ; + +guest_handle_add_offset (xatpr->idxs, start); +guest_handle_add_offset (xatpr->gpfns, start); +guest_handle_add_offset (xatpr->errs, start); + xatpr->size -= start; + +while ( xatpr->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn;
@@ -630,12 +640,11 @@ static int xenmem_add_to_physmap_range(sguest_handle_add_offset (xatpr->idxs,1 );guest_handle_add_offset (xatpr->gpfns,1 );guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--;/* Check for continuation if it's not the last iteration. */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) +if ( xatpr->size > ++done &&hypercall_preempt_check () ) { - rc = -EAGAIN ; + rc = start + done; goto out; } }
@@ -820,6 +829,13 @@ long do_memory_op(unsigned long cmd, XENstruct xen_add_to_physmap_range xatpr;struct domain *d; +BUILD_BUG_ON ((typeof (xatpr.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); + +/* Check for malicious or buggy input. */ + if ( start_extent != (typeof(xatpr.size))start_extent ) +return -EDOM ; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
@@ -841,18 +857,14 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr); + rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent);rcu_unlock_domain (d); -if ( rc == -EAGAIN ) - { -if ( !__copy_to_guest (arg, &xatpr,1 ) ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); -else - rc = -EFAULT ; - } +if ( rc >0 ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"lh" , + op | (rc <<MEMOP_EXTENT_SHIFT ), arg);return rc; }
fix XENMEM_add_to_physmap_range preemption handling
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
xen/common/memory.c +26 -14
@@ -596,11 +596,21 @@ static int xenmem_add_to_physmap(struct }static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr) +struct xen_add_to_physmap_range *xatpr, +unsigned int start) { +unsigned int done =0 ;int rc; -while ( xatpr->size >0 ) +if ( xatpr->size < start ) +return -EILSEQ ; + +guest_handle_add_offset (xatpr->idxs, start); +guest_handle_add_offset (xatpr->gpfns, start); +guest_handle_add_offset (xatpr->errs, start); + xatpr->size -= start; + +while ( xatpr->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn;
@@ -630,12 +640,11 @@ static int xenmem_add_to_physmap_range(sguest_handle_add_offset (xatpr->idxs,1 );guest_handle_add_offset (xatpr->gpfns,1 );guest_handle_add_offset (xatpr->errs,1 ); - xatpr->size--;/* Check for continuation if it's not the last iteration. */ -if ( xatpr->size >0 &&hypercall_preempt_check () ) +if ( xatpr->size > ++done &&hypercall_preempt_check () ) { - rc = -EAGAIN ; + rc = start + done; goto out; } }
@@ -820,6 +829,13 @@ long do_memory_op(unsigned long cmd, XENstruct xen_add_to_physmap_range xatpr;struct domain *d; +BUILD_BUG_ON ((typeof (xatpr.size))-1 > + (UINT_MAX >>MEMOP_EXTENT_SHIFT )); + +/* Check for malicious or buggy input. */ + if ( start_extent != (typeof(xatpr.size))start_extent ) +return -EDOM ; + if ( copy_from_guest(&xatpr, arg, 1) || !guest_handle_okay(xatpr.idxs, xatpr.size) || !guest_handle_okay(xatpr.gpfns, xatpr.size) ||
@@ -841,18 +857,14 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr); + rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent);rcu_unlock_domain (d); -if ( rc == -EAGAIN ) - { -if ( !__copy_to_guest (arg, &xatpr,1 ) ) - rc =hypercall_create_continuation ( - __HYPERVISOR_memory_op,"ih" , op, arg); -else - rc = -EFAULT ; - } +if ( rc >0 ) + rc =hypercall_create_continuation ( + __HYPERVISOR_memory_op,"lh" , + op | (rc <<MEMOP_EXTENT_SHIFT ), arg);return rc; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 4/5] fix XENMEM_add_to_physmap_range preemption handling
Quoted 8 lines · Jan Beulich
Just like for all other hypercalls we shouldn't be modifying the input structure - all of the fields are, even if not explicitly documented, just inputs (the one OUT one really refers to the memory pointed to by that handle rather than the handle itself).
Signed-off-by Jan Beulich <[email protected]>Reviewed-by Tim Deegan <[email protected]>Acked-by Keir Fraser <[email protected]>
PATCH v3 5/5 rename XENMEM_add_to_physmap_{range => batch}
In reply to Jan BeulichThe use of "range" here wasn't really correct - there are no ranges involved. As the comment in the public header already correctly said, all this is about is batching of XENMEM_add_to_physmap calls (with the addition of having a way to specify a foreign domain for XENMAPSPACE_gmfn_foreign).
xen/common/memory.c +29 -29
@@ -595,54 +595,54 @@ static int xenmem_add_to_physmap(structreturn rc; } -static int xenmem_add_to_physmap_range (struct domain *d, -struct xen_add_to_physmap_range *xatpr, +static int xenmem_add_to_physmap_batch (struct domain *d, +struct xen_add_to_physmap_batch *xatpb,unsigned int start) {unsigned int done =0 ;int rc; -if ( xatpr->size < start ) +if ( xatpb->size < start )return -EILSEQ ; -guest_handle_add_offset (xatpr->idxs, start); -guest_handle_add_offset (xatpr->gpfns, start); -guest_handle_add_offset (xatpr->errs, start); - xatpr->size -= start; +guest_handle_add_offset (xatpb->idxs, start); +guest_handle_add_offset (xatpb->gpfns, start); +guest_handle_add_offset (xatpb->errs, start); + xatpb->size -= start; -while ( xatpr->size > done ) +while ( xatpb->size > done ) {xen_ulong_t idx;xen_pfn_t gpfn; -if (unlikely (__copy_from_guest_offset (&idx, xatpr->idxs,0 ,1 )) ) +if (unlikely (__copy_from_guest_offset (&idx, xatpb->idxs,0 ,1 )) ) { rc = -EFAULT ; goto out; } -if (unlikely (__copy_from_guest_offset (&gpfn, xatpr->gpfns,0 ,1 )) ) +if (unlikely (__copy_from_guest_offset (&gpfn, xatpb->gpfns,0 ,1 )) ) { rc = -EFAULT ; goto out; } - rc =xenmem_add_to_physmap_one (d, xatpr->space, - xatpr->foreign_domid, + rc =xenmem_add_to_physmap_one (d, xatpb->space, + xatpb->foreign_domid, idx, gpfn); -if (unlikely (__copy_to_guest_offset (xatpr->errs,0 , &rc,1 )) ) +if (unlikely (__copy_to_guest_offset (xatpb->errs,0 , &rc,1 )) ) { rc = -EFAULT ; goto out; } -guest_handle_add_offset (xatpr->idxs,1 ); -guest_handle_add_offset (xatpr->gpfns,1 ); -guest_handle_add_offset (xatpr->errs,1 ); +guest_handle_add_offset (xatpb->idxs,1 ); +guest_handle_add_offset (xatpb->gpfns,1 ); +guest_handle_add_offset (xatpb->errs,1 );/* Check for continuation if it's not the last iteration. */ -if ( xatpr->size > ++done &&hypercall_preempt_check () ) +if ( xatpb->size > ++done &&hypercall_preempt_check () ) { rc = start + done; goto out;
@@ -797,7 +797,7 @@ long do_memory_op(unsigned long cmd, XENif (copy_from_guest (&xatp, arg,1 ) )return -EFAULT ; -/* Foreign mapping is only possible via add_to_physmap_range. */ +/* Foreign mapping is only possible via add_to_physmap_batch. */ if ( xatp.space == XENMAPSPACE_gmfn_foreign )return -ENOSYS ;
@@ -824,29 +824,29 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } -case XENMEM_add_to_physmap_range: +case XENMEM_add_to_physmap_batch: { -struct xen_add_to_physmap_range xatpr; +struct xen_add_to_physmap_batch xatpb;struct domain *d; -BUILD_BUG_ON ((typeof (xatpr.size))-1 > +BUILD_BUG_ON ((typeof (xatpb.size))-1 > (UINT_MAX >>MEMOP_EXTENT_SHIFT ));/* Check for malicious or buggy input. */ - if ( start_extent != (typeof(xatpr.size))start_extent ) + if ( start_extent != (typeof(xatpb.size))start_extent )return -EDOM ; -if (copy_from_guest (&xatpr, arg,1 ) || - !guest_handle_okay (xatpr.idxs, xatpr.size) || - !guest_handle_okay (xatpr.gpfns, xatpr.size) || - !guest_handle_okay (xatpr.errs, xatpr.size) ) +if (copy_from_guest (&xatpb, arg,1 ) || + !guest_handle_okay (xatpb.idxs, xatpb.size) || + !guest_handle_okay (xatpb.gpfns, xatpb.size) || + !guest_handle_okay (xatpb.errs, xatpb.size) )return -EFAULT ;/* This mapspace is unsupported for this hypercall. */ -if ( xatpr.space == XENMAPSPACE_gmfn_range ) +if ( xatpb.space == XENMAPSPACE_gmfn_range )return -EOPNOTSUPP ; - d =rcu_lock_domain_by_any_id (xatpr.domid); + d =rcu_lock_domain_by_any_id (xatpb.domid);if ( d ==NULL )return -ESRCH ;
@@ -857,7 +857,7 @@ long do_memory_op(unsigned long cmd, XENreturn rc; } - rc =xenmem_add_to_physmap_range (d, &xatpr, start_extent); + rc =xenmem_add_to_physmap_batch (d, &xatpb, start_extent);rcu_unlock_domain (d);
xen/include/public/arch-arm.h +1 -1
@@ -79,7 +79,7 @@* * In addition the following arch specific sub-ops: * * XENMEM_add_to_physmap -* * XENMEM_add_to_physmap_range +* * XENMEM_add_to_physmap_batch * * HYPERVISOR_domctl * All generic sub-operations, with the exception of:
xen/include/public/memory.h +12 -6
@@ -207,8 +207,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_machphys_map#define XENMAPSPACE_gmfn 2/* GMFN */ #define XENMAPSPACE_gmfn_range 3/* GMFN range, XENMEM_add_to_physmap only. */ #define XENMAPSPACE_gmfn_foreign 4/* GMFN from another dom, -* XENMEM_add_to_physmap_range only. -*/ +* XENMEM_add_to_physmap_batch only. */ /* ` } */ /*
@@ -238,8 +237,8 @@ typedef struct xen_add_to_physmap xen_adDEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_t);/* A batched version of add_to_physmap. */ -#define XENMEM_add_to_physmap_range 23 -struct xen_add_to_physmap_range { +#define XENMEM_add_to_physmap_batch 23 +struct xen_add_to_physmap_batch {/* IN */ /* Which domain to change the mapping for. */ domid_t domid;
@@ -260,8 +259,15 @@ struct xen_add_to_physmap_range {/* Per index error code. */ XEN_GUEST_HANDLE (int ) errs; }; -typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t ; -DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_range_t); +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t); + +#if __XEN_INTERFACE_VERSION__ <0x00040400 +#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch +#define xen_add_to_physmap_range xen_add_to_physmap_batch +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t); +#endif /* * Unmaps the page appearing at a particular GPFN from the specified guest's
rename XENMEM_add_to_physmap_{range => batch}
The use of "range" here wasn't really correct - there are no ranges involved. As the comment in the public header already correctly said, all this is about is batching of XENMEM_add_to_physmap calls (with the addition of having a way to specify a foreign domain for XENMAPSPACE_gmfn_foreign).
xen/common/memory.c +29 -29
126 lines not on this page · raw message
xen/include/public/arch-arm.h +1 -1
@@ -79,7 +79,7 @@* * In addition the following arch specific sub-ops: * * XENMEM_add_to_physmap -* * XENMEM_add_to_physmap_range +* * XENMEM_add_to_physmap_batch * * HYPERVISOR_domctl * All generic sub-operations, with the exception of:
xen/include/public/memory.h +12 -6
@@ -207,8 +207,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_machphys_map#define XENMAPSPACE_gmfn 2/* GMFN */ #define XENMAPSPACE_gmfn_range 3/* GMFN range, XENMEM_add_to_physmap only. */ #define XENMAPSPACE_gmfn_foreign 4/* GMFN from another dom, -* XENMEM_add_to_physmap_range only. -*/ +* XENMEM_add_to_physmap_batch only. */ /* ` } */ /*
@@ -238,8 +237,8 @@ typedef struct xen_add_to_physmap xen_adDEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_t);/* A batched version of add_to_physmap. */ -#define XENMEM_add_to_physmap_range 23 -struct xen_add_to_physmap_range { +#define XENMEM_add_to_physmap_batch 23 +struct xen_add_to_physmap_batch {/* IN */ /* Which domain to change the mapping for. */ domid_t domid;
@@ -260,8 +259,15 @@ struct xen_add_to_physmap_range {/* Per index error code. */ XEN_GUEST_HANDLE (int ) errs; }; -typedef struct xen_add_to_physmap_range xen_add_to_physmap_range_t ; -DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_range_t); +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t); + +#if __XEN_INTERFACE_VERSION__ <0x00040400 +#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch +#define xen_add_to_physmap_range xen_add_to_physmap_batch +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t); +#endif /* * Unmaps the page appearing at a particular GPFN from the specified guest's
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v3 5/5] rename XENMEM_add_to_physmap_{range => batch}
xen/include/public/memory.h struct xen_add_to_physmap_range { · line 269
Quoted 5 lines · Jan Beulich
xen/include/public/memory.h +5
-0+#if __XEN_INTERFACE_VERSION__ <0x00040400 +#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch +#define xen_add_to_physmap_range xen_add_to_physmap_batch +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t);
This last one should be a x_a_t_p_range_t I think?
Quoted 6 lines
+#endif
/*
* Unmaps the page appearing at a particular GPFN from the specified guest's
Re: [PATCH v3 5/5] rename XENMEM_add_to_physmap_{range => batch}
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/include/public/memory.h struct xen_add_to_physmap_range { · line 269
Quoted 5 lines · Jan Beulich
xen/include/public/memory.h +5
-0+#if __XEN_INTERFACE_VERSION__ <0x00040400 +#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch +#define xen_add_to_physmap_range xen_add_to_physmap_batch +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t);This last one should be a
x_a_t_p_range_tI think?
Oh, yes, of course.
Jan
Ian Campbell
Acked-byRe: [PATCH v3 5/5] rename XENMEM_add_to_physmap_{range => batch}
Quoted 11 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/include/public/memory.h struct xen_add_to_physmap_range { · line 269
Quoted 5 lines · Jan Beulich
xen/include/public/memory.h +5
-0+#if __XEN_INTERFACE_VERSION__ <0x00040400 +#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch +#define xen_add_to_physmap_range xen_add_to_physmap_batch +typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t ; +DEFINE_XEN_GUEST_HANDLE (xen_add_to_physmap_batch_t);This last one should be a
x_a_t_p_range_tI think?Oh, yes, of course.
I had also meant to say:
With that change:
Ian.