ia64/xen-unstable
changeset 9223:e408a374840c
Replace memory_op subcommands reserved_phys_area and map_shared_info
with new subcommand add_to_physmap.
This changes the domain0 tools interface, but only when building
shadow-translate-mode guests.
Signed-off-by: Keir Fraser <keir@xensource.com>
with new subcommand add_to_physmap.
This changes the domain0 tools interface, but only when building
shadow-translate-mode guests.
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Fri Mar 10 16:00:36 2006 +0100 (2006-03-10) |
parents | c5286130a96e |
children | d4e433d615b0 |
files | tools/libxc/xc_linux_build.c tools/libxc/xc_private.c xen/arch/x86/mm.c xen/include/asm-x86/grant_table.h xen/include/asm-x86/page.h xen/include/public/memory.h |
line diff
1.1 --- a/tools/libxc/xc_linux_build.c Fri Mar 10 13:27:24 2006 +0000 1.2 +++ b/tools/libxc/xc_linux_build.c Fri Mar 10 16:00:36 2006 +0100 1.3 @@ -863,8 +863,7 @@ static int setup_guest(int xc_handle, 1.4 1.5 if ( shadow_mode_enabled ) 1.6 { 1.7 - struct xen_reserved_phys_area xrpa; 1.8 - struct xen_map_shared_info xmsi; 1.9 + struct xen_add_to_physmap xatp; 1.10 1.11 /* Enable shadow translate mode */ 1.12 if ( xc_shadow_control(xc_handle, dom, 1.13 @@ -875,26 +874,36 @@ static int setup_guest(int xc_handle, 1.14 goto error_out; 1.15 } 1.16 1.17 - /* Find the shared info frame. It's guaranteed to be at the 1.18 - start of the PFN hole. */ 1.19 - xrpa.domid = dom; 1.20 - xrpa.idx = 0; 1.21 - rc = xc_memory_op(xc_handle, XENMEM_reserved_phys_area, &xrpa); 1.22 - if ( rc != 0 ) 1.23 - { 1.24 - PERROR("Cannot find shared info pfn"); 1.25 - goto error_out; 1.26 - } 1.27 + guest_shared_info_mfn = (vsharedinfo_start-dsi.v_start) >> PAGE_SHIFT; 1.28 1.29 - guest_shared_info_mfn = (vsharedinfo_start-dsi.v_start) >> PAGE_SHIFT; 1.30 - xmsi.domid = dom; 1.31 - xmsi.pfn = guest_shared_info_mfn; 1.32 - rc = xc_memory_op(xc_handle, XENMEM_map_shared_info, &xmsi); 1.33 + /* Map shared info frame into guest physmap. */ 1.34 + xatp.domid = dom; 1.35 + xatp.space = XENMAPSPACE_shared_info; 1.36 + xatp.idx = 0; 1.37 + xatp.gpfn = guest_shared_info_mfn; 1.38 + rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp); 1.39 if ( rc != 0 ) 1.40 { 1.41 PERROR("Cannot map shared info pfn"); 1.42 goto error_out; 1.43 } 1.44 + 1.45 + /* Map grant table frames into guest physmap. */ 1.46 + for ( i = 0; ; i++ ) 1.47 + { 1.48 + xatp.domid = dom; 1.49 + xatp.space = XENMAPSPACE_grant_table; 1.50 + xatp.idx = i; 1.51 + xatp.gpfn = nr_pages + i; 1.52 + rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp); 1.53 + if ( rc != 0 ) 1.54 + { 1.55 + if ( errno == EINVAL ) 1.56 + break; /* done all grant tables */ 1.57 + PERROR("Cannot map grant table pfn"); 1.58 + goto error_out; 1.59 + } 1.60 + } 1.61 } 1.62 else 1.63 {
2.1 --- a/tools/libxc/xc_private.c Fri Mar 10 13:27:24 2006 +0000 2.2 +++ b/tools/libxc/xc_private.c Fri Mar 10 16:00:36 2006 +0100 2.3 @@ -231,8 +231,8 @@ int xc_memory_op(int xc_handle, 2.4 goto out1; 2.5 } 2.6 break; 2.7 - case XENMEM_reserved_phys_area: 2.8 - if ( mlock(arg, sizeof(struct xen_reserved_phys_area)) ) 2.9 + case XENMEM_add_to_physmap: 2.10 + if ( mlock(arg, sizeof(struct xen_add_to_physmap)) ) 2.11 { 2.12 PERROR("Could not mlock"); 2.13 goto out1; 2.14 @@ -277,8 +277,8 @@ int xc_memory_op(int xc_handle, 2.15 safe_munlock(xmml->extent_start, 2.16 xmml->max_extents * sizeof(unsigned long)); 2.17 break; 2.18 - case XENMEM_reserved_phys_area: 2.19 - safe_munlock(arg, sizeof(struct xen_reserved_phys_area)); 2.20 + case XENMEM_add_to_physmap: 2.21 + safe_munlock(arg, sizeof(struct xen_add_to_physmap)); 2.22 break; 2.23 case XENMEM_translate_gpfn_list: 2.24 safe_munlock(trans->mfn_list, trans->nr_gpfns * sizeof(long));
3.1 --- a/xen/arch/x86/mm.c Fri Mar 10 13:27:24 2006 +0000 3.2 +++ b/xen/arch/x86/mm.c Fri Mar 10 16:00:36 2006 +0100 3.3 @@ -234,6 +234,8 @@ void share_xen_page_with_guest( 3.4 if ( page_get_owner(page) == d ) 3.5 return; 3.6 3.7 + set_gpfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY); 3.8 + 3.9 spin_lock(&d->page_alloc_lock); 3.10 3.11 /* The incremented type count pins as writable or read-only. */ 3.12 @@ -2817,81 +2819,54 @@ long do_update_descriptor(u64 pa, u64 de 3.13 3.14 long arch_memory_op(int op, GUEST_HANDLE(void) arg) 3.15 { 3.16 - unsigned long pfn; 3.17 - struct domain *d; 3.18 - unsigned int i; 3.19 - 3.20 switch ( op ) 3.21 { 3.22 - case XENMEM_reserved_phys_area: { 3.23 - struct xen_reserved_phys_area xrpa; 3.24 - 3.25 - if ( copy_from_guest(&xrpa, arg, 1) ) 3.26 + case XENMEM_add_to_physmap: 3.27 + { 3.28 + struct xen_add_to_physmap xatp; 3.29 + unsigned long mfn = 0, gpfn; 3.30 + struct domain *d; 3.31 + 3.32 + if ( copy_from_guest(&xatp, arg, 1) ) 3.33 return -EFAULT; 3.34 3.35 - /* No guest has more than one reserved area. */ 3.36 - if ( xrpa.idx != 0 ) 3.37 - return -ESRCH; 3.38 - 3.39 - if ( (d = find_domain_by_id(xrpa.domid)) == NULL ) 3.40 + if ( (d = find_domain_by_id(xatp.domid)) == NULL ) 3.41 return -ESRCH; 3.42 3.43 - /* Only initialised translated guests have a reserved area. */ 3.44 - if ( !shadow_mode_translate(d) || (d->max_pages == 0) ) 3.45 + switch ( xatp.space ) 3.46 { 3.47 - put_domain(d); 3.48 - return -ESRCH; 3.49 - } 3.50 - 3.51 - LOCK_BIGLOCK(d); 3.52 - if ( d->arch.first_reserved_pfn == 0 ) 3.53 - { 3.54 - d->arch.first_reserved_pfn = pfn = d->max_pages; 3.55 - for ( i = 0; i < NR_GRANT_FRAMES; i++ ) 3.56 - guest_physmap_add_page( 3.57 - d, pfn + i, gnttab_shared_mfn(d, d->grant_table, i)); 3.58 + case XENMAPSPACE_shared_info: 3.59 + if ( xatp.idx == 0 ) 3.60 + mfn = virt_to_mfn(d->shared_info); 3.61 + break; 3.62 + case XENMAPSPACE_grant_table: 3.63 + if ( xatp.idx < NR_GRANT_FRAMES ) 3.64 + mfn = virt_to_mfn(d->grant_table->shared) + xatp.idx; 3.65 + break; 3.66 + default: 3.67 + break; 3.68 } 3.69 - UNLOCK_BIGLOCK(d); 3.70 - 3.71 - xrpa.first_gpfn = d->arch.first_reserved_pfn; 3.72 - xrpa.nr_gpfns = NR_GRANT_FRAMES; 3.73 - 3.74 - put_domain(d); 3.75 - 3.76 - if ( copy_to_guest(arg, &xrpa, 1) ) 3.77 - return -EFAULT; 3.78 - 3.79 - break; 3.80 - } 3.81 - 3.82 - case XENMEM_map_shared_info: { 3.83 - struct xen_map_shared_info xmsi; 3.84 - 3.85 - if ( copy_from_guest(&xmsi, arg, 1) ) 3.86 - return -EFAULT; 3.87 - 3.88 - if ( (d = find_domain_by_id(xmsi.domid)) == NULL ) 3.89 - return -ESRCH; 3.90 - 3.91 - /* Only initialised translated guests can set the shared_info 3.92 - * mapping. */ 3.93 - if ( !shadow_mode_translate(d) || (d->max_pages == 0) ) 3.94 + 3.95 + if ( !shadow_mode_translate(d) || (mfn == 0) ) 3.96 { 3.97 put_domain(d); 3.98 - return -ESRCH; 3.99 - } 3.100 - 3.101 - if ( xmsi.pfn > d->max_pages ) { 3.102 - put_domain(d); 3.103 return -EINVAL; 3.104 } 3.105 3.106 LOCK_BIGLOCK(d); 3.107 + 3.108 /* Remove previously mapped page if it was present. */ 3.109 - if ( mfn_valid(gmfn_to_mfn(d, xmsi.pfn)) ) 3.110 - guest_remove_page(d, xmsi.pfn); 3.111 - guest_physmap_add_page(d, xmsi.pfn, 3.112 - virt_to_maddr(d->shared_info) >> PAGE_SHIFT); 3.113 + if ( mfn_valid(gmfn_to_mfn(d, xatp.gpfn)) ) 3.114 + guest_remove_page(d, xatp.gpfn); 3.115 + 3.116 + /* Unmap from old location, if any. */ 3.117 + gpfn = get_gpfn_from_mfn(mfn); 3.118 + if ( gpfn != INVALID_M2P_ENTRY ) 3.119 + guest_physmap_remove_page(d, gpfn, mfn); 3.120 + 3.121 + /* Map at new location. */ 3.122 + guest_physmap_add_page(d, xatp.gpfn, mfn); 3.123 + 3.124 UNLOCK_BIGLOCK(d); 3.125 3.126 put_domain(d);
4.1 --- a/xen/include/asm-x86/grant_table.h Fri Mar 10 13:27:24 2006 +0000 4.2 +++ b/xen/include/asm-x86/grant_table.h Fri Mar 10 16:00:36 2006 +0100 4.3 @@ -26,9 +26,6 @@ int steal_page_for_grant_transfer( 4.4 share_xen_page_with_guest( \ 4.5 virt_to_page((char *)(t)->shared + ((i) * PAGE_SIZE)), \ 4.6 (d), XENSHARE_writable); \ 4.7 - set_gpfn_from_mfn( \ 4.8 - (virt_to_maddr((t)->shared) >> PAGE_SHIFT) + (i), \ 4.9 - INVALID_M2P_ENTRY); \ 4.10 } while ( 0 ) 4.11 4.12 #define gnttab_shared_mfn(d, t, i) \
5.1 --- a/xen/include/asm-x86/page.h Fri Mar 10 13:27:24 2006 +0000 5.2 +++ b/xen/include/asm-x86/page.h Fri Mar 10 16:00:36 2006 +0100 5.3 @@ -191,6 +191,10 @@ typedef struct { u64 pfn; } pagetable_t; 5.4 #define __pa(x) (virt_to_maddr(x)) 5.5 #define __va(x) (maddr_to_virt(x)) 5.6 5.7 +/* Convert between Xen-heap virtual addresses and machine frame numbers. */ 5.8 +#define virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT) 5.9 +#define mfn_to_virt(mfn) (maddr_to_virt(mfn << PAGE_SHIFT)) 5.10 + 5.11 /* Convert between machine frame numbers and page-info structures. */ 5.12 #define mfn_to_page(mfn) (frame_table + (mfn)) 5.13 #define page_to_mfn(pg) ((unsigned long)((pg) - frame_table))
6.1 --- a/xen/include/public/memory.h Fri Mar 10 13:27:24 2006 +0000 6.2 +++ b/xen/include/public/memory.h Fri Mar 10 16:00:36 2006 +0100 6.3 @@ -97,25 +97,27 @@ typedef struct xen_machphys_mfn_list { 6.4 DEFINE_GUEST_HANDLE(xen_machphys_mfn_list_t); 6.5 6.6 /* 6.7 - * Returns the base and size of the specified reserved 'RAM hole' in the 6.8 - * specified guest's pseudophysical address space. 6.9 - * arg == addr of xen_reserved_phys_area_t. 6.10 + * Sets the GPFN at which a particular page appears in the specified guest's 6.11 + * pseudophysical address space. 6.12 + * arg == addr of xen_add_to_physmap_t. 6.13 */ 6.14 -#define XENMEM_reserved_phys_area 7 6.15 -typedef struct xen_reserved_phys_area { 6.16 - /* Which domain to report about? */ 6.17 +#define XENMEM_add_to_physmap 7 6.18 +typedef struct xen_add_to_physmap { 6.19 + /* Which domain to change the mapping for. */ 6.20 domid_t domid; 6.21 6.22 - /* 6.23 - * Which reserved area to report? Out-of-range request reports 6.24 - * -ESRCH. Currently no architecture will have more than one reserved area. 6.25 - */ 6.26 - unsigned int idx; 6.27 + /* Source mapping space. */ 6.28 +#define XENMAPSPACE_shared_info 0 /* shared info page */ 6.29 +#define XENMAPSPACE_grant_table 1 /* grant table page */ 6.30 + unsigned int space; 6.31 6.32 - /* Base and size of the specified reserved area. */ 6.33 - unsigned long first_gpfn, nr_gpfns; 6.34 -} xen_reserved_phys_area_t; 6.35 -DEFINE_GUEST_HANDLE(xen_reserved_phys_area_t); 6.36 + /* Index into source mapping space. */ 6.37 + unsigned long idx; 6.38 + 6.39 + /* GPFN where the source mapping page should appear. */ 6.40 + unsigned long gpfn; 6.41 +} xen_add_to_physmap_t; 6.42 +DEFINE_GUEST_HANDLE(xen_add_to_physmap_t); 6.43 6.44 /* 6.45 * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error 6.46 @@ -140,21 +142,6 @@ typedef struct xen_translate_gpfn_list { 6.47 } xen_translate_gpfn_list_t; 6.48 DEFINE_GUEST_HANDLE(xen_translate_gpfn_list_t); 6.49 6.50 -/* 6.51 - * Sets the GPFN at which the shared_info_page appears in the specified 6.52 - * guest's pseudophysical address space. 6.53 - * arg == addr of xen_map_shared_info_t. 6.54 - */ 6.55 -#define XENMEM_map_shared_info 9 6.56 -typedef struct xen_map_shared_info { 6.57 - /* Which domain to change the mapping for. */ 6.58 - domid_t domid; 6.59 - 6.60 - /* GPFN where the shared_info_page should appear. */ 6.61 - unsigned long pfn; 6.62 -} xen_map_shared_info_t; 6.63 -DEFINE_GUEST_HANDLE(xen_map_shared_info_t); 6.64 - 6.65 #endif /* __XEN_PUBLIC_MEMORY_H__ */ 6.66 6.67 /*