xen/grant_table: introduce GNTTABOP_unmap_and_duplicate
RFC PATCH 1/1 xen/grant_table: introduce GNTTABOP_unmap_and_duplicate
GNTTABOP_unmap_and_replace has two issues:
- it unconditionally replaces the mapping passed in new_addr with 0;
- it doesn't support GNTMAP_contains_pte mappings on x86, returning a general error instead of some form of ENOSYS.
Introduce a new operation called GNTTABOP_unmap_and_duplicate that behaves like GNTTABOP_unmap_and_replace without zeroing the mapping passed in new_addr. Also return GNTST_enosys instead of GNTST_general_error if GNTMAP_contains_pte is specified.
--- xen/arch/arm/mm.c | 2 +- xen/arch/x86/mm.c | 36 ++++++++++++---- xen/common/compat/grant_table.c | 8 ++++ xen/common/grant_table.c | 83 ++++++++++++++++++++++++++++++++++++- xen/include/asm-arm/grant_table.h | 2 +- xen/include/asm-x86/grant_table.h | 3 +- xen/include/public/grant_table.h | 23 ++++++++++ xen/include/xlat.lst | 1 + 8 files changed, 145 insertions(+), 13 deletions(-)
xen/arch/arm/mm.c +1 -1
@@ -1122,7 +1122,7 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, }int replace_grant_host_mapping (unsigned long addr,unsigned long mfn, -unsigned long new_addr,unsigned int flags) +unsigned long new_addr,unsigned int flags,bool_t zero_new_addr) {unsigned long gfn = (unsigned long )(addr >>PAGE_SHIFT );struct domain *d = current->domain;
xen/arch/x86/mm.c +27 -9
@@ -4048,7 +4048,8 @@ static int replace_grant_p2m_mapping( }int replace_grant_host_mapping ( -uint64_t addr,unsigned long frame,uint64_t new_addr,unsigned int flags) +uint64_t addr,unsigned long frame,uint64_t new_addr,unsigned int flags, +bool_t zero_new_addr) {struct vcpu *curr = current;l1_pgentry_t *pl1e, ol1e;
@@ -4065,7 +4066,7 @@ int replace_grant_host_mapping(return destroy_grant_pte_mapping (addr, frame, curr->domain);MEM_LOG ("Unsupported grant table operation" ); -return GNTST_general_error; +return GNTST_enosys; }if ( !new_addr )
@@ -4103,14 +4104,31 @@ int replace_grant_host_mapping( ol1e = *pl1e; -if (unlikely (!UPDATE_ENTRY (l1, pl1e, ol1e,l1e_empty (), - gl1mfn, curr,0 )) ) +if ( zero_new_addr ) { -page_unlock (l1pg); -put_page (l1pg); -MEM_LOG ("Cannot delete PTE entry at %p" , (unsigned long *)pl1e); -guest_unmap_l1e (curr, pl1e); -return GNTST_general_error; +if (unlikely (!UPDATE_ENTRY (l1, pl1e, ol1e,l1e_empty (), + gl1mfn, curr,0 )) ) + { +page_unlock (l1pg); +put_page (l1pg); +MEM_LOG ("Cannot delete PTE entry at %p" , (unsigned long *)pl1e); +guest_unmap_l1e (curr, pl1e); +return GNTST_general_error; + } + } +else + { +/* Increase refcount */ +if (unlikely (!get_page_and_type (l1e_get_page (ol1e), curr->domain, + PGT_writable_page)) ) + { +page_unlock (l1pg); +put_page (l1pg); +guest_unmap_l1e (curr, pl1e); +MEM_LOG ("Cannot increase refcount of frame at %" PRI_mfn, +page_to_mfn (l1e_get_page (ol1e))); +return GNTST_general_error; + } }page_unlock (l1pg);
xen/common/compat/grant_table.c +8 -0
@@ -51,6 +51,10 @@ CHECK_gnttab_get_version; CHECK_gnttab_swap_grant_ref;#undef xen_gnttab_swap_grant_ref +#define xen_gnttab_unmap_and_duplicate gnttab_unmap_and_duplicate +CHECK_gnttab_unmap_and_duplicate; +#undef xen_gnttab_unmap_and_duplicate +int compat_grant_table_op (unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) cmp_uop,unsigned int count)
@@ -106,6 +110,10 @@ int compat_grant_table_op(unsigned int cmd,CASE (swap_grant_ref);#endif +#ifndef CHECK_gnttab_unmap_and_duplicate +CASE (unmap_and_duplicate); +#endif +#undef CASEdefault :return do_grant_table_op (cmd, cmp_uop, count);
xen/common/grant_table.c +82 -1
113 lines not on this page · raw message
xen/include/asm-arm/grant_table.h +1 -1
@@ -12,7 +12,7 @@ int create_grant_host_mapping(unsigned long gpaddr, cache_flags);#define gnttab_host_mapping_get_page_type (op, d, rd) (0)int replace_grant_host_mapping (unsigned long gpaddr,unsigned long mfn, -unsigned long new_gpaddr,unsigned int flags); +unsigned long new_gpaddr,unsigned int flags,bool_t zero_new_addr);void gnttab_mark_dirty (struct domain *d,unsigned long l);#define gnttab_create_status_page (d, t, i) do {} while (0)#define gnttab_status_gmfn (d, t, i) (0)
xen/include/asm-x86/grant_table.h +2 -1
@@ -16,7 +16,8 @@int create_grant_host_mapping (uint64_t addr,unsigned long frame,unsigned int flags,unsigned int cache_flags);int replace_grant_host_mapping ( -uint64_t addr,unsigned long frame,uint64_t new_addr,unsigned int flags); +uint64_t addr,unsigned long frame,uint64_t new_addr,unsigned int flags, +bool_t zero_new_addr);#define gnttab_create_shared_page (d, t, i) \ do { \
xen/include/public/grant_table.h +23 -0
@@ -309,6 +309,7 @@ typedef uint16_t grant_status_t;#define GNTTABOP_get_status_frames 9#define GNTTABOP_get_version 10#define GNTTABOP_swap_grant_ref 11 +#define GNTTABOP_unmap_and_duplicate 12#endif /* __XEN_INTERFACE_VERSION__ */ /* ` } */
@@ -574,6 +575,27 @@ struct gnttab_swap_grant_ref {typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t ;DEFINE_XEN_GUEST_HANDLE (gnttab_swap_grant_ref_t); +/* +* GNTTABOP_unmap_and_duplicate: Destroy one or more grant-reference mappings +* tracked by <handle> but atomically replace the page table entry with one +* pointing to the machine address under <new_addr>. +* NOTES: +* 1. The call may fail in an undefined manner if either mapping is not +* tracked by <handle>. +* 2. After executing a batch of unmaps, it is guaranteed that no stale +* mappings will remain in the device or host TLBs. +*/ +struct gnttab_unmap_and_duplicate { +/* IN parameters. */ +uint64_t host_addr; +uint64_t new_addr; +grant_handle_t handle; +/* OUT parameters. */ +int16_t status;/* => enum grant_status */ +}; +typedef struct gnttab_unmap_and_duplicate gnttab_unmap_and_duplicate_t ; +DEFINE_XEN_GUEST_HANDLE (gnttab_unmap_and_duplicate_t); +#endif /* __XEN_INTERFACE_VERSION__ */ /*
@@ -631,6 +653,7 @@ DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t);#define GNTST_bad_copy_arg (-10)/* copy arguments cross page boundary. */ #define GNTST_address_too_big (-11)/* transfer page address too large. */ #define GNTST_eagain (-12)/* Operation not done; try again. */ +#define GNTST_enosys (-13)/* Operation not implemented. */ /* ` } */ #define GNTTABOP_error_msgs { \
xen/include/xlat.lst +1 -0
@@ -51,6 +51,7 @@ ? grant_entry_header grant_table.h ? grant_entry_v2 grant_table.h ? gnttab_swap_grant_ref grant_table.h +? gnttab_unmap_and_duplicate grant_table.h ? kexec_exec kexec.h ! kexec_image kexec.h ! kexec_range kexec.h
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 10 lines · Roger Pau Monne
GNTTABOP_unmap_and_replacehas two issues:
- it unconditionally replaces the mapping passed innew_addrwith 0;
- it doesn't supportGNTMAP_contains_ptemappings on x86, returning a general error instead of some form of ENOSYS.Introduce a new operation called
GNTTABOP_unmap_and_duplicatethat behaves likeGNTTABOP_unmap_and_replacewithout zeroing the mapping passed innew_addr. Also returnGNTST_enosysinstead ofGNTST_general_errorifGNTMAP_contains_pteis specified.
Quoted 5 lines
Signed-off-by Stefano Stabellini <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Cc Tim Deegan <[email protected]>Cc Jan Beulich <[email protected]>Cc Keir Fraser <[email protected]>
Any comments on this one or should I just drop the RFC and resend?
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel